1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2014 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/>. */
25 #include "expression.h"
34 #include "exceptions.h"
37 static int print_field_values (struct type *, const gdb_byte *,
39 struct ui_file *, int,
41 const struct value_print_options *,
42 int, struct type *, int);
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 if (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,
126 const struct value *val,
127 const struct value_print_options *options)
130 unsigned int things_printed = 0;
132 struct type *elttype, *index_type;
134 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
135 struct value *mark = value_mark ();
138 elttype = TYPE_TARGET_TYPE (type);
139 eltlen = TYPE_LENGTH (check_typedef (elttype));
140 index_type = TYPE_INDEX_TYPE (type);
145 if (get_discrete_bounds (index_type, &low, &high) < 0)
148 len = high - low + 1;
152 annotate_array_section_begin (i, elttype);
154 while (i < len && things_printed < options->print_max)
156 struct value *v0, *v1;
161 if (options->prettyformat_arrays)
163 fprintf_filtered (stream, ",\n");
164 print_spaces_filtered (2 + 2 * recurse, stream);
168 fprintf_filtered (stream, ", ");
171 wrap_here (n_spaces (2 + 2 * recurse));
172 maybe_print_array_index (index_type, i + low, stream, options);
175 v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
176 (i0 * bitsize) / HOST_CHAR_BIT,
177 (i0 * bitsize) % HOST_CHAR_BIT,
184 v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
185 (i * bitsize) / HOST_CHAR_BIT,
186 (i * bitsize) % HOST_CHAR_BIT,
188 if (!value_available_contents_eq (v0, value_embedded_offset (v0),
189 v1, value_embedded_offset (v1),
194 if (i - i0 > options->repeat_count_threshold)
196 struct value_print_options opts = *options;
199 val_print (elttype, value_contents_for_printing (v0),
200 value_embedded_offset (v0), 0, stream,
201 recurse + 1, v0, &opts, current_language);
202 annotate_elt_rep (i - i0);
203 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
204 annotate_elt_rep_end ();
210 struct value_print_options opts = *options;
213 for (j = i0; j < i; j += 1)
217 if (options->prettyformat_arrays)
219 fprintf_filtered (stream, ",\n");
220 print_spaces_filtered (2 + 2 * recurse, stream);
224 fprintf_filtered (stream, ", ");
226 wrap_here (n_spaces (2 + 2 * recurse));
227 maybe_print_array_index (index_type, j + low,
230 val_print (elttype, value_contents_for_printing (v0),
231 value_embedded_offset (v0), 0, stream,
232 recurse + 1, v0, &opts, current_language);
236 things_printed += i - i0;
238 annotate_array_section_end ();
241 fprintf_filtered (stream, "...");
244 value_free_to_mark (mark);
248 printable_val_type (struct type *type, const gdb_byte *valaddr)
250 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
253 /* Print the character C on STREAM as part of the contents of a literal
254 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
258 ada_emit_char (int c, struct type *type, struct ui_file *stream,
259 int quoter, int type_len)
261 /* If this character fits in the normal ASCII range, and is
262 a printable character, then print the character as if it was
263 an ASCII character, even if this is a wide character.
264 The UCHAR_MAX check is necessary because the isascii function
265 requires that its argument have a value of an unsigned char,
266 or EOF (EOF is obviously not printable). */
267 if (c <= UCHAR_MAX && isascii (c) && isprint (c))
269 if (c == quoter && c == '"')
270 fprintf_filtered (stream, "\"\"");
272 fprintf_filtered (stream, "%c", c);
275 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
278 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
282 char_at (const gdb_byte *string, int i, int type_len,
283 enum bfd_endian byte_order)
288 return (int) extract_unsigned_integer (string + type_len * i,
289 type_len, byte_order);
292 /* Wrapper around memcpy to make it legal argument to ui_file_put. */
294 ui_memcpy (void *dest, const char *buffer, long len)
296 memcpy (dest, buffer, (size_t) len);
297 ((char *) dest)[len] = '\0';
300 /* Print a floating-point value of type TYPE, pointed to in GDB by
301 VALADDR, on STREAM. Use Ada formatting conventions: there must be
302 a decimal point, and at least one digit before and after the
303 point. We use GNAT format for NaNs and infinities. */
305 ada_print_floating (const gdb_byte *valaddr, struct type *type,
306 struct ui_file *stream)
310 struct ui_file *tmp_stream = mem_fileopen ();
311 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
313 print_floating (valaddr, type, tmp_stream);
314 ui_file_put (tmp_stream, ui_memcpy, buffer);
315 do_cleanups (cleanups);
319 /* Modify for Ada rules. */
321 s = strstr (result, "inf");
323 s = strstr (result, "Inf");
325 s = strstr (result, "INF");
331 s = strstr (result, "nan");
333 s = strstr (result, "NaN");
335 s = strstr (result, "Nan");
339 if (result[0] == '-')
344 if (s == NULL && strchr (result, '.') == NULL)
346 s = strchr (result, 'e');
348 fprintf_filtered (stream, "%s.0", result);
350 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
353 fprintf_filtered (stream, "%s", result);
357 ada_printchar (int c, struct type *type, struct ui_file *stream)
359 fputs_filtered ("'", stream);
360 ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
361 fputs_filtered ("'", stream);
364 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
365 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
366 like a default signed integer. */
369 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
376 print_longest (stream, 'd', 0, val);
380 type = ada_check_typedef (type);
382 switch (TYPE_CODE (type))
386 len = TYPE_NFIELDS (type);
387 for (i = 0; i < len; i++)
389 if (TYPE_FIELD_ENUMVAL (type, i) == val)
396 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
400 print_longest (stream, 'd', 0, val);
405 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
409 LA_PRINT_CHAR (val, type, stream);
413 fprintf_filtered (stream, val ? "true" : "false");
416 case TYPE_CODE_RANGE:
417 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
420 case TYPE_CODE_UNDEF:
422 case TYPE_CODE_ARRAY:
423 case TYPE_CODE_STRUCT:
424 case TYPE_CODE_UNION:
429 case TYPE_CODE_STRING:
430 case TYPE_CODE_ERROR:
431 case TYPE_CODE_MEMBERPTR:
432 case TYPE_CODE_METHODPTR:
433 case TYPE_CODE_METHOD:
435 warning (_("internal error: unhandled type in ada_print_scalar"));
439 error (_("Invalid type code in symbol table."));
444 /* Print the character string STRING, printing at most LENGTH characters.
445 Printing stops early if the number hits print_max; repeat counts
446 are printed as appropriate. Print ellipses at the end if we
447 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
448 TYPE_LEN is the length (1 or 2) of the character type. */
451 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
452 unsigned int length, int force_ellipses, int type_len,
453 const struct value_print_options *options)
455 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype));
457 unsigned int things_printed = 0;
463 fputs_filtered ("\"\"", stream);
467 for (i = 0; i < length && things_printed < options->print_max; i += 1)
469 /* Position of the character we are examining
470 to see whether it is repeated. */
472 /* Number of repetitions we have detected so far. */
479 fputs_filtered (", ", stream);
486 && char_at (string, rep1, type_len, byte_order)
487 == char_at (string, i, type_len, byte_order))
493 if (reps > options->repeat_count_threshold)
497 fputs_filtered ("\", ", stream);
500 fputs_filtered ("'", stream);
501 ada_emit_char (char_at (string, i, type_len, byte_order),
502 elttype, stream, '\'', type_len);
503 fputs_filtered ("'", stream);
504 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
506 things_printed += options->repeat_count_threshold;
513 fputs_filtered ("\"", stream);
516 ada_emit_char (char_at (string, i, type_len, byte_order),
517 elttype, stream, '"', type_len);
522 /* Terminate the quotes if necessary. */
524 fputs_filtered ("\"", stream);
526 if (force_ellipses || i < length)
527 fputs_filtered ("...", stream);
531 ada_printstr (struct ui_file *stream, struct type *type,
532 const gdb_byte *string, unsigned int length,
533 const char *encoding, int force_ellipses,
534 const struct value_print_options *options)
536 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
541 /* Assuming TYPE is a simple array, print the value of this array located
542 at VALADDR + OFFSET. See ada_val_print for a description of the various
543 parameters of this function; they are identical. */
546 ada_val_print_array (struct type *type, const gdb_byte *valaddr,
547 int offset, CORE_ADDR address,
548 struct ui_file *stream, int recurse,
549 const struct value *val,
550 const struct value_print_options *options)
552 /* For an array of chars, print with string syntax. */
553 if (ada_is_string_type (type)
554 && (options->format == 0 || options->format == 's'))
556 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
557 struct type *elttype = TYPE_TARGET_TYPE (type);
561 /* We know that ELTTYPE cannot possibly be null, because we found
562 that TYPE is a string-like type. Similarly, the size of ELTTYPE
563 should also be non-null, since it's a character-like type. */
564 gdb_assert (elttype != NULL);
565 gdb_assert (TYPE_LENGTH (elttype) != 0);
567 eltlen = TYPE_LENGTH (elttype);
568 len = TYPE_LENGTH (type) / eltlen;
570 if (options->prettyformat_arrays)
571 print_spaces_filtered (2 + 2 * recurse, stream);
573 /* If requested, look for the first null char and only print
574 elements up to it. */
575 if (options->stop_print_at_null)
579 /* Look for a NULL char. */
582 && temp_len < options->print_max
583 && char_at (valaddr + offset,
584 temp_len, eltlen, byte_order) != 0);
589 printstr (stream, elttype, valaddr + offset, len, 0, eltlen, options);
593 fprintf_filtered (stream, "(");
594 print_optional_low_bound (stream, type, options);
595 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
596 val_print_packed_array_elements (type, valaddr, offset,
597 0, stream, recurse, val, options);
599 val_print_array_elements (type, valaddr, offset, address,
600 stream, recurse, val, options, 0);
601 fprintf_filtered (stream, ")");
606 print_variant_part (struct type *type, int field_num,
607 const gdb_byte *valaddr, int offset,
608 struct ui_file *stream, int recurse,
609 const struct value *val,
610 const struct value_print_options *options,
612 struct type *outer_type, int outer_offset)
614 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
615 int which = ada_which_variant_applies (var_type, outer_type,
616 valaddr + outer_offset);
621 return print_field_values
622 (TYPE_FIELD_TYPE (var_type, which),
624 offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
625 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
626 stream, recurse, val, options,
627 comma_needed, outer_type, outer_offset);
630 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
632 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
633 meanings as in ada_print_value and ada_val_print.
635 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
636 record (used to get discriminant values when printing variant
639 COMMA_NEEDED is 1 if fields have been printed at the current recursion
640 level, so that a comma is needed before any field printed by this
643 Returns 1 if COMMA_NEEDED or any fields were printed. */
646 print_field_values (struct type *type, const gdb_byte *valaddr,
647 int offset, struct ui_file *stream, int recurse,
648 const struct value *val,
649 const struct value_print_options *options,
651 struct type *outer_type, int outer_offset)
655 len = TYPE_NFIELDS (type);
657 for (i = 0; i < len; i += 1)
659 if (ada_is_ignored_field (type, i))
662 if (ada_is_wrapper_field (type, i))
665 print_field_values (TYPE_FIELD_TYPE (type, i),
668 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
669 stream, recurse, val, options,
670 comma_needed, type, offset);
673 else if (ada_is_variant_part (type, i))
676 print_variant_part (type, i, valaddr,
677 offset, stream, recurse, val,
678 options, comma_needed,
679 outer_type, outer_offset);
684 fprintf_filtered (stream, ", ");
687 if (options->prettyformat)
689 fprintf_filtered (stream, "\n");
690 print_spaces_filtered (2 + 2 * recurse, stream);
694 wrap_here (n_spaces (2 + 2 * recurse));
697 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
698 fprintf_filtered (stream, "%.*s",
699 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
700 TYPE_FIELD_NAME (type, i));
701 annotate_field_name_end ();
702 fputs_filtered (" => ", stream);
703 annotate_field_value ();
705 if (TYPE_FIELD_PACKED (type, i))
709 /* Bitfields require special handling, especially due to byte
711 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
713 fputs_filtered (_("<optimized out or zero length>"), stream);
717 int bit_pos = TYPE_FIELD_BITPOS (type, i);
718 int bit_size = TYPE_FIELD_BITSIZE (type, i);
719 struct value_print_options opts;
721 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
722 v = ada_value_primitive_packed_val
724 offset + bit_pos / HOST_CHAR_BIT,
725 bit_pos % HOST_CHAR_BIT,
726 bit_size, TYPE_FIELD_TYPE (type, i));
729 val_print (TYPE_FIELD_TYPE (type, i),
730 value_contents_for_printing (v),
731 value_embedded_offset (v), 0,
732 stream, recurse + 1, v,
733 &opts, current_language);
738 struct value_print_options opts = *options;
741 ada_val_print (TYPE_FIELD_TYPE (type, i),
744 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
745 0, stream, recurse + 1, val, &opts);
747 annotate_field_end ();
753 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
754 thin pointers, etc). */
757 ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr,
758 int offset, CORE_ADDR address,
759 struct ui_file *stream, int recurse,
760 const struct value *original_value,
761 const struct value_print_options *options,
762 const struct language_defn *language)
764 struct value *mark = value_mark ();
767 val = value_from_contents_and_address (type, valaddr + offset, address);
768 /* If this is a reference, coerce it now. This helps taking care
769 of the case where ADDRESS is meaningless because original_value
771 val = coerce_ref (val);
772 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
773 val = ada_coerce_to_simple_array_ptr (val);
775 val = ada_coerce_to_simple_array (val);
778 gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
779 fprintf_filtered (stream, "0x0");
782 val_print (value_type (val), value_contents_for_printing (val),
783 value_embedded_offset (val), value_address (val),
784 stream, recurse, val, options, language);
785 value_free_to_mark (mark);
788 /* Implement Ada val_print'ing for the case where TYPE is
792 ada_val_print_ptr (struct type *type, const gdb_byte *valaddr,
793 int offset, int offset_aligned, CORE_ADDR address,
794 struct ui_file *stream, int recurse,
795 const struct value *original_value,
796 const struct value_print_options *options,
797 const struct language_defn *language)
799 val_print (type, valaddr, offset, address, stream, recurse,
800 original_value, options, language_def (language_c));
802 if (ada_is_tag_type (type))
805 value_from_contents_and_address (type,
806 valaddr + offset_aligned,
807 address + offset_aligned);
808 const char *name = ada_tag_name (val);
811 fprintf_filtered (stream, " (%s)", name);
815 /* Implement Ada val_print'ing for the case where TYPE is
816 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
819 ada_val_print_num (struct type *type, const gdb_byte *valaddr,
820 int offset, int offset_aligned, CORE_ADDR address,
821 struct ui_file *stream, int recurse,
822 const struct value *original_value,
823 const struct value_print_options *options,
824 const struct language_defn *language)
826 if (ada_is_fixed_point_type (type))
828 LONGEST v = unpack_long (type, valaddr + offset_aligned);
830 fprintf_filtered (stream, TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g",
831 (double) ada_fixed_to_float (type, v));
834 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
836 struct type *target_type = TYPE_TARGET_TYPE (type);
838 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
840 /* Obscure case of range type that has different length from
841 its base type. Perform a conversion, or we will get a
842 nonsense value. Actually, we could use the same
843 code regardless of lengths; I'm just avoiding a cast. */
845 = value_from_contents_and_address (type, valaddr + offset, 0);
846 struct value *v = value_cast (target_type, v1);
848 val_print (target_type, value_contents_for_printing (v),
849 value_embedded_offset (v), 0, stream,
850 recurse + 1, v, options, language);
853 val_print (TYPE_TARGET_TYPE (type), valaddr, offset,
854 address, stream, recurse, original_value,
860 int format = (options->format ? options->format
861 : options->output_format);
865 struct value_print_options opts = *options;
867 opts.format = format;
868 val_print_scalar_formatted (type, valaddr, offset_aligned,
869 original_value, &opts, 0, stream);
871 else if (ada_is_system_address_type (type))
873 /* FIXME: We want to print System.Address variables using
874 the same format as for any access type. But for some
875 reason GNAT encodes the System.Address type as an int,
876 so we have to work-around this deficiency by handling
877 System.Address values as a special case. */
879 struct gdbarch *gdbarch = get_type_arch (type);
880 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
881 CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned,
884 fprintf_filtered (stream, "(");
885 type_print (type, "", stream, -1);
886 fprintf_filtered (stream, ") ");
887 fputs_filtered (paddress (gdbarch, addr), stream);
891 val_print_type_code_int (type, valaddr + offset_aligned, stream);
892 if (ada_is_character_type (type))
896 fputs_filtered (" ", stream);
897 c = unpack_long (type, valaddr + offset_aligned);
898 ada_printchar (c, type, stream);
905 /* Implement Ada val_print'ing for the case where TYPE is
909 ada_val_print_enum (struct type *type, const gdb_byte *valaddr,
910 int offset, int offset_aligned, CORE_ADDR address,
911 struct ui_file *stream, int recurse,
912 const struct value *original_value,
913 const struct value_print_options *options,
914 const struct language_defn *language)
922 val_print_scalar_formatted (type, valaddr, offset_aligned,
923 original_value, options, 0, stream);
927 len = TYPE_NFIELDS (type);
928 val = unpack_long (type, valaddr + offset_aligned);
929 for (i = 0; i < len; i++)
932 if (val == TYPE_FIELD_ENUMVAL (type, i))
938 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
941 fprintf_filtered (stream, "%ld %s", (long) val, name);
943 fputs_filtered (name, stream);
946 print_longest (stream, 'd', 0, val);
949 /* Implement Ada val_print'ing for the case where TYPE is
953 ada_val_print_flt (struct type *type, const gdb_byte *valaddr,
954 int offset, int offset_aligned, CORE_ADDR address,
955 struct ui_file *stream, int recurse,
956 const struct value *original_value,
957 const struct value_print_options *options,
958 const struct language_defn *language)
962 val_print (type, valaddr, offset, address, stream, recurse,
963 original_value, options, language_def (language_c));
967 ada_print_floating (valaddr + offset, type, stream);
970 /* Implement Ada val_print'ing for the case where TYPE is
971 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
974 ada_val_print_struct_union
975 (struct type *type, const gdb_byte *valaddr, int offset,
976 int offset_aligned, CORE_ADDR address, struct ui_file *stream,
977 int recurse, const struct value *original_value,
978 const struct value_print_options *options,
979 const struct language_defn *language)
981 if (ada_is_bogus_array_descriptor (type))
983 fprintf_filtered (stream, "(...?)");
987 fprintf_filtered (stream, "(");
989 if (print_field_values (type, valaddr, offset_aligned,
990 stream, recurse, original_value, options,
991 0, type, offset_aligned) != 0
992 && options->prettyformat)
994 fprintf_filtered (stream, "\n");
995 print_spaces_filtered (2 * recurse, stream);
998 fprintf_filtered (stream, ")");
1001 /* Implement Ada val_print'ing for the case where TYPE is
1005 ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
1006 int offset, int offset_aligned, CORE_ADDR address,
1007 struct ui_file *stream, int recurse,
1008 const struct value *original_value,
1009 const struct value_print_options *options,
1010 const struct language_defn *language)
1012 /* For references, the debugger is expected to print the value as
1013 an address if DEREF_REF is null. But printing an address in place
1014 of the object value would be confusing to an Ada programmer.
1015 So, for Ada values, we print the actual dereferenced value
1017 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
1019 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
1021 CORE_ADDR deref_val_int;
1022 struct value *deref_val;
1024 deref_val = coerce_ref_if_computed (original_value);
1027 if (ada_is_tagged_type (value_type (deref_val), 1))
1028 deref_val = ada_tag_value_at_base_address (deref_val);
1030 common_val_print (deref_val, stream, recurse + 1, options,
1035 deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
1036 if (deref_val_int != 0)
1039 ada_value_ind (value_from_pointer
1040 (lookup_pointer_type (elttype),
1043 if (ada_is_tagged_type (value_type (deref_val), 1))
1044 deref_val = ada_tag_value_at_base_address (deref_val);
1046 val_print (value_type (deref_val),
1047 value_contents_for_printing (deref_val),
1048 value_embedded_offset (deref_val),
1049 value_address (deref_val), stream, recurse + 1,
1050 deref_val, options, current_language);
1053 fputs_filtered ("(null)", stream);
1056 fputs_filtered ("???", stream);
1059 /* See the comment on ada_val_print. This function differs in that it
1060 does not catch evaluation errors (leaving that to ada_val_print). */
1063 ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
1064 int offset, CORE_ADDR address,
1065 struct ui_file *stream, int recurse,
1066 const struct value *original_value,
1067 const struct value_print_options *options,
1068 const struct language_defn *language)
1072 type = ada_check_typedef (type);
1074 if (ada_is_array_descriptor_type (type)
1075 || (ada_is_constrained_packed_array_type (type)
1076 && TYPE_CODE (type) != TYPE_CODE_PTR))
1078 ada_val_print_gnat_array (type, valaddr, offset, address,
1079 stream, recurse, original_value,
1084 offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
1085 type = printable_val_type (type, valaddr + offset_aligned);
1087 switch (TYPE_CODE (type))
1090 val_print (type, valaddr, offset, address, stream, recurse,
1091 original_value, options, language_def (language_c));
1095 ada_val_print_ptr (type, valaddr, offset, offset_aligned,
1096 address, stream, recurse, original_value,
1101 case TYPE_CODE_RANGE:
1102 ada_val_print_num (type, valaddr, offset, offset_aligned,
1103 address, stream, recurse, original_value,
1107 case TYPE_CODE_ENUM:
1108 ada_val_print_enum (type, valaddr, offset, offset_aligned,
1109 address, stream, recurse, original_value,
1114 ada_val_print_flt (type, valaddr, offset, offset_aligned,
1115 address, stream, recurse, original_value,
1119 case TYPE_CODE_UNION:
1120 case TYPE_CODE_STRUCT:
1121 ada_val_print_struct_union (type, valaddr, offset, offset_aligned,
1122 address, stream, recurse,
1123 original_value, options, language);
1126 case TYPE_CODE_ARRAY:
1127 ada_val_print_array (type, valaddr, offset_aligned,
1128 address, stream, recurse, original_value,
1133 ada_val_print_ref (type, valaddr, offset, offset_aligned,
1134 address, stream, recurse, original_value,
1140 /* See val_print for a description of the various parameters of this
1141 function; they are identical. */
1144 ada_val_print (struct type *type, const gdb_byte *valaddr,
1145 int embedded_offset, CORE_ADDR address,
1146 struct ui_file *stream, int recurse,
1147 const struct value *val,
1148 const struct value_print_options *options)
1150 volatile struct gdb_exception except;
1152 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */
1153 TRY_CATCH (except, RETURN_MASK_ALL)
1155 ada_val_print_1 (type, valaddr, embedded_offset, address,
1156 stream, recurse, val, options,
1162 ada_value_print (struct value *val0, struct ui_file *stream,
1163 const struct value_print_options *options)
1165 struct value *val = ada_to_fixed_value (val0);
1166 CORE_ADDR address = value_address (val);
1167 struct type *type = ada_check_typedef (value_type (val));
1168 struct value_print_options opts;
1170 /* If it is a pointer, indicate what it points to. */
1171 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1173 /* Hack: don't print (char *) for char strings. Their
1174 type is indicated by the quoted string anyway. */
1175 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
1176 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
1177 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
1179 fprintf_filtered (stream, "(");
1180 type_print (type, "", stream, -1);
1181 fprintf_filtered (stream, ") ");
1184 else if (ada_is_array_descriptor_type (type))
1186 /* We do not print the type description unless TYPE is an array
1187 access type (this is encoded by the compiler as a typedef to
1188 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1189 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1191 fprintf_filtered (stream, "(");
1192 type_print (type, "", stream, -1);
1193 fprintf_filtered (stream, ") ");
1196 else if (ada_is_bogus_array_descriptor (type))
1198 fprintf_filtered (stream, "(");
1199 type_print (type, "", stream, -1);
1200 fprintf_filtered (stream, ") (...?)");
1206 val_print (type, value_contents_for_printing (val),
1207 value_embedded_offset (val), address,
1208 stream, 0, val, &opts, current_language);