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, 2011
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 static void print_record (struct type *, const gdb_byte *, int,
43 const struct value_print_options *);
45 static int print_field_values (struct type *, const gdb_byte *,
47 struct ui_file *, int,
49 const struct value_print_options *,
50 int, struct type *, int);
52 static void adjust_type_signedness (struct type *);
54 static int ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR,
55 struct ui_file *, int,
57 const struct value_print_options *);
60 /* Make TYPE unsigned if its range of values includes no negatives. */
62 adjust_type_signedness (struct type *type)
64 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
65 && TYPE_LOW_BOUND (type) >= 0)
66 TYPE_UNSIGNED (type) = 1;
69 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
70 if non-standard (i.e., other than 1 for numbers, other than lower bound
71 of index type for enumerated type). Returns 1 if something printed,
75 print_optional_low_bound (struct ui_file *stream, struct type *type,
76 const struct value_print_options *options)
78 struct type *index_type;
82 if (options->print_array_indexes)
85 if (!get_array_bounds (type, &low_bound, &high_bound))
88 /* If this is an empty array, then don't print the lower bound.
89 That would be confusing, because we would print the lower bound,
90 followed by... nothing! */
91 if (low_bound > high_bound)
94 index_type = TYPE_INDEX_TYPE (type);
96 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
98 /* We need to know what the base type is, in order to do the
99 appropriate check below. Otherwise, if this is a subrange
100 of an enumerated type, where the underlying value of the
101 first element is typically 0, we might test the low bound
102 against the wrong value. */
103 index_type = TYPE_TARGET_TYPE (index_type);
106 switch (TYPE_CODE (index_type))
113 if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
116 case TYPE_CODE_UNDEF:
125 ada_print_scalar (index_type, low_bound, stream);
126 fprintf_filtered (stream, " => ");
130 /* Version of val_print_array_elements for GNAT-style packed arrays.
131 Prints elements of packed array of type TYPE at bit offset
132 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
133 separates with commas. RECURSE is the recursion (nesting) level.
134 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
137 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
139 int bitoffset, struct ui_file *stream,
141 const struct value *val,
142 const struct value_print_options *options)
145 unsigned int things_printed = 0;
147 struct type *elttype, *index_type;
149 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
150 struct value *mark = value_mark ();
153 elttype = TYPE_TARGET_TYPE (type);
154 eltlen = TYPE_LENGTH (check_typedef (elttype));
155 index_type = TYPE_INDEX_TYPE (type);
160 if (get_discrete_bounds (index_type, &low, &high) < 0)
163 len = high - low + 1;
167 annotate_array_section_begin (i, elttype);
169 while (i < len && things_printed < options->print_max)
171 struct value *v0, *v1;
176 if (options->prettyprint_arrays)
178 fprintf_filtered (stream, ",\n");
179 print_spaces_filtered (2 + 2 * recurse, stream);
183 fprintf_filtered (stream, ", ");
186 wrap_here (n_spaces (2 + 2 * recurse));
187 maybe_print_array_index (index_type, i + low, stream, options);
190 v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
191 (i0 * bitsize) / HOST_CHAR_BIT,
192 (i0 * bitsize) % HOST_CHAR_BIT,
199 v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
200 (i * bitsize) / HOST_CHAR_BIT,
201 (i * bitsize) % HOST_CHAR_BIT,
203 if (!value_available_contents_eq (v0, value_embedded_offset (v0),
204 v1, value_embedded_offset (v1),
209 if (i - i0 > options->repeat_count_threshold)
211 struct value_print_options opts = *options;
214 val_print (elttype, value_contents_for_printing (v0),
215 value_embedded_offset (v0), 0, stream,
216 recurse + 1, v0, &opts, current_language);
217 annotate_elt_rep (i - i0);
218 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
219 annotate_elt_rep_end ();
225 struct value_print_options opts = *options;
228 for (j = i0; j < i; j += 1)
232 if (options->prettyprint_arrays)
234 fprintf_filtered (stream, ",\n");
235 print_spaces_filtered (2 + 2 * recurse, stream);
239 fprintf_filtered (stream, ", ");
241 wrap_here (n_spaces (2 + 2 * recurse));
242 maybe_print_array_index (index_type, j + low,
245 val_print (elttype, value_contents_for_printing (v0),
246 value_embedded_offset (v0), 0, stream,
247 recurse + 1, v0, &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
273 ada_emit_char (int c, struct type *type, struct ui_file *stream,
274 int quoter, int type_len)
276 /* If this character fits in the normal ASCII range, and is
277 a printable character, then print the character as if it was
278 an ASCII character, even if this is a wide character.
279 The UCHAR_MAX check is necessary because the isascii function
280 requires that its argument have a value of an unsigned char,
281 or EOF (EOF is obviously not printable). */
282 if (c <= UCHAR_MAX && isascii (c) && isprint (c))
284 if (c == quoter && c == '"')
285 fprintf_filtered (stream, "\"\"");
287 fprintf_filtered (stream, "%c", c);
290 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
293 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
297 char_at (const gdb_byte *string, int i, int type_len,
298 enum bfd_endian byte_order)
303 return (int) extract_unsigned_integer (string + type_len * i,
304 type_len, byte_order);
307 /* Wrapper around memcpy to make it legal argument to ui_file_put. */
309 ui_memcpy (void *dest, const char *buffer, long len)
311 memcpy (dest, buffer, (size_t) len);
312 ((char *) dest)[len] = '\0';
315 /* Print a floating-point value of type TYPE, pointed to in GDB by
316 VALADDR, on STREAM. Use Ada formatting conventions: there must be
317 a decimal point, and at least one digit before and after the
318 point. We use GNAT format for NaNs and infinities. */
320 ada_print_floating (const gdb_byte *valaddr, struct type *type,
321 struct ui_file *stream)
326 struct ui_file *tmp_stream = mem_fileopen ();
327 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
329 print_floating (valaddr, type, tmp_stream);
330 ui_file_put (tmp_stream, ui_memcpy, buffer);
331 do_cleanups (cleanups);
334 len = strlen (result);
336 /* Modify for Ada rules. */
338 s = strstr (result, "inf");
340 s = strstr (result, "Inf");
342 s = strstr (result, "INF");
348 s = strstr (result, "nan");
350 s = strstr (result, "NaN");
352 s = strstr (result, "Nan");
356 if (result[0] == '-')
361 if (s == NULL && strchr (result, '.') == NULL)
363 s = strchr (result, 'e');
365 fprintf_filtered (stream, "%s.0", result);
367 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
370 fprintf_filtered (stream, "%s", result);
374 ada_printchar (int c, struct type *type, struct ui_file *stream)
376 fputs_filtered ("'", stream);
377 ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
378 fputs_filtered ("'", stream);
381 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
382 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
383 like a default signed integer. */
386 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
393 print_longest (stream, 'd', 0, val);
397 type = ada_check_typedef (type);
399 switch (TYPE_CODE (type))
403 len = TYPE_NFIELDS (type);
404 for (i = 0; i < len; i++)
406 if (TYPE_FIELD_BITPOS (type, i) == val)
413 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
417 print_longest (stream, 'd', 0, val);
422 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
426 LA_PRINT_CHAR (val, type, stream);
430 fprintf_filtered (stream, val ? "true" : "false");
433 case TYPE_CODE_RANGE:
434 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
437 case TYPE_CODE_UNDEF:
439 case TYPE_CODE_ARRAY:
440 case TYPE_CODE_STRUCT:
441 case TYPE_CODE_UNION:
446 case TYPE_CODE_STRING:
447 case TYPE_CODE_ERROR:
448 case TYPE_CODE_MEMBERPTR:
449 case TYPE_CODE_METHODPTR:
450 case TYPE_CODE_METHOD:
452 warning (_("internal error: unhandled type in ada_print_scalar"));
456 error (_("Invalid type code in symbol table."));
461 /* Print the character string STRING, printing at most LENGTH characters.
462 Printing stops early if the number hits print_max; repeat counts
463 are printed as appropriate. Print ellipses at the end if we
464 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
465 TYPE_LEN is the length (1 or 2) of the character type. */
468 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
469 unsigned int length, int force_ellipses, int type_len,
470 const struct value_print_options *options)
472 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype));
474 unsigned int things_printed = 0;
480 fputs_filtered ("\"\"", stream);
484 for (i = 0; i < length && things_printed < options->print_max; i += 1)
486 /* Position of the character we are examining
487 to see whether it is repeated. */
489 /* Number of repetitions we have detected so far. */
496 fputs_filtered (", ", stream);
503 && char_at (string, rep1, type_len, byte_order)
504 == char_at (string, i, type_len, byte_order))
510 if (reps > options->repeat_count_threshold)
514 if (options->inspect_it)
515 fputs_filtered ("\\\", ", stream);
517 fputs_filtered ("\", ", stream);
520 fputs_filtered ("'", stream);
521 ada_emit_char (char_at (string, i, type_len, byte_order),
522 elttype, stream, '\'', type_len);
523 fputs_filtered ("'", stream);
524 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
526 things_printed += options->repeat_count_threshold;
533 if (options->inspect_it)
534 fputs_filtered ("\\\"", stream);
536 fputs_filtered ("\"", stream);
539 ada_emit_char (char_at (string, i, type_len, byte_order),
540 elttype, stream, '"', type_len);
545 /* Terminate the quotes if necessary. */
548 if (options->inspect_it)
549 fputs_filtered ("\\\"", stream);
551 fputs_filtered ("\"", stream);
554 if (force_ellipses || i < length)
555 fputs_filtered ("...", stream);
559 ada_printstr (struct ui_file *stream, struct type *type,
560 const gdb_byte *string, unsigned int length,
561 const char *encoding, int force_ellipses,
562 const struct value_print_options *options)
564 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
569 /* See val_print for a description of the various parameters of this
570 function; they are identical. The semantics of the return value is
571 also identical to val_print. */
574 ada_val_print (struct type *type, const gdb_byte *valaddr,
575 int embedded_offset, CORE_ADDR address,
576 struct ui_file *stream, int recurse,
577 const struct value *val,
578 const struct value_print_options *options)
580 volatile struct gdb_exception except;
583 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */
584 TRY_CATCH (except, RETURN_MASK_ALL)
586 result = ada_val_print_1 (type, valaddr, embedded_offset, address,
587 stream, recurse, val, options);
590 if (except.reason < 0)
596 /* Assuming TYPE is a simple array, print the value of this array located
597 at VALADDR + OFFSET. See ada_val_print for a description of the various
598 parameters of this function; they are identical. The semantics
599 of the return value is also identical to ada_val_print. */
602 ada_val_print_array (struct type *type, const gdb_byte *valaddr,
603 int offset, CORE_ADDR address,
604 struct ui_file *stream, int recurse,
605 const struct value *val,
606 const struct value_print_options *options)
610 /* For an array of chars, print with string syntax. */
611 if (ada_is_string_type (type)
612 && (options->format == 0 || options->format == 's'))
614 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
615 struct type *elttype = TYPE_TARGET_TYPE (type);
619 /* We know that ELTTYPE cannot possibly be null, because we found
620 that TYPE is a string-like type. Similarly, the size of ELTTYPE
621 should also be non-null, since it's a character-like type. */
622 gdb_assert (elttype != NULL);
623 gdb_assert (TYPE_LENGTH (elttype) != 0);
625 eltlen = TYPE_LENGTH (elttype);
626 len = TYPE_LENGTH (type) / eltlen;
628 if (options->prettyprint_arrays)
629 print_spaces_filtered (2 + 2 * recurse, stream);
631 /* If requested, look for the first null char and only print
632 elements up to it. */
633 if (options->stop_print_at_null)
637 /* Look for a NULL char. */
640 && temp_len < options->print_max
641 && char_at (valaddr + offset,
642 temp_len, eltlen, byte_order) != 0);
647 printstr (stream, elttype, valaddr + offset, len, 0, eltlen, options);
652 fprintf_filtered (stream, "(");
653 print_optional_low_bound (stream, type, options);
654 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
655 val_print_packed_array_elements (type, valaddr, offset,
656 0, stream, recurse, val, options);
658 val_print_array_elements (type, valaddr, offset, address,
659 stream, recurse, val, options, 0);
660 fprintf_filtered (stream, ")");
666 /* See the comment on ada_val_print. This function differs in that it
667 does not catch evaluation errors (leaving that to ada_val_print). */
670 ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
671 int offset, CORE_ADDR address,
672 struct ui_file *stream, int recurse,
673 const struct value *original_value,
674 const struct value_print_options *options)
678 struct type *elttype;
682 type = ada_check_typedef (type);
684 if (ada_is_array_descriptor_type (type)
685 || (ada_is_constrained_packed_array_type (type)
686 && TYPE_CODE (type) != TYPE_CODE_PTR))
689 struct value *mark = value_mark ();
692 val = value_from_contents_and_address (type, valaddr + offset, address);
693 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
694 val = ada_coerce_to_simple_array_ptr (val);
696 val = ada_coerce_to_simple_array (val);
699 gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
700 fprintf_filtered (stream, "0x0");
704 retn = ada_val_print_1 (value_type (val),
705 value_contents_for_printing (val),
706 value_embedded_offset (val),
707 value_address (val), stream, recurse,
709 value_free_to_mark (mark);
713 offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
714 type = printable_val_type (type, valaddr + offset_aligned);
716 switch (TYPE_CODE (type))
719 return c_val_print (type, valaddr, offset, address, stream,
720 recurse, original_value, options);
724 int ret = c_val_print (type, valaddr, offset, address,
725 stream, recurse, original_value, options);
727 if (ada_is_tag_type (type))
730 value_from_contents_and_address (type,
731 valaddr + offset_aligned,
732 address + offset_aligned);
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 + offset_aligned);
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. */
764 = value_from_contents_and_address (type, valaddr + offset, 0);
765 struct value *v = value_cast (target_type, v1);
767 return ada_val_print_1 (target_type,
768 value_contents_for_printing (v),
769 value_embedded_offset (v), 0,
770 stream, recurse + 1, v, options);
773 return ada_val_print_1 (TYPE_TARGET_TYPE (type),
775 address, stream, recurse,
776 original_value, options);
780 int format = (options->format ? options->format
781 : options->output_format);
785 struct value_print_options opts = *options;
787 opts.format = format;
788 val_print_scalar_formatted (type, valaddr, offset_aligned,
789 original_value, &opts, 0, stream);
791 else if (ada_is_system_address_type (type))
793 /* FIXME: We want to print System.Address variables using
794 the same format as for any access type. But for some
795 reason GNAT encodes the System.Address type as an int,
796 so we have to work-around this deficiency by handling
797 System.Address values as a special case. */
799 struct gdbarch *gdbarch = get_type_arch (type);
800 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
801 CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned,
804 fprintf_filtered (stream, "(");
805 type_print (type, "", stream, -1);
806 fprintf_filtered (stream, ") ");
807 fputs_filtered (paddress (gdbarch, addr), stream);
811 val_print_type_code_int (type, valaddr + offset_aligned, stream);
812 if (ada_is_character_type (type))
816 fputs_filtered (" ", stream);
817 c = unpack_long (type, valaddr + offset_aligned);
818 ada_printchar (c, type, stream);
827 val_print_scalar_formatted (type, valaddr, offset_aligned,
828 original_value, options, 0, stream);
831 len = TYPE_NFIELDS (type);
832 val = unpack_long (type, valaddr + offset_aligned);
833 for (i = 0; i < len; i++)
836 if (val == TYPE_FIELD_BITPOS (type, i))
843 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
846 fprintf_filtered (stream, "%ld %s", (long) val, name);
848 fputs_filtered (name, stream);
852 print_longest (stream, 'd', 0, val);
856 case TYPE_CODE_FLAGS:
858 val_print_scalar_formatted (type, valaddr, offset_aligned,
859 original_value, options, 0, stream);
861 val_print_type_code_flags (type, valaddr + offset_aligned, stream);
866 return c_val_print (type, valaddr, offset, address, stream,
867 recurse, original_value, options);
869 ada_print_floating (valaddr + offset, type, stream);
872 case TYPE_CODE_UNION:
873 case TYPE_CODE_STRUCT:
874 if (ada_is_bogus_array_descriptor (type))
876 fprintf_filtered (stream, "(...?)");
881 print_record (type, valaddr, offset_aligned,
882 stream, recurse, original_value, options);
886 case TYPE_CODE_ARRAY:
887 return ada_val_print_array (type, valaddr, offset_aligned,
888 address, stream, recurse, original_value,
892 /* For references, the debugger is expected to print the value as
893 an address if DEREF_REF is null. But printing an address in place
894 of the object value would be confusing to an Ada programmer.
895 So, for Ada values, we print the actual dereferenced value
897 elttype = check_typedef (TYPE_TARGET_TYPE (type));
899 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
901 CORE_ADDR deref_val_int;
902 struct value *deref_val;
904 deref_val = coerce_ref_if_computed (original_value);
907 common_val_print (deref_val, stream, recurse + 1, options,
912 deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
913 if (deref_val_int != 0)
915 struct value *deref_val =
916 ada_value_ind (value_from_pointer
917 (lookup_pointer_type (elttype),
920 val_print (value_type (deref_val),
921 value_contents_for_printing (deref_val),
922 value_embedded_offset (deref_val),
923 value_address (deref_val), stream, recurse + 1,
924 deref_val, options, current_language);
927 fputs_filtered ("(null)", stream);
930 fputs_filtered ("???", stream);
939 print_variant_part (struct type *type, int field_num,
940 const gdb_byte *valaddr, int offset,
941 struct ui_file *stream, int recurse,
942 const struct value *val,
943 const struct value_print_options *options,
945 struct type *outer_type, int outer_offset)
947 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
948 int which = ada_which_variant_applies (var_type, outer_type,
949 valaddr + outer_offset);
954 return print_field_values
955 (TYPE_FIELD_TYPE (var_type, which),
957 offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
958 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
959 stream, recurse, val, options,
960 comma_needed, outer_type, outer_offset);
964 ada_value_print (struct value *val0, struct ui_file *stream,
965 const struct value_print_options *options)
967 struct value *val = ada_to_fixed_value (val0);
968 CORE_ADDR address = value_address (val);
969 struct type *type = ada_check_typedef (value_type (val));
970 struct value_print_options opts;
972 /* If it is a pointer, indicate what it points to. */
973 if (TYPE_CODE (type) == TYPE_CODE_PTR)
975 /* Hack: don't print (char *) for char strings. Their
976 type is indicated by the quoted string anyway. */
977 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
978 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
979 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
981 fprintf_filtered (stream, "(");
982 type_print (type, "", stream, -1);
983 fprintf_filtered (stream, ") ");
986 else if (ada_is_array_descriptor_type (type))
988 /* We do not print the type description unless TYPE is an array
989 access type (this is encoded by the compiler as a typedef to
990 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
991 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
993 fprintf_filtered (stream, "(");
994 type_print (type, "", stream, -1);
995 fprintf_filtered (stream, ") ");
998 else if (ada_is_bogus_array_descriptor (type))
1000 fprintf_filtered (stream, "(");
1001 type_print (type, "", stream, -1);
1002 fprintf_filtered (stream, ") (...?)");
1008 return (val_print (type, value_contents_for_printing (val),
1009 value_embedded_offset (val), address,
1010 stream, 0, val, &opts, current_language));
1014 print_record (struct type *type, const gdb_byte *valaddr,
1016 struct ui_file *stream, int recurse,
1017 const struct value *val,
1018 const struct value_print_options *options)
1020 type = ada_check_typedef (type);
1022 fprintf_filtered (stream, "(");
1024 if (print_field_values (type, valaddr, offset,
1025 stream, recurse, val, options,
1026 0, type, offset) != 0 && options->pretty)
1028 fprintf_filtered (stream, "\n");
1029 print_spaces_filtered (2 * recurse, stream);
1032 fprintf_filtered (stream, ")");
1035 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
1037 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
1038 meanings as in ada_print_value and ada_val_print.
1040 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
1041 record (used to get discriminant values when printing variant
1044 COMMA_NEEDED is 1 if fields have been printed at the current recursion
1045 level, so that a comma is needed before any field printed by this
1048 Returns 1 if COMMA_NEEDED or any fields were printed. */
1051 print_field_values (struct type *type, const gdb_byte *valaddr,
1052 int offset, struct ui_file *stream, int recurse,
1053 const struct value *val,
1054 const struct value_print_options *options,
1056 struct type *outer_type, int outer_offset)
1060 len = TYPE_NFIELDS (type);
1062 for (i = 0; i < len; i += 1)
1064 if (ada_is_ignored_field (type, i))
1067 if (ada_is_wrapper_field (type, i))
1070 print_field_values (TYPE_FIELD_TYPE (type, i),
1073 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
1074 stream, recurse, val, options,
1075 comma_needed, type, offset);
1078 else if (ada_is_variant_part (type, i))
1081 print_variant_part (type, i, valaddr,
1082 offset, stream, recurse, val,
1083 options, comma_needed,
1084 outer_type, outer_offset);
1089 fprintf_filtered (stream, ", ");
1092 if (options->pretty)
1094 fprintf_filtered (stream, "\n");
1095 print_spaces_filtered (2 + 2 * recurse, stream);
1099 wrap_here (n_spaces (2 + 2 * recurse));
1101 if (options->inspect_it)
1103 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
1104 fputs_filtered ("\"( ptr \"", stream);
1106 fputs_filtered ("\"( nodef \"", stream);
1107 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1108 language_cplus, DMGL_NO_OPTS);
1109 fputs_filtered ("\" \"", stream);
1110 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
1111 language_cplus, DMGL_NO_OPTS);
1112 fputs_filtered ("\") \"", stream);
1116 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1117 fprintf_filtered (stream, "%.*s",
1118 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
1119 TYPE_FIELD_NAME (type, i));
1120 annotate_field_name_end ();
1121 fputs_filtered (" => ", stream);
1122 annotate_field_value ();
1125 if (TYPE_FIELD_PACKED (type, i))
1129 /* Bitfields require special handling, especially due to byte
1131 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
1133 fputs_filtered (_("<optimized out or zero length>"), stream);
1137 int bit_pos = TYPE_FIELD_BITPOS (type, i);
1138 int bit_size = TYPE_FIELD_BITSIZE (type, i);
1139 struct value_print_options opts;
1141 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
1142 v = ada_value_primitive_packed_val
1144 offset + bit_pos / HOST_CHAR_BIT,
1145 bit_pos % HOST_CHAR_BIT,
1146 bit_size, TYPE_FIELD_TYPE (type, i));
1149 val_print (TYPE_FIELD_TYPE (type, i),
1150 value_contents_for_printing (v),
1151 value_embedded_offset (v), 0,
1152 stream, recurse + 1, v,
1153 &opts, current_language);
1158 struct value_print_options opts = *options;
1161 ada_val_print (TYPE_FIELD_TYPE (type, i),
1164 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
1165 0, stream, recurse + 1, val, &opts);
1167 annotate_field_end ();
1170 return comma_needed;