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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 #include "expression.h"
31 #include "c-lang.h" /* For c_val_print */
32 #include "typeprint.h"
37 chill_print_value_fields
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int,
38 enum val_prettyprint
, struct type
**));
41 chill_print_type_scalar
PARAMS ((struct type
*, LONGEST
, GDB_FILE
*));
44 chill_val_print_array_elements
PARAMS ((struct type
*, char *, CORE_ADDR
, GDB_FILE
*,
45 int, int, int, enum val_prettyprint
));
48 /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
49 Used to print data from type structures in a specified type. For example,
50 array bounds may be characters or booleans in some languages, and this
51 allows the ranges to be printed in their "natural" form rather than as
52 decimal integer values. */
55 chill_print_type_scalar (type
, val
, stream
)
60 switch (TYPE_CODE (type
))
63 if (TYPE_TARGET_TYPE (type
))
65 chill_print_type_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
72 case TYPE_CODE_STRUCT
:
80 case TYPE_CODE_STRING
:
81 case TYPE_CODE_BITSTRING
:
83 case TYPE_CODE_MEMBER
:
84 case TYPE_CODE_METHOD
:
88 case TYPE_CODE_COMPLEX
:
89 case TYPE_CODE_TYPEDEF
:
93 print_type_scalar (type
, val
, stream
);
96 /* Print the elements of an array.
97 Similar to val_print_array_elements, but prints
98 element indexes (in Chill syntax). */
101 chill_val_print_array_elements (type
, valaddr
, address
, stream
,
102 format
, deref_ref
, recurse
, pretty
)
110 enum val_prettyprint pretty
;
113 unsigned int things_printed
= 0;
115 struct type
*elttype
;
116 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
117 struct type
*index_type
= TYPE_TARGET_TYPE (range_type
);
119 /* Position of the array element we are examining to see
120 whether it is repeated. */
122 /* Number of repetitions we have detected so far. */
124 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
126 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
127 eltlen
= TYPE_LENGTH (elttype
);
128 len
= TYPE_LENGTH (type
) / eltlen
;
130 annotate_array_section_begin (i
, elttype
);
132 for (; i
< len
&& things_printed
< print_max
; i
++)
136 if (prettyprint_arrays
)
138 fprintf_filtered (stream
, ",\n");
139 print_spaces_filtered (2 + 2 * recurse
, stream
);
143 fprintf_filtered (stream
, ", ");
146 wrap_here (n_spaces (2 + 2 * recurse
));
150 while ((rep1
< len
) &&
151 !memcmp (valaddr
+ i
* eltlen
, valaddr
+ rep1
* eltlen
, eltlen
))
157 fputs_filtered ("(", stream
);
158 chill_print_type_scalar (index_type
, low_bound
+ i
, stream
);
161 fputs_filtered (":", stream
);
162 chill_print_type_scalar (index_type
, low_bound
+ i
+ reps
- 1,
164 fputs_filtered ("): ", stream
);
165 val_print (elttype
, valaddr
+ i
* eltlen
, 0, 0, stream
, format
,
166 deref_ref
, recurse
+ 1, pretty
);
173 fputs_filtered ("): ", stream
);
174 val_print (elttype
, valaddr
+ i
* eltlen
, 0, 0, stream
, format
,
175 deref_ref
, recurse
+ 1, pretty
);
180 annotate_array_section_end ();
183 fprintf_filtered (stream
, "...");
187 /* Print data of type TYPE located at VALADDR (within GDB), which came from
188 the inferior at address ADDRESS, onto stdio stream STREAM according to
189 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
192 If the data are a string pointer, returns the number of string characters
195 If DEREF_REF is nonzero, then dereference references, otherwise just print
198 The PRETTY parameter controls prettyprinting. */
201 chill_val_print (type
, valaddr
, embedded_offset
, address
,
202 stream
, format
, deref_ref
, recurse
, pretty
)
211 enum val_prettyprint pretty
;
214 unsigned int i
= 0; /* Number of characters printed. */
215 struct type
*elttype
;
218 CHECK_TYPEDEF (type
);
220 switch (TYPE_CODE (type
))
222 case TYPE_CODE_ARRAY
:
223 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
225 if (prettyprint_arrays
)
227 print_spaces_filtered (2 + 2 * recurse
, stream
);
229 fprintf_filtered (stream
, "[");
230 chill_val_print_array_elements (type
, valaddr
, address
, stream
,
231 format
, deref_ref
, recurse
, pretty
);
232 fprintf_filtered (stream
, "]");
236 error ("unimplemented in chill_val_print; unspecified array length");
241 format
= format
? format
: output_format
;
244 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
248 val_print_type_code_int (type
, valaddr
, stream
);
253 format
= format
? format
: output_format
;
256 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
260 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
268 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
272 print_floating (valaddr
, type
, stream
);
277 format
= format
? format
: output_format
;
280 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
284 /* FIXME: Why is this using builtin_type_chill_bool not type? */
285 val
= unpack_long (builtin_type_chill_bool
, valaddr
);
286 fprintf_filtered (stream
, val
? "TRUE" : "FALSE");
290 case TYPE_CODE_UNDEF
:
291 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
292 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
293 and no complete type for struct foo in that file. */
294 fprintf_filtered (stream
, "<incomplete type>");
298 if (format
&& format
!= 's')
300 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
303 addr
= unpack_pointer (type
, valaddr
);
304 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
306 /* We assume a NULL pointer is all zeros ... */
309 fputs_filtered ("NULL", stream
);
313 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
315 /* Try to print what function it points to. */
316 print_address_demangle (addr
, stream
, demangle
);
317 /* Return value is irrelevant except for string pointers. */
320 if (addressprint
&& format
!= 's')
322 print_address_numeric (addr
, 1, stream
);
325 /* For a pointer to char or unsigned char, also print the string
326 pointed to, unless pointer is null. */
327 if (TYPE_LENGTH (elttype
) == 1
328 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
329 && (format
== 0 || format
== 's')
331 && /* If print_max is UINT_MAX, the alloca below will fail.
332 In that case don't try to print the string. */
333 print_max
< UINT_MAX
)
334 i
= val_print_string (addr
, -1, TYPE_LENGTH (elttype
), stream
);
336 /* Return number of characters printed, plus one for the
337 terminating null if we have "reached the end". */
338 return (i
+ (print_max
&& i
!= print_max
));
341 case TYPE_CODE_STRING
:
342 i
= TYPE_LENGTH (type
);
343 LA_PRINT_STRING (stream
, valaddr
, i
, 1, 0);
344 /* Return number of characters printed, plus one for the terminating
345 null if we have "reached the end". */
346 return (i
+ (print_max
&& i
!= print_max
));
349 case TYPE_CODE_BITSTRING
:
351 elttype
= TYPE_INDEX_TYPE (type
);
352 CHECK_TYPEDEF (elttype
);
353 if (TYPE_FLAGS (elttype
) & TYPE_FLAG_STUB
)
355 fprintf_filtered (stream
, "<incomplete type>");
360 struct type
*range
= elttype
;
361 LONGEST low_bound
, high_bound
;
363 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
367 fputs_filtered ("B'", stream
);
369 fputs_filtered ("[", stream
);
371 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
375 fputs_filtered ("<error value>", stream
);
379 for (i
= low_bound
; i
<= high_bound
; i
++)
381 int element
= value_bit_index (type
, valaddr
, i
);
385 goto maybe_bad_bstring
;
388 fprintf_filtered (stream
, "%d", element
);
392 fputs_filtered (", ", stream
);
393 chill_print_type_scalar (range
, (LONGEST
) i
, stream
);
396 /* Look for a continuous range of true elements. */
397 if (i
+ 1 <= high_bound
&& value_bit_index (type
, valaddr
, ++i
))
399 int j
= i
; /* j is the upper bound so far of the range */
400 fputs_filtered (":", stream
);
401 while (i
+ 1 <= high_bound
402 && value_bit_index (type
, valaddr
, ++i
))
404 chill_print_type_scalar (range
, (LONGEST
) j
, stream
);
410 fputs_filtered ("'", stream
);
412 fputs_filtered ("]", stream
);
416 case TYPE_CODE_STRUCT
:
417 if (chill_varying_type (type
))
419 struct type
*inner
= check_typedef (TYPE_FIELD_TYPE (type
, 1));
420 long length
= unpack_long (TYPE_FIELD_TYPE (type
, 0), valaddr
);
421 char *data_addr
= valaddr
+ TYPE_FIELD_BITPOS (type
, 1) / 8;
423 switch (TYPE_CODE (inner
))
425 case TYPE_CODE_STRING
:
426 if (length
> TYPE_LENGTH (type
) - 2)
428 fprintf_filtered (stream
,
429 "<dynamic length %ld > static length %d> *invalid*",
430 length
, TYPE_LENGTH (type
));
432 /* Don't print the string; doing so might produce a
436 LA_PRINT_STRING (stream
, data_addr
, length
, 1, 0);
442 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
449 fprintf_filtered (stream
, "LOC(");
450 print_address_numeric
451 (extract_address (valaddr
, TARGET_PTR_BIT
/ HOST_CHAR_BIT
),
454 fprintf_filtered (stream
, ")");
456 fputs_filtered (": ", stream
);
458 /* De-reference the reference. */
461 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
463 value_ptr deref_val
=
465 (TYPE_TARGET_TYPE (type
),
466 unpack_pointer (lookup_pointer_type (builtin_type_void
),
469 val_print (VALUE_TYPE (deref_val
),
470 VALUE_CONTENTS (deref_val
),
472 VALUE_ADDRESS (deref_val
), stream
, format
,
473 deref_ref
, recurse
+ 1, pretty
);
476 fputs_filtered ("???", stream
);
481 c_val_print (type
, valaddr
, 0, address
, stream
, format
,
482 deref_ref
, recurse
, pretty
);
485 case TYPE_CODE_RANGE
:
486 if (TYPE_TARGET_TYPE (type
))
487 chill_val_print (TYPE_TARGET_TYPE (type
), valaddr
, 0, address
, stream
,
488 format
, deref_ref
, recurse
, pretty
);
491 case TYPE_CODE_MEMBER
:
492 case TYPE_CODE_UNION
:
495 case TYPE_CODE_ERROR
:
497 /* Let's defer printing to the C printer, rather than
498 print an error message. FIXME! */
499 c_val_print (type
, valaddr
, 0, address
, stream
, format
,
500 deref_ref
, recurse
, pretty
);
506 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
507 print out a structure's fields: cp_print_value_fields and cplus_print_value.
509 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
510 same meanings as in cplus_print_value and c_val_print.
512 DONT_PRINT is an array of baseclass types that we
513 should not print, or zero if called from top level. */
516 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
523 enum val_prettyprint pretty
;
524 struct type
**dont_print
;
529 CHECK_TYPEDEF (type
);
531 fprintf_filtered (stream
, "[");
532 len
= TYPE_NFIELDS (type
);
535 fprintf_filtered (stream
, "<No data fields>");
539 for (i
= 0; i
< len
; i
++)
543 fprintf_filtered (stream
, ", ");
548 fprintf_filtered (stream
, "\n");
549 print_spaces_filtered (2 + 2 * recurse
, stream
);
553 wrap_here (n_spaces (2 + 2 * recurse
));
555 fputs_filtered (".", stream
);
556 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
557 language_chill
, DMGL_NO_OPTS
);
558 fputs_filtered (": ", stream
);
559 if (TYPE_FIELD_PACKED (type
, i
))
563 /* Bitfields require special handling, especially due to byte
565 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
566 unpack_field_as_long (type
, valaddr
, i
));
568 chill_val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0, 0,
569 stream
, format
, 0, recurse
+ 1, pretty
);
573 chill_val_print (TYPE_FIELD_TYPE (type
, i
),
574 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8, 0,
575 0, stream
, format
, 0, recurse
+ 1, pretty
);
580 fprintf_filtered (stream
, "\n");
581 print_spaces_filtered (2 * recurse
, stream
);
584 fprintf_filtered (stream
, "]");
588 chill_value_print (val
, stream
, format
, pretty
)
592 enum val_prettyprint pretty
;
594 struct type
*type
= VALUE_TYPE (val
);
595 struct type
*real_type
= check_typedef (type
);
597 /* If it is a pointer, indicate what it points to.
599 Print type also if it is a reference. */
601 if (TYPE_CODE (real_type
) == TYPE_CODE_PTR
||
602 TYPE_CODE (real_type
) == TYPE_CODE_REF
)
604 char *valaddr
= VALUE_CONTENTS (val
);
605 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
606 if (TYPE_CODE (type
) != TYPE_CODE_PTR
|| addr
!= 0)
609 char *name
= TYPE_NAME (type
);
611 fputs_filtered (name
, stream
);
612 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_VOID
)
613 fputs_filtered ("PTR", stream
);
616 fprintf_filtered (stream
, "(");
617 type_print (type
, "", stream
, -1);
618 fprintf_filtered (stream
, ")");
620 fprintf_filtered (stream
, "(");
621 i
= val_print (type
, valaddr
, 0, VALUE_ADDRESS (val
),
622 stream
, format
, 1, 0, pretty
);
623 fprintf_filtered (stream
, ")");
627 return (val_print (type
, VALUE_CONTENTS (val
), 0,
628 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));