1 /* Support for printing Ada values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001,
4 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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "gdb_string.h"
27 #include "expression.h"
37 /* Encapsulates arguments to ada_val_print. */
38 struct ada_val_print_args
44 struct ui_file
*stream
;
48 enum val_prettyprint pretty
;
51 extern int inspect_it
;
52 extern unsigned int repeat_count_threshold
;
54 static void print_record (struct type
*, char *, struct ui_file
*, int,
55 int, enum val_prettyprint
);
57 static int print_field_values (struct type
*, char *, struct ui_file
*,
58 int, int, enum val_prettyprint
,
59 int, struct type
*, char *);
61 static int print_variant_part (struct type
*, int, char *,
62 struct ui_file
*, int, int,
63 enum val_prettyprint
, int, struct type
*,
66 static void val_print_packed_array_elements (struct type
*, char *valaddr
,
67 int, struct ui_file
*, int, int,
68 enum val_prettyprint
);
70 static void adjust_type_signedness (struct type
*);
72 static int ada_val_print_stub (PTR args0
);
74 static int ada_val_print_1 (struct type
*, char *, int, CORE_ADDR
,
75 struct ui_file
*, int, int, int,
76 enum val_prettyprint
);
77 static void ada_print_floating (char *, struct type
*, struct ui_file
*);
80 /* Make TYPE unsigned if its range of values includes no negatives. */
82 adjust_type_signedness (struct type
*type
)
84 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
85 && TYPE_LOW_BOUND (type
) >= 0)
86 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
89 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
90 if non-standard (i.e., other than 1 for numbers, other than lower bound
91 of index type for enumerated type). Returns 1 if something printed,
95 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
)
97 struct type
*index_type
;
100 index_type
= TYPE_INDEX_TYPE (type
);
103 if (index_type
== NULL
)
105 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
107 low_bound
= TYPE_LOW_BOUND (index_type
);
108 index_type
= TYPE_TARGET_TYPE (index_type
);
113 switch (TYPE_CODE (index_type
))
116 if (low_bound
== TYPE_FIELD_BITPOS (index_type
, 0))
119 case TYPE_CODE_UNDEF
:
120 index_type
= builtin_type_long
;
128 ada_print_scalar (index_type
, (LONGEST
) low_bound
, stream
);
129 fprintf_filtered (stream
, " => ");
133 /* Version of val_print_array_elements for GNAT-style packed arrays.
134 Prints elements of packed array of type TYPE at bit offset
135 BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and
136 separates with commas. RECURSE is the recursion (nesting) level.
137 If PRETTY, uses "prettier" format. TYPE must have been decoded (as
138 by ada_coerce_to_simple_array). */
141 val_print_packed_array_elements (struct type
*type
, char *valaddr
,
142 int bitoffset
, struct ui_file
*stream
,
143 int format
, int recurse
,
144 enum val_prettyprint pretty
)
147 unsigned int things_printed
= 0;
149 struct type
*elttype
;
151 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
152 struct value
*mark
= value_mark ();
154 elttype
= TYPE_TARGET_TYPE (type
);
155 eltlen
= TYPE_LENGTH (check_typedef (elttype
));
159 if (get_discrete_bounds (TYPE_FIELD_TYPE (type
, 0), &low
, &high
) < 0)
162 len
= high
- low
+ 1;
166 annotate_array_section_begin (i
, elttype
);
168 while (i
< len
&& things_printed
< print_max
)
170 struct value
*v0
, *v1
;
175 if (prettyprint_arrays
)
177 fprintf_filtered (stream
, ",\n");
178 print_spaces_filtered (2 + 2 * recurse
, stream
);
182 fprintf_filtered (stream
, ", ");
185 wrap_here (n_spaces (2 + 2 * recurse
));
188 v0
= ada_value_primitive_packed_val (NULL
, valaddr
,
189 (i0
* bitsize
) / HOST_CHAR_BIT
,
190 (i0
* bitsize
) % HOST_CHAR_BIT
,
197 v1
= ada_value_primitive_packed_val (NULL
, valaddr
,
198 (i
* bitsize
) / HOST_CHAR_BIT
,
199 (i
* bitsize
) % HOST_CHAR_BIT
,
201 if (memcmp (VALUE_CONTENTS (v0
), VALUE_CONTENTS (v1
), eltlen
) != 0)
205 if (i
- i0
> repeat_count_threshold
)
207 val_print (elttype
, VALUE_CONTENTS (v0
), 0, 0, stream
, format
,
208 0, recurse
+ 1, pretty
);
209 annotate_elt_rep (i
- i0
);
210 fprintf_filtered (stream
, " <repeats %u times>", i
- i0
);
211 annotate_elt_rep_end ();
217 for (j
= i0
; j
< i
; j
+= 1)
221 if (prettyprint_arrays
)
223 fprintf_filtered (stream
, ",\n");
224 print_spaces_filtered (2 + 2 * recurse
, stream
);
228 fprintf_filtered (stream
, ", ");
230 wrap_here (n_spaces (2 + 2 * recurse
));
232 val_print (elttype
, VALUE_CONTENTS (v0
), 0, 0, stream
, format
,
233 0, recurse
+ 1, pretty
);
237 things_printed
+= i
- i0
;
239 annotate_array_section_end ();
242 fprintf_filtered (stream
, "...");
245 value_free_to_mark (mark
);
249 printable_val_type (struct type
*type
, char *valaddr
)
251 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
);
254 /* Print the character C on STREAM as part of the contents of a literal
255 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
256 (1 or 2) of the character. */
259 ada_emit_char (int c
, struct ui_file
*stream
, int quoter
, int type_len
)
264 c
&= (1 << (type_len
* TARGET_CHAR_BIT
)) - 1;
266 if (isascii (c
) && isprint (c
))
268 if (c
== quoter
&& c
== '"')
269 fprintf_filtered (stream
, "[\"%c\"]", quoter
);
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 (1
278 or 2) of a character. */
281 char_at (char *string
, int i
, int type_len
)
286 return (int) extract_unsigned_integer (string
+ 2 * i
, 2);
289 /* Wrapper around memcpy to make it legal argument to ui_file_put */
291 ui_memcpy (void *dest
, const char *buffer
, long len
)
293 memcpy (dest
, buffer
, (size_t) len
);
294 ((char *) dest
)[len
] = '\0';
297 /* Print a floating-point value of type TYPE, pointed to in GDB by
298 VALADDR, on STREAM. Use Ada formatting conventions: there must be
299 a decimal point, and at least one digit before and after the
300 point. We use GNAT format for NaNs and infinities. */
302 ada_print_floating (char *valaddr
, struct type
*type
, struct ui_file
*stream
)
307 struct ui_file
*tmp_stream
= mem_fileopen ();
308 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_stream
);
310 print_floating (valaddr
, type
, tmp_stream
);
311 ui_file_put (tmp_stream
, ui_memcpy
, buffer
);
312 do_cleanups (cleanups
);
315 len
= strlen (result
);
317 /* Modify for Ada rules. */
318 if ((s
= strstr (result
, "inf")) != NULL
319 || (s
= strstr (result
, "Inf")) != NULL
320 || (s
= strstr (result
, "INF")) != NULL
)
322 else if ((s
= strstr (result
, "nan")) != NULL
323 || (s
= strstr (result
, "NaN")) != NULL
324 || (s
= strstr (result
, "Nan")) != NULL
)
327 if (result
[0] == '-')
330 else if (strchr (result
, '.') == NULL
)
332 if ((s
= strchr (result
, 'e')) == NULL
)
333 fprintf_filtered (stream
, "%s.0", result
);
335 fprintf_filtered (stream
, "%.*s.0%s", (int) (s
-result
), result
, s
);
338 fprintf_filtered (stream
, "%s", result
);
342 ada_printchar (int c
, struct ui_file
*stream
)
344 fputs_filtered ("'", stream
);
345 ada_emit_char (c
, stream
, '\'', 1);
346 fputs_filtered ("'", stream
);
349 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
350 form appropriate for TYPE. */
353 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
358 CHECK_TYPEDEF (type
);
360 switch (TYPE_CODE (type
))
364 len
= TYPE_NFIELDS (type
);
365 for (i
= 0; i
< len
; i
++)
367 if (TYPE_FIELD_BITPOS (type
, i
) == val
)
374 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
378 print_longest (stream
, 'd', 0, val
);
383 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
387 LA_PRINT_CHAR ((unsigned char) val
, stream
);
391 fprintf_filtered (stream
, val
? "true" : "false");
394 case TYPE_CODE_RANGE
:
395 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
398 case TYPE_CODE_UNDEF
:
400 case TYPE_CODE_ARRAY
:
401 case TYPE_CODE_STRUCT
:
402 case TYPE_CODE_UNION
:
407 case TYPE_CODE_STRING
:
408 case TYPE_CODE_ERROR
:
409 case TYPE_CODE_MEMBER
:
410 case TYPE_CODE_METHOD
:
412 warning ("internal error: unhandled type in ada_print_scalar");
416 error ("Invalid type code in symbol table.");
421 /* Print the character string STRING, printing at most LENGTH characters.
422 Printing stops early if the number hits print_max; repeat counts
423 are printed as appropriate. Print ellipses at the end if we
424 had to stop before printing LENGTH characters, or if
425 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
429 printstr (struct ui_file
*stream
, char *string
, unsigned int length
,
430 int force_ellipses
, int type_len
)
433 unsigned int things_printed
= 0;
439 fputs_filtered ("\"\"", stream
);
443 for (i
= 0; i
< length
&& things_printed
< print_max
; i
+= 1)
445 /* Position of the character we are examining
446 to see whether it is repeated. */
448 /* Number of repetitions we have detected so far. */
455 fputs_filtered (", ", stream
);
461 while (rep1
< length
&&
462 char_at (string
, rep1
, type_len
) == char_at (string
, i
,
469 if (reps
> repeat_count_threshold
)
474 fputs_filtered ("\\\", ", stream
);
476 fputs_filtered ("\", ", stream
);
479 fputs_filtered ("'", stream
);
480 ada_emit_char (char_at (string
, i
, type_len
), stream
, '\'',
482 fputs_filtered ("'", stream
);
483 fprintf_filtered (stream
, " <repeats %u times>", reps
);
485 things_printed
+= repeat_count_threshold
;
493 fputs_filtered ("\\\"", stream
);
495 fputs_filtered ("\"", stream
);
498 ada_emit_char (char_at (string
, i
, type_len
), stream
, '"',
504 /* Terminate the quotes if necessary. */
508 fputs_filtered ("\\\"", stream
);
510 fputs_filtered ("\"", stream
);
513 if (force_ellipses
|| i
< length
)
514 fputs_filtered ("...", stream
);
518 ada_printstr (struct ui_file
*stream
, char *string
, unsigned int length
,
519 int width
, int force_ellipses
)
521 printstr (stream
, string
, length
, force_ellipses
, width
);
525 /* Print data of type TYPE located at VALADDR (within GDB), which came from
526 the inferior at address ADDRESS, onto stdio stream STREAM according to
527 FORMAT (a letter as for the printf % codes or 0 for natural format).
528 The data at VALADDR is in target byte order.
530 If the data is printed as a string, returns the number of string characters
533 If DEREF_REF is nonzero, then dereference references, otherwise just print
536 RECURSE indicates the amount of indentation to supply before
537 continuation lines; this amount is roughly twice the value of RECURSE.
539 When PRETTY is non-zero, prints record fields on separate lines.
540 (For some reason, the current version of gdb instead uses a global
541 variable---prettyprint_arrays--- to causes a similar effect on
545 ada_val_print (struct type
*type
, char *valaddr0
, int embedded_offset
,
546 CORE_ADDR address
, struct ui_file
*stream
, int format
,
547 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
549 struct ada_val_print_args args
;
551 args
.valaddr0
= valaddr0
;
552 args
.embedded_offset
= embedded_offset
;
553 args
.address
= address
;
554 args
.stream
= stream
;
555 args
.format
= format
;
556 args
.deref_ref
= deref_ref
;
557 args
.recurse
= recurse
;
558 args
.pretty
= pretty
;
560 return catch_errors (ada_val_print_stub
, &args
, NULL
, RETURN_MASK_ALL
);
563 /* Helper for ada_val_print; used as argument to catch_errors to
564 unmarshal the arguments to ada_val_print_1, which does the work. */
566 ada_val_print_stub (PTR args0
)
568 struct ada_val_print_args
*argsp
= (struct ada_val_print_args
*) args0
;
569 return ada_val_print_1 (argsp
->type
, argsp
->valaddr0
,
570 argsp
->embedded_offset
, argsp
->address
,
571 argsp
->stream
, argsp
->format
, argsp
->deref_ref
,
572 argsp
->recurse
, argsp
->pretty
);
575 /* See the comment on ada_val_print. This function differs in that it
576 * does not catch evaluation errors (leaving that to ada_val_print). */
579 ada_val_print_1 (struct type
*type
, char *valaddr0
, int embedded_offset
,
580 CORE_ADDR address
, struct ui_file
*stream
, int format
,
581 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
585 struct type
*elttype
;
588 char *valaddr
= valaddr0
+ embedded_offset
;
590 CHECK_TYPEDEF (type
);
592 if (ada_is_array_descriptor_type (type
) || ada_is_packed_array_type (type
))
595 struct value
*mark
= value_mark ();
597 val
= value_from_contents_and_address (type
, valaddr
, address
);
598 val
= ada_coerce_to_simple_array_ptr (val
);
601 fprintf_filtered (stream
, "(null)");
605 retn
= ada_val_print_1 (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
606 VALUE_ADDRESS (val
), stream
, format
,
607 deref_ref
, recurse
, pretty
);
608 value_free_to_mark (mark
);
612 valaddr
= ada_aligned_value_addr (type
, valaddr
);
613 embedded_offset
-= valaddr
- valaddr0
- embedded_offset
;
614 type
= printable_val_type (type
, valaddr
);
616 switch (TYPE_CODE (type
))
619 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
620 format
, deref_ref
, recurse
, pretty
);
624 int ret
= c_val_print (type
, valaddr0
, embedded_offset
, address
,
625 stream
, format
, deref_ref
, recurse
, pretty
);
626 if (ada_is_tag_type (type
))
629 value_from_contents_and_address (type
, valaddr
, address
);
630 const char *name
= ada_tag_name (val
);
632 fprintf_filtered (stream
, " (%s)", name
);
639 case TYPE_CODE_RANGE
:
640 if (ada_is_fixed_point_type (type
))
642 LONGEST v
= unpack_long (type
, valaddr
);
643 int len
= TYPE_LENGTH (type
);
645 fprintf_filtered (stream
, len
< 4 ? "%.11g" : "%.17g",
646 (double) ada_fixed_to_float (type
, v
));
649 else if (ada_is_vax_floating_type (type
))
652 value_from_contents_and_address (type
, valaddr
, address
);
653 struct value
*func
= ada_vax_float_print_function (type
);
656 static struct type
*parray_of_char
= NULL
;
657 struct value
*printable_val
;
659 if (parray_of_char
== NULL
)
663 (NULL
, builtin_type_char
,
664 create_range_type (NULL
, builtin_type_int
, 0, 32)), NULL
);
667 value_ind (value_cast (parray_of_char
,
668 call_function_by_hand (func
, 1,
671 fprintf_filtered (stream
, "%s", VALUE_CONTENTS (printable_val
));
674 /* No special printing function. Do as best we can. */
676 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
678 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
679 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
681 /* Obscure case of range type that has different length from
682 its base type. Perform a conversion, or we will get a
683 nonsense value. Actually, we could use the same
684 code regardless of lengths; I'm just avoiding a cast. */
685 struct value
*v
= value_cast (target_type
,
686 value_from_contents_and_address
688 return ada_val_print_1 (target_type
, VALUE_CONTENTS (v
), 0, 0,
689 stream
, format
, 0, recurse
+ 1, pretty
);
692 return ada_val_print_1 (TYPE_TARGET_TYPE (type
),
693 valaddr0
, embedded_offset
,
694 address
, stream
, format
, deref_ref
,
699 format
= format
? format
: output_format
;
702 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
704 else if (ada_is_system_address_type (type
))
706 /* FIXME: We want to print System.Address variables using
707 the same format as for any access type. But for some
708 reason GNAT encodes the System.Address type as an int,
709 so we have to work-around this deficiency by handling
710 System.Address values as a special case. */
711 fprintf_filtered (stream
, "(");
712 type_print (type
, "", stream
, -1);
713 fprintf_filtered (stream
, ") ");
714 print_address_numeric
715 (extract_typed_address (valaddr
, builtin_type_void_data_ptr
),
720 val_print_type_code_int (type
, valaddr
, stream
);
721 if (ada_is_character_type (type
))
723 fputs_filtered (" ", stream
);
724 ada_printchar ((unsigned char) unpack_long (type
, valaddr
),
734 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
737 len
= TYPE_NFIELDS (type
);
738 val
= unpack_long (type
, valaddr
);
739 for (i
= 0; i
< len
; i
++)
742 if (val
== TYPE_FIELD_BITPOS (type
, i
))
749 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
751 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
753 fputs_filtered (name
, stream
);
757 print_longest (stream
, 'd', 0, val
);
763 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
764 format
, deref_ref
, recurse
, pretty
);
766 ada_print_floating (valaddr0
+ embedded_offset
, type
, stream
);
769 case TYPE_CODE_UNION
:
770 case TYPE_CODE_STRUCT
:
771 if (ada_is_bogus_array_descriptor (type
))
773 fprintf_filtered (stream
, "(...?)");
778 print_record (type
, valaddr
, stream
, format
, recurse
, pretty
);
782 case TYPE_CODE_ARRAY
:
783 elttype
= TYPE_TARGET_TYPE (type
);
787 eltlen
= TYPE_LENGTH (elttype
);
788 /* FIXME: This doesn't deal with non-empty arrays of
789 0-length items (not a typical case!) */
793 len
= TYPE_LENGTH (type
) / eltlen
;
795 /* For an array of chars, print with string syntax. */
796 if (ada_is_string_type (type
) && (format
== 0 || format
== 's'))
798 if (prettyprint_arrays
)
800 print_spaces_filtered (2 + 2 * recurse
, stream
);
802 /* If requested, look for the first null char and only print
803 elements up to it. */
804 if (stop_print_at_null
)
808 /* Look for a NULL char. */
810 temp_len
< len
&& temp_len
< print_max
811 && char_at (valaddr
, temp_len
, eltlen
) != 0;
816 printstr (stream
, valaddr
, len
, 0, eltlen
);
821 fprintf_filtered (stream
, "(");
822 print_optional_low_bound (stream
, type
);
823 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
824 val_print_packed_array_elements (type
, valaddr
, 0, stream
,
825 format
, recurse
, pretty
);
827 val_print_array_elements (type
, valaddr
, address
, stream
,
828 format
, deref_ref
, recurse
,
830 fprintf_filtered (stream
, ")");
836 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
837 /* De-reference the reference */
840 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
842 LONGEST deref_val_int
= (LONGEST
)
843 unpack_pointer (lookup_pointer_type (builtin_type_void
),
845 if (deref_val_int
!= 0)
847 struct value
*deref_val
=
848 ada_value_ind (value_from_longest
849 (lookup_pointer_type (elttype
),
851 val_print (VALUE_TYPE (deref_val
),
852 VALUE_CONTENTS (deref_val
), 0,
853 VALUE_ADDRESS (deref_val
), stream
, format
,
854 deref_ref
, recurse
+ 1, pretty
);
857 fputs_filtered ("(null)", stream
);
860 fputs_filtered ("???", stream
);
869 print_variant_part (struct type
*type
, int field_num
, char *valaddr
,
870 struct ui_file
*stream
, int format
, int recurse
,
871 enum val_prettyprint pretty
, int comma_needed
,
872 struct type
*outer_type
, char *outer_valaddr
)
874 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
875 int which
= ada_which_variant_applies (var_type
, outer_type
, outer_valaddr
);
880 return print_field_values
881 (TYPE_FIELD_TYPE (var_type
, which
),
882 valaddr
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
883 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
884 stream
, format
, recurse
, pretty
,
885 comma_needed
, outer_type
, outer_valaddr
);
889 ada_value_print (struct value
*val0
, struct ui_file
*stream
, int format
,
890 enum val_prettyprint pretty
)
892 char *valaddr
= VALUE_CONTENTS (val0
);
893 CORE_ADDR address
= VALUE_ADDRESS (val0
) + VALUE_OFFSET (val0
);
895 ada_to_fixed_type (VALUE_TYPE (val0
), valaddr
, address
, NULL
);
897 value_from_contents_and_address (type
, valaddr
, address
);
899 /* If it is a pointer, indicate what it points to. */
900 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
902 /* Hack: don't print (char *) for char strings. Their
903 type is indicated by the quoted string anyway. */
904 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
905 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
906 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
908 fprintf_filtered (stream
, "(");
909 type_print (type
, "", stream
, -1);
910 fprintf_filtered (stream
, ") ");
913 else if (ada_is_array_descriptor_type (type
))
915 fprintf_filtered (stream
, "(");
916 type_print (type
, "", stream
, -1);
917 fprintf_filtered (stream
, ") ");
919 else if (ada_is_bogus_array_descriptor (type
))
921 fprintf_filtered (stream
, "(");
922 type_print (type
, "", stream
, -1);
923 fprintf_filtered (stream
, ") (...?)");
927 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
928 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == 0
929 && TYPE_CODE (TYPE_INDEX_TYPE (type
)) == TYPE_CODE_RANGE
)
931 /* This is an array of zero-length elements, that is an array
932 of null records. This array needs to be printed by hand,
933 as the standard routine to print arrays relies on the size of
934 the array elements to be nonzero. This is because it computes
935 the number of elements in the array by dividing the array size
936 by the array element size. */
937 fprintf_filtered (stream
, "(%d .. %d => ())",
938 TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
)),
939 TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type
)));
943 return (val_print (type
, VALUE_CONTENTS (val
), 0, address
,
944 stream
, format
, 1, 0, pretty
));
948 print_record (struct type
*type
, char *valaddr
, struct ui_file
*stream
,
949 int format
, int recurse
, enum val_prettyprint pretty
)
951 CHECK_TYPEDEF (type
);
953 fprintf_filtered (stream
, "(");
955 if (print_field_values (type
, valaddr
, stream
, format
, recurse
, pretty
,
956 0, type
, valaddr
) != 0 && pretty
)
958 fprintf_filtered (stream
, "\n");
959 print_spaces_filtered (2 * recurse
, stream
);
962 fprintf_filtered (stream
, ")");
965 /* Print out fields of value at VALADDR having structure type TYPE.
967 TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the
968 same meanings as in ada_print_value and ada_val_print.
970 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
971 (used to get discriminant values when printing variant parts).
973 COMMA_NEEDED is 1 if fields have been printed at the current recursion
974 level, so that a comma is needed before any field printed by this
977 Returns 1 if COMMA_NEEDED or any fields were printed. */
980 print_field_values (struct type
*type
, char *valaddr
, struct ui_file
*stream
,
981 int format
, int recurse
, enum val_prettyprint pretty
,
982 int comma_needed
, struct type
*outer_type
,
987 len
= TYPE_NFIELDS (type
);
989 for (i
= 0; i
< len
; i
+= 1)
991 if (ada_is_ignored_field (type
, i
))
994 if (ada_is_wrapper_field (type
, i
))
997 print_field_values (TYPE_FIELD_TYPE (type
, i
),
999 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1000 stream
, format
, recurse
, pretty
,
1001 comma_needed
, type
, valaddr
);
1004 else if (ada_is_variant_part (type
, i
))
1007 print_variant_part (type
, i
, valaddr
,
1008 stream
, format
, recurse
, pretty
, comma_needed
,
1009 outer_type
, outer_valaddr
);
1014 fprintf_filtered (stream
, ", ");
1019 fprintf_filtered (stream
, "\n");
1020 print_spaces_filtered (2 + 2 * recurse
, stream
);
1024 wrap_here (n_spaces (2 + 2 * recurse
));
1028 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
1029 fputs_filtered ("\"( ptr \"", stream
);
1031 fputs_filtered ("\"( nodef \"", stream
);
1032 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1033 language_cplus
, DMGL_NO_OPTS
);
1034 fputs_filtered ("\" \"", stream
);
1035 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1036 language_cplus
, DMGL_NO_OPTS
);
1037 fputs_filtered ("\") \"", stream
);
1041 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
1042 fprintf_filtered (stream
, "%.*s",
1043 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
1044 TYPE_FIELD_NAME (type
, i
));
1045 annotate_field_name_end ();
1046 fputs_filtered (" => ", stream
);
1047 annotate_field_value ();
1050 if (TYPE_FIELD_PACKED (type
, i
))
1054 /* Bitfields require special handling, especially due to byte
1056 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
1057 && TYPE_FIELD_IGNORE (type
, i
))
1059 fputs_filtered ("<optimized out or zero length>", stream
);
1063 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
1064 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
1066 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
1067 v
= ada_value_primitive_packed_val (NULL
, valaddr
,
1068 bit_pos
/ HOST_CHAR_BIT
,
1069 bit_pos
% HOST_CHAR_BIT
,
1071 TYPE_FIELD_TYPE (type
, i
));
1072 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0, 0,
1073 stream
, format
, 0, recurse
+ 1, pretty
);
1077 ada_val_print (TYPE_FIELD_TYPE (type
, i
),
1078 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1079 0, 0, stream
, format
, 0, recurse
+ 1, pretty
);
1080 annotate_field_end ();
1083 return comma_needed
;