gcc lint
[deliverable/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 "value.h"
27 #include "language.h"
28 #include "demangle.h"
29
30 static void
31 chill_print_value_fields PARAMS ((struct type *, char *, FILE *, int, int,
32 enum val_prettyprint, struct type **));
33
34 \f
35 /* Print data of type TYPE located at VALADDR (within GDB), which came from
36 the inferior at address ADDRESS, onto stdio stream STREAM according to
37 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
38 target byte order.
39
40 If the data are a string pointer, returns the number of string characters
41 printed.
42
43 If DEREF_REF is nonzero, then dereference references, otherwise just print
44 them like pointers.
45
46 The PRETTY parameter controls prettyprinting. */
47
48 int
49 chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
50 pretty)
51 struct type *type;
52 char *valaddr;
53 CORE_ADDR address;
54 FILE *stream;
55 int format;
56 int deref_ref;
57 int recurse;
58 enum val_prettyprint pretty;
59 {
60 LONGEST val;
61 unsigned int i = 0; /* Number of characters printed. */
62 struct type *elttype;
63 CORE_ADDR addr;
64
65 switch (TYPE_CODE (type))
66 {
67 case TYPE_CODE_ARRAY:
68 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
69 {
70 if (prettyprint_arrays)
71 {
72 print_spaces_filtered (2 + 2 * recurse, stream);
73 }
74 fprintf_filtered (stream, "[");
75 val_print_array_elements (type, valaddr, address, stream, format,
76 deref_ref, recurse, pretty, 0);
77 fprintf_filtered (stream, "]");
78 }
79 else
80 {
81 error ("unimplemented in chill_val_print; unspecified array length");
82 }
83 break;
84
85 case TYPE_CODE_INT:
86 format = format ? format : output_format;
87 if (format)
88 {
89 print_scalar_formatted (valaddr, type, format, 0, stream);
90 }
91 else
92 {
93 val_print_type_code_int (type, valaddr, stream);
94 }
95 break;
96
97 case TYPE_CODE_CHAR:
98 format = format ? format : output_format;
99 if (format)
100 {
101 print_scalar_formatted (valaddr, type, format, 0, stream);
102 }
103 else
104 {
105 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
106 stream);
107 }
108 break;
109
110 case TYPE_CODE_FLT:
111 if (format)
112 {
113 print_scalar_formatted (valaddr, type, format, 0, stream);
114 }
115 else
116 {
117 print_floating (valaddr, type, stream);
118 }
119 break;
120
121 case TYPE_CODE_BOOL:
122 format = format ? format : output_format;
123 if (format)
124 {
125 print_scalar_formatted (valaddr, type, format, 0, stream);
126 }
127 else
128 {
129 val = unpack_long (builtin_type_chill_bool, valaddr);
130 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
131 }
132 break;
133
134 case TYPE_CODE_UNDEF:
135 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
136 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
137 and no complete type for struct foo in that file. */
138 fprintf_filtered (stream, "<incomplete type>");
139 break;
140
141 case TYPE_CODE_PTR:
142 if (format && format != 's')
143 {
144 print_scalar_formatted (valaddr, type, format, 0, stream);
145 break;
146 }
147 addr = unpack_pointer (type, valaddr);
148 elttype = TYPE_TARGET_TYPE (type);
149
150 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
151 {
152 /* Try to print what function it points to. */
153 print_address_demangle (addr, stream, demangle);
154 /* Return value is irrelevant except for string pointers. */
155 return (0);
156 }
157 if (addressprint && format != 's')
158 {
159 fprintf_filtered (stream, "H'%x", addr);
160 }
161
162 /* For a pointer to char or unsigned char, also print the string
163 pointed to, unless pointer is null. */
164 if (TYPE_LENGTH (elttype) == 1
165 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
166 && (format == 0 || format == 's')
167 && addr != 0
168 && /* If print_max is UINT_MAX, the alloca below will fail.
169 In that case don't try to print the string. */
170 print_max < UINT_MAX)
171 {
172 i = val_print_string (addr, 0, stream);
173 }
174 /* Return number of characters printed, plus one for the
175 terminating null if we have "reached the end". */
176 return (i + (print_max && i != print_max));
177 break;
178
179 case TYPE_CODE_STRING:
180 if (format && format != 's')
181 {
182 print_scalar_formatted (valaddr, type, format, 0, stream);
183 break;
184 }
185 if (addressprint && format != 's')
186 {
187 /* This used to say `addr', which is unset at this point.
188 Is `address' what is meant? */
189 fprintf_filtered (stream, "H'%x ", address);
190 }
191 i = TYPE_LENGTH (type);
192 LA_PRINT_STRING (stream, valaddr, i, 0);
193 /* Return number of characters printed, plus one for the terminating
194 null if we have "reached the end". */
195 return (i + (print_max && i != print_max));
196 break;
197
198 case TYPE_CODE_STRUCT:
199 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
200 0);
201 break;
202
203 case TYPE_CODE_REF:
204 if (addressprint)
205 {
206 fprintf_filtered (stream, "LOC(H'%lx)",
207 unpack_long (builtin_type_int, valaddr));
208 if (deref_ref)
209 fputs_filtered (": ", stream);
210 }
211 /* De-reference the reference. */
212 if (deref_ref)
213 {
214 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
215 {
216 value deref_val =
217 value_at
218 (TYPE_TARGET_TYPE (type),
219 unpack_pointer (lookup_pointer_type (builtin_type_void),
220 valaddr));
221 val_print (VALUE_TYPE (deref_val),
222 VALUE_CONTENTS (deref_val),
223 VALUE_ADDRESS (deref_val), stream, format,
224 deref_ref, recurse + 1, pretty);
225 }
226 else
227 fputs_filtered ("???", stream);
228 }
229 break;
230
231 case TYPE_CODE_ENUM:
232 c_val_print (type, valaddr, address, stream, format,
233 deref_ref, recurse, pretty);
234 break;
235
236 case TYPE_CODE_MEMBER:
237 case TYPE_CODE_UNION:
238 case TYPE_CODE_FUNC:
239 case TYPE_CODE_VOID:
240 case TYPE_CODE_ERROR:
241 case TYPE_CODE_RANGE:
242 default:
243 /* Let's derfer printing to the C printer, rather than
244 print an error message. FIXME! */
245 c_val_print (type, valaddr, address, stream, format,
246 deref_ref, recurse, pretty);
247 }
248 fflush (stream);
249 return (0);
250 }
251
252 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
253 print out a structure's fields: cp_print_value_fields and cplus_print_value.
254
255 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
256 same meanings as in cplus_print_value and c_val_print.
257
258 DONT_PRINT is an array of baseclass types that we
259 should not print, or zero if called from top level. */
260
261 static void
262 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
263 dont_print)
264 struct type *type;
265 char *valaddr;
266 FILE *stream;
267 int format;
268 int recurse;
269 enum val_prettyprint pretty;
270 struct type **dont_print;
271 {
272 int i, len;
273 int fields_seen = 0;
274
275 check_stub_type (type);
276
277 fprintf_filtered (stream, "[");
278 len = TYPE_NFIELDS (type);
279 if (len == 0)
280 {
281 fprintf_filtered (stream, "<No data fields>");
282 }
283 else
284 {
285 for (i = 0; i < len; i++)
286 {
287 if (fields_seen)
288 {
289 fprintf_filtered (stream, ", ");
290 }
291 fields_seen = 1;
292 if (pretty)
293 {
294 fprintf_filtered (stream, "\n");
295 print_spaces_filtered (2 + 2 * recurse, stream);
296 }
297 else
298 {
299 wrap_here (n_spaces (2 + 2 * recurse));
300 }
301 fputs_filtered (".", stream);
302 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
303 language_chill, DMGL_NO_OPTS);
304 fputs_filtered (": ", stream);
305 if (TYPE_FIELD_PACKED (type, i))
306 {
307 value v;
308
309 /* Bitfields require special handling, especially due to byte
310 order problems. */
311 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
312 unpack_field_as_long (type, valaddr, i));
313
314 chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
315 stream, format, 0, recurse + 1, pretty);
316 }
317 else
318 {
319 chill_val_print (TYPE_FIELD_TYPE (type, i),
320 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
321 0, stream, format, 0, recurse + 1, pretty);
322 }
323 }
324 if (pretty)
325 {
326 fprintf_filtered (stream, "\n");
327 print_spaces_filtered (2 * recurse, stream);
328 }
329 }
330 fprintf_filtered (stream, "]");
331 }
332
This page took 0.038813 seconds and 5 git commands to generate.