1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2022 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/>. */
23 #include "expression.h"
29 #include "target-float.h"
30 #include "cli/cli-style.h"
33 static int print_field_values (struct value
*, struct value
*,
34 struct ui_file
*, int,
35 const struct value_print_options
*,
36 int, const struct language_defn
*);
40 /* Make TYPE unsigned if its range of values includes no negatives. */
42 adjust_type_signedness (struct type
*type
)
44 if (type
!= NULL
&& type
->code () == TYPE_CODE_RANGE
45 && type
->bounds ()->low
.const_val () >= 0)
46 type
->set_is_unsigned (true);
49 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
50 if non-standard (i.e., other than 1 for numbers, other than lower bound
51 of index type for enumerated type). Returns 1 if something printed,
55 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
56 const struct value_print_options
*options
)
58 struct type
*index_type
;
62 if (options
->print_array_indexes
)
65 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
68 /* If this is an empty array, then don't print the lower bound.
69 That would be confusing, because we would print the lower bound,
70 followed by... nothing! */
71 if (low_bound
> high_bound
)
74 index_type
= type
->index_type ();
76 while (index_type
->code () == TYPE_CODE_RANGE
)
78 /* We need to know what the base type is, in order to do the
79 appropriate check below. Otherwise, if this is a subrange
80 of an enumerated type, where the underlying value of the
81 first element is typically 0, we might test the low bound
82 against the wrong value. */
83 index_type
= TYPE_TARGET_TYPE (index_type
);
86 /* Don't print the lower bound if it's the default one. */
87 switch (index_type
->code ())
97 low_bound
= index_type
->field (low_bound
).loc_enumval ();
108 ada_print_scalar (index_type
, low_bound
, stream
);
109 gdb_printf (stream
, " => ");
113 /* Version of val_print_array_elements for GNAT-style packed arrays.
114 Prints elements of packed array of type TYPE from VALADDR on
115 STREAM. Formats according to OPTIONS and separates with commas.
116 RECURSE is the recursion (nesting) level. TYPE must have been
117 decoded (as by ada_coerce_to_simple_array). */
120 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
121 int offset
, struct ui_file
*stream
,
123 const struct value_print_options
*options
)
126 unsigned int things_printed
= 0;
128 struct type
*elttype
, *index_type
;
129 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
130 struct value
*mark
= value_mark ();
133 elttype
= TYPE_TARGET_TYPE (type
);
134 index_type
= type
->index_type ();
139 if (!get_discrete_bounds (index_type
, &low
, &high
))
143 /* The array length should normally be HIGH_POS - LOW_POS + 1.
144 But in Ada we allow LOW_POS to be greater than HIGH_POS for
145 empty arrays. In that situation, the array length is just zero,
150 len
= high
- low
+ 1;
153 if (index_type
->code () == TYPE_CODE_RANGE
)
154 index_type
= TYPE_TARGET_TYPE (index_type
);
157 annotate_array_section_begin (i
, elttype
);
159 while (i
< len
&& things_printed
< options
->print_max
)
161 struct value
*v0
, *v1
;
166 if (options
->prettyformat_arrays
)
168 gdb_printf (stream
, ",\n");
169 print_spaces (2 + 2 * recurse
, stream
);
173 gdb_printf (stream
, ", ");
176 else if (options
->prettyformat_arrays
)
178 gdb_printf (stream
, "\n");
179 print_spaces (2 + 2 * recurse
, stream
);
181 stream
->wrap_here (2 + 2 * recurse
);
182 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
185 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
186 (i0
* bitsize
) / HOST_CHAR_BIT
,
187 (i0
* bitsize
) % HOST_CHAR_BIT
,
194 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
195 (i
* bitsize
) / HOST_CHAR_BIT
,
196 (i
* bitsize
) % HOST_CHAR_BIT
,
198 if (TYPE_LENGTH (check_typedef (value_type (v0
)))
199 != TYPE_LENGTH (check_typedef (value_type (v1
))))
201 if (!value_contents_eq (v0
, value_embedded_offset (v0
),
202 v1
, value_embedded_offset (v1
),
203 TYPE_LENGTH (check_typedef (value_type (v0
)))))
207 if (i
- i0
> options
->repeat_count_threshold
)
209 struct value_print_options opts
= *options
;
212 common_val_print (v0
, stream
, recurse
+ 1, &opts
, current_language
);
213 annotate_elt_rep (i
- i0
);
214 gdb_printf (stream
, _(" %p[<repeats %u times>%p]"),
215 metadata_style
.style ().ptr (), i
- i0
, nullptr);
216 annotate_elt_rep_end ();
222 struct value_print_options opts
= *options
;
225 for (j
= i0
; j
< i
; j
+= 1)
229 if (options
->prettyformat_arrays
)
231 gdb_printf (stream
, ",\n");
232 print_spaces (2 + 2 * recurse
, stream
);
236 gdb_printf (stream
, ", ");
238 stream
->wrap_here (2 + 2 * recurse
);
239 maybe_print_array_index (index_type
, j
+ low
,
242 common_val_print (v0
, stream
, recurse
+ 1, &opts
,
247 things_printed
+= i
- i0
;
249 annotate_array_section_end ();
252 gdb_printf (stream
, "...");
255 value_free_to_mark (mark
);
258 /* Print the character C on STREAM as part of the contents of a literal
259 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
263 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
264 int quoter
, int type_len
)
266 /* If this character fits in the normal ASCII range, and is
267 a printable character, then print the character as if it was
268 an ASCII character, even if this is a wide character.
269 The UCHAR_MAX check is necessary because the isascii function
270 requires that its argument have a value of an unsigned char,
271 or EOF (EOF is obviously not printable). */
272 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
274 if (c
== quoter
&& c
== '"')
275 gdb_printf (stream
, "\"\"");
277 gdb_printf (stream
, "%c", c
);
281 /* Follow GNAT's lead here and only use 6 digits for
282 wide_wide_character. */
283 gdb_printf (stream
, "[\"%0*x\"]", std::min (6, type_len
* 2), c
);
287 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
291 char_at (const gdb_byte
*string
, int i
, int type_len
,
292 enum bfd_endian byte_order
)
297 return (int) extract_unsigned_integer (string
+ type_len
* i
,
298 type_len
, byte_order
);
301 /* Print a floating-point value of type TYPE, pointed to in GDB by
302 VALADDR, on STREAM. Use Ada formatting conventions: there must be
303 a decimal point, and at least one digit before and after the
304 point. We use the GNAT format for NaNs and infinities. */
307 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
308 struct ui_file
*stream
)
310 string_file tmp_stream
;
312 print_floating (valaddr
, type
, &tmp_stream
);
314 std::string s
= tmp_stream
.release ();
315 size_t skip_count
= 0;
317 /* Don't try to modify a result representing an error. */
320 gdb_puts (s
.c_str (), stream
);
324 /* Modify for Ada rules. */
326 size_t pos
= s
.find ("inf");
327 if (pos
== std::string::npos
)
328 pos
= s
.find ("Inf");
329 if (pos
== std::string::npos
)
330 pos
= s
.find ("INF");
331 if (pos
!= std::string::npos
)
332 s
.replace (pos
, 3, "Inf");
334 if (pos
== std::string::npos
)
336 pos
= s
.find ("nan");
337 if (pos
== std::string::npos
)
338 pos
= s
.find ("NaN");
339 if (pos
== std::string::npos
)
340 pos
= s
.find ("Nan");
341 if (pos
!= std::string::npos
)
343 s
[pos
] = s
[pos
+ 2] = 'N';
349 if (pos
== std::string::npos
350 && s
.find ('.') == std::string::npos
)
353 if (pos
== std::string::npos
)
354 gdb_printf (stream
, "%s.0", s
.c_str ());
356 gdb_printf (stream
, "%.*s.0%s", (int) pos
, s
.c_str (), &s
[pos
]);
359 gdb_printf (stream
, "%s", &s
[skip_count
]);
363 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
365 gdb_puts ("'", stream
);
366 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
367 gdb_puts ("'", stream
);
370 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
371 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
372 like a default signed integer. */
375 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
382 print_longest (stream
, 'd', 0, val
);
386 type
= ada_check_typedef (type
);
388 switch (type
->code ())
392 len
= type
->num_fields ();
393 for (i
= 0; i
< len
; i
++)
395 if (type
->field (i
).loc_enumval () == val
)
402 fputs_styled (ada_enum_name (type
->field (i
).name ()),
403 variable_name_style
.style (), stream
);
407 print_longest (stream
, 'd', 0, val
);
412 print_longest (stream
, type
->is_unsigned () ? 'u' : 'd', 0, val
);
416 current_language
->printchar (val
, type
, stream
);
420 gdb_printf (stream
, val
? "true" : "false");
423 case TYPE_CODE_RANGE
:
424 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
427 case TYPE_CODE_UNDEF
:
429 case TYPE_CODE_ARRAY
:
430 case TYPE_CODE_STRUCT
:
431 case TYPE_CODE_UNION
:
436 case TYPE_CODE_STRING
:
437 case TYPE_CODE_ERROR
:
438 case TYPE_CODE_MEMBERPTR
:
439 case TYPE_CODE_METHODPTR
:
440 case TYPE_CODE_METHOD
:
442 warning (_("internal error: unhandled type in ada_print_scalar"));
446 error (_("Invalid type code in symbol table."));
450 /* Print the character string STRING, printing at most LENGTH characters.
451 Printing stops early if the number hits print_max; repeat counts
452 are printed as appropriate. Print ellipses at the end if we
453 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
454 TYPE_LEN is the length (1 or 2) of the character type. */
457 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
458 unsigned int length
, int force_ellipses
, int type_len
,
459 const struct value_print_options
*options
)
461 enum bfd_endian byte_order
= type_byte_order (elttype
);
463 unsigned int things_printed
= 0;
469 gdb_puts ("\"\"", stream
);
473 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
475 /* Position of the character we are examining
476 to see whether it is repeated. */
478 /* Number of repetitions we have detected so far. */
485 gdb_puts (", ", stream
);
492 && char_at (string
, rep1
, type_len
, byte_order
)
493 == char_at (string
, i
, type_len
, byte_order
))
499 if (reps
> options
->repeat_count_threshold
)
503 gdb_puts ("\", ", stream
);
506 gdb_puts ("'", stream
);
507 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
508 elttype
, stream
, '\'', type_len
);
509 gdb_puts ("'", stream
);
510 gdb_printf (stream
, _(" %p[<repeats %u times>%p]"),
511 metadata_style
.style ().ptr (), reps
, nullptr);
513 things_printed
+= options
->repeat_count_threshold
;
520 gdb_puts ("\"", stream
);
523 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
524 elttype
, stream
, '"', type_len
);
529 /* Terminate the quotes if necessary. */
531 gdb_puts ("\"", stream
);
533 if (force_ellipses
|| i
< length
)
534 gdb_puts ("...", stream
);
538 ada_printstr (struct ui_file
*stream
, struct type
*type
,
539 const gdb_byte
*string
, unsigned int length
,
540 const char *encoding
, int force_ellipses
,
541 const struct value_print_options
*options
)
543 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
548 print_variant_part (struct value
*value
, int field_num
,
549 struct value
*outer_value
,
550 struct ui_file
*stream
, int recurse
,
551 const struct value_print_options
*options
,
553 const struct language_defn
*language
)
555 struct type
*type
= value_type (value
);
556 struct type
*var_type
= type
->field (field_num
).type ();
557 int which
= ada_which_variant_applies (var_type
, outer_value
);
562 struct value
*variant_field
= value_field (value
, field_num
);
563 struct value
*active_component
= value_field (variant_field
, which
);
564 return print_field_values (active_component
, outer_value
, stream
, recurse
,
565 options
, comma_needed
, language
);
568 /* Print out fields of VALUE.
570 STREAM, RECURSE, and OPTIONS have the same meanings as in
571 ada_print_value and ada_value_print.
573 OUTER_VALUE gives the enclosing record (used to get discriminant
574 values when printing variant parts).
576 COMMA_NEEDED is 1 if fields have been printed at the current recursion
577 level, so that a comma is needed before any field printed by this
580 Returns 1 if COMMA_NEEDED or any fields were printed. */
583 print_field_values (struct value
*value
, struct value
*outer_value
,
584 struct ui_file
*stream
, int recurse
,
585 const struct value_print_options
*options
,
587 const struct language_defn
*language
)
591 struct type
*type
= value_type (value
);
592 len
= type
->num_fields ();
594 for (i
= 0; i
< len
; i
+= 1)
596 if (ada_is_ignored_field (type
, i
))
599 if (ada_is_wrapper_field (type
, i
))
601 struct value
*field_val
= ada_value_primitive_field (value
, 0,
604 print_field_values (field_val
, field_val
,
605 stream
, recurse
, options
,
606 comma_needed
, language
);
609 else if (ada_is_variant_part (type
, i
))
612 print_variant_part (value
, i
, outer_value
, stream
, recurse
,
613 options
, comma_needed
, language
);
618 gdb_printf (stream
, ", ");
621 if (options
->prettyformat
)
623 gdb_printf (stream
, "\n");
624 print_spaces (2 + 2 * recurse
, stream
);
628 stream
->wrap_here (2 + 2 * recurse
);
631 annotate_field_begin (type
->field (i
).type ());
632 gdb_printf (stream
, "%.*s",
633 ada_name_prefix_len (type
->field (i
).name ()),
634 type
->field (i
).name ());
635 annotate_field_name_end ();
636 gdb_puts (" => ", stream
);
637 annotate_field_value ();
639 if (TYPE_FIELD_PACKED (type
, i
))
641 /* Bitfields require special handling, especially due to byte
643 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
645 fputs_styled (_("<optimized out or zero length>"),
646 metadata_style
.style (), stream
);
651 int bit_pos
= type
->field (i
).loc_bitpos ();
652 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
653 struct value_print_options opts
;
655 adjust_type_signedness (type
->field (i
).type ());
656 v
= ada_value_primitive_packed_val
658 bit_pos
/ HOST_CHAR_BIT
,
659 bit_pos
% HOST_CHAR_BIT
,
660 bit_size
, type
->field (i
).type ());
663 common_val_print (v
, stream
, recurse
+ 1, &opts
, language
);
668 struct value_print_options opts
= *options
;
672 struct value
*v
= value_field (value
, i
);
673 common_val_print (v
, stream
, recurse
+ 1, &opts
, language
);
675 annotate_field_end ();
681 /* Implement Ada val_print'ing for the case where TYPE is
682 a TYPE_CODE_ARRAY of characters. */
685 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
687 struct ui_file
*stream
, int recurse
,
688 const struct value_print_options
*options
)
690 enum bfd_endian byte_order
= type_byte_order (type
);
691 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
695 /* We know that ELTTYPE cannot possibly be null, because we assume
696 that we're called only when TYPE is a string-like type.
697 Similarly, the size of ELTTYPE should also be non-null, since
698 it's a character-like type. */
699 gdb_assert (elttype
!= NULL
);
700 gdb_assert (TYPE_LENGTH (elttype
) != 0);
702 eltlen
= TYPE_LENGTH (elttype
);
703 len
= TYPE_LENGTH (type
) / eltlen
;
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 value_print'ing for the case where TYPE is a
729 ada_value_print_ptr (struct value
*val
,
730 struct ui_file
*stream
, int recurse
,
731 const struct value_print_options
*options
)
734 && TYPE_TARGET_TYPE (value_type (val
))->code () == TYPE_CODE_INT
735 && TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (val
))) == 0)
737 gdb_puts ("null", stream
);
741 common_val_print (val
, stream
, recurse
, options
, language_def (language_c
));
743 struct type
*type
= ada_check_typedef (value_type (val
));
744 if (ada_is_tag_type (type
))
746 gdb::unique_xmalloc_ptr
<char> name
= ada_tag_name (val
);
749 gdb_printf (stream
, " (%s)", name
.get ());
753 /* Implement Ada val_print'ing for the case where TYPE is
754 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
757 ada_value_print_num (struct value
*val
, struct ui_file
*stream
, int recurse
,
758 const struct value_print_options
*options
)
760 struct type
*type
= ada_check_typedef (value_type (val
));
761 const gdb_byte
*valaddr
= value_contents_for_printing (val
).data ();
763 if (type
->code () == TYPE_CODE_RANGE
764 && (TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_ENUM
765 || TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_BOOL
766 || TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_CHAR
))
768 /* For enum-valued ranges, we want to recurse, because we'll end
769 up printing the constant's name rather than its numeric
770 value. Character and fixed-point types are also printed
771 differently, so recuse for those as well. */
772 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
773 val
= value_cast (target_type
, val
);
774 common_val_print (val
, stream
, recurse
+ 1, options
,
775 language_def (language_ada
));
780 int format
= (options
->format
? options
->format
781 : options
->output_format
);
785 struct value_print_options opts
= *options
;
787 opts
.format
= format
;
788 value_print_scalar_formatted (val
, &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
= type
->arch ();
799 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
800 CORE_ADDR addr
= extract_typed_address (valaddr
, ptr_type
);
802 gdb_printf (stream
, "(");
803 type_print (type
, "", stream
, -1);
804 gdb_printf (stream
, ") ");
805 gdb_puts (paddress (gdbarch
, addr
), stream
);
809 value_print_scalar_formatted (val
, options
, 0, stream
);
810 if (ada_is_character_type (type
))
814 gdb_puts (" ", stream
);
815 c
= unpack_long (type
, valaddr
);
816 ada_printchar (c
, type
, stream
);
823 /* Implement Ada val_print'ing for the case where TYPE is
827 ada_val_print_enum (struct value
*value
, struct ui_file
*stream
, int recurse
,
828 const struct value_print_options
*options
)
836 value_print_scalar_formatted (value
, options
, 0, stream
);
840 struct type
*type
= ada_check_typedef (value_type (value
));
841 const gdb_byte
*valaddr
= value_contents_for_printing (value
).data ();
842 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
844 len
= type
->num_fields ();
845 val
= unpack_long (type
, valaddr
+ offset_aligned
);
846 for (i
= 0; i
< len
; i
++)
849 if (val
== type
->field (i
).loc_enumval ())
855 const char *name
= ada_enum_name (type
->field (i
).name ());
858 gdb_printf (stream
, "%ld %ps", (long) val
,
859 styled_string (variable_name_style
.style (),
862 fputs_styled (name
, variable_name_style
.style (), stream
);
865 print_longest (stream
, 'd', 0, val
);
868 /* Implement Ada val_print'ing for the case where the type is
869 TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
872 ada_val_print_struct_union (struct value
*value
,
873 struct ui_file
*stream
,
875 const struct value_print_options
*options
)
877 if (ada_is_bogus_array_descriptor (value_type (value
)))
879 gdb_printf (stream
, "(...?)");
883 gdb_printf (stream
, "(");
885 if (print_field_values (value
, value
, stream
, recurse
, options
,
886 0, language_def (language_ada
)) != 0
887 && options
->prettyformat
)
889 gdb_printf (stream
, "\n");
890 print_spaces (2 * recurse
, stream
);
893 gdb_printf (stream
, ")");
896 /* Implement Ada value_print'ing for the case where TYPE is a
900 ada_value_print_array (struct value
*val
, struct ui_file
*stream
, int recurse
,
901 const struct value_print_options
*options
)
903 struct type
*type
= ada_check_typedef (value_type (val
));
905 /* For an array of characters, print with string syntax. */
906 if (ada_is_string_type (type
)
907 && (options
->format
== 0 || options
->format
== 's'))
909 const gdb_byte
*valaddr
= value_contents_for_printing (val
).data ();
910 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
912 ada_val_print_string (type
, valaddr
, offset_aligned
, stream
, recurse
,
917 gdb_printf (stream
, "(");
918 print_optional_low_bound (stream
, type
, options
);
920 if (value_entirely_optimized_out (val
))
921 val_print_optimized_out (val
, stream
);
922 else if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
924 const gdb_byte
*valaddr
= value_contents_for_printing (val
).data ();
925 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
926 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
927 stream
, recurse
, options
);
930 value_print_array_elements (val
, stream
, recurse
, options
, 0);
931 gdb_printf (stream
, ")");
934 /* Implement Ada val_print'ing for the case where TYPE is
938 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
939 int offset
, int offset_aligned
, CORE_ADDR address
,
940 struct ui_file
*stream
, int recurse
,
941 struct value
*original_value
,
942 const struct value_print_options
*options
)
944 /* For references, the debugger is expected to print the value as
945 an address if DEREF_REF is null. But printing an address in place
946 of the object value would be confusing to an Ada programmer.
947 So, for Ada values, we print the actual dereferenced value
949 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
950 struct value
*deref_val
;
951 CORE_ADDR deref_val_int
;
953 if (elttype
->code () == TYPE_CODE_UNDEF
)
955 fputs_styled ("<ref to undefined type>", metadata_style
.style (),
960 deref_val
= coerce_ref_if_computed (original_value
);
963 if (ada_is_tagged_type (value_type (deref_val
), 1))
964 deref_val
= ada_tag_value_at_base_address (deref_val
);
966 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
967 language_def (language_ada
));
971 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
972 if (deref_val_int
== 0)
974 gdb_puts ("(null)", stream
);
979 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
981 if (ada_is_tagged_type (value_type (deref_val
), 1))
982 deref_val
= ada_tag_value_at_base_address (deref_val
);
984 if (value_lazy (deref_val
))
985 value_fetch_lazy (deref_val
);
987 common_val_print (deref_val
, stream
, recurse
+ 1,
988 options
, language_def (language_ada
));
991 /* See the comment on ada_value_print. This function differs in that
992 it does not catch evaluation errors (leaving that to its
996 ada_value_print_inner (struct value
*val
, struct ui_file
*stream
, int recurse
,
997 const struct value_print_options
*options
)
999 struct type
*type
= ada_check_typedef (value_type (val
));
1001 if (ada_is_array_descriptor_type (type
)
1002 || (ada_is_constrained_packed_array_type (type
)
1003 && type
->code () != TYPE_CODE_PTR
))
1005 /* If this is a reference, coerce it now. This helps taking
1006 care of the case where ADDRESS is meaningless because
1007 original_value was not an lval. */
1008 val
= coerce_ref (val
);
1009 val
= ada_get_decoded_value (val
);
1012 gdb_assert (type
->code () == TYPE_CODE_TYPEDEF
);
1013 gdb_printf (stream
, "0x0");
1018 val
= ada_to_fixed_value (val
);
1020 type
= value_type (val
);
1021 struct type
*saved_type
= type
;
1023 const gdb_byte
*valaddr
= value_contents_for_printing (val
).data ();
1024 CORE_ADDR address
= value_address (val
);
1025 gdb::array_view
<const gdb_byte
> view
1026 = gdb::make_array_view (valaddr
, TYPE_LENGTH (type
));
1027 type
= ada_check_typedef (resolve_dynamic_type (type
, view
, address
));
1028 if (type
!= saved_type
)
1030 val
= value_copy (val
);
1031 deprecated_set_value_type (val
, type
);
1034 if (is_fixed_point_type (type
))
1035 type
= type
->fixed_point_type_base_type ();
1037 switch (type
->code ())
1040 common_val_print (val
, stream
, recurse
, options
,
1041 language_def (language_c
));
1045 ada_value_print_ptr (val
, stream
, recurse
, options
);
1049 case TYPE_CODE_RANGE
:
1050 ada_value_print_num (val
, stream
, recurse
, options
);
1053 case TYPE_CODE_ENUM
:
1054 ada_val_print_enum (val
, stream
, recurse
, options
);
1058 if (options
->format
)
1060 common_val_print (val
, stream
, recurse
, options
,
1061 language_def (language_c
));
1065 ada_print_floating (valaddr
, type
, stream
);
1068 case TYPE_CODE_UNION
:
1069 case TYPE_CODE_STRUCT
:
1070 ada_val_print_struct_union (val
, stream
, recurse
, options
);
1073 case TYPE_CODE_ARRAY
:
1074 ada_value_print_array (val
, stream
, recurse
, options
);
1078 ada_val_print_ref (type
, valaddr
, 0, 0,
1079 address
, stream
, recurse
, val
,
1086 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1087 const struct value_print_options
*options
)
1089 struct value
*val
= ada_to_fixed_value (val0
);
1090 struct type
*type
= ada_check_typedef (value_type (val
));
1091 struct value_print_options opts
;
1093 /* If it is a pointer, indicate what it points to; but not for
1094 "void *" pointers. */
1095 if (type
->code () == TYPE_CODE_PTR
1096 && !(TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_INT
1097 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == 0))
1099 /* Hack: don't print (char *) for char strings. Their
1100 type is indicated by the quoted string anyway. */
1101 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
1102 || TYPE_TARGET_TYPE (type
)->code () != TYPE_CODE_INT
1103 || TYPE_TARGET_TYPE (type
)->is_unsigned ())
1105 gdb_printf (stream
, "(");
1106 type_print (type
, "", stream
, -1);
1107 gdb_printf (stream
, ") ");
1110 else if (ada_is_array_descriptor_type (type
))
1112 /* We do not print the type description unless TYPE is an array
1113 access type (this is encoded by the compiler as a typedef to
1114 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1115 if (type
->code () == TYPE_CODE_TYPEDEF
)
1117 gdb_printf (stream
, "(");
1118 type_print (type
, "", stream
, -1);
1119 gdb_printf (stream
, ") ");
1122 else if (ada_is_bogus_array_descriptor (type
))
1124 gdb_printf (stream
, "(");
1125 type_print (type
, "", stream
, -1);
1126 gdb_printf (stream
, ") (...?)");
1132 common_val_print (val
, stream
, 0, &opts
, current_language
);