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, 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);
167 if (get_discrete_bounds (index_type, &low, &high) < 0)
170 len = high - low + 1;
174 annotate_array_section_begin (i, elttype);
176 while (i < len && things_printed < options->print_max)
178 struct value *v0, *v1;
183 if (options->prettyprint_arrays)
185 fprintf_filtered (stream, ",\n");
186 print_spaces_filtered (2 + 2 * recurse, stream);
190 fprintf_filtered (stream, ", ");
193 wrap_here (n_spaces (2 + 2 * recurse));
194 maybe_print_array_index (index_type, i + low, stream, options);
197 v0 = ada_value_primitive_packed_val (NULL, valaddr,
198 (i0 * bitsize) / HOST_CHAR_BIT,
199 (i0 * bitsize) % HOST_CHAR_BIT,
206 v1 = ada_value_primitive_packed_val (NULL, valaddr,
207 (i * bitsize) / HOST_CHAR_BIT,
208 (i * bitsize) % HOST_CHAR_BIT,
210 if (memcmp (value_contents (v0), value_contents (v1), eltlen) != 0)
214 if (i - i0 > options->repeat_count_threshold)
216 struct value_print_options opts = *options;
219 val_print (elttype, value_contents (v0), 0, 0, stream,
220 recurse + 1, &opts, current_language);
221 annotate_elt_rep (i - i0);
222 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
223 annotate_elt_rep_end ();
229 struct value_print_options opts = *options;
232 for (j = i0; j < i; j += 1)
236 if (options->prettyprint_arrays)
238 fprintf_filtered (stream, ",\n");
239 print_spaces_filtered (2 + 2 * recurse, stream);
243 fprintf_filtered (stream, ", ");
245 wrap_here (n_spaces (2 + 2 * recurse));
246 maybe_print_array_index (index_type, j + low,
249 val_print (elttype, value_contents (v0), 0, 0, stream,
250 recurse + 1, &opts, current_language);
254 things_printed += i - i0;
256 annotate_array_section_end ();
259 fprintf_filtered (stream, "...");
262 value_free_to_mark (mark);
266 printable_val_type (struct type *type, const gdb_byte *valaddr)
268 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
271 /* Print the character C on STREAM as part of the contents of a literal
272 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
273 (1 or 2) of the character. */
276 ada_emit_char (int c, struct type *type, struct ui_file *stream,
277 int quoter, int type_len)
282 c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1;
284 if (isascii (c) && isprint (c))
286 if (c == quoter && c == '"')
287 fprintf_filtered (stream, "\"\"");
289 fprintf_filtered (stream, "%c", c);
292 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
295 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
296 or 2) of a character. */
299 char_at (const gdb_byte *string, int i, int type_len,
300 enum bfd_endian byte_order)
305 return (int) extract_unsigned_integer (string + 2 * i, 2, byte_order);
308 /* Wrapper around memcpy to make it legal argument to ui_file_put */
310 ui_memcpy (void *dest, const char *buffer, long len)
312 memcpy (dest, buffer, (size_t) len);
313 ((char *) dest)[len] = '\0';
316 /* Print a floating-point value of type TYPE, pointed to in GDB by
317 VALADDR, on STREAM. Use Ada formatting conventions: there must be
318 a decimal point, and at least one digit before and after the
319 point. We use GNAT format for NaNs and infinities. */
321 ada_print_floating (const gdb_byte *valaddr, struct type *type,
322 struct ui_file *stream)
327 struct ui_file *tmp_stream = mem_fileopen ();
328 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
330 print_floating (valaddr, type, tmp_stream);
331 ui_file_put (tmp_stream, ui_memcpy, buffer);
332 do_cleanups (cleanups);
335 len = strlen (result);
337 /* Modify for Ada rules. */
339 s = strstr (result, "inf");
341 s = strstr (result, "Inf");
343 s = strstr (result, "INF");
349 s = strstr (result, "nan");
351 s = strstr (result, "NaN");
353 s = strstr (result, "Nan");
357 if (result[0] == '-')
362 if (s == NULL && strchr (result, '.') == NULL)
364 s = strchr (result, 'e');
366 fprintf_filtered (stream, "%s.0", result);
368 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
371 fprintf_filtered (stream, "%s", result);
375 ada_printchar (int c, struct type *type, struct ui_file *stream)
377 fputs_filtered ("'", stream);
378 ada_emit_char (c, type, stream, '\'', 1);
379 fputs_filtered ("'", stream);
382 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
383 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
384 like a default signed integer. */
387 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
394 print_longest (stream, 'd', 0, val);
398 type = ada_check_typedef (type);
400 switch (TYPE_CODE (type))
404 len = TYPE_NFIELDS (type);
405 for (i = 0; i < len; i++)
407 if (TYPE_FIELD_BITPOS (type, i) == val)
414 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
418 print_longest (stream, 'd', 0, val);
423 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
427 LA_PRINT_CHAR ((unsigned char) val, type, stream);
431 fprintf_filtered (stream, val ? "true" : "false");
434 case TYPE_CODE_RANGE:
435 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
438 case TYPE_CODE_UNDEF:
440 case TYPE_CODE_ARRAY:
441 case TYPE_CODE_STRUCT:
442 case TYPE_CODE_UNION:
447 case TYPE_CODE_STRING:
448 case TYPE_CODE_ERROR:
449 case TYPE_CODE_MEMBERPTR:
450 case TYPE_CODE_METHODPTR:
451 case TYPE_CODE_METHOD:
453 warning (_("internal error: unhandled type in ada_print_scalar"));
457 error (_("Invalid type code in symbol table."));
462 /* Print the character string STRING, printing at most LENGTH characters.
463 Printing stops early if the number hits print_max; repeat counts
464 are printed as appropriate. Print ellipses at the end if we
465 had to stop before printing LENGTH characters, or if
466 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
470 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
471 unsigned int length, int force_ellipses, int type_len,
472 const struct value_print_options *options)
474 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype));
476 unsigned int things_printed = 0;
482 fputs_filtered ("\"\"", stream);
486 for (i = 0; i < length && things_printed < options->print_max; i += 1)
488 /* Position of the character we are examining
489 to see whether it is repeated. */
491 /* Number of repetitions we have detected so far. */
498 fputs_filtered (", ", stream);
505 && char_at (string, rep1, type_len, byte_order)
506 == char_at (string, i, type_len, byte_order))
512 if (reps > options->repeat_count_threshold)
516 if (options->inspect_it)
517 fputs_filtered ("\\\", ", stream);
519 fputs_filtered ("\", ", stream);
522 fputs_filtered ("'", stream);
523 ada_emit_char (char_at (string, i, type_len, byte_order),
524 elttype, stream, '\'', type_len);
525 fputs_filtered ("'", stream);
526 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
528 things_printed += options->repeat_count_threshold;
535 if (options->inspect_it)
536 fputs_filtered ("\\\"", stream);
538 fputs_filtered ("\"", stream);
541 ada_emit_char (char_at (string, i, type_len, byte_order),
542 elttype, stream, '"', type_len);
547 /* Terminate the quotes if necessary. */
550 if (options->inspect_it)
551 fputs_filtered ("\\\"", stream);
553 fputs_filtered ("\"", stream);
556 if (force_ellipses || i < length)
557 fputs_filtered ("...", stream);
561 ada_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
562 unsigned int length, const char *encoding, int force_ellipses,
563 const struct value_print_options *options)
565 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
570 /* Print data of type TYPE located at VALADDR (within GDB), which came from
571 the inferior at address ADDRESS, onto stdio stream STREAM according to
572 OPTIONS. The data at VALADDR is in target byte order.
574 If the data is printed as a string, returns the number of string characters
577 RECURSE indicates the amount of indentation to supply before
578 continuation lines; this amount is roughly twice the value of RECURSE. */
581 ada_val_print (struct type *type, const gdb_byte *valaddr0,
582 int embedded_offset, CORE_ADDR address,
583 struct ui_file *stream, int recurse,
584 const struct value_print_options *options)
586 struct ada_val_print_args args;
588 args.valaddr0 = valaddr0;
589 args.embedded_offset = embedded_offset;
590 args.address = address;
591 args.stream = stream;
592 args.recurse = recurse;
593 args.options = options;
595 return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL);
598 /* Helper for ada_val_print; used as argument to catch_errors to
599 unmarshal the arguments to ada_val_print_1, which does the work. */
601 ada_val_print_stub (void *args0)
603 struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0;
605 return ada_val_print_1 (argsp->type, argsp->valaddr0,
606 argsp->embedded_offset, argsp->address,
607 argsp->stream, argsp->recurse, argsp->options);
610 /* Assuming TYPE is a simple array, print the value of this array located
611 at VALADDR. See ada_val_print for a description of the various
612 parameters of this function; they are identical. The semantics
613 of the return value is also identical to ada_val_print. */
616 ada_val_print_array (struct type *type, const gdb_byte *valaddr,
617 CORE_ADDR address, struct ui_file *stream, int recurse,
618 const struct value_print_options *options)
620 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
621 struct type *elttype = TYPE_TARGET_TYPE (type);
629 eltlen = TYPE_LENGTH (elttype);
633 len = TYPE_LENGTH (type) / eltlen;
635 /* For an array of chars, print with string syntax. */
636 if (ada_is_string_type (type)
637 && (options->format == 0 || options->format == 's'))
639 if (options->prettyprint_arrays)
640 print_spaces_filtered (2 + 2 * recurse, stream);
642 /* If requested, look for the first null char and only print
643 elements up to it. */
644 if (options->stop_print_at_null)
648 /* Look for a NULL char. */
651 && temp_len < options->print_max
652 && char_at (valaddr, temp_len, eltlen, byte_order) != 0);
657 printstr (stream, elttype, valaddr, len, 0, eltlen, options);
662 fprintf_filtered (stream, "(");
663 print_optional_low_bound (stream, type, options);
664 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
665 val_print_packed_array_elements (type, valaddr, 0, stream,
668 val_print_array_elements (type, valaddr, address, stream,
669 recurse, options, 0);
670 fprintf_filtered (stream, ")");
676 /* See the comment on ada_val_print. This function differs in that it
677 does not catch evaluation errors (leaving that to ada_val_print). */
680 ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
681 int embedded_offset, CORE_ADDR address,
682 struct ui_file *stream, int recurse,
683 const struct value_print_options *options)
687 struct type *elttype;
689 const gdb_byte *valaddr = valaddr0 + embedded_offset;
691 type = ada_check_typedef (type);
693 if (ada_is_array_descriptor_type (type)
694 || ada_is_constrained_packed_array_type (type))
697 struct value *mark = value_mark ();
700 val = value_from_contents_and_address (type, valaddr, address);
701 val = ada_coerce_to_simple_array_ptr (val);
704 fprintf_filtered (stream, "(null)");
708 retn = ada_val_print_1 (value_type (val), value_contents (val), 0,
709 value_address (val), stream, recurse, options);
710 value_free_to_mark (mark);
714 valaddr = ada_aligned_value_addr (type, valaddr);
715 embedded_offset -= valaddr - valaddr0 - embedded_offset;
716 type = printable_val_type (type, valaddr);
718 switch (TYPE_CODE (type))
721 return c_val_print (type, valaddr0, embedded_offset, address, stream,
726 int ret = c_val_print (type, valaddr0, embedded_offset, address,
727 stream, recurse, options);
729 if (ada_is_tag_type (type))
732 value_from_contents_and_address (type, valaddr, address);
733 const char *name = ada_tag_name (val);
736 fprintf_filtered (stream, " (%s)", name);
743 case TYPE_CODE_RANGE:
744 if (ada_is_fixed_point_type (type))
746 LONGEST v = unpack_long (type, valaddr);
747 int len = TYPE_LENGTH (type);
749 fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
750 (double) ada_fixed_to_float (type, v));
753 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
755 struct type *target_type = TYPE_TARGET_TYPE (type);
757 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
759 /* Obscure case of range type that has different length from
760 its base type. Perform a conversion, or we will get a
761 nonsense value. Actually, we could use the same
762 code regardless of lengths; I'm just avoiding a cast. */
763 struct value *v = value_cast (target_type,
764 value_from_contents_and_address
767 return ada_val_print_1 (target_type, value_contents (v), 0, 0,
768 stream, recurse + 1, options);
771 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
772 valaddr0, embedded_offset,
773 address, stream, recurse, options);
777 int format = (options->format ? options->format
778 : options->output_format);
782 struct value_print_options opts = *options;
784 opts.format = format;
785 print_scalar_formatted (valaddr, type, &opts, 0, stream);
787 else if (ada_is_system_address_type (type))
789 /* FIXME: We want to print System.Address variables using
790 the same format as for any access type. But for some
791 reason GNAT encodes the System.Address type as an int,
792 so we have to work-around this deficiency by handling
793 System.Address values as a special case. */
795 struct gdbarch *gdbarch = get_type_arch (type);
796 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
797 CORE_ADDR addr = extract_typed_address (valaddr, ptr_type);
799 fprintf_filtered (stream, "(");
800 type_print (type, "", stream, -1);
801 fprintf_filtered (stream, ") ");
802 fputs_filtered (paddress (gdbarch, addr), stream);
806 val_print_type_code_int (type, valaddr, stream);
807 if (ada_is_character_type (type))
809 fputs_filtered (" ", stream);
810 ada_printchar ((unsigned char) unpack_long (type, valaddr),
820 print_scalar_formatted (valaddr, type, options, 0, stream);
823 len = TYPE_NFIELDS (type);
824 val = unpack_long (type, valaddr);
825 for (i = 0; i < len; i++)
828 if (val == TYPE_FIELD_BITPOS (type, i))
835 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
838 fprintf_filtered (stream, "%ld %s", (long) val, name);
840 fputs_filtered (name, stream);
844 print_longest (stream, 'd', 0, val);
848 case TYPE_CODE_FLAGS:
850 print_scalar_formatted (valaddr, type, options, 0, stream);
852 val_print_type_code_flags (type, valaddr, stream);
857 return c_val_print (type, valaddr0, embedded_offset, address, stream,
860 ada_print_floating (valaddr0 + embedded_offset, type, stream);
863 case TYPE_CODE_UNION:
864 case TYPE_CODE_STRUCT:
865 if (ada_is_bogus_array_descriptor (type))
867 fprintf_filtered (stream, "(...?)");
872 print_record (type, valaddr, stream, recurse, options);
876 case TYPE_CODE_ARRAY:
877 return ada_val_print_array (type, valaddr, address, stream,
881 /* For references, the debugger is expected to print the value as
882 an address if DEREF_REF is null. But printing an address in place
883 of the object value would be confusing to an Ada programmer.
884 So, for Ada values, we print the actual dereferenced value
886 elttype = check_typedef (TYPE_TARGET_TYPE (type));
888 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
890 LONGEST deref_val_int = (LONGEST) unpack_pointer (type, valaddr);
892 if (deref_val_int != 0)
894 struct value *deref_val =
895 ada_value_ind (value_from_longest
896 (lookup_pointer_type (elttype),
899 val_print (value_type (deref_val),
900 value_contents (deref_val), 0,
901 value_address (deref_val), stream, recurse + 1,
902 options, current_language);
905 fputs_filtered ("(null)", stream);
908 fputs_filtered ("???", stream);
917 print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr,
918 struct ui_file *stream, int recurse,
919 const struct value_print_options *options, int comma_needed,
920 struct type *outer_type, const gdb_byte *outer_valaddr)
922 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
923 int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr);
928 return print_field_values
929 (TYPE_FIELD_TYPE (var_type, which),
930 valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
931 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
932 stream, recurse, options,
933 comma_needed, outer_type, outer_valaddr);
937 ada_value_print (struct value *val0, struct ui_file *stream,
938 const struct value_print_options *options)
940 struct value *val = ada_to_fixed_value (val0);
941 CORE_ADDR address = value_address (val);
942 struct type *type = value_type (val);
943 struct value_print_options opts;
945 /* If it is a pointer, indicate what it points to. */
946 if (TYPE_CODE (type) == TYPE_CODE_PTR)
948 /* Hack: don't print (char *) for char strings. Their
949 type is indicated by the quoted string anyway. */
950 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
951 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
952 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
954 fprintf_filtered (stream, "(");
955 type_print (type, "", stream, -1);
956 fprintf_filtered (stream, ") ");
959 else if (ada_is_array_descriptor_type (type))
961 fprintf_filtered (stream, "(");
962 type_print (type, "", stream, -1);
963 fprintf_filtered (stream, ") ");
965 else if (ada_is_bogus_array_descriptor (type))
967 fprintf_filtered (stream, "(");
968 type_print (type, "", stream, -1);
969 fprintf_filtered (stream, ") (...?)");
975 return (val_print (type, value_contents (val), 0, address,
976 stream, 0, &opts, current_language));
980 print_record (struct type *type, const gdb_byte *valaddr,
981 struct ui_file *stream, int recurse,
982 const struct value_print_options *options)
984 type = ada_check_typedef (type);
986 fprintf_filtered (stream, "(");
988 if (print_field_values (type, valaddr, stream, recurse, options,
989 0, type, valaddr) != 0 && options->pretty)
991 fprintf_filtered (stream, "\n");
992 print_spaces_filtered (2 * recurse, stream);
995 fprintf_filtered (stream, ")");
998 /* Print out fields of value at VALADDR having structure type TYPE.
1000 TYPE, VALADDR, STREAM, RECURSE, and OPTIONS have the
1001 same meanings as in ada_print_value and ada_val_print.
1003 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
1004 (used to get discriminant values when printing variant parts).
1006 COMMA_NEEDED is 1 if fields have been printed at the current recursion
1007 level, so that a comma is needed before any field printed by this
1010 Returns 1 if COMMA_NEEDED or any fields were printed. */
1013 print_field_values (struct type *type, const gdb_byte *valaddr,
1014 struct ui_file *stream, int recurse,
1015 const struct value_print_options *options,
1017 struct type *outer_type, const gdb_byte *outer_valaddr)
1021 len = TYPE_NFIELDS (type);
1023 for (i = 0; i < len; i += 1)
1025 if (ada_is_ignored_field (type, i))
1028 if (ada_is_wrapper_field (type, i))
1031 print_field_values (TYPE_FIELD_TYPE (type, i),
1033 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1034 stream, recurse, options,
1035 comma_needed, type, valaddr);
1038 else if (ada_is_variant_part (type, i))
1041 print_variant_part (type, i, valaddr,
1042 stream, recurse, options, comma_needed,
1043 outer_type, outer_valaddr);
1048 fprintf_filtered (stream, ", ");
1051 if (options->pretty)
1053 fprintf_filtered (stream, "\n");
1054 print_spaces_filtered (2 + 2 * recurse, stream);
1058 wrap_here (n_spaces (2 + 2 * recurse));
1060 if (options->inspect_it)
1062 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1063 fputs_filtered ("\"( ptr \"", stream);
1065 fputs_filtered ("\"( nodef \"", stream);
1066 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1067 language_cplus, DMGL_NO_OPTS);
1068 fputs_filtered ("\" \"", stream);
1069 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1070 language_cplus, DMGL_NO_OPTS);
1071 fputs_filtered ("\") \"", stream);
1075 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1076 fprintf_filtered (stream, "%.*s",
1077 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1078 TYPE_FIELD_NAME (type, i));
1079 annotate_field_name_end ();
1080 fputs_filtered (" => ", stream);
1081 annotate_field_value ();
1084 if (TYPE_FIELD_PACKED (type, i))
1088 /* Bitfields require special handling, especially due to byte
1090 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
1092 fputs_filtered (_("<optimized out or zero length>"), stream);
1096 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1097 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1098 struct value_print_options opts;
1100 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1101 v = ada_value_primitive_packed_val (NULL, valaddr,
1102 bit_pos / HOST_CHAR_BIT,
1103 bit_pos % HOST_CHAR_BIT,
1105 TYPE_FIELD_TYPE (type, i));
1108 val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0,
1109 stream, recurse + 1, &opts, current_language);
1114 struct value_print_options opts = *options;
1117 ada_val_print (TYPE_FIELD_TYPE (type, i),
1118 valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
1119 0, 0, stream, recurse + 1, &opts);
1121 annotate_field_end ();
1124 return comma_needed;