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, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
27 #include "expression.h"
36 #include "exceptions.h"
39 static void print_record (struct type
*, const gdb_byte
*, struct ui_file
*,
42 const struct value_print_options
*);
44 static int print_field_values (struct type
*, const gdb_byte
*,
45 struct ui_file
*, int,
47 const struct value_print_options
*,
51 static void adjust_type_signedness (struct type
*);
53 static int ada_val_print_1 (struct type
*, const gdb_byte
*, int, CORE_ADDR
,
54 struct ui_file
*, int,
56 const struct value_print_options
*);
59 /* Make TYPE unsigned if its range of values includes no negatives. */
61 adjust_type_signedness (struct type
*type
)
63 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
64 && TYPE_LOW_BOUND (type
) >= 0)
65 TYPE_UNSIGNED (type
) = 1;
68 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
69 if non-standard (i.e., other than 1 for numbers, other than lower bound
70 of index type for enumerated type). Returns 1 if something printed,
74 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
75 const struct value_print_options
*options
)
77 struct type
*index_type
;
81 if (options
->print_array_indexes
)
84 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
87 /* If this is an empty array, then don't print the lower bound.
88 That would be confusing, because we would print the lower bound,
89 followed by... nothing! */
90 if (low_bound
> high_bound
)
93 index_type
= TYPE_INDEX_TYPE (type
);
95 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
97 /* We need to know what the base type is, in order to do the
98 appropriate check below. Otherwise, if this is a subrange
99 of an enumerated type, where the underlying value of the
100 first element is typically 0, we might test the low bound
101 against the wrong value. */
102 index_type
= TYPE_TARGET_TYPE (index_type
);
105 switch (TYPE_CODE (index_type
))
112 if (low_bound
== TYPE_FIELD_BITPOS (index_type
, 0))
115 case TYPE_CODE_UNDEF
:
124 ada_print_scalar (index_type
, low_bound
, stream
);
125 fprintf_filtered (stream
, " => ");
129 /* Version of val_print_array_elements for GNAT-style packed arrays.
130 Prints elements of packed array of type TYPE at bit offset
131 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
132 separates with commas. RECURSE is the recursion (nesting) level.
133 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
136 val_print_packed_array_elements (struct type
*type
, const gdb_byte
*valaddr
,
137 int bitoffset
, struct ui_file
*stream
,
139 const struct value
*val
,
140 const struct value_print_options
*options
)
143 unsigned int things_printed
= 0;
145 struct type
*elttype
, *index_type
;
147 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
148 struct value
*mark
= value_mark ();
151 elttype
= TYPE_TARGET_TYPE (type
);
152 eltlen
= TYPE_LENGTH (check_typedef (elttype
));
153 index_type
= TYPE_INDEX_TYPE (type
);
158 if (get_discrete_bounds (index_type
, &low
, &high
) < 0)
161 len
= high
- low
+ 1;
165 annotate_array_section_begin (i
, elttype
);
167 while (i
< len
&& things_printed
< options
->print_max
)
169 struct value
*v0
, *v1
;
174 if (options
->prettyprint_arrays
)
176 fprintf_filtered (stream
, ",\n");
177 print_spaces_filtered (2 + 2 * recurse
, stream
);
181 fprintf_filtered (stream
, ", ");
184 wrap_here (n_spaces (2 + 2 * recurse
));
185 maybe_print_array_index (index_type
, i
+ low
, stream
, options
);
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
> options
->repeat_count_threshold
)
207 struct value_print_options opts
= *options
;
210 val_print (elttype
, value_contents (v0
), 0, 0, stream
,
211 recurse
+ 1, val
, &opts
, current_language
);
212 annotate_elt_rep (i
- i0
);
213 fprintf_filtered (stream
, _(" <repeats %u times>"), i
- i0
);
214 annotate_elt_rep_end ();
220 struct value_print_options opts
= *options
;
223 for (j
= i0
; j
< i
; j
+= 1)
227 if (options
->prettyprint_arrays
)
229 fprintf_filtered (stream
, ",\n");
230 print_spaces_filtered (2 + 2 * recurse
, stream
);
234 fprintf_filtered (stream
, ", ");
236 wrap_here (n_spaces (2 + 2 * recurse
));
237 maybe_print_array_index (index_type
, j
+ low
,
240 val_print (elttype
, value_contents (v0
), 0, 0, stream
,
241 recurse
+ 1, val
, &opts
, current_language
);
245 things_printed
+= i
- i0
;
247 annotate_array_section_end ();
250 fprintf_filtered (stream
, "...");
253 value_free_to_mark (mark
);
257 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
259 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
262 /* Print the character C on STREAM as part of the contents of a literal
263 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
264 (1 or 2) of the character. */
267 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
268 int quoter
, int type_len
)
273 c
&= (1 << (type_len
* TARGET_CHAR_BIT
)) - 1;
275 if (isascii (c
) && isprint (c
))
277 if (c
== quoter
&& c
== '"')
278 fprintf_filtered (stream
, "\"\"");
280 fprintf_filtered (stream
, "%c", c
);
283 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
286 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
287 or 2) of a character. */
290 char_at (const gdb_byte
*string
, int i
, int type_len
,
291 enum bfd_endian byte_order
)
296 return (int) extract_unsigned_integer (string
+ 2 * i
, 2, byte_order
);
299 /* Wrapper around memcpy to make it legal argument to ui_file_put. */
301 ui_memcpy (void *dest
, const char *buffer
, long len
)
303 memcpy (dest
, buffer
, (size_t) len
);
304 ((char *) dest
)[len
] = '\0';
307 /* Print a floating-point value of type TYPE, pointed to in GDB by
308 VALADDR, on STREAM. Use Ada formatting conventions: there must be
309 a decimal point, and at least one digit before and after the
310 point. We use GNAT format for NaNs and infinities. */
312 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
313 struct ui_file
*stream
)
318 struct ui_file
*tmp_stream
= mem_fileopen ();
319 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_stream
);
321 print_floating (valaddr
, type
, tmp_stream
);
322 ui_file_put (tmp_stream
, ui_memcpy
, buffer
);
323 do_cleanups (cleanups
);
326 len
= strlen (result
);
328 /* Modify for Ada rules. */
330 s
= strstr (result
, "inf");
332 s
= strstr (result
, "Inf");
334 s
= strstr (result
, "INF");
340 s
= strstr (result
, "nan");
342 s
= strstr (result
, "NaN");
344 s
= strstr (result
, "Nan");
348 if (result
[0] == '-')
353 if (s
== NULL
&& strchr (result
, '.') == NULL
)
355 s
= strchr (result
, 'e');
357 fprintf_filtered (stream
, "%s.0", result
);
359 fprintf_filtered (stream
, "%.*s.0%s", (int) (s
-result
), result
, s
);
362 fprintf_filtered (stream
, "%s", result
);
366 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
368 fputs_filtered ("'", stream
);
369 ada_emit_char (c
, type
, stream
, '\'', 1);
370 fputs_filtered ("'", stream
);
373 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
374 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
375 like a default signed integer. */
378 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
385 print_longest (stream
, 'd', 0, val
);
389 type
= ada_check_typedef (type
);
391 switch (TYPE_CODE (type
))
395 len
= TYPE_NFIELDS (type
);
396 for (i
= 0; i
< len
; i
++)
398 if (TYPE_FIELD_BITPOS (type
, i
) == val
)
405 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
409 print_longest (stream
, 'd', 0, val
);
414 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
418 LA_PRINT_CHAR ((unsigned char) val
, type
, stream
);
422 fprintf_filtered (stream
, val
? "true" : "false");
425 case TYPE_CODE_RANGE
:
426 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
429 case TYPE_CODE_UNDEF
:
431 case TYPE_CODE_ARRAY
:
432 case TYPE_CODE_STRUCT
:
433 case TYPE_CODE_UNION
:
438 case TYPE_CODE_STRING
:
439 case TYPE_CODE_ERROR
:
440 case TYPE_CODE_MEMBERPTR
:
441 case TYPE_CODE_METHODPTR
:
442 case TYPE_CODE_METHOD
:
444 warning (_("internal error: unhandled type in ada_print_scalar"));
448 error (_("Invalid type code in symbol table."));
453 /* Print the character string STRING, printing at most LENGTH characters.
454 Printing stops early if the number hits print_max; repeat counts
455 are printed as appropriate. Print ellipses at the end if we
456 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
457 TYPE_LEN is the length (1 or 2) of the character type. */
460 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
461 unsigned int length
, int force_ellipses
, int type_len
,
462 const struct value_print_options
*options
)
464 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (elttype
));
466 unsigned int things_printed
= 0;
472 fputs_filtered ("\"\"", stream
);
476 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
478 /* Position of the character we are examining
479 to see whether it is repeated. */
481 /* Number of repetitions we have detected so far. */
488 fputs_filtered (", ", stream
);
495 && char_at (string
, rep1
, type_len
, byte_order
)
496 == char_at (string
, i
, type_len
, byte_order
))
502 if (reps
> options
->repeat_count_threshold
)
506 if (options
->inspect_it
)
507 fputs_filtered ("\\\", ", stream
);
509 fputs_filtered ("\", ", stream
);
512 fputs_filtered ("'", stream
);
513 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
514 elttype
, stream
, '\'', type_len
);
515 fputs_filtered ("'", stream
);
516 fprintf_filtered (stream
, _(" <repeats %u times>"), reps
);
518 things_printed
+= options
->repeat_count_threshold
;
525 if (options
->inspect_it
)
526 fputs_filtered ("\\\"", stream
);
528 fputs_filtered ("\"", stream
);
531 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
532 elttype
, stream
, '"', type_len
);
537 /* Terminate the quotes if necessary. */
540 if (options
->inspect_it
)
541 fputs_filtered ("\\\"", stream
);
543 fputs_filtered ("\"", stream
);
546 if (force_ellipses
|| i
< length
)
547 fputs_filtered ("...", stream
);
551 ada_printstr (struct ui_file
*stream
, struct type
*type
,
552 const gdb_byte
*string
, unsigned int length
,
553 const char *encoding
, int force_ellipses
,
554 const struct value_print_options
*options
)
556 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
561 /* Print data of type TYPE located at VALADDR (within GDB), which came from
562 the inferior at address ADDRESS, onto stdio stream STREAM according to
563 OPTIONS. The data at VALADDR is in target byte order.
565 If the data is printed as a string, returns the number of string characters
568 RECURSE indicates the amount of indentation to supply before
569 continuation lines; this amount is roughly twice the value of RECURSE. */
572 ada_val_print (struct type
*type
, const gdb_byte
*valaddr0
,
573 int embedded_offset
, CORE_ADDR address
,
574 struct ui_file
*stream
, int recurse
,
575 const struct value
*val
,
576 const struct value_print_options
*options
)
578 volatile struct gdb_exception except
;
581 TRY_CATCH (except
, RETURN_MASK_ALL
)
583 result
= ada_val_print_1 (type
, valaddr0
, embedded_offset
, address
,
584 stream
, recurse
, val
, options
);
587 if (except
.reason
< 0)
593 /* Assuming TYPE is a simple array, print the value of this array located
594 at VALADDR. See ada_val_print for a description of the various
595 parameters of this function; they are identical. The semantics
596 of the return value is also identical to ada_val_print. */
599 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
600 CORE_ADDR address
, struct ui_file
*stream
, int recurse
,
601 const struct value
*val
,
602 const struct value_print_options
*options
)
604 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (type
));
605 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
608 /* For an array of chars, print with string syntax. */
609 if (ada_is_string_type (type
)
610 && (options
->format
== 0 || options
->format
== 's'))
618 eltlen
= TYPE_LENGTH (elttype
);
622 len
= TYPE_LENGTH (type
) / eltlen
;
624 if (options
->prettyprint_arrays
)
625 print_spaces_filtered (2 + 2 * recurse
, stream
);
627 /* If requested, look for the first null char and only print
628 elements up to it. */
629 if (options
->stop_print_at_null
)
633 /* Look for a NULL char. */
636 && temp_len
< options
->print_max
637 && char_at (valaddr
, temp_len
, eltlen
, byte_order
) != 0);
642 printstr (stream
, elttype
, valaddr
, len
, 0, eltlen
, options
);
647 fprintf_filtered (stream
, "(");
648 print_optional_low_bound (stream
, type
, options
);
649 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
650 val_print_packed_array_elements (type
, valaddr
, 0, stream
,
651 recurse
, val
, options
);
653 val_print_array_elements (type
, valaddr
, address
, stream
,
654 recurse
, val
, options
, 0);
655 fprintf_filtered (stream
, ")");
661 /* See the comment on ada_val_print. This function differs in that it
662 does not catch evaluation errors (leaving that to ada_val_print). */
665 ada_val_print_1 (struct type
*type
, const gdb_byte
*valaddr0
,
666 int embedded_offset
, CORE_ADDR address
,
667 struct ui_file
*stream
, int recurse
,
668 const struct value
*original_value
,
669 const struct value_print_options
*options
)
673 struct type
*elttype
;
675 const gdb_byte
*valaddr
= valaddr0
+ embedded_offset
;
677 type
= ada_check_typedef (type
);
679 if (ada_is_array_descriptor_type (type
)
680 || ada_is_constrained_packed_array_type (type
))
683 struct value
*mark
= value_mark ();
686 val
= value_from_contents_and_address (type
, valaddr
, address
);
687 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
688 val
= ada_coerce_to_simple_array_ptr (val
);
690 val
= ada_coerce_to_simple_array (val
);
693 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
694 fprintf_filtered (stream
, "0x0");
698 retn
= ada_val_print_1 (value_type (val
), value_contents (val
), 0,
699 value_address (val
), stream
, recurse
,
701 value_free_to_mark (mark
);
705 valaddr
= ada_aligned_value_addr (type
, valaddr
);
706 embedded_offset
-= valaddr
- valaddr0
- embedded_offset
;
707 type
= printable_val_type (type
, valaddr
);
709 switch (TYPE_CODE (type
))
712 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
713 recurse
, original_value
, options
);
717 int ret
= c_val_print (type
, valaddr0
, embedded_offset
, address
,
718 stream
, recurse
, original_value
, options
);
720 if (ada_is_tag_type (type
))
723 value_from_contents_and_address (type
, valaddr
, address
);
724 const char *name
= ada_tag_name (val
);
727 fprintf_filtered (stream
, " (%s)", name
);
734 case TYPE_CODE_RANGE
:
735 if (ada_is_fixed_point_type (type
))
737 LONGEST v
= unpack_long (type
, valaddr
);
738 int len
= TYPE_LENGTH (type
);
740 fprintf_filtered (stream
, len
< 4 ? "%.11g" : "%.17g",
741 (double) ada_fixed_to_float (type
, v
));
744 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
746 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
748 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
750 /* Obscure case of range type that has different length from
751 its base type. Perform a conversion, or we will get a
752 nonsense value. Actually, we could use the same
753 code regardless of lengths; I'm just avoiding a cast. */
754 struct value
*v
= value_cast (target_type
,
755 value_from_contents_and_address
758 return ada_val_print_1 (target_type
, value_contents (v
), 0, 0,
759 stream
, recurse
+ 1, NULL
, options
);
762 return ada_val_print_1 (TYPE_TARGET_TYPE (type
),
763 valaddr0
, embedded_offset
,
764 address
, stream
, recurse
,
765 original_value
, options
);
769 int format
= (options
->format
? options
->format
770 : options
->output_format
);
774 struct value_print_options opts
= *options
;
776 opts
.format
= format
;
777 print_scalar_formatted (valaddr
, type
, &opts
, 0, stream
);
779 else if (ada_is_system_address_type (type
))
781 /* FIXME: We want to print System.Address variables using
782 the same format as for any access type. But for some
783 reason GNAT encodes the System.Address type as an int,
784 so we have to work-around this deficiency by handling
785 System.Address values as a special case. */
787 struct gdbarch
*gdbarch
= get_type_arch (type
);
788 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
789 CORE_ADDR addr
= extract_typed_address (valaddr
, ptr_type
);
791 fprintf_filtered (stream
, "(");
792 type_print (type
, "", stream
, -1);
793 fprintf_filtered (stream
, ") ");
794 fputs_filtered (paddress (gdbarch
, addr
), stream
);
798 val_print_type_code_int (type
, valaddr
, stream
);
799 if (ada_is_character_type (type
))
801 fputs_filtered (" ", stream
);
802 ada_printchar ((unsigned char) unpack_long (type
, valaddr
),
812 print_scalar_formatted (valaddr
, type
, options
, 0, stream
);
815 len
= TYPE_NFIELDS (type
);
816 val
= unpack_long (type
, valaddr
);
817 for (i
= 0; i
< len
; i
++)
820 if (val
== TYPE_FIELD_BITPOS (type
, i
))
827 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
830 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
832 fputs_filtered (name
, stream
);
836 print_longest (stream
, 'd', 0, val
);
840 case TYPE_CODE_FLAGS
:
842 print_scalar_formatted (valaddr
, type
, options
, 0, stream
);
844 val_print_type_code_flags (type
, valaddr
, stream
);
849 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
850 recurse
, original_value
, options
);
852 ada_print_floating (valaddr0
+ embedded_offset
, type
, stream
);
855 case TYPE_CODE_UNION
:
856 case TYPE_CODE_STRUCT
:
857 if (ada_is_bogus_array_descriptor (type
))
859 fprintf_filtered (stream
, "(...?)");
864 print_record (type
, valaddr
, stream
, recurse
, original_value
,
869 case TYPE_CODE_ARRAY
:
870 return ada_val_print_array (type
, valaddr
, address
, stream
,
871 recurse
, original_value
, options
);
874 /* For references, the debugger is expected to print the value as
875 an address if DEREF_REF is null. But printing an address in place
876 of the object value would be confusing to an Ada programmer.
877 So, for Ada values, we print the actual dereferenced value
879 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
881 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
883 LONGEST deref_val_int
= (LONGEST
) unpack_pointer (type
, valaddr
);
885 if (deref_val_int
!= 0)
887 struct value
*deref_val
=
888 ada_value_ind (value_from_longest
889 (lookup_pointer_type (elttype
),
892 val_print (value_type (deref_val
),
893 value_contents (deref_val
), 0,
894 value_address (deref_val
), stream
, recurse
+ 1,
895 original_value
, options
, current_language
);
898 fputs_filtered ("(null)", stream
);
901 fputs_filtered ("???", stream
);
910 print_variant_part (struct type
*type
, int field_num
, const gdb_byte
*valaddr
,
911 struct ui_file
*stream
, int recurse
,
912 const struct value
*val
,
913 const struct value_print_options
*options
,
915 struct type
*outer_type
, const gdb_byte
*outer_valaddr
)
917 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
918 int which
= ada_which_variant_applies (var_type
, outer_type
, outer_valaddr
);
923 return print_field_values
924 (TYPE_FIELD_TYPE (var_type
, which
),
925 valaddr
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
926 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
927 stream
, recurse
, val
, options
,
928 comma_needed
, outer_type
, outer_valaddr
);
932 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
933 const struct value_print_options
*options
)
935 struct value
*val
= ada_to_fixed_value (val0
);
936 CORE_ADDR address
= value_address (val
);
937 struct type
*type
= value_type (val
);
938 struct value_print_options opts
;
940 /* If it is a pointer, indicate what it points to. */
941 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
943 /* Hack: don't print (char *) for char strings. Their
944 type is indicated by the quoted string anyway. */
945 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
946 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
947 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
949 fprintf_filtered (stream
, "(");
950 type_print (type
, "", stream
, -1);
951 fprintf_filtered (stream
, ") ");
954 else if (ada_is_array_descriptor_type (type
))
956 /* We do not print the type description unless TYPE is an array
957 access type (this is encoded by the compiler as a typedef to
958 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
959 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
961 fprintf_filtered (stream
, "(");
962 type_print (type
, "", stream
, -1);
963 fprintf_filtered (stream
, ") ");
966 else if (ada_is_bogus_array_descriptor (type
))
968 fprintf_filtered (stream
, "(");
969 type_print (type
, "", stream
, -1);
970 fprintf_filtered (stream
, ") (...?)");
976 return (val_print (type
, value_contents (val
), 0, address
,
977 stream
, 0, val
, &opts
, current_language
));
981 print_record (struct type
*type
, const gdb_byte
*valaddr
,
982 struct ui_file
*stream
, int recurse
,
983 const struct value
*val
,
984 const struct value_print_options
*options
)
986 type
= ada_check_typedef (type
);
988 fprintf_filtered (stream
, "(");
990 if (print_field_values (type
, valaddr
, stream
, recurse
, val
, options
,
991 0, type
, valaddr
) != 0 && options
->pretty
)
993 fprintf_filtered (stream
, "\n");
994 print_spaces_filtered (2 * recurse
, stream
);
997 fprintf_filtered (stream
, ")");
1000 /* Print out fields of value at VALADDR having structure type TYPE.
1002 TYPE, VALADDR, STREAM, RECURSE, and OPTIONS have the
1003 same meanings as in ada_print_value and ada_val_print.
1005 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
1006 (used to get discriminant values when printing variant parts).
1008 COMMA_NEEDED is 1 if fields have been printed at the current recursion
1009 level, so that a comma is needed before any field printed by this
1012 Returns 1 if COMMA_NEEDED or any fields were printed. */
1015 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
1016 struct ui_file
*stream
, int recurse
,
1017 const struct value
*val
,
1018 const struct value_print_options
*options
,
1020 struct type
*outer_type
, const gdb_byte
*outer_valaddr
)
1024 len
= TYPE_NFIELDS (type
);
1026 for (i
= 0; i
< len
; i
+= 1)
1028 if (ada_is_ignored_field (type
, i
))
1031 if (ada_is_wrapper_field (type
, i
))
1034 print_field_values (TYPE_FIELD_TYPE (type
, i
),
1036 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1037 stream
, recurse
, val
, options
,
1038 comma_needed
, type
, valaddr
);
1041 else if (ada_is_variant_part (type
, i
))
1044 print_variant_part (type
, i
, valaddr
,
1045 stream
, recurse
, val
, options
, comma_needed
,
1046 outer_type
, outer_valaddr
);
1051 fprintf_filtered (stream
, ", ");
1054 if (options
->pretty
)
1056 fprintf_filtered (stream
, "\n");
1057 print_spaces_filtered (2 + 2 * recurse
, stream
);
1061 wrap_here (n_spaces (2 + 2 * recurse
));
1063 if (options
->inspect_it
)
1065 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
1066 fputs_filtered ("\"( ptr \"", stream
);
1068 fputs_filtered ("\"( nodef \"", stream
);
1069 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1070 language_cplus
, DMGL_NO_OPTS
);
1071 fputs_filtered ("\" \"", stream
);
1072 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1073 language_cplus
, DMGL_NO_OPTS
);
1074 fputs_filtered ("\") \"", stream
);
1078 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
1079 fprintf_filtered (stream
, "%.*s",
1080 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
1081 TYPE_FIELD_NAME (type
, i
));
1082 annotate_field_name_end ();
1083 fputs_filtered (" => ", stream
);
1084 annotate_field_value ();
1087 if (TYPE_FIELD_PACKED (type
, i
))
1091 /* Bitfields require special handling, especially due to byte
1093 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
1095 fputs_filtered (_("<optimized out or zero length>"), stream
);
1099 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
1100 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
1101 struct value_print_options opts
;
1103 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
1104 v
= ada_value_primitive_packed_val (NULL
, valaddr
,
1105 bit_pos
/ HOST_CHAR_BIT
,
1106 bit_pos
% HOST_CHAR_BIT
,
1108 TYPE_FIELD_TYPE (type
, i
));
1111 val_print (TYPE_FIELD_TYPE (type
, i
), value_contents (v
), 0, 0,
1112 stream
, recurse
+ 1, v
,
1113 &opts
, current_language
);
1118 struct value_print_options opts
= *options
;
1121 ada_val_print (TYPE_FIELD_TYPE (type
, i
),
1122 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1123 0, 0, stream
, recurse
+ 1, val
, &opts
);
1125 annotate_field_end ();
1128 return comma_needed
;