1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2017 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"
35 static int print_field_values (struct type
*, const gdb_byte
*,
37 struct ui_file
*, int,
39 const struct value_print_options
*,
40 int, struct type
*, int,
41 const struct language_defn
*);
44 /* Make TYPE unsigned if its range of values includes no negatives. */
46 adjust_type_signedness (struct type
*type
)
48 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
49 && TYPE_LOW_BOUND (type
) >= 0)
50 TYPE_UNSIGNED (type
) = 1;
53 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
54 if non-standard (i.e., other than 1 for numbers, other than lower bound
55 of index type for enumerated type). Returns 1 if something printed,
59 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
60 const struct value_print_options
*options
)
62 struct type
*index_type
;
66 if (options
->print_array_indexes
)
69 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
72 /* If this is an empty array, then don't print the lower bound.
73 That would be confusing, because we would print the lower bound,
74 followed by... nothing! */
75 if (low_bound
> high_bound
)
78 index_type
= TYPE_INDEX_TYPE (type
);
80 while (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
82 /* We need to know what the base type is, in order to do the
83 appropriate check below. Otherwise, if this is a subrange
84 of an enumerated type, where the underlying value of the
85 first element is typically 0, we might test the low bound
86 against the wrong value. */
87 index_type
= TYPE_TARGET_TYPE (index_type
);
90 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
);
142 if (get_discrete_bounds (index_type
, &low
, &high
) < 0)
145 len
= high
- low
+ 1;
149 annotate_array_section_begin (i
, elttype
);
151 while (i
< len
&& things_printed
< options
->print_max
)
153 struct value
*v0
, *v1
;
158 if (options
->prettyformat_arrays
)
160 fprintf_filtered (stream
, ",\n");
161 print_spaces_filtered (2 + 2 * recurse
, stream
);
165 fprintf_filtered (stream
, ", ");
168 wrap_here (n_spaces (2 + 2 * recurse
));
169 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
172 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
173 (i0
* bitsize
) / HOST_CHAR_BIT
,
174 (i0
* bitsize
) % HOST_CHAR_BIT
,
181 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
182 (i
* bitsize
) / HOST_CHAR_BIT
,
183 (i
* bitsize
) % HOST_CHAR_BIT
,
185 if (TYPE_LENGTH (check_typedef (value_type (v0
)))
186 != TYPE_LENGTH (check_typedef (value_type (v1
))))
188 if (!value_contents_eq (v0
, value_embedded_offset (v0
),
189 v1
, value_embedded_offset (v1
),
190 TYPE_LENGTH (check_typedef (value_type (v0
)))))
194 if (i
- i0
> options
->repeat_count_threshold
)
196 struct value_print_options opts
= *options
;
200 value_embedded_offset (v0
), 0, stream
,
201 recurse
+ 1, v0
, &opts
, current_language
);
202 annotate_elt_rep (i
- i0
);
203 fprintf_filtered (stream
, _(" <repeats %u times>"), i
- i0
);
204 annotate_elt_rep_end ();
210 struct value_print_options opts
= *options
;
213 for (j
= i0
; j
< i
; j
+= 1)
217 if (options
->prettyformat_arrays
)
219 fprintf_filtered (stream
, ",\n");
220 print_spaces_filtered (2 + 2 * recurse
, stream
);
224 fprintf_filtered (stream
, ", ");
226 wrap_here (n_spaces (2 + 2 * recurse
));
227 maybe_print_array_index (index_type
, j
+ low
,
231 value_embedded_offset (v0
), 0, stream
,
232 recurse
+ 1, v0
, &opts
, current_language
);
236 things_printed
+= i
- i0
;
238 annotate_array_section_end ();
241 fprintf_filtered (stream
, "...");
244 value_free_to_mark (mark
);
248 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
250 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
253 /* Print the character C on STREAM as part of the contents of a literal
254 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
258 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
259 int quoter
, int type_len
)
261 /* If this character fits in the normal ASCII range, and is
262 a printable character, then print the character as if it was
263 an ASCII character, even if this is a wide character.
264 The UCHAR_MAX check is necessary because the isascii function
265 requires that its argument have a value of an unsigned char,
266 or EOF (EOF is obviously not printable). */
267 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
269 if (c
== quoter
&& c
== '"')
270 fprintf_filtered (stream
, "\"\"");
272 fprintf_filtered (stream
, "%c", c
);
275 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
278 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
282 char_at (const gdb_byte
*string
, int i
, int type_len
,
283 enum bfd_endian byte_order
)
288 return (int) extract_unsigned_integer (string
+ type_len
* i
,
289 type_len
, byte_order
);
292 /* Print a floating-point value of type TYPE, pointed to in GDB by
293 VALADDR, on STREAM. Use Ada formatting conventions: there must be
294 a decimal point, and at least one digit before and after the
295 point. We use the GNAT format for NaNs and infinities. */
298 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
299 struct ui_file
*stream
)
301 string_file tmp_stream
;
303 print_floating (valaddr
, type
, &tmp_stream
);
305 std::string
&s
= tmp_stream
.string ();
306 size_t skip_count
= 0;
308 /* Modify for Ada rules. */
310 size_t pos
= s
.find ("inf");
311 if (pos
== std::string::npos
)
312 pos
= s
.find ("Inf");
313 if (pos
== std::string::npos
)
314 pos
= s
.find ("INF");
315 if (pos
!= std::string::npos
)
316 s
.replace (pos
, 3, "Inf");
318 if (pos
== std::string::npos
)
320 pos
= s
.find ("nan");
321 if (pos
== std::string::npos
)
322 pos
= s
.find ("NaN");
323 if (pos
== std::string::npos
)
324 pos
= s
.find ("Nan");
325 if (pos
!= std::string::npos
)
327 s
[pos
] = s
[pos
+ 2] = 'N';
333 if (pos
== std::string::npos
334 && s
.find ('.') == std::string::npos
)
337 if (pos
== std::string::npos
)
338 fprintf_filtered (stream
, "%s.0", s
.c_str ());
340 fprintf_filtered (stream
, "%.*s.0%s", (int) pos
, s
.c_str (), &s
[pos
]);
343 fprintf_filtered (stream
, "%s", &s
[skip_count
]);
347 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
349 fputs_filtered ("'", stream
);
350 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
351 fputs_filtered ("'", stream
);
354 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
355 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
356 like a default signed integer. */
359 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
366 print_longest (stream
, 'd', 0, val
);
370 type
= ada_check_typedef (type
);
372 switch (TYPE_CODE (type
))
376 len
= TYPE_NFIELDS (type
);
377 for (i
= 0; i
< len
; i
++)
379 if (TYPE_FIELD_ENUMVAL (type
, i
) == val
)
386 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
390 print_longest (stream
, 'd', 0, val
);
395 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
399 LA_PRINT_CHAR (val
, type
, stream
);
403 fprintf_filtered (stream
, val
? "true" : "false");
406 case TYPE_CODE_RANGE
:
407 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
410 case TYPE_CODE_UNDEF
:
412 case TYPE_CODE_ARRAY
:
413 case TYPE_CODE_STRUCT
:
414 case TYPE_CODE_UNION
:
419 case TYPE_CODE_STRING
:
420 case TYPE_CODE_ERROR
:
421 case TYPE_CODE_MEMBERPTR
:
422 case TYPE_CODE_METHODPTR
:
423 case TYPE_CODE_METHOD
:
425 warning (_("internal error: unhandled type in ada_print_scalar"));
429 error (_("Invalid type code in symbol table."));
434 /* Print the character string STRING, printing at most LENGTH characters.
435 Printing stops early if the number hits print_max; repeat counts
436 are printed as appropriate. Print ellipses at the end if we
437 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
438 TYPE_LEN is the length (1 or 2) of the character type. */
441 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
442 unsigned int length
, int force_ellipses
, int type_len
,
443 const struct value_print_options
*options
)
445 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (elttype
));
447 unsigned int things_printed
= 0;
453 fputs_filtered ("\"\"", stream
);
457 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
459 /* Position of the character we are examining
460 to see whether it is repeated. */
462 /* Number of repetitions we have detected so far. */
469 fputs_filtered (", ", stream
);
476 && char_at (string
, rep1
, type_len
, byte_order
)
477 == char_at (string
, i
, type_len
, byte_order
))
483 if (reps
> options
->repeat_count_threshold
)
487 fputs_filtered ("\", ", stream
);
490 fputs_filtered ("'", stream
);
491 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
492 elttype
, stream
, '\'', type_len
);
493 fputs_filtered ("'", stream
);
494 fprintf_filtered (stream
, _(" <repeats %u times>"), reps
);
496 things_printed
+= options
->repeat_count_threshold
;
503 fputs_filtered ("\"", stream
);
506 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
507 elttype
, stream
, '"', type_len
);
512 /* Terminate the quotes if necessary. */
514 fputs_filtered ("\"", stream
);
516 if (force_ellipses
|| i
< length
)
517 fputs_filtered ("...", stream
);
521 ada_printstr (struct ui_file
*stream
, struct type
*type
,
522 const gdb_byte
*string
, unsigned int length
,
523 const char *encoding
, int force_ellipses
,
524 const struct value_print_options
*options
)
526 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
531 print_variant_part (struct type
*type
, int field_num
,
532 const gdb_byte
*valaddr
, int offset
,
533 struct ui_file
*stream
, int recurse
,
535 const struct value_print_options
*options
,
537 struct type
*outer_type
, int outer_offset
,
538 const struct language_defn
*language
)
540 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
541 int which
= ada_which_variant_applies (var_type
, outer_type
,
542 valaddr
+ outer_offset
);
547 return print_field_values
548 (TYPE_FIELD_TYPE (var_type
, which
),
550 offset
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
551 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
552 stream
, recurse
, val
, options
,
553 comma_needed
, outer_type
, outer_offset
, language
);
556 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
558 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
559 meanings as in ada_print_value and ada_val_print.
561 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
562 record (used to get discriminant values when printing variant
565 COMMA_NEEDED is 1 if fields have been printed at the current recursion
566 level, so that a comma is needed before any field printed by this
569 Returns 1 if COMMA_NEEDED or any fields were printed. */
572 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
573 int offset
, struct ui_file
*stream
, int recurse
,
575 const struct value_print_options
*options
,
577 struct type
*outer_type
, int outer_offset
,
578 const struct language_defn
*language
)
582 len
= TYPE_NFIELDS (type
);
584 for (i
= 0; i
< len
; i
+= 1)
586 if (ada_is_ignored_field (type
, i
))
589 if (ada_is_wrapper_field (type
, i
))
592 print_field_values (TYPE_FIELD_TYPE (type
, i
),
595 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
596 stream
, recurse
, val
, options
,
597 comma_needed
, type
, offset
, language
);
600 else if (ada_is_variant_part (type
, i
))
603 print_variant_part (type
, i
, valaddr
,
604 offset
, stream
, recurse
, val
,
605 options
, comma_needed
,
606 outer_type
, outer_offset
, language
);
611 fprintf_filtered (stream
, ", ");
614 if (options
->prettyformat
)
616 fprintf_filtered (stream
, "\n");
617 print_spaces_filtered (2 + 2 * recurse
, stream
);
621 wrap_here (n_spaces (2 + 2 * recurse
));
624 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
625 fprintf_filtered (stream
, "%.*s",
626 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
627 TYPE_FIELD_NAME (type
, i
));
628 annotate_field_name_end ();
629 fputs_filtered (" => ", stream
);
630 annotate_field_value ();
632 if (TYPE_FIELD_PACKED (type
, i
))
634 /* Bitfields require special handling, especially due to byte
636 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
638 fputs_filtered (_("<optimized out or zero length>"), stream
);
643 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
644 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
645 struct value_print_options opts
;
647 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
648 v
= ada_value_primitive_packed_val
650 offset
+ bit_pos
/ HOST_CHAR_BIT
,
651 bit_pos
% HOST_CHAR_BIT
,
652 bit_size
, TYPE_FIELD_TYPE (type
, i
));
655 val_print (TYPE_FIELD_TYPE (type
, i
),
656 value_embedded_offset (v
), 0,
657 stream
, recurse
+ 1, v
,
663 struct value_print_options opts
= *options
;
666 val_print (TYPE_FIELD_TYPE (type
, i
),
667 (offset
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
668 0, stream
, recurse
+ 1, val
, &opts
, language
);
670 annotate_field_end ();
676 /* Implement Ada val_print'ing for the case where TYPE is
677 a TYPE_CODE_ARRAY of characters. */
680 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
681 int offset
, int offset_aligned
, CORE_ADDR address
,
682 struct ui_file
*stream
, int recurse
,
683 struct value
*original_value
,
684 const struct value_print_options
*options
)
686 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (type
));
687 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
691 /* We know that ELTTYPE cannot possibly be null, because we assume
692 that we're called only when TYPE is a string-like type.
693 Similarly, the size of ELTTYPE should also be non-null, since
694 it's a character-like type. */
695 gdb_assert (elttype
!= NULL
);
696 gdb_assert (TYPE_LENGTH (elttype
) != 0);
698 eltlen
= TYPE_LENGTH (elttype
);
699 len
= TYPE_LENGTH (type
) / eltlen
;
701 if (options
->prettyformat_arrays
)
702 print_spaces_filtered (2 + 2 * recurse
, stream
);
704 /* If requested, look for the first null char and only print
705 elements up to it. */
706 if (options
->stop_print_at_null
)
710 /* Look for a NULL char. */
713 && temp_len
< options
->print_max
714 && char_at (valaddr
+ offset_aligned
,
715 temp_len
, eltlen
, byte_order
) != 0);
720 printstr (stream
, elttype
, valaddr
+ offset_aligned
, len
, 0,
724 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
725 thin pointers, etc). */
728 ada_val_print_gnat_array (struct type
*type
, const gdb_byte
*valaddr
,
729 int offset
, CORE_ADDR address
,
730 struct ui_file
*stream
, int recurse
,
731 struct value
*original_value
,
732 const struct value_print_options
*options
,
733 const struct language_defn
*language
)
735 struct value
*mark
= value_mark ();
738 val
= value_from_contents_and_address (type
, valaddr
+ offset
, address
);
739 /* If this is a reference, coerce it now. This helps taking care
740 of the case where ADDRESS is meaningless because original_value
742 val
= coerce_ref (val
);
743 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
744 val
= ada_coerce_to_simple_array_ptr (val
);
746 val
= ada_coerce_to_simple_array (val
);
749 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
750 fprintf_filtered (stream
, "0x0");
753 val_print (value_type (val
),
754 value_embedded_offset (val
), value_address (val
),
755 stream
, recurse
, val
, options
, language
);
756 value_free_to_mark (mark
);
759 /* Implement Ada val_print'ing for the case where TYPE is
763 ada_val_print_ptr (struct type
*type
, const gdb_byte
*valaddr
,
764 int offset
, int offset_aligned
, CORE_ADDR address
,
765 struct ui_file
*stream
, int recurse
,
766 struct value
*original_value
,
767 const struct value_print_options
*options
,
768 const struct language_defn
*language
)
770 val_print (type
, offset
, address
, stream
, recurse
,
771 original_value
, options
, language_def (language_c
));
773 if (ada_is_tag_type (type
))
776 value_from_contents_and_address (type
,
777 valaddr
+ offset_aligned
,
778 address
+ offset_aligned
);
779 const char *name
= ada_tag_name (val
);
782 fprintf_filtered (stream
, " (%s)", name
);
786 /* Implement Ada val_print'ing for the case where TYPE is
787 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
790 ada_val_print_num (struct type
*type
, const gdb_byte
*valaddr
,
791 int offset
, int offset_aligned
, CORE_ADDR address
,
792 struct ui_file
*stream
, int recurse
,
793 struct value
*original_value
,
794 const struct value_print_options
*options
,
795 const struct language_defn
*language
)
797 if (ada_is_fixed_point_type (type
))
799 LONGEST v
= unpack_long (type
, valaddr
+ offset_aligned
);
801 fprintf_filtered (stream
, TYPE_LENGTH (type
) < 4 ? "%.11g" : "%.17g",
802 (double) ada_fixed_to_float (type
, v
));
805 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
807 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
809 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
811 /* Obscure case of range type that has different length from
812 its base type. Perform a conversion, or we will get a
813 nonsense value. Actually, we could use the same
814 code regardless of lengths; I'm just avoiding a cast. */
816 = value_from_contents_and_address (type
, valaddr
+ offset
, 0);
817 struct value
*v
= value_cast (target_type
, v1
);
819 val_print (target_type
,
820 value_embedded_offset (v
), 0, stream
,
821 recurse
+ 1, v
, options
, language
);
824 val_print (TYPE_TARGET_TYPE (type
), offset
,
825 address
, stream
, recurse
, original_value
,
831 int format
= (options
->format
? options
->format
832 : options
->output_format
);
836 struct value_print_options opts
= *options
;
838 opts
.format
= format
;
839 val_print_scalar_formatted (type
, offset_aligned
,
840 original_value
, &opts
, 0, stream
);
842 else if (ada_is_system_address_type (type
))
844 /* FIXME: We want to print System.Address variables using
845 the same format as for any access type. But for some
846 reason GNAT encodes the System.Address type as an int,
847 so we have to work-around this deficiency by handling
848 System.Address values as a special case. */
850 struct gdbarch
*gdbarch
= get_type_arch (type
);
851 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
852 CORE_ADDR addr
= extract_typed_address (valaddr
+ offset_aligned
,
855 fprintf_filtered (stream
, "(");
856 type_print (type
, "", stream
, -1);
857 fprintf_filtered (stream
, ") ");
858 fputs_filtered (paddress (gdbarch
, addr
), stream
);
862 val_print_type_code_int (type
, valaddr
+ offset_aligned
, stream
);
863 if (ada_is_character_type (type
))
867 fputs_filtered (" ", stream
);
868 c
= unpack_long (type
, valaddr
+ offset_aligned
);
869 ada_printchar (c
, type
, stream
);
876 /* Implement Ada val_print'ing for the case where TYPE is
880 ada_val_print_enum (struct type
*type
, const gdb_byte
*valaddr
,
881 int offset
, int offset_aligned
, CORE_ADDR address
,
882 struct ui_file
*stream
, int recurse
,
883 struct value
*original_value
,
884 const struct value_print_options
*options
,
885 const struct language_defn
*language
)
893 val_print_scalar_formatted (type
, offset_aligned
,
894 original_value
, options
, 0, stream
);
898 len
= TYPE_NFIELDS (type
);
899 val
= unpack_long (type
, valaddr
+ offset_aligned
);
900 for (i
= 0; i
< len
; i
++)
903 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
909 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
912 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
914 fputs_filtered (name
, stream
);
917 print_longest (stream
, 'd', 0, val
);
920 /* Implement Ada val_print'ing for the case where TYPE is
924 ada_val_print_flt (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
,
929 const struct language_defn
*language
)
933 val_print (type
, offset
, address
, stream
, recurse
,
934 original_value
, options
, language_def (language_c
));
938 ada_print_floating (valaddr
+ offset
, type
, stream
);
941 /* Implement Ada val_print'ing for the case where TYPE is
942 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
945 ada_val_print_struct_union
946 (struct type
*type
, const gdb_byte
*valaddr
, int offset
,
947 int offset_aligned
, CORE_ADDR address
, struct ui_file
*stream
,
948 int recurse
, struct value
*original_value
,
949 const struct value_print_options
*options
,
950 const struct language_defn
*language
)
952 if (ada_is_bogus_array_descriptor (type
))
954 fprintf_filtered (stream
, "(...?)");
958 fprintf_filtered (stream
, "(");
960 if (print_field_values (type
, valaddr
, offset_aligned
,
961 stream
, recurse
, original_value
, options
,
962 0, type
, offset_aligned
, language
) != 0
963 && options
->prettyformat
)
965 fprintf_filtered (stream
, "\n");
966 print_spaces_filtered (2 * recurse
, stream
);
969 fprintf_filtered (stream
, ")");
972 /* Implement Ada val_print'ing for the case where TYPE is
973 a TYPE_CODE_ARRAY. */
976 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
977 int offset
, int offset_aligned
, CORE_ADDR address
,
978 struct ui_file
*stream
, int recurse
,
979 struct value
*original_value
,
980 const struct value_print_options
*options
)
982 /* For an array of characters, print with string syntax. */
983 if (ada_is_string_type (type
)
984 && (options
->format
== 0 || options
->format
== 's'))
986 ada_val_print_string (type
, valaddr
, offset
, offset_aligned
,
987 address
, stream
, recurse
, original_value
,
992 fprintf_filtered (stream
, "(");
993 print_optional_low_bound (stream
, type
, options
);
994 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
995 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
997 original_value
, options
);
999 val_print_array_elements (type
, offset_aligned
, address
,
1000 stream
, recurse
, original_value
,
1002 fprintf_filtered (stream
, ")");
1005 /* Implement Ada val_print'ing for the case where TYPE is
1009 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
1010 int offset
, int offset_aligned
, CORE_ADDR address
,
1011 struct ui_file
*stream
, int recurse
,
1012 struct value
*original_value
,
1013 const struct value_print_options
*options
,
1014 const struct language_defn
*language
)
1016 /* For references, the debugger is expected to print the value as
1017 an address if DEREF_REF is null. But printing an address in place
1018 of the object value would be confusing to an Ada programmer.
1019 So, for Ada values, we print the actual dereferenced value
1021 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
1022 struct value
*deref_val
;
1023 CORE_ADDR deref_val_int
;
1025 if (TYPE_CODE (elttype
) == TYPE_CODE_UNDEF
)
1027 fputs_filtered ("<ref to undefined type>", stream
);
1031 deref_val
= coerce_ref_if_computed (original_value
);
1034 if (ada_is_tagged_type (value_type (deref_val
), 1))
1035 deref_val
= ada_tag_value_at_base_address (deref_val
);
1037 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
1042 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
1043 if (deref_val_int
== 0)
1045 fputs_filtered ("(null)", stream
);
1050 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
1052 if (ada_is_tagged_type (value_type (deref_val
), 1))
1053 deref_val
= ada_tag_value_at_base_address (deref_val
);
1055 /* Make sure that the object does not have an unreasonable size
1056 before trying to print it. This can happen for instance with
1057 references to dynamic objects whose contents is uninitialized
1058 (Eg: an array whose bounds are not set yet). */
1059 ada_ensure_varsize_limit (value_type (deref_val
));
1061 if (value_lazy (deref_val
))
1062 value_fetch_lazy (deref_val
);
1064 val_print (value_type (deref_val
),
1065 value_embedded_offset (deref_val
),
1066 value_address (deref_val
), stream
, recurse
+ 1,
1067 deref_val
, options
, language
);
1070 /* See the comment on ada_val_print. This function differs in that it
1071 does not catch evaluation errors (leaving that to ada_val_print). */
1074 ada_val_print_1 (struct type
*type
,
1075 int offset
, CORE_ADDR address
,
1076 struct ui_file
*stream
, int recurse
,
1077 struct value
*original_value
,
1078 const struct value_print_options
*options
,
1079 const struct language_defn
*language
)
1082 const gdb_byte
*valaddr
= value_contents_for_printing (original_value
);
1084 type
= ada_check_typedef (type
);
1086 if (ada_is_array_descriptor_type (type
)
1087 || (ada_is_constrained_packed_array_type (type
)
1088 && TYPE_CODE (type
) != TYPE_CODE_PTR
))
1090 ada_val_print_gnat_array (type
, valaddr
, offset
, address
,
1091 stream
, recurse
, original_value
,
1096 offset_aligned
= offset
+ ada_aligned_value_addr (type
, valaddr
) - valaddr
;
1097 type
= printable_val_type (type
, valaddr
+ offset_aligned
);
1098 type
= resolve_dynamic_type (type
, valaddr
+ offset_aligned
,
1099 address
+ offset_aligned
);
1101 switch (TYPE_CODE (type
))
1104 val_print (type
, offset
, address
, stream
, recurse
,
1105 original_value
, options
, language_def (language_c
));
1109 ada_val_print_ptr (type
, valaddr
, offset
, offset_aligned
,
1110 address
, stream
, recurse
, original_value
,
1115 case TYPE_CODE_RANGE
:
1116 ada_val_print_num (type
, valaddr
, offset
, offset_aligned
,
1117 address
, stream
, recurse
, original_value
,
1121 case TYPE_CODE_ENUM
:
1122 ada_val_print_enum (type
, valaddr
, offset
, offset_aligned
,
1123 address
, stream
, recurse
, original_value
,
1128 ada_val_print_flt (type
, valaddr
, offset
, offset_aligned
,
1129 address
, stream
, recurse
, original_value
,
1133 case TYPE_CODE_UNION
:
1134 case TYPE_CODE_STRUCT
:
1135 ada_val_print_struct_union (type
, valaddr
, offset
, offset_aligned
,
1136 address
, stream
, recurse
,
1137 original_value
, options
, language
);
1140 case TYPE_CODE_ARRAY
:
1141 ada_val_print_array (type
, valaddr
, offset
, offset_aligned
,
1142 address
, stream
, recurse
, original_value
,
1147 ada_val_print_ref (type
, valaddr
, offset
, offset_aligned
,
1148 address
, stream
, recurse
, original_value
,
1154 /* See val_print for a description of the various parameters of this
1155 function; they are identical. */
1158 ada_val_print (struct type
*type
,
1159 int embedded_offset
, CORE_ADDR address
,
1160 struct ui_file
*stream
, int recurse
,
1162 const struct value_print_options
*options
)
1165 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */
1168 ada_val_print_1 (type
, embedded_offset
, address
,
1169 stream
, recurse
, val
, options
,
1172 CATCH (except
, RETURN_MASK_ALL
)
1179 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1180 const struct value_print_options
*options
)
1182 struct value
*val
= ada_to_fixed_value (val0
);
1183 CORE_ADDR address
= value_address (val
);
1184 struct type
*type
= ada_check_typedef (value_enclosing_type (val
));
1185 struct value_print_options opts
;
1187 /* If it is a pointer, indicate what it points to. */
1188 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1190 /* Hack: don't print (char *) for char strings. Their
1191 type is indicated by the quoted string anyway. */
1192 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
1193 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
1194 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
1196 fprintf_filtered (stream
, "(");
1197 type_print (type
, "", stream
, -1);
1198 fprintf_filtered (stream
, ") ");
1201 else if (ada_is_array_descriptor_type (type
))
1203 /* We do not print the type description unless TYPE is an array
1204 access type (this is encoded by the compiler as a typedef to
1205 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1206 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1208 fprintf_filtered (stream
, "(");
1209 type_print (type
, "", stream
, -1);
1210 fprintf_filtered (stream
, ") ");
1213 else if (ada_is_bogus_array_descriptor (type
))
1215 fprintf_filtered (stream
, "(");
1216 type_print (type
, "", stream
, -1);
1217 fprintf_filtered (stream
, ") (...?)");
1224 value_embedded_offset (val
), address
,
1225 stream
, 0, val
, &opts
, current_language
);