Commit | Line | Data |
---|---|---|
a8a69e63 | 1 | /* Support for printing Chill values for GDB, the GNU debugger. |
67e9b3b3 PS |
2 | Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
a8a69e63 FF |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
6c9638b4 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
a8a69e63 FF |
20 | |
21 | #include "defs.h" | |
22 | #include "obstack.h" | |
23 | #include "symtab.h" | |
24 | #include "gdbtypes.h" | |
25 | #include "valprint.h" | |
26 | #include "expression.h" | |
8fbdca53 | 27 | #include "value.h" |
a8a69e63 | 28 | #include "language.h" |
5e81259d | 29 | #include "demangle.h" |
100f92e2 | 30 | #include "c-lang.h" /* For c_val_print */ |
1c95d7ab JK |
31 | #include "typeprint.h" |
32 | #include "ch-lang.h" | |
477b2425 | 33 | #include "annotate.h" |
a8a69e63 | 34 | |
8fbdca53 | 35 | static void |
199b2450 | 36 | chill_print_value_fields PARAMS ((struct type *, char *, GDB_FILE *, int, int, |
8fbdca53 FF |
37 | enum val_prettyprint, struct type **)); |
38 | ||
b607efe7 FF |
39 | static void |
40 | chill_print_type_scalar PARAMS ((struct type *, LONGEST, GDB_FILE *)); | |
41 | ||
42 | static void | |
43 | chill_val_print_array_elements PARAMS ((struct type *, char *, CORE_ADDR, GDB_FILE *, | |
44 | int, int, int, enum val_prettyprint)); | |
45 | ||
3bcf4181 PB |
46 | \f |
47 | /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM. | |
48 | Used to print data from type structures in a specified type. For example, | |
49 | array bounds may be characters or booleans in some languages, and this | |
50 | allows the ranges to be printed in their "natural" form rather than as | |
51 | decimal integer values. */ | |
52 | ||
b607efe7 | 53 | static void |
3bcf4181 PB |
54 | chill_print_type_scalar (type, val, stream) |
55 | struct type *type; | |
56 | LONGEST val; | |
57 | GDB_FILE *stream; | |
58 | { | |
59 | switch (TYPE_CODE (type)) | |
60 | { | |
61 | case TYPE_CODE_RANGE: | |
62 | if (TYPE_TARGET_TYPE (type)) | |
63 | { | |
64 | chill_print_type_scalar (TYPE_TARGET_TYPE (type), val, stream); | |
65 | return; | |
66 | } | |
6b14af2b FF |
67 | break; |
68 | case TYPE_CODE_UNDEF: | |
69 | case TYPE_CODE_PTR: | |
70 | case TYPE_CODE_ARRAY: | |
71 | case TYPE_CODE_STRUCT: | |
72 | case TYPE_CODE_UNION: | |
73 | case TYPE_CODE_ENUM: | |
74 | case TYPE_CODE_FUNC: | |
75 | case TYPE_CODE_INT: | |
76 | case TYPE_CODE_FLT: | |
77 | case TYPE_CODE_VOID: | |
78 | case TYPE_CODE_SET: | |
79 | case TYPE_CODE_STRING: | |
80 | case TYPE_CODE_BITSTRING: | |
81 | case TYPE_CODE_ERROR: | |
82 | case TYPE_CODE_MEMBER: | |
83 | case TYPE_CODE_METHOD: | |
84 | case TYPE_CODE_REF: | |
85 | case TYPE_CODE_CHAR: | |
86 | case TYPE_CODE_BOOL: | |
87 | case TYPE_CODE_COMPLEX: | |
5e548861 | 88 | case TYPE_CODE_TYPEDEF: |
6b14af2b FF |
89 | default: |
90 | break; | |
3bcf4181 PB |
91 | } |
92 | print_type_scalar (type, val, stream); | |
93 | } | |
a8a69e63 | 94 | \f |
35f8a588 PB |
95 | /* Print the elements of an array. |
96 | Similar to val_print_array_elements, but prints | |
97 | element indexes (in Chill syntax). */ | |
98 | ||
99 | static void | |
100 | chill_val_print_array_elements (type, valaddr, address, stream, | |
101 | format, deref_ref, recurse, pretty) | |
102 | struct type *type; | |
103 | char *valaddr; | |
104 | CORE_ADDR address; | |
105 | GDB_FILE *stream; | |
106 | int format; | |
107 | int deref_ref; | |
108 | int recurse; | |
109 | enum val_prettyprint pretty; | |
110 | { | |
111 | unsigned int i = 0; | |
112 | unsigned int things_printed = 0; | |
113 | unsigned len; | |
114 | struct type *elttype; | |
115 | struct type *range_type = TYPE_FIELD_TYPE (type, 0); | |
116 | struct type *index_type = TYPE_TARGET_TYPE (range_type); | |
117 | unsigned eltlen; | |
118 | /* Position of the array element we are examining to see | |
119 | whether it is repeated. */ | |
120 | unsigned int rep1; | |
121 | /* Number of repetitions we have detected so far. */ | |
122 | unsigned int reps; | |
123 | LONGEST low_bound = TYPE_FIELD_BITPOS (range_type, 0); | |
35f8a588 | 124 | |
5e548861 | 125 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
35f8a588 PB |
126 | eltlen = TYPE_LENGTH (elttype); |
127 | len = TYPE_LENGTH (type) / eltlen; | |
128 | ||
129 | annotate_array_section_begin (i, elttype); | |
130 | ||
131 | for (; i < len && things_printed < print_max; i++) | |
132 | { | |
133 | if (i != 0) | |
134 | { | |
135 | if (prettyprint_arrays) | |
136 | { | |
137 | fprintf_filtered (stream, ",\n"); | |
138 | print_spaces_filtered (2 + 2 * recurse, stream); | |
139 | } | |
140 | else | |
141 | { | |
142 | fprintf_filtered (stream, ", "); | |
143 | } | |
144 | } | |
145 | wrap_here (n_spaces (2 + 2 * recurse)); | |
146 | ||
147 | rep1 = i + 1; | |
148 | reps = 1; | |
149 | while ((rep1 < len) && | |
150 | !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen)) | |
151 | { | |
152 | ++reps; | |
153 | ++rep1; | |
154 | } | |
155 | ||
156 | fputs_filtered ("(", stream); | |
3bcf4181 | 157 | chill_print_type_scalar (index_type, low_bound + i, stream); |
35f8a588 PB |
158 | if (reps > 1) |
159 | { | |
160 | fputs_filtered (":", stream); | |
3bcf4181 PB |
161 | chill_print_type_scalar (index_type, low_bound + i + reps - 1, |
162 | stream); | |
35f8a588 | 163 | fputs_filtered ("): ", stream); |
4ef1f467 | 164 | val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format, |
35f8a588 PB |
165 | deref_ref, recurse + 1, pretty); |
166 | ||
167 | i = rep1 - 1; | |
168 | things_printed += 1; | |
169 | } | |
170 | else | |
171 | { | |
172 | fputs_filtered ("): ", stream); | |
4ef1f467 | 173 | val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format, |
35f8a588 PB |
174 | deref_ref, recurse + 1, pretty); |
175 | annotate_elt (); | |
176 | things_printed++; | |
177 | } | |
178 | } | |
179 | annotate_array_section_end (); | |
180 | if (i < len) | |
181 | { | |
182 | fprintf_filtered (stream, "..."); | |
183 | } | |
184 | } | |
185 | ||
a8a69e63 FF |
186 | /* Print data of type TYPE located at VALADDR (within GDB), which came from |
187 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
188 | FORMAT (a letter or 0 for natural format). The data at VALADDR is in | |
189 | target byte order. | |
190 | ||
191 | If the data are a string pointer, returns the number of string characters | |
192 | printed. | |
193 | ||
194 | If DEREF_REF is nonzero, then dereference references, otherwise just print | |
195 | them like pointers. | |
196 | ||
197 | The PRETTY parameter controls prettyprinting. */ | |
198 | ||
199 | int | |
4ef1f467 DT |
200 | chill_val_print (type, valaddr, embedded_offset, address, |
201 | stream, format, deref_ref, recurse, pretty) | |
a8a69e63 FF |
202 | struct type *type; |
203 | char *valaddr; | |
4ef1f467 | 204 | int embedded_offset; |
a8a69e63 | 205 | CORE_ADDR address; |
199b2450 | 206 | GDB_FILE *stream; |
a8a69e63 FF |
207 | int format; |
208 | int deref_ref; | |
209 | int recurse; | |
210 | enum val_prettyprint pretty; | |
211 | { | |
a8a69e63 | 212 | LONGEST val; |
ec16f701 | 213 | unsigned int i = 0; /* Number of characters printed. */ |
c7da3ed3 | 214 | struct type *elttype; |
c7da3ed3 | 215 | CORE_ADDR addr; |
a8a69e63 | 216 | |
5e548861 PB |
217 | CHECK_TYPEDEF (type); |
218 | ||
a8a69e63 FF |
219 | switch (TYPE_CODE (type)) |
220 | { | |
221 | case TYPE_CODE_ARRAY: | |
222 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
223 | { | |
a8a69e63 FF |
224 | if (prettyprint_arrays) |
225 | { | |
226 | print_spaces_filtered (2 + 2 * recurse, stream); | |
227 | } | |
228 | fprintf_filtered (stream, "["); | |
35f8a588 PB |
229 | chill_val_print_array_elements (type, valaddr, address, stream, |
230 | format, deref_ref, recurse, pretty); | |
a8a69e63 FF |
231 | fprintf_filtered (stream, "]"); |
232 | } | |
233 | else | |
234 | { | |
235 | error ("unimplemented in chill_val_print; unspecified array length"); | |
236 | } | |
237 | break; | |
238 | ||
239 | case TYPE_CODE_INT: | |
240 | format = format ? format : output_format; | |
241 | if (format) | |
242 | { | |
243 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
244 | } | |
245 | else | |
246 | { | |
247 | val_print_type_code_int (type, valaddr, stream); | |
248 | } | |
249 | break; | |
250 | ||
251 | case TYPE_CODE_CHAR: | |
252 | format = format ? format : output_format; | |
253 | if (format) | |
254 | { | |
255 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
256 | } | |
257 | else | |
258 | { | |
259 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr), | |
260 | stream); | |
261 | } | |
262 | break; | |
263 | ||
264 | case TYPE_CODE_FLT: | |
265 | if (format) | |
266 | { | |
267 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
268 | } | |
269 | else | |
270 | { | |
271 | print_floating (valaddr, type, stream); | |
272 | } | |
273 | break; | |
274 | ||
275 | case TYPE_CODE_BOOL: | |
276 | format = format ? format : output_format; | |
277 | if (format) | |
278 | { | |
279 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
280 | } | |
281 | else | |
282 | { | |
61932a8e | 283 | /* FIXME: Why is this using builtin_type_chill_bool not type? */ |
a8a69e63 FF |
284 | val = unpack_long (builtin_type_chill_bool, valaddr); |
285 | fprintf_filtered (stream, val ? "TRUE" : "FALSE"); | |
286 | } | |
287 | break; | |
288 | ||
289 | case TYPE_CODE_UNDEF: | |
290 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
291 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" | |
292 | and no complete type for struct foo in that file. */ | |
293 | fprintf_filtered (stream, "<incomplete type>"); | |
294 | break; | |
295 | ||
296 | case TYPE_CODE_PTR: | |
c7da3ed3 FF |
297 | if (format && format != 's') |
298 | { | |
299 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
300 | break; | |
301 | } | |
302 | addr = unpack_pointer (type, valaddr); | |
5e548861 | 303 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
e10cfcaa PB |
304 | |
305 | /* We assume a NULL pointer is all zeros ... */ | |
306 | if (addr == 0) | |
307 | { | |
308 | fputs_filtered ("NULL", stream); | |
309 | return 0; | |
310 | } | |
c7da3ed3 FF |
311 | |
312 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
313 | { | |
314 | /* Try to print what function it points to. */ | |
315 | print_address_demangle (addr, stream, demangle); | |
316 | /* Return value is irrelevant except for string pointers. */ | |
317 | return (0); | |
318 | } | |
319 | if (addressprint && format != 's') | |
320 | { | |
d24c0599 | 321 | print_address_numeric (addr, 1, stream); |
c7da3ed3 FF |
322 | } |
323 | ||
324 | /* For a pointer to char or unsigned char, also print the string | |
325 | pointed to, unless pointer is null. */ | |
c7da3ed3 FF |
326 | if (TYPE_LENGTH (elttype) == 1 |
327 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR | |
328 | && (format == 0 || format == 's') | |
329 | && addr != 0 | |
330 | && /* If print_max is UINT_MAX, the alloca below will fail. | |
331 | In that case don't try to print the string. */ | |
332 | print_max < UINT_MAX) | |
242c0d81 SG |
333 | i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); |
334 | ||
c7da3ed3 FF |
335 | /* Return number of characters printed, plus one for the |
336 | terminating null if we have "reached the end". */ | |
337 | return (i + (print_max && i != print_max)); | |
338 | break; | |
339 | ||
c4413e2c | 340 | case TYPE_CODE_STRING: |
ec16f701 | 341 | i = TYPE_LENGTH (type); |
242c0d81 | 342 | LA_PRINT_STRING (stream, valaddr, i, 1, 0); |
c4413e2c FF |
343 | /* Return number of characters printed, plus one for the terminating |
344 | null if we have "reached the end". */ | |
345 | return (i + (print_max && i != print_max)); | |
346 | break; | |
347 | ||
cba00921 | 348 | case TYPE_CODE_BITSTRING: |
e909f287 | 349 | case TYPE_CODE_SET: |
6f52d064 | 350 | elttype = TYPE_INDEX_TYPE (type); |
5e548861 | 351 | CHECK_TYPEDEF (elttype); |
e10cfcaa PB |
352 | if (TYPE_FLAGS (elttype) & TYPE_FLAG_STUB) |
353 | { | |
354 | fprintf_filtered (stream, "<incomplete type>"); | |
355 | gdb_flush (stream); | |
356 | break; | |
357 | } | |
e909f287 | 358 | { |
e10cfcaa | 359 | struct type *range = elttype; |
706bfe5a | 360 | LONGEST low_bound, high_bound; |
e909f287 | 361 | int i; |
cba00921 | 362 | int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING; |
e909f287 | 363 | int need_comma = 0; |
e909f287 PB |
364 | |
365 | if (is_bitstring) | |
366 | fputs_filtered ("B'", stream); | |
367 | else | |
368 | fputs_filtered ("[", stream); | |
706bfe5a PB |
369 | |
370 | i = get_discrete_bounds (range, &low_bound, &high_bound); | |
371 | maybe_bad_bstring: | |
372 | if (i < 0) | |
373 | { | |
374 | fputs_filtered ("<error value>", stream); | |
375 | goto done; | |
376 | } | |
377 | ||
e909f287 PB |
378 | for (i = low_bound; i <= high_bound; i++) |
379 | { | |
380 | int element = value_bit_index (type, valaddr, i); | |
706bfe5a PB |
381 | if (element < 0) |
382 | { | |
383 | i = element; | |
384 | goto maybe_bad_bstring; | |
385 | } | |
e909f287 PB |
386 | if (is_bitstring) |
387 | fprintf_filtered (stream, "%d", element); | |
388 | else if (element) | |
389 | { | |
390 | if (need_comma) | |
391 | fputs_filtered (", ", stream); | |
b607efe7 | 392 | chill_print_type_scalar (range, (LONGEST) i, stream); |
e909f287 PB |
393 | need_comma = 1; |
394 | ||
395 | /* Look for a continuous range of true elements. */ | |
396 | if (i+1 <= high_bound && value_bit_index (type, valaddr, ++i)) | |
397 | { | |
398 | int j = i; /* j is the upper bound so far of the range */ | |
399 | fputs_filtered (":", stream); | |
400 | while (i+1 <= high_bound | |
401 | && value_bit_index (type, valaddr, ++i)) | |
402 | j = i; | |
b607efe7 | 403 | chill_print_type_scalar (range, (LONGEST) j, stream); |
e909f287 PB |
404 | } |
405 | } | |
406 | } | |
706bfe5a | 407 | done: |
e909f287 PB |
408 | if (is_bitstring) |
409 | fputs_filtered ("'", stream); | |
410 | else | |
411 | fputs_filtered ("]", stream); | |
412 | } | |
413 | break; | |
414 | ||
8fbdca53 | 415 | case TYPE_CODE_STRUCT: |
6073b8de | 416 | if (chill_varying_type (type)) |
cba00921 | 417 | { |
5e548861 | 418 | struct type *inner = check_typedef (TYPE_FIELD_TYPE (type, 1)); |
cba00921 PB |
419 | long length = unpack_long (TYPE_FIELD_TYPE (type, 0), valaddr); |
420 | char *data_addr = valaddr + TYPE_FIELD_BITPOS (type, 1) / 8; | |
421 | ||
422 | switch (TYPE_CODE (inner)) | |
423 | { | |
424 | case TYPE_CODE_STRING: | |
bf6a4419 | 425 | if (length > TYPE_LENGTH (type) - 2) |
cba00921 PB |
426 | { |
427 | fprintf_filtered (stream, | |
bf6a4419 | 428 | "<dynamic length %ld > static length %d> *invalid*", |
cba00921 | 429 | length, TYPE_LENGTH (type)); |
bf6a4419 JB |
430 | |
431 | /* Don't print the string; doing so might produce a | |
432 | segfault. */ | |
433 | return length; | |
cba00921 | 434 | } |
242c0d81 | 435 | LA_PRINT_STRING (stream, data_addr, length, 1, 0); |
cba00921 | 436 | return length; |
1c95d7ab JK |
437 | default: |
438 | break; | |
cba00921 PB |
439 | } |
440 | } | |
8fbdca53 FF |
441 | chill_print_value_fields (type, valaddr, stream, format, recurse, pretty, |
442 | 0); | |
443 | break; | |
444 | ||
a8a69e63 | 445 | case TYPE_CODE_REF: |
8a177da6 PB |
446 | if (addressprint) |
447 | { | |
833e0d94 JK |
448 | fprintf_filtered (stream, "LOC("); |
449 | print_address_numeric | |
450 | (extract_address (valaddr, TARGET_PTR_BIT / HOST_CHAR_BIT), | |
d24c0599 | 451 | 1, |
833e0d94 JK |
452 | stream); |
453 | fprintf_filtered (stream, ")"); | |
8a177da6 PB |
454 | if (deref_ref) |
455 | fputs_filtered (": ", stream); | |
456 | } | |
457 | /* De-reference the reference. */ | |
458 | if (deref_ref) | |
459 | { | |
460 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF) | |
461 | { | |
82a2edfb | 462 | value_ptr deref_val = |
8a177da6 PB |
463 | value_at |
464 | (TYPE_TARGET_TYPE (type), | |
465 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
6c310da8 SG |
466 | valaddr), |
467 | NULL); | |
8a177da6 PB |
468 | val_print (VALUE_TYPE (deref_val), |
469 | VALUE_CONTENTS (deref_val), | |
4ef1f467 | 470 | 0, |
8a177da6 PB |
471 | VALUE_ADDRESS (deref_val), stream, format, |
472 | deref_ref, recurse + 1, pretty); | |
473 | } | |
474 | else | |
475 | fputs_filtered ("???", stream); | |
476 | } | |
477 | break; | |
478 | ||
a8a69e63 | 479 | case TYPE_CODE_ENUM: |
4ef1f467 | 480 | c_val_print (type, valaddr, 0, address, stream, format, |
8a177da6 PB |
481 | deref_ref, recurse, pretty); |
482 | break; | |
483 | ||
11b959da FF |
484 | case TYPE_CODE_RANGE: |
485 | if (TYPE_TARGET_TYPE (type)) | |
4ef1f467 | 486 | chill_val_print (TYPE_TARGET_TYPE (type), valaddr, 0, address, stream, |
11b959da FF |
487 | format, deref_ref, recurse, pretty); |
488 | break; | |
489 | ||
8a177da6 PB |
490 | case TYPE_CODE_MEMBER: |
491 | case TYPE_CODE_UNION: | |
a8a69e63 FF |
492 | case TYPE_CODE_FUNC: |
493 | case TYPE_CODE_VOID: | |
494 | case TYPE_CODE_ERROR: | |
a8a69e63 | 495 | default: |
11b959da | 496 | /* Let's defer printing to the C printer, rather than |
8a177da6 | 497 | print an error message. FIXME! */ |
4ef1f467 | 498 | c_val_print (type, valaddr, 0, address, stream, format, |
8a177da6 | 499 | deref_ref, recurse, pretty); |
a8a69e63 | 500 | } |
199b2450 | 501 | gdb_flush (stream); |
a8a69e63 FF |
502 | return (0); |
503 | } | |
8fbdca53 FF |
504 | |
505 | /* Mutually recursive subroutines of cplus_print_value and c_val_print to | |
506 | print out a structure's fields: cp_print_value_fields and cplus_print_value. | |
507 | ||
508 | TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the | |
509 | same meanings as in cplus_print_value and c_val_print. | |
510 | ||
511 | DONT_PRINT is an array of baseclass types that we | |
512 | should not print, or zero if called from top level. */ | |
513 | ||
514 | static void | |
515 | chill_print_value_fields (type, valaddr, stream, format, recurse, pretty, | |
516 | dont_print) | |
517 | struct type *type; | |
518 | char *valaddr; | |
199b2450 | 519 | GDB_FILE *stream; |
8fbdca53 FF |
520 | int format; |
521 | int recurse; | |
522 | enum val_prettyprint pretty; | |
523 | struct type **dont_print; | |
524 | { | |
525 | int i, len; | |
526 | int fields_seen = 0; | |
527 | ||
5e548861 | 528 | CHECK_TYPEDEF (type); |
8fbdca53 | 529 | |
8a177da6 | 530 | fprintf_filtered (stream, "["); |
8fbdca53 FF |
531 | len = TYPE_NFIELDS (type); |
532 | if (len == 0) | |
533 | { | |
534 | fprintf_filtered (stream, "<No data fields>"); | |
535 | } | |
536 | else | |
537 | { | |
538 | for (i = 0; i < len; i++) | |
539 | { | |
540 | if (fields_seen) | |
541 | { | |
542 | fprintf_filtered (stream, ", "); | |
543 | } | |
544 | fields_seen = 1; | |
545 | if (pretty) | |
546 | { | |
547 | fprintf_filtered (stream, "\n"); | |
548 | print_spaces_filtered (2 + 2 * recurse, stream); | |
549 | } | |
550 | else | |
551 | { | |
552 | wrap_here (n_spaces (2 + 2 * recurse)); | |
553 | } | |
8a177da6 | 554 | fputs_filtered (".", stream); |
5e81259d FF |
555 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), |
556 | language_chill, DMGL_NO_OPTS); | |
8a177da6 | 557 | fputs_filtered (": ", stream); |
8fbdca53 FF |
558 | if (TYPE_FIELD_PACKED (type, i)) |
559 | { | |
82a2edfb | 560 | value_ptr v; |
8fbdca53 FF |
561 | |
562 | /* Bitfields require special handling, especially due to byte | |
563 | order problems. */ | |
564 | v = value_from_longest (TYPE_FIELD_TYPE (type, i), | |
565 | unpack_field_as_long (type, valaddr, i)); | |
566 | ||
4ef1f467 | 567 | chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0, |
8fbdca53 FF |
568 | stream, format, 0, recurse + 1, pretty); |
569 | } | |
570 | else | |
571 | { | |
572 | chill_val_print (TYPE_FIELD_TYPE (type, i), | |
4ef1f467 | 573 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, 0, |
8fbdca53 FF |
574 | 0, stream, format, 0, recurse + 1, pretty); |
575 | } | |
576 | } | |
577 | if (pretty) | |
578 | { | |
579 | fprintf_filtered (stream, "\n"); | |
580 | print_spaces_filtered (2 * recurse, stream); | |
581 | } | |
582 | } | |
8a177da6 | 583 | fprintf_filtered (stream, "]"); |
8fbdca53 | 584 | } |
e10cfcaa PB |
585 | \f |
586 | int | |
587 | chill_value_print (val, stream, format, pretty) | |
588 | value_ptr val; | |
589 | GDB_FILE *stream; | |
590 | int format; | |
591 | enum val_prettyprint pretty; | |
592 | { | |
398f584f | 593 | struct type *type = VALUE_TYPE (val); |
5e548861 | 594 | struct type *real_type = check_typedef (type); |
e10cfcaa | 595 | |
398f584f | 596 | /* If it is a pointer, indicate what it points to. |
e10cfcaa | 597 | |
5e548861 | 598 | Print type also if it is a reference. */ |
e10cfcaa | 599 | |
5e548861 PB |
600 | if (TYPE_CODE (real_type) == TYPE_CODE_PTR || |
601 | TYPE_CODE (real_type) == TYPE_CODE_REF) | |
398f584f PB |
602 | { |
603 | char *valaddr = VALUE_CONTENTS (val); | |
604 | CORE_ADDR addr = unpack_pointer (type, valaddr); | |
605 | if (TYPE_CODE (type) != TYPE_CODE_PTR || addr != 0) | |
e10cfcaa | 606 | { |
398f584f PB |
607 | int i; |
608 | char *name = TYPE_NAME (type); | |
609 | if (name) | |
610 | fputs_filtered (name, stream); | |
611 | else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID) | |
612 | fputs_filtered ("PTR", stream); | |
613 | else | |
e10cfcaa | 614 | { |
e10cfcaa | 615 | fprintf_filtered (stream, "("); |
398f584f | 616 | type_print (type, "", stream, -1); |
e10cfcaa | 617 | fprintf_filtered (stream, ")"); |
e10cfcaa | 618 | } |
398f584f | 619 | fprintf_filtered (stream, "("); |
4ef1f467 | 620 | i = val_print (type, valaddr, 0, VALUE_ADDRESS (val), |
398f584f PB |
621 | stream, format, 1, 0, pretty); |
622 | fprintf_filtered (stream, ")"); | |
623 | return i; | |
e10cfcaa | 624 | } |
e10cfcaa | 625 | } |
4ef1f467 | 626 | return (val_print (type, VALUE_CONTENTS (val), 0, |
398f584f | 627 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty)); |
e10cfcaa PB |
628 | } |
629 | ||
630 |