1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
34 #include "target-float.h"
36 static int print_field_values (struct type *, const gdb_byte *,
38 struct ui_file *, int,
40 const struct value_print_options *,
41 int, struct type *, int,
42 const struct language_defn *);
45 /* Make TYPE unsigned if its range of values includes no negatives. */
47 adjust_type_signedness (struct type *type)
49 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
50 && TYPE_LOW_BOUND (type) >= 0)
51 TYPE_UNSIGNED (type) = 1;
54 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
55 if non-standard (i.e., other than 1 for numbers, other than lower bound
56 of index type for enumerated type). Returns 1 if something printed,
60 print_optional_low_bound (struct ui_file *stream, struct type *type,
61 const struct value_print_options *options)
63 struct type *index_type;
67 if (options->print_array_indexes)
70 if (!get_array_bounds (type, &low_bound, &high_bound))
73 /* If this is an empty array, then don't print the lower bound.
74 That would be confusing, because we would print the lower bound,
75 followed by... nothing! */
76 if (low_bound > high_bound)
79 index_type = TYPE_INDEX_TYPE (type);
81 while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
83 /* We need to know what the base type is, in order to do the
84 appropriate check below. Otherwise, if this is a subrange
85 of an enumerated type, where the underlying value of the
86 first element is typically 0, we might test the low bound
87 against the wrong value. */
88 index_type = TYPE_TARGET_TYPE (index_type);
91 switch (TYPE_CODE (index_type))
98 if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0))
101 case TYPE_CODE_UNDEF:
110 ada_print_scalar (index_type, low_bound, stream);
111 fprintf_filtered (stream, " => ");
115 /* Version of val_print_array_elements for GNAT-style packed arrays.
116 Prints elements of packed array of type TYPE at bit offset
117 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
118 separates with commas. RECURSE is the recursion (nesting) level.
119 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
122 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
124 int bitoffset, struct ui_file *stream,
127 const struct value_print_options *options)
130 unsigned int things_printed = 0;
132 struct type *elttype, *index_type;
133 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
134 struct value *mark = value_mark ();
137 elttype = TYPE_TARGET_TYPE (type);
138 index_type = TYPE_INDEX_TYPE (type);
143 if (get_discrete_bounds (index_type, &low, &high) < 0)
146 len = high - low + 1;
150 annotate_array_section_begin (i, elttype);
152 while (i < len && things_printed < options->print_max)
154 struct value *v0, *v1;
159 if (options->prettyformat_arrays)
161 fprintf_filtered (stream, ",\n");
162 print_spaces_filtered (2 + 2 * recurse, stream);
166 fprintf_filtered (stream, ", ");
169 wrap_here (n_spaces (2 + 2 * recurse));
170 maybe_print_array_index (index_type, i + low, stream, options);
173 v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
174 (i0 * bitsize) / HOST_CHAR_BIT,
175 (i0 * bitsize) % HOST_CHAR_BIT,
182 v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
183 (i * bitsize) / HOST_CHAR_BIT,
184 (i * bitsize) % HOST_CHAR_BIT,
186 if (TYPE_LENGTH (check_typedef (value_type (v0)))
187 != TYPE_LENGTH (check_typedef (value_type (v1))))
189 if (!value_contents_eq (v0, value_embedded_offset (v0),
190 v1, value_embedded_offset (v1),
191 TYPE_LENGTH (check_typedef (value_type (v0)))))
195 if (i - i0 > options->repeat_count_threshold)
197 struct value_print_options opts = *options;
201 value_embedded_offset (v0), 0, stream,
202 recurse + 1, v0, &opts, current_language);
203 annotate_elt_rep (i - i0);
204 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
205 annotate_elt_rep_end ();
211 struct value_print_options opts = *options;
214 for (j = i0; j < i; j += 1)
218 if (options->prettyformat_arrays)
220 fprintf_filtered (stream, ",\n");
221 print_spaces_filtered (2 + 2 * recurse, stream);
225 fprintf_filtered (stream, ", ");
227 wrap_here (n_spaces (2 + 2 * recurse));
228 maybe_print_array_index (index_type, j + low,
232 value_embedded_offset (v0), 0, stream,
233 recurse + 1, v0, &opts, current_language);
237 things_printed += i - i0;
239 annotate_array_section_end ();
242 fprintf_filtered (stream, "...");
245 value_free_to_mark (mark);
249 printable_val_type (struct type *type, const gdb_byte *valaddr)
251 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
254 /* Print the character C on STREAM as part of the contents of a literal
255 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
259 ada_emit_char (int c, struct type *type, struct ui_file *stream,
260 int quoter, int type_len)
262 /* If this character fits in the normal ASCII range, and is
263 a printable character, then print the character as if it was
264 an ASCII character, even if this is a wide character.
265 The UCHAR_MAX check is necessary because the isascii function
266 requires that its argument have a value of an unsigned char,
267 or EOF (EOF is obviously not printable). */
268 if (c <= UCHAR_MAX && isascii (c) && isprint (c))
270 if (c == quoter && c == '"')
271 fprintf_filtered (stream, "\"\"");
273 fprintf_filtered (stream, "%c", c);
276 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
279 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
283 char_at (const gdb_byte *string, int i, int type_len,
284 enum bfd_endian byte_order)
289 return (int) extract_unsigned_integer (string + type_len * i,
290 type_len, byte_order);
293 /* Print a floating-point value of type TYPE, pointed to in GDB by
294 VALADDR, on STREAM. Use Ada formatting conventions: there must be
295 a decimal point, and at least one digit before and after the
296 point. We use the GNAT format for NaNs and infinities. */
299 ada_print_floating (const gdb_byte *valaddr, struct type *type,
300 struct ui_file *stream)
302 string_file tmp_stream;
304 print_floating (valaddr, type, &tmp_stream);
306 std::string &s = tmp_stream.string ();
307 size_t skip_count = 0;
309 /* Modify for Ada rules. */
311 size_t pos = s.find ("inf");
312 if (pos == std::string::npos)
313 pos = s.find ("Inf");
314 if (pos == std::string::npos)
315 pos = s.find ("INF");
316 if (pos != std::string::npos)
317 s.replace (pos, 3, "Inf");
319 if (pos == std::string::npos)
321 pos = s.find ("nan");
322 if (pos == std::string::npos)
323 pos = s.find ("NaN");
324 if (pos == std::string::npos)
325 pos = s.find ("Nan");
326 if (pos != std::string::npos)
328 s[pos] = s[pos + 2] = 'N';
334 if (pos == std::string::npos
335 && s.find ('.') == std::string::npos)
338 if (pos == std::string::npos)
339 fprintf_filtered (stream, "%s.0", s.c_str ());
341 fprintf_filtered (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
344 fprintf_filtered (stream, "%s", &s[skip_count]);
348 ada_printchar (int c, struct type *type, struct ui_file *stream)
350 fputs_filtered ("'", stream);
351 ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
352 fputs_filtered ("'", stream);
355 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
356 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
357 like a default signed integer. */
360 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
367 print_longest (stream, 'd', 0, val);
371 type = ada_check_typedef (type);
373 switch (TYPE_CODE (type))
377 len = TYPE_NFIELDS (type);
378 for (i = 0; i < len; i++)
380 if (TYPE_FIELD_ENUMVAL (type, i) == val)
387 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
391 print_longest (stream, 'd', 0, val);
396 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
400 LA_PRINT_CHAR (val, type, stream);
404 fprintf_filtered (stream, val ? "true" : "false");
407 case TYPE_CODE_RANGE:
408 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
411 case TYPE_CODE_UNDEF:
413 case TYPE_CODE_ARRAY:
414 case TYPE_CODE_STRUCT:
415 case TYPE_CODE_UNION:
420 case TYPE_CODE_STRING:
421 case TYPE_CODE_ERROR:
422 case TYPE_CODE_MEMBERPTR:
423 case TYPE_CODE_METHODPTR:
424 case TYPE_CODE_METHOD:
426 warning (_("internal error: unhandled type in ada_print_scalar"));
430 error (_("Invalid type code in symbol table."));
435 /* Print the character string STRING, printing at most LENGTH characters.
436 Printing stops early if the number hits print_max; repeat counts
437 are printed as appropriate. Print ellipses at the end if we
438 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
439 TYPE_LEN is the length (1 or 2) of the character type. */
442 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
443 unsigned int length, int force_ellipses, int type_len,
444 const struct value_print_options *options)
446 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype));
448 unsigned int things_printed = 0;
454 fputs_filtered ("\"\"", stream);
458 for (i = 0; i < length && things_printed < options->print_max; i += 1)
460 /* Position of the character we are examining
461 to see whether it is repeated. */
463 /* Number of repetitions we have detected so far. */
470 fputs_filtered (", ", stream);
477 && char_at (string, rep1, type_len, byte_order)
478 == char_at (string, i, type_len, byte_order))
484 if (reps > options->repeat_count_threshold)
488 fputs_filtered ("\", ", stream);
491 fputs_filtered ("'", stream);
492 ada_emit_char (char_at (string, i, type_len, byte_order),
493 elttype, stream, '\'', type_len);
494 fputs_filtered ("'", stream);
495 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
497 things_printed += options->repeat_count_threshold;
504 fputs_filtered ("\"", stream);
507 ada_emit_char (char_at (string, i, type_len, byte_order),
508 elttype, stream, '"', type_len);
513 /* Terminate the quotes if necessary. */
515 fputs_filtered ("\"", stream);
517 if (force_ellipses || i < length)
518 fputs_filtered ("...", stream);
522 ada_printstr (struct ui_file *stream, struct type *type,
523 const gdb_byte *string, unsigned int length,
524 const char *encoding, int force_ellipses,
525 const struct value_print_options *options)
527 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
532 print_variant_part (struct type *type, int field_num,
533 const gdb_byte *valaddr, int offset,
534 struct ui_file *stream, int recurse,
536 const struct value_print_options *options,
538 struct type *outer_type, int outer_offset,
539 const struct language_defn *language)
541 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
542 int which = ada_which_variant_applies (var_type, outer_type,
543 valaddr + outer_offset);
548 return print_field_values
549 (TYPE_FIELD_TYPE (var_type, which),
551 offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
552 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
553 stream, recurse, val, options,
554 comma_needed, outer_type, outer_offset, language);
557 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
559 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
560 meanings as in ada_print_value and ada_val_print.
562 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
563 record (used to get discriminant values when printing variant
566 COMMA_NEEDED is 1 if fields have been printed at the current recursion
567 level, so that a comma is needed before any field printed by this
570 Returns 1 if COMMA_NEEDED or any fields were printed. */
573 print_field_values (struct type *type, const gdb_byte *valaddr,
574 int offset, struct ui_file *stream, int recurse,
576 const struct value_print_options *options,
578 struct type *outer_type, int outer_offset,
579 const struct language_defn *language)
583 len = TYPE_NFIELDS (type);
585 for (i = 0; i < len; i += 1)
587 if (ada_is_ignored_field (type, i))
590 if (ada_is_wrapper_field (type, i))
593 print_field_values (TYPE_FIELD_TYPE (type, i),
596 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
597 stream, recurse, val, options,
598 comma_needed, type, offset, language);
601 else if (ada_is_variant_part (type, i))
604 print_variant_part (type, i, valaddr,
605 offset, stream, recurse, val,
606 options, comma_needed,
607 outer_type, outer_offset, language);
612 fprintf_filtered (stream, ", ");
615 if (options->prettyformat)
617 fprintf_filtered (stream, "\n");
618 print_spaces_filtered (2 + 2 * recurse, stream);
622 wrap_here (n_spaces (2 + 2 * recurse));
625 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
626 fprintf_filtered (stream, "%.*s",
627 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
628 TYPE_FIELD_NAME (type, i));
629 annotate_field_name_end ();
630 fputs_filtered (" => ", stream);
631 annotate_field_value ();
633 if (TYPE_FIELD_PACKED (type, i))
635 /* Bitfields require special handling, especially due to byte
637 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
639 fputs_filtered (_("<optimized out or zero length>"), stream);
644 int bit_pos = TYPE_FIELD_BITPOS (type, i);
645 int bit_size = TYPE_FIELD_BITSIZE (type, i);
646 struct value_print_options opts;
648 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
649 v = ada_value_primitive_packed_val
651 offset + bit_pos / HOST_CHAR_BIT,
652 bit_pos % HOST_CHAR_BIT,
653 bit_size, TYPE_FIELD_TYPE (type, i));
656 val_print (TYPE_FIELD_TYPE (type, i),
657 value_embedded_offset (v), 0,
658 stream, recurse + 1, v,
664 struct value_print_options opts = *options;
667 val_print (TYPE_FIELD_TYPE (type, i),
668 (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
669 0, stream, recurse + 1, val, &opts, language);
671 annotate_field_end ();
677 /* Implement Ada val_print'ing for the case where TYPE is
678 a TYPE_CODE_ARRAY of characters. */
681 ada_val_print_string (struct type *type, const gdb_byte *valaddr,
682 int offset, int offset_aligned, CORE_ADDR address,
683 struct ui_file *stream, int recurse,
684 struct value *original_value,
685 const struct value_print_options *options)
687 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
688 struct type *elttype = TYPE_TARGET_TYPE (type);
692 /* We know that ELTTYPE cannot possibly be null, because we assume
693 that we're called only when TYPE is a string-like type.
694 Similarly, the size of ELTTYPE should also be non-null, since
695 it's a character-like type. */
696 gdb_assert (elttype != NULL);
697 gdb_assert (TYPE_LENGTH (elttype) != 0);
699 eltlen = TYPE_LENGTH (elttype);
700 len = TYPE_LENGTH (type) / eltlen;
702 if (options->prettyformat_arrays)
703 print_spaces_filtered (2 + 2 * recurse, stream);
705 /* If requested, look for the first null char and only print
706 elements up to it. */
707 if (options->stop_print_at_null)
711 /* Look for a NULL char. */
714 && temp_len < options->print_max
715 && char_at (valaddr + offset_aligned,
716 temp_len, eltlen, byte_order) != 0);
721 printstr (stream, elttype, valaddr + offset_aligned, len, 0,
725 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
726 thin pointers, etc). */
729 ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr,
730 int offset, CORE_ADDR address,
731 struct ui_file *stream, int recurse,
732 struct value *original_value,
733 const struct value_print_options *options,
734 const struct language_defn *language)
736 struct value *mark = value_mark ();
739 val = value_from_contents_and_address (type, valaddr + offset, address);
740 /* If this is a reference, coerce it now. This helps taking care
741 of the case where ADDRESS is meaningless because original_value
743 val = coerce_ref (val);
744 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
745 val = ada_coerce_to_simple_array_ptr (val);
747 val = ada_coerce_to_simple_array (val);
750 gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
751 fprintf_filtered (stream, "0x0");
754 val_print (value_type (val),
755 value_embedded_offset (val), value_address (val),
756 stream, recurse, val, options, language);
757 value_free_to_mark (mark);
760 /* Implement Ada val_print'ing for the case where TYPE is
764 ada_val_print_ptr (struct type *type, const gdb_byte *valaddr,
765 int offset, int offset_aligned, CORE_ADDR address,
766 struct ui_file *stream, int recurse,
767 struct value *original_value,
768 const struct value_print_options *options,
769 const struct language_defn *language)
771 val_print (type, offset, address, stream, recurse,
772 original_value, options, language_def (language_c));
774 if (ada_is_tag_type (type))
777 value_from_contents_and_address (type,
778 valaddr + offset_aligned,
779 address + offset_aligned);
780 const char *name = ada_tag_name (val);
783 fprintf_filtered (stream, " (%s)", name);
787 /* Implement Ada val_print'ing for the case where TYPE is
788 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
791 ada_val_print_num (struct type *type, const gdb_byte *valaddr,
792 int offset, int offset_aligned, CORE_ADDR address,
793 struct ui_file *stream, int recurse,
794 struct value *original_value,
795 const struct value_print_options *options,
796 const struct language_defn *language)
798 if (ada_is_fixed_point_type (type))
800 struct value *scale = ada_scaling_factor (type);
801 struct value *v = value_from_contents (type, valaddr + offset_aligned);
802 v = value_cast (value_type (scale), v);
803 v = value_binop (v, scale, BINOP_MUL);
805 const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g";
807 = target_float_to_string (value_contents (v), value_type (v), fmt);
808 fputs_filtered (str.c_str (), stream);
811 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
813 struct type *target_type = TYPE_TARGET_TYPE (type);
815 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
817 /* Obscure case of range type that has different length from
818 its base type. Perform a conversion, or we will get a
819 nonsense value. Actually, we could use the same
820 code regardless of lengths; I'm just avoiding a cast. */
822 = value_from_contents_and_address (type, valaddr + offset, 0);
823 struct value *v = value_cast (target_type, v1);
825 val_print (target_type,
826 value_embedded_offset (v), 0, stream,
827 recurse + 1, v, options, language);
830 val_print (TYPE_TARGET_TYPE (type), offset,
831 address, stream, recurse, original_value,
837 int format = (options->format ? options->format
838 : options->output_format);
842 struct value_print_options opts = *options;
844 opts.format = format;
845 val_print_scalar_formatted (type, offset_aligned,
846 original_value, &opts, 0, stream);
848 else if (ada_is_system_address_type (type))
850 /* FIXME: We want to print System.Address variables using
851 the same format as for any access type. But for some
852 reason GNAT encodes the System.Address type as an int,
853 so we have to work-around this deficiency by handling
854 System.Address values as a special case. */
856 struct gdbarch *gdbarch = get_type_arch (type);
857 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
858 CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned,
861 fprintf_filtered (stream, "(");
862 type_print (type, "", stream, -1);
863 fprintf_filtered (stream, ") ");
864 fputs_filtered (paddress (gdbarch, addr), stream);
868 val_print_scalar_formatted (type, offset_aligned,
869 original_value, options, 0, stream);
870 if (ada_is_character_type (type))
874 fputs_filtered (" ", stream);
875 c = unpack_long (type, valaddr + offset_aligned);
876 ada_printchar (c, type, stream);
883 /* Implement Ada val_print'ing for the case where TYPE is
887 ada_val_print_enum (struct type *type, const gdb_byte *valaddr,
888 int offset, int offset_aligned, CORE_ADDR address,
889 struct ui_file *stream, int recurse,
890 struct value *original_value,
891 const struct value_print_options *options,
892 const struct language_defn *language)
900 val_print_scalar_formatted (type, offset_aligned,
901 original_value, options, 0, stream);
905 len = TYPE_NFIELDS (type);
906 val = unpack_long (type, valaddr + offset_aligned);
907 for (i = 0; i < len; i++)
910 if (val == TYPE_FIELD_ENUMVAL (type, i))
916 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
919 fprintf_filtered (stream, "%ld %s", (long) val, name);
921 fputs_filtered (name, stream);
924 print_longest (stream, 'd', 0, val);
927 /* Implement Ada val_print'ing for the case where TYPE is
931 ada_val_print_flt (struct type *type, const gdb_byte *valaddr,
932 int offset, int offset_aligned, CORE_ADDR address,
933 struct ui_file *stream, int recurse,
934 struct value *original_value,
935 const struct value_print_options *options,
936 const struct language_defn *language)
940 val_print (type, offset, address, stream, recurse,
941 original_value, options, language_def (language_c));
945 ada_print_floating (valaddr + offset, type, stream);
948 /* Implement Ada val_print'ing for the case where TYPE is
949 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
952 ada_val_print_struct_union
953 (struct type *type, const gdb_byte *valaddr, int offset,
954 int offset_aligned, CORE_ADDR address, struct ui_file *stream,
955 int recurse, struct value *original_value,
956 const struct value_print_options *options,
957 const struct language_defn *language)
959 if (ada_is_bogus_array_descriptor (type))
961 fprintf_filtered (stream, "(...?)");
965 fprintf_filtered (stream, "(");
967 if (print_field_values (type, valaddr, offset_aligned,
968 stream, recurse, original_value, options,
969 0, type, offset_aligned, language) != 0
970 && options->prettyformat)
972 fprintf_filtered (stream, "\n");
973 print_spaces_filtered (2 * recurse, stream);
976 fprintf_filtered (stream, ")");
979 /* Implement Ada val_print'ing for the case where TYPE is
980 a TYPE_CODE_ARRAY. */
983 ada_val_print_array (struct type *type, const gdb_byte *valaddr,
984 int offset, int offset_aligned, CORE_ADDR address,
985 struct ui_file *stream, int recurse,
986 struct value *original_value,
987 const struct value_print_options *options)
989 /* For an array of characters, print with string syntax. */
990 if (ada_is_string_type (type)
991 && (options->format == 0 || options->format == 's'))
993 ada_val_print_string (type, valaddr, offset, offset_aligned,
994 address, stream, recurse, original_value,
999 fprintf_filtered (stream, "(");
1000 print_optional_low_bound (stream, type, options);
1001 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
1002 val_print_packed_array_elements (type, valaddr, offset_aligned,
1004 original_value, options);
1006 val_print_array_elements (type, offset_aligned, address,
1007 stream, recurse, original_value,
1009 fprintf_filtered (stream, ")");
1012 /* Implement Ada val_print'ing for the case where TYPE is
1016 ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
1017 int offset, int offset_aligned, CORE_ADDR address,
1018 struct ui_file *stream, int recurse,
1019 struct value *original_value,
1020 const struct value_print_options *options,
1021 const struct language_defn *language)
1023 /* For references, the debugger is expected to print the value as
1024 an address if DEREF_REF is null. But printing an address in place
1025 of the object value would be confusing to an Ada programmer.
1026 So, for Ada values, we print the actual dereferenced value
1028 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
1029 struct value *deref_val;
1030 CORE_ADDR deref_val_int;
1032 if (TYPE_CODE (elttype) == TYPE_CODE_UNDEF)
1034 fputs_filtered ("<ref to undefined type>", stream);
1038 deref_val = coerce_ref_if_computed (original_value);
1041 if (ada_is_tagged_type (value_type (deref_val), 1))
1042 deref_val = ada_tag_value_at_base_address (deref_val);
1044 common_val_print (deref_val, stream, recurse + 1, options,
1049 deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
1050 if (deref_val_int == 0)
1052 fputs_filtered ("(null)", stream);
1057 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype),
1059 if (ada_is_tagged_type (value_type (deref_val), 1))
1060 deref_val = ada_tag_value_at_base_address (deref_val);
1062 /* Make sure that the object does not have an unreasonable size
1063 before trying to print it. This can happen for instance with
1064 references to dynamic objects whose contents is uninitialized
1065 (Eg: an array whose bounds are not set yet). */
1066 ada_ensure_varsize_limit (value_type (deref_val));
1068 if (value_lazy (deref_val))
1069 value_fetch_lazy (deref_val);
1071 val_print (value_type (deref_val),
1072 value_embedded_offset (deref_val),
1073 value_address (deref_val), stream, recurse + 1,
1074 deref_val, options, language);
1077 /* See the comment on ada_val_print. This function differs in that it
1078 does not catch evaluation errors (leaving that to ada_val_print). */
1081 ada_val_print_1 (struct type *type,
1082 int offset, CORE_ADDR address,
1083 struct ui_file *stream, int recurse,
1084 struct value *original_value,
1085 const struct value_print_options *options,
1086 const struct language_defn *language)
1089 const gdb_byte *valaddr = value_contents_for_printing (original_value);
1091 type = ada_check_typedef (type);
1093 if (ada_is_array_descriptor_type (type)
1094 || (ada_is_constrained_packed_array_type (type)
1095 && TYPE_CODE (type) != TYPE_CODE_PTR))
1097 ada_val_print_gnat_array (type, valaddr, offset, address,
1098 stream, recurse, original_value,
1103 offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
1104 type = printable_val_type (type, valaddr + offset_aligned);
1105 type = resolve_dynamic_type (type, valaddr + offset_aligned,
1106 address + offset_aligned);
1108 switch (TYPE_CODE (type))
1111 val_print (type, offset, address, stream, recurse,
1112 original_value, options, language_def (language_c));
1116 ada_val_print_ptr (type, valaddr, offset, offset_aligned,
1117 address, stream, recurse, original_value,
1122 case TYPE_CODE_RANGE:
1123 ada_val_print_num (type, valaddr, offset, offset_aligned,
1124 address, stream, recurse, original_value,
1128 case TYPE_CODE_ENUM:
1129 ada_val_print_enum (type, valaddr, offset, offset_aligned,
1130 address, stream, recurse, original_value,
1135 ada_val_print_flt (type, valaddr, offset, offset_aligned,
1136 address, stream, recurse, original_value,
1140 case TYPE_CODE_UNION:
1141 case TYPE_CODE_STRUCT:
1142 ada_val_print_struct_union (type, valaddr, offset, offset_aligned,
1143 address, stream, recurse,
1144 original_value, options, language);
1147 case TYPE_CODE_ARRAY:
1148 ada_val_print_array (type, valaddr, offset, offset_aligned,
1149 address, stream, recurse, original_value,
1154 ada_val_print_ref (type, valaddr, offset, offset_aligned,
1155 address, stream, recurse, original_value,
1161 /* See val_print for a description of the various parameters of this
1162 function; they are identical. */
1165 ada_val_print (struct type *type,
1166 int embedded_offset, CORE_ADDR address,
1167 struct ui_file *stream, int recurse,
1169 const struct value_print_options *options)
1173 ada_val_print_1 (type, embedded_offset, address,
1174 stream, recurse, val, options,
1177 CATCH (except, RETURN_MASK_ERROR)
1179 fprintf_filtered (stream, _("<error reading variable: %s>"),
1186 ada_value_print (struct value *val0, struct ui_file *stream,
1187 const struct value_print_options *options)
1189 struct value *val = ada_to_fixed_value (val0);
1190 CORE_ADDR address = value_address (val);
1191 struct type *type = ada_check_typedef (value_enclosing_type (val));
1192 struct value_print_options opts;
1194 /* If it is a pointer, indicate what it points to. */
1195 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1197 /* Hack: don't print (char *) for char strings. Their
1198 type is indicated by the quoted string anyway. */
1199 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
1200 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
1201 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
1203 fprintf_filtered (stream, "(");
1204 type_print (type, "", stream, -1);
1205 fprintf_filtered (stream, ") ");
1208 else if (ada_is_array_descriptor_type (type))
1210 /* We do not print the type description unless TYPE is an array
1211 access type (this is encoded by the compiler as a typedef to
1212 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1213 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1215 fprintf_filtered (stream, "(");
1216 type_print (type, "", stream, -1);
1217 fprintf_filtered (stream, ") ");
1220 else if (ada_is_bogus_array_descriptor (type))
1222 fprintf_filtered (stream, "(");
1223 type_print (type, "", stream, -1);
1224 fprintf_filtered (stream, ") (...?)");
1231 value_embedded_offset (val), address,
1232 stream, 0, val, &opts, current_language);