1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988-1989, 1991-1994, 1997, 2001-2012 Free
4 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 3 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, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_string.h"
26 #include "expression.h"
35 #include "exceptions.h"
38 static void print_record (struct type *, const gdb_byte *, int,
42 const struct value_print_options *);
44 static int print_field_values (struct type *, const gdb_byte *,
46 struct ui_file *, int,
48 const struct value_print_options *,
49 int, struct type *, int);
51 static void adjust_type_signedness (struct type *);
53 static int ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR,
54 struct ui_file *, int,
56 const struct value_print_options *);
59 /* Make TYPE unsigned if its range of values includes no negatives. */
61 adjust_type_signedness (struct type *type)
63 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
64 && TYPE_LOW_BOUND (type) >= 0)
65 TYPE_UNSIGNED (type) = 1;
68 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
69 if non-standard (i.e., other than 1 for numbers, other than lower bound
70 of index type for enumerated type). Returns 1 if something printed,
74 print_optional_low_bound (struct ui_file *stream, struct type *type,
75 const struct value_print_options *options)
77 struct type *index_type;
81 if (options->print_array_indexes)
84 if (!get_array_bounds (type, &low_bound, &high_bound))
87 /* If this is an empty array, then don't print the lower bound.
88 That would be confusing, because we would print the lower bound,
89 followed by... nothing! */
90 if (low_bound > high_bound)
93 index_type = TYPE_INDEX_TYPE (type);
95 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
97 /* We need to know what the base type is, in order to do the
98 appropriate check below. Otherwise, if this is a subrange
99 of an enumerated type, where the underlying value of the
100 first element is typically 0, we might test the low bound
101 against the wrong value. */
102 index_type = TYPE_TARGET_TYPE (index_type);
105 switch (TYPE_CODE (index_type))
112 if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
115 case TYPE_CODE_UNDEF:
124 ada_print_scalar (index_type, low_bound, stream);
125 fprintf_filtered (stream, " => ");
129 /* Version of val_print_array_elements for GNAT-style packed arrays.
130 Prints elements of packed array of type TYPE at bit offset
131 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
132 separates with commas. RECURSE is the recursion (nesting) level.
133 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
136 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
138 int bitoffset, struct ui_file *stream,
140 const struct value *val,
141 const struct value_print_options *options)
144 unsigned int things_printed = 0;
146 struct type *elttype, *index_type;
148 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
149 struct value *mark = value_mark ();
152 elttype = TYPE_TARGET_TYPE (type);
153 eltlen = TYPE_LENGTH (check_typedef (elttype));
154 index_type = TYPE_INDEX_TYPE (type);
159 if (get_discrete_bounds (index_type, &low, &high) < 0)
162 len = high - low + 1;
166 annotate_array_section_begin (i, elttype);
168 while (i < len && things_printed < options->print_max)
170 struct value *v0, *v1;
175 if (options->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));
186 maybe_print_array_index (index_type, i + low, stream, options);
189 v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
190 (i0 * bitsize) / HOST_CHAR_BIT,
191 (i0 * bitsize) % HOST_CHAR_BIT,
198 v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
199 (i * bitsize) / HOST_CHAR_BIT,
200 (i * bitsize) % HOST_CHAR_BIT,
202 if (!value_available_contents_eq (v0, value_embedded_offset (v0),
203 v1, value_embedded_offset (v1),
208 if (i - i0 > options->repeat_count_threshold)
210 struct value_print_options opts = *options;
213 val_print (elttype, value_contents_for_printing (v0),
214 value_embedded_offset (v0), 0, stream,
215 recurse + 1, v0, &opts, current_language);
216 annotate_elt_rep (i - i0);
217 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
218 annotate_elt_rep_end ();
224 struct value_print_options opts = *options;
227 for (j = i0; j < i; j += 1)
231 if (options->prettyprint_arrays)
233 fprintf_filtered (stream, ",\n");
234 print_spaces_filtered (2 + 2 * recurse, stream);
238 fprintf_filtered (stream, ", ");
240 wrap_here (n_spaces (2 + 2 * recurse));
241 maybe_print_array_index (index_type, j + low,
244 val_print (elttype, value_contents_for_printing (v0),
245 value_embedded_offset (v0), 0, stream,
246 recurse + 1, v0, &opts, current_language);
250 things_printed += i - i0;
252 annotate_array_section_end ();
255 fprintf_filtered (stream, "...");
258 value_free_to_mark (mark);
262 printable_val_type (struct type *type, const gdb_byte *valaddr)
264 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
267 /* Print the character C on STREAM as part of the contents of a literal
268 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
272 ada_emit_char (int c, struct type *type, struct ui_file *stream,
273 int quoter, int type_len)
275 /* If this character fits in the normal ASCII range, and is
276 a printable character, then print the character as if it was
277 an ASCII character, even if this is a wide character.
278 The UCHAR_MAX check is necessary because the isascii function
279 requires that its argument have a value of an unsigned char,
280 or EOF (EOF is obviously not printable). */
281 if (c <= UCHAR_MAX && 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
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 + type_len * i,
303 type_len, byte_order);
306 /* Wrapper around memcpy to make it legal argument to ui_file_put. */
308 ui_memcpy (void *dest, const char *buffer, long len)
310 memcpy (dest, buffer, (size_t) len);
311 ((char *) dest)[len] = '\0';
314 /* Print a floating-point value of type TYPE, pointed to in GDB by
315 VALADDR, on STREAM. Use Ada formatting conventions: there must be
316 a decimal point, and at least one digit before and after the
317 point. We use GNAT format for NaNs and infinities. */
319 ada_print_floating (const gdb_byte *valaddr, struct type *type,
320 struct ui_file *stream)
325 struct ui_file *tmp_stream = mem_fileopen ();
326 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
328 print_floating (valaddr, type, tmp_stream);
329 ui_file_put (tmp_stream, ui_memcpy, buffer);
330 do_cleanups (cleanups);
333 len = strlen (result);
335 /* Modify for Ada rules. */
337 s = strstr (result, "inf");
339 s = strstr (result, "Inf");
341 s = strstr (result, "INF");
347 s = strstr (result, "nan");
349 s = strstr (result, "NaN");
351 s = strstr (result, "Nan");
355 if (result[0] == '-')
360 if (s == NULL && strchr (result, '.') == NULL)
362 s = strchr (result, 'e');
364 fprintf_filtered (stream, "%s.0", result);
366 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
369 fprintf_filtered (stream, "%s", result);
373 ada_printchar (int c, struct type *type, struct ui_file *stream)
375 fputs_filtered ("'", stream);
376 ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
377 fputs_filtered ("'", stream);
380 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
381 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
382 like a default signed integer. */
385 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
392 print_longest (stream, 'd', 0, val);
396 type = ada_check_typedef (type);
398 switch (TYPE_CODE (type))
402 len = TYPE_NFIELDS (type);
403 for (i = 0; i < len; i++)
405 if (TYPE_FIELD_BITPOS (type, i) == val)
412 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
416 print_longest (stream, 'd', 0, val);
421 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
425 LA_PRINT_CHAR (val, type, stream);
429 fprintf_filtered (stream, val ? "true" : "false");
432 case TYPE_CODE_RANGE:
433 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
436 case TYPE_CODE_UNDEF:
438 case TYPE_CODE_ARRAY:
439 case TYPE_CODE_STRUCT:
440 case TYPE_CODE_UNION:
445 case TYPE_CODE_STRING:
446 case TYPE_CODE_ERROR:
447 case TYPE_CODE_MEMBERPTR:
448 case TYPE_CODE_METHODPTR:
449 case TYPE_CODE_METHOD:
451 warning (_("internal error: unhandled type in ada_print_scalar"));
455 error (_("Invalid type code in symbol table."));
460 /* Print the character string STRING, printing at most LENGTH characters.
461 Printing stops early if the number hits print_max; repeat counts
462 are printed as appropriate. Print ellipses at the end if we
463 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
464 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,
559 const gdb_byte *string, unsigned int length,
560 const char *encoding, int force_ellipses,
561 const struct value_print_options *options)
563 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
568 /* See val_print for a description of the various parameters of this
569 function; they are identical. The semantics of the return value is
570 also identical to val_print. */
573 ada_val_print (struct type *type, const gdb_byte *valaddr,
574 int embedded_offset, CORE_ADDR address,
575 struct ui_file *stream, int recurse,
576 const struct value *val,
577 const struct value_print_options *options)
579 volatile struct gdb_exception except;
582 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */
583 TRY_CATCH (except, RETURN_MASK_ALL)
585 result = ada_val_print_1 (type, valaddr, embedded_offset, address,
586 stream, recurse, val, options);
589 if (except.reason < 0)
595 /* Assuming TYPE is a simple array, print the value of this array located
596 at VALADDR + OFFSET. See ada_val_print for a description of the various
597 parameters of this function; they are identical. The semantics
598 of the return value is also identical to ada_val_print. */
601 ada_val_print_array (struct type *type, const gdb_byte *valaddr,
602 int offset, CORE_ADDR address,
603 struct ui_file *stream, int recurse,
604 const struct value *val,
605 const struct value_print_options *options)
609 /* For an array of chars, print with string syntax. */
610 if (ada_is_string_type (type)
611 && (options->format == 0 || options->format == 's'))
613 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
614 struct type *elttype = TYPE_TARGET_TYPE (type);
618 /* We know that ELTTYPE cannot possibly be null, because we found
619 that TYPE is a string-like type. Similarly, the size of ELTTYPE
620 should also be non-null, since it's a character-like type. */
621 gdb_assert (elttype != NULL);
622 gdb_assert (TYPE_LENGTH (elttype) != 0);
624 eltlen = TYPE_LENGTH (elttype);
625 len = TYPE_LENGTH (type) / eltlen;
627 if (options->prettyprint_arrays)
628 print_spaces_filtered (2 + 2 * recurse, stream);
630 /* If requested, look for the first null char and only print
631 elements up to it. */
632 if (options->stop_print_at_null)
636 /* Look for a NULL char. */
639 && temp_len < options->print_max
640 && char_at (valaddr + offset,
641 temp_len, eltlen, byte_order) != 0);
646 printstr (stream, elttype, valaddr + offset, len, 0, eltlen, options);
651 fprintf_filtered (stream, "(");
652 print_optional_low_bound (stream, type, options);
653 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
654 val_print_packed_array_elements (type, valaddr, offset,
655 0, stream, recurse, val, options);
657 val_print_array_elements (type, valaddr, offset, address,
658 stream, recurse, val, options, 0);
659 fprintf_filtered (stream, ")");
665 /* See the comment on ada_val_print. This function differs in that it
666 does not catch evaluation errors (leaving that to ada_val_print). */
669 ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
670 int offset, CORE_ADDR address,
671 struct ui_file *stream, int recurse,
672 const struct value *original_value,
673 const struct value_print_options *options)
677 struct type *elttype;
681 type = ada_check_typedef (type);
683 if (ada_is_array_descriptor_type (type)
684 || (ada_is_constrained_packed_array_type (type)
685 && TYPE_CODE (type) != TYPE_CODE_PTR))
688 struct value *mark = value_mark ();
691 val = value_from_contents_and_address (type, valaddr + offset, address);
692 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
693 val = ada_coerce_to_simple_array_ptr (val);
695 val = ada_coerce_to_simple_array (val);
698 gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
699 fprintf_filtered (stream, "0x0");
703 retn = ada_val_print_1 (value_type (val),
704 value_contents_for_printing (val),
705 value_embedded_offset (val),
706 value_address (val), stream, recurse,
708 value_free_to_mark (mark);
712 offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
713 type = printable_val_type (type, valaddr + offset_aligned);
715 switch (TYPE_CODE (type))
718 return c_val_print (type, valaddr, offset, address, stream,
719 recurse, original_value, options);
723 int ret = c_val_print (type, valaddr, offset, address,
724 stream, recurse, original_value, options);
726 if (ada_is_tag_type (type))
729 value_from_contents_and_address (type,
730 valaddr + offset_aligned,
731 address + offset_aligned);
732 const char *name = ada_tag_name (val);
735 fprintf_filtered (stream, " (%s)", name);
742 case TYPE_CODE_RANGE:
743 if (ada_is_fixed_point_type (type))
745 LONGEST v = unpack_long (type, valaddr + offset_aligned);
746 int len = TYPE_LENGTH (type);
748 fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
749 (double) ada_fixed_to_float (type, v));
752 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
754 struct type *target_type = TYPE_TARGET_TYPE (type);
756 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
758 /* Obscure case of range type that has different length from
759 its base type. Perform a conversion, or we will get a
760 nonsense value. Actually, we could use the same
761 code regardless of lengths; I'm just avoiding a cast. */
763 = value_from_contents_and_address (type, valaddr + offset, 0);
764 struct value *v = value_cast (target_type, v1);
766 return ada_val_print_1 (target_type,
767 value_contents_for_printing (v),
768 value_embedded_offset (v), 0,
769 stream, recurse + 1, v, options);
772 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
774 address, stream, recurse,
775 original_value, options);
779 int format = (options->format ? options->format
780 : options->output_format);
784 struct value_print_options opts = *options;
786 opts.format = format;
787 val_print_scalar_formatted (type, valaddr, offset_aligned,
788 original_value, &opts, 0, stream);
790 else if (ada_is_system_address_type (type))
792 /* FIXME: We want to print System.Address variables using
793 the same format as for any access type. But for some
794 reason GNAT encodes the System.Address type as an int,
795 so we have to work-around this deficiency by handling
796 System.Address values as a special case. */
798 struct gdbarch *gdbarch = get_type_arch (type);
799 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
800 CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned,
803 fprintf_filtered (stream, "(");
804 type_print (type, "", stream, -1);
805 fprintf_filtered (stream, ") ");
806 fputs_filtered (paddress (gdbarch, addr), stream);
810 val_print_type_code_int (type, valaddr + offset_aligned, stream);
811 if (ada_is_character_type (type))
815 fputs_filtered (" ", stream);
816 c = unpack_long (type, valaddr + offset_aligned);
817 ada_printchar (c, type, stream);
826 val_print_scalar_formatted (type, valaddr, offset_aligned,
827 original_value, options, 0, stream);
830 len = TYPE_NFIELDS (type);
831 val = unpack_long (type, valaddr + offset_aligned);
832 for (i = 0; i < len; i++)
835 if (val == TYPE_FIELD_BITPOS (type, i))
842 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
845 fprintf_filtered (stream, "%ld %s", (long) val, name);
847 fputs_filtered (name, stream);
851 print_longest (stream, 'd', 0, val);
855 case TYPE_CODE_FLAGS:
857 val_print_scalar_formatted (type, valaddr, offset_aligned,
858 original_value, options, 0, stream);
860 val_print_type_code_flags (type, valaddr + offset_aligned, stream);
865 return c_val_print (type, valaddr, offset, address, stream,
866 recurse, original_value, options);
868 ada_print_floating (valaddr + offset, type, stream);
871 case TYPE_CODE_UNION:
872 case TYPE_CODE_STRUCT:
873 if (ada_is_bogus_array_descriptor (type))
875 fprintf_filtered (stream, "(...?)");
880 print_record (type, valaddr, offset_aligned,
881 stream, recurse, original_value, options);
885 case TYPE_CODE_ARRAY:
886 return ada_val_print_array (type, valaddr, offset_aligned,
887 address, stream, recurse, original_value,
891 /* For references, the debugger is expected to print the value as
892 an address if DEREF_REF is null. But printing an address in place
893 of the object value would be confusing to an Ada programmer.
894 So, for Ada values, we print the actual dereferenced value
896 elttype = check_typedef (TYPE_TARGET_TYPE (type));
898 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
900 CORE_ADDR deref_val_int;
901 struct value *deref_val;
903 deref_val = coerce_ref_if_computed (original_value);
906 common_val_print (deref_val, stream, recurse + 1, options,
911 deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
912 if (deref_val_int != 0)
914 struct value *deref_val =
915 ada_value_ind (value_from_pointer
916 (lookup_pointer_type (elttype),
919 val_print (value_type (deref_val),
920 value_contents_for_printing (deref_val),
921 value_embedded_offset (deref_val),
922 value_address (deref_val), stream, recurse + 1,
923 deref_val, options, current_language);
926 fputs_filtered ("(null)", stream);
929 fputs_filtered ("???", stream);
938 print_variant_part (struct type *type, int field_num,
939 const gdb_byte *valaddr, int offset,
940 struct ui_file *stream, int recurse,
941 const struct value *val,
942 const struct value_print_options *options,
944 struct type *outer_type, int outer_offset)
946 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
947 int which = ada_which_variant_applies (var_type, outer_type,
948 valaddr + outer_offset);
953 return print_field_values
954 (TYPE_FIELD_TYPE (var_type, which),
956 offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
957 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
958 stream, recurse, val, options,
959 comma_needed, outer_type, outer_offset);
963 ada_value_print (struct value *val0, struct ui_file *stream,
964 const struct value_print_options *options)
966 struct value *val = ada_to_fixed_value (val0);
967 CORE_ADDR address = value_address (val);
968 struct type *type = ada_check_typedef (value_type (val));
969 struct value_print_options opts;
971 /* If it is a pointer, indicate what it points to. */
972 if (TYPE_CODE (type) == TYPE_CODE_PTR)
974 /* Hack: don't print (char *) for char strings. Their
975 type is indicated by the quoted string anyway. */
976 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
977 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
978 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
980 fprintf_filtered (stream, "(");
981 type_print (type, "", stream, -1);
982 fprintf_filtered (stream, ") ");
985 else if (ada_is_array_descriptor_type (type))
987 /* We do not print the type description unless TYPE is an array
988 access type (this is encoded by the compiler as a typedef to
989 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
990 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
992 fprintf_filtered (stream, "(");
993 type_print (type, "", stream, -1);
994 fprintf_filtered (stream, ") ");
997 else if (ada_is_bogus_array_descriptor (type))
999 fprintf_filtered (stream, "(");
1000 type_print (type, "", stream, -1);
1001 fprintf_filtered (stream, ") (...?)");
1007 return (val_print (type, value_contents_for_printing (val),
1008 value_embedded_offset (val), address,
1009 stream, 0, val, &opts, current_language));
1013 print_record (struct type *type, const gdb_byte *valaddr,
1015 struct ui_file *stream, int recurse,
1016 const struct value *val,
1017 const struct value_print_options *options)
1019 type = ada_check_typedef (type);
1021 fprintf_filtered (stream, "(");
1023 if (print_field_values (type, valaddr, offset,
1024 stream, recurse, val, options,
1025 0, type, offset) != 0 && options->pretty)
1027 fprintf_filtered (stream, "\n");
1028 print_spaces_filtered (2 * recurse, stream);
1031 fprintf_filtered (stream, ")");
1034 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
1036 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
1037 meanings as in ada_print_value and ada_val_print.
1039 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
1040 record (used to get discriminant values when printing variant
1043 COMMA_NEEDED is 1 if fields have been printed at the current recursion
1044 level, so that a comma is needed before any field printed by this
1047 Returns 1 if COMMA_NEEDED or any fields were printed. */
1050 print_field_values (struct type *type, const gdb_byte *valaddr,
1051 int offset, struct ui_file *stream, int recurse,
1052 const struct value *val,
1053 const struct value_print_options *options,
1055 struct type *outer_type, int outer_offset)
1059 len = TYPE_NFIELDS (type);
1061 for (i = 0; i < len; i += 1)
1063 if (ada_is_ignored_field (type, i))
1066 if (ada_is_wrapper_field (type, i))
1069 print_field_values (TYPE_FIELD_TYPE (type, i),
1072 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
1073 stream, recurse, val, options,
1074 comma_needed, type, offset);
1077 else if (ada_is_variant_part (type, i))
1080 print_variant_part (type, i, valaddr,
1081 offset, stream, recurse, val,
1082 options, comma_needed,
1083 outer_type, outer_offset);
1088 fprintf_filtered (stream, ", ");
1091 if (options->pretty)
1093 fprintf_filtered (stream, "\n");
1094 print_spaces_filtered (2 + 2 * recurse, stream);
1098 wrap_here (n_spaces (2 + 2 * recurse));
1100 if (options->inspect_it)
1102 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1103 fputs_filtered ("\"( ptr \"", stream);
1105 fputs_filtered ("\"( nodef \"", stream);
1106 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1107 language_cplus, DMGL_NO_OPTS);
1108 fputs_filtered ("\" \"", stream);
1109 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1110 language_cplus, DMGL_NO_OPTS);
1111 fputs_filtered ("\") \"", stream);
1115 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1116 fprintf_filtered (stream, "%.*s",
1117 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1118 TYPE_FIELD_NAME (type, i));
1119 annotate_field_name_end ();
1120 fputs_filtered (" => ", stream);
1121 annotate_field_value ();
1124 if (TYPE_FIELD_PACKED (type, i))
1128 /* Bitfields require special handling, especially due to byte
1130 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
1132 fputs_filtered (_("<optimized out or zero length>"), stream);
1136 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1137 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1138 struct value_print_options opts;
1140 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1141 v = ada_value_primitive_packed_val
1143 offset + bit_pos / HOST_CHAR_BIT,
1144 bit_pos % HOST_CHAR_BIT,
1145 bit_size, TYPE_FIELD_TYPE (type, i));
1148 val_print (TYPE_FIELD_TYPE (type, i),
1149 value_contents_for_printing (v),
1150 value_embedded_offset (v), 0,
1151 stream, recurse + 1, v,
1152 &opts, current_language);
1157 struct value_print_options opts = *options;
1160 ada_val_print (TYPE_FIELD_TYPE (type, i),
1163 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
1164 0, stream, recurse + 1, val, &opts);
1166 annotate_field_end ();
1169 return comma_needed;