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 int low_bound = TYPE_LOW_BOUND (range);
351 int high_bound = TYPE_HIGH_BOUND (range);
353 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
357 fputs_filtered ("B'", stream);
359 fputs_filtered ("[", stream);
360 for (i = low_bound; i <= high_bound; i++)
362 int element = value_bit_index (type, valaddr, i);
364 fprintf_filtered (stream, "%d", element);
368 fputs_filtered (", ", stream);
369 chill_print_type_scalar (range, i, stream);
372 /* Look for a continuous range of true elements. */
373 if (i+1 <= high_bound && value_bit_index (type, valaddr, ++i))
375 int j = i; /* j is the upper bound so far of the range */
376 fputs_filtered (":", stream);
377 while (i+1 <= high_bound
378 && value_bit_index (type, valaddr, ++i))
380 chill_print_type_scalar (range, j, stream);
385 fputs_filtered ("'", stream);
387 fputs_filtered ("]", stream);
391 case TYPE_CODE_STRUCT:
392 if (chill_varying_type (type))
394 struct type *inner = TYPE_FIELD_TYPE (type, 1);
395 long length = unpack_long (TYPE_FIELD_TYPE (type, 0), valaddr);
396 char *data_addr = valaddr + TYPE_FIELD_BITPOS (type, 1) / 8;
398 switch (TYPE_CODE (inner))
400 case TYPE_CODE_STRING:
401 if (length > TYPE_LENGTH (type))
403 fprintf_filtered (stream,
404 "<dynamic length %ld > static length %d>",
405 length, TYPE_LENGTH (type));
407 LA_PRINT_STRING (stream, data_addr, length, 0);
413 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
420 fprintf_filtered (stream, "LOC(");
421 print_address_numeric
422 (extract_address (valaddr, TARGET_PTR_BIT / HOST_CHAR_BIT),
425 fprintf_filtered (stream, ")");
427 fputs_filtered (": ", stream);
429 /* De-reference the reference. */
432 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
434 value_ptr deref_val =
436 (TYPE_TARGET_TYPE (type),
437 unpack_pointer (lookup_pointer_type (builtin_type_void),
439 val_print (VALUE_TYPE (deref_val),
440 VALUE_CONTENTS (deref_val),
441 VALUE_ADDRESS (deref_val), stream, format,
442 deref_ref, recurse + 1, pretty);
445 fputs_filtered ("???", stream);
450 c_val_print (type, valaddr, address, stream, format,
451 deref_ref, recurse, pretty);
454 case TYPE_CODE_RANGE:
455 if (TYPE_TARGET_TYPE (type))
456 chill_val_print (TYPE_TARGET_TYPE (type), valaddr, address, stream,
457 format, deref_ref, recurse, pretty);
460 case TYPE_CODE_MEMBER:
461 case TYPE_CODE_UNION:
464 case TYPE_CODE_ERROR:
466 /* Let's defer printing to the C printer, rather than
467 print an error message. FIXME! */
468 c_val_print (type, valaddr, address, stream, format,
469 deref_ref, recurse, pretty);
475 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
476 print out a structure's fields: cp_print_value_fields and cplus_print_value.
478 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
479 same meanings as in cplus_print_value and c_val_print.
481 DONT_PRINT is an array of baseclass types that we
482 should not print, or zero if called from top level. */
485 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
492 enum val_prettyprint pretty;
493 struct type **dont_print;
498 check_stub_type (type);
500 fprintf_filtered (stream, "[");
501 len = TYPE_NFIELDS (type);
504 fprintf_filtered (stream, "<No data fields>");
508 for (i = 0; i < len; i++)
512 fprintf_filtered (stream, ", ");
517 fprintf_filtered (stream, "\n");
518 print_spaces_filtered (2 + 2 * recurse, stream);
522 wrap_here (n_spaces (2 + 2 * recurse));
524 fputs_filtered (".", stream);
525 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
526 language_chill, DMGL_NO_OPTS);
527 fputs_filtered (": ", stream);
528 if (TYPE_FIELD_PACKED (type, i))
532 /* Bitfields require special handling, especially due to byte
534 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
535 unpack_field_as_long (type, valaddr, i));
537 chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
538 stream, format, 0, recurse + 1, pretty);
542 chill_val_print (TYPE_FIELD_TYPE (type, i),
543 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
544 0, stream, format, 0, recurse + 1, pretty);
549 fprintf_filtered (stream, "\n");
550 print_spaces_filtered (2 * recurse, stream);
553 fprintf_filtered (stream, "]");
557 chill_value_print (val, stream, format, pretty)
561 enum val_prettyprint pretty;
563 /* A "repeated" value really contains several values in a row.
564 They are made by the @ operator.
565 Print such values as if they were arrays. */
567 if (VALUE_REPEATED (val))
569 register unsigned int n = VALUE_REPETITIONS (val);
570 register unsigned int typelen = TYPE_LENGTH (VALUE_TYPE (val));
571 fprintf_filtered (stream, "[");
572 /* Print arrays of characters using string syntax. */
573 if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
575 LA_PRINT_STRING (stream, VALUE_CONTENTS (val), n, 0);
578 value_print_array_elements (val, stream, format, pretty);
580 fprintf_filtered (stream, "]");
581 return (n * typelen);
585 struct type *type = VALUE_TYPE (val);
587 /* If it is a pointer, indicate what it points to.
589 Print type also if it is a reference.
591 C++: if it is a member pointer, we will take care
592 of that when we print it. */
593 if (TYPE_CODE (type) == TYPE_CODE_PTR ||
594 TYPE_CODE (type) == TYPE_CODE_REF)
596 char *valaddr = VALUE_CONTENTS (val);
597 CORE_ADDR addr = unpack_pointer (type, valaddr);
598 if (TYPE_CODE (type) != TYPE_CODE_PTR || addr != 0)
601 char *name = TYPE_NAME (type);
603 fputs_filtered (name, stream);
604 else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
605 fputs_filtered ("PTR", stream);
608 fprintf_filtered (stream, "(");
609 type_print (type, "", stream, -1);
610 fprintf_filtered (stream, ")");
612 fprintf_filtered (stream, "(");
613 i = val_print (type, valaddr, VALUE_ADDRESS (val),
614 stream, format, 1, 0, pretty);
615 fprintf_filtered (stream, ")");
619 return (val_print (type, VALUE_CONTENTS (val),
620 VALUE_ADDRESS (val), stream, format, 1, 0, pretty));