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"
36 #include "exceptions.h"
38 /* Encapsulates arguments to ada_val_print. */
39 struct ada_val_print_args
45 struct ui_file *stream;
49 enum val_prettyprint pretty;
52 static void print_record (struct type *, char *, struct ui_file *, int,
53 int, enum val_prettyprint);
55 static int print_field_values (struct type *, char *, struct ui_file *,
56 int, int, enum val_prettyprint,
57 int, struct type *, char *);
59 static int print_variant_part (struct type *, int, char *,
60 struct ui_file *, int, int,
61 enum val_prettyprint, int, struct type *,
64 static void val_print_packed_array_elements (struct type *, char *valaddr,
65 int, struct ui_file *, int, int,
66 enum val_prettyprint);
68 static void adjust_type_signedness (struct type *);
70 static int ada_val_print_stub (void *args0);
72 static int ada_val_print_1 (struct type *, char *, int, CORE_ADDR,
73 struct ui_file *, int, int, int,
74 enum val_prettyprint);
75 static void ada_print_floating (char *, struct type *, struct ui_file *);
78 /* Make TYPE unsigned if its range of values includes no negatives. */
80 adjust_type_signedness (struct type *type)
82 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
83 && TYPE_LOW_BOUND (type) >= 0)
84 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
87 /* Assuming TYPE is a simple, non-empty array type, prints its lower bound
88 on STREAM, if non-standard (i.e., other than 1 for numbers, other
89 than lower bound of index type for enumerated type). Returns 1
90 if something printed, otherwise 0. */
93 print_optional_low_bound (struct ui_file *stream, struct type *type)
95 struct type *index_type;
98 index_type = TYPE_INDEX_TYPE (type);
101 if (index_type == NULL)
103 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
105 low_bound = TYPE_LOW_BOUND (index_type);
106 if (low_bound > TYPE_HIGH_BOUND (index_type))
108 index_type = TYPE_TARGET_TYPE (index_type);
113 switch (TYPE_CODE (index_type))
116 if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
119 case TYPE_CODE_UNDEF:
120 index_type = builtin_type_long;
128 ada_print_scalar (index_type, (LONGEST) low_bound, stream);
129 fprintf_filtered (stream, " => ");
133 /* Version of val_print_array_elements for GNAT-style packed arrays.
134 Prints elements of packed array of type TYPE at bit offset
135 BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and
136 separates with commas. RECURSE is the recursion (nesting) level.
137 If PRETTY, uses "prettier" format. TYPE must have been decoded (as
138 by ada_coerce_to_simple_array). */
141 val_print_packed_array_elements (struct type *type, char *valaddr,
142 int bitoffset, struct ui_file *stream,
143 int format, int recurse,
144 enum val_prettyprint pretty)
147 unsigned int things_printed = 0;
149 struct type *elttype;
151 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
152 struct value *mark = value_mark ();
154 elttype = TYPE_TARGET_TYPE (type);
155 eltlen = TYPE_LENGTH (check_typedef (elttype));
159 if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0)
162 len = high - low + 1;
166 annotate_array_section_begin (i, elttype);
168 while (i < len && things_printed < print_max)
170 struct value *v0, *v1;
175 if (prettyprint_arrays)
177 fprintf_filtered (stream, ",\n");
178 print_spaces_filtered (2 + 2 * recurse, stream);
182 fprintf_filtered (stream, ", ");
185 wrap_here (n_spaces (2 + 2 * recurse));
188 v0 = ada_value_primitive_packed_val (NULL, valaddr,
189 (i0 * bitsize) / HOST_CHAR_BIT,
190 (i0 * bitsize) % HOST_CHAR_BIT,
197 v1 = ada_value_primitive_packed_val (NULL, valaddr,
198 (i * bitsize) / HOST_CHAR_BIT,
199 (i * bitsize) % HOST_CHAR_BIT,
201 if (memcmp (VALUE_CONTENTS (v0), VALUE_CONTENTS (v1), eltlen) != 0)
205 if (i - i0 > repeat_count_threshold)
207 val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format,
208 0, recurse + 1, pretty);
209 annotate_elt_rep (i - i0);
210 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
211 annotate_elt_rep_end ();
217 for (j = i0; j < i; j += 1)
221 if (prettyprint_arrays)
223 fprintf_filtered (stream, ",\n");
224 print_spaces_filtered (2 + 2 * recurse, stream);
228 fprintf_filtered (stream, ", ");
230 wrap_here (n_spaces (2 + 2 * recurse));
232 val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format,
233 0, recurse + 1, pretty);
237 things_printed += i - i0;
239 annotate_array_section_end ();
242 fprintf_filtered (stream, "...");
245 value_free_to_mark (mark);
249 printable_val_type (struct type *type, char *valaddr)
251 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL);
254 /* Print the character C on STREAM as part of the contents of a literal
255 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
256 (1 or 2) of the character. */
259 ada_emit_char (int c, struct ui_file *stream, int quoter, int type_len)
264 c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1;
266 if (isascii (c) && isprint (c))
268 if (c == quoter && c == '"')
269 fprintf_filtered (stream, "[\"%c\"]", quoter);
271 fprintf_filtered (stream, "%c", c);
274 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
277 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
278 or 2) of a character. */
281 char_at (char *string, int i, int type_len)
286 return (int) extract_unsigned_integer (string + 2 * i, 2);
289 /* Wrapper around memcpy to make it legal argument to ui_file_put */
291 ui_memcpy (void *dest, const char *buffer, long len)
293 memcpy (dest, buffer, (size_t) len);
294 ((char *) dest)[len] = '\0';
297 /* Print a floating-point value of type TYPE, pointed to in GDB by
298 VALADDR, on STREAM. Use Ada formatting conventions: there must be
299 a decimal point, and at least one digit before and after the
300 point. We use GNAT format for NaNs and infinities. */
302 ada_print_floating (char *valaddr, struct type *type, struct ui_file *stream)
307 struct ui_file *tmp_stream = mem_fileopen ();
308 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
310 print_floating (valaddr, type, tmp_stream);
311 ui_file_put (tmp_stream, ui_memcpy, buffer);
312 do_cleanups (cleanups);
315 len = strlen (result);
317 /* Modify for Ada rules. */
319 s = strstr (result, "inf");
321 s = strstr (result, "Inf");
323 s = strstr (result, "INF");
329 s = strstr (result, "nan");
331 s = strstr (result, "NaN");
333 s = strstr (result, "Nan");
337 if (result[0] == '-')
342 if (s == NULL && strchr (result, '.') == NULL)
344 s = strchr (result, 'e');
346 fprintf_filtered (stream, "%s.0", result);
348 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
351 fprintf_filtered (stream, "%s", result);
355 ada_printchar (int c, struct ui_file *stream)
357 fputs_filtered ("'", stream);
358 ada_emit_char (c, stream, '\'', 1);
359 fputs_filtered ("'", stream);
362 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
363 form appropriate for TYPE. */
366 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
371 type = ada_check_typedef (type);
373 switch (TYPE_CODE (type))
377 len = TYPE_NFIELDS (type);
378 for (i = 0; i < len; i++)
380 if (TYPE_FIELD_BITPOS (type, i) == val)
387 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
391 print_longest (stream, 'd', 0, val);
396 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
400 LA_PRINT_CHAR ((unsigned char) val, stream);
404 fprintf_filtered (stream, val ? "true" : "false");
407 case TYPE_CODE_RANGE:
408 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
411 case TYPE_CODE_UNDEF:
413 case TYPE_CODE_ARRAY:
414 case TYPE_CODE_STRUCT:
415 case TYPE_CODE_UNION:
420 case TYPE_CODE_STRING:
421 case TYPE_CODE_ERROR:
422 case TYPE_CODE_MEMBER:
423 case TYPE_CODE_METHOD:
425 warning (_("internal error: unhandled type in ada_print_scalar"));
429 error (_("Invalid type code in symbol table."));
434 /* Print the character string STRING, printing at most LENGTH characters.
435 Printing stops early if the number hits print_max; repeat counts
436 are printed as appropriate. Print ellipses at the end if we
437 had to stop before printing LENGTH characters, or if
438 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
442 printstr (struct ui_file *stream, char *string, unsigned int length,
443 int force_ellipses, int type_len)
446 unsigned int things_printed = 0;
452 fputs_filtered ("\"\"", stream);
456 for (i = 0; i < length && things_printed < print_max; i += 1)
458 /* Position of the character we are examining
459 to see whether it is repeated. */
461 /* Number of repetitions we have detected so far. */
468 fputs_filtered (", ", stream);
475 && char_at (string, rep1, type_len) == char_at (string, i,
482 if (reps > repeat_count_threshold)
487 fputs_filtered ("\\\", ", stream);
489 fputs_filtered ("\", ", stream);
492 fputs_filtered ("'", stream);
493 ada_emit_char (char_at (string, i, type_len), stream, '\'',
495 fputs_filtered ("'", stream);
496 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
498 things_printed += repeat_count_threshold;
506 fputs_filtered ("\\\"", stream);
508 fputs_filtered ("\"", stream);
511 ada_emit_char (char_at (string, i, type_len), stream, '"',
517 /* Terminate the quotes if necessary. */
521 fputs_filtered ("\\\"", stream);
523 fputs_filtered ("\"", stream);
526 if (force_ellipses || i < length)
527 fputs_filtered ("...", stream);
531 ada_printstr (struct ui_file *stream, char *string, unsigned int length,
532 int width, int force_ellipses)
534 printstr (stream, string, length, force_ellipses, width);
538 /* Print data of type TYPE located at VALADDR (within GDB), which came from
539 the inferior at address ADDRESS, onto stdio stream STREAM according to
540 FORMAT (a letter as for the printf % codes or 0 for natural format).
541 The data at VALADDR is in target byte order.
543 If the data is printed as a string, returns the number of string characters
546 If DEREF_REF is nonzero, then dereference references, otherwise just print
549 RECURSE indicates the amount of indentation to supply before
550 continuation lines; this amount is roughly twice the value of RECURSE.
552 When PRETTY is non-zero, prints record fields on separate lines.
553 (For some reason, the current version of gdb instead uses a global
554 variable---prettyprint_arrays--- to causes a similar effect on
558 ada_val_print (struct type *type, char *valaddr0, int embedded_offset,
559 CORE_ADDR address, struct ui_file *stream, int format,
560 int deref_ref, int recurse, enum val_prettyprint pretty)
562 struct ada_val_print_args args;
564 args.valaddr0 = valaddr0;
565 args.embedded_offset = embedded_offset;
566 args.address = address;
567 args.stream = stream;
568 args.format = format;
569 args.deref_ref = deref_ref;
570 args.recurse = recurse;
571 args.pretty = pretty;
573 return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL);
576 /* Helper for ada_val_print; used as argument to catch_errors to
577 unmarshal the arguments to ada_val_print_1, which does the work. */
579 ada_val_print_stub (void *args0)
581 struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0;
582 return ada_val_print_1 (argsp->type, argsp->valaddr0,
583 argsp->embedded_offset, argsp->address,
584 argsp->stream, argsp->format, argsp->deref_ref,
585 argsp->recurse, argsp->pretty);
588 /* See the comment on ada_val_print. This function differs in that it
589 * does not catch evaluation errors (leaving that to ada_val_print). */
592 ada_val_print_1 (struct type *type, char *valaddr0, int embedded_offset,
593 CORE_ADDR address, struct ui_file *stream, int format,
594 int deref_ref, int recurse, enum val_prettyprint pretty)
598 struct type *elttype;
601 char *valaddr = valaddr0 + embedded_offset;
603 type = ada_check_typedef (type);
605 if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type))
608 struct value *mark = value_mark ();
610 val = value_from_contents_and_address (type, valaddr, address);
611 val = ada_coerce_to_simple_array_ptr (val);
614 fprintf_filtered (stream, "(null)");
618 retn = ada_val_print_1 (value_type (val), VALUE_CONTENTS (val), 0,
619 VALUE_ADDRESS (val), stream, format,
620 deref_ref, recurse, pretty);
621 value_free_to_mark (mark);
625 valaddr = ada_aligned_value_addr (type, valaddr);
626 embedded_offset -= valaddr - valaddr0 - embedded_offset;
627 type = printable_val_type (type, valaddr);
629 switch (TYPE_CODE (type))
632 return c_val_print (type, valaddr0, embedded_offset, address, stream,
633 format, deref_ref, recurse, pretty);
637 int ret = c_val_print (type, valaddr0, embedded_offset, address,
638 stream, format, deref_ref, recurse, pretty);
639 if (ada_is_tag_type (type))
642 value_from_contents_and_address (type, valaddr, address);
643 const char *name = ada_tag_name (val);
645 fprintf_filtered (stream, " (%s)", name);
652 case TYPE_CODE_RANGE:
653 if (ada_is_fixed_point_type (type))
655 LONGEST v = unpack_long (type, valaddr);
656 int len = TYPE_LENGTH (type);
658 fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
659 (double) ada_fixed_to_float (type, v));
662 else if (ada_is_vax_floating_type (type))
665 value_from_contents_and_address (type, valaddr, address);
666 struct value *func = ada_vax_float_print_function (type);
669 static struct type *parray_of_char = NULL;
670 struct value *printable_val;
672 if (parray_of_char == NULL)
676 (NULL, builtin_type_char,
677 create_range_type (NULL, builtin_type_int, 0, 32)), NULL);
680 value_ind (value_cast (parray_of_char,
681 call_function_by_hand (func, 1,
684 fprintf_filtered (stream, "%s", VALUE_CONTENTS (printable_val));
687 /* No special printing function. Do as best we can. */
689 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
691 struct type *target_type = TYPE_TARGET_TYPE (type);
692 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
694 /* Obscure case of range type that has different length from
695 its base type. Perform a conversion, or we will get a
696 nonsense value. Actually, we could use the same
697 code regardless of lengths; I'm just avoiding a cast. */
698 struct value *v = value_cast (target_type,
699 value_from_contents_and_address
701 return ada_val_print_1 (target_type, VALUE_CONTENTS (v), 0, 0,
702 stream, format, 0, recurse + 1, pretty);
705 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
706 valaddr0, embedded_offset,
707 address, stream, format, deref_ref,
712 format = format ? format : output_format;
715 print_scalar_formatted (valaddr, type, format, 0, stream);
717 else if (ada_is_system_address_type (type))
719 /* FIXME: We want to print System.Address variables using
720 the same format as for any access type. But for some
721 reason GNAT encodes the System.Address type as an int,
722 so we have to work-around this deficiency by handling
723 System.Address values as a special case. */
724 fprintf_filtered (stream, "(");
725 type_print (type, "", stream, -1);
726 fprintf_filtered (stream, ") ");
727 print_address_numeric
728 (extract_typed_address (valaddr, builtin_type_void_data_ptr),
733 val_print_type_code_int (type, valaddr, stream);
734 if (ada_is_character_type (type))
736 fputs_filtered (" ", stream);
737 ada_printchar ((unsigned char) unpack_long (type, valaddr),
747 print_scalar_formatted (valaddr, type, format, 0, stream);
750 len = TYPE_NFIELDS (type);
751 val = unpack_long (type, valaddr);
752 for (i = 0; i < len; i++)
755 if (val == TYPE_FIELD_BITPOS (type, i))
762 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
764 fprintf_filtered (stream, "%ld %s", (long) val, name);
766 fputs_filtered (name, stream);
770 print_longest (stream, 'd', 0, val);
776 return c_val_print (type, valaddr0, embedded_offset, address, stream,
777 format, deref_ref, recurse, pretty);
779 ada_print_floating (valaddr0 + embedded_offset, type, stream);
782 case TYPE_CODE_UNION:
783 case TYPE_CODE_STRUCT:
784 if (ada_is_bogus_array_descriptor (type))
786 fprintf_filtered (stream, "(...?)");
791 print_record (type, valaddr, stream, format, recurse, pretty);
795 case TYPE_CODE_ARRAY:
796 elttype = TYPE_TARGET_TYPE (type);
800 eltlen = TYPE_LENGTH (elttype);
801 /* FIXME: This doesn't deal with non-empty arrays of
802 0-length items (not a typical case!) */
806 len = TYPE_LENGTH (type) / eltlen;
808 /* For an array of chars, print with string syntax. */
809 if (ada_is_string_type (type) && (format == 0 || format == 's'))
811 if (prettyprint_arrays)
813 print_spaces_filtered (2 + 2 * recurse, stream);
815 /* If requested, look for the first null char and only print
816 elements up to it. */
817 if (stop_print_at_null)
821 /* Look for a NULL char. */
823 temp_len < len && temp_len < print_max
824 && char_at (valaddr, temp_len, eltlen) != 0;
829 printstr (stream, valaddr, len, 0, eltlen);
834 fprintf_filtered (stream, "(");
835 print_optional_low_bound (stream, type);
836 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
837 val_print_packed_array_elements (type, valaddr, 0, stream,
838 format, recurse, pretty);
840 val_print_array_elements (type, valaddr, address, stream,
841 format, deref_ref, recurse,
843 fprintf_filtered (stream, ")");
849 elttype = check_typedef (TYPE_TARGET_TYPE (type));
850 /* De-reference the reference */
853 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
855 LONGEST deref_val_int = (LONGEST)
856 unpack_pointer (lookup_pointer_type (builtin_type_void),
858 if (deref_val_int != 0)
860 struct value *deref_val =
861 ada_value_ind (value_from_longest
862 (lookup_pointer_type (elttype),
864 val_print (value_type (deref_val),
865 VALUE_CONTENTS (deref_val), 0,
866 VALUE_ADDRESS (deref_val), stream, format,
867 deref_ref, recurse + 1, pretty);
870 fputs_filtered ("(null)", stream);
873 fputs_filtered ("???", stream);
882 print_variant_part (struct type *type, int field_num, char *valaddr,
883 struct ui_file *stream, int format, int recurse,
884 enum val_prettyprint pretty, int comma_needed,
885 struct type *outer_type, char *outer_valaddr)
887 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
888 int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr);
893 return print_field_values
894 (TYPE_FIELD_TYPE (var_type, which),
895 valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
896 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
897 stream, format, recurse, pretty,
898 comma_needed, outer_type, outer_valaddr);
902 ada_value_print (struct value *val0, struct ui_file *stream, int format,
903 enum val_prettyprint pretty)
905 char *valaddr = VALUE_CONTENTS (val0);
906 CORE_ADDR address = VALUE_ADDRESS (val0) + value_offset (val0);
908 ada_to_fixed_type (value_type (val0), valaddr, address, NULL);
910 value_from_contents_and_address (type, valaddr, address);
912 /* If it is a pointer, indicate what it points to. */
913 if (TYPE_CODE (type) == TYPE_CODE_PTR)
915 /* Hack: don't print (char *) for char strings. Their
916 type is indicated by the quoted string anyway. */
917 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
918 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
919 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
921 fprintf_filtered (stream, "(");
922 type_print (type, "", stream, -1);
923 fprintf_filtered (stream, ") ");
926 else if (ada_is_array_descriptor_type (type))
928 fprintf_filtered (stream, "(");
929 type_print (type, "", stream, -1);
930 fprintf_filtered (stream, ") ");
932 else if (ada_is_bogus_array_descriptor (type))
934 fprintf_filtered (stream, "(");
935 type_print (type, "", stream, -1);
936 fprintf_filtered (stream, ") (...?)");
940 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
941 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == 0
942 && TYPE_CODE (TYPE_INDEX_TYPE (type)) == TYPE_CODE_RANGE)
944 /* This is an array of zero-length elements, that is an array
945 of null records. This array needs to be printed by hand,
946 as the standard routine to print arrays relies on the size of
947 the array elements to be nonzero. This is because it computes
948 the number of elements in the array by dividing the array size
949 by the array element size. */
950 fprintf_filtered (stream, "(%d .. %d => ())",
951 TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
952 TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type)));
956 return (val_print (type, VALUE_CONTENTS (val), 0, address,
957 stream, format, 1, 0, pretty));
961 print_record (struct type *type, char *valaddr, struct ui_file *stream,
962 int format, int recurse, enum val_prettyprint pretty)
964 type = ada_check_typedef (type);
966 fprintf_filtered (stream, "(");
968 if (print_field_values (type, valaddr, stream, format, recurse, pretty,
969 0, type, valaddr) != 0 && pretty)
971 fprintf_filtered (stream, "\n");
972 print_spaces_filtered (2 * recurse, stream);
975 fprintf_filtered (stream, ")");
978 /* Print out fields of value at VALADDR having structure type TYPE.
980 TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the
981 same meanings as in ada_print_value and ada_val_print.
983 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
984 (used to get discriminant values when printing variant parts).
986 COMMA_NEEDED is 1 if fields have been printed at the current recursion
987 level, so that a comma is needed before any field printed by this
990 Returns 1 if COMMA_NEEDED or any fields were printed. */
993 print_field_values (struct type *type, char *valaddr, struct ui_file *stream,
994 int format, int recurse, enum val_prettyprint pretty,
995 int comma_needed, struct type *outer_type,
1000 len = TYPE_NFIELDS (type);
1002 for (i = 0; i < len; i += 1)
1004 if (ada_is_ignored_field (type, i))
1007 if (ada_is_wrapper_field (type, i))
1010 print_field_values (TYPE_FIELD_TYPE (type, i),
1012 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1013 stream, format, recurse, pretty,
1014 comma_needed, type, valaddr);
1017 else if (ada_is_variant_part (type, i))
1020 print_variant_part (type, i, valaddr,
1021 stream, format, recurse, pretty, comma_needed,
1022 outer_type, outer_valaddr);
1027 fprintf_filtered (stream, ", ");
1032 fprintf_filtered (stream, "\n");
1033 print_spaces_filtered (2 + 2 * recurse, stream);
1037 wrap_here (n_spaces (2 + 2 * recurse));
1041 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1042 fputs_filtered ("\"( ptr \"", stream);
1044 fputs_filtered ("\"( nodef \"", stream);
1045 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1046 language_cplus, DMGL_NO_OPTS);
1047 fputs_filtered ("\" \"", stream);
1048 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1049 language_cplus, DMGL_NO_OPTS);
1050 fputs_filtered ("\") \"", stream);
1054 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1055 fprintf_filtered (stream, "%.*s",
1056 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1057 TYPE_FIELD_NAME (type, i));
1058 annotate_field_name_end ();
1059 fputs_filtered (" => ", stream);
1060 annotate_field_value ();
1063 if (TYPE_FIELD_PACKED (type, i))
1067 /* Bitfields require special handling, especially due to byte
1069 if (TYPE_CPLUS_SPECIFIC (type) != NULL
1070 && TYPE_FIELD_IGNORE (type, i))
1072 fputs_filtered (_("<optimized out or zero length>"), stream);
1076 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1077 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1079 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1080 v = ada_value_primitive_packed_val (NULL, valaddr,
1081 bit_pos / HOST_CHAR_BIT,
1082 bit_pos % HOST_CHAR_BIT,
1084 TYPE_FIELD_TYPE (type, i));
1085 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0,
1086 stream, format, 0, recurse + 1, pretty);
1090 ada_val_print (TYPE_FIELD_TYPE (type, i),
1091 valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1092 0, 0, stream, format, 0, recurse + 1, pretty);
1093 annotate_field_end ();
1096 return comma_needed;