1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001,
4 2002, 2003, 2004, 2005 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
42 const gdb_byte *valaddr0;
45 struct ui_file *stream;
49 enum val_prettyprint pretty;
52 static void print_record (struct type *, const gdb_byte *, struct ui_file *,
53 int, int, enum val_prettyprint);
55 static int print_field_values (struct type *, const gdb_byte *,
56 struct ui_file *, int, int,
57 enum val_prettyprint, int, struct type *,
60 static void adjust_type_signedness (struct type *);
62 static int ada_val_print_stub (void *args0);
64 static int ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR,
65 struct ui_file *, int, int, int,
66 enum val_prettyprint);
69 /* Make TYPE unsigned if its range of values includes no negatives. */
71 adjust_type_signedness (struct type *type)
73 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
74 && TYPE_LOW_BOUND (type) >= 0)
75 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
78 /* Assuming TYPE is a simple, non-empty array type, prints its lower bound
79 on STREAM, if non-standard (i.e., other than 1 for numbers, other
80 than lower bound of index type for enumerated type). Returns 1
81 if something printed, otherwise 0. */
84 print_optional_low_bound (struct ui_file *stream, struct type *type)
86 struct type *index_type;
89 index_type = TYPE_INDEX_TYPE (type);
92 if (index_type == NULL)
94 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
96 low_bound = TYPE_LOW_BOUND (index_type);
97 if (low_bound > TYPE_HIGH_BOUND (index_type))
99 index_type = TYPE_TARGET_TYPE (index_type);
104 switch (TYPE_CODE (index_type))
107 if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
110 case TYPE_CODE_UNDEF:
111 index_type = builtin_type_long;
119 ada_print_scalar (index_type, (LONGEST) low_bound, stream);
120 fprintf_filtered (stream, " => ");
124 /* Version of val_print_array_elements for GNAT-style packed arrays.
125 Prints elements of packed array of type TYPE at bit offset
126 BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and
127 separates with commas. RECURSE is the recursion (nesting) level.
128 If PRETTY, uses "prettier" format. TYPE must have been decoded (as
129 by ada_coerce_to_simple_array). */
132 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
133 int bitoffset, struct ui_file *stream,
134 int format, int recurse,
135 enum val_prettyprint pretty)
138 unsigned int things_printed = 0;
140 struct type *elttype;
142 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
143 struct value *mark = value_mark ();
145 elttype = TYPE_TARGET_TYPE (type);
146 eltlen = TYPE_LENGTH (check_typedef (elttype));
150 if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0)
153 len = high - low + 1;
157 annotate_array_section_begin (i, elttype);
159 while (i < len && things_printed < print_max)
161 struct value *v0, *v1;
166 if (prettyprint_arrays)
168 fprintf_filtered (stream, ",\n");
169 print_spaces_filtered (2 + 2 * recurse, stream);
173 fprintf_filtered (stream, ", ");
176 wrap_here (n_spaces (2 + 2 * recurse));
179 v0 = ada_value_primitive_packed_val (NULL, valaddr,
180 (i0 * bitsize) / HOST_CHAR_BIT,
181 (i0 * bitsize) % HOST_CHAR_BIT,
188 v1 = ada_value_primitive_packed_val (NULL, valaddr,
189 (i * bitsize) / HOST_CHAR_BIT,
190 (i * bitsize) % HOST_CHAR_BIT,
192 if (memcmp (value_contents (v0), value_contents (v1), eltlen) != 0)
196 if (i - i0 > repeat_count_threshold)
198 val_print (elttype, value_contents (v0), 0, 0, stream, format,
199 0, recurse + 1, pretty);
200 annotate_elt_rep (i - i0);
201 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
202 annotate_elt_rep_end ();
208 for (j = i0; j < i; j += 1)
212 if (prettyprint_arrays)
214 fprintf_filtered (stream, ",\n");
215 print_spaces_filtered (2 + 2 * recurse, stream);
219 fprintf_filtered (stream, ", ");
221 wrap_here (n_spaces (2 + 2 * recurse));
223 val_print (elttype, value_contents (v0), 0, 0, stream, format,
224 0, recurse + 1, pretty);
228 things_printed += i - i0;
230 annotate_array_section_end ();
233 fprintf_filtered (stream, "...");
236 value_free_to_mark (mark);
240 printable_val_type (struct type *type, const gdb_byte *valaddr)
242 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL);
245 /* Print the character C on STREAM as part of the contents of a literal
246 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
247 (1 or 2) of the character. */
250 ada_emit_char (int c, struct ui_file *stream, int quoter, int type_len)
255 c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1;
257 if (isascii (c) && isprint (c))
259 if (c == quoter && c == '"')
260 fprintf_filtered (stream, "[\"%c\"]", quoter);
262 fprintf_filtered (stream, "%c", c);
265 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
268 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
269 or 2) of a character. */
272 char_at (const gdb_byte *string, int i, int type_len)
277 return (int) extract_unsigned_integer (string + 2 * i, 2);
280 /* Wrapper around memcpy to make it legal argument to ui_file_put */
282 ui_memcpy (void *dest, const char *buffer, long len)
284 memcpy (dest, buffer, (size_t) len);
285 ((char *) dest)[len] = '\0';
288 /* Print a floating-point value of type TYPE, pointed to in GDB by
289 VALADDR, on STREAM. Use Ada formatting conventions: there must be
290 a decimal point, and at least one digit before and after the
291 point. We use GNAT format for NaNs and infinities. */
293 ada_print_floating (const gdb_byte *valaddr, struct type *type,
294 struct ui_file *stream)
299 struct ui_file *tmp_stream = mem_fileopen ();
300 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
302 print_floating (valaddr, type, tmp_stream);
303 ui_file_put (tmp_stream, ui_memcpy, buffer);
304 do_cleanups (cleanups);
307 len = strlen (result);
309 /* Modify for Ada rules. */
311 s = strstr (result, "inf");
313 s = strstr (result, "Inf");
315 s = strstr (result, "INF");
321 s = strstr (result, "nan");
323 s = strstr (result, "NaN");
325 s = strstr (result, "Nan");
329 if (result[0] == '-')
334 if (s == NULL && strchr (result, '.') == NULL)
336 s = strchr (result, 'e');
338 fprintf_filtered (stream, "%s.0", result);
340 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
343 fprintf_filtered (stream, "%s", result);
347 ada_printchar (int c, struct ui_file *stream)
349 fputs_filtered ("'", stream);
350 ada_emit_char (c, stream, '\'', 1);
351 fputs_filtered ("'", stream);
354 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
355 form appropriate for TYPE. */
358 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
363 type = ada_check_typedef (type);
365 switch (TYPE_CODE (type))
369 len = TYPE_NFIELDS (type);
370 for (i = 0; i < len; i++)
372 if (TYPE_FIELD_BITPOS (type, i) == val)
379 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
383 print_longest (stream, 'd', 0, val);
388 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
392 LA_PRINT_CHAR ((unsigned char) val, stream);
396 fprintf_filtered (stream, val ? "true" : "false");
399 case TYPE_CODE_RANGE:
400 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
403 case TYPE_CODE_UNDEF:
405 case TYPE_CODE_ARRAY:
406 case TYPE_CODE_STRUCT:
407 case TYPE_CODE_UNION:
412 case TYPE_CODE_STRING:
413 case TYPE_CODE_ERROR:
414 case TYPE_CODE_MEMBER:
415 case TYPE_CODE_METHOD:
417 warning (_("internal error: unhandled type in ada_print_scalar"));
421 error (_("Invalid type code in symbol table."));
426 /* Print the character string STRING, printing at most LENGTH characters.
427 Printing stops early if the number hits print_max; repeat counts
428 are printed as appropriate. Print ellipses at the end if we
429 had to stop before printing LENGTH characters, or if
430 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
434 printstr (struct ui_file *stream, const gdb_byte *string,
435 unsigned int length, int force_ellipses, int type_len)
438 unsigned int things_printed = 0;
444 fputs_filtered ("\"\"", stream);
448 for (i = 0; i < length && things_printed < print_max; i += 1)
450 /* Position of the character we are examining
451 to see whether it is repeated. */
453 /* Number of repetitions we have detected so far. */
460 fputs_filtered (", ", stream);
467 && char_at (string, rep1, type_len) == char_at (string, i,
474 if (reps > repeat_count_threshold)
479 fputs_filtered ("\\\", ", stream);
481 fputs_filtered ("\", ", stream);
484 fputs_filtered ("'", stream);
485 ada_emit_char (char_at (string, i, type_len), stream, '\'',
487 fputs_filtered ("'", stream);
488 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
490 things_printed += repeat_count_threshold;
498 fputs_filtered ("\\\"", stream);
500 fputs_filtered ("\"", stream);
503 ada_emit_char (char_at (string, i, type_len), stream, '"',
509 /* Terminate the quotes if necessary. */
513 fputs_filtered ("\\\"", stream);
515 fputs_filtered ("\"", stream);
518 if (force_ellipses || i < length)
519 fputs_filtered ("...", stream);
523 ada_printstr (struct ui_file *stream, const gdb_byte *string,
524 unsigned int length, int width, int force_ellipses)
526 printstr (stream, string, length, force_ellipses, width);
530 /* Print data of type TYPE located at VALADDR (within GDB), which came from
531 the inferior at address ADDRESS, onto stdio stream STREAM according to
532 FORMAT (a letter as for the printf % codes or 0 for natural format).
533 The data at VALADDR is in target byte order.
535 If the data is printed as a string, returns the number of string characters
538 If DEREF_REF is nonzero, then dereference references, otherwise just print
541 RECURSE indicates the amount of indentation to supply before
542 continuation lines; this amount is roughly twice the value of RECURSE.
544 When PRETTY is non-zero, prints record fields on separate lines.
545 (For some reason, the current version of gdb instead uses a global
546 variable---prettyprint_arrays--- to causes a similar effect on
550 ada_val_print (struct type *type, const gdb_byte *valaddr0,
551 int embedded_offset, CORE_ADDR address,
552 struct ui_file *stream, int format, int deref_ref,
553 int recurse, enum val_prettyprint pretty)
555 struct ada_val_print_args args;
557 args.valaddr0 = valaddr0;
558 args.embedded_offset = embedded_offset;
559 args.address = address;
560 args.stream = stream;
561 args.format = format;
562 args.deref_ref = deref_ref;
563 args.recurse = recurse;
564 args.pretty = pretty;
566 return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL);
569 /* Helper for ada_val_print; used as argument to catch_errors to
570 unmarshal the arguments to ada_val_print_1, which does the work. */
572 ada_val_print_stub (void *args0)
574 struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0;
575 return ada_val_print_1 (argsp->type, argsp->valaddr0,
576 argsp->embedded_offset, argsp->address,
577 argsp->stream, argsp->format, argsp->deref_ref,
578 argsp->recurse, argsp->pretty);
581 /* See the comment on ada_val_print. This function differs in that it
582 * does not catch evaluation errors (leaving that to ada_val_print). */
585 ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
586 int embedded_offset, CORE_ADDR address,
587 struct ui_file *stream, int format,
588 int deref_ref, int recurse, enum val_prettyprint pretty)
592 struct type *elttype;
595 const gdb_byte *valaddr = valaddr0 + embedded_offset;
597 type = ada_check_typedef (type);
599 if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type))
602 struct value *mark = value_mark ();
604 val = value_from_contents_and_address (type, valaddr, address);
605 val = ada_coerce_to_simple_array_ptr (val);
608 fprintf_filtered (stream, "(null)");
612 retn = ada_val_print_1 (value_type (val), value_contents (val), 0,
613 VALUE_ADDRESS (val), stream, format,
614 deref_ref, recurse, pretty);
615 value_free_to_mark (mark);
619 valaddr = ada_aligned_value_addr (type, valaddr);
620 embedded_offset -= valaddr - valaddr0 - embedded_offset;
621 type = printable_val_type (type, valaddr);
623 switch (TYPE_CODE (type))
626 return c_val_print (type, valaddr0, embedded_offset, address, stream,
627 format, deref_ref, recurse, pretty);
631 int ret = c_val_print (type, valaddr0, embedded_offset, address,
632 stream, format, deref_ref, recurse, pretty);
633 if (ada_is_tag_type (type))
636 value_from_contents_and_address (type, valaddr, address);
637 const char *name = ada_tag_name (val);
639 fprintf_filtered (stream, " (%s)", name);
646 case TYPE_CODE_RANGE:
647 if (ada_is_fixed_point_type (type))
649 LONGEST v = unpack_long (type, valaddr);
650 int len = TYPE_LENGTH (type);
652 fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
653 (double) ada_fixed_to_float (type, v));
656 else if (ada_is_vax_floating_type (type))
659 value_from_contents_and_address (type, valaddr, address);
660 struct value *func = ada_vax_float_print_function (type);
663 static struct type *parray_of_char = NULL;
664 struct value *printable_val;
666 if (parray_of_char == NULL)
670 (NULL, builtin_type_char,
671 create_range_type (NULL, builtin_type_int, 0, 32)), NULL);
674 value_ind (value_cast (parray_of_char,
675 call_function_by_hand (func, 1,
678 fprintf_filtered (stream, "%s", value_contents (printable_val));
681 /* No special printing function. Do as best we can. */
683 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
685 struct type *target_type = TYPE_TARGET_TYPE (type);
686 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
688 /* Obscure case of range type that has different length from
689 its base type. Perform a conversion, or we will get a
690 nonsense value. Actually, we could use the same
691 code regardless of lengths; I'm just avoiding a cast. */
692 struct value *v = value_cast (target_type,
693 value_from_contents_and_address
695 return ada_val_print_1 (target_type, value_contents (v), 0, 0,
696 stream, format, 0, recurse + 1, pretty);
699 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
700 valaddr0, embedded_offset,
701 address, stream, format, deref_ref,
706 format = format ? format : output_format;
709 print_scalar_formatted (valaddr, type, format, 0, stream);
711 else if (ada_is_system_address_type (type))
713 /* FIXME: We want to print System.Address variables using
714 the same format as for any access type. But for some
715 reason GNAT encodes the System.Address type as an int,
716 so we have to work-around this deficiency by handling
717 System.Address values as a special case. */
718 fprintf_filtered (stream, "(");
719 type_print (type, "", stream, -1);
720 fprintf_filtered (stream, ") ");
721 deprecated_print_address_numeric
722 (extract_typed_address (valaddr, builtin_type_void_data_ptr),
727 val_print_type_code_int (type, valaddr, stream);
728 if (ada_is_character_type (type))
730 fputs_filtered (" ", stream);
731 ada_printchar ((unsigned char) unpack_long (type, valaddr),
741 print_scalar_formatted (valaddr, type, format, 0, stream);
744 len = TYPE_NFIELDS (type);
745 val = unpack_long (type, valaddr);
746 for (i = 0; i < len; i++)
749 if (val == TYPE_FIELD_BITPOS (type, i))
756 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
758 fprintf_filtered (stream, "%ld %s", (long) val, name);
760 fputs_filtered (name, stream);
764 print_longest (stream, 'd', 0, val);
770 return c_val_print (type, valaddr0, embedded_offset, address, stream,
771 format, deref_ref, recurse, pretty);
773 ada_print_floating (valaddr0 + embedded_offset, type, stream);
776 case TYPE_CODE_UNION:
777 case TYPE_CODE_STRUCT:
778 if (ada_is_bogus_array_descriptor (type))
780 fprintf_filtered (stream, "(...?)");
785 print_record (type, valaddr, stream, format, recurse, pretty);
789 case TYPE_CODE_ARRAY:
790 elttype = TYPE_TARGET_TYPE (type);
794 eltlen = TYPE_LENGTH (elttype);
795 /* FIXME: This doesn't deal with non-empty arrays of
796 0-length items (not a typical case!) */
800 len = TYPE_LENGTH (type) / eltlen;
802 /* For an array of chars, print with string syntax. */
803 if (ada_is_string_type (type) && (format == 0 || format == 's'))
805 if (prettyprint_arrays)
807 print_spaces_filtered (2 + 2 * recurse, stream);
809 /* If requested, look for the first null char and only print
810 elements up to it. */
811 if (stop_print_at_null)
815 /* Look for a NULL char. */
817 temp_len < len && temp_len < print_max
818 && char_at (valaddr, temp_len, eltlen) != 0;
823 printstr (stream, valaddr, len, 0, eltlen);
828 fprintf_filtered (stream, "(");
829 print_optional_low_bound (stream, type);
830 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
831 val_print_packed_array_elements (type, valaddr, 0, stream,
832 format, recurse, pretty);
834 val_print_array_elements (type, valaddr, address, stream,
835 format, deref_ref, recurse,
837 fprintf_filtered (stream, ")");
843 elttype = check_typedef (TYPE_TARGET_TYPE (type));
844 /* De-reference the reference */
847 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
849 LONGEST deref_val_int = (LONGEST)
850 unpack_pointer (lookup_pointer_type (builtin_type_void),
852 if (deref_val_int != 0)
854 struct value *deref_val =
855 ada_value_ind (value_from_longest
856 (lookup_pointer_type (elttype),
858 val_print (value_type (deref_val),
859 value_contents (deref_val), 0,
860 VALUE_ADDRESS (deref_val), stream, format,
861 deref_ref, recurse + 1, pretty);
864 fputs_filtered ("(null)", stream);
867 fputs_filtered ("???", stream);
876 print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr,
877 struct ui_file *stream, int format, int recurse,
878 enum val_prettyprint pretty, int comma_needed,
879 struct type *outer_type, const gdb_byte *outer_valaddr)
881 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
882 int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr);
887 return print_field_values
888 (TYPE_FIELD_TYPE (var_type, which),
889 valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
890 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
891 stream, format, recurse, pretty,
892 comma_needed, outer_type, outer_valaddr);
896 ada_value_print (struct value *val0, struct ui_file *stream, int format,
897 enum val_prettyprint pretty)
899 const gdb_byte *valaddr = value_contents (val0);
900 CORE_ADDR address = VALUE_ADDRESS (val0) + value_offset (val0);
902 ada_to_fixed_type (value_type (val0), valaddr, address, NULL);
904 value_from_contents_and_address (type, valaddr, address);
906 /* If it is a pointer, indicate what it points to. */
907 if (TYPE_CODE (type) == TYPE_CODE_PTR)
909 /* Hack: don't print (char *) for char strings. Their
910 type is indicated by the quoted string anyway. */
911 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
912 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
913 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
915 fprintf_filtered (stream, "(");
916 type_print (type, "", stream, -1);
917 fprintf_filtered (stream, ") ");
920 else if (ada_is_array_descriptor_type (type))
922 fprintf_filtered (stream, "(");
923 type_print (type, "", stream, -1);
924 fprintf_filtered (stream, ") ");
926 else if (ada_is_bogus_array_descriptor (type))
928 fprintf_filtered (stream, "(");
929 type_print (type, "", stream, -1);
930 fprintf_filtered (stream, ") (...?)");
934 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
935 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == 0
936 && TYPE_CODE (TYPE_INDEX_TYPE (type)) == TYPE_CODE_RANGE)
938 /* This is an array of zero-length elements, that is an array
939 of null records. This array needs to be printed by hand,
940 as the standard routine to print arrays relies on the size of
941 the array elements to be nonzero. This is because it computes
942 the number of elements in the array by dividing the array size
943 by the array element size. */
944 fprintf_filtered (stream, "(%d .. %d => ())",
945 TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
946 TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type)));
950 return (val_print (type, value_contents (val), 0, address,
951 stream, format, 1, 0, pretty));
955 print_record (struct type *type, const gdb_byte *valaddr,
956 struct ui_file *stream, int format, int recurse,
957 enum val_prettyprint pretty)
959 type = ada_check_typedef (type);
961 fprintf_filtered (stream, "(");
963 if (print_field_values (type, valaddr, stream, format, recurse, pretty,
964 0, type, valaddr) != 0 && pretty)
966 fprintf_filtered (stream, "\n");
967 print_spaces_filtered (2 * recurse, stream);
970 fprintf_filtered (stream, ")");
973 /* Print out fields of value at VALADDR having structure type TYPE.
975 TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the
976 same meanings as in ada_print_value and ada_val_print.
978 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
979 (used to get discriminant values when printing variant parts).
981 COMMA_NEEDED is 1 if fields have been printed at the current recursion
982 level, so that a comma is needed before any field printed by this
985 Returns 1 if COMMA_NEEDED or any fields were printed. */
988 print_field_values (struct type *type, const gdb_byte *valaddr,
989 struct ui_file *stream, int format, int recurse,
990 enum val_prettyprint pretty, int comma_needed,
991 struct type *outer_type, const gdb_byte *outer_valaddr)
995 len = TYPE_NFIELDS (type);
997 for (i = 0; i < len; i += 1)
999 if (ada_is_ignored_field (type, i))
1002 if (ada_is_wrapper_field (type, i))
1005 print_field_values (TYPE_FIELD_TYPE (type, i),
1007 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1008 stream, format, recurse, pretty,
1009 comma_needed, type, valaddr);
1012 else if (ada_is_variant_part (type, i))
1015 print_variant_part (type, i, valaddr,
1016 stream, format, recurse, pretty, comma_needed,
1017 outer_type, outer_valaddr);
1022 fprintf_filtered (stream, ", ");
1027 fprintf_filtered (stream, "\n");
1028 print_spaces_filtered (2 + 2 * recurse, stream);
1032 wrap_here (n_spaces (2 + 2 * recurse));
1036 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1037 fputs_filtered ("\"( ptr \"", stream);
1039 fputs_filtered ("\"( nodef \"", stream);
1040 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1041 language_cplus, DMGL_NO_OPTS);
1042 fputs_filtered ("\" \"", stream);
1043 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1044 language_cplus, DMGL_NO_OPTS);
1045 fputs_filtered ("\") \"", stream);
1049 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1050 fprintf_filtered (stream, "%.*s",
1051 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1052 TYPE_FIELD_NAME (type, i));
1053 annotate_field_name_end ();
1054 fputs_filtered (" => ", stream);
1055 annotate_field_value ();
1058 if (TYPE_FIELD_PACKED (type, i))
1062 /* Bitfields require special handling, especially due to byte
1064 if (TYPE_CPLUS_SPECIFIC (type) != NULL
1065 && TYPE_FIELD_IGNORE (type, i))
1067 fputs_filtered (_("<optimized out or zero length>"), stream);
1071 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1072 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1074 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1075 v = ada_value_primitive_packed_val (NULL, valaddr,
1076 bit_pos / HOST_CHAR_BIT,
1077 bit_pos % HOST_CHAR_BIT,
1079 TYPE_FIELD_TYPE (type, i));
1080 val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0,
1081 stream, format, 0, recurse + 1, pretty);
1085 ada_val_print (TYPE_FIELD_TYPE (type, i),
1086 valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1087 0, 0, stream, format, 0, recurse + 1, pretty);
1088 annotate_field_end ();
1091 return comma_needed;