1 /* Support for printing Ada values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001,
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "gdb_string.h"
27 #include "expression.h"
37 /* Encapsulates arguments to ada_val_print. */
38 struct ada_val_print_args
44 struct ui_file *stream;
48 enum val_prettyprint pretty;
51 static void print_record (struct type *, char *, struct ui_file *, int,
52 int, enum val_prettyprint);
54 static int print_field_values (struct type *, char *, struct ui_file *,
55 int, int, enum val_prettyprint,
56 int, struct type *, char *);
58 static int print_variant_part (struct type *, int, char *,
59 struct ui_file *, int, int,
60 enum val_prettyprint, int, struct type *,
63 static void val_print_packed_array_elements (struct type *, char *valaddr,
64 int, struct ui_file *, int, int,
65 enum val_prettyprint);
67 static void adjust_type_signedness (struct type *);
69 static int ada_val_print_stub (void *args0);
71 static int ada_val_print_1 (struct type *, char *, int, CORE_ADDR,
72 struct ui_file *, int, int, int,
73 enum val_prettyprint);
74 static void ada_print_floating (char *, struct type *, struct ui_file *);
77 /* Make TYPE unsigned if its range of values includes no negatives. */
79 adjust_type_signedness (struct type *type)
81 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
82 && TYPE_LOW_BOUND (type) >= 0)
83 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
86 /* Assuming TYPE is a simple, non-empty array type, prints its lower bound
87 on STREAM, if non-standard (i.e., other than 1 for numbers, other
88 than lower bound of index type for enumerated type). Returns 1
89 if something printed, otherwise 0. */
92 print_optional_low_bound (struct ui_file *stream, struct type *type)
94 struct type *index_type;
97 index_type = TYPE_INDEX_TYPE (type);
100 if (index_type == NULL)
102 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
104 low_bound = TYPE_LOW_BOUND (index_type);
105 if (low_bound > TYPE_HIGH_BOUND (index_type))
107 index_type = TYPE_TARGET_TYPE (index_type);
112 switch (TYPE_CODE (index_type))
115 if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
118 case TYPE_CODE_UNDEF:
119 index_type = builtin_type_long;
127 ada_print_scalar (index_type, (LONGEST) low_bound, stream);
128 fprintf_filtered (stream, " => ");
132 /* Version of val_print_array_elements for GNAT-style packed arrays.
133 Prints elements of packed array of type TYPE at bit offset
134 BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and
135 separates with commas. RECURSE is the recursion (nesting) level.
136 If PRETTY, uses "prettier" format. TYPE must have been decoded (as
137 by ada_coerce_to_simple_array). */
140 val_print_packed_array_elements (struct type *type, char *valaddr,
141 int bitoffset, struct ui_file *stream,
142 int format, int recurse,
143 enum val_prettyprint pretty)
146 unsigned int things_printed = 0;
148 struct type *elttype;
150 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
151 struct value *mark = value_mark ();
153 elttype = TYPE_TARGET_TYPE (type);
154 eltlen = TYPE_LENGTH (check_typedef (elttype));
158 if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0)
161 len = high - low + 1;
165 annotate_array_section_begin (i, elttype);
167 while (i < len && things_printed < print_max)
169 struct value *v0, *v1;
174 if (prettyprint_arrays)
176 fprintf_filtered (stream, ",\n");
177 print_spaces_filtered (2 + 2 * recurse, stream);
181 fprintf_filtered (stream, ", ");
184 wrap_here (n_spaces (2 + 2 * recurse));
187 v0 = ada_value_primitive_packed_val (NULL, valaddr,
188 (i0 * bitsize) / HOST_CHAR_BIT,
189 (i0 * bitsize) % HOST_CHAR_BIT,
196 v1 = ada_value_primitive_packed_val (NULL, valaddr,
197 (i * bitsize) / HOST_CHAR_BIT,
198 (i * bitsize) % HOST_CHAR_BIT,
200 if (memcmp (VALUE_CONTENTS (v0), VALUE_CONTENTS (v1), eltlen) != 0)
204 if (i - i0 > repeat_count_threshold)
206 val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format,
207 0, recurse + 1, pretty);
208 annotate_elt_rep (i - i0);
209 fprintf_filtered (stream, " <repeats %u times>", i - i0);
210 annotate_elt_rep_end ();
216 for (j = i0; j < i; j += 1)
220 if (prettyprint_arrays)
222 fprintf_filtered (stream, ",\n");
223 print_spaces_filtered (2 + 2 * recurse, stream);
227 fprintf_filtered (stream, ", ");
229 wrap_here (n_spaces (2 + 2 * recurse));
231 val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format,
232 0, recurse + 1, pretty);
236 things_printed += i - i0;
238 annotate_array_section_end ();
241 fprintf_filtered (stream, "...");
244 value_free_to_mark (mark);
248 printable_val_type (struct type *type, char *valaddr)
250 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL);
253 /* Print the character C on STREAM as part of the contents of a literal
254 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
255 (1 or 2) of the character. */
258 ada_emit_char (int c, struct ui_file *stream, int quoter, int type_len)
263 c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1;
265 if (isascii (c) && isprint (c))
267 if (c == quoter && c == '"')
268 fprintf_filtered (stream, "[\"%c\"]", quoter);
270 fprintf_filtered (stream, "%c", c);
273 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
276 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
277 or 2) of a character. */
280 char_at (char *string, int i, int type_len)
285 return (int) extract_unsigned_integer (string + 2 * i, 2);
288 /* Wrapper around memcpy to make it legal argument to ui_file_put */
290 ui_memcpy (void *dest, const char *buffer, long len)
292 memcpy (dest, buffer, (size_t) len);
293 ((char *) dest)[len] = '\0';
296 /* Print a floating-point value of type TYPE, pointed to in GDB by
297 VALADDR, on STREAM. Use Ada formatting conventions: there must be
298 a decimal point, and at least one digit before and after the
299 point. We use GNAT format for NaNs and infinities. */
301 ada_print_floating (char *valaddr, struct type *type, struct ui_file *stream)
306 struct ui_file *tmp_stream = mem_fileopen ();
307 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
309 print_floating (valaddr, type, tmp_stream);
310 ui_file_put (tmp_stream, ui_memcpy, buffer);
311 do_cleanups (cleanups);
314 len = strlen (result);
316 /* Modify for Ada rules. */
318 s = strstr (result, "inf");
320 s = strstr (result, "Inf");
322 s = strstr (result, "INF");
328 s = strstr (result, "nan");
330 s = strstr (result, "NaN");
332 s = strstr (result, "Nan");
336 if (result[0] == '-')
341 if (s == NULL && strchr (result, '.') == NULL)
343 s = strchr (result, 'e');
345 fprintf_filtered (stream, "%s.0", result);
347 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
350 fprintf_filtered (stream, "%s", result);
354 ada_printchar (int c, struct ui_file *stream)
356 fputs_filtered ("'", stream);
357 ada_emit_char (c, stream, '\'', 1);
358 fputs_filtered ("'", stream);
361 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
362 form appropriate for TYPE. */
365 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
370 type = ada_check_typedef (type);
372 switch (TYPE_CODE (type))
376 len = TYPE_NFIELDS (type);
377 for (i = 0; i < len; i++)
379 if (TYPE_FIELD_BITPOS (type, i) == val)
386 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
390 print_longest (stream, 'd', 0, val);
395 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
399 LA_PRINT_CHAR ((unsigned char) val, stream);
403 fprintf_filtered (stream, val ? "true" : "false");
406 case TYPE_CODE_RANGE:
407 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
410 case TYPE_CODE_UNDEF:
412 case TYPE_CODE_ARRAY:
413 case TYPE_CODE_STRUCT:
414 case TYPE_CODE_UNION:
419 case TYPE_CODE_STRING:
420 case TYPE_CODE_ERROR:
421 case TYPE_CODE_MEMBER:
422 case TYPE_CODE_METHOD:
424 warning ("internal error: unhandled type in ada_print_scalar");
428 error ("Invalid type code in symbol table.");
433 /* Print the character string STRING, printing at most LENGTH characters.
434 Printing stops early if the number hits print_max; repeat counts
435 are printed as appropriate. Print ellipses at the end if we
436 had to stop before printing LENGTH characters, or if
437 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
441 printstr (struct ui_file *stream, char *string, unsigned int length,
442 int force_ellipses, int type_len)
445 unsigned int things_printed = 0;
451 fputs_filtered ("\"\"", stream);
455 for (i = 0; i < length && things_printed < print_max; i += 1)
457 /* Position of the character we are examining
458 to see whether it is repeated. */
460 /* Number of repetitions we have detected so far. */
467 fputs_filtered (", ", stream);
474 && char_at (string, rep1, type_len) == char_at (string, i,
481 if (reps > repeat_count_threshold)
486 fputs_filtered ("\\\", ", stream);
488 fputs_filtered ("\", ", stream);
491 fputs_filtered ("'", stream);
492 ada_emit_char (char_at (string, i, type_len), stream, '\'',
494 fputs_filtered ("'", stream);
495 fprintf_filtered (stream, " <repeats %u times>", reps);
497 things_printed += repeat_count_threshold;
505 fputs_filtered ("\\\"", stream);
507 fputs_filtered ("\"", stream);
510 ada_emit_char (char_at (string, i, type_len), stream, '"',
516 /* Terminate the quotes if necessary. */
520 fputs_filtered ("\\\"", stream);
522 fputs_filtered ("\"", stream);
525 if (force_ellipses || i < length)
526 fputs_filtered ("...", stream);
530 ada_printstr (struct ui_file *stream, char *string, unsigned int length,
531 int width, int force_ellipses)
533 printstr (stream, string, length, force_ellipses, width);
537 /* Print data of type TYPE located at VALADDR (within GDB), which came from
538 the inferior at address ADDRESS, onto stdio stream STREAM according to
539 FORMAT (a letter as for the printf % codes or 0 for natural format).
540 The data at VALADDR is in target byte order.
542 If the data is printed as a string, returns the number of string characters
545 If DEREF_REF is nonzero, then dereference references, otherwise just print
548 RECURSE indicates the amount of indentation to supply before
549 continuation lines; this amount is roughly twice the value of RECURSE.
551 When PRETTY is non-zero, prints record fields on separate lines.
552 (For some reason, the current version of gdb instead uses a global
553 variable---prettyprint_arrays--- to causes a similar effect on
557 ada_val_print (struct type *type, char *valaddr0, int embedded_offset,
558 CORE_ADDR address, struct ui_file *stream, int format,
559 int deref_ref, int recurse, enum val_prettyprint pretty)
561 struct ada_val_print_args args;
563 args.valaddr0 = valaddr0;
564 args.embedded_offset = embedded_offset;
565 args.address = address;
566 args.stream = stream;
567 args.format = format;
568 args.deref_ref = deref_ref;
569 args.recurse = recurse;
570 args.pretty = pretty;
572 return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL);
575 /* Helper for ada_val_print; used as argument to catch_errors to
576 unmarshal the arguments to ada_val_print_1, which does the work. */
578 ada_val_print_stub (void *args0)
580 struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0;
581 return ada_val_print_1 (argsp->type, argsp->valaddr0,
582 argsp->embedded_offset, argsp->address,
583 argsp->stream, argsp->format, argsp->deref_ref,
584 argsp->recurse, argsp->pretty);
587 /* See the comment on ada_val_print. This function differs in that it
588 * does not catch evaluation errors (leaving that to ada_val_print). */
591 ada_val_print_1 (struct type *type, char *valaddr0, int embedded_offset,
592 CORE_ADDR address, struct ui_file *stream, int format,
593 int deref_ref, int recurse, enum val_prettyprint pretty)
597 struct type *elttype;
600 char *valaddr = valaddr0 + embedded_offset;
602 type = ada_check_typedef (type);
604 if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type))
607 struct value *mark = value_mark ();
609 val = value_from_contents_and_address (type, valaddr, address);
610 val = ada_coerce_to_simple_array_ptr (val);
613 fprintf_filtered (stream, "(null)");
617 retn = ada_val_print_1 (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
618 VALUE_ADDRESS (val), stream, format,
619 deref_ref, recurse, pretty);
620 value_free_to_mark (mark);
624 valaddr = ada_aligned_value_addr (type, valaddr);
625 embedded_offset -= valaddr - valaddr0 - embedded_offset;
626 type = printable_val_type (type, valaddr);
628 switch (TYPE_CODE (type))
631 return c_val_print (type, valaddr0, embedded_offset, address, stream,
632 format, deref_ref, recurse, pretty);
636 int ret = c_val_print (type, valaddr0, embedded_offset, address,
637 stream, format, deref_ref, recurse, pretty);
638 if (ada_is_tag_type (type))
641 value_from_contents_and_address (type, valaddr, address);
642 const char *name = ada_tag_name (val);
644 fprintf_filtered (stream, " (%s)", name);
651 case TYPE_CODE_RANGE:
652 if (ada_is_fixed_point_type (type))
654 LONGEST v = unpack_long (type, valaddr);
655 int len = TYPE_LENGTH (type);
657 fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
658 (double) ada_fixed_to_float (type, v));
661 else if (ada_is_vax_floating_type (type))
664 value_from_contents_and_address (type, valaddr, address);
665 struct value *func = ada_vax_float_print_function (type);
668 static struct type *parray_of_char = NULL;
669 struct value *printable_val;
671 if (parray_of_char == NULL)
675 (NULL, builtin_type_char,
676 create_range_type (NULL, builtin_type_int, 0, 32)), NULL);
679 value_ind (value_cast (parray_of_char,
680 call_function_by_hand (func, 1,
683 fprintf_filtered (stream, "%s", VALUE_CONTENTS (printable_val));
686 /* No special printing function. Do as best we can. */
688 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
690 struct type *target_type = TYPE_TARGET_TYPE (type);
691 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
693 /* Obscure case of range type that has different length from
694 its base type. Perform a conversion, or we will get a
695 nonsense value. Actually, we could use the same
696 code regardless of lengths; I'm just avoiding a cast. */
697 struct value *v = value_cast (target_type,
698 value_from_contents_and_address
700 return ada_val_print_1 (target_type, VALUE_CONTENTS (v), 0, 0,
701 stream, format, 0, recurse + 1, pretty);
704 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
705 valaddr0, embedded_offset,
706 address, stream, format, deref_ref,
711 format = format ? format : output_format;
714 print_scalar_formatted (valaddr, type, format, 0, stream);
716 else if (ada_is_system_address_type (type))
718 /* FIXME: We want to print System.Address variables using
719 the same format as for any access type. But for some
720 reason GNAT encodes the System.Address type as an int,
721 so we have to work-around this deficiency by handling
722 System.Address values as a special case. */
723 fprintf_filtered (stream, "(");
724 type_print (type, "", stream, -1);
725 fprintf_filtered (stream, ") ");
726 print_address_numeric
727 (extract_typed_address (valaddr, builtin_type_void_data_ptr),
732 val_print_type_code_int (type, valaddr, stream);
733 if (ada_is_character_type (type))
735 fputs_filtered (" ", stream);
736 ada_printchar ((unsigned char) unpack_long (type, valaddr),
746 print_scalar_formatted (valaddr, type, format, 0, stream);
749 len = TYPE_NFIELDS (type);
750 val = unpack_long (type, valaddr);
751 for (i = 0; i < len; i++)
754 if (val == TYPE_FIELD_BITPOS (type, i))
761 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
763 fprintf_filtered (stream, "%ld %s", (long) val, name);
765 fputs_filtered (name, stream);
769 print_longest (stream, 'd', 0, val);
775 return c_val_print (type, valaddr0, embedded_offset, address, stream,
776 format, deref_ref, recurse, pretty);
778 ada_print_floating (valaddr0 + embedded_offset, type, stream);
781 case TYPE_CODE_UNION:
782 case TYPE_CODE_STRUCT:
783 if (ada_is_bogus_array_descriptor (type))
785 fprintf_filtered (stream, "(...?)");
790 print_record (type, valaddr, stream, format, recurse, pretty);
794 case TYPE_CODE_ARRAY:
795 elttype = TYPE_TARGET_TYPE (type);
799 eltlen = TYPE_LENGTH (elttype);
800 /* FIXME: This doesn't deal with non-empty arrays of
801 0-length items (not a typical case!) */
805 len = TYPE_LENGTH (type) / eltlen;
807 /* For an array of chars, print with string syntax. */
808 if (ada_is_string_type (type) && (format == 0 || format == 's'))
810 if (prettyprint_arrays)
812 print_spaces_filtered (2 + 2 * recurse, stream);
814 /* If requested, look for the first null char and only print
815 elements up to it. */
816 if (stop_print_at_null)
820 /* Look for a NULL char. */
822 temp_len < len && temp_len < print_max
823 && char_at (valaddr, temp_len, eltlen) != 0;
828 printstr (stream, valaddr, len, 0, eltlen);
833 fprintf_filtered (stream, "(");
834 print_optional_low_bound (stream, type);
835 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
836 val_print_packed_array_elements (type, valaddr, 0, stream,
837 format, recurse, pretty);
839 val_print_array_elements (type, valaddr, address, stream,
840 format, deref_ref, recurse,
842 fprintf_filtered (stream, ")");
848 elttype = check_typedef (TYPE_TARGET_TYPE (type));
849 /* De-reference the reference */
852 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
854 LONGEST deref_val_int = (LONGEST)
855 unpack_pointer (lookup_pointer_type (builtin_type_void),
857 if (deref_val_int != 0)
859 struct value *deref_val =
860 ada_value_ind (value_from_longest
861 (lookup_pointer_type (elttype),
863 val_print (VALUE_TYPE (deref_val),
864 VALUE_CONTENTS (deref_val), 0,
865 VALUE_ADDRESS (deref_val), stream, format,
866 deref_ref, recurse + 1, pretty);
869 fputs_filtered ("(null)", stream);
872 fputs_filtered ("???", stream);
881 print_variant_part (struct type *type, int field_num, char *valaddr,
882 struct ui_file *stream, int format, int recurse,
883 enum val_prettyprint pretty, int comma_needed,
884 struct type *outer_type, char *outer_valaddr)
886 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
887 int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr);
892 return print_field_values
893 (TYPE_FIELD_TYPE (var_type, which),
894 valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
895 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
896 stream, format, recurse, pretty,
897 comma_needed, outer_type, outer_valaddr);
901 ada_value_print (struct value *val0, struct ui_file *stream, int format,
902 enum val_prettyprint pretty)
904 char *valaddr = VALUE_CONTENTS (val0);
905 CORE_ADDR address = VALUE_ADDRESS (val0) + VALUE_OFFSET (val0);
907 ada_to_fixed_type (VALUE_TYPE (val0), valaddr, address, NULL);
909 value_from_contents_and_address (type, valaddr, address);
911 /* If it is a pointer, indicate what it points to. */
912 if (TYPE_CODE (type) == TYPE_CODE_PTR)
914 /* Hack: don't print (char *) for char strings. Their
915 type is indicated by the quoted string anyway. */
916 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
917 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
918 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
920 fprintf_filtered (stream, "(");
921 type_print (type, "", stream, -1);
922 fprintf_filtered (stream, ") ");
925 else if (ada_is_array_descriptor_type (type))
927 fprintf_filtered (stream, "(");
928 type_print (type, "", stream, -1);
929 fprintf_filtered (stream, ") ");
931 else if (ada_is_bogus_array_descriptor (type))
933 fprintf_filtered (stream, "(");
934 type_print (type, "", stream, -1);
935 fprintf_filtered (stream, ") (...?)");
939 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
940 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == 0
941 && TYPE_CODE (TYPE_INDEX_TYPE (type)) == TYPE_CODE_RANGE)
943 /* This is an array of zero-length elements, that is an array
944 of null records. This array needs to be printed by hand,
945 as the standard routine to print arrays relies on the size of
946 the array elements to be nonzero. This is because it computes
947 the number of elements in the array by dividing the array size
948 by the array element size. */
949 fprintf_filtered (stream, "(%d .. %d => ())",
950 TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
951 TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type)));
955 return (val_print (type, VALUE_CONTENTS (val), 0, address,
956 stream, format, 1, 0, pretty));
960 print_record (struct type *type, char *valaddr, struct ui_file *stream,
961 int format, int recurse, enum val_prettyprint pretty)
963 type = ada_check_typedef (type);
965 fprintf_filtered (stream, "(");
967 if (print_field_values (type, valaddr, stream, format, recurse, pretty,
968 0, type, valaddr) != 0 && pretty)
970 fprintf_filtered (stream, "\n");
971 print_spaces_filtered (2 * recurse, stream);
974 fprintf_filtered (stream, ")");
977 /* Print out fields of value at VALADDR having structure type TYPE.
979 TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the
980 same meanings as in ada_print_value and ada_val_print.
982 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
983 (used to get discriminant values when printing variant parts).
985 COMMA_NEEDED is 1 if fields have been printed at the current recursion
986 level, so that a comma is needed before any field printed by this
989 Returns 1 if COMMA_NEEDED or any fields were printed. */
992 print_field_values (struct type *type, char *valaddr, struct ui_file *stream,
993 int format, int recurse, enum val_prettyprint pretty,
994 int comma_needed, struct type *outer_type,
999 len = TYPE_NFIELDS (type);
1001 for (i = 0; i < len; i += 1)
1003 if (ada_is_ignored_field (type, i))
1006 if (ada_is_wrapper_field (type, i))
1009 print_field_values (TYPE_FIELD_TYPE (type, i),
1011 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1012 stream, format, recurse, pretty,
1013 comma_needed, type, valaddr);
1016 else if (ada_is_variant_part (type, i))
1019 print_variant_part (type, i, valaddr,
1020 stream, format, recurse, pretty, comma_needed,
1021 outer_type, outer_valaddr);
1026 fprintf_filtered (stream, ", ");
1031 fprintf_filtered (stream, "\n");
1032 print_spaces_filtered (2 + 2 * recurse, stream);
1036 wrap_here (n_spaces (2 + 2 * recurse));
1040 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1041 fputs_filtered ("\"( ptr \"", stream);
1043 fputs_filtered ("\"( nodef \"", stream);
1044 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1045 language_cplus, DMGL_NO_OPTS);
1046 fputs_filtered ("\" \"", stream);
1047 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1048 language_cplus, DMGL_NO_OPTS);
1049 fputs_filtered ("\") \"", stream);
1053 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1054 fprintf_filtered (stream, "%.*s",
1055 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1056 TYPE_FIELD_NAME (type, i));
1057 annotate_field_name_end ();
1058 fputs_filtered (" => ", stream);
1059 annotate_field_value ();
1062 if (TYPE_FIELD_PACKED (type, i))
1066 /* Bitfields require special handling, especially due to byte
1068 if (TYPE_CPLUS_SPECIFIC (type) != NULL
1069 && TYPE_FIELD_IGNORE (type, i))
1071 fputs_filtered ("<optimized out or zero length>", stream);
1075 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1076 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1078 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1079 v = ada_value_primitive_packed_val (NULL, valaddr,
1080 bit_pos / HOST_CHAR_BIT,
1081 bit_pos % HOST_CHAR_BIT,
1083 TYPE_FIELD_TYPE (type, i));
1084 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0,
1085 stream, format, 0, recurse + 1, pretty);
1089 ada_val_print (TYPE_FIELD_TYPE (type, i),
1090 valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1091 0, 0, stream, format, 0, recurse + 1, pretty);
1092 annotate_field_end ();
1095 return comma_needed;