1 /* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "expression.h"
30 #include "c-lang.h" /* For c_val_print */
31 #include "typeprint.h"
35 chill_print_value_fields
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int,
36 enum val_prettyprint
, struct type
**));
39 /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
40 Used to print data from type structures in a specified type. For example,
41 array bounds may be characters or booleans in some languages, and this
42 allows the ranges to be printed in their "natural" form rather than as
43 decimal integer values. */
46 chill_print_type_scalar (type
, val
, stream
)
51 switch (TYPE_CODE (type
))
54 if (TYPE_TARGET_TYPE (type
))
56 chill_print_type_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
60 print_type_scalar (type
, val
, stream
);
63 /* Print the elements of an array.
64 Similar to val_print_array_elements, but prints
65 element indexes (in Chill syntax). */
68 chill_val_print_array_elements (type
, valaddr
, address
, stream
,
69 format
, deref_ref
, recurse
, pretty
)
77 enum val_prettyprint pretty
;
80 unsigned int things_printed
= 0;
83 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
84 struct type
*index_type
= TYPE_TARGET_TYPE (range_type
);
86 /* Position of the array element we are examining to see
87 whether it is repeated. */
89 /* Number of repetitions we have detected so far. */
91 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
92 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
94 elttype
= TYPE_TARGET_TYPE (type
);
95 eltlen
= TYPE_LENGTH (elttype
);
96 len
= TYPE_LENGTH (type
) / eltlen
;
98 annotate_array_section_begin (i
, elttype
);
100 for (; i
< len
&& things_printed
< print_max
; i
++)
104 if (prettyprint_arrays
)
106 fprintf_filtered (stream
, ",\n");
107 print_spaces_filtered (2 + 2 * recurse
, stream
);
111 fprintf_filtered (stream
, ", ");
114 wrap_here (n_spaces (2 + 2 * recurse
));
118 while ((rep1
< len
) &&
119 !memcmp (valaddr
+ i
* eltlen
, valaddr
+ rep1
* eltlen
, eltlen
))
125 fputs_filtered ("(", stream
);
126 chill_print_type_scalar (index_type
, low_bound
+ i
, stream
);
129 fputs_filtered (":", stream
);
130 chill_print_type_scalar (index_type
, low_bound
+ i
+ reps
- 1,
132 fputs_filtered ("): ", stream
);
133 val_print (elttype
, valaddr
+ i
* eltlen
, 0, stream
, format
,
134 deref_ref
, recurse
+ 1, pretty
);
141 fputs_filtered ("): ", stream
);
142 val_print (elttype
, valaddr
+ i
* eltlen
, 0, stream
, format
,
143 deref_ref
, recurse
+ 1, pretty
);
148 annotate_array_section_end ();
151 fprintf_filtered (stream
, "...");
155 /* Print data of type TYPE located at VALADDR (within GDB), which came from
156 the inferior at address ADDRESS, onto stdio stream STREAM according to
157 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
160 If the data are a string pointer, returns the number of string characters
163 If DEREF_REF is nonzero, then dereference references, otherwise just print
166 The PRETTY parameter controls prettyprinting. */
169 chill_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
,
178 enum val_prettyprint pretty
;
181 unsigned int i
= 0; /* Number of characters printed. */
182 struct type
*elttype
;
185 switch (TYPE_CODE (type
))
187 case TYPE_CODE_ARRAY
:
188 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
190 if (prettyprint_arrays
)
192 print_spaces_filtered (2 + 2 * recurse
, stream
);
194 fprintf_filtered (stream
, "[");
195 chill_val_print_array_elements (type
, valaddr
, address
, stream
,
196 format
, deref_ref
, recurse
, pretty
);
197 fprintf_filtered (stream
, "]");
201 error ("unimplemented in chill_val_print; unspecified array length");
206 format
= format
? format
: output_format
;
209 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
213 val_print_type_code_int (type
, valaddr
, stream
);
218 format
= format
? format
: output_format
;
221 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
225 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
233 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
237 print_floating (valaddr
, type
, stream
);
242 format
= format
? format
: output_format
;
245 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
249 /* FIXME: Why is this using builtin_type_chill_bool not type? */
250 val
= unpack_long (builtin_type_chill_bool
, valaddr
);
251 fprintf_filtered (stream
, val
? "TRUE" : "FALSE");
255 case TYPE_CODE_UNDEF
:
256 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
257 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
258 and no complete type for struct foo in that file. */
259 fprintf_filtered (stream
, "<incomplete type>");
263 if (format
&& format
!= 's')
265 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
268 addr
= unpack_pointer (type
, valaddr
);
269 elttype
= TYPE_TARGET_TYPE (type
);
271 /* We assume a NULL pointer is all zeros ... */
274 fputs_filtered ("NULL", stream
);
278 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
280 /* Try to print what function it points to. */
281 print_address_demangle (addr
, stream
, demangle
);
282 /* Return value is irrelevant except for string pointers. */
285 if (addressprint
&& format
!= 's')
287 print_address_numeric (addr
, 1, stream
);
290 /* For a pointer to char or unsigned char, also print the string
291 pointed to, unless pointer is null. */
292 if (TYPE_LENGTH (elttype
) == 1
293 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
294 && (format
== 0 || format
== 's')
296 && /* If print_max is UINT_MAX, the alloca below will fail.
297 In that case don't try to print the string. */
298 print_max
< UINT_MAX
)
300 i
= val_print_string (addr
, 0, stream
);
302 /* Return number of characters printed, plus one for the
303 terminating null if we have "reached the end". */
304 return (i
+ (print_max
&& i
!= print_max
));
307 case TYPE_CODE_STRING
:
308 i
= TYPE_LENGTH (type
);
309 LA_PRINT_STRING (stream
, valaddr
, i
, 0);
310 /* Return number of characters printed, plus one for the terminating
311 null if we have "reached the end". */
312 return (i
+ (print_max
&& i
!= print_max
));
315 case TYPE_CODE_BITSTRING
:
317 elttype
= TYPE_INDEX_TYPE (type
);
318 check_stub_type (elttype
);
319 if (TYPE_FLAGS (elttype
) & TYPE_FLAG_STUB
)
321 fprintf_filtered (stream
, "<incomplete type>");
326 struct type
*range
= elttype
;
327 int low_bound
= TYPE_LOW_BOUND (range
);
328 int high_bound
= TYPE_HIGH_BOUND (range
);
330 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
334 fputs_filtered ("B'", stream
);
336 fputs_filtered ("[", stream
);
337 for (i
= low_bound
; i
<= high_bound
; i
++)
339 int element
= value_bit_index (type
, valaddr
, i
);
341 fprintf_filtered (stream
, "%d", element
);
345 fputs_filtered (", ", stream
);
346 chill_print_type_scalar (range
, i
, stream
);
349 /* Look for a continuous range of true elements. */
350 if (i
+1 <= high_bound
&& value_bit_index (type
, valaddr
, ++i
))
352 int j
= i
; /* j is the upper bound so far of the range */
353 fputs_filtered (":", stream
);
354 while (i
+1 <= high_bound
355 && value_bit_index (type
, valaddr
, ++i
))
357 chill_print_type_scalar (range
, j
, stream
);
362 fputs_filtered ("'", stream
);
364 fputs_filtered ("]", stream
);
368 case TYPE_CODE_STRUCT
:
369 if (chill_varying_type (type
))
371 struct type
*inner
= TYPE_FIELD_TYPE (type
, 1);
372 long length
= unpack_long (TYPE_FIELD_TYPE (type
, 0), valaddr
);
373 char *data_addr
= valaddr
+ TYPE_FIELD_BITPOS (type
, 1) / 8;
375 switch (TYPE_CODE (inner
))
377 case TYPE_CODE_STRING
:
378 if (length
> TYPE_LENGTH (type
))
380 fprintf_filtered (stream
,
381 "<dynamic length %d > static length %d>",
382 length
, TYPE_LENGTH (type
));
384 LA_PRINT_STRING (stream
, data_addr
, length
, 0);
390 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
397 fprintf_filtered (stream
, "LOC(");
398 print_address_numeric
399 (extract_address (valaddr
, TARGET_PTR_BIT
/ HOST_CHAR_BIT
),
402 fprintf_filtered (stream
, ")");
404 fputs_filtered (": ", stream
);
406 /* De-reference the reference. */
409 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
411 value_ptr deref_val
=
413 (TYPE_TARGET_TYPE (type
),
414 unpack_pointer (lookup_pointer_type (builtin_type_void
),
416 val_print (VALUE_TYPE (deref_val
),
417 VALUE_CONTENTS (deref_val
),
418 VALUE_ADDRESS (deref_val
), stream
, format
,
419 deref_ref
, recurse
+ 1, pretty
);
422 fputs_filtered ("???", stream
);
427 c_val_print (type
, valaddr
, address
, stream
, format
,
428 deref_ref
, recurse
, pretty
);
431 case TYPE_CODE_RANGE
:
432 if (TYPE_TARGET_TYPE (type
))
433 chill_val_print (TYPE_TARGET_TYPE (type
), valaddr
, address
, stream
,
434 format
, deref_ref
, recurse
, pretty
);
437 case TYPE_CODE_MEMBER
:
438 case TYPE_CODE_UNION
:
441 case TYPE_CODE_ERROR
:
443 /* Let's defer printing to the C printer, rather than
444 print an error message. FIXME! */
445 c_val_print (type
, valaddr
, address
, stream
, format
,
446 deref_ref
, recurse
, pretty
);
452 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
453 print out a structure's fields: cp_print_value_fields and cplus_print_value.
455 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
456 same meanings as in cplus_print_value and c_val_print.
458 DONT_PRINT is an array of baseclass types that we
459 should not print, or zero if called from top level. */
462 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
469 enum val_prettyprint pretty
;
470 struct type
**dont_print
;
475 check_stub_type (type
);
477 fprintf_filtered (stream
, "[");
478 len
= TYPE_NFIELDS (type
);
481 fprintf_filtered (stream
, "<No data fields>");
485 for (i
= 0; i
< len
; i
++)
489 fprintf_filtered (stream
, ", ");
494 fprintf_filtered (stream
, "\n");
495 print_spaces_filtered (2 + 2 * recurse
, stream
);
499 wrap_here (n_spaces (2 + 2 * recurse
));
501 fputs_filtered (".", stream
);
502 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
503 language_chill
, DMGL_NO_OPTS
);
504 fputs_filtered (": ", stream
);
505 if (TYPE_FIELD_PACKED (type
, i
))
509 /* Bitfields require special handling, especially due to byte
511 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
512 unpack_field_as_long (type
, valaddr
, i
));
514 chill_val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
515 stream
, format
, 0, recurse
+ 1, pretty
);
519 chill_val_print (TYPE_FIELD_TYPE (type
, i
),
520 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
521 0, stream
, format
, 0, recurse
+ 1, pretty
);
526 fprintf_filtered (stream
, "\n");
527 print_spaces_filtered (2 * recurse
, stream
);
530 fprintf_filtered (stream
, "]");
534 chill_value_print (val
, stream
, format
, pretty
)
538 enum val_prettyprint pretty
;
540 /* A "repeated" value really contains several values in a row.
541 They are made by the @ operator.
542 Print such values as if they were arrays. */
544 if (VALUE_REPEATED (val
))
546 register unsigned int n
= VALUE_REPETITIONS (val
);
547 register unsigned int typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
548 fprintf_filtered (stream
, "[");
549 /* Print arrays of characters using string syntax. */
550 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
552 LA_PRINT_STRING (stream
, VALUE_CONTENTS (val
), n
, 0);
555 value_print_array_elements (val
, stream
, format
, pretty
);
557 fprintf_filtered (stream
, "]");
558 return (n
* typelen
);
562 struct type
*type
= VALUE_TYPE (val
);
564 /* If it is a pointer, indicate what it points to.
566 Print type also if it is a reference.
568 C++: if it is a member pointer, we will take care
569 of that when we print it. */
570 if (TYPE_CODE (type
) == TYPE_CODE_PTR
||
571 TYPE_CODE (type
) == TYPE_CODE_REF
)
573 char *valaddr
= VALUE_CONTENTS (val
);
574 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
575 if (TYPE_CODE (type
) != TYPE_CODE_PTR
|| addr
!= 0)
578 char *name
= TYPE_NAME (type
);
580 fputs_filtered (name
, stream
);
581 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_VOID
)
582 fputs_filtered ("PTR", stream
);
585 fprintf_filtered (stream
, "(");
586 type_print (type
, "", stream
, -1);
587 fprintf_filtered (stream
, ")");
589 fprintf_filtered (stream
, "(");
590 i
= val_print (type
, valaddr
, VALUE_ADDRESS (val
),
591 stream
, format
, 1, 0, pretty
);
592 fprintf_filtered (stream
, ")");
596 return (val_print (type
, VALUE_CONTENTS (val
),
597 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));