1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2020 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 type
*, const gdb_byte
*,
35 struct ui_file
*, int,
37 const struct value_print_options
*,
38 int, struct type
*, int,
39 const struct language_defn
*);
42 /* Make TYPE unsigned if its range of values includes no negatives. */
44 adjust_type_signedness (struct type
*type
)
46 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
47 && TYPE_LOW_BOUND (type
) >= 0)
48 TYPE_UNSIGNED (type
) = 1;
51 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
52 if non-standard (i.e., other than 1 for numbers, other than lower bound
53 of index type for enumerated type). Returns 1 if something printed,
57 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
58 const struct value_print_options
*options
)
60 struct type
*index_type
;
64 if (options
->print_array_indexes
)
67 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
70 /* If this is an empty array, then don't print the lower bound.
71 That would be confusing, because we would print the lower bound,
72 followed by... nothing! */
73 if (low_bound
> high_bound
)
76 index_type
= TYPE_INDEX_TYPE (type
);
78 while (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
80 /* We need to know what the base type is, in order to do the
81 appropriate check below. Otherwise, if this is a subrange
82 of an enumerated type, where the underlying value of the
83 first element is typically 0, we might test the low bound
84 against the wrong value. */
85 index_type
= TYPE_TARGET_TYPE (index_type
);
88 /* Don't print the lower bound if it's the default one. */
89 switch (TYPE_CODE (index_type
))
97 if (low_bound
== TYPE_FIELD_ENUMVAL (index_type
, 0))
100 case TYPE_CODE_UNDEF
:
109 ada_print_scalar (index_type
, low_bound
, stream
);
110 fprintf_filtered (stream
, " => ");
114 /* Version of val_print_array_elements for GNAT-style packed arrays.
115 Prints elements of packed array of type TYPE at bit offset
116 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
117 separates with commas. RECURSE is the recursion (nesting) level.
118 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
121 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
123 int bitoffset
, struct ui_file
*stream
,
126 const struct value_print_options
*options
)
129 unsigned int things_printed
= 0;
131 struct type
*elttype
, *index_type
;
132 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
133 struct value
*mark
= value_mark ();
136 elttype
= TYPE_TARGET_TYPE (type
);
137 index_type
= TYPE_INDEX_TYPE (type
);
141 struct type
*base_index_type
;
143 if (get_discrete_bounds (index_type
, &low
, &high
) < 0)
146 len
= high
- low
+ 1;
148 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
149 base_index_type
= TYPE_TARGET_TYPE (index_type
);
151 base_index_type
= index_type
;
153 if (TYPE_CODE (base_index_type
) == TYPE_CODE_ENUM
)
155 LONGEST low_pos
, high_pos
;
157 /* Non-contiguous enumerations types can by used as index types
158 so the array length is computed from the positions of the
159 first and last literal in the enumeration type, and not from
160 the values of these literals. */
162 if (!discrete_position (base_index_type
, low
, &low_pos
)
163 || !discrete_position (base_index_type
, high
, &high_pos
))
165 warning (_("unable to get positions in array, use bounds instead"));
170 /* The array length should normally be HIGH_POS - LOW_POS + 1.
171 But in Ada we allow LOW_POS to be greater than HIGH_POS for
172 empty arrays. In that situation, the array length is just zero,
175 if (low_pos
> high_pos
)
178 len
= high_pos
- low_pos
+ 1;
183 annotate_array_section_begin (i
, elttype
);
185 while (i
< len
&& things_printed
< options
->print_max
)
187 struct value
*v0
, *v1
;
192 if (options
->prettyformat_arrays
)
194 fprintf_filtered (stream
, ",\n");
195 print_spaces_filtered (2 + 2 * recurse
, stream
);
199 fprintf_filtered (stream
, ", ");
202 wrap_here (n_spaces (2 + 2 * recurse
));
203 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
206 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
207 (i0
* bitsize
) / HOST_CHAR_BIT
,
208 (i0
* bitsize
) % HOST_CHAR_BIT
,
215 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
216 (i
* bitsize
) / HOST_CHAR_BIT
,
217 (i
* bitsize
) % HOST_CHAR_BIT
,
219 if (TYPE_LENGTH (check_typedef (value_type (v0
)))
220 != TYPE_LENGTH (check_typedef (value_type (v1
))))
222 if (!value_contents_eq (v0
, value_embedded_offset (v0
),
223 v1
, value_embedded_offset (v1
),
224 TYPE_LENGTH (check_typedef (value_type (v0
)))))
228 if (i
- i0
> options
->repeat_count_threshold
)
230 struct value_print_options opts
= *options
;
234 value_embedded_offset (v0
), 0, stream
,
235 recurse
+ 1, v0
, &opts
, current_language
);
236 annotate_elt_rep (i
- i0
);
237 fprintf_filtered (stream
, _(" %p[<repeats %u times>%p]"),
238 metadata_style
.style ().ptr (), i
- i0
, nullptr);
239 annotate_elt_rep_end ();
245 struct value_print_options opts
= *options
;
248 for (j
= i0
; j
< i
; j
+= 1)
252 if (options
->prettyformat_arrays
)
254 fprintf_filtered (stream
, ",\n");
255 print_spaces_filtered (2 + 2 * recurse
, stream
);
259 fprintf_filtered (stream
, ", ");
261 wrap_here (n_spaces (2 + 2 * recurse
));
262 maybe_print_array_index (index_type
, j
+ low
,
266 value_embedded_offset (v0
), 0, stream
,
267 recurse
+ 1, v0
, &opts
, current_language
);
271 things_printed
+= i
- i0
;
273 annotate_array_section_end ();
276 fprintf_filtered (stream
, "...");
279 value_free_to_mark (mark
);
283 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
285 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
288 /* Print the character C on STREAM as part of the contents of a literal
289 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
293 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
294 int quoter
, int type_len
)
296 /* If this character fits in the normal ASCII range, and is
297 a printable character, then print the character as if it was
298 an ASCII character, even if this is a wide character.
299 The UCHAR_MAX check is necessary because the isascii function
300 requires that its argument have a value of an unsigned char,
301 or EOF (EOF is obviously not printable). */
302 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
304 if (c
== quoter
&& c
== '"')
305 fprintf_filtered (stream
, "\"\"");
307 fprintf_filtered (stream
, "%c", c
);
310 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
313 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
317 char_at (const gdb_byte
*string
, int i
, int type_len
,
318 enum bfd_endian byte_order
)
323 return (int) extract_unsigned_integer (string
+ type_len
* i
,
324 type_len
, byte_order
);
327 /* Print a floating-point value of type TYPE, pointed to in GDB by
328 VALADDR, on STREAM. Use Ada formatting conventions: there must be
329 a decimal point, and at least one digit before and after the
330 point. We use the GNAT format for NaNs and infinities. */
333 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
334 struct ui_file
*stream
)
336 string_file tmp_stream
;
338 print_floating (valaddr
, type
, &tmp_stream
);
340 std::string
&s
= tmp_stream
.string ();
341 size_t skip_count
= 0;
343 /* Modify for Ada rules. */
345 size_t pos
= s
.find ("inf");
346 if (pos
== std::string::npos
)
347 pos
= s
.find ("Inf");
348 if (pos
== std::string::npos
)
349 pos
= s
.find ("INF");
350 if (pos
!= std::string::npos
)
351 s
.replace (pos
, 3, "Inf");
353 if (pos
== std::string::npos
)
355 pos
= s
.find ("nan");
356 if (pos
== std::string::npos
)
357 pos
= s
.find ("NaN");
358 if (pos
== std::string::npos
)
359 pos
= s
.find ("Nan");
360 if (pos
!= std::string::npos
)
362 s
[pos
] = s
[pos
+ 2] = 'N';
368 if (pos
== std::string::npos
369 && s
.find ('.') == std::string::npos
)
372 if (pos
== std::string::npos
)
373 fprintf_filtered (stream
, "%s.0", s
.c_str ());
375 fprintf_filtered (stream
, "%.*s.0%s", (int) pos
, s
.c_str (), &s
[pos
]);
378 fprintf_filtered (stream
, "%s", &s
[skip_count
]);
382 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
384 fputs_filtered ("'", stream
);
385 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
386 fputs_filtered ("'", stream
);
389 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
390 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
391 like a default signed integer. */
394 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
401 print_longest (stream
, 'd', 0, val
);
405 type
= ada_check_typedef (type
);
407 switch (TYPE_CODE (type
))
411 len
= TYPE_NFIELDS (type
);
412 for (i
= 0; i
< len
; i
++)
414 if (TYPE_FIELD_ENUMVAL (type
, i
) == val
)
421 fputs_styled (ada_enum_name (TYPE_FIELD_NAME (type
, i
)),
422 variable_name_style
.style (), stream
);
426 print_longest (stream
, 'd', 0, val
);
431 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
435 LA_PRINT_CHAR (val
, type
, stream
);
439 fprintf_filtered (stream
, val
? "true" : "false");
442 case TYPE_CODE_RANGE
:
443 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
446 case TYPE_CODE_UNDEF
:
448 case TYPE_CODE_ARRAY
:
449 case TYPE_CODE_STRUCT
:
450 case TYPE_CODE_UNION
:
455 case TYPE_CODE_STRING
:
456 case TYPE_CODE_ERROR
:
457 case TYPE_CODE_MEMBERPTR
:
458 case TYPE_CODE_METHODPTR
:
459 case TYPE_CODE_METHOD
:
461 warning (_("internal error: unhandled type in ada_print_scalar"));
465 error (_("Invalid type code in symbol table."));
469 /* Print the character string STRING, printing at most LENGTH characters.
470 Printing stops early if the number hits print_max; repeat counts
471 are printed as appropriate. Print ellipses at the end if we
472 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
473 TYPE_LEN is the length (1 or 2) of the character type. */
476 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
477 unsigned int length
, int force_ellipses
, int type_len
,
478 const struct value_print_options
*options
)
480 enum bfd_endian byte_order
= type_byte_order (elttype
);
482 unsigned int things_printed
= 0;
488 fputs_filtered ("\"\"", stream
);
492 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
494 /* Position of the character we are examining
495 to see whether it is repeated. */
497 /* Number of repetitions we have detected so far. */
504 fputs_filtered (", ", stream
);
511 && char_at (string
, rep1
, type_len
, byte_order
)
512 == char_at (string
, i
, type_len
, byte_order
))
518 if (reps
> options
->repeat_count_threshold
)
522 fputs_filtered ("\", ", stream
);
525 fputs_filtered ("'", stream
);
526 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
527 elttype
, stream
, '\'', type_len
);
528 fputs_filtered ("'", stream
);
529 fprintf_filtered (stream
, _(" %p[<repeats %u times>%p]"),
530 metadata_style
.style ().ptr (), reps
, nullptr);
532 things_printed
+= options
->repeat_count_threshold
;
539 fputs_filtered ("\"", stream
);
542 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
543 elttype
, stream
, '"', type_len
);
548 /* Terminate the quotes if necessary. */
550 fputs_filtered ("\"", stream
);
552 if (force_ellipses
|| i
< length
)
553 fputs_filtered ("...", stream
);
557 ada_printstr (struct ui_file
*stream
, struct type
*type
,
558 const gdb_byte
*string
, unsigned int length
,
559 const char *encoding
, int force_ellipses
,
560 const struct value_print_options
*options
)
562 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
567 print_variant_part (struct type
*type
, int field_num
,
568 const gdb_byte
*valaddr
, int offset
,
569 struct ui_file
*stream
, int recurse
,
571 const struct value_print_options
*options
,
573 struct type
*outer_type
, int outer_offset
,
574 const struct language_defn
*language
)
576 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
577 int which
= ada_which_variant_applies (var_type
, outer_type
,
578 valaddr
+ outer_offset
);
583 return print_field_values
584 (TYPE_FIELD_TYPE (var_type
, which
),
586 offset
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
587 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
588 stream
, recurse
, val
, options
,
589 comma_needed
, outer_type
, outer_offset
, language
);
592 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
594 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
595 meanings as in ada_print_value and ada_val_print.
597 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
598 record (used to get discriminant values when printing variant
601 COMMA_NEEDED is 1 if fields have been printed at the current recursion
602 level, so that a comma is needed before any field printed by this
605 Returns 1 if COMMA_NEEDED or any fields were printed. */
608 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
609 int offset
, struct ui_file
*stream
, int recurse
,
611 const struct value_print_options
*options
,
613 struct type
*outer_type
, int outer_offset
,
614 const struct language_defn
*language
)
618 len
= TYPE_NFIELDS (type
);
620 for (i
= 0; i
< len
; i
+= 1)
622 if (ada_is_ignored_field (type
, i
))
625 if (ada_is_wrapper_field (type
, i
))
628 print_field_values (TYPE_FIELD_TYPE (type
, i
),
631 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
632 stream
, recurse
, val
, options
,
633 comma_needed
, type
, offset
, language
);
636 else if (ada_is_variant_part (type
, i
))
639 print_variant_part (type
, i
, valaddr
,
640 offset
, stream
, recurse
, val
,
641 options
, comma_needed
,
642 outer_type
, outer_offset
, language
);
647 fprintf_filtered (stream
, ", ");
650 if (options
->prettyformat
)
652 fprintf_filtered (stream
, "\n");
653 print_spaces_filtered (2 + 2 * recurse
, stream
);
657 wrap_here (n_spaces (2 + 2 * recurse
));
660 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
661 fprintf_filtered (stream
, "%.*s",
662 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
663 TYPE_FIELD_NAME (type
, i
));
664 annotate_field_name_end ();
665 fputs_filtered (" => ", stream
);
666 annotate_field_value ();
668 if (TYPE_FIELD_PACKED (type
, i
))
670 /* Bitfields require special handling, especially due to byte
672 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
674 fputs_styled (_("<optimized out or zero length>"),
675 metadata_style
.style (), stream
);
680 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
681 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
682 struct value_print_options opts
;
684 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
685 v
= ada_value_primitive_packed_val
687 offset
+ bit_pos
/ HOST_CHAR_BIT
,
688 bit_pos
% HOST_CHAR_BIT
,
689 bit_size
, TYPE_FIELD_TYPE (type
, i
));
692 val_print (TYPE_FIELD_TYPE (type
, i
),
693 value_embedded_offset (v
), 0,
694 stream
, recurse
+ 1, v
,
700 struct value_print_options opts
= *options
;
703 val_print (TYPE_FIELD_TYPE (type
, i
),
704 (offset
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
705 0, stream
, recurse
+ 1, val
, &opts
, language
);
707 annotate_field_end ();
713 /* Implement Ada val_print'ing for the case where TYPE is
714 a TYPE_CODE_ARRAY of characters. */
717 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
718 int offset
, int offset_aligned
, CORE_ADDR address
,
719 struct ui_file
*stream
, int recurse
,
720 struct value
*original_value
,
721 const struct value_print_options
*options
)
723 enum bfd_endian byte_order
= type_byte_order (type
);
724 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
728 /* We know that ELTTYPE cannot possibly be null, because we assume
729 that we're called only when TYPE is a string-like type.
730 Similarly, the size of ELTTYPE should also be non-null, since
731 it's a character-like type. */
732 gdb_assert (elttype
!= NULL
);
733 gdb_assert (TYPE_LENGTH (elttype
) != 0);
735 eltlen
= TYPE_LENGTH (elttype
);
736 len
= TYPE_LENGTH (type
) / eltlen
;
738 if (options
->prettyformat_arrays
)
739 print_spaces_filtered (2 + 2 * recurse
, stream
);
741 /* If requested, look for the first null char and only print
742 elements up to it. */
743 if (options
->stop_print_at_null
)
747 /* Look for a NULL char. */
750 && temp_len
< options
->print_max
751 && char_at (valaddr
+ offset_aligned
,
752 temp_len
, eltlen
, byte_order
) != 0);
757 printstr (stream
, elttype
, valaddr
+ offset_aligned
, len
, 0,
761 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
762 thin pointers, etc). */
765 ada_val_print_gnat_array (struct value
*val
,
766 struct ui_file
*stream
, int recurse
,
767 const struct value_print_options
*options
)
769 scoped_value_mark free_values
;
771 struct type
*type
= ada_check_typedef (value_type (val
));
773 /* If this is a reference, coerce it now. This helps taking care
774 of the case where ADDRESS is meaningless because original_value
776 val
= coerce_ref (val
);
777 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
778 val
= ada_coerce_to_simple_array_ptr (val
);
780 val
= ada_coerce_to_simple_array (val
);
783 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
784 fprintf_filtered (stream
, "0x0");
787 common_val_print (val
, stream
, recurse
, options
,
788 language_def (language_ada
));
791 /* Implement Ada val_print'ing for the case where TYPE is
795 ada_val_print_ptr (struct type
*type
, const gdb_byte
*valaddr
,
796 int offset
, int offset_aligned
, CORE_ADDR address
,
797 struct ui_file
*stream
, int recurse
,
798 struct value
*original_value
,
799 const struct value_print_options
*options
)
801 val_print (type
, offset
, address
, stream
, recurse
,
802 original_value
, options
, language_def (language_c
));
804 if (ada_is_tag_type (type
))
807 value_from_contents_and_address (type
,
808 valaddr
+ offset_aligned
,
809 address
+ offset_aligned
);
810 const char *name
= ada_tag_name (val
);
813 fprintf_filtered (stream
, " (%s)", name
);
817 /* Implement Ada val_print'ing for the case where TYPE is
818 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
821 ada_val_print_num (struct type
*type
, const gdb_byte
*valaddr
,
822 int offset
, int offset_aligned
, CORE_ADDR address
,
823 struct ui_file
*stream
, int recurse
,
824 struct value
*original_value
,
825 const struct value_print_options
*options
)
827 if (ada_is_fixed_point_type (type
))
829 struct value
*scale
= ada_scaling_factor (type
);
830 struct value
*v
= value_from_contents (type
, valaddr
+ offset_aligned
);
831 v
= value_cast (value_type (scale
), v
);
832 v
= value_binop (v
, scale
, BINOP_MUL
);
834 const char *fmt
= TYPE_LENGTH (type
) < 4 ? "%.11g" : "%.17g";
836 = target_float_to_string (value_contents (v
), value_type (v
), fmt
);
837 fputs_filtered (str
.c_str (), stream
);
840 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
841 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ENUM
842 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_BOOL
843 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CHAR
))
845 /* For enum-valued ranges, we want to recurse, because we'll end
846 up printing the constant's name rather than its numeric
847 value. Character and fixed-point types are also printed
848 differently, so recuse for those as well. */
849 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
851 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
853 /* Obscure case of range type that has different length from
854 its base type. Perform a conversion, or we will get a
855 nonsense value. Actually, we could use the same
856 code regardless of lengths; I'm just avoiding a cast. */
858 = value_from_contents_and_address (type
, valaddr
+ offset
, 0);
859 struct value
*v
= value_cast (target_type
, v1
);
861 val_print (target_type
,
862 value_embedded_offset (v
), 0, stream
,
863 recurse
+ 1, v
, options
,
864 language_def (language_ada
));
867 val_print (TYPE_TARGET_TYPE (type
), offset
,
868 address
, stream
, recurse
, original_value
,
869 options
, language_def (language_ada
));
874 int format
= (options
->format
? options
->format
875 : options
->output_format
);
879 struct value_print_options opts
= *options
;
881 opts
.format
= format
;
882 val_print_scalar_formatted (type
, offset_aligned
,
883 original_value
, &opts
, 0, stream
);
885 else if (ada_is_system_address_type (type
))
887 /* FIXME: We want to print System.Address variables using
888 the same format as for any access type. But for some
889 reason GNAT encodes the System.Address type as an int,
890 so we have to work-around this deficiency by handling
891 System.Address values as a special case. */
893 struct gdbarch
*gdbarch
= get_type_arch (type
);
894 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
895 CORE_ADDR addr
= extract_typed_address (valaddr
+ offset_aligned
,
898 fprintf_filtered (stream
, "(");
899 type_print (type
, "", stream
, -1);
900 fprintf_filtered (stream
, ") ");
901 fputs_filtered (paddress (gdbarch
, addr
), stream
);
905 val_print_scalar_formatted (type
, offset_aligned
,
906 original_value
, options
, 0, stream
);
907 if (ada_is_character_type (type
))
911 fputs_filtered (" ", stream
);
912 c
= unpack_long (type
, valaddr
+ offset_aligned
);
913 ada_printchar (c
, type
, stream
);
920 /* Implement Ada val_print'ing for the case where TYPE is
924 ada_val_print_enum (struct type
*type
, const gdb_byte
*valaddr
,
925 int offset
, int offset_aligned
, CORE_ADDR address
,
926 struct ui_file
*stream
, int recurse
,
927 struct value
*original_value
,
928 const struct value_print_options
*options
)
936 val_print_scalar_formatted (type
, offset_aligned
,
937 original_value
, options
, 0, stream
);
941 len
= TYPE_NFIELDS (type
);
942 val
= unpack_long (type
, valaddr
+ offset_aligned
);
943 for (i
= 0; i
< len
; i
++)
946 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
952 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
955 fprintf_filtered (stream
, "%ld %ps", (long) val
,
956 styled_string (variable_name_style
.style (),
959 fputs_styled (name
, variable_name_style
.style (), stream
);
962 print_longest (stream
, 'd', 0, val
);
965 /* Implement Ada val_print'ing for the case where TYPE is
969 ada_val_print_flt (struct type
*type
, const gdb_byte
*valaddr
,
970 int offset
, int offset_aligned
, CORE_ADDR address
,
971 struct ui_file
*stream
, int recurse
,
972 struct value
*original_value
,
973 const struct value_print_options
*options
)
977 val_print (type
, offset
, address
, stream
, recurse
,
978 original_value
, options
, language_def (language_c
));
982 ada_print_floating (valaddr
+ offset
, type
, stream
);
985 /* Implement Ada val_print'ing for the case where TYPE is
986 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
989 ada_val_print_struct_union
990 (struct type
*type
, const gdb_byte
*valaddr
, int offset
,
991 int offset_aligned
, CORE_ADDR address
, struct ui_file
*stream
,
992 int recurse
, struct value
*original_value
,
993 const struct value_print_options
*options
)
995 if (ada_is_bogus_array_descriptor (type
))
997 fprintf_filtered (stream
, "(...?)");
1001 fprintf_filtered (stream
, "(");
1003 if (print_field_values (type
, valaddr
, offset_aligned
,
1004 stream
, recurse
, original_value
, options
,
1005 0, type
, offset_aligned
,
1006 language_def (language_ada
)) != 0
1007 && options
->prettyformat
)
1009 fprintf_filtered (stream
, "\n");
1010 print_spaces_filtered (2 * recurse
, stream
);
1013 fprintf_filtered (stream
, ")");
1016 /* Implement Ada val_print'ing for the case where TYPE is
1017 a TYPE_CODE_ARRAY. */
1020 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
1021 int offset
, int offset_aligned
, CORE_ADDR address
,
1022 struct ui_file
*stream
, int recurse
,
1023 struct value
*original_value
,
1024 const struct value_print_options
*options
)
1026 /* For an array of characters, print with string syntax. */
1027 if (ada_is_string_type (type
)
1028 && (options
->format
== 0 || options
->format
== 's'))
1030 ada_val_print_string (type
, valaddr
, offset
, offset_aligned
,
1031 address
, stream
, recurse
, original_value
,
1036 fprintf_filtered (stream
, "(");
1037 print_optional_low_bound (stream
, type
, options
);
1038 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1039 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
1041 original_value
, options
);
1043 val_print_array_elements (type
, offset_aligned
, address
,
1044 stream
, recurse
, original_value
,
1046 fprintf_filtered (stream
, ")");
1049 /* Implement Ada val_print'ing for the case where TYPE is
1053 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
1054 int offset
, int offset_aligned
, CORE_ADDR address
,
1055 struct ui_file
*stream
, int recurse
,
1056 struct value
*original_value
,
1057 const struct value_print_options
*options
)
1059 /* For references, the debugger is expected to print the value as
1060 an address if DEREF_REF is null. But printing an address in place
1061 of the object value would be confusing to an Ada programmer.
1062 So, for Ada values, we print the actual dereferenced value
1064 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
1065 struct value
*deref_val
;
1066 CORE_ADDR deref_val_int
;
1068 if (TYPE_CODE (elttype
) == TYPE_CODE_UNDEF
)
1070 fputs_styled ("<ref to undefined type>", metadata_style
.style (),
1075 deref_val
= coerce_ref_if_computed (original_value
);
1078 if (ada_is_tagged_type (value_type (deref_val
), 1))
1079 deref_val
= ada_tag_value_at_base_address (deref_val
);
1081 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
1082 language_def (language_ada
));
1086 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
1087 if (deref_val_int
== 0)
1089 fputs_filtered ("(null)", stream
);
1094 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
1096 if (ada_is_tagged_type (value_type (deref_val
), 1))
1097 deref_val
= ada_tag_value_at_base_address (deref_val
);
1099 /* Make sure that the object does not have an unreasonable size
1100 before trying to print it. This can happen for instance with
1101 references to dynamic objects whose contents is uninitialized
1102 (Eg: an array whose bounds are not set yet). */
1103 ada_ensure_varsize_limit (value_type (deref_val
));
1105 if (value_lazy (deref_val
))
1106 value_fetch_lazy (deref_val
);
1108 val_print (value_type (deref_val
),
1109 value_embedded_offset (deref_val
),
1110 value_address (deref_val
), stream
, recurse
+ 1,
1111 deref_val
, options
, language_def (language_ada
));
1114 /* See the comment on ada_val_print. This function differs in that it
1115 does not catch evaluation errors (leaving that to ada_val_print). */
1118 ada_val_print_1 (struct type
*type
,
1119 int offset
, CORE_ADDR address
,
1120 struct ui_file
*stream
, int recurse
,
1121 struct value
*original_value
,
1122 const struct value_print_options
*options
)
1125 const gdb_byte
*valaddr
= value_contents_for_printing (original_value
);
1127 type
= ada_check_typedef (type
);
1129 if (ada_is_array_descriptor_type (type
)
1130 || (ada_is_constrained_packed_array_type (type
)
1131 && TYPE_CODE (type
) != TYPE_CODE_PTR
))
1133 struct value
*val
= value_from_contents_and_address (type
,
1136 ada_val_print_gnat_array (val
, stream
, recurse
, options
);
1140 offset_aligned
= offset
+ ada_aligned_value_addr (type
, valaddr
) - valaddr
;
1141 type
= printable_val_type (type
, valaddr
+ offset_aligned
);
1142 type
= resolve_dynamic_type (type
, valaddr
+ offset_aligned
,
1143 address
+ offset_aligned
);
1145 switch (TYPE_CODE (type
))
1148 val_print (type
, offset
, address
, stream
, recurse
,
1149 original_value
, options
, language_def (language_c
));
1153 ada_val_print_ptr (type
, valaddr
, offset
, offset_aligned
,
1154 address
, stream
, recurse
, original_value
,
1159 case TYPE_CODE_RANGE
:
1160 ada_val_print_num (type
, valaddr
, offset
, offset_aligned
,
1161 address
, stream
, recurse
, original_value
,
1165 case TYPE_CODE_ENUM
:
1166 ada_val_print_enum (type
, valaddr
, offset
, offset_aligned
,
1167 address
, stream
, recurse
, original_value
,
1172 ada_val_print_flt (type
, valaddr
, offset
, offset_aligned
,
1173 address
, stream
, recurse
, original_value
,
1177 case TYPE_CODE_UNION
:
1178 case TYPE_CODE_STRUCT
:
1179 ada_val_print_struct_union (type
, valaddr
, offset
, offset_aligned
,
1180 address
, stream
, recurse
,
1181 original_value
, options
);
1184 case TYPE_CODE_ARRAY
:
1185 ada_val_print_array (type
, valaddr
, offset
, offset_aligned
,
1186 address
, stream
, recurse
, original_value
,
1191 ada_val_print_ref (type
, valaddr
, offset
, offset_aligned
,
1192 address
, stream
, recurse
, original_value
,
1198 /* See val_print for a description of the various parameters of this
1199 function; they are identical. */
1202 ada_val_print (struct type
*type
,
1203 int embedded_offset
, CORE_ADDR address
,
1204 struct ui_file
*stream
, int recurse
,
1206 const struct value_print_options
*options
)
1210 ada_val_print_1 (type
, embedded_offset
, address
,
1211 stream
, recurse
, val
, options
);
1213 catch (const gdb_exception_error
&except
)
1215 fprintf_styled (stream
, metadata_style
.style (),
1216 _("<error reading variable: %s>"),
1221 /* See the comment on ada_value_print. This function differs in that
1222 it does not catch evaluation errors (leaving that to
1223 ada_value_print). */
1226 ada_value_print_1 (struct value
*val
, struct ui_file
*stream
, int recurse
,
1227 const struct value_print_options
*options
)
1229 struct type
*type
= ada_check_typedef (value_type (val
));
1231 if (ada_is_array_descriptor_type (type
)
1232 || (ada_is_constrained_packed_array_type (type
)
1233 && TYPE_CODE (type
) != TYPE_CODE_PTR
))
1235 ada_val_print_gnat_array (val
, stream
, recurse
, options
);
1239 val
= ada_to_fixed_value (val
);
1240 type
= value_type (val
);
1241 struct type
*saved_type
= type
;
1243 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
1244 CORE_ADDR address
= value_address (val
);
1245 type
= ada_check_typedef (resolve_dynamic_type (type
, valaddr
, address
));
1246 if (type
!= saved_type
)
1248 val
= value_copy (val
);
1249 deprecated_set_value_type (val
, type
);
1252 switch (TYPE_CODE (type
))
1255 common_val_print (val
, stream
, recurse
, options
,
1256 language_def (language_c
));
1260 ada_val_print_ptr (type
, valaddr
, 0, 0,
1261 address
, stream
, recurse
, val
,
1266 case TYPE_CODE_RANGE
:
1267 ada_val_print_num (type
, valaddr
, 0, 0,
1268 address
, stream
, recurse
, val
,
1272 case TYPE_CODE_ENUM
:
1273 ada_val_print_enum (type
, valaddr
, 0, 0,
1274 address
, stream
, recurse
, val
,
1279 ada_val_print_flt (type
, valaddr
, 0, 0,
1280 address
, stream
, recurse
, val
,
1284 case TYPE_CODE_UNION
:
1285 case TYPE_CODE_STRUCT
:
1286 ada_val_print_struct_union (type
, valaddr
, 0, 0,
1287 address
, stream
, recurse
,
1291 case TYPE_CODE_ARRAY
:
1292 ada_val_print_array (type
, valaddr
, 0, 0,
1293 address
, stream
, recurse
, val
,
1298 ada_val_print_ref (type
, valaddr
, 0, 0,
1299 address
, stream
, recurse
, val
,
1305 /* See ada-lang.h. */
1308 ada_value_print_inner (struct value
*val
, struct ui_file
*stream
,
1310 const struct value_print_options
*options
)
1314 ada_value_print_1 (val
, stream
, recurse
, options
);
1316 catch (const gdb_exception_error
&except
)
1318 fprintf_styled (stream
, metadata_style
.style (),
1319 _("<error reading variable: %s>"),
1325 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1326 const struct value_print_options
*options
)
1328 struct value
*val
= ada_to_fixed_value (val0
);
1329 CORE_ADDR address
= value_address (val
);
1330 struct type
*type
= ada_check_typedef (value_type (val
));
1331 struct value_print_options opts
;
1333 /* If it is a pointer, indicate what it points to. */
1334 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1336 /* Hack: don't print (char *) for char strings. Their
1337 type is indicated by the quoted string anyway. */
1338 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
1339 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
1340 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
1342 fprintf_filtered (stream
, "(");
1343 type_print (type
, "", stream
, -1);
1344 fprintf_filtered (stream
, ") ");
1347 else if (ada_is_array_descriptor_type (type
))
1349 /* We do not print the type description unless TYPE is an array
1350 access type (this is encoded by the compiler as a typedef to
1351 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1352 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1354 fprintf_filtered (stream
, "(");
1355 type_print (type
, "", stream
, -1);
1356 fprintf_filtered (stream
, ") ");
1359 else if (ada_is_bogus_array_descriptor (type
))
1361 fprintf_filtered (stream
, "(");
1362 type_print (type
, "", stream
, -1);
1363 fprintf_filtered (stream
, ") (...?)");
1370 value_embedded_offset (val
), address
,
1371 stream
, 0, val
, &opts
, current_language
);