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 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 array type, prints its lower bound on STREAM,
78 if non-standard (i.e., other than 1 for numbers, other than lower bound
79 of index type for enumerated type). Returns 1 if something printed,
83 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
)
85 struct type
*index_type
;
89 if (print_array_indexes_p ())
92 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
95 /* If this is an empty array, then don't print the lower bound.
96 That would be confusing, because we would print the lower bound,
97 followed by... nothing! */
98 if (low_bound
> high_bound
)
101 index_type
= TYPE_INDEX_TYPE (type
);
103 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
105 /* We need to know what the base type is, in order to do the
106 appropriate check below. Otherwise, if this is a subrange
107 of an enumerated type, where the underlying value of the
108 first element is typically 0, we might test the low bound
109 against the wrong value. */
110 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
, const gdb_byte
*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
, *index_type
;
151 unsigned long bitsize
= TYPE_FIELD_BITSIZE (type
, 0);
152 struct value
*mark
= value_mark ();
155 elttype
= TYPE_TARGET_TYPE (type
);
156 eltlen
= TYPE_LENGTH (check_typedef (elttype
));
157 index_type
= TYPE_INDEX_TYPE (type
);
161 if (get_discrete_bounds (TYPE_FIELD_TYPE (type
, 0), &low
, &high
) < 0)
164 len
= high
- low
+ 1;
168 annotate_array_section_begin (i
, elttype
);
170 while (i
< len
&& things_printed
< print_max
)
172 struct value
*v0
, *v1
;
177 if (prettyprint_arrays
)
179 fprintf_filtered (stream
, ",\n");
180 print_spaces_filtered (2 + 2 * recurse
, stream
);
184 fprintf_filtered (stream
, ", ");
187 wrap_here (n_spaces (2 + 2 * recurse
));
188 maybe_print_array_index (index_type
, i
+ low
, stream
, format
, pretty
);
191 v0
= ada_value_primitive_packed_val (NULL
, valaddr
,
192 (i0
* bitsize
) / HOST_CHAR_BIT
,
193 (i0
* bitsize
) % HOST_CHAR_BIT
,
200 v1
= ada_value_primitive_packed_val (NULL
, valaddr
,
201 (i
* bitsize
) / HOST_CHAR_BIT
,
202 (i
* bitsize
) % HOST_CHAR_BIT
,
204 if (memcmp (value_contents (v0
), value_contents (v1
), eltlen
) != 0)
208 if (i
- i0
> repeat_count_threshold
)
210 val_print (elttype
, value_contents (v0
), 0, 0, stream
, format
,
211 0, recurse
+ 1, pretty
, current_language
);
212 annotate_elt_rep (i
- i0
);
213 fprintf_filtered (stream
, _(" <repeats %u times>"), i
- i0
);
214 annotate_elt_rep_end ();
220 for (j
= i0
; j
< i
; j
+= 1)
224 if (prettyprint_arrays
)
226 fprintf_filtered (stream
, ",\n");
227 print_spaces_filtered (2 + 2 * recurse
, stream
);
231 fprintf_filtered (stream
, ", ");
233 wrap_here (n_spaces (2 + 2 * recurse
));
234 maybe_print_array_index (index_type
, j
+ low
,
235 stream
, format
, pretty
);
237 val_print (elttype
, value_contents (v0
), 0, 0, stream
, format
,
238 0, recurse
+ 1, pretty
, current_language
);
242 things_printed
+= i
- i0
;
244 annotate_array_section_end ();
247 fprintf_filtered (stream
, "...");
250 value_free_to_mark (mark
);
254 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
256 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
259 /* Print the character C on STREAM as part of the contents of a literal
260 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
261 (1 or 2) of the character. */
264 ada_emit_char (int c
, struct ui_file
*stream
, int quoter
, int type_len
)
269 c
&= (1 << (type_len
* TARGET_CHAR_BIT
)) - 1;
271 if (isascii (c
) && isprint (c
))
273 if (c
== quoter
&& c
== '"')
274 fprintf_filtered (stream
, "\"\"");
276 fprintf_filtered (stream
, "%c", c
);
279 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
282 /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
283 or 2) of a character. */
286 char_at (const gdb_byte
*string
, int i
, int type_len
)
291 return (int) extract_unsigned_integer (string
+ 2 * i
, 2);
294 /* Wrapper around memcpy to make it legal argument to ui_file_put */
296 ui_memcpy (void *dest
, const char *buffer
, long len
)
298 memcpy (dest
, buffer
, (size_t) len
);
299 ((char *) dest
)[len
] = '\0';
302 /* Print a floating-point value of type TYPE, pointed to in GDB by
303 VALADDR, on STREAM. Use Ada formatting conventions: there must be
304 a decimal point, and at least one digit before and after the
305 point. We use GNAT format for NaNs and infinities. */
307 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
308 struct ui_file
*stream
)
313 struct ui_file
*tmp_stream
= mem_fileopen ();
314 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_stream
);
316 print_floating (valaddr
, type
, tmp_stream
);
317 ui_file_put (tmp_stream
, ui_memcpy
, buffer
);
318 do_cleanups (cleanups
);
321 len
= strlen (result
);
323 /* Modify for Ada rules. */
325 s
= strstr (result
, "inf");
327 s
= strstr (result
, "Inf");
329 s
= strstr (result
, "INF");
335 s
= strstr (result
, "nan");
337 s
= strstr (result
, "NaN");
339 s
= strstr (result
, "Nan");
343 if (result
[0] == '-')
348 if (s
== NULL
&& strchr (result
, '.') == NULL
)
350 s
= strchr (result
, 'e');
352 fprintf_filtered (stream
, "%s.0", result
);
354 fprintf_filtered (stream
, "%.*s.0%s", (int) (s
-result
), result
, s
);
357 fprintf_filtered (stream
, "%s", result
);
361 ada_printchar (int c
, struct ui_file
*stream
)
363 fputs_filtered ("'", stream
);
364 ada_emit_char (c
, stream
, '\'', 1);
365 fputs_filtered ("'", stream
);
368 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
369 form appropriate for TYPE. */
372 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
377 type
= ada_check_typedef (type
);
379 switch (TYPE_CODE (type
))
383 len
= TYPE_NFIELDS (type
);
384 for (i
= 0; i
< len
; i
++)
386 if (TYPE_FIELD_BITPOS (type
, i
) == val
)
393 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
397 print_longest (stream
, 'd', 0, val
);
402 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
406 LA_PRINT_CHAR ((unsigned char) val
, stream
);
410 fprintf_filtered (stream
, val
? "true" : "false");
413 case TYPE_CODE_RANGE
:
414 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
417 case TYPE_CODE_UNDEF
:
419 case TYPE_CODE_ARRAY
:
420 case TYPE_CODE_STRUCT
:
421 case TYPE_CODE_UNION
:
426 case TYPE_CODE_STRING
:
427 case TYPE_CODE_ERROR
:
428 case TYPE_CODE_MEMBERPTR
:
429 case TYPE_CODE_METHODPTR
:
430 case TYPE_CODE_METHOD
:
432 warning (_("internal error: unhandled type in ada_print_scalar"));
436 error (_("Invalid type code in symbol table."));
441 /* Print the character string STRING, printing at most LENGTH characters.
442 Printing stops early if the number hits print_max; repeat counts
443 are printed as appropriate. Print ellipses at the end if we
444 had to stop before printing LENGTH characters, or if
445 FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type.
449 printstr (struct ui_file
*stream
, const gdb_byte
*string
,
450 unsigned int length
, int force_ellipses
, int type_len
)
453 unsigned int things_printed
= 0;
459 fputs_filtered ("\"\"", stream
);
463 for (i
= 0; i
< length
&& things_printed
< print_max
; i
+= 1)
465 /* Position of the character we are examining
466 to see whether it is repeated. */
468 /* Number of repetitions we have detected so far. */
475 fputs_filtered (", ", stream
);
482 && char_at (string
, rep1
, type_len
) == char_at (string
, i
,
489 if (reps
> repeat_count_threshold
)
494 fputs_filtered ("\\\", ", stream
);
496 fputs_filtered ("\", ", stream
);
499 fputs_filtered ("'", stream
);
500 ada_emit_char (char_at (string
, i
, type_len
), stream
, '\'',
502 fputs_filtered ("'", stream
);
503 fprintf_filtered (stream
, _(" <repeats %u times>"), reps
);
505 things_printed
+= repeat_count_threshold
;
513 fputs_filtered ("\\\"", stream
);
515 fputs_filtered ("\"", stream
);
518 ada_emit_char (char_at (string
, i
, type_len
), stream
, '"',
524 /* Terminate the quotes if necessary. */
528 fputs_filtered ("\\\"", stream
);
530 fputs_filtered ("\"", stream
);
533 if (force_ellipses
|| i
< length
)
534 fputs_filtered ("...", stream
);
538 ada_printstr (struct ui_file
*stream
, const gdb_byte
*string
,
539 unsigned int length
, int width
, int force_ellipses
)
541 printstr (stream
, string
, length
, force_ellipses
, width
);
545 /* Print data of type TYPE located at VALADDR (within GDB), which came from
546 the inferior at address ADDRESS, onto stdio stream STREAM according to
547 FORMAT (a letter as for the printf % codes or 0 for natural format).
548 The data at VALADDR is in target byte order.
550 If the data is printed as a string, returns the number of string characters
553 If DEREF_REF is nonzero, then dereference references, otherwise just print
556 RECURSE indicates the amount of indentation to supply before
557 continuation lines; this amount is roughly twice the value of RECURSE.
559 When PRETTY is non-zero, prints record fields on separate lines.
560 (For some reason, the current version of gdb instead uses a global
561 variable---prettyprint_arrays--- to causes a similar effect on
565 ada_val_print (struct type
*type
, const gdb_byte
*valaddr0
,
566 int embedded_offset
, CORE_ADDR address
,
567 struct ui_file
*stream
, int format
, int deref_ref
,
568 int recurse
, enum val_prettyprint pretty
)
570 struct ada_val_print_args args
;
572 args
.valaddr0
= valaddr0
;
573 args
.embedded_offset
= embedded_offset
;
574 args
.address
= address
;
575 args
.stream
= stream
;
576 args
.format
= format
;
577 args
.deref_ref
= deref_ref
;
578 args
.recurse
= recurse
;
579 args
.pretty
= pretty
;
581 return catch_errors (ada_val_print_stub
, &args
, NULL
, RETURN_MASK_ALL
);
584 /* Helper for ada_val_print; used as argument to catch_errors to
585 unmarshal the arguments to ada_val_print_1, which does the work. */
587 ada_val_print_stub (void *args0
)
589 struct ada_val_print_args
*argsp
= (struct ada_val_print_args
*) args0
;
590 return ada_val_print_1 (argsp
->type
, argsp
->valaddr0
,
591 argsp
->embedded_offset
, argsp
->address
,
592 argsp
->stream
, argsp
->format
, argsp
->deref_ref
,
593 argsp
->recurse
, argsp
->pretty
);
596 /* Assuming TYPE is a simple array, print the value of this array located
597 at VALADDR. See ada_val_print for a description of the various
598 parameters of this function; they are identical. The semantics
599 of the return value is also identical to ada_val_print. */
602 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
603 CORE_ADDR address
, struct ui_file
*stream
, int format
,
604 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
606 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
614 eltlen
= TYPE_LENGTH (elttype
);
618 len
= TYPE_LENGTH (type
) / eltlen
;
620 /* For an array of chars, print with string syntax. */
621 if (ada_is_string_type (type
) && (format
== 0 || format
== 's'))
623 if (prettyprint_arrays
)
624 print_spaces_filtered (2 + 2 * recurse
, stream
);
626 /* If requested, look for the first null char and only print
627 elements up to it. */
628 if (stop_print_at_null
)
632 /* Look for a NULL char. */
635 && temp_len
< print_max
636 && char_at (valaddr
, temp_len
, eltlen
) != 0);
641 printstr (stream
, valaddr
, len
, 0, eltlen
);
646 fprintf_filtered (stream
, "(");
647 print_optional_low_bound (stream
, type
);
648 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
649 val_print_packed_array_elements (type
, valaddr
, 0, stream
,
650 format
, recurse
, pretty
);
652 val_print_array_elements (type
, valaddr
, address
, stream
,
653 format
, deref_ref
, recurse
,
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 format
,
668 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
672 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
) || ada_is_packed_array_type (type
))
682 struct value
*mark
= value_mark ();
684 val
= value_from_contents_and_address (type
, valaddr
, address
);
685 val
= ada_coerce_to_simple_array_ptr (val
);
688 fprintf_filtered (stream
, "(null)");
692 retn
= ada_val_print_1 (value_type (val
), value_contents (val
), 0,
693 VALUE_ADDRESS (val
), stream
, format
,
694 deref_ref
, recurse
, pretty
);
695 value_free_to_mark (mark
);
699 valaddr
= ada_aligned_value_addr (type
, valaddr
);
700 embedded_offset
-= valaddr
- valaddr0
- embedded_offset
;
701 type
= printable_val_type (type
, valaddr
);
703 switch (TYPE_CODE (type
))
706 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
707 format
, deref_ref
, recurse
, pretty
);
711 int ret
= c_val_print (type
, valaddr0
, embedded_offset
, address
,
712 stream
, format
, deref_ref
, recurse
, pretty
);
713 if (ada_is_tag_type (type
))
716 value_from_contents_and_address (type
, valaddr
, address
);
717 const char *name
= ada_tag_name (val
);
719 fprintf_filtered (stream
, " (%s)", name
);
726 case TYPE_CODE_RANGE
:
727 if (ada_is_fixed_point_type (type
))
729 LONGEST v
= unpack_long (type
, valaddr
);
730 int len
= TYPE_LENGTH (type
);
732 fprintf_filtered (stream
, len
< 4 ? "%.11g" : "%.17g",
733 (double) ada_fixed_to_float (type
, v
));
736 else if (ada_is_vax_floating_type (type
))
739 value_from_contents_and_address (type
, valaddr
, address
);
740 struct value
*func
= ada_vax_float_print_function (type
);
743 static struct type
*parray_of_char
= NULL
;
744 struct value
*printable_val
;
746 if (parray_of_char
== NULL
)
750 (NULL
, builtin_type_char
,
751 create_range_type (NULL
, builtin_type_int
, 0, 32)), NULL
);
754 value_ind (value_cast (parray_of_char
,
755 call_function_by_hand (func
, 1,
758 fprintf_filtered (stream
, "%s", value_contents (printable_val
));
761 /* No special printing function. Do as best we can. */
763 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
765 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
766 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
768 /* Obscure case of range type that has different length from
769 its base type. Perform a conversion, or we will get a
770 nonsense value. Actually, we could use the same
771 code regardless of lengths; I'm just avoiding a cast. */
772 struct value
*v
= value_cast (target_type
,
773 value_from_contents_and_address
775 return ada_val_print_1 (target_type
, value_contents (v
), 0, 0,
776 stream
, format
, 0, recurse
+ 1, pretty
);
779 return ada_val_print_1 (TYPE_TARGET_TYPE (type
),
780 valaddr0
, embedded_offset
,
781 address
, stream
, format
, deref_ref
,
786 format
= format
? format
: output_format
;
789 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
791 else if (ada_is_system_address_type (type
))
793 /* FIXME: We want to print System.Address variables using
794 the same format as for any access type. But for some
795 reason GNAT encodes the System.Address type as an int,
796 so we have to work-around this deficiency by handling
797 System.Address values as a special case. */
798 fprintf_filtered (stream
, "(");
799 type_print (type
, "", stream
, -1);
800 fprintf_filtered (stream
, ") ");
801 fputs_filtered (paddress (extract_typed_address
802 (valaddr
, builtin_type_void_data_ptr
)),
807 val_print_type_code_int (type
, valaddr
, stream
);
808 if (ada_is_character_type (type
))
810 fputs_filtered (" ", stream
);
811 ada_printchar ((unsigned char) unpack_long (type
, valaddr
),
821 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
824 len
= TYPE_NFIELDS (type
);
825 val
= unpack_long (type
, valaddr
);
826 for (i
= 0; i
< len
; i
++)
829 if (val
== TYPE_FIELD_BITPOS (type
, i
))
836 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
838 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
840 fputs_filtered (name
, stream
);
844 print_longest (stream
, 'd', 0, val
);
848 case TYPE_CODE_FLAGS
:
850 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
852 val_print_type_code_flags (type
, valaddr
, stream
);
857 return c_val_print (type
, valaddr0
, embedded_offset
, address
, stream
,
858 format
, deref_ref
, recurse
, pretty
);
860 ada_print_floating (valaddr0
+ embedded_offset
, type
, stream
);
863 case TYPE_CODE_UNION
:
864 case TYPE_CODE_STRUCT
:
865 if (ada_is_bogus_array_descriptor (type
))
867 fprintf_filtered (stream
, "(...?)");
872 print_record (type
, valaddr
, stream
, format
, recurse
, pretty
);
876 case TYPE_CODE_ARRAY
:
877 return ada_val_print_array (type
, valaddr
, address
, stream
, format
,
878 deref_ref
, recurse
, pretty
);
881 /* For references, the debugger is expected to print the value as
882 an address if DEREF_REF is null. But printing an address in place
883 of the object value would be confusing to an Ada programmer.
884 So, for Ada values, we print the actual dereferenced value
886 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
888 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
890 LONGEST deref_val_int
= (LONGEST
)
891 unpack_pointer (lookup_pointer_type (builtin_type_void
),
893 if (deref_val_int
!= 0)
895 struct value
*deref_val
=
896 ada_value_ind (value_from_longest
897 (lookup_pointer_type (elttype
),
899 val_print (value_type (deref_val
),
900 value_contents (deref_val
), 0,
901 VALUE_ADDRESS (deref_val
), stream
, format
,
902 deref_ref
, recurse
+ 1, pretty
, current_language
);
905 fputs_filtered ("(null)", stream
);
908 fputs_filtered ("???", stream
);
917 print_variant_part (struct type
*type
, int field_num
, const gdb_byte
*valaddr
,
918 struct ui_file
*stream
, int format
, int recurse
,
919 enum val_prettyprint pretty
, int comma_needed
,
920 struct type
*outer_type
, const gdb_byte
*outer_valaddr
)
922 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
923 int which
= ada_which_variant_applies (var_type
, outer_type
, outer_valaddr
);
928 return print_field_values
929 (TYPE_FIELD_TYPE (var_type
, which
),
930 valaddr
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
931 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
932 stream
, format
, recurse
, pretty
,
933 comma_needed
, outer_type
, outer_valaddr
);
937 ada_value_print (struct value
*val0
, struct ui_file
*stream
, int format
,
938 enum val_prettyprint pretty
)
940 const gdb_byte
*valaddr
= value_contents (val0
);
941 CORE_ADDR address
= VALUE_ADDRESS (val0
) + value_offset (val0
);
943 ada_to_fixed_type (value_type (val0
), valaddr
, address
, NULL
, 1);
945 value_from_contents_and_address (type
, valaddr
, address
);
947 /* If it is a pointer, indicate what it points to. */
948 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
950 /* Hack: don't print (char *) for char strings. Their
951 type is indicated by the quoted string anyway. */
952 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
953 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
954 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
956 fprintf_filtered (stream
, "(");
957 type_print (type
, "", stream
, -1);
958 fprintf_filtered (stream
, ") ");
961 else if (ada_is_array_descriptor_type (type
))
963 fprintf_filtered (stream
, "(");
964 type_print (type
, "", stream
, -1);
965 fprintf_filtered (stream
, ") ");
967 else if (ada_is_bogus_array_descriptor (type
))
969 fprintf_filtered (stream
, "(");
970 type_print (type
, "", stream
, -1);
971 fprintf_filtered (stream
, ") (...?)");
975 return (val_print (type
, value_contents (val
), 0, address
,
976 stream
, format
, 1, 0, pretty
, current_language
));
980 print_record (struct type
*type
, const gdb_byte
*valaddr
,
981 struct ui_file
*stream
, int format
, int recurse
,
982 enum val_prettyprint pretty
)
984 type
= ada_check_typedef (type
);
986 fprintf_filtered (stream
, "(");
988 if (print_field_values (type
, valaddr
, stream
, format
, recurse
, pretty
,
989 0, type
, valaddr
) != 0 && pretty
)
991 fprintf_filtered (stream
, "\n");
992 print_spaces_filtered (2 * recurse
, stream
);
995 fprintf_filtered (stream
, ")");
998 /* Print out fields of value at VALADDR having structure type TYPE.
1000 TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the
1001 same meanings as in ada_print_value and ada_val_print.
1003 OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record
1004 (used to get discriminant values when printing variant parts).
1006 COMMA_NEEDED is 1 if fields have been printed at the current recursion
1007 level, so that a comma is needed before any field printed by this
1010 Returns 1 if COMMA_NEEDED or any fields were printed. */
1013 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
1014 struct ui_file
*stream
, int format
, int recurse
,
1015 enum val_prettyprint pretty
, int comma_needed
,
1016 struct type
*outer_type
, const gdb_byte
*outer_valaddr
)
1020 len
= TYPE_NFIELDS (type
);
1022 for (i
= 0; i
< len
; i
+= 1)
1024 if (ada_is_ignored_field (type
, i
))
1027 if (ada_is_wrapper_field (type
, i
))
1030 print_field_values (TYPE_FIELD_TYPE (type
, i
),
1032 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1033 stream
, format
, recurse
, pretty
,
1034 comma_needed
, type
, valaddr
);
1037 else if (ada_is_variant_part (type
, i
))
1040 print_variant_part (type
, i
, valaddr
,
1041 stream
, format
, recurse
, pretty
, comma_needed
,
1042 outer_type
, outer_valaddr
);
1047 fprintf_filtered (stream
, ", ");
1052 fprintf_filtered (stream
, "\n");
1053 print_spaces_filtered (2 + 2 * recurse
, stream
);
1057 wrap_here (n_spaces (2 + 2 * recurse
));
1061 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
1062 fputs_filtered ("\"( ptr \"", stream
);
1064 fputs_filtered ("\"( nodef \"", stream
);
1065 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1066 language_cplus
, DMGL_NO_OPTS
);
1067 fputs_filtered ("\" \"", stream
);
1068 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1069 language_cplus
, DMGL_NO_OPTS
);
1070 fputs_filtered ("\") \"", stream
);
1074 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
1075 fprintf_filtered (stream
, "%.*s",
1076 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
1077 TYPE_FIELD_NAME (type
, i
));
1078 annotate_field_name_end ();
1079 fputs_filtered (" => ", stream
);
1080 annotate_field_value ();
1083 if (TYPE_FIELD_PACKED (type
, i
))
1087 /* Bitfields require special handling, especially due to byte
1089 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
1090 && TYPE_FIELD_IGNORE (type
, i
))
1092 fputs_filtered (_("<optimized out or zero length>"), stream
);
1096 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
1097 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
1099 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
1100 v
= ada_value_primitive_packed_val (NULL
, valaddr
,
1101 bit_pos
/ HOST_CHAR_BIT
,
1102 bit_pos
% HOST_CHAR_BIT
,
1104 TYPE_FIELD_TYPE (type
, i
));
1105 val_print (TYPE_FIELD_TYPE (type
, i
), value_contents (v
), 0, 0,
1106 stream
, format
, 0, recurse
+ 1, pretty
,
1111 ada_val_print (TYPE_FIELD_TYPE (type
, i
),
1112 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
,
1113 0, 0, stream
, format
, 0, recurse
+ 1, pretty
);
1114 annotate_field_end ();
1117 return comma_needed
;