1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
27 #include "expression.h"
36 #include "exceptions.h"
39 /* Encapsulates arguments to ada_val_print. */
40 struct ada_val_print_args
43 const gdb_byte *valaddr0;
46 struct ui_file *stream;
48 const struct value_print_options *options;
51 static void print_record (struct type *, const gdb_byte *, struct ui_file *,
52 int, const struct value_print_options *);
54 static int print_field_values (struct type *, const gdb_byte *,
55 struct ui_file *, int,
56 const struct value_print_options *,
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,
66 const struct value_print_options *);
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_UNSIGNED (type) = 1;
78 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
79 if non-standard (i.e., other than 1 for numbers, other than lower bound
80 of index type for enumerated type). Returns 1 if something printed,
84 print_optional_low_bound (struct ui_file *stream, struct type *type,
85 const struct value_print_options *options)
87 struct type *index_type;
91 if (options->print_array_indexes)
94 if (!get_array_bounds (type, &low_bound, &high_bound))
97 /* If this is an empty array, then don't print the lower bound.
98 That would be confusing, because we would print the lower bound,
99 followed by... nothing! */
100 if (low_bound > high_bound)
103 index_type = TYPE_INDEX_TYPE (type);
105 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
107 /* We need to know what the base type is, in order to do the
108 appropriate check below. Otherwise, if this is a subrange
109 of an enumerated type, where the underlying value of the
110 first element is typically 0, we might test the low bound
111 against the wrong value. */
112 index_type = TYPE_TARGET_TYPE (index_type);
115 switch (TYPE_CODE (index_type))
122 if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
125 case TYPE_CODE_UNDEF:
134 ada_print_scalar (index_type, (LONGEST) low_bound, stream);
135 fprintf_filtered (stream, " => ");
139 /* Version of val_print_array_elements for GNAT-style packed arrays.
140 Prints elements of packed array of type TYPE at bit offset
141 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
142 separates with commas. RECURSE is the recursion (nesting) level.
143 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
146 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
147 int bitoffset, struct ui_file *stream,
149 const struct value_print_options *options)
152 unsigned int things_printed = 0;
154 struct type *elttype, *index_type;
156 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
157 struct value *mark = value_mark ();
160 elttype = TYPE_TARGET_TYPE (type);
161 eltlen = TYPE_LENGTH (check_typedef (elttype));
162 index_type = TYPE_INDEX_TYPE (type);
166 if (get_discrete_bounds (index_type, &low, &high) < 0)
169 len = high - low + 1;
173 annotate_array_section_begin (i, elttype);
175 while (i < len && things_printed < options->print_max)
177 struct value *v0, *v1;
182 if (options->prettyprint_arrays)
184 fprintf_filtered (stream, ",\n");
185 print_spaces_filtered (2 + 2 * recurse, stream);
189 fprintf_filtered (stream, ", ");
192 wrap_here (n_spaces (2 + 2 * recurse));
193 maybe_print_array_index (index_type, i + low, stream, options);
196 v0 = ada_value_primitive_packed_val (NULL, valaddr,
197 (i0 * bitsize) / HOST_CHAR_BIT,
198 (i0 * bitsize) % HOST_CHAR_BIT,
205 v1 = ada_value_primitive_packed_val (NULL, valaddr,
206 (i * bitsize) / HOST_CHAR_BIT,
207 (i * bitsize) % HOST_CHAR_BIT,
209 if (memcmp (value_contents (v0), value_contents (v1), eltlen) != 0)
213 if (i - i0 > options->repeat_count_threshold)
215 struct value_print_options opts = *options;
217 val_print (elttype, value_contents (v0), 0, 0, stream,
218 recurse + 1, &opts, current_language);
219 annotate_elt_rep (i - i0);
220 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
221 annotate_elt_rep_end ();
227 struct value_print_options opts = *options;
229 for (j = i0; j < i; j += 1)
233 if (options->prettyprint_arrays)
235 fprintf_filtered (stream, ",\n");
236 print_spaces_filtered (2 + 2 * recurse, stream);
240 fprintf_filtered (stream, ", ");
242 wrap_here (n_spaces (2 + 2 * recurse));
243 maybe_print_array_index (index_type, j + low,
246 val_print (elttype, value_contents (v0), 0, 0, stream,
247 recurse + 1, &opts, current_language);
251 things_printed += i - i0;
253 annotate_array_section_end ();
256 fprintf_filtered (stream, "...");
259 value_free_to_mark (mark);
263 printable_val_type (struct type *type, const gdb_byte *valaddr)
265 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
268 /* Print the character C on STREAM as part of the contents of a literal
269 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
270 (1 or 2) of the character. */
273 ada_emit_char (int c, struct type *type, struct ui_file *stream,
274 int quoter, int type_len)
279 c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1;
281 if (isascii (c) && isprint (c))
283 if (c == quoter && c == '"')
284 fprintf_filtered (stream, "\"\"");
286 fprintf_filtered (stream, "%c", c);
289 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
292 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
293 or 2) of a character. */
296 char_at (const gdb_byte *string, int i, int type_len,
297 enum bfd_endian byte_order)
302 return (int) extract_unsigned_integer (string + 2 * i, 2, byte_order);
305 /* Wrapper around memcpy to make it legal argument to ui_file_put */
307 ui_memcpy (void *dest, const char *buffer, long len)
309 memcpy (dest, buffer, (size_t) len);
310 ((char *) dest)[len] = '\0';
313 /* Print a floating-point value of type TYPE, pointed to in GDB by
314 VALADDR, on STREAM. Use Ada formatting conventions: there must be
315 a decimal point, and at least one digit before and after the
316 point. We use GNAT format for NaNs and infinities. */
318 ada_print_floating (const gdb_byte *valaddr, struct type *type,
319 struct ui_file *stream)
324 struct ui_file *tmp_stream = mem_fileopen ();
325 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
327 print_floating (valaddr, type, tmp_stream);
328 ui_file_put (tmp_stream, ui_memcpy, buffer);
329 do_cleanups (cleanups);
332 len = strlen (result);
334 /* Modify for Ada rules. */
336 s = strstr (result, "inf");
338 s = strstr (result, "Inf");
340 s = strstr (result, "INF");
346 s = strstr (result, "nan");
348 s = strstr (result, "NaN");
350 s = strstr (result, "Nan");
354 if (result[0] == '-')
359 if (s == NULL && strchr (result, '.') == NULL)
361 s = strchr (result, 'e');
363 fprintf_filtered (stream, "%s.0", result);
365 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
368 fprintf_filtered (stream, "%s", result);
372 ada_printchar (int c, struct type *type, struct ui_file *stream)
374 fputs_filtered ("'", stream);
375 ada_emit_char (c, type, stream, '\'', 1);
376 fputs_filtered ("'", stream);
379 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
380 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
381 like a default signed integer. */
384 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
391 print_longest (stream, 'd', 0, val);
395 type = ada_check_typedef (type);
397 switch (TYPE_CODE (type))
401 len = TYPE_NFIELDS (type);
402 for (i = 0; i < len; i++)
404 if (TYPE_FIELD_BITPOS (type, i) == val)
411 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
415 print_longest (stream, 'd', 0, val);
420 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
424 LA_PRINT_CHAR ((unsigned char) val, type, stream);
428 fprintf_filtered (stream, val ? "true" : "false");
431 case TYPE_CODE_RANGE:
432 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
435 case TYPE_CODE_UNDEF:
437 case TYPE_CODE_ARRAY:
438 case TYPE_CODE_STRUCT:
439 case TYPE_CODE_UNION:
444 case TYPE_CODE_STRING:
445 case TYPE_CODE_ERROR:
446 case TYPE_CODE_MEMBERPTR:
447 case TYPE_CODE_METHODPTR:
448 case TYPE_CODE_METHOD:
450 warning (_("internal error: unhandled type in ada_print_scalar"));
454 error (_("Invalid type code in symbol table."));
459 /* Print the character string STRING, printing at most LENGTH characters.
460 Printing stops early if the number hits print_max; repeat counts
461 are printed as appropriate. Print ellipses at the end if we
462 had to stop before printing LENGTH characters, or if
463 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
467 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
468 unsigned int length, int force_ellipses, int type_len,
469 const struct value_print_options *options)
471 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype));
473 unsigned int things_printed = 0;
479 fputs_filtered ("\"\"", stream);
483 for (i = 0; i < length && things_printed < options->print_max; i += 1)
485 /* Position of the character we are examining
486 to see whether it is repeated. */
488 /* Number of repetitions we have detected so far. */
495 fputs_filtered (", ", stream);
502 && char_at (string, rep1, type_len, byte_order)
503 == char_at (string, i, type_len, byte_order))
509 if (reps > options->repeat_count_threshold)
513 if (options->inspect_it)
514 fputs_filtered ("\\\", ", stream);
516 fputs_filtered ("\", ", stream);
519 fputs_filtered ("'", stream);
520 ada_emit_char (char_at (string, i, type_len, byte_order),
521 elttype, stream, '\'', type_len);
522 fputs_filtered ("'", stream);
523 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
525 things_printed += options->repeat_count_threshold;
532 if (options->inspect_it)
533 fputs_filtered ("\\\"", stream);
535 fputs_filtered ("\"", stream);
538 ada_emit_char (char_at (string, i, type_len, byte_order),
539 elttype, stream, '"', type_len);
544 /* Terminate the quotes if necessary. */
547 if (options->inspect_it)
548 fputs_filtered ("\\\"", stream);
550 fputs_filtered ("\"", stream);
553 if (force_ellipses || i < length)
554 fputs_filtered ("...", stream);
558 ada_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
559 unsigned int length, const char *encoding, int force_ellipses,
560 const struct value_print_options *options)
562 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
567 /* Print data of type TYPE located at VALADDR (within GDB), which came from
568 the inferior at address ADDRESS, onto stdio stream STREAM according to
569 OPTIONS. The data at VALADDR is in target byte order.
571 If the data is printed as a string, returns the number of string characters
574 RECURSE indicates the amount of indentation to supply before
575 continuation lines; this amount is roughly twice the value of RECURSE. */
578 ada_val_print (struct type *type, const gdb_byte *valaddr0,
579 int embedded_offset, CORE_ADDR address,
580 struct ui_file *stream, int recurse,
581 const struct value_print_options *options)
583 struct ada_val_print_args args;
585 args.valaddr0 = valaddr0;
586 args.embedded_offset = embedded_offset;
587 args.address = address;
588 args.stream = stream;
589 args.recurse = recurse;
590 args.options = options;
592 return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL);
595 /* Helper for ada_val_print; used as argument to catch_errors to
596 unmarshal the arguments to ada_val_print_1, which does the work. */
598 ada_val_print_stub (void *args0)
600 struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0;
601 return ada_val_print_1 (argsp->type, argsp->valaddr0,
602 argsp->embedded_offset, argsp->address,
603 argsp->stream, argsp->recurse, argsp->options);
606 /* Assuming TYPE is a simple array, print the value of this array located
607 at VALADDR. See ada_val_print for a description of the various
608 parameters of this function; they are identical. The semantics
609 of the return value is also identical to ada_val_print. */
612 ada_val_print_array (struct type *type, const gdb_byte *valaddr,
613 CORE_ADDR address, struct ui_file *stream, int recurse,
614 const struct value_print_options *options)
616 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
617 struct type *elttype = TYPE_TARGET_TYPE (type);
625 eltlen = TYPE_LENGTH (elttype);
629 len = TYPE_LENGTH (type) / eltlen;
631 /* For an array of chars, print with string syntax. */
632 if (ada_is_string_type (type)
633 && (options->format == 0 || options->format == 's'))
635 if (options->prettyprint_arrays)
636 print_spaces_filtered (2 + 2 * recurse, stream);
638 /* If requested, look for the first null char and only print
639 elements up to it. */
640 if (options->stop_print_at_null)
644 /* Look for a NULL char. */
647 && temp_len < options->print_max
648 && char_at (valaddr, temp_len, eltlen, byte_order) != 0);
653 printstr (stream, elttype, valaddr, len, 0, eltlen, options);
658 fprintf_filtered (stream, "(");
659 print_optional_low_bound (stream, type, options);
660 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
661 val_print_packed_array_elements (type, valaddr, 0, stream,
664 val_print_array_elements (type, valaddr, address, stream,
665 recurse, options, 0);
666 fprintf_filtered (stream, ")");
672 /* See the comment on ada_val_print. This function differs in that it
673 does not catch evaluation errors (leaving that to ada_val_print). */
676 ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
677 int embedded_offset, CORE_ADDR address,
678 struct ui_file *stream, int recurse,
679 const struct value_print_options *options)
683 struct type *elttype;
686 const gdb_byte *valaddr = valaddr0 + embedded_offset;
688 type = ada_check_typedef (type);
690 if (ada_is_array_descriptor_type (type)
691 || ada_is_constrained_packed_array_type (type))
694 struct value *mark = value_mark ();
696 val = value_from_contents_and_address (type, valaddr, address);
697 val = ada_coerce_to_simple_array_ptr (val);
700 fprintf_filtered (stream, "(null)");
704 retn = ada_val_print_1 (value_type (val), value_contents (val), 0,
705 value_address (val), stream, recurse, options);
706 value_free_to_mark (mark);
710 valaddr = ada_aligned_value_addr (type, valaddr);
711 embedded_offset -= valaddr - valaddr0 - embedded_offset;
712 type = printable_val_type (type, valaddr);
714 switch (TYPE_CODE (type))
717 return c_val_print (type, valaddr0, embedded_offset, address, stream,
722 int ret = c_val_print (type, valaddr0, embedded_offset, address,
723 stream, recurse, options);
724 if (ada_is_tag_type (type))
727 value_from_contents_and_address (type, valaddr, address);
728 const char *name = ada_tag_name (val);
730 fprintf_filtered (stream, " (%s)", name);
737 case TYPE_CODE_RANGE:
738 if (ada_is_fixed_point_type (type))
740 LONGEST v = unpack_long (type, valaddr);
741 int len = TYPE_LENGTH (type);
743 fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
744 (double) ada_fixed_to_float (type, v));
747 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
749 struct type *target_type = TYPE_TARGET_TYPE (type);
750 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
752 /* Obscure case of range type that has different length from
753 its base type. Perform a conversion, or we will get a
754 nonsense value. Actually, we could use the same
755 code regardless of lengths; I'm just avoiding a cast. */
756 struct value *v = value_cast (target_type,
757 value_from_contents_and_address
759 return ada_val_print_1 (target_type, value_contents (v), 0, 0,
760 stream, recurse + 1, options);
763 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
764 valaddr0, embedded_offset,
765 address, stream, recurse, options);
769 int format = (options->format ? options->format
770 : options->output_format);
773 struct value_print_options opts = *options;
774 opts.format = format;
775 print_scalar_formatted (valaddr, type, &opts, 0, stream);
777 else if (ada_is_system_address_type (type))
779 /* FIXME: We want to print System.Address variables using
780 the same format as for any access type. But for some
781 reason GNAT encodes the System.Address type as an int,
782 so we have to work-around this deficiency by handling
783 System.Address values as a special case. */
785 struct gdbarch *gdbarch = get_type_arch (type);
786 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
787 CORE_ADDR addr = extract_typed_address (valaddr, ptr_type);
789 fprintf_filtered (stream, "(");
790 type_print (type, "", stream, -1);
791 fprintf_filtered (stream, ") ");
792 fputs_filtered (paddress (gdbarch, addr), stream);
796 val_print_type_code_int (type, valaddr, stream);
797 if (ada_is_character_type (type))
799 fputs_filtered (" ", stream);
800 ada_printchar ((unsigned char) unpack_long (type, valaddr),
810 print_scalar_formatted (valaddr, type, options, 0, stream);
813 len = TYPE_NFIELDS (type);
814 val = unpack_long (type, valaddr);
815 for (i = 0; i < len; i++)
818 if (val == TYPE_FIELD_BITPOS (type, i))
825 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
827 fprintf_filtered (stream, "%ld %s", (long) val, name);
829 fputs_filtered (name, stream);
833 print_longest (stream, 'd', 0, val);
837 case TYPE_CODE_FLAGS:
839 print_scalar_formatted (valaddr, type, options, 0, stream);
841 val_print_type_code_flags (type, valaddr, stream);
846 return c_val_print (type, valaddr0, embedded_offset, address, stream,
849 ada_print_floating (valaddr0 + embedded_offset, type, stream);
852 case TYPE_CODE_UNION:
853 case TYPE_CODE_STRUCT:
854 if (ada_is_bogus_array_descriptor (type))
856 fprintf_filtered (stream, "(...?)");
861 print_record (type, valaddr, stream, recurse, options);
865 case TYPE_CODE_ARRAY:
866 return ada_val_print_array (type, valaddr, address, stream,
870 /* For references, the debugger is expected to print the value as
871 an address if DEREF_REF is null. But printing an address in place
872 of the object value would be confusing to an Ada programmer.
873 So, for Ada values, we print the actual dereferenced value
875 elttype = check_typedef (TYPE_TARGET_TYPE (type));
877 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
879 LONGEST deref_val_int = (LONGEST) unpack_pointer (type, valaddr);
880 if (deref_val_int != 0)
882 struct value *deref_val =
883 ada_value_ind (value_from_longest
884 (lookup_pointer_type (elttype),
886 val_print (value_type (deref_val),
887 value_contents (deref_val), 0,
888 value_address (deref_val), stream, recurse + 1,
889 options, current_language);
892 fputs_filtered ("(null)", stream);
895 fputs_filtered ("???", stream);
904 print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr,
905 struct ui_file *stream, int recurse,
906 const struct value_print_options *options, int comma_needed,
907 struct type *outer_type, const gdb_byte *outer_valaddr)
909 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
910 int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr);
915 return print_field_values
916 (TYPE_FIELD_TYPE (var_type, which),
917 valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
918 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
919 stream, recurse, options,
920 comma_needed, outer_type, outer_valaddr);
924 ada_value_print (struct value *val0, struct ui_file *stream,
925 const struct value_print_options *options)
927 const gdb_byte *valaddr = value_contents (val0);
928 CORE_ADDR address = value_address (val0);
930 ada_to_fixed_type (value_type (val0), valaddr, address, NULL, 1);
932 value_from_contents_and_address (type, valaddr, address);
933 struct value_print_options opts;
935 /* If it is a pointer, indicate what it points to. */
936 if (TYPE_CODE (type) == TYPE_CODE_PTR)
938 /* Hack: don't print (char *) for char strings. Their
939 type is indicated by the quoted string anyway. */
940 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
941 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
942 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
944 fprintf_filtered (stream, "(");
945 type_print (type, "", stream, -1);
946 fprintf_filtered (stream, ") ");
949 else if (ada_is_array_descriptor_type (type))
951 fprintf_filtered (stream, "(");
952 type_print (type, "", stream, -1);
953 fprintf_filtered (stream, ") ");
955 else if (ada_is_bogus_array_descriptor (type))
957 fprintf_filtered (stream, "(");
958 type_print (type, "", stream, -1);
959 fprintf_filtered (stream, ") (...?)");
965 return (val_print (type, value_contents (val), 0, address,
966 stream, 0, &opts, current_language));
970 print_record (struct type *type, const gdb_byte *valaddr,
971 struct ui_file *stream, int recurse,
972 const struct value_print_options *options)
974 type = ada_check_typedef (type);
976 fprintf_filtered (stream, "(");
978 if (print_field_values (type, valaddr, stream, recurse, options,
979 0, type, valaddr) != 0 && options->pretty)
981 fprintf_filtered (stream, "\n");
982 print_spaces_filtered (2 * recurse, stream);
985 fprintf_filtered (stream, ")");
988 /* Print out fields of value at VALADDR having structure type TYPE.
990 TYPE, VALADDR, STREAM, RECURSE, and OPTIONS have the
991 same meanings as in ada_print_value and ada_val_print.
993 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
994 (used to get discriminant values when printing variant parts).
996 COMMA_NEEDED is 1 if fields have been printed at the current recursion
997 level, so that a comma is needed before any field printed by this
1000 Returns 1 if COMMA_NEEDED or any fields were printed. */
1003 print_field_values (struct type *type, const gdb_byte *valaddr,
1004 struct ui_file *stream, int recurse,
1005 const struct value_print_options *options,
1007 struct type *outer_type, const gdb_byte *outer_valaddr)
1011 len = TYPE_NFIELDS (type);
1013 for (i = 0; i < len; i += 1)
1015 if (ada_is_ignored_field (type, i))
1018 if (ada_is_wrapper_field (type, i))
1021 print_field_values (TYPE_FIELD_TYPE (type, i),
1023 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1024 stream, recurse, options,
1025 comma_needed, type, valaddr);
1028 else if (ada_is_variant_part (type, i))
1031 print_variant_part (type, i, valaddr,
1032 stream, recurse, options, comma_needed,
1033 outer_type, outer_valaddr);
1038 fprintf_filtered (stream, ", ");
1041 if (options->pretty)
1043 fprintf_filtered (stream, "\n");
1044 print_spaces_filtered (2 + 2 * recurse, stream);
1048 wrap_here (n_spaces (2 + 2 * recurse));
1050 if (options->inspect_it)
1052 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1053 fputs_filtered ("\"( ptr \"", stream);
1055 fputs_filtered ("\"( nodef \"", stream);
1056 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1057 language_cplus, DMGL_NO_OPTS);
1058 fputs_filtered ("\" \"", stream);
1059 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1060 language_cplus, DMGL_NO_OPTS);
1061 fputs_filtered ("\") \"", stream);
1065 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1066 fprintf_filtered (stream, "%.*s",
1067 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1068 TYPE_FIELD_NAME (type, i));
1069 annotate_field_name_end ();
1070 fputs_filtered (" => ", stream);
1071 annotate_field_value ();
1074 if (TYPE_FIELD_PACKED (type, i))
1078 /* Bitfields require special handling, especially due to byte
1080 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
1082 fputs_filtered (_("<optimized out or zero length>"), stream);
1086 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1087 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1088 struct value_print_options opts;
1090 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1091 v = ada_value_primitive_packed_val (NULL, valaddr,
1092 bit_pos / HOST_CHAR_BIT,
1093 bit_pos % HOST_CHAR_BIT,
1095 TYPE_FIELD_TYPE (type, i));
1098 val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0,
1099 stream, recurse + 1, &opts, current_language);
1104 struct value_print_options opts = *options;
1106 ada_val_print (TYPE_FIELD_TYPE (type, i),
1107 valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1108 0, 0, stream, recurse + 1, &opts);
1110 annotate_field_end ();
1113 return comma_needed;