1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_string.h"
26 #include "expression.h"
35 #include "exceptions.h"
37 /* Encapsulates arguments to ada_val_print. */
38 struct ada_val_print_args
41 const gdb_byte
*valaddr0
;
44 struct ui_file
*stream
;
48 enum val_prettyprint pretty
;
51 static void print_record (struct type
*, const gdb_byte
*, struct ui_file
*,
52 int, int, enum val_prettyprint
);
54 static int print_field_values (struct type
*, const gdb_byte
*,
55 struct ui_file
*, int, int,
56 enum val_prettyprint
, int, struct type
*,
59 static void adjust_type_signedness (struct type
*);
61 static int ada_val_print_stub (void *args0
);
63 static int ada_val_print_1 (struct type
*, const gdb_byte
*, int, CORE_ADDR
,
64 struct ui_file
*, int, int, int,
65 enum val_prettyprint
);
68 /* Make TYPE unsigned if its range of values includes no negatives. */
70 adjust_type_signedness (struct type
*type
)
72 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
73 && TYPE_LOW_BOUND (type
) >= 0)
74 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
77 /* Assuming TYPE is a simple, non-empty array type, prints its lower bound
78 on STREAM, if non-standard (i.e., other than 1 for numbers, other
79 than lower bound of index type for enumerated type). Returns 1
80 if something printed, otherwise 0. */
83 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
)
85 struct type
*index_type
;
88 if (print_array_indexes_p ())
91 if (!get_array_low_bound (type
, &low_bound
))
94 index_type
= TYPE_INDEX_TYPE (type
);
96 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
98 /* We need to know what the base type is, in order to do the
99 appropriate check below. Otherwise, if this is a subrange
100 of an enumerated type, where the underlying value of the
101 first element is typically 0, we might test the low bound
102 against the wrong value. */
103 index_type
= TYPE_TARGET_TYPE (index_type
);
106 switch (TYPE_CODE (index_type
))
109 if (low_bound
== TYPE_FIELD_BITPOS (index_type
, 0))
112 case TYPE_CODE_UNDEF
:
113 index_type
= builtin_type_long
;
121 ada_print_scalar (index_type
, (LONGEST
) low_bound
, stream
);
122 fprintf_filtered (stream
, " => ");
126 /* Version of val_print_array_elements for GNAT-style packed arrays.
127 Prints elements of packed array of type TYPE at bit offset
128 BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and
129 separates with commas. RECURSE is the recursion (nesting) level.
130 If PRETTY, uses "prettier" format. TYPE must have been decoded (as
131 by ada_coerce_to_simple_array). */
134 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
135 int bitoffset
, struct ui_file
*stream
,
136 int format
, int recurse
,
137 enum val_prettyprint pretty
)
140 unsigned int things_printed
= 0;
142 struct type
*elttype
, *index_type
;
144 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
145 struct value
*mark
= value_mark ();
148 elttype
= TYPE_TARGET_TYPE (type
);
149 eltlen
= TYPE_LENGTH (check_typedef (elttype
));
150 index_type
= TYPE_INDEX_TYPE (type
);
154 if (get_discrete_bounds (TYPE_FIELD_TYPE (type
, 0), &low
, &high
) < 0)
157 len
= high
- low
+ 1;
161 annotate_array_section_begin (i
, elttype
);
163 while (i
< len
&& things_printed
< print_max
)
165 struct value
*v0
, *v1
;
170 if (prettyprint_arrays
)
172 fprintf_filtered (stream
, ",\n");
173 print_spaces_filtered (2 + 2 * recurse
, stream
);
177 fprintf_filtered (stream
, ", ");
180 wrap_here (n_spaces (2 + 2 * recurse
));
181 maybe_print_array_index (index_type
, i
+ low
, stream
, format
, pretty
);
184 v0
= ada_value_primitive_packed_val (NULL
, valaddr
,
185 (i0
* bitsize
) / HOST_CHAR_BIT
,
186 (i0
* bitsize
) % HOST_CHAR_BIT
,
193 v1
= ada_value_primitive_packed_val (NULL
, valaddr
,
194 (i
* bitsize
) / HOST_CHAR_BIT
,
195 (i
* bitsize
) % HOST_CHAR_BIT
,
197 if (memcmp (value_contents (v0
), value_contents (v1
), eltlen
) != 0)
201 if (i
- i0
> repeat_count_threshold
)
203 val_print (elttype
, value_contents (v0
), 0, 0, stream
, format
,
204 0, recurse
+ 1, pretty
);
205 annotate_elt_rep (i
- i0
);
206 fprintf_filtered (stream
, _(" <repeats %u times>"), i
- i0
);
207 annotate_elt_rep_end ();
213 for (j
= i0
; j
< i
; j
+= 1)
217 if (prettyprint_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
,
228 stream
, format
, pretty
);
230 val_print (elttype
, value_contents (v0
), 0, 0, stream
, format
,
231 0, recurse
+ 1, pretty
);
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
);
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
254 (1 or 2) of the character. */
257 ada_emit_char (int c
, struct ui_file
*stream
, int quoter
, int type_len
)
262 c
&= (1 << (type_len
* TARGET_CHAR_BIT
)) - 1;
264 if (isascii (c
) && isprint (c
))
266 if (c
== quoter
&& c
== '"')
267 fprintf_filtered (stream
, "\"\"");
269 fprintf_filtered (stream
, "%c", c
);
272 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
275 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
276 or 2) of a character. */
279 char_at (const gdb_byte
*string
, int i
, int type_len
)
284 return (int) extract_unsigned_integer (string
+ 2 * i
, 2);
287 /* Wrapper around memcpy to make it legal argument to ui_file_put */
289 ui_memcpy (void *dest
, const char *buffer
, long len
)
291 memcpy (dest
, buffer
, (size_t) len
);
292 ((char *) dest
)[len
] = '\0';
295 /* Print a floating-point value of type TYPE, pointed to in GDB by
296 VALADDR, on STREAM. Use Ada formatting conventions: there must be
297 a decimal point, and at least one digit before and after the
298 point. We use GNAT format for NaNs and infinities. */
300 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
301 struct ui_file
*stream
)
306 struct ui_file
*tmp_stream
= mem_fileopen ();
307 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_stream
);
309 print_floating (valaddr
, type
, tmp_stream
);
310 ui_file_put (tmp_stream
, ui_memcpy
, buffer
);
311 do_cleanups (cleanups
);
314 len
= strlen (result
);
316 /* Modify for Ada rules. */
318 s
= strstr (result
, "inf");
320 s
= strstr (result
, "Inf");
322 s
= strstr (result
, "INF");
328 s
= strstr (result
, "nan");
330 s
= strstr (result
, "NaN");
332 s
= strstr (result
, "Nan");
336 if (result
[0] == '-')
341 if (s
== NULL
&& strchr (result
, '.') == NULL
)
343 s
= strchr (result
, 'e');
345 fprintf_filtered (stream
, "%s.0", result
);
347 fprintf_filtered (stream
, "%.*s.0%s", (int) (s
-result
), result
, s
);
350 fprintf_filtered (stream
, "%s", result
);
354 ada_printchar (int c
, struct ui_file
*stream
)
356 fputs_filtered ("'", stream
);
357 ada_emit_char (c
, stream
, '\'', 1);
358 fputs_filtered ("'", stream
);
361 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
362 form appropriate for TYPE. */
365 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
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_BITPOS (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 ((unsigned char) val
, 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
438 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
442 printstr (struct ui_file
*stream
, const gdb_byte
*string
,
443 unsigned int length
, int force_ellipses
, int type_len
)
446 unsigned int things_printed
= 0;
452 fputs_filtered ("\"\"", stream
);
456 for (i
= 0; i
< length
&& things_printed
< print_max
; i
+= 1)
458 /* Position of the character we are examining
459 to see whether it is repeated. */
461 /* Number of repetitions we have detected so far. */
468 fputs_filtered (", ", stream
);
475 && char_at (string
, rep1
, type_len
) == char_at (string
, i
,
482 if (reps
> repeat_count_threshold
)
487 fputs_filtered ("\\\", ", stream
);
489 fputs_filtered ("\", ", stream
);
492 fputs_filtered ("'", stream
);
493 ada_emit_char (char_at (string
, i
, type_len
), stream
, '\'',
495 fputs_filtered ("'", stream
);
496 fprintf_filtered (stream
, _(" <repeats %u times>"), reps
);
498 things_printed
+= repeat_count_threshold
;
506 fputs_filtered ("\\\"", stream
);
508 fputs_filtered ("\"", stream
);
511 ada_emit_char (char_at (string
, i
, type_len
), stream
, '"',
517 /* Terminate the quotes if necessary. */
521 fputs_filtered ("\\\"", stream
);
523 fputs_filtered ("\"", stream
);
526 if (force_ellipses
|| i
< length
)
527 fputs_filtered ("...", stream
);
531 ada_printstr (struct ui_file
*stream
, const gdb_byte
*string
,
532 unsigned int length
, int width
, int force_ellipses
)
534 printstr (stream
, string
, length
, force_ellipses
, width
);
538 /* Print data of type TYPE located at VALADDR (within GDB), which came from
539 the inferior at address ADDRESS, onto stdio stream STREAM according to
540 FORMAT (a letter as for the printf % codes or 0 for natural format).
541 The data at VALADDR is in target byte order.
543 If the data is printed as a string, returns the number of string characters
546 If DEREF_REF is nonzero, then dereference references, otherwise just print
549 RECURSE indicates the amount of indentation to supply before
550 continuation lines; this amount is roughly twice the value of RECURSE.
552 When PRETTY is non-zero, prints record fields on separate lines.
553 (For some reason, the current version of gdb instead uses a global
554 variable---prettyprint_arrays--- to causes a similar effect on
558 ada_val_print (struct type
*type
, const gdb_byte
*valaddr0
,
559 int embedded_offset
, CORE_ADDR address
,
560 struct ui_file
*stream
, int format
, int deref_ref
,
561 int recurse
, enum val_prettyprint pretty
)
563 struct ada_val_print_args args
;
565 args
.valaddr0
= valaddr0
;
566 args
.embedded_offset
= embedded_offset
;
567 args
.address
= address
;
568 args
.stream
= stream
;
569 args
.format
= format
;
570 args
.deref_ref
= deref_ref
;
571 args
.recurse
= recurse
;
572 args
.pretty
= pretty
;
574 return catch_errors (ada_val_print_stub
, &args
, NULL
, RETURN_MASK_ALL
);
577 /* Helper for ada_val_print; used as argument to catch_errors to
578 unmarshal the arguments to ada_val_print_1, which does the work. */
580 ada_val_print_stub (void *args0
)
582 struct ada_val_print_args
*argsp
= (struct ada_val_print_args
*) args0
;
583 return ada_val_print_1 (argsp
->type
, argsp
->valaddr0
,
584 argsp
->embedded_offset
, argsp
->address
,
585 argsp
->stream
, argsp
->format
, argsp
->deref_ref
,
586 argsp
->recurse
, argsp
->pretty
);
589 /* See the comment on ada_val_print. This function differs in that it
590 * does not catch evaluation errors (leaving that to ada_val_print). */
593 ada_val_print_1 (struct type
*type
, const gdb_byte
*valaddr0
,
594 int embedded_offset
, CORE_ADDR address
,
595 struct ui_file
*stream
, int format
,
596 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
600 struct type
*elttype
;
603 const gdb_byte
*valaddr
= valaddr0
+ embedded_offset
;
605 type
= ada_check_typedef (type
);
607 if (ada_is_array_descriptor_type (type
) || ada_is_packed_array_type (type
))
610 struct value
*mark
= value_mark ();
612 val
= value_from_contents_and_address (type
, valaddr
, address
);
613 val
= ada_coerce_to_simple_array_ptr (val
);
616 fprintf_filtered (stream
, "(null)");
620 retn
= ada_val_print_1 (value_type (val
), value_contents (val
), 0,
621 VALUE_ADDRESS (val
), stream
, format
,
622 deref_ref
, recurse
, pretty
);
623 value_free_to_mark (mark
);
627 valaddr
= ada_aligned_value_addr (type
, valaddr
);
628 embedded_offset
-= valaddr
- valaddr0
- embedded_offset
;
629 type
= printable_val_type (type
, valaddr
);
631 switch (TYPE_CODE (type
))
634 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
635 format
, deref_ref
, recurse
, pretty
);
639 int ret
= c_val_print (type
, valaddr0
, embedded_offset
, address
,
640 stream
, format
, deref_ref
, recurse
, pretty
);
641 if (ada_is_tag_type (type
))
644 value_from_contents_and_address (type
, valaddr
, address
);
645 const char *name
= ada_tag_name (val
);
647 fprintf_filtered (stream
, " (%s)", name
);
654 case TYPE_CODE_RANGE
:
655 if (ada_is_fixed_point_type (type
))
657 LONGEST v
= unpack_long (type
, valaddr
);
658 int len
= TYPE_LENGTH (type
);
660 fprintf_filtered (stream
, len
< 4 ? "%.11g" : "%.17g",
661 (double) ada_fixed_to_float (type
, v
));
664 else if (ada_is_vax_floating_type (type
))
667 value_from_contents_and_address (type
, valaddr
, address
);
668 struct value
*func
= ada_vax_float_print_function (type
);
671 static struct type
*parray_of_char
= NULL
;
672 struct value
*printable_val
;
674 if (parray_of_char
== NULL
)
678 (NULL
, builtin_type_char
,
679 create_range_type (NULL
, builtin_type_int
, 0, 32)), NULL
);
682 value_ind (value_cast (parray_of_char
,
683 call_function_by_hand (func
, 1,
686 fprintf_filtered (stream
, "%s", value_contents (printable_val
));
689 /* No special printing function. Do as best we can. */
691 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
693 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
694 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
696 /* Obscure case of range type that has different length from
697 its base type. Perform a conversion, or we will get a
698 nonsense value. Actually, we could use the same
699 code regardless of lengths; I'm just avoiding a cast. */
700 struct value
*v
= value_cast (target_type
,
701 value_from_contents_and_address
703 return ada_val_print_1 (target_type
, value_contents (v
), 0, 0,
704 stream
, format
, 0, recurse
+ 1, pretty
);
707 return ada_val_print_1 (TYPE_TARGET_TYPE (type
),
708 valaddr0
, embedded_offset
,
709 address
, stream
, format
, deref_ref
,
714 format
= format
? format
: output_format
;
717 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
719 else if (ada_is_system_address_type (type
))
721 /* FIXME: We want to print System.Address variables using
722 the same format as for any access type. But for some
723 reason GNAT encodes the System.Address type as an int,
724 so we have to work-around this deficiency by handling
725 System.Address values as a special case. */
726 fprintf_filtered (stream
, "(");
727 type_print (type
, "", stream
, -1);
728 fprintf_filtered (stream
, ") ");
729 deprecated_print_address_numeric
730 (extract_typed_address (valaddr
, builtin_type_void_data_ptr
),
735 val_print_type_code_int (type
, valaddr
, stream
);
736 if (ada_is_character_type (type
))
738 fputs_filtered (" ", stream
);
739 ada_printchar ((unsigned char) unpack_long (type
, valaddr
),
749 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
752 len
= TYPE_NFIELDS (type
);
753 val
= unpack_long (type
, valaddr
);
754 for (i
= 0; i
< len
; i
++)
757 if (val
== TYPE_FIELD_BITPOS (type
, i
))
764 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
766 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
768 fputs_filtered (name
, stream
);
772 print_longest (stream
, 'd', 0, val
);
776 case TYPE_CODE_FLAGS
:
778 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
780 val_print_type_code_flags (type
, valaddr
, stream
);
785 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
786 format
, deref_ref
, recurse
, pretty
);
788 ada_print_floating (valaddr0
+ embedded_offset
, type
, stream
);
791 case TYPE_CODE_UNION
:
792 case TYPE_CODE_STRUCT
:
793 if (ada_is_bogus_array_descriptor (type
))
795 fprintf_filtered (stream
, "(...?)");
800 print_record (type
, valaddr
, stream
, format
, recurse
, pretty
);
804 case TYPE_CODE_ARRAY
:
805 elttype
= TYPE_TARGET_TYPE (type
);
809 eltlen
= TYPE_LENGTH (elttype
);
810 /* FIXME: This doesn't deal with non-empty arrays of
811 0-length items (not a typical case!) */
815 len
= TYPE_LENGTH (type
) / eltlen
;
817 /* For an array of chars, print with string syntax. */
818 if (ada_is_string_type (type
) && (format
== 0 || format
== 's'))
820 if (prettyprint_arrays
)
822 print_spaces_filtered (2 + 2 * recurse
, stream
);
824 /* If requested, look for the first null char and only print
825 elements up to it. */
826 if (stop_print_at_null
)
830 /* Look for a NULL char. */
832 temp_len
< len
&& temp_len
< print_max
833 && char_at (valaddr
, temp_len
, eltlen
) != 0;
838 printstr (stream
, valaddr
, len
, 0, eltlen
);
843 fprintf_filtered (stream
, "(");
844 print_optional_low_bound (stream
, type
);
845 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
846 val_print_packed_array_elements (type
, valaddr
, 0, stream
,
847 format
, recurse
, pretty
);
849 val_print_array_elements (type
, valaddr
, address
, stream
,
850 format
, deref_ref
, recurse
,
852 fprintf_filtered (stream
, ")");
858 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
859 /* De-reference the reference */
862 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
864 LONGEST deref_val_int
= (LONGEST
)
865 unpack_pointer (lookup_pointer_type (builtin_type_void
),
867 if (deref_val_int
!= 0)
869 struct value
*deref_val
=
870 ada_value_ind (value_from_longest
871 (lookup_pointer_type (elttype
),
873 val_print (value_type (deref_val
),
874 value_contents (deref_val
), 0,
875 VALUE_ADDRESS (deref_val
), stream
, format
,
876 deref_ref
, recurse
+ 1, pretty
);
879 fputs_filtered ("(null)", stream
);
882 fputs_filtered ("???", stream
);
891 print_variant_part (struct type
*type
, int field_num
, const gdb_byte
*valaddr
,
892 struct ui_file
*stream
, int format
, int recurse
,
893 enum val_prettyprint pretty
, int comma_needed
,
894 struct type
*outer_type
, const gdb_byte
*outer_valaddr
)
896 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
897 int which
= ada_which_variant_applies (var_type
, outer_type
, outer_valaddr
);
902 return print_field_values
903 (TYPE_FIELD_TYPE (var_type
, which
),
904 valaddr
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
905 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
906 stream
, format
, recurse
, pretty
,
907 comma_needed
, outer_type
, outer_valaddr
);
911 ada_value_print (struct value
*val0
, struct ui_file
*stream
, int format
,
912 enum val_prettyprint pretty
)
914 const gdb_byte
*valaddr
= value_contents (val0
);
915 CORE_ADDR address
= VALUE_ADDRESS (val0
) + value_offset (val0
);
917 ada_to_fixed_type (value_type (val0
), valaddr
, address
, NULL
);
919 value_from_contents_and_address (type
, valaddr
, address
);
921 /* If it is a pointer, indicate what it points to. */
922 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
924 /* Hack: don't print (char *) for char strings. Their
925 type is indicated by the quoted string anyway. */
926 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
927 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
928 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
930 fprintf_filtered (stream
, "(");
931 type_print (type
, "", stream
, -1);
932 fprintf_filtered (stream
, ") ");
935 else if (ada_is_array_descriptor_type (type
))
937 fprintf_filtered (stream
, "(");
938 type_print (type
, "", stream
, -1);
939 fprintf_filtered (stream
, ") ");
941 else if (ada_is_bogus_array_descriptor (type
))
943 fprintf_filtered (stream
, "(");
944 type_print (type
, "", stream
, -1);
945 fprintf_filtered (stream
, ") (...?)");
949 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
950 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == 0
951 && TYPE_CODE (TYPE_INDEX_TYPE (type
)) == TYPE_CODE_RANGE
)
953 /* This is an array of zero-length elements, that is an array
954 of null records. This array needs to be printed by hand,
955 as the standard routine to print arrays relies on the size of
956 the array elements to be nonzero. This is because it computes
957 the number of elements in the array by dividing the array size
958 by the array element size. */
959 fprintf_filtered (stream
, "(%d .. %d => ())",
960 TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
)),
961 TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type
)));
965 return (val_print (type
, value_contents (val
), 0, address
,
966 stream
, format
, 1, 0, pretty
));
970 print_record (struct type
*type
, const gdb_byte
*valaddr
,
971 struct ui_file
*stream
, int format
, int recurse
,
972 enum val_prettyprint pretty
)
974 type
= ada_check_typedef (type
);
976 fprintf_filtered (stream
, "(");
978 if (print_field_values (type
, valaddr
, stream
, format
, recurse
, pretty
,
979 0, type
, valaddr
) != 0 && pretty
)
981 fprintf_filtered (stream
, "\n");
982 print_spaces_filtered (2 * recurse
, stream
);
985 fprintf_filtered (stream
, ")");
988 /* Print out fields of value at VALADDR having structure type TYPE.
990 TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the
991 same meanings as in ada_print_value and ada_val_print.
993 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
994 (used to get discriminant values when printing variant parts).
996 COMMA_NEEDED is 1 if fields have been printed at the current recursion
997 level, so that a comma is needed before any field printed by this
1000 Returns 1 if COMMA_NEEDED or any fields were printed. */
1003 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
1004 struct ui_file
*stream
, int format
, int recurse
,
1005 enum val_prettyprint pretty
, int comma_needed
,
1006 struct type
*outer_type
, const gdb_byte
*outer_valaddr
)
1010 len
= TYPE_NFIELDS (type
);
1012 for (i
= 0; i
< len
; i
+= 1)
1014 if (ada_is_ignored_field (type
, i
))
1017 if (ada_is_wrapper_field (type
, i
))
1020 print_field_values (TYPE_FIELD_TYPE (type
, i
),
1022 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1023 stream
, format
, recurse
, pretty
,
1024 comma_needed
, type
, valaddr
);
1027 else if (ada_is_variant_part (type
, i
))
1030 print_variant_part (type
, i
, valaddr
,
1031 stream
, format
, recurse
, pretty
, comma_needed
,
1032 outer_type
, outer_valaddr
);
1037 fprintf_filtered (stream
, ", ");
1042 fprintf_filtered (stream
, "\n");
1043 print_spaces_filtered (2 + 2 * recurse
, stream
);
1047 wrap_here (n_spaces (2 + 2 * recurse
));
1051 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
1052 fputs_filtered ("\"( ptr \"", stream
);
1054 fputs_filtered ("\"( nodef \"", stream
);
1055 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1056 language_cplus
, DMGL_NO_OPTS
);
1057 fputs_filtered ("\" \"", stream
);
1058 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1059 language_cplus
, DMGL_NO_OPTS
);
1060 fputs_filtered ("\") \"", stream
);
1064 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
1065 fprintf_filtered (stream
, "%.*s",
1066 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
1067 TYPE_FIELD_NAME (type
, i
));
1068 annotate_field_name_end ();
1069 fputs_filtered (" => ", stream
);
1070 annotate_field_value ();
1073 if (TYPE_FIELD_PACKED (type
, i
))
1077 /* Bitfields require special handling, especially due to byte
1079 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
1080 && TYPE_FIELD_IGNORE (type
, i
))
1082 fputs_filtered (_("<optimized out or zero length>"), stream
);
1086 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
1087 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
1089 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
1090 v
= ada_value_primitive_packed_val (NULL
, valaddr
,
1091 bit_pos
/ HOST_CHAR_BIT
,
1092 bit_pos
% HOST_CHAR_BIT
,
1094 TYPE_FIELD_TYPE (type
, i
));
1095 val_print (TYPE_FIELD_TYPE (type
, i
), value_contents (v
), 0, 0,
1096 stream
, format
, 0, recurse
+ 1, pretty
);
1100 ada_val_print (TYPE_FIELD_TYPE (type
, i
),
1101 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1102 0, 0, stream
, format
, 0, recurse
+ 1, pretty
);
1103 annotate_field_end ();
1106 return comma_needed
;