]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/ch-valprint.c
* Makefile.in (VERSION): Bump to 4.7.4.
[thirdparty/binutils-gdb.git] / gdb / ch-valprint.c
1 /* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "defs.h"
21 #include "obstack.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "valprint.h"
25 #include "expression.h"
26 #include "language.h"
27
28 \f
29 /* Print data of type TYPE located at VALADDR (within GDB), which came from
30 the inferior at address ADDRESS, onto stdio stream STREAM according to
31 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
32 target byte order.
33
34 If the data are a string pointer, returns the number of string characters
35 printed.
36
37 If DEREF_REF is nonzero, then dereference references, otherwise just print
38 them like pointers.
39
40 The PRETTY parameter controls prettyprinting. */
41
42 int
43 chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
44 pretty)
45 struct type *type;
46 char *valaddr;
47 CORE_ADDR address;
48 FILE *stream;
49 int format;
50 int deref_ref;
51 int recurse;
52 enum val_prettyprint pretty;
53 {
54 unsigned len;
55 struct type *elttype;
56 unsigned eltlen;
57 LONGEST val;
58
59 switch (TYPE_CODE (type))
60 {
61 case TYPE_CODE_ARRAY:
62 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
63 {
64 elttype = TYPE_TARGET_TYPE (type);
65 eltlen = TYPE_LENGTH (elttype);
66 len = TYPE_LENGTH (type) / eltlen;
67 if (prettyprint_arrays)
68 {
69 print_spaces_filtered (2 + 2 * recurse, stream);
70 }
71 fprintf_filtered (stream, "[");
72 /* For an array of chars, print with string syntax. */
73 if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
74 && (format == 0 || format == 's') )
75 {
76 LA_PRINT_STRING (stream, valaddr, len, 0);
77 }
78 else
79 {
80 val_print_array_elements (type, valaddr, address, stream,
81 format, deref_ref, recurse, pretty, 0);
82 }
83 fprintf_filtered (stream, "]");
84 }
85 else
86 {
87 error ("unimplemented in chill_val_print; unspecified array length");
88 }
89 break;
90
91 case TYPE_CODE_INT:
92 format = format ? format : output_format;
93 if (format)
94 {
95 print_scalar_formatted (valaddr, type, format, 0, stream);
96 }
97 else
98 {
99 val_print_type_code_int (type, valaddr, stream);
100 }
101 break;
102
103 case TYPE_CODE_CHAR:
104 format = format ? format : output_format;
105 if (format)
106 {
107 print_scalar_formatted (valaddr, type, format, 0, stream);
108 }
109 else
110 {
111 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
112 stream);
113 }
114 break;
115
116 case TYPE_CODE_FLT:
117 if (format)
118 {
119 print_scalar_formatted (valaddr, type, format, 0, stream);
120 }
121 else
122 {
123 print_floating (valaddr, type, stream);
124 }
125 break;
126
127 case TYPE_CODE_BOOL:
128 format = format ? format : output_format;
129 if (format)
130 {
131 print_scalar_formatted (valaddr, type, format, 0, stream);
132 }
133 else
134 {
135 val = unpack_long (builtin_type_chill_bool, valaddr);
136 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
137 }
138 break;
139
140 case TYPE_CODE_UNDEF:
141 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
142 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
143 and no complete type for struct foo in that file. */
144 fprintf_filtered (stream, "<incomplete type>");
145 break;
146
147 case TYPE_CODE_PTR:
148 case TYPE_CODE_MEMBER:
149 case TYPE_CODE_REF:
150 case TYPE_CODE_UNION:
151 case TYPE_CODE_STRUCT:
152 case TYPE_CODE_ENUM:
153 case TYPE_CODE_FUNC:
154 case TYPE_CODE_VOID:
155 case TYPE_CODE_ERROR:
156 case TYPE_CODE_RANGE:
157 error ("Unimplemented chill_val_print support for type %d",
158 TYPE_CODE (type));
159 break;
160
161 default:
162 error ("Invalid Chill type code %d in symbol table.", TYPE_CODE (type));
163 }
164 fflush (stream);
165 return (0);
166 }