1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2024 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/>. */
22 #include "expression.h"
28 #include "target-float.h"
29 #include "cli/cli-style.h"
32 static int print_field_values (struct value
*, struct value
*,
33 struct ui_file
*, int,
34 const struct value_print_options
*,
35 int, const struct language_defn
*);
39 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
40 if non-standard (i.e., other than 1 for numbers, other than lower bound
41 of index type for enumerated type). Returns 1 if something printed,
45 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
46 const struct value_print_options
*options
)
48 struct type
*index_type
;
52 if (options
->print_array_indexes
)
55 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
58 /* If this is an empty array, then don't print the lower bound.
59 That would be confusing, because we would print the lower bound,
60 followed by... nothing! */
61 if (low_bound
> high_bound
)
64 index_type
= type
->index_type ();
66 while (index_type
->code () == TYPE_CODE_RANGE
)
68 /* We need to know what the base type is, in order to do the
69 appropriate check below. Otherwise, if this is a subrange
70 of an enumerated type, where the underlying value of the
71 first element is typically 0, we might test the low bound
72 against the wrong value. */
73 index_type
= index_type
->target_type ();
76 /* Don't print the lower bound if it's the default one. */
77 switch (index_type
->code ())
87 low_bound
= index_type
->field (low_bound
).loc_enumval ();
98 ada_print_scalar (index_type
, low_bound
, stream
);
99 gdb_printf (stream
, " => ");
103 /* Version of val_print_array_elements for GNAT-style packed arrays.
104 Prints elements of packed array of type TYPE from VALADDR on
105 STREAM. Formats according to OPTIONS and separates with commas.
106 RECURSE is the recursion (nesting) level. TYPE must have been
107 decoded (as by ada_coerce_to_simple_array). */
110 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
111 int offset
, struct ui_file
*stream
,
113 const struct value_print_options
*options
)
116 unsigned int things_printed
= 0;
118 struct type
*elttype
, *index_type
;
119 unsigned long bitsize
= type
->field (0).bitsize ();
122 scoped_value_mark mark
;
124 elttype
= type
->target_type ();
125 index_type
= type
->index_type ();
130 if (!get_discrete_bounds (index_type
, &low
, &high
))
134 /* The array length should normally be HIGH_POS - LOW_POS + 1.
135 But in Ada we allow LOW_POS to be greater than HIGH_POS for
136 empty arrays. In that situation, the array length is just zero,
141 len
= high
- low
+ 1;
144 if (index_type
->code () == TYPE_CODE_RANGE
)
145 index_type
= index_type
->target_type ();
148 annotate_array_section_begin (i
, elttype
);
150 while (i
< len
&& things_printed
< options
->print_max
)
152 /* Both this outer loop and the inner loop that checks for
153 duplicates may allocate many values. To avoid using too much
154 memory, both spots release values as they work. */
155 scoped_value_mark outer_free_values
;
157 struct value
*v0
, *v1
;
162 if (options
->prettyformat_arrays
)
164 gdb_printf (stream
, ",\n");
165 print_spaces (2 + 2 * recurse
, stream
);
169 gdb_printf (stream
, ", ");
172 else if (options
->prettyformat_arrays
)
174 gdb_printf (stream
, "\n");
175 print_spaces (2 + 2 * recurse
, stream
);
177 stream
->wrap_here (2 + 2 * recurse
);
178 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
181 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
182 (i0
* bitsize
) / HOST_CHAR_BIT
,
183 (i0
* bitsize
) % HOST_CHAR_BIT
,
187 /* Make sure to free any values in the inner loop. */
188 scoped_value_mark free_values
;
193 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
194 (i
* bitsize
) / HOST_CHAR_BIT
,
195 (i
* bitsize
) % HOST_CHAR_BIT
,
197 if (check_typedef (v0
->type ())->length ()
198 != check_typedef (v1
->type ())->length ())
200 if (!v0
->contents_eq (v0
->embedded_offset (),
201 v1
, v1
->embedded_offset (),
202 check_typedef (v0
->type ())->length ()))
206 if (i
- i0
> options
->repeat_count_threshold
)
208 struct value_print_options opts
= *options
;
210 opts
.deref_ref
= false;
211 common_val_print (v0
, stream
, recurse
+ 1, &opts
, current_language
);
212 annotate_elt_rep (i
- i0
);
213 gdb_printf (stream
, _(" %p[<repeats %u times>%p]"),
214 metadata_style
.style ().ptr (), i
- i0
, nullptr);
215 annotate_elt_rep_end ();
221 struct value_print_options opts
= *options
;
223 opts
.deref_ref
= false;
224 for (j
= i0
; j
< i
; j
+= 1)
228 if (options
->prettyformat_arrays
)
230 gdb_printf (stream
, ",\n");
231 print_spaces (2 + 2 * recurse
, stream
);
235 gdb_printf (stream
, ", ");
237 stream
->wrap_here (2 + 2 * recurse
);
238 maybe_print_array_index (index_type
, j
+ low
,
241 common_val_print (v0
, stream
, recurse
+ 1, &opts
,
246 things_printed
+= i
- i0
;
248 annotate_array_section_end ();
251 gdb_printf (stream
, "...");
255 /* Print the character C on STREAM as part of the contents of a literal
256 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
260 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
261 int quoter
, int type_len
)
263 /* If this character fits in the normal ASCII range, and is
264 a printable character, then print the character as if it was
265 an ASCII character, even if this is a wide character.
266 The UCHAR_MAX check is necessary because the isascii function
267 requires that its argument have a value of an unsigned char,
268 or EOF (EOF is obviously not printable). */
269 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
271 if (c
== quoter
&& c
== '"')
272 gdb_printf (stream
, "\"\"");
274 gdb_printf (stream
, "%c", c
);
278 /* Follow GNAT's lead here and only use 6 digits for
279 wide_wide_character. */
280 gdb_printf (stream
, "[\"%0*x\"]", std::min (6, type_len
* 2), c
);
284 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
288 char_at (const gdb_byte
*string
, int i
, int type_len
,
289 enum bfd_endian byte_order
)
294 return (int) extract_unsigned_integer (string
+ type_len
* i
,
295 type_len
, byte_order
);
298 /* Print a floating-point value of type TYPE, pointed to in GDB by
299 VALADDR, on STREAM. Use Ada formatting conventions: there must be
300 a decimal point, and at least one digit before and after the
301 point. We use the GNAT format for NaNs and infinities. */
304 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
305 struct ui_file
*stream
)
307 string_file tmp_stream
;
309 print_floating (valaddr
, type
, &tmp_stream
);
311 std::string s
= tmp_stream
.release ();
312 size_t skip_count
= 0;
314 /* Don't try to modify a result representing an error. */
317 gdb_puts (s
.c_str (), stream
);
321 /* Modify for Ada rules. */
323 size_t pos
= s
.find ("inf");
324 if (pos
== std::string::npos
)
325 pos
= s
.find ("Inf");
326 if (pos
== std::string::npos
)
327 pos
= s
.find ("INF");
328 if (pos
!= std::string::npos
)
329 s
.replace (pos
, 3, "Inf");
331 if (pos
== std::string::npos
)
333 pos
= s
.find ("nan");
334 if (pos
== std::string::npos
)
335 pos
= s
.find ("NaN");
336 if (pos
== std::string::npos
)
337 pos
= s
.find ("Nan");
338 if (pos
!= std::string::npos
)
340 s
[pos
] = s
[pos
+ 2] = 'N';
346 if (pos
== std::string::npos
347 && s
.find ('.') == std::string::npos
)
350 if (pos
== std::string::npos
)
351 gdb_printf (stream
, "%s.0", s
.c_str ());
353 gdb_printf (stream
, "%.*s.0%s", (int) pos
, s
.c_str (), &s
[pos
]);
356 gdb_printf (stream
, "%s", &s
[skip_count
]);
360 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
362 gdb_puts ("'", stream
);
363 ada_emit_char (c
, type
, stream
, '\'', type
->length ());
364 gdb_puts ("'", stream
);
367 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
368 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
369 like a default signed integer. */
372 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 ())
387 std::optional
<LONGEST
> posn
= discrete_position (type
, val
);
388 if (posn
.has_value ())
389 fputs_styled (ada_enum_name (type
->field (*posn
).name ()),
390 variable_name_style
.style (), stream
);
392 print_longest (stream
, 'd', 0, val
);
397 print_longest (stream
, type
->is_unsigned () ? 'u' : 'd', 0, val
);
401 current_language
->printchar (val
, type
, stream
);
405 gdb_printf (stream
, val
? "true" : "false");
408 case TYPE_CODE_RANGE
:
409 ada_print_scalar (type
->target_type (), val
, stream
);
412 case TYPE_CODE_UNDEF
:
414 case TYPE_CODE_ARRAY
:
415 case TYPE_CODE_STRUCT
:
416 case TYPE_CODE_UNION
:
421 case TYPE_CODE_STRING
:
422 case TYPE_CODE_ERROR
:
423 case TYPE_CODE_MEMBERPTR
:
424 case TYPE_CODE_METHODPTR
:
425 case TYPE_CODE_METHOD
:
427 warning (_("internal error: unhandled type in ada_print_scalar"));
431 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
= type_byte_order (elttype
);
448 unsigned int things_printed
= 0;
454 gdb_puts ("\"\"", stream
);
458 unsigned int print_max_chars
= get_print_max_chars (options
);
459 for (i
= 0; i
< length
&& things_printed
< print_max_chars
; i
+= 1)
461 /* Position of the character we are examining
462 to see whether it is repeated. */
464 /* Number of repetitions we have detected so far. */
471 gdb_puts (", ", stream
);
478 && char_at (string
, rep1
, type_len
, byte_order
)
479 == char_at (string
, i
, type_len
, byte_order
))
485 if (reps
> options
->repeat_count_threshold
)
489 gdb_puts ("\", ", stream
);
492 gdb_puts ("'", stream
);
493 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
494 elttype
, stream
, '\'', type_len
);
495 gdb_puts ("'", stream
);
496 gdb_printf (stream
, _(" %p[<repeats %u times>%p]"),
497 metadata_style
.style ().ptr (), reps
, nullptr);
499 things_printed
+= options
->repeat_count_threshold
;
506 gdb_puts ("\"", stream
);
509 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
510 elttype
, stream
, '"', type_len
);
515 /* Terminate the quotes if necessary. */
517 gdb_puts ("\"", stream
);
519 if (force_ellipses
|| i
< length
)
520 gdb_puts ("...", stream
);
524 ada_printstr (struct ui_file
*stream
, struct type
*type
,
525 const gdb_byte
*string
, unsigned int length
,
526 const char *encoding
, int force_ellipses
,
527 const struct value_print_options
*options
)
529 printstr (stream
, type
, string
, length
, force_ellipses
, type
->length (),
534 print_variant_part (struct value
*value
, int field_num
,
535 struct value
*outer_value
,
536 struct ui_file
*stream
, int recurse
,
537 const struct value_print_options
*options
,
539 const struct language_defn
*language
)
541 struct type
*type
= value
->type ();
542 struct type
*var_type
= type
->field (field_num
).type ();
543 int which
= ada_which_variant_applies (var_type
, outer_value
);
548 struct value
*variant_field
= value_field (value
, field_num
);
549 struct value
*active_component
= value_field (variant_field
, which
);
550 return print_field_values (active_component
, outer_value
, stream
, recurse
,
551 options
, comma_needed
, language
);
554 /* Print out fields of VALUE.
556 STREAM, RECURSE, and OPTIONS have the same meanings as in
557 ada_print_value and ada_value_print.
559 OUTER_VALUE gives the enclosing record (used to get discriminant
560 values when printing variant parts).
562 COMMA_NEEDED is 1 if fields have been printed at the current recursion
563 level, so that a comma is needed before any field printed by this
566 Returns 1 if COMMA_NEEDED or any fields were printed. */
569 print_field_values (struct value
*value
, struct value
*outer_value
,
570 struct ui_file
*stream
, int recurse
,
571 const struct value_print_options
*options
,
573 const struct language_defn
*language
)
577 struct type
*type
= value
->type ();
578 len
= type
->num_fields ();
580 for (i
= 0; i
< len
; i
+= 1)
582 if (ada_is_ignored_field (type
, i
))
585 if (ada_is_wrapper_field (type
, i
))
587 struct value
*field_val
= ada_value_primitive_field (value
, 0,
590 print_field_values (field_val
, field_val
,
591 stream
, recurse
, options
,
592 comma_needed
, language
);
595 else if (ada_is_variant_part (type
, i
))
598 print_variant_part (value
, i
, outer_value
, stream
, recurse
,
599 options
, comma_needed
, language
);
604 gdb_printf (stream
, ", ");
607 if (options
->prettyformat
)
609 gdb_printf (stream
, "\n");
610 print_spaces (2 + 2 * recurse
, stream
);
614 stream
->wrap_here (2 + 2 * recurse
);
617 annotate_field_begin (type
->field (i
).type ());
618 gdb_printf (stream
, "%.*s",
619 ada_name_prefix_len (type
->field (i
).name ()),
620 type
->field (i
).name ());
621 annotate_field_name_end ();
622 gdb_puts (" => ", stream
);
623 annotate_field_value ();
625 if (type
->field (i
).is_packed ())
627 /* Bitfields require special handling, especially due to byte
629 if (type
->field (i
).is_ignored ())
631 fputs_styled (_("<optimized out or zero length>"),
632 metadata_style
.style (), stream
);
637 int bit_pos
= type
->field (i
).loc_bitpos ();
638 int bit_size
= type
->field (i
).bitsize ();
639 struct value_print_options opts
;
641 v
= ada_value_primitive_packed_val
643 bit_pos
/ HOST_CHAR_BIT
,
644 bit_pos
% HOST_CHAR_BIT
,
645 bit_size
, type
->field (i
).type ());
647 opts
.deref_ref
= false;
648 common_val_print (v
, stream
, recurse
+ 1, &opts
, language
);
653 struct value_print_options opts
= *options
;
655 opts
.deref_ref
= false;
657 struct value
*v
= value_field (value
, i
);
658 common_val_print (v
, stream
, recurse
+ 1, &opts
, language
);
660 annotate_field_end ();
666 /* Implement Ada val_print'ing for the case where TYPE is
667 a TYPE_CODE_ARRAY of characters. */
670 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
672 struct ui_file
*stream
, int recurse
,
673 const struct value_print_options
*options
)
675 enum bfd_endian byte_order
= type_byte_order (type
);
676 struct type
*elttype
= type
->target_type ();
680 /* We know that ELTTYPE cannot possibly be null, because we assume
681 that we're called only when TYPE is a string-like type.
682 Similarly, the size of ELTTYPE should also be non-null, since
683 it's a character-like type. */
684 gdb_assert (elttype
!= NULL
);
685 gdb_assert (elttype
->length () != 0);
687 eltlen
= elttype
->length ();
688 len
= type
->length () / eltlen
;
690 /* If requested, look for the first null char and only print
691 elements up to it. */
692 if (options
->stop_print_at_null
)
694 unsigned int print_max_chars
= get_print_max_chars (options
);
697 /* Look for a NULL char. */
700 && temp_len
< print_max_chars
701 && char_at (valaddr
+ offset_aligned
,
702 temp_len
, eltlen
, byte_order
) != 0);
707 printstr (stream
, elttype
, valaddr
+ offset_aligned
, len
, 0,
711 /* Implement Ada value_print'ing for the case where TYPE is a
715 ada_value_print_ptr (struct value
*val
,
716 struct ui_file
*stream
, int recurse
,
717 const struct value_print_options
*options
)
720 && val
->type ()->target_type ()->code () == TYPE_CODE_INT
721 && val
->type ()->target_type ()->length () == 0)
723 gdb_puts ("null", stream
);
727 common_val_print (val
, stream
, recurse
, options
, language_def (language_c
));
729 struct type
*type
= ada_check_typedef (val
->type ());
730 if (ada_is_tag_type (type
))
732 gdb::unique_xmalloc_ptr
<char> name
= ada_tag_name (val
);
735 gdb_printf (stream
, " (%s)", name
.get ());
739 /* Implement Ada val_print'ing for the case where TYPE is
740 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
743 ada_value_print_num (struct value
*val
, struct ui_file
*stream
, int recurse
,
744 const struct value_print_options
*options
)
746 struct type
*type
= ada_check_typedef (val
->type ());
747 const gdb_byte
*valaddr
= val
->contents_for_printing ().data ();
749 if (type
->code () == TYPE_CODE_RANGE
750 && (type
->target_type ()->code () == TYPE_CODE_ENUM
751 || type
->target_type ()->code () == TYPE_CODE_BOOL
752 || type
->target_type ()->code () == TYPE_CODE_CHAR
))
754 /* For enum-valued ranges, we want to recurse, because we'll end
755 up printing the constant's name rather than its numeric
756 value. Character and fixed-point types are also printed
757 differently, so recurse for those as well. */
758 struct type
*target_type
= type
->target_type ();
759 val
= value_cast (target_type
, val
);
760 common_val_print (val
, stream
, recurse
+ 1, options
,
761 language_def (language_ada
));
766 int format
= (options
->format
? options
->format
767 : options
->output_format
);
771 struct value_print_options opts
= *options
;
773 opts
.format
= format
;
774 value_print_scalar_formatted (val
, &opts
, 0, stream
);
776 else if (ada_is_system_address_type (type
))
778 /* FIXME: We want to print System.Address variables using
779 the same format as for any access type. But for some
780 reason GNAT encodes the System.Address type as an int,
781 so we have to work-around this deficiency by handling
782 System.Address values as a special case. */
784 struct gdbarch
*gdbarch
= type
->arch ();
785 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
786 CORE_ADDR addr
= extract_typed_address (valaddr
, ptr_type
);
788 gdb_printf (stream
, "(");
789 type_print (type
, "", stream
, -1);
790 gdb_printf (stream
, ") ");
791 gdb_puts (paddress (gdbarch
, addr
), stream
);
795 value_print_scalar_formatted (val
, options
, 0, stream
);
796 if (ada_is_character_type (type
))
800 gdb_puts (" ", stream
);
801 c
= unpack_long (type
, valaddr
);
802 ada_printchar (c
, type
, stream
);
809 /* Implement Ada val_print'ing for the case where TYPE is
813 ada_val_print_enum (struct value
*value
, struct ui_file
*stream
, int recurse
,
814 const struct value_print_options
*options
)
820 value_print_scalar_formatted (value
, options
, 0, stream
);
824 struct type
*type
= ada_check_typedef (value
->type ());
825 const gdb_byte
*valaddr
= value
->contents_for_printing ().data ();
826 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
828 val
= unpack_long (type
, valaddr
+ offset_aligned
);
829 std::optional
<LONGEST
> posn
= discrete_position (type
, val
);
830 if (posn
.has_value ())
832 const char *name
= ada_enum_name (type
->field (*posn
).name ());
835 gdb_printf (stream
, "%ld %ps", (long) val
,
836 styled_string (variable_name_style
.style (),
839 fputs_styled (name
, variable_name_style
.style (), stream
);
842 print_longest (stream
, 'd', 0, val
);
845 /* Implement Ada val_print'ing for the case where the type is
846 TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
849 ada_val_print_struct_union (struct value
*value
,
850 struct ui_file
*stream
,
852 const struct value_print_options
*options
)
854 gdb_printf (stream
, "(");
856 if (print_field_values (value
, value
, stream
, recurse
, options
,
857 0, language_def (language_ada
)) != 0
858 && options
->prettyformat
)
860 gdb_printf (stream
, "\n");
861 print_spaces (2 * recurse
, stream
);
864 gdb_printf (stream
, ")");
867 /* Implement Ada value_print'ing for the case where TYPE is a
871 ada_value_print_array (struct value
*val
, struct ui_file
*stream
, int recurse
,
872 const struct value_print_options
*options
)
874 struct type
*type
= ada_check_typedef (val
->type ());
876 /* For an array of characters, print with string syntax. */
877 if (ada_is_string_type (type
)
878 && (options
->format
== 0 || options
->format
== 's'))
880 const gdb_byte
*valaddr
= val
->contents_for_printing ().data ();
881 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
883 ada_val_print_string (type
, valaddr
, offset_aligned
, stream
, recurse
,
888 gdb_printf (stream
, "(");
889 print_optional_low_bound (stream
, type
, options
);
891 if (val
->entirely_optimized_out ())
892 val_print_optimized_out (val
, stream
);
893 else if (type
->field (0).bitsize () > 0)
895 const gdb_byte
*valaddr
= val
->contents_for_printing ().data ();
896 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
897 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
898 stream
, recurse
, options
);
901 value_print_array_elements (val
, stream
, recurse
, options
, 0);
902 gdb_printf (stream
, ")");
905 /* Implement Ada val_print'ing for the case where TYPE is
909 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
910 int offset
, int offset_aligned
, CORE_ADDR address
,
911 struct ui_file
*stream
, int recurse
,
912 struct value
*original_value
,
913 const struct value_print_options
*options
)
915 /* For references, the debugger is expected to print the value as
916 an address if DEREF_REF is null. But printing an address in place
917 of the object value would be confusing to an Ada programmer.
918 So, for Ada values, we print the actual dereferenced value
920 struct type
*elttype
= check_typedef (type
->target_type ());
921 struct value
*deref_val
;
922 CORE_ADDR deref_val_int
;
924 if (elttype
->code () == TYPE_CODE_UNDEF
)
926 fputs_styled ("<ref to undefined type>", metadata_style
.style (),
931 deref_val
= coerce_ref_if_computed (original_value
);
934 if (ada_is_tagged_type (deref_val
->type (), 1))
935 deref_val
= ada_tag_value_at_base_address (deref_val
);
937 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
938 language_def (language_ada
));
942 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
943 if (deref_val_int
== 0)
945 gdb_puts ("(null)", stream
);
950 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
952 if (ada_is_tagged_type (deref_val
->type (), 1))
953 deref_val
= ada_tag_value_at_base_address (deref_val
);
955 if (deref_val
->lazy ())
956 deref_val
->fetch_lazy ();
958 common_val_print (deref_val
, stream
, recurse
+ 1,
959 options
, language_def (language_ada
));
962 /* See the comment on ada_value_print. This function differs in that
963 it does not catch evaluation errors (leaving that to its
967 ada_value_print_inner (struct value
*val
, struct ui_file
*stream
, int recurse
,
968 const struct value_print_options
*options
)
970 struct type
*type
= ada_check_typedef (val
->type ());
972 if (ada_is_array_descriptor_type (type
)
973 || (ada_is_constrained_packed_array_type (type
)
974 && type
->code () != TYPE_CODE_PTR
))
976 /* If this is a reference, coerce it now. This helps taking
977 care of the case where ADDRESS is meaningless because
978 original_value was not an lval. */
979 val
= coerce_ref (val
);
980 val
= ada_get_decoded_value (val
);
983 gdb_assert (type
->code () == TYPE_CODE_TYPEDEF
);
984 gdb_printf (stream
, "0x0");
989 val
= ada_to_fixed_value (val
);
992 struct type
*saved_type
= type
;
994 const gdb_byte
*valaddr
= val
->contents_for_printing ().data ();
995 CORE_ADDR address
= val
->address ();
996 gdb::array_view
<const gdb_byte
> view
997 = gdb::make_array_view (valaddr
, type
->length ());
998 type
= ada_check_typedef (resolve_dynamic_type (type
, view
, address
));
999 if (type
!= saved_type
)
1002 val
->deprecated_set_type (type
);
1005 if (is_fixed_point_type (type
))
1006 type
= type
->fixed_point_type_base_type ();
1008 switch (type
->code ())
1011 common_val_print (val
, stream
, recurse
, options
,
1012 language_def (language_c
));
1016 ada_value_print_ptr (val
, stream
, recurse
, options
);
1020 case TYPE_CODE_RANGE
:
1021 ada_value_print_num (val
, stream
, recurse
, options
);
1024 case TYPE_CODE_ENUM
:
1025 ada_val_print_enum (val
, stream
, recurse
, options
);
1029 if (options
->format
)
1031 common_val_print (val
, stream
, recurse
, options
,
1032 language_def (language_c
));
1036 ada_print_floating (valaddr
, type
, stream
);
1039 case TYPE_CODE_UNION
:
1040 case TYPE_CODE_STRUCT
:
1041 ada_val_print_struct_union (val
, stream
, recurse
, options
);
1044 case TYPE_CODE_ARRAY
:
1045 ada_value_print_array (val
, stream
, recurse
, options
);
1049 ada_val_print_ref (type
, valaddr
, 0, 0,
1050 address
, stream
, recurse
, val
,
1057 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1058 const struct value_print_options
*options
)
1060 struct value
*val
= ada_to_fixed_value (val0
);
1061 struct type
*type
= ada_check_typedef (val
->type ());
1062 struct value_print_options opts
;
1064 /* If it is a pointer, indicate what it points to; but not for
1065 "void *" pointers. */
1066 if (type
->code () == TYPE_CODE_PTR
1067 && !(type
->target_type ()->code () == TYPE_CODE_INT
1068 && type
->target_type ()->length () == 0))
1070 /* Hack: don't print (char *) for char strings. Their
1071 type is indicated by the quoted string anyway. */
1072 if (type
->target_type ()->length () != sizeof (char)
1073 || type
->target_type ()->code () != TYPE_CODE_INT
1074 || type
->target_type ()->is_unsigned ())
1076 gdb_printf (stream
, "(");
1077 type_print (type
, "", stream
, -1);
1078 gdb_printf (stream
, ") ");
1081 else if (ada_is_array_descriptor_type (type
))
1083 /* We do not print the type description unless TYPE is an array
1084 access type (this is encoded by the compiler as a typedef to
1085 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1086 if (type
->code () == TYPE_CODE_TYPEDEF
)
1088 gdb_printf (stream
, "(");
1089 type_print (type
, "", stream
, -1);
1090 gdb_printf (stream
, ") ");
1095 opts
.deref_ref
= true;
1096 common_val_print (val
, stream
, 0, &opts
, current_language
);