1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2019 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/>. */
24 #include "expression.h"
34 #include "target-float.h"
35 #include "cli/cli-style.h"
37 static int print_field_values (struct type
*, const gdb_byte
*,
39 struct ui_file
*, int,
41 const struct value_print_options
*,
42 int, struct type
*, int,
43 const struct language_defn
*);
46 /* Make TYPE unsigned if its range of values includes no negatives. */
48 adjust_type_signedness (struct type
*type
)
50 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
51 && TYPE_LOW_BOUND (type
) >= 0)
52 TYPE_UNSIGNED (type
) = 1;
55 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
56 if non-standard (i.e., other than 1 for numbers, other than lower bound
57 of index type for enumerated type). Returns 1 if something printed,
61 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
62 const struct value_print_options
*options
)
64 struct type
*index_type
;
68 if (options
->print_array_indexes
)
71 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
74 /* If this is an empty array, then don't print the lower bound.
75 That would be confusing, because we would print the lower bound,
76 followed by... nothing! */
77 if (low_bound
> high_bound
)
80 index_type
= TYPE_INDEX_TYPE (type
);
82 while (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
84 /* We need to know what the base type is, in order to do the
85 appropriate check below. Otherwise, if this is a subrange
86 of an enumerated type, where the underlying value of the
87 first element is typically 0, we might test the low bound
88 against the wrong value. */
89 index_type
= TYPE_TARGET_TYPE (index_type
);
92 /* Don't print the lower bound if it's the default one. */
93 switch (TYPE_CODE (index_type
))
101 if (low_bound
== TYPE_FIELD_ENUMVAL (index_type
, 0))
104 case TYPE_CODE_UNDEF
:
113 ada_print_scalar (index_type
, low_bound
, stream
);
114 fprintf_filtered (stream
, " => ");
118 /* Version of val_print_array_elements for GNAT-style packed arrays.
119 Prints elements of packed array of type TYPE at bit offset
120 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
121 separates with commas. RECURSE is the recursion (nesting) level.
122 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
125 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
127 int bitoffset
, struct ui_file
*stream
,
130 const struct value_print_options
*options
)
133 unsigned int things_printed
= 0;
135 struct type
*elttype
, *index_type
;
136 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
137 struct value
*mark
= value_mark ();
140 elttype
= TYPE_TARGET_TYPE (type
);
141 index_type
= TYPE_INDEX_TYPE (type
);
145 struct type
*base_index_type
;
147 if (get_discrete_bounds (index_type
, &low
, &high
) < 0)
150 len
= high
- low
+ 1;
152 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
153 base_index_type
= TYPE_TARGET_TYPE (index_type
);
155 base_index_type
= index_type
;
157 if (TYPE_CODE (base_index_type
) == TYPE_CODE_ENUM
)
159 LONGEST low_pos
, high_pos
;
161 /* Non-contiguous enumerations types can by used as index types
162 so the array length is computed from the positions of the
163 first and last literal in the enumeration type, and not from
164 the values of these literals. */
166 if (!discrete_position (base_index_type
, low
, &low_pos
)
167 || !discrete_position (base_index_type
, high
, &high_pos
))
169 warning (_("unable to get positions in array, use bounds instead"));
174 /* The array length should normally be HIGH_POS - LOW_POS + 1.
175 But in Ada we allow LOW_POS to be greater than HIGH_POS for
176 empty arrays. In that situation, the array length is just zero,
179 if (low_pos
> high_pos
)
182 len
= high_pos
- low_pos
+ 1;
187 annotate_array_section_begin (i
, elttype
);
189 while (i
< len
&& things_printed
< options
->print_max
)
191 struct value
*v0
, *v1
;
196 if (options
->prettyformat_arrays
)
198 fprintf_filtered (stream
, ",\n");
199 print_spaces_filtered (2 + 2 * recurse
, stream
);
203 fprintf_filtered (stream
, ", ");
206 wrap_here (n_spaces (2 + 2 * recurse
));
207 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
210 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
211 (i0
* bitsize
) / HOST_CHAR_BIT
,
212 (i0
* bitsize
) % HOST_CHAR_BIT
,
219 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
220 (i
* bitsize
) / HOST_CHAR_BIT
,
221 (i
* bitsize
) % HOST_CHAR_BIT
,
223 if (TYPE_LENGTH (check_typedef (value_type (v0
)))
224 != TYPE_LENGTH (check_typedef (value_type (v1
))))
226 if (!value_contents_eq (v0
, value_embedded_offset (v0
),
227 v1
, value_embedded_offset (v1
),
228 TYPE_LENGTH (check_typedef (value_type (v0
)))))
232 if (i
- i0
> options
->repeat_count_threshold
)
234 struct value_print_options opts
= *options
;
238 value_embedded_offset (v0
), 0, stream
,
239 recurse
+ 1, v0
, &opts
, current_language
);
240 annotate_elt_rep (i
- i0
);
241 fprintf_filtered (stream
, _(" %p[<repeats %u times>%p]"),
242 metadata_style
.style ().ptr (), i
- i0
, nullptr);
243 annotate_elt_rep_end ();
249 struct value_print_options opts
= *options
;
252 for (j
= i0
; j
< i
; j
+= 1)
256 if (options
->prettyformat_arrays
)
258 fprintf_filtered (stream
, ",\n");
259 print_spaces_filtered (2 + 2 * recurse
, stream
);
263 fprintf_filtered (stream
, ", ");
265 wrap_here (n_spaces (2 + 2 * recurse
));
266 maybe_print_array_index (index_type
, j
+ low
,
270 value_embedded_offset (v0
), 0, stream
,
271 recurse
+ 1, v0
, &opts
, current_language
);
275 things_printed
+= i
- i0
;
277 annotate_array_section_end ();
280 fprintf_filtered (stream
, "...");
283 value_free_to_mark (mark
);
287 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
289 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
292 /* Print the character C on STREAM as part of the contents of a literal
293 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
297 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
298 int quoter
, int type_len
)
300 /* If this character fits in the normal ASCII range, and is
301 a printable character, then print the character as if it was
302 an ASCII character, even if this is a wide character.
303 The UCHAR_MAX check is necessary because the isascii function
304 requires that its argument have a value of an unsigned char,
305 or EOF (EOF is obviously not printable). */
306 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
308 if (c
== quoter
&& c
== '"')
309 fprintf_filtered (stream
, "\"\"");
311 fprintf_filtered (stream
, "%c", c
);
314 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
317 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
321 char_at (const gdb_byte
*string
, int i
, int type_len
,
322 enum bfd_endian byte_order
)
327 return (int) extract_unsigned_integer (string
+ type_len
* i
,
328 type_len
, byte_order
);
331 /* Print a floating-point value of type TYPE, pointed to in GDB by
332 VALADDR, on STREAM. Use Ada formatting conventions: there must be
333 a decimal point, and at least one digit before and after the
334 point. We use the GNAT format for NaNs and infinities. */
337 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
338 struct ui_file
*stream
)
340 string_file tmp_stream
;
342 print_floating (valaddr
, type
, &tmp_stream
);
344 std::string
&s
= tmp_stream
.string ();
345 size_t skip_count
= 0;
347 /* Modify for Ada rules. */
349 size_t pos
= s
.find ("inf");
350 if (pos
== std::string::npos
)
351 pos
= s
.find ("Inf");
352 if (pos
== std::string::npos
)
353 pos
= s
.find ("INF");
354 if (pos
!= std::string::npos
)
355 s
.replace (pos
, 3, "Inf");
357 if (pos
== std::string::npos
)
359 pos
= s
.find ("nan");
360 if (pos
== std::string::npos
)
361 pos
= s
.find ("NaN");
362 if (pos
== std::string::npos
)
363 pos
= s
.find ("Nan");
364 if (pos
!= std::string::npos
)
366 s
[pos
] = s
[pos
+ 2] = 'N';
372 if (pos
== std::string::npos
373 && s
.find ('.') == std::string::npos
)
376 if (pos
== std::string::npos
)
377 fprintf_filtered (stream
, "%s.0", s
.c_str ());
379 fprintf_filtered (stream
, "%.*s.0%s", (int) pos
, s
.c_str (), &s
[pos
]);
382 fprintf_filtered (stream
, "%s", &s
[skip_count
]);
386 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
388 fputs_filtered ("'", stream
);
389 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
390 fputs_filtered ("'", stream
);
393 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
394 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
395 like a default signed integer. */
398 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
405 print_longest (stream
, 'd', 0, val
);
409 type
= ada_check_typedef (type
);
411 switch (TYPE_CODE (type
))
415 len
= TYPE_NFIELDS (type
);
416 for (i
= 0; i
< len
; i
++)
418 if (TYPE_FIELD_ENUMVAL (type
, i
) == val
)
425 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
429 print_longest (stream
, 'd', 0, val
);
434 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
438 LA_PRINT_CHAR (val
, type
, stream
);
442 fprintf_filtered (stream
, val
? "true" : "false");
445 case TYPE_CODE_RANGE
:
446 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
449 case TYPE_CODE_UNDEF
:
451 case TYPE_CODE_ARRAY
:
452 case TYPE_CODE_STRUCT
:
453 case TYPE_CODE_UNION
:
458 case TYPE_CODE_STRING
:
459 case TYPE_CODE_ERROR
:
460 case TYPE_CODE_MEMBERPTR
:
461 case TYPE_CODE_METHODPTR
:
462 case TYPE_CODE_METHOD
:
464 warning (_("internal error: unhandled type in ada_print_scalar"));
468 error (_("Invalid type code in symbol table."));
472 /* Print the character string STRING, printing at most LENGTH characters.
473 Printing stops early if the number hits print_max; repeat counts
474 are printed as appropriate. Print ellipses at the end if we
475 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
476 TYPE_LEN is the length (1 or 2) of the character type. */
479 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
480 unsigned int length
, int force_ellipses
, int type_len
,
481 const struct value_print_options
*options
)
483 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (elttype
));
485 unsigned int things_printed
= 0;
491 fputs_filtered ("\"\"", stream
);
495 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
497 /* Position of the character we are examining
498 to see whether it is repeated. */
500 /* Number of repetitions we have detected so far. */
507 fputs_filtered (", ", stream
);
514 && char_at (string
, rep1
, type_len
, byte_order
)
515 == char_at (string
, i
, type_len
, byte_order
))
521 if (reps
> options
->repeat_count_threshold
)
525 fputs_filtered ("\", ", stream
);
528 fputs_filtered ("'", stream
);
529 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
530 elttype
, stream
, '\'', type_len
);
531 fputs_filtered ("'", stream
);
532 fprintf_filtered (stream
, _(" %p[<repeats %u times>%p]"),
533 metadata_style
.style ().ptr (), reps
, nullptr);
535 things_printed
+= options
->repeat_count_threshold
;
542 fputs_filtered ("\"", stream
);
545 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
546 elttype
, stream
, '"', type_len
);
551 /* Terminate the quotes if necessary. */
553 fputs_filtered ("\"", stream
);
555 if (force_ellipses
|| i
< length
)
556 fputs_filtered ("...", stream
);
560 ada_printstr (struct ui_file
*stream
, struct type
*type
,
561 const gdb_byte
*string
, unsigned int length
,
562 const char *encoding
, int force_ellipses
,
563 const struct value_print_options
*options
)
565 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
570 print_variant_part (struct type
*type
, int field_num
,
571 const gdb_byte
*valaddr
, int offset
,
572 struct ui_file
*stream
, int recurse
,
574 const struct value_print_options
*options
,
576 struct type
*outer_type
, int outer_offset
,
577 const struct language_defn
*language
)
579 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
580 int which
= ada_which_variant_applies (var_type
, outer_type
,
581 valaddr
+ outer_offset
);
586 return print_field_values
587 (TYPE_FIELD_TYPE (var_type
, which
),
589 offset
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
590 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
591 stream
, recurse
, val
, options
,
592 comma_needed
, outer_type
, outer_offset
, language
);
595 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
597 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
598 meanings as in ada_print_value and ada_val_print.
600 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
601 record (used to get discriminant values when printing variant
604 COMMA_NEEDED is 1 if fields have been printed at the current recursion
605 level, so that a comma is needed before any field printed by this
608 Returns 1 if COMMA_NEEDED or any fields were printed. */
611 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
612 int offset
, struct ui_file
*stream
, int recurse
,
614 const struct value_print_options
*options
,
616 struct type
*outer_type
, int outer_offset
,
617 const struct language_defn
*language
)
621 len
= TYPE_NFIELDS (type
);
623 for (i
= 0; i
< len
; i
+= 1)
625 if (ada_is_ignored_field (type
, i
))
628 if (ada_is_wrapper_field (type
, i
))
631 print_field_values (TYPE_FIELD_TYPE (type
, i
),
634 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
635 stream
, recurse
, val
, options
,
636 comma_needed
, type
, offset
, language
);
639 else if (ada_is_variant_part (type
, i
))
642 print_variant_part (type
, i
, valaddr
,
643 offset
, stream
, recurse
, val
,
644 options
, comma_needed
,
645 outer_type
, outer_offset
, language
);
650 fprintf_filtered (stream
, ", ");
653 if (options
->prettyformat
)
655 fprintf_filtered (stream
, "\n");
656 print_spaces_filtered (2 + 2 * recurse
, stream
);
660 wrap_here (n_spaces (2 + 2 * recurse
));
663 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
664 fprintf_filtered (stream
, "%.*s",
665 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
666 TYPE_FIELD_NAME (type
, i
));
667 annotate_field_name_end ();
668 fputs_filtered (" => ", stream
);
669 annotate_field_value ();
671 if (TYPE_FIELD_PACKED (type
, i
))
673 /* Bitfields require special handling, especially due to byte
675 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
677 fputs_styled (_("<optimized out or zero length>"),
678 metadata_style
.style (), stream
);
683 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
684 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
685 struct value_print_options opts
;
687 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
688 v
= ada_value_primitive_packed_val
690 offset
+ bit_pos
/ HOST_CHAR_BIT
,
691 bit_pos
% HOST_CHAR_BIT
,
692 bit_size
, TYPE_FIELD_TYPE (type
, i
));
695 val_print (TYPE_FIELD_TYPE (type
, i
),
696 value_embedded_offset (v
), 0,
697 stream
, recurse
+ 1, v
,
703 struct value_print_options opts
= *options
;
706 val_print (TYPE_FIELD_TYPE (type
, i
),
707 (offset
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
708 0, stream
, recurse
+ 1, val
, &opts
, language
);
710 annotate_field_end ();
716 /* Implement Ada val_print'ing for the case where TYPE is
717 a TYPE_CODE_ARRAY of characters. */
720 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
721 int offset
, int offset_aligned
, CORE_ADDR address
,
722 struct ui_file
*stream
, int recurse
,
723 struct value
*original_value
,
724 const struct value_print_options
*options
)
726 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (type
));
727 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
731 /* We know that ELTTYPE cannot possibly be null, because we assume
732 that we're called only when TYPE is a string-like type.
733 Similarly, the size of ELTTYPE should also be non-null, since
734 it's a character-like type. */
735 gdb_assert (elttype
!= NULL
);
736 gdb_assert (TYPE_LENGTH (elttype
) != 0);
738 eltlen
= TYPE_LENGTH (elttype
);
739 len
= TYPE_LENGTH (type
) / eltlen
;
741 if (options
->prettyformat_arrays
)
742 print_spaces_filtered (2 + 2 * recurse
, stream
);
744 /* If requested, look for the first null char and only print
745 elements up to it. */
746 if (options
->stop_print_at_null
)
750 /* Look for a NULL char. */
753 && temp_len
< options
->print_max
754 && char_at (valaddr
+ offset_aligned
,
755 temp_len
, eltlen
, byte_order
) != 0);
760 printstr (stream
, elttype
, valaddr
+ offset_aligned
, len
, 0,
764 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
765 thin pointers, etc). */
768 ada_val_print_gnat_array (struct type
*type
, const gdb_byte
*valaddr
,
769 int offset
, CORE_ADDR address
,
770 struct ui_file
*stream
, int recurse
,
771 struct value
*original_value
,
772 const struct value_print_options
*options
)
774 struct value
*mark
= value_mark ();
777 val
= value_from_contents_and_address (type
, valaddr
+ offset
, address
);
778 /* If this is a reference, coerce it now. This helps taking care
779 of the case where ADDRESS is meaningless because original_value
781 val
= coerce_ref (val
);
782 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
783 val
= ada_coerce_to_simple_array_ptr (val
);
785 val
= ada_coerce_to_simple_array (val
);
788 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
789 fprintf_filtered (stream
, "0x0");
792 val_print (value_type (val
),
793 value_embedded_offset (val
), value_address (val
),
794 stream
, recurse
, val
, options
,
795 language_def (language_ada
));
796 value_free_to_mark (mark
);
799 /* Implement Ada val_print'ing for the case where TYPE is
803 ada_val_print_ptr (struct type
*type
, const gdb_byte
*valaddr
,
804 int offset
, int offset_aligned
, CORE_ADDR address
,
805 struct ui_file
*stream
, int recurse
,
806 struct value
*original_value
,
807 const struct value_print_options
*options
)
809 val_print (type
, offset
, address
, stream
, recurse
,
810 original_value
, options
, language_def (language_c
));
812 if (ada_is_tag_type (type
))
815 value_from_contents_and_address (type
,
816 valaddr
+ offset_aligned
,
817 address
+ offset_aligned
);
818 const char *name
= ada_tag_name (val
);
821 fprintf_filtered (stream
, " (%s)", name
);
825 /* Implement Ada val_print'ing for the case where TYPE is
826 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
829 ada_val_print_num (struct type
*type
, const gdb_byte
*valaddr
,
830 int offset
, int offset_aligned
, CORE_ADDR address
,
831 struct ui_file
*stream
, int recurse
,
832 struct value
*original_value
,
833 const struct value_print_options
*options
)
835 if (ada_is_fixed_point_type (type
))
837 struct value
*scale
= ada_scaling_factor (type
);
838 struct value
*v
= value_from_contents (type
, valaddr
+ offset_aligned
);
839 v
= value_cast (value_type (scale
), v
);
840 v
= value_binop (v
, scale
, BINOP_MUL
);
842 const char *fmt
= TYPE_LENGTH (type
) < 4 ? "%.11g" : "%.17g";
844 = target_float_to_string (value_contents (v
), value_type (v
), fmt
);
845 fputs_filtered (str
.c_str (), stream
);
848 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
849 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ENUM
850 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_BOOL
851 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CHAR
))
853 /* For enum-valued ranges, we want to recurse, because we'll end
854 up printing the constant's name rather than its numeric
855 value. Character and fixed-point types are also printed
856 differently, so recuse for those as well. */
857 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
859 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
861 /* Obscure case of range type that has different length from
862 its base type. Perform a conversion, or we will get a
863 nonsense value. Actually, we could use the same
864 code regardless of lengths; I'm just avoiding a cast. */
866 = value_from_contents_and_address (type
, valaddr
+ offset
, 0);
867 struct value
*v
= value_cast (target_type
, v1
);
869 val_print (target_type
,
870 value_embedded_offset (v
), 0, stream
,
871 recurse
+ 1, v
, options
,
872 language_def (language_ada
));
875 val_print (TYPE_TARGET_TYPE (type
), offset
,
876 address
, stream
, recurse
, original_value
,
877 options
, language_def (language_ada
));
882 int format
= (options
->format
? options
->format
883 : options
->output_format
);
887 struct value_print_options opts
= *options
;
889 opts
.format
= format
;
890 val_print_scalar_formatted (type
, offset_aligned
,
891 original_value
, &opts
, 0, stream
);
893 else if (ada_is_system_address_type (type
))
895 /* FIXME: We want to print System.Address variables using
896 the same format as for any access type. But for some
897 reason GNAT encodes the System.Address type as an int,
898 so we have to work-around this deficiency by handling
899 System.Address values as a special case. */
901 struct gdbarch
*gdbarch
= get_type_arch (type
);
902 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
903 CORE_ADDR addr
= extract_typed_address (valaddr
+ offset_aligned
,
906 fprintf_filtered (stream
, "(");
907 type_print (type
, "", stream
, -1);
908 fprintf_filtered (stream
, ") ");
909 fputs_filtered (paddress (gdbarch
, addr
), stream
);
913 val_print_scalar_formatted (type
, offset_aligned
,
914 original_value
, options
, 0, stream
);
915 if (ada_is_character_type (type
))
919 fputs_filtered (" ", stream
);
920 c
= unpack_long (type
, valaddr
+ offset_aligned
);
921 ada_printchar (c
, type
, stream
);
928 /* Implement Ada val_print'ing for the case where TYPE is
932 ada_val_print_enum (struct type
*type
, const gdb_byte
*valaddr
,
933 int offset
, int offset_aligned
, CORE_ADDR address
,
934 struct ui_file
*stream
, int recurse
,
935 struct value
*original_value
,
936 const struct value_print_options
*options
)
944 val_print_scalar_formatted (type
, offset_aligned
,
945 original_value
, options
, 0, stream
);
949 len
= TYPE_NFIELDS (type
);
950 val
= unpack_long (type
, valaddr
+ offset_aligned
);
951 for (i
= 0; i
< len
; i
++)
954 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
960 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
963 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
965 fputs_filtered (name
, stream
);
968 print_longest (stream
, 'd', 0, val
);
971 /* Implement Ada val_print'ing for the case where TYPE is
975 ada_val_print_flt (struct type
*type
, const gdb_byte
*valaddr
,
976 int offset
, int offset_aligned
, CORE_ADDR address
,
977 struct ui_file
*stream
, int recurse
,
978 struct value
*original_value
,
979 const struct value_print_options
*options
)
983 val_print (type
, offset
, address
, stream
, recurse
,
984 original_value
, options
, language_def (language_c
));
988 ada_print_floating (valaddr
+ offset
, type
, stream
);
991 /* Implement Ada val_print'ing for the case where TYPE is
992 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
995 ada_val_print_struct_union
996 (struct type
*type
, const gdb_byte
*valaddr
, int offset
,
997 int offset_aligned
, CORE_ADDR address
, struct ui_file
*stream
,
998 int recurse
, struct value
*original_value
,
999 const struct value_print_options
*options
)
1001 if (ada_is_bogus_array_descriptor (type
))
1003 fprintf_filtered (stream
, "(...?)");
1007 fprintf_filtered (stream
, "(");
1009 if (print_field_values (type
, valaddr
, offset_aligned
,
1010 stream
, recurse
, original_value
, options
,
1011 0, type
, offset_aligned
,
1012 language_def (language_ada
)) != 0
1013 && options
->prettyformat
)
1015 fprintf_filtered (stream
, "\n");
1016 print_spaces_filtered (2 * recurse
, stream
);
1019 fprintf_filtered (stream
, ")");
1022 /* Implement Ada val_print'ing for the case where TYPE is
1023 a TYPE_CODE_ARRAY. */
1026 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
1027 int offset
, int offset_aligned
, CORE_ADDR address
,
1028 struct ui_file
*stream
, int recurse
,
1029 struct value
*original_value
,
1030 const struct value_print_options
*options
)
1032 /* For an array of characters, print with string syntax. */
1033 if (ada_is_string_type (type
)
1034 && (options
->format
== 0 || options
->format
== 's'))
1036 ada_val_print_string (type
, valaddr
, offset
, offset_aligned
,
1037 address
, stream
, recurse
, original_value
,
1042 fprintf_filtered (stream
, "(");
1043 print_optional_low_bound (stream
, type
, options
);
1044 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1045 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
1047 original_value
, options
);
1049 val_print_array_elements (type
, offset_aligned
, address
,
1050 stream
, recurse
, original_value
,
1052 fprintf_filtered (stream
, ")");
1055 /* Implement Ada val_print'ing for the case where TYPE is
1059 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
1060 int offset
, int offset_aligned
, CORE_ADDR address
,
1061 struct ui_file
*stream
, int recurse
,
1062 struct value
*original_value
,
1063 const struct value_print_options
*options
)
1065 /* For references, the debugger is expected to print the value as
1066 an address if DEREF_REF is null. But printing an address in place
1067 of the object value would be confusing to an Ada programmer.
1068 So, for Ada values, we print the actual dereferenced value
1070 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
1071 struct value
*deref_val
;
1072 CORE_ADDR deref_val_int
;
1074 if (TYPE_CODE (elttype
) == TYPE_CODE_UNDEF
)
1076 fputs_styled ("<ref to undefined type>", metadata_style
.style (),
1081 deref_val
= coerce_ref_if_computed (original_value
);
1084 if (ada_is_tagged_type (value_type (deref_val
), 1))
1085 deref_val
= ada_tag_value_at_base_address (deref_val
);
1087 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
1088 language_def (language_ada
));
1092 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
1093 if (deref_val_int
== 0)
1095 fputs_filtered ("(null)", stream
);
1100 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
1102 if (ada_is_tagged_type (value_type (deref_val
), 1))
1103 deref_val
= ada_tag_value_at_base_address (deref_val
);
1105 /* Make sure that the object does not have an unreasonable size
1106 before trying to print it. This can happen for instance with
1107 references to dynamic objects whose contents is uninitialized
1108 (Eg: an array whose bounds are not set yet). */
1109 ada_ensure_varsize_limit (value_type (deref_val
));
1111 if (value_lazy (deref_val
))
1112 value_fetch_lazy (deref_val
);
1114 val_print (value_type (deref_val
),
1115 value_embedded_offset (deref_val
),
1116 value_address (deref_val
), stream
, recurse
+ 1,
1117 deref_val
, options
, language_def (language_ada
));
1120 /* See the comment on ada_val_print. This function differs in that it
1121 does not catch evaluation errors (leaving that to ada_val_print). */
1124 ada_val_print_1 (struct type
*type
,
1125 int offset
, CORE_ADDR address
,
1126 struct ui_file
*stream
, int recurse
,
1127 struct value
*original_value
,
1128 const struct value_print_options
*options
)
1131 const gdb_byte
*valaddr
= value_contents_for_printing (original_value
);
1133 type
= ada_check_typedef (type
);
1135 if (ada_is_array_descriptor_type (type
)
1136 || (ada_is_constrained_packed_array_type (type
)
1137 && TYPE_CODE (type
) != TYPE_CODE_PTR
))
1139 ada_val_print_gnat_array (type
, valaddr
, offset
, address
,
1140 stream
, recurse
, original_value
,
1145 offset_aligned
= offset
+ ada_aligned_value_addr (type
, valaddr
) - valaddr
;
1146 type
= printable_val_type (type
, valaddr
+ offset_aligned
);
1147 type
= resolve_dynamic_type (type
, valaddr
+ offset_aligned
,
1148 address
+ offset_aligned
);
1150 switch (TYPE_CODE (type
))
1153 val_print (type
, offset
, address
, stream
, recurse
,
1154 original_value
, options
, language_def (language_c
));
1158 ada_val_print_ptr (type
, valaddr
, offset
, offset_aligned
,
1159 address
, stream
, recurse
, original_value
,
1164 case TYPE_CODE_RANGE
:
1165 ada_val_print_num (type
, valaddr
, offset
, offset_aligned
,
1166 address
, stream
, recurse
, original_value
,
1170 case TYPE_CODE_ENUM
:
1171 ada_val_print_enum (type
, valaddr
, offset
, offset_aligned
,
1172 address
, stream
, recurse
, original_value
,
1177 ada_val_print_flt (type
, valaddr
, offset
, offset_aligned
,
1178 address
, stream
, recurse
, original_value
,
1182 case TYPE_CODE_UNION
:
1183 case TYPE_CODE_STRUCT
:
1184 ada_val_print_struct_union (type
, valaddr
, offset
, offset_aligned
,
1185 address
, stream
, recurse
,
1186 original_value
, options
);
1189 case TYPE_CODE_ARRAY
:
1190 ada_val_print_array (type
, valaddr
, offset
, offset_aligned
,
1191 address
, stream
, recurse
, original_value
,
1196 ada_val_print_ref (type
, valaddr
, offset
, offset_aligned
,
1197 address
, stream
, recurse
, original_value
,
1203 /* See val_print for a description of the various parameters of this
1204 function; they are identical. */
1207 ada_val_print (struct type
*type
,
1208 int embedded_offset
, CORE_ADDR address
,
1209 struct ui_file
*stream
, int recurse
,
1211 const struct value_print_options
*options
)
1215 ada_val_print_1 (type
, embedded_offset
, address
,
1216 stream
, recurse
, val
, options
);
1218 catch (const gdb_exception_error
&except
)
1220 fprintf_styled (stream
, metadata_style
.style (),
1221 _("<error reading variable: %s>"),
1227 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1228 const struct value_print_options
*options
)
1230 struct value
*val
= ada_to_fixed_value (val0
);
1231 CORE_ADDR address
= value_address (val
);
1232 struct type
*type
= ada_check_typedef (value_type (val
));
1233 struct value_print_options opts
;
1235 /* If it is a pointer, indicate what it points to. */
1236 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1238 /* Hack: don't print (char *) for char strings. Their
1239 type is indicated by the quoted string anyway. */
1240 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
1241 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
1242 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
1244 fprintf_filtered (stream
, "(");
1245 type_print (type
, "", stream
, -1);
1246 fprintf_filtered (stream
, ") ");
1249 else if (ada_is_array_descriptor_type (type
))
1251 /* We do not print the type description unless TYPE is an array
1252 access type (this is encoded by the compiler as a typedef to
1253 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1254 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1256 fprintf_filtered (stream
, "(");
1257 type_print (type
, "", stream
, -1);
1258 fprintf_filtered (stream
, ") ");
1261 else if (ada_is_bogus_array_descriptor (type
))
1263 fprintf_filtered (stream
, "(");
1264 type_print (type
, "", stream
, -1);
1265 fprintf_filtered (stream
, ") (...?)");
1272 value_embedded_offset (val
), address
,
1273 stream
, 0, val
, &opts
, current_language
);