120d8ad8709c43710f1237f3d943f0aa8e6543e7
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, Boston, MA 02111-1307, USA. */
26 #include "expression.h"
30 #include "c-lang.h" /* For c_val_print */
31 #include "typeprint.h"
36 chill_print_value_fields
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int,
37 enum val_prettyprint
, struct type
**));
40 /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
41 Used to print data from type structures in a specified type. For example,
42 array bounds may be characters or booleans in some languages, and this
43 allows the ranges to be printed in their "natural" form rather than as
44 decimal integer values. */
47 chill_print_type_scalar (type
, val
, stream
)
52 switch (TYPE_CODE (type
))
55 if (TYPE_TARGET_TYPE (type
))
57 chill_print_type_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
64 case TYPE_CODE_STRUCT
:
72 case TYPE_CODE_STRING
:
73 case TYPE_CODE_BITSTRING
:
75 case TYPE_CODE_MEMBER
:
76 case TYPE_CODE_METHOD
:
80 case TYPE_CODE_COMPLEX
:
84 print_type_scalar (type
, val
, stream
);
87 /* Print the elements of an array.
88 Similar to val_print_array_elements, but prints
89 element indexes (in Chill syntax). */
92 chill_val_print_array_elements (type
, valaddr
, address
, stream
,
93 format
, deref_ref
, recurse
, pretty
)
101 enum val_prettyprint pretty
;
104 unsigned int things_printed
= 0;
106 struct type
*elttype
;
107 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
108 struct type
*index_type
= TYPE_TARGET_TYPE (range_type
);
110 /* Position of the array element we are examining to see
111 whether it is repeated. */
113 /* Number of repetitions we have detected so far. */
115 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
117 elttype
= TYPE_TARGET_TYPE (type
);
118 eltlen
= TYPE_LENGTH (elttype
);
119 len
= TYPE_LENGTH (type
) / eltlen
;
121 annotate_array_section_begin (i
, elttype
);
123 for (; i
< len
&& things_printed
< print_max
; i
++)
127 if (prettyprint_arrays
)
129 fprintf_filtered (stream
, ",\n");
130 print_spaces_filtered (2 + 2 * recurse
, stream
);
134 fprintf_filtered (stream
, ", ");
137 wrap_here (n_spaces (2 + 2 * recurse
));
141 while ((rep1
< len
) &&
142 !memcmp (valaddr
+ i
* eltlen
, valaddr
+ rep1
* eltlen
, eltlen
))
148 fputs_filtered ("(", stream
);
149 chill_print_type_scalar (index_type
, low_bound
+ i
, stream
);
152 fputs_filtered (":", stream
);
153 chill_print_type_scalar (index_type
, low_bound
+ i
+ reps
- 1,
155 fputs_filtered ("): ", stream
);
156 val_print (elttype
, valaddr
+ i
* eltlen
, 0, stream
, format
,
157 deref_ref
, recurse
+ 1, pretty
);
164 fputs_filtered ("): ", stream
);
165 val_print (elttype
, valaddr
+ i
* eltlen
, 0, stream
, format
,
166 deref_ref
, recurse
+ 1, pretty
);
171 annotate_array_section_end ();
174 fprintf_filtered (stream
, "...");
178 /* Print data of type TYPE located at VALADDR (within GDB), which came from
179 the inferior at address ADDRESS, onto stdio stream STREAM according to
180 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
183 If the data are a string pointer, returns the number of string characters
186 If DEREF_REF is nonzero, then dereference references, otherwise just print
189 The PRETTY parameter controls prettyprinting. */
192 chill_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
,
201 enum val_prettyprint pretty
;
204 unsigned int i
= 0; /* Number of characters printed. */
205 struct type
*elttype
;
208 switch (TYPE_CODE (type
))
210 case TYPE_CODE_ARRAY
:
211 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
213 if (prettyprint_arrays
)
215 print_spaces_filtered (2 + 2 * recurse
, stream
);
217 fprintf_filtered (stream
, "[");
218 chill_val_print_array_elements (type
, valaddr
, address
, stream
,
219 format
, deref_ref
, recurse
, pretty
);
220 fprintf_filtered (stream
, "]");
224 error ("unimplemented in chill_val_print; unspecified array length");
229 format
= format
? format
: output_format
;
232 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
236 val_print_type_code_int (type
, valaddr
, stream
);
241 format
= format
? format
: output_format
;
244 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
248 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
256 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
260 print_floating (valaddr
, type
, stream
);
265 format
= format
? format
: output_format
;
268 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
272 /* FIXME: Why is this using builtin_type_chill_bool not type? */
273 val
= unpack_long (builtin_type_chill_bool
, valaddr
);
274 fprintf_filtered (stream
, val
? "TRUE" : "FALSE");
278 case TYPE_CODE_UNDEF
:
279 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
280 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
281 and no complete type for struct foo in that file. */
282 fprintf_filtered (stream
, "<incomplete type>");
286 if (format
&& format
!= 's')
288 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
291 addr
= unpack_pointer (type
, valaddr
);
292 elttype
= TYPE_TARGET_TYPE (type
);
294 /* We assume a NULL pointer is all zeros ... */
297 fputs_filtered ("NULL", stream
);
301 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
303 /* Try to print what function it points to. */
304 print_address_demangle (addr
, stream
, demangle
);
305 /* Return value is irrelevant except for string pointers. */
308 if (addressprint
&& format
!= 's')
310 print_address_numeric (addr
, 1, stream
);
313 /* For a pointer to char or unsigned char, also print the string
314 pointed to, unless pointer is null. */
315 if (TYPE_LENGTH (elttype
) == 1
316 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
317 && (format
== 0 || format
== 's')
319 && /* If print_max is UINT_MAX, the alloca below will fail.
320 In that case don't try to print the string. */
321 print_max
< UINT_MAX
)
323 i
= val_print_string (addr
, 0, stream
);
325 /* Return number of characters printed, plus one for the
326 terminating null if we have "reached the end". */
327 return (i
+ (print_max
&& i
!= print_max
));
330 case TYPE_CODE_STRING
:
331 i
= TYPE_LENGTH (type
);
332 LA_PRINT_STRING (stream
, valaddr
, i
, 0);
333 /* Return number of characters printed, plus one for the terminating
334 null if we have "reached the end". */
335 return (i
+ (print_max
&& i
!= print_max
));
338 case TYPE_CODE_BITSTRING
:
340 elttype
= TYPE_INDEX_TYPE (type
);
341 check_stub_type (elttype
);
342 if (TYPE_FLAGS (elttype
) & TYPE_FLAG_STUB
)
344 fprintf_filtered (stream
, "<incomplete type>");
349 struct type
*range
= elttype
;
350 LONGEST low_bound
, high_bound
;
352 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
356 fputs_filtered ("B'", stream
);
358 fputs_filtered ("[", stream
);
360 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
364 fputs_filtered ("<error value>", stream
);
368 for (i
= low_bound
; i
<= high_bound
; i
++)
370 int element
= value_bit_index (type
, valaddr
, i
);
374 goto maybe_bad_bstring
;
377 fprintf_filtered (stream
, "%d", element
);
381 fputs_filtered (", ", stream
);
382 chill_print_type_scalar (range
, i
, stream
);
385 /* Look for a continuous range of true elements. */
386 if (i
+1 <= high_bound
&& value_bit_index (type
, valaddr
, ++i
))
388 int j
= i
; /* j is the upper bound so far of the range */
389 fputs_filtered (":", stream
);
390 while (i
+1 <= high_bound
391 && value_bit_index (type
, valaddr
, ++i
))
393 chill_print_type_scalar (range
, j
, stream
);
399 fputs_filtered ("'", stream
);
401 fputs_filtered ("]", stream
);
405 case TYPE_CODE_STRUCT
:
406 if (chill_varying_type (type
))
408 struct type
*inner
= TYPE_FIELD_TYPE (type
, 1);
409 long length
= unpack_long (TYPE_FIELD_TYPE (type
, 0), valaddr
);
410 char *data_addr
= valaddr
+ TYPE_FIELD_BITPOS (type
, 1) / 8;
412 switch (TYPE_CODE (inner
))
414 case TYPE_CODE_STRING
:
415 if (length
> TYPE_LENGTH (type
))
417 fprintf_filtered (stream
,
418 "<dynamic length %ld > static length %d>",
419 length
, TYPE_LENGTH (type
));
421 LA_PRINT_STRING (stream
, data_addr
, length
, 0);
427 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
434 fprintf_filtered (stream
, "LOC(");
435 print_address_numeric
436 (extract_address (valaddr
, TARGET_PTR_BIT
/ HOST_CHAR_BIT
),
439 fprintf_filtered (stream
, ")");
441 fputs_filtered (": ", stream
);
443 /* De-reference the reference. */
446 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
448 value_ptr deref_val
=
450 (TYPE_TARGET_TYPE (type
),
451 unpack_pointer (lookup_pointer_type (builtin_type_void
),
453 val_print (VALUE_TYPE (deref_val
),
454 VALUE_CONTENTS (deref_val
),
455 VALUE_ADDRESS (deref_val
), stream
, format
,
456 deref_ref
, recurse
+ 1, pretty
);
459 fputs_filtered ("???", stream
);
464 c_val_print (type
, valaddr
, address
, stream
, format
,
465 deref_ref
, recurse
, pretty
);
468 case TYPE_CODE_RANGE
:
469 if (TYPE_TARGET_TYPE (type
))
470 chill_val_print (TYPE_TARGET_TYPE (type
), valaddr
, address
, stream
,
471 format
, deref_ref
, recurse
, pretty
);
474 case TYPE_CODE_MEMBER
:
475 case TYPE_CODE_UNION
:
478 case TYPE_CODE_ERROR
:
480 /* Let's defer printing to the C printer, rather than
481 print an error message. FIXME! */
482 c_val_print (type
, valaddr
, address
, stream
, format
,
483 deref_ref
, recurse
, pretty
);
489 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
490 print out a structure's fields: cp_print_value_fields and cplus_print_value.
492 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
493 same meanings as in cplus_print_value and c_val_print.
495 DONT_PRINT is an array of baseclass types that we
496 should not print, or zero if called from top level. */
499 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
506 enum val_prettyprint pretty
;
507 struct type
**dont_print
;
512 check_stub_type (type
);
514 fprintf_filtered (stream
, "[");
515 len
= TYPE_NFIELDS (type
);
518 fprintf_filtered (stream
, "<No data fields>");
522 for (i
= 0; i
< len
; i
++)
526 fprintf_filtered (stream
, ", ");
531 fprintf_filtered (stream
, "\n");
532 print_spaces_filtered (2 + 2 * recurse
, stream
);
536 wrap_here (n_spaces (2 + 2 * recurse
));
538 fputs_filtered (".", stream
);
539 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
540 language_chill
, DMGL_NO_OPTS
);
541 fputs_filtered (": ", stream
);
542 if (TYPE_FIELD_PACKED (type
, i
))
546 /* Bitfields require special handling, especially due to byte
548 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
549 unpack_field_as_long (type
, valaddr
, i
));
551 chill_val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
552 stream
, format
, 0, recurse
+ 1, pretty
);
556 chill_val_print (TYPE_FIELD_TYPE (type
, i
),
557 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
558 0, stream
, format
, 0, recurse
+ 1, pretty
);
563 fprintf_filtered (stream
, "\n");
564 print_spaces_filtered (2 * recurse
, stream
);
567 fprintf_filtered (stream
, "]");
571 chill_value_print (val
, stream
, format
, pretty
)
575 enum val_prettyprint pretty
;
577 /* A "repeated" value really contains several values in a row.
578 They are made by the @ operator.
579 Print such values as if they were arrays. */
581 if (VALUE_REPEATED (val
))
583 register unsigned int n
= VALUE_REPETITIONS (val
);
584 register unsigned int typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
585 fprintf_filtered (stream
, "[");
586 /* Print arrays of characters using string syntax. */
587 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
589 LA_PRINT_STRING (stream
, VALUE_CONTENTS (val
), n
, 0);
592 value_print_array_elements (val
, stream
, format
, pretty
);
594 fprintf_filtered (stream
, "]");
595 return (n
* typelen
);
599 struct type
*type
= VALUE_TYPE (val
);
601 /* If it is a pointer, indicate what it points to.
603 Print type also if it is a reference.
605 C++: if it is a member pointer, we will take care
606 of that when we print it. */
607 if (TYPE_CODE (type
) == TYPE_CODE_PTR
||
608 TYPE_CODE (type
) == TYPE_CODE_REF
)
610 char *valaddr
= VALUE_CONTENTS (val
);
611 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
612 if (TYPE_CODE (type
) != TYPE_CODE_PTR
|| addr
!= 0)
615 char *name
= TYPE_NAME (type
);
617 fputs_filtered (name
, stream
);
618 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_VOID
)
619 fputs_filtered ("PTR", stream
);
622 fprintf_filtered (stream
, "(");
623 type_print (type
, "", stream
, -1);
624 fprintf_filtered (stream
, ")");
626 fprintf_filtered (stream
, "(");
627 i
= val_print (type
, valaddr
, VALUE_ADDRESS (val
),
628 stream
, format
, 1, 0, pretty
);
629 fprintf_filtered (stream
, ")");
633 return (val_print (type
, VALUE_CONTENTS (val
),
634 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));