1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2015 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
,
125 const struct value
*val
,
126 const struct value_print_options
*options
)
129 unsigned int things_printed
= 0;
131 struct type
*elttype
, *index_type
;
133 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
134 struct value
*mark
= value_mark ();
137 elttype
= TYPE_TARGET_TYPE (type
);
138 eltlen
= TYPE_LENGTH (check_typedef (elttype
));
139 index_type
= TYPE_INDEX_TYPE (type
);
144 if (get_discrete_bounds (index_type
, &low
, &high
) < 0)
147 len
= high
- low
+ 1;
151 annotate_array_section_begin (i
, elttype
);
153 while (i
< len
&& things_printed
< options
->print_max
)
155 struct value
*v0
, *v1
;
160 if (options
->prettyformat_arrays
)
162 fprintf_filtered (stream
, ",\n");
163 print_spaces_filtered (2 + 2 * recurse
, stream
);
167 fprintf_filtered (stream
, ", ");
170 wrap_here (n_spaces (2 + 2 * recurse
));
171 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
174 v0
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
175 (i0
* bitsize
) / HOST_CHAR_BIT
,
176 (i0
* bitsize
) % HOST_CHAR_BIT
,
183 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
184 (i
* bitsize
) / HOST_CHAR_BIT
,
185 (i
* bitsize
) % HOST_CHAR_BIT
,
187 if (!value_contents_eq (v0
, value_embedded_offset (v0
),
188 v1
, value_embedded_offset (v1
),
193 if (i
- i0
> options
->repeat_count_threshold
)
195 struct value_print_options opts
= *options
;
198 val_print (elttype
, value_contents_for_printing (v0
),
199 value_embedded_offset (v0
), 0, stream
,
200 recurse
+ 1, v0
, &opts
, current_language
);
201 annotate_elt_rep (i
- i0
);
202 fprintf_filtered (stream
, _(" <repeats %u times>"), i
- i0
);
203 annotate_elt_rep_end ();
209 struct value_print_options opts
= *options
;
212 for (j
= i0
; j
< i
; j
+= 1)
216 if (options
->prettyformat_arrays
)
218 fprintf_filtered (stream
, ",\n");
219 print_spaces_filtered (2 + 2 * recurse
, stream
);
223 fprintf_filtered (stream
, ", ");
225 wrap_here (n_spaces (2 + 2 * recurse
));
226 maybe_print_array_index (index_type
, j
+ low
,
229 val_print (elttype
, value_contents_for_printing (v0
),
230 value_embedded_offset (v0
), 0, stream
,
231 recurse
+ 1, v0
, &opts
, current_language
);
235 things_printed
+= i
- i0
;
237 annotate_array_section_end ();
240 fprintf_filtered (stream
, "...");
243 value_free_to_mark (mark
);
247 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
249 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
252 /* Print the character C on STREAM as part of the contents of a literal
253 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
257 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
258 int quoter
, int type_len
)
260 /* If this character fits in the normal ASCII range, and is
261 a printable character, then print the character as if it was
262 an ASCII character, even if this is a wide character.
263 The UCHAR_MAX check is necessary because the isascii function
264 requires that its argument have a value of an unsigned char,
265 or EOF (EOF is obviously not printable). */
266 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
268 if (c
== quoter
&& c
== '"')
269 fprintf_filtered (stream
, "\"\"");
271 fprintf_filtered (stream
, "%c", c
);
274 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
277 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
281 char_at (const gdb_byte
*string
, int i
, int type_len
,
282 enum bfd_endian byte_order
)
287 return (int) extract_unsigned_integer (string
+ type_len
* i
,
288 type_len
, byte_order
);
291 /* Print a floating-point value of type TYPE, pointed to in GDB by
292 VALADDR, on STREAM. Use Ada formatting conventions: there must be
293 a decimal point, and at least one digit before and after the
294 point. We use the GNAT format for NaNs and infinities. */
297 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
298 struct ui_file
*stream
)
301 struct ui_file
*tmp_stream
= mem_fileopen ();
302 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_stream
);
304 print_floating (valaddr
, type
, tmp_stream
);
305 result
= ui_file_xstrdup (tmp_stream
, NULL
);
306 make_cleanup (xfree
, result
);
308 /* Modify for Ada rules. */
310 s
= strstr (result
, "inf");
312 s
= strstr (result
, "Inf");
314 s
= strstr (result
, "INF");
320 s
= strstr (result
, "nan");
322 s
= strstr (result
, "NaN");
324 s
= strstr (result
, "Nan");
328 if (result
[0] == '-')
333 if (s
== NULL
&& strchr (result
, '.') == NULL
)
335 s
= strchr (result
, 'e');
337 fprintf_filtered (stream
, "%s.0", result
);
339 fprintf_filtered (stream
, "%.*s.0%s", (int) (s
-result
), result
, s
);
342 fprintf_filtered (stream
, "%s", result
);
344 do_cleanups (cleanups
);
348 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
350 fputs_filtered ("'", stream
);
351 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
352 fputs_filtered ("'", stream
);
355 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
356 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
357 like a default signed integer. */
360 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
367 print_longest (stream
, 'd', 0, val
);
371 type
= ada_check_typedef (type
);
373 switch (TYPE_CODE (type
))
377 len
= TYPE_NFIELDS (type
);
378 for (i
= 0; i
< len
; i
++)
380 if (TYPE_FIELD_ENUMVAL (type
, i
) == val
)
387 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
391 print_longest (stream
, 'd', 0, val
);
396 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
400 LA_PRINT_CHAR (val
, type
, stream
);
404 fprintf_filtered (stream
, val
? "true" : "false");
407 case TYPE_CODE_RANGE
:
408 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
411 case TYPE_CODE_UNDEF
:
413 case TYPE_CODE_ARRAY
:
414 case TYPE_CODE_STRUCT
:
415 case TYPE_CODE_UNION
:
420 case TYPE_CODE_STRING
:
421 case TYPE_CODE_ERROR
:
422 case TYPE_CODE_MEMBERPTR
:
423 case TYPE_CODE_METHODPTR
:
424 case TYPE_CODE_METHOD
:
426 warning (_("internal error: unhandled type in ada_print_scalar"));
430 error (_("Invalid type code in symbol table."));
435 /* Print the character string STRING, printing at most LENGTH characters.
436 Printing stops early if the number hits print_max; repeat counts
437 are printed as appropriate. Print ellipses at the end if we
438 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
439 TYPE_LEN is the length (1 or 2) of the character type. */
442 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
443 unsigned int length
, int force_ellipses
, int type_len
,
444 const struct value_print_options
*options
)
446 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (elttype
));
448 unsigned int things_printed
= 0;
454 fputs_filtered ("\"\"", stream
);
458 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
460 /* Position of the character we are examining
461 to see whether it is repeated. */
463 /* Number of repetitions we have detected so far. */
470 fputs_filtered (", ", stream
);
477 && char_at (string
, rep1
, type_len
, byte_order
)
478 == char_at (string
, i
, type_len
, byte_order
))
484 if (reps
> options
->repeat_count_threshold
)
488 fputs_filtered ("\", ", stream
);
491 fputs_filtered ("'", stream
);
492 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
493 elttype
, stream
, '\'', type_len
);
494 fputs_filtered ("'", stream
);
495 fprintf_filtered (stream
, _(" <repeats %u times>"), reps
);
497 things_printed
+= options
->repeat_count_threshold
;
504 fputs_filtered ("\"", stream
);
507 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
508 elttype
, stream
, '"', type_len
);
513 /* Terminate the quotes if necessary. */
515 fputs_filtered ("\"", stream
);
517 if (force_ellipses
|| i
< length
)
518 fputs_filtered ("...", stream
);
522 ada_printstr (struct ui_file
*stream
, struct type
*type
,
523 const gdb_byte
*string
, unsigned int length
,
524 const char *encoding
, int force_ellipses
,
525 const struct value_print_options
*options
)
527 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
532 print_variant_part (struct type
*type
, int field_num
,
533 const gdb_byte
*valaddr
, int offset
,
534 struct ui_file
*stream
, int recurse
,
535 const struct value
*val
,
536 const struct value_print_options
*options
,
538 struct type
*outer_type
, int outer_offset
,
539 const struct language_defn
*language
)
541 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
542 int which
= ada_which_variant_applies (var_type
, outer_type
,
543 valaddr
+ outer_offset
);
548 return print_field_values
549 (TYPE_FIELD_TYPE (var_type
, which
),
551 offset
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
552 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
553 stream
, recurse
, val
, options
,
554 comma_needed
, outer_type
, outer_offset
, language
);
557 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
559 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
560 meanings as in ada_print_value and ada_val_print.
562 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
563 record (used to get discriminant values when printing variant
566 COMMA_NEEDED is 1 if fields have been printed at the current recursion
567 level, so that a comma is needed before any field printed by this
570 Returns 1 if COMMA_NEEDED or any fields were printed. */
573 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
574 int offset
, struct ui_file
*stream
, int recurse
,
575 const struct value
*val
,
576 const struct value_print_options
*options
,
578 struct type
*outer_type
, int outer_offset
,
579 const struct language_defn
*language
)
583 len
= TYPE_NFIELDS (type
);
585 for (i
= 0; i
< len
; i
+= 1)
587 if (ada_is_ignored_field (type
, i
))
590 if (ada_is_wrapper_field (type
, i
))
593 print_field_values (TYPE_FIELD_TYPE (type
, i
),
596 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
597 stream
, recurse
, val
, options
,
598 comma_needed
, type
, offset
, language
);
601 else if (ada_is_variant_part (type
, i
))
604 print_variant_part (type
, i
, valaddr
,
605 offset
, stream
, recurse
, val
,
606 options
, comma_needed
,
607 outer_type
, outer_offset
, language
);
612 fprintf_filtered (stream
, ", ");
615 if (options
->prettyformat
)
617 fprintf_filtered (stream
, "\n");
618 print_spaces_filtered (2 + 2 * recurse
, stream
);
622 wrap_here (n_spaces (2 + 2 * recurse
));
625 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
626 fprintf_filtered (stream
, "%.*s",
627 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
628 TYPE_FIELD_NAME (type
, i
));
629 annotate_field_name_end ();
630 fputs_filtered (" => ", stream
);
631 annotate_field_value ();
633 if (TYPE_FIELD_PACKED (type
, i
))
637 /* Bitfields require special handling, especially due to byte
639 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
641 fputs_filtered (_("<optimized out or zero length>"), stream
);
645 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
646 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
647 struct value_print_options opts
;
649 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
650 v
= ada_value_primitive_packed_val
652 offset
+ bit_pos
/ HOST_CHAR_BIT
,
653 bit_pos
% HOST_CHAR_BIT
,
654 bit_size
, TYPE_FIELD_TYPE (type
, i
));
657 val_print (TYPE_FIELD_TYPE (type
, i
),
658 value_contents_for_printing (v
),
659 value_embedded_offset (v
), 0,
660 stream
, recurse
+ 1, v
,
666 struct value_print_options opts
= *options
;
669 val_print (TYPE_FIELD_TYPE (type
, i
), valaddr
,
670 (offset
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
671 0, stream
, recurse
+ 1, val
, &opts
, language
);
673 annotate_field_end ();
679 /* Implement Ada val_print'ing for the case where TYPE is
680 a TYPE_CODE_ARRAY of characters. */
683 ada_val_print_string (struct type
*type
, const gdb_byte
*valaddr
,
684 int offset
, int offset_aligned
, CORE_ADDR address
,
685 struct ui_file
*stream
, int recurse
,
686 const struct value
*original_value
,
687 const struct value_print_options
*options
)
689 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (type
));
690 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
694 /* We know that ELTTYPE cannot possibly be null, because we assume
695 that we're called only when TYPE is a string-like type.
696 Similarly, the size of ELTTYPE should also be non-null, since
697 it's a character-like type. */
698 gdb_assert (elttype
!= NULL
);
699 gdb_assert (TYPE_LENGTH (elttype
) != 0);
701 eltlen
= TYPE_LENGTH (elttype
);
702 len
= TYPE_LENGTH (type
) / eltlen
;
704 if (options
->prettyformat_arrays
)
705 print_spaces_filtered (2 + 2 * recurse
, stream
);
707 /* If requested, look for the first null char and only print
708 elements up to it. */
709 if (options
->stop_print_at_null
)
713 /* Look for a NULL char. */
716 && temp_len
< options
->print_max
717 && char_at (valaddr
+ offset_aligned
,
718 temp_len
, eltlen
, byte_order
) != 0);
723 printstr (stream
, elttype
, valaddr
+ offset_aligned
, len
, 0,
727 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
728 thin pointers, etc). */
731 ada_val_print_gnat_array (struct type
*type
, const gdb_byte
*valaddr
,
732 int offset
, CORE_ADDR address
,
733 struct ui_file
*stream
, int recurse
,
734 const struct value
*original_value
,
735 const struct value_print_options
*options
,
736 const struct language_defn
*language
)
738 struct value
*mark
= value_mark ();
741 val
= value_from_contents_and_address (type
, valaddr
+ offset
, address
);
742 /* If this is a reference, coerce it now. This helps taking care
743 of the case where ADDRESS is meaningless because original_value
745 val
= coerce_ref (val
);
746 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
747 val
= ada_coerce_to_simple_array_ptr (val
);
749 val
= ada_coerce_to_simple_array (val
);
752 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
753 fprintf_filtered (stream
, "0x0");
756 val_print (value_type (val
), value_contents_for_printing (val
),
757 value_embedded_offset (val
), value_address (val
),
758 stream
, recurse
, val
, options
, language
);
759 value_free_to_mark (mark
);
762 /* Implement Ada val_print'ing for the case where TYPE is
766 ada_val_print_ptr (struct type
*type
, const gdb_byte
*valaddr
,
767 int offset
, int offset_aligned
, CORE_ADDR address
,
768 struct ui_file
*stream
, int recurse
,
769 const struct value
*original_value
,
770 const struct value_print_options
*options
,
771 const struct language_defn
*language
)
773 val_print (type
, valaddr
, offset
, address
, stream
, recurse
,
774 original_value
, options
, language_def (language_c
));
776 if (ada_is_tag_type (type
))
779 value_from_contents_and_address (type
,
780 valaddr
+ offset_aligned
,
781 address
+ offset_aligned
);
782 const char *name
= ada_tag_name (val
);
785 fprintf_filtered (stream
, " (%s)", name
);
789 /* Implement Ada val_print'ing for the case where TYPE is
790 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
793 ada_val_print_num (struct type
*type
, const gdb_byte
*valaddr
,
794 int offset
, int offset_aligned
, CORE_ADDR address
,
795 struct ui_file
*stream
, int recurse
,
796 const struct value
*original_value
,
797 const struct value_print_options
*options
,
798 const struct language_defn
*language
)
800 if (ada_is_fixed_point_type (type
))
802 LONGEST v
= unpack_long (type
, valaddr
+ offset_aligned
);
804 fprintf_filtered (stream
, TYPE_LENGTH (type
) < 4 ? "%.11g" : "%.17g",
805 (double) ada_fixed_to_float (type
, v
));
808 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
810 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
812 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
814 /* Obscure case of range type that has different length from
815 its base type. Perform a conversion, or we will get a
816 nonsense value. Actually, we could use the same
817 code regardless of lengths; I'm just avoiding a cast. */
819 = value_from_contents_and_address (type
, valaddr
+ offset
, 0);
820 struct value
*v
= value_cast (target_type
, v1
);
822 val_print (target_type
, value_contents_for_printing (v
),
823 value_embedded_offset (v
), 0, stream
,
824 recurse
+ 1, v
, options
, language
);
827 val_print (TYPE_TARGET_TYPE (type
), valaddr
, offset
,
828 address
, stream
, recurse
, original_value
,
834 int format
= (options
->format
? options
->format
835 : options
->output_format
);
839 struct value_print_options opts
= *options
;
841 opts
.format
= format
;
842 val_print_scalar_formatted (type
, valaddr
, offset_aligned
,
843 original_value
, &opts
, 0, stream
);
845 else if (ada_is_system_address_type (type
))
847 /* FIXME: We want to print System.Address variables using
848 the same format as for any access type. But for some
849 reason GNAT encodes the System.Address type as an int,
850 so we have to work-around this deficiency by handling
851 System.Address values as a special case. */
853 struct gdbarch
*gdbarch
= get_type_arch (type
);
854 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
855 CORE_ADDR addr
= extract_typed_address (valaddr
+ offset_aligned
,
858 fprintf_filtered (stream
, "(");
859 type_print (type
, "", stream
, -1);
860 fprintf_filtered (stream
, ") ");
861 fputs_filtered (paddress (gdbarch
, addr
), stream
);
865 val_print_type_code_int (type
, valaddr
+ offset_aligned
, stream
);
866 if (ada_is_character_type (type
))
870 fputs_filtered (" ", stream
);
871 c
= unpack_long (type
, valaddr
+ offset_aligned
);
872 ada_printchar (c
, type
, stream
);
879 /* Implement Ada val_print'ing for the case where TYPE is
883 ada_val_print_enum (struct type
*type
, const gdb_byte
*valaddr
,
884 int offset
, int offset_aligned
, CORE_ADDR address
,
885 struct ui_file
*stream
, int recurse
,
886 const struct value
*original_value
,
887 const struct value_print_options
*options
,
888 const struct language_defn
*language
)
896 val_print_scalar_formatted (type
, valaddr
, offset_aligned
,
897 original_value
, options
, 0, stream
);
901 len
= TYPE_NFIELDS (type
);
902 val
= unpack_long (type
, valaddr
+ offset_aligned
);
903 for (i
= 0; i
< len
; i
++)
906 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
912 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
915 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
917 fputs_filtered (name
, stream
);
920 print_longest (stream
, 'd', 0, val
);
923 /* Implement Ada val_print'ing for the case where TYPE is
927 ada_val_print_flt (struct type
*type
, const gdb_byte
*valaddr
,
928 int offset
, int offset_aligned
, CORE_ADDR address
,
929 struct ui_file
*stream
, int recurse
,
930 const struct value
*original_value
,
931 const struct value_print_options
*options
,
932 const struct language_defn
*language
)
936 val_print (type
, valaddr
, offset
, address
, stream
, recurse
,
937 original_value
, options
, language_def (language_c
));
941 ada_print_floating (valaddr
+ offset
, type
, stream
);
944 /* Implement Ada val_print'ing for the case where TYPE is
945 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
948 ada_val_print_struct_union
949 (struct type
*type
, const gdb_byte
*valaddr
, int offset
,
950 int offset_aligned
, CORE_ADDR address
, struct ui_file
*stream
,
951 int recurse
, const struct value
*original_value
,
952 const struct value_print_options
*options
,
953 const struct language_defn
*language
)
955 if (ada_is_bogus_array_descriptor (type
))
957 fprintf_filtered (stream
, "(...?)");
961 fprintf_filtered (stream
, "(");
963 if (print_field_values (type
, valaddr
, offset_aligned
,
964 stream
, recurse
, original_value
, options
,
965 0, type
, offset_aligned
, language
) != 0
966 && options
->prettyformat
)
968 fprintf_filtered (stream
, "\n");
969 print_spaces_filtered (2 * recurse
, stream
);
972 fprintf_filtered (stream
, ")");
975 /* Implement Ada val_print'ing for the case where TYPE is
976 a TYPE_CODE_ARRAY. */
979 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
980 int offset
, int offset_aligned
, CORE_ADDR address
,
981 struct ui_file
*stream
, int recurse
,
982 const struct value
*original_value
,
983 const struct value_print_options
*options
)
985 /* For an array of characters, print with string syntax. */
986 if (ada_is_string_type (type
)
987 && (options
->format
== 0 || options
->format
== 's'))
989 ada_val_print_string (type
, valaddr
, offset
, offset_aligned
,
990 address
, stream
, recurse
, original_value
,
995 fprintf_filtered (stream
, "(");
996 print_optional_low_bound (stream
, type
, options
);
997 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
998 val_print_packed_array_elements (type
, valaddr
, offset_aligned
,
1000 original_value
, options
);
1002 val_print_array_elements (type
, valaddr
, offset_aligned
, address
,
1003 stream
, recurse
, original_value
,
1005 fprintf_filtered (stream
, ")");
1008 /* Implement Ada val_print'ing for the case where TYPE is
1012 ada_val_print_ref (struct type
*type
, const gdb_byte
*valaddr
,
1013 int offset
, int offset_aligned
, CORE_ADDR address
,
1014 struct ui_file
*stream
, int recurse
,
1015 const struct value
*original_value
,
1016 const struct value_print_options
*options
,
1017 const struct language_defn
*language
)
1019 /* For references, the debugger is expected to print the value as
1020 an address if DEREF_REF is null. But printing an address in place
1021 of the object value would be confusing to an Ada programmer.
1022 So, for Ada values, we print the actual dereferenced value
1024 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
1025 struct value
*deref_val
;
1026 CORE_ADDR deref_val_int
;
1028 if (TYPE_CODE (elttype
) == TYPE_CODE_UNDEF
)
1030 fputs_filtered ("<ref to undefined type>", stream
);
1034 deref_val
= coerce_ref_if_computed (original_value
);
1037 if (ada_is_tagged_type (value_type (deref_val
), 1))
1038 deref_val
= ada_tag_value_at_base_address (deref_val
);
1040 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
1045 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
1046 if (deref_val_int
== 0)
1048 fputs_filtered ("(null)", stream
);
1053 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype
),
1055 if (ada_is_tagged_type (value_type (deref_val
), 1))
1056 deref_val
= ada_tag_value_at_base_address (deref_val
);
1058 /* Make sure that the object does not have an unreasonable size
1059 before trying to print it. This can happen for instance with
1060 references to dynamic objects whose contents is uninitialized
1061 (Eg: an array whose bounds are not set yet). */
1062 ada_ensure_varsize_limit (value_type (deref_val
));
1064 val_print (value_type (deref_val
),
1065 value_contents_for_printing (deref_val
),
1066 value_embedded_offset (deref_val
),
1067 value_address (deref_val
), stream
, recurse
+ 1,
1068 deref_val
, options
, language
);
1071 /* See the comment on ada_val_print. This function differs in that it
1072 does not catch evaluation errors (leaving that to ada_val_print). */
1075 ada_val_print_1 (struct type
*type
, const gdb_byte
*valaddr
,
1076 int offset
, CORE_ADDR address
,
1077 struct ui_file
*stream
, int recurse
,
1078 const struct value
*original_value
,
1079 const struct value_print_options
*options
,
1080 const struct language_defn
*language
)
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
);
1099 switch (TYPE_CODE (type
))
1102 val_print (type
, valaddr
, offset
, address
, stream
, recurse
,
1103 original_value
, options
, language_def (language_c
));
1107 ada_val_print_ptr (type
, valaddr
, offset
, offset_aligned
,
1108 address
, stream
, recurse
, original_value
,
1113 case TYPE_CODE_RANGE
:
1114 ada_val_print_num (type
, valaddr
, offset
, offset_aligned
,
1115 address
, stream
, recurse
, original_value
,
1119 case TYPE_CODE_ENUM
:
1120 ada_val_print_enum (type
, valaddr
, offset
, offset_aligned
,
1121 address
, stream
, recurse
, original_value
,
1126 ada_val_print_flt (type
, valaddr
, offset
, offset_aligned
,
1127 address
, stream
, recurse
, original_value
,
1131 case TYPE_CODE_UNION
:
1132 case TYPE_CODE_STRUCT
:
1133 ada_val_print_struct_union (type
, valaddr
, offset
, offset_aligned
,
1134 address
, stream
, recurse
,
1135 original_value
, options
, language
);
1138 case TYPE_CODE_ARRAY
:
1139 ada_val_print_array (type
, valaddr
, offset
, offset_aligned
,
1140 address
, stream
, recurse
, original_value
,
1145 ada_val_print_ref (type
, valaddr
, offset
, offset_aligned
,
1146 address
, stream
, recurse
, original_value
,
1152 /* See val_print for a description of the various parameters of this
1153 function; they are identical. */
1156 ada_val_print (struct type
*type
, const gdb_byte
*valaddr
,
1157 int embedded_offset
, CORE_ADDR address
,
1158 struct ui_file
*stream
, int recurse
,
1159 const struct value
*val
,
1160 const struct value_print_options
*options
)
1163 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */
1166 ada_val_print_1 (type
, valaddr
, embedded_offset
, address
,
1167 stream
, recurse
, val
, options
,
1170 CATCH (except
, RETURN_MASK_ALL
)
1177 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
1178 const struct value_print_options
*options
)
1180 struct value
*val
= ada_to_fixed_value (val0
);
1181 CORE_ADDR address
= value_address (val
);
1182 struct type
*type
= ada_check_typedef (value_enclosing_type (val
));
1183 struct value_print_options opts
;
1185 /* If it is a pointer, indicate what it points to. */
1186 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1188 /* Hack: don't print (char *) for char strings. Their
1189 type is indicated by the quoted string anyway. */
1190 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
1191 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
1192 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
1194 fprintf_filtered (stream
, "(");
1195 type_print (type
, "", stream
, -1);
1196 fprintf_filtered (stream
, ") ");
1199 else if (ada_is_array_descriptor_type (type
))
1201 /* We do not print the type description unless TYPE is an array
1202 access type (this is encoded by the compiler as a typedef to
1203 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1204 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1206 fprintf_filtered (stream
, "(");
1207 type_print (type
, "", stream
, -1);
1208 fprintf_filtered (stream
, ") ");
1211 else if (ada_is_bogus_array_descriptor (type
))
1213 fprintf_filtered (stream
, "(");
1214 type_print (type
, "", stream
, -1);
1215 fprintf_filtered (stream
, ") (...?)");
1221 val_print (type
, value_contents_for_printing (val
),
1222 value_embedded_offset (val
), address
,
1223 stream
, 0, val
, &opts
, current_language
);