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 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
) == TYPE_CODE_RANGE
45 && TYPE_LOW_BOUND (type
) >= 0)
46 TYPE_UNSIGNED (type
) = 1;
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 (type
);
76 while (TYPE_CODE (index_type
) == 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 (TYPE_CODE (index_type
))
95 if (low_bound
== TYPE_FIELD_ENUMVAL (index_type
, 0))
107 ada_print_scalar (index_type
, low_bound
, stream
);
108 fprintf_filtered (stream
, " => ");
112 /* Version of val_print_array_elements for GNAT-style packed arrays.
113 Prints elements of packed array of type TYPE from VALADDR on
114 STREAM. Formats according to OPTIONS and separates with commas.
115 RECURSE is the recursion (nesting) level. TYPE must have been
116 decoded (as by ada_coerce_to_simple_array). */
119 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
120 int offset
, struct ui_file
*stream
,
122 const struct value_print_options
*options
)
125 unsigned int things_printed
= 0;
127 struct type
*elttype
, *index_type
;
128 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
129 struct value
*mark
= value_mark ();
132 elttype
= TYPE_TARGET_TYPE (type
);
133 index_type
= TYPE_INDEX_TYPE (type
);
137 struct type
*base_index_type
;
139 if (get_discrete_bounds (index_type
, &low
, &high
) < 0)
142 len
= high
- low
+ 1;
144 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
145 base_index_type
= TYPE_TARGET_TYPE (index_type
);
147 base_index_type
= index_type
;
149 if (TYPE_CODE (base_index_type
) == TYPE_CODE_ENUM
)
151 LONGEST low_pos
, high_pos
;
153 /* Non-contiguous enumerations types can by used as index types
154 so the array length is computed from the positions of the
155 first and last literal in the enumeration type, and not from
156 the values of these literals. */
158 if (!discrete_position (base_index_type
, low
, &low_pos
)
159 || !discrete_position (base_index_type
, high
, &high_pos
))
161 warning (_("unable to get positions in array, use bounds instead"));
166 /* The array length should normally be HIGH_POS - LOW_POS + 1.
167 But in Ada we allow LOW_POS to be greater than HIGH_POS for
168 empty arrays. In that situation, the array length is just zero,
171 if (low_pos
> high_pos
)
174 len
= high_pos
- low_pos
+ 1;
179 annotate_array_section_begin (i
, elttype
);
181 while (i
< len
&& things_printed
< options
->print_max
)
183 struct value
*v0
, *v1
;
188 if (options
->prettyformat_arrays
)
190 fprintf_filtered (stream
, ",\n");
191 print_spaces_filtered (2 + 2 * recurse
, stream
);
195 fprintf_filtered (stream
, ", ");
198 wrap_here (n_spaces (2 + 2 * recurse
));
199 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
202 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
203 (i0
* bitsize
) / HOST_CHAR_BIT
,
204 (i0
* bitsize
) % HOST_CHAR_BIT
,
211 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
212 (i
* bitsize
) / HOST_CHAR_BIT
,
213 (i
* bitsize
) % HOST_CHAR_BIT
,
215 if (TYPE_LENGTH (check_typedef (value_type (v0
)))
216 != TYPE_LENGTH (check_typedef (value_type (v1
))))
218 if (!value_contents_eq (v0
, value_embedded_offset (v0
),
219 v1
, value_embedded_offset (v1
),
220 TYPE_LENGTH (check_typedef (value_type (v0
)))))
224 if (i
- i0
> options
->repeat_count_threshold
)
226 struct value_print_options opts
= *options
;
229 common_val_print (v0
, stream
, recurse
+ 1, &opts
, current_language
);
230 annotate_elt_rep (i
- i0
);
231 fprintf_filtered (stream
, _(" %p[<repeats %u times>%p]"),
232 metadata_style
.style ().ptr (), i
- i0
, nullptr);
233 annotate_elt_rep_end ();
239 struct value_print_options opts
= *options
;
242 for (j
= i0
; j
< i
; j
+= 1)
246 if (options
->prettyformat_arrays
)
248 fprintf_filtered (stream
, ",\n");
249 print_spaces_filtered (2 + 2 * recurse
, stream
);
253 fprintf_filtered (stream
, ", ");
255 wrap_here (n_spaces (2 + 2 * recurse
));
256 maybe_print_array_index (index_type
, j
+ low
,
259 common_val_print (v0
, stream
, recurse
+ 1, &opts
,
264 things_printed
+= i
- i0
;
266 annotate_array_section_end ();
269 fprintf_filtered (stream
, "...");
272 value_free_to_mark (mark
);
275 /* Print the character C on STREAM as part of the contents of a literal
276 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
280 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
281 int quoter
, int type_len
)
283 /* If this character fits in the normal ASCII range, and is
284 a printable character, then print the character as if it was
285 an ASCII character, even if this is a wide character.
286 The UCHAR_MAX check is necessary because the isascii function
287 requires that its argument have a value of an unsigned char,
288 or EOF (EOF is obviously not printable). */
289 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
291 if (c
== quoter
&& c
== '"')
292 fprintf_filtered (stream
, "\"\"");
294 fprintf_filtered (stream
, "%c", c
);
297 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
300 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
304 char_at (const gdb_byte
*string
, int i
, int type_len
,
305 enum bfd_endian byte_order
)
310 return (int) extract_unsigned_integer (string
+ type_len
* i
,
311 type_len
, byte_order
);
314 /* Print a floating-point value of type TYPE, pointed to in GDB by
315 VALADDR, on STREAM. Use Ada formatting conventions: there must be
316 a decimal point, and at least one digit before and after the
317 point. We use the GNAT format for NaNs and infinities. */
320 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
321 struct ui_file
*stream
)
323 string_file tmp_stream
;
325 print_floating (valaddr
, type
, &tmp_stream
);
327 std::string
&s
= tmp_stream
.string ();
328 size_t skip_count
= 0;
330 /* Modify for Ada rules. */
332 size_t pos
= s
.find ("inf");
333 if (pos
== std::string::npos
)
334 pos
= s
.find ("Inf");
335 if (pos
== std::string::npos
)
336 pos
= s
.find ("INF");
337 if (pos
!= std::string::npos
)
338 s
.replace (pos
, 3, "Inf");
340 if (pos
== std::string::npos
)
342 pos
= s
.find ("nan");
343 if (pos
== std::string::npos
)
344 pos
= s
.find ("NaN");
345 if (pos
== std::string::npos
)
346 pos
= s
.find ("Nan");
347 if (pos
!= std::string::npos
)
349 s
[pos
] = s
[pos
+ 2] = 'N';
355 if (pos
== std::string::npos
356 && s
.find ('.') == std::string::npos
)
359 if (pos
== std::string::npos
)
360 fprintf_filtered (stream
, "%s.0", s
.c_str ());
362 fprintf_filtered (stream
, "%.*s.0%s", (int) pos
, s
.c_str (), &s
[pos
]);
365 fprintf_filtered (stream
, "%s", &s
[skip_count
]);
369 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
371 fputs_filtered ("'", stream
);
372 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
373 fputs_filtered ("'", stream
);
376 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
377 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
378 like a default signed integer. */
381 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
388 print_longest (stream
, 'd', 0, val
);
392 type
= ada_check_typedef (type
);
394 switch (TYPE_CODE (type
))
398 len
= TYPE_NFIELDS (type
);
399 for (i
= 0; i
< len
; i
++)
401 if (TYPE_FIELD_ENUMVAL (type
, i
) == val
)
408 fputs_styled (ada_enum_name (TYPE_FIELD_NAME (type
, i
)),
409 variable_name_style
.style (), stream
);
413 print_longest (stream
, 'd', 0, val
);
418 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
422 LA_PRINT_CHAR (val
, type
, stream
);
426 fprintf_filtered (stream
, val
? "true" : "false");
429 case TYPE_CODE_RANGE
:
430 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
433 case TYPE_CODE_UNDEF
:
435 case TYPE_CODE_ARRAY
:
436 case TYPE_CODE_STRUCT
:
437 case TYPE_CODE_UNION
:
442 case TYPE_CODE_STRING
:
443 case TYPE_CODE_ERROR
:
444 case TYPE_CODE_MEMBERPTR
:
445 case TYPE_CODE_METHODPTR
:
446 case TYPE_CODE_METHOD
:
448 warning (_("internal error: unhandled type in ada_print_scalar"));
452 error (_("Invalid type code in symbol table."));
456 /* Print the character string STRING, printing at most LENGTH characters.
457 Printing stops early if the number hits print_max; repeat counts
458 are printed as appropriate. Print ellipses at the end if we
459 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
460 TYPE_LEN is the length (1 or 2) of the character type. */
463 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
464 unsigned int length
, int force_ellipses
, int type_len
,
465 const struct value_print_options
*options
)
467 enum bfd_endian byte_order
= type_byte_order (elttype
);
469 unsigned int things_printed
= 0;
475 fputs_filtered ("\"\"", stream
);
479 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
481 /* Position of the character we are examining
482 to see whether it is repeated. */
484 /* Number of repetitions we have detected so far. */
491 fputs_filtered (", ", stream
);
498 && char_at (string
, rep1
, type_len
, byte_order
)
499 == char_at (string
, i
, type_len
, byte_order
))
505 if (reps
> options
->repeat_count_threshold
)
509 fputs_filtered ("\", ", stream
);
512 fputs_filtered ("'", stream
);
513 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
514 elttype
, stream
, '\'', type_len
);
515 fputs_filtered ("'", stream
);
516 fprintf_filtered (stream
, _(" %p[<repeats %u times>%p]"),
517 metadata_style
.style ().ptr (), reps
, nullptr);
519 things_printed
+= options
->repeat_count_threshold
;
526 fputs_filtered ("\"", stream
);
529 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
530 elttype
, stream
, '"', type_len
);
535 /* Terminate the quotes if necessary. */
537 fputs_filtered ("\"", stream
);
539 if (force_ellipses
|| i
< length
)
540 fputs_filtered ("...", stream
);
544 ada_printstr (struct ui_file
*stream
, struct type
*type
,
545 const gdb_byte
*string
, unsigned int length
,
546 const char *encoding
, int force_ellipses
,
547 const struct value_print_options
*options
)
549 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
554 print_variant_part (struct value
*value
, int field_num
,
555 struct value
*outer_value
,
556 struct ui_file
*stream
, int recurse
,
557 const struct value_print_options
*options
,
559 const struct language_defn
*language
)
561 struct type
*type
= value_type (value
);
562 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
563 int which
= ada_which_variant_applies (var_type
,
564 value_type (outer_value
),
565 value_contents (outer_value
));
570 struct value
*active_component
= value_field (value
, which
);
571 return print_field_values (active_component
, outer_value
, stream
, recurse
,
572 options
, comma_needed
, language
);
575 /* Print out fields of VALUE.
577 STREAM, RECURSE, and OPTIONS have the same meanings as in
578 ada_print_value and ada_value_print.
580 OUTER_VALUE gives the enclosing record (used to get discriminant
581 values when printing variant parts).
583 COMMA_NEEDED is 1 if fields have been printed at the current recursion
584 level, so that a comma is needed before any field printed by this
587 Returns 1 if COMMA_NEEDED or any fields were printed. */
590 print_field_values (struct value
*value
, struct value
*outer_value
,
591 struct ui_file
*stream
, int recurse
,
592 const struct value_print_options
*options
,
594 const struct language_defn
*language
)
598 struct type
*type
= value_type (value
);
599 len
= TYPE_NFIELDS (type
);
601 for (i
= 0; i
< len
; i
+= 1)
603 if (ada_is_ignored_field (type
, i
))
606 if (ada_is_wrapper_field (type
, i
))
609 print_field_values (value_field (value
, i
), outer_value
,
610 stream
, recurse
, options
,
611 comma_needed
, language
);
614 else if (ada_is_variant_part (type
, i
))
617 print_variant_part (value
, i
, outer_value
, stream
, recurse
,
618 options
, comma_needed
, language
);
623 fprintf_filtered (stream
, ", ");
626 if (options
->prettyformat
)
628 fprintf_filtered (stream
, "\n");
629 print_spaces_filtered (2 + 2 * recurse
, stream
);
633 wrap_here (n_spaces (2 + 2 * recurse
));
636 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
637 fprintf_filtered (stream
, "%.*s",
638 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
639 TYPE_FIELD_NAME (type
, i
));
640 annotate_field_name_end ();
641 fputs_filtered (" => ", stream
);
642 annotate_field_value ();
644 if (TYPE_FIELD_PACKED (type
, i
))
646 /* Bitfields require special handling, especially due to byte
648 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
650 fputs_styled (_("<optimized out or zero length>"),
651 metadata_style
.style (), stream
);
656 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
657 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
658 struct value_print_options opts
;
660 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
661 v
= ada_value_primitive_packed_val
663 bit_pos
/ HOST_CHAR_BIT
,
664 bit_pos
% HOST_CHAR_BIT
,
665 bit_size
, TYPE_FIELD_TYPE (type
, i
));
668 common_val_print (v
, stream
, recurse
+ 1, &opts
, language
);
673 struct value_print_options opts
= *options
;
677 struct value
*v
= value_field (value
, i
);
678 common_val_print (v
, stream
, recurse
+ 1, &opts
, language
);
680 annotate_field_end ();
686 /* Implement Ada val_print'ing for the case where TYPE is
687 a TYPE_CODE_ARRAY of characters. */
690 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
692 struct ui_file
*stream
, int recurse
,
693 const struct value_print_options
*options
)
695 enum bfd_endian byte_order
= type_byte_order (type
);
696 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
700 /* We know that ELTTYPE cannot possibly be null, because we assume
701 that we're called only when TYPE is a string-like type.
702 Similarly, the size of ELTTYPE should also be non-null, since
703 it's a character-like type. */
704 gdb_assert (elttype
!= NULL
);
705 gdb_assert (TYPE_LENGTH (elttype
) != 0);
707 eltlen
= TYPE_LENGTH (elttype
);
708 len
= TYPE_LENGTH (type
) / eltlen
;
710 if (options
->prettyformat_arrays
)
711 print_spaces_filtered (2 + 2 * recurse
, stream
);
713 /* If requested, look for the first null char and only print
714 elements up to it. */
715 if (options
->stop_print_at_null
)
719 /* Look for a NULL char. */
722 && temp_len
< options
->print_max
723 && char_at (valaddr
+ offset_aligned
,
724 temp_len
, eltlen
, byte_order
) != 0);
729 printstr (stream
, elttype
, valaddr
+ offset_aligned
, len
, 0,
733 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
734 thin pointers, etc). */
737 ada_val_print_gnat_array (struct value
*val
,
738 struct ui_file
*stream
, int recurse
,
739 const struct value_print_options
*options
)
741 scoped_value_mark free_values
;
743 struct type
*type
= ada_check_typedef (value_type (val
));
745 /* If this is a reference, coerce it now. This helps taking care
746 of the case where ADDRESS is meaningless because original_value
748 val
= coerce_ref (val
);
749 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
750 val
= ada_coerce_to_simple_array_ptr (val
);
752 val
= ada_coerce_to_simple_array (val
);
755 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
756 fprintf_filtered (stream
, "0x0");
759 common_val_print (val
, stream
, recurse
, options
,
760 language_def (language_ada
));
763 /* Implement Ada value_print'ing for the case where TYPE is a
767 ada_value_print_ptr (struct value
*val
,
768 struct ui_file
*stream
, int recurse
,
769 const struct value_print_options
*options
)
771 common_val_print (val
, stream
, recurse
, options
, language_def (language_c
));
773 struct type
*type
= ada_check_typedef (value_type (val
));
774 if (ada_is_tag_type (type
))
776 const char *name
= ada_tag_name (val
);
779 fprintf_filtered (stream
, " (%s)", name
);
783 /* Implement Ada val_print'ing for the case where TYPE is
784 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
787 ada_value_print_num (struct value
*val
, struct ui_file
*stream
, int recurse
,
788 const struct value_print_options
*options
)
790 struct type
*type
= ada_check_typedef (value_type (val
));
791 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
793 if (ada_is_fixed_point_type (type
))
795 struct value
*scale
= ada_scaling_factor (type
);
796 val
= value_cast (value_type (scale
), val
);
797 val
= value_binop (val
, scale
, BINOP_MUL
);
799 const char *fmt
= TYPE_LENGTH (type
) < 4 ? "%.11g" : "%.17g";
801 = target_float_to_string (value_contents (val
), value_type (val
), fmt
);
802 fputs_filtered (str
.c_str (), stream
);
805 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
806 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ENUM
807 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_BOOL
808 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CHAR
))
810 /* For enum-valued ranges, we want to recurse, because we'll end
811 up printing the constant's name rather than its numeric
812 value. Character and fixed-point types are also printed
813 differently, so recuse for those as well. */
814 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
815 val
= value_cast (target_type
, val
);
816 common_val_print (val
, stream
, recurse
+ 1, options
,
817 language_def (language_ada
));
822 int format
= (options
->format
? options
->format
823 : options
->output_format
);
827 struct value_print_options opts
= *options
;
829 opts
.format
= format
;
830 value_print_scalar_formatted (val
, &opts
, 0, stream
);
832 else if (ada_is_system_address_type (type
))
834 /* FIXME: We want to print System.Address variables using
835 the same format as for any access type. But for some
836 reason GNAT encodes the System.Address type as an int,
837 so we have to work-around this deficiency by handling
838 System.Address values as a special case. */
840 struct gdbarch
*gdbarch
= get_type_arch (type
);
841 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
842 CORE_ADDR addr
= extract_typed_address (valaddr
, ptr_type
);
844 fprintf_filtered (stream
, "(");
845 type_print (type
, "", stream
, -1);
846 fprintf_filtered (stream
, ") ");
847 fputs_filtered (paddress (gdbarch
, addr
), stream
);
851 value_print_scalar_formatted (val
, options
, 0, stream
);
852 if (ada_is_character_type (type
))
856 fputs_filtered (" ", stream
);
857 c
= unpack_long (type
, valaddr
);
858 ada_printchar (c
, type
, stream
);
865 /* Implement Ada val_print'ing for the case where TYPE is
869 ada_val_print_enum (struct value
*value
, struct ui_file
*stream
, int recurse
,
870 const struct value_print_options
*options
)
878 value_print_scalar_formatted (value
, options
, 0, stream
);
882 struct type
*type
= ada_check_typedef (value_type (value
));
883 const gdb_byte
*valaddr
= value_contents_for_printing (value
);
884 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
886 len
= TYPE_NFIELDS (type
);
887 val
= unpack_long (type
, valaddr
+ offset_aligned
);
888 for (i
= 0; i
< len
; i
++)
891 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
897 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
900 fprintf_filtered (stream
, "%ld %ps", (long) val
,
901 styled_string (variable_name_style
.style (),
904 fputs_styled (name
, variable_name_style
.style (), stream
);
907 print_longest (stream
, 'd', 0, val
);
910 /* Implement Ada val_print'ing for the case where the type is
911 TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
914 ada_val_print_struct_union (struct value
*value
,
915 struct ui_file
*stream
,
917 const struct value_print_options
*options
)
919 if (ada_is_bogus_array_descriptor (value_type (value
)))
921 fprintf_filtered (stream
, "(...?)");
925 fprintf_filtered (stream
, "(");
927 if (print_field_values (value
, value
, stream
, recurse
, options
,
928 0, language_def (language_ada
)) != 0
929 && options
->prettyformat
)
931 fprintf_filtered (stream
, "\n");
932 print_spaces_filtered (2 * recurse
, stream
);
935 fprintf_filtered (stream
, ")");
938 /* Implement Ada value_print'ing for the case where TYPE is a
942 ada_value_print_array (struct value
*val
, struct ui_file
*stream
, int recurse
,
943 const struct value_print_options
*options
)
945 struct type
*type
= ada_check_typedef (value_type (val
));
947 /* For an array of characters, print with string syntax. */
948 if (ada_is_string_type (type
)
949 && (options
->format
== 0 || options
->format
== 's'))
951 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
952 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
954 ada_val_print_string (type
, valaddr
, offset_aligned
, stream
, recurse
,
959 fprintf_filtered (stream
, "(");
960 print_optional_low_bound (stream
, type
, options
);
961 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
963 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
964 int offset_aligned
= ada_aligned_value_addr (type
, valaddr
) - valaddr
;
965 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
966 stream
, recurse
, options
);
969 value_print_array_elements (val
, stream
, recurse
, options
, 0);
970 fprintf_filtered (stream
, ")");
973 /* Implement Ada val_print'ing for the case where TYPE is
977 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
978 int offset
, int offset_aligned
, CORE_ADDR address
,
979 struct ui_file
*stream
, int recurse
,
980 struct value
*original_value
,
981 const struct value_print_options
*options
)
983 /* For references, the debugger is expected to print the value as
984 an address if DEREF_REF is null. But printing an address in place
985 of the object value would be confusing to an Ada programmer.
986 So, for Ada values, we print the actual dereferenced value
988 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
989 struct value
*deref_val
;
990 CORE_ADDR deref_val_int
;
992 if (TYPE_CODE (elttype
) == TYPE_CODE_UNDEF
)
994 fputs_styled ("<ref to undefined type>", metadata_style
.style (),
999 deref_val
= coerce_ref_if_computed (original_value
);
1002 if (ada_is_tagged_type (value_type (deref_val
), 1))
1003 deref_val
= ada_tag_value_at_base_address (deref_val
);
1005 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
1006 language_def (language_ada
));
1010 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
1011 if (deref_val_int
== 0)
1013 fputs_filtered ("(null)", stream
);
1018 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
1020 if (ada_is_tagged_type (value_type (deref_val
), 1))
1021 deref_val
= ada_tag_value_at_base_address (deref_val
);
1023 /* Make sure that the object does not have an unreasonable size
1024 before trying to print it. This can happen for instance with
1025 references to dynamic objects whose contents is uninitialized
1026 (Eg: an array whose bounds are not set yet). */
1027 ada_ensure_varsize_limit (value_type (deref_val
));
1029 if (value_lazy (deref_val
))
1030 value_fetch_lazy (deref_val
);
1032 common_val_print (deref_val
, stream
, recurse
+ 1,
1033 options
, language_def (language_ada
));
1036 /* See the comment on ada_value_print. This function differs in that
1037 it does not catch evaluation errors (leaving that to
1038 ada_value_print). */
1041 ada_value_print_1 (struct value
*val
, struct ui_file
*stream
, int recurse
,
1042 const struct value_print_options
*options
)
1044 struct type
*type
= ada_check_typedef (value_type (val
));
1046 if (ada_is_array_descriptor_type (type
)
1047 || (ada_is_constrained_packed_array_type (type
)
1048 && TYPE_CODE (type
) != TYPE_CODE_PTR
))
1050 ada_val_print_gnat_array (val
, stream
, recurse
, options
);
1054 val
= ada_to_fixed_value (val
);
1055 type
= value_type (val
);
1056 struct type
*saved_type
= type
;
1058 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
1059 CORE_ADDR address
= value_address (val
);
1060 type
= ada_check_typedef (resolve_dynamic_type (type
, valaddr
, address
));
1061 if (type
!= saved_type
)
1063 val
= value_copy (val
);
1064 deprecated_set_value_type (val
, type
);
1067 switch (TYPE_CODE (type
))
1070 common_val_print (val
, stream
, recurse
, options
,
1071 language_def (language_c
));
1075 ada_value_print_ptr (val
, stream
, recurse
, options
);
1079 case TYPE_CODE_RANGE
:
1080 ada_value_print_num (val
, stream
, recurse
, options
);
1083 case TYPE_CODE_ENUM
:
1084 ada_val_print_enum (val
, stream
, recurse
, options
);
1088 if (options
->format
)
1090 common_val_print (val
, stream
, recurse
, options
,
1091 language_def (language_c
));
1095 ada_print_floating (valaddr
, type
, stream
);
1098 case TYPE_CODE_UNION
:
1099 case TYPE_CODE_STRUCT
:
1100 ada_val_print_struct_union (val
, stream
, recurse
, options
);
1103 case TYPE_CODE_ARRAY
:
1104 ada_value_print_array (val
, stream
, recurse
, options
);
1108 ada_val_print_ref (type
, valaddr
, 0, 0,
1109 address
, stream
, recurse
, val
,
1115 /* See ada-lang.h. */
1118 ada_value_print_inner (struct value
*val
, struct ui_file
*stream
,
1120 const struct value_print_options
*options
)
1124 ada_value_print_1 (val
, stream
, recurse
, options
);
1126 catch (const gdb_exception_error
&except
)
1128 fprintf_styled (stream
, metadata_style
.style (),
1129 _("<error reading variable: %s>"),
1135 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1136 const struct value_print_options
*options
)
1138 struct value
*val
= ada_to_fixed_value (val0
);
1139 struct type
*type
= ada_check_typedef (value_type (val
));
1140 struct value_print_options opts
;
1142 /* If it is a pointer, indicate what it points to. */
1143 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1145 /* Hack: don't print (char *) for char strings. Their
1146 type is indicated by the quoted string anyway. */
1147 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
1148 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
1149 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
1151 fprintf_filtered (stream
, "(");
1152 type_print (type
, "", stream
, -1);
1153 fprintf_filtered (stream
, ") ");
1156 else if (ada_is_array_descriptor_type (type
))
1158 /* We do not print the type description unless TYPE is an array
1159 access type (this is encoded by the compiler as a typedef to
1160 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1161 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1163 fprintf_filtered (stream
, "(");
1164 type_print (type
, "", stream
, -1);
1165 fprintf_filtered (stream
, ") ");
1168 else if (ada_is_bogus_array_descriptor (type
))
1170 fprintf_filtered (stream
, "(");
1171 type_print (type
, "", stream
, -1);
1172 fprintf_filtered (stream
, ") (...?)");
1178 common_val_print (val
, stream
, 0, &opts
, current_language
);