1 /* Support for printing Ada values for GDB, the GNU debugger.
3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_string.h"
25 #include "expression.h"
34 #include "exceptions.h"
37 static void print_record (struct type
*, const gdb_byte
*, int,
41 const struct value_print_options
*);
43 static int print_field_values (struct type
*, const gdb_byte
*,
45 struct ui_file
*, int,
47 const struct value_print_options
*,
48 int, struct type
*, int);
50 static void adjust_type_signedness (struct type
*);
52 static void ada_val_print_1 (struct type
*, const gdb_byte
*, int, CORE_ADDR
,
53 struct ui_file
*, int,
55 const struct value_print_options
*);
58 /* Make TYPE unsigned if its range of values includes no negatives. */
60 adjust_type_signedness (struct type
*type
)
62 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
63 && TYPE_LOW_BOUND (type
) >= 0)
64 TYPE_UNSIGNED (type
) = 1;
67 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
68 if non-standard (i.e., other than 1 for numbers, other than lower bound
69 of index type for enumerated type). Returns 1 if something printed,
73 print_optional_low_bound (struct ui_file
*stream
, struct type
*type
,
74 const struct value_print_options
*options
)
76 struct type
*index_type
;
80 if (options
->print_array_indexes
)
83 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
86 /* If this is an empty array, then don't print the lower bound.
87 That would be confusing, because we would print the lower bound,
88 followed by... nothing! */
89 if (low_bound
> high_bound
)
92 index_type
= TYPE_INDEX_TYPE (type
);
94 if (TYPE_CODE (index_type
) == TYPE_CODE_RANGE
)
96 /* We need to know what the base type is, in order to do the
97 appropriate check below. Otherwise, if this is a subrange
98 of an enumerated type, where the underlying value of the
99 first element is typically 0, we might test the low bound
100 against the wrong value. */
101 index_type
= TYPE_TARGET_TYPE (index_type
);
104 switch (TYPE_CODE (index_type
))
111 if (low_bound
== TYPE_FIELD_ENUMVAL (index_type
, 0))
114 case TYPE_CODE_UNDEF
:
123 ada_print_scalar (index_type
, low_bound
, stream
);
124 fprintf_filtered (stream
, " => ");
128 /* Version of val_print_array_elements for GNAT-style packed arrays.
129 Prints elements of packed array of type TYPE at bit offset
130 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
131 separates with commas. RECURSE is the recursion (nesting) level.
132 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
135 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
+ offset
,
189 (i0
* bitsize
) / HOST_CHAR_BIT
,
190 (i0
* bitsize
) % HOST_CHAR_BIT
,
197 v1
= ada_value_primitive_packed_val (NULL
, valaddr
+ offset
,
198 (i
* bitsize
) / HOST_CHAR_BIT
,
199 (i
* bitsize
) % HOST_CHAR_BIT
,
201 if (!value_available_contents_eq (v0
, value_embedded_offset (v0
),
202 v1
, value_embedded_offset (v1
),
207 if (i
- i0
> options
->repeat_count_threshold
)
209 struct value_print_options opts
= *options
;
212 val_print (elttype
, value_contents_for_printing (v0
),
213 value_embedded_offset (v0
), 0, stream
,
214 recurse
+ 1, v0
, &opts
, current_language
);
215 annotate_elt_rep (i
- i0
);
216 fprintf_filtered (stream
, _(" <repeats %u times>"), i
- i0
);
217 annotate_elt_rep_end ();
223 struct value_print_options opts
= *options
;
226 for (j
= i0
; j
< i
; j
+= 1)
230 if (options
->prettyprint_arrays
)
232 fprintf_filtered (stream
, ",\n");
233 print_spaces_filtered (2 + 2 * recurse
, stream
);
237 fprintf_filtered (stream
, ", ");
239 wrap_here (n_spaces (2 + 2 * recurse
));
240 maybe_print_array_index (index_type
, j
+ low
,
243 val_print (elttype
, value_contents_for_printing (v0
),
244 value_embedded_offset (v0
), 0, stream
,
245 recurse
+ 1, v0
, &opts
, current_language
);
249 things_printed
+= i
- i0
;
251 annotate_array_section_end ();
254 fprintf_filtered (stream
, "...");
257 value_free_to_mark (mark
);
261 printable_val_type (struct type
*type
, const gdb_byte
*valaddr
)
263 return ada_to_fixed_type (ada_aligned_type (type
), valaddr
, 0, NULL
, 1);
266 /* Print the character C on STREAM as part of the contents of a literal
267 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
271 ada_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
272 int quoter
, int type_len
)
274 /* If this character fits in the normal ASCII range, and is
275 a printable character, then print the character as if it was
276 an ASCII character, even if this is a wide character.
277 The UCHAR_MAX check is necessary because the isascii function
278 requires that its argument have a value of an unsigned char,
279 or EOF (EOF is obviously not printable). */
280 if (c
<= UCHAR_MAX
&& isascii (c
) && isprint (c
))
282 if (c
== quoter
&& c
== '"')
283 fprintf_filtered (stream
, "\"\"");
285 fprintf_filtered (stream
, "%c", c
);
288 fprintf_filtered (stream
, "[\"%0*x\"]", type_len
* 2, c
);
291 /* Character #I of STRING, given that TYPE_LEN is the size in bytes
295 char_at (const gdb_byte
*string
, int i
, int type_len
,
296 enum bfd_endian byte_order
)
301 return (int) extract_unsigned_integer (string
+ type_len
* i
,
302 type_len
, byte_order
);
305 /* Wrapper around memcpy to make it legal argument to ui_file_put. */
307 ui_memcpy (void *dest
, const char *buffer
, long len
)
309 memcpy (dest
, buffer
, (size_t) len
);
310 ((char *) dest
)[len
] = '\0';
313 /* Print a floating-point value of type TYPE, pointed to in GDB by
314 VALADDR, on STREAM. Use Ada formatting conventions: there must be
315 a decimal point, and at least one digit before and after the
316 point. We use GNAT format for NaNs and infinities. */
318 ada_print_floating (const gdb_byte
*valaddr
, struct type
*type
,
319 struct ui_file
*stream
)
324 struct ui_file
*tmp_stream
= mem_fileopen ();
325 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_stream
);
327 print_floating (valaddr
, type
, tmp_stream
);
328 ui_file_put (tmp_stream
, ui_memcpy
, buffer
);
329 do_cleanups (cleanups
);
332 len
= strlen (result
);
334 /* Modify for Ada rules. */
336 s
= strstr (result
, "inf");
338 s
= strstr (result
, "Inf");
340 s
= strstr (result
, "INF");
346 s
= strstr (result
, "nan");
348 s
= strstr (result
, "NaN");
350 s
= strstr (result
, "Nan");
354 if (result
[0] == '-')
359 if (s
== NULL
&& strchr (result
, '.') == NULL
)
361 s
= strchr (result
, 'e');
363 fprintf_filtered (stream
, "%s.0", result
);
365 fprintf_filtered (stream
, "%.*s.0%s", (int) (s
-result
), result
, s
);
368 fprintf_filtered (stream
, "%s", result
);
372 ada_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
374 fputs_filtered ("'", stream
);
375 ada_emit_char (c
, type
, stream
, '\'', TYPE_LENGTH (type
));
376 fputs_filtered ("'", stream
);
379 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
380 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
381 like a default signed integer. */
384 ada_print_scalar (struct type
*type
, LONGEST val
, struct ui_file
*stream
)
391 print_longest (stream
, 'd', 0, val
);
395 type
= ada_check_typedef (type
);
397 switch (TYPE_CODE (type
))
401 len
= TYPE_NFIELDS (type
);
402 for (i
= 0; i
< len
; i
++)
404 if (TYPE_FIELD_ENUMVAL (type
, i
) == val
)
411 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type
, i
)), stream
);
415 print_longest (stream
, 'd', 0, val
);
420 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0, val
);
424 LA_PRINT_CHAR (val
, type
, stream
);
428 fprintf_filtered (stream
, val
? "true" : "false");
431 case TYPE_CODE_RANGE
:
432 ada_print_scalar (TYPE_TARGET_TYPE (type
), val
, stream
);
435 case TYPE_CODE_UNDEF
:
437 case TYPE_CODE_ARRAY
:
438 case TYPE_CODE_STRUCT
:
439 case TYPE_CODE_UNION
:
444 case TYPE_CODE_STRING
:
445 case TYPE_CODE_ERROR
:
446 case TYPE_CODE_MEMBERPTR
:
447 case TYPE_CODE_METHODPTR
:
448 case TYPE_CODE_METHOD
:
450 warning (_("internal error: unhandled type in ada_print_scalar"));
454 error (_("Invalid type code in symbol table."));
459 /* Print the character string STRING, printing at most LENGTH characters.
460 Printing stops early if the number hits print_max; repeat counts
461 are printed as appropriate. Print ellipses at the end if we
462 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
463 TYPE_LEN is the length (1 or 2) of the character type. */
466 printstr (struct ui_file
*stream
, struct type
*elttype
, const gdb_byte
*string
,
467 unsigned int length
, int force_ellipses
, int type_len
,
468 const struct value_print_options
*options
)
470 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (elttype
));
472 unsigned int things_printed
= 0;
478 fputs_filtered ("\"\"", stream
);
482 for (i
= 0; i
< length
&& things_printed
< options
->print_max
; i
+= 1)
484 /* Position of the character we are examining
485 to see whether it is repeated. */
487 /* Number of repetitions we have detected so far. */
494 fputs_filtered (", ", stream
);
501 && char_at (string
, rep1
, type_len
, byte_order
)
502 == char_at (string
, i
, type_len
, byte_order
))
508 if (reps
> options
->repeat_count_threshold
)
512 if (options
->inspect_it
)
513 fputs_filtered ("\\\", ", stream
);
515 fputs_filtered ("\", ", stream
);
518 fputs_filtered ("'", stream
);
519 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
520 elttype
, stream
, '\'', type_len
);
521 fputs_filtered ("'", stream
);
522 fprintf_filtered (stream
, _(" <repeats %u times>"), reps
);
524 things_printed
+= options
->repeat_count_threshold
;
531 if (options
->inspect_it
)
532 fputs_filtered ("\\\"", stream
);
534 fputs_filtered ("\"", stream
);
537 ada_emit_char (char_at (string
, i
, type_len
, byte_order
),
538 elttype
, stream
, '"', type_len
);
543 /* Terminate the quotes if necessary. */
546 if (options
->inspect_it
)
547 fputs_filtered ("\\\"", stream
);
549 fputs_filtered ("\"", stream
);
552 if (force_ellipses
|| i
< length
)
553 fputs_filtered ("...", stream
);
557 ada_printstr (struct ui_file
*stream
, struct type
*type
,
558 const gdb_byte
*string
, unsigned int length
,
559 const char *encoding
, int force_ellipses
,
560 const struct value_print_options
*options
)
562 printstr (stream
, type
, string
, length
, force_ellipses
, TYPE_LENGTH (type
),
567 /* See val_print for a description of the various parameters of this
568 function; they are identical. */
571 ada_val_print (struct type
*type
, const gdb_byte
*valaddr
,
572 int embedded_offset
, CORE_ADDR address
,
573 struct ui_file
*stream
, int recurse
,
574 const struct value
*val
,
575 const struct value_print_options
*options
)
577 volatile struct gdb_exception except
;
579 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */
580 TRY_CATCH (except
, RETURN_MASK_ALL
)
582 ada_val_print_1 (type
, valaddr
, embedded_offset
, address
,
583 stream
, recurse
, val
, options
);
587 /* Assuming TYPE is a simple array, print the value of this array located
588 at VALADDR + OFFSET. See ada_val_print for a description of the various
589 parameters of this function; they are identical. */
592 ada_val_print_array (struct type
*type
, const gdb_byte
*valaddr
,
593 int offset
, CORE_ADDR address
,
594 struct ui_file
*stream
, int recurse
,
595 const struct value
*val
,
596 const struct value_print_options
*options
)
598 /* For an array of chars, print with string syntax. */
599 if (ada_is_string_type (type
)
600 && (options
->format
== 0 || options
->format
== 's'))
602 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (type
));
603 struct type
*elttype
= TYPE_TARGET_TYPE (type
);
607 /* We know that ELTTYPE cannot possibly be null, because we found
608 that TYPE is a string-like type. Similarly, the size of ELTTYPE
609 should also be non-null, since it's a character-like type. */
610 gdb_assert (elttype
!= NULL
);
611 gdb_assert (TYPE_LENGTH (elttype
) != 0);
613 eltlen
= TYPE_LENGTH (elttype
);
614 len
= TYPE_LENGTH (type
) / eltlen
;
616 if (options
->prettyprint_arrays
)
617 print_spaces_filtered (2 + 2 * recurse
, stream
);
619 /* If requested, look for the first null char and only print
620 elements up to it. */
621 if (options
->stop_print_at_null
)
625 /* Look for a NULL char. */
628 && temp_len
< options
->print_max
629 && char_at (valaddr
+ offset
,
630 temp_len
, eltlen
, byte_order
) != 0);
635 printstr (stream
, elttype
, valaddr
+ offset
, len
, 0, eltlen
, options
);
639 fprintf_filtered (stream
, "(");
640 print_optional_low_bound (stream
, type
, options
);
641 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
642 val_print_packed_array_elements (type
, valaddr
, offset
,
643 0, stream
, recurse
, val
, options
);
645 val_print_array_elements (type
, valaddr
, offset
, address
,
646 stream
, recurse
, val
, options
, 0);
647 fprintf_filtered (stream
, ")");
651 /* See the comment on ada_val_print. This function differs in that it
652 does not catch evaluation errors (leaving that to ada_val_print). */
655 ada_val_print_1 (struct type
*type
, const gdb_byte
*valaddr
,
656 int offset
, CORE_ADDR address
,
657 struct ui_file
*stream
, int recurse
,
658 const struct value
*original_value
,
659 const struct value_print_options
*options
)
662 struct type
*elttype
;
665 type
= ada_check_typedef (type
);
667 if (ada_is_array_descriptor_type (type
)
668 || (ada_is_constrained_packed_array_type (type
)
669 && TYPE_CODE (type
) != TYPE_CODE_PTR
))
671 struct value
*mark
= value_mark ();
674 val
= value_from_contents_and_address (type
, valaddr
+ offset
, address
);
675 /* If this is a reference, coerce it now. This helps taking care
676 of the case where ADDRESS is meaningless because original_value
678 val
= coerce_ref (val
);
679 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
) /* array access type. */
680 val
= ada_coerce_to_simple_array_ptr (val
);
682 val
= ada_coerce_to_simple_array (val
);
685 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
);
686 fprintf_filtered (stream
, "0x0");
689 ada_val_print_1 (value_type (val
),
690 value_contents_for_printing (val
),
691 value_embedded_offset (val
),
692 value_address (val
), stream
, recurse
,
694 value_free_to_mark (mark
);
698 offset_aligned
= offset
+ ada_aligned_value_addr (type
, valaddr
) - valaddr
;
699 type
= printable_val_type (type
, valaddr
+ offset_aligned
);
701 switch (TYPE_CODE (type
))
704 c_val_print (type
, valaddr
, offset
, address
, stream
,
705 recurse
, original_value
, options
);
710 c_val_print (type
, valaddr
, offset
, address
,
711 stream
, recurse
, original_value
, options
);
713 if (ada_is_tag_type (type
))
716 value_from_contents_and_address (type
,
717 valaddr
+ offset_aligned
,
718 address
+ offset_aligned
);
719 const char *name
= ada_tag_name (val
);
722 fprintf_filtered (stream
, " (%s)", name
);
728 case TYPE_CODE_RANGE
:
729 if (ada_is_fixed_point_type (type
))
731 LONGEST v
= unpack_long (type
, valaddr
+ offset_aligned
);
733 fprintf_filtered (stream
, TYPE_LENGTH (type
) < 4 ? "%.11g" : "%.17g",
734 (double) ada_fixed_to_float (type
, v
));
737 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
739 struct type
*target_type
= TYPE_TARGET_TYPE (type
);
741 if (TYPE_LENGTH (type
) != TYPE_LENGTH (target_type
))
743 /* Obscure case of range type that has different length from
744 its base type. Perform a conversion, or we will get a
745 nonsense value. Actually, we could use the same
746 code regardless of lengths; I'm just avoiding a cast. */
748 = value_from_contents_and_address (type
, valaddr
+ offset
, 0);
749 struct value
*v
= value_cast (target_type
, v1
);
751 ada_val_print_1 (target_type
,
752 value_contents_for_printing (v
),
753 value_embedded_offset (v
), 0,
754 stream
, recurse
+ 1, v
, options
);
757 ada_val_print_1 (TYPE_TARGET_TYPE (type
),
759 address
, stream
, recurse
,
760 original_value
, options
);
765 int format
= (options
->format
? options
->format
766 : options
->output_format
);
770 struct value_print_options opts
= *options
;
772 opts
.format
= format
;
773 val_print_scalar_formatted (type
, valaddr
, offset_aligned
,
774 original_value
, &opts
, 0, stream
);
776 else if (ada_is_system_address_type (type
))
778 /* FIXME: We want to print System.Address variables using
779 the same format as for any access type. But for some
780 reason GNAT encodes the System.Address type as an int,
781 so we have to work-around this deficiency by handling
782 System.Address values as a special case. */
784 struct gdbarch
*gdbarch
= get_type_arch (type
);
785 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
786 CORE_ADDR addr
= extract_typed_address (valaddr
+ offset_aligned
,
789 fprintf_filtered (stream
, "(");
790 type_print (type
, "", stream
, -1);
791 fprintf_filtered (stream
, ") ");
792 fputs_filtered (paddress (gdbarch
, addr
), stream
);
796 val_print_type_code_int (type
, valaddr
+ offset_aligned
, stream
);
797 if (ada_is_character_type (type
))
801 fputs_filtered (" ", stream
);
802 c
= unpack_long (type
, valaddr
+ offset_aligned
);
803 ada_printchar (c
, type
, stream
);
816 val_print_scalar_formatted (type
, valaddr
, offset_aligned
,
817 original_value
, options
, 0, stream
);
820 len
= TYPE_NFIELDS (type
);
821 val
= unpack_long (type
, valaddr
+ offset_aligned
);
822 for (i
= 0; i
< len
; i
++)
825 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
832 const char *name
= ada_enum_name (TYPE_FIELD_NAME (type
, i
));
835 fprintf_filtered (stream
, "%ld %s", (long) val
, name
);
837 fputs_filtered (name
, stream
);
841 print_longest (stream
, 'd', 0, val
);
849 c_val_print (type
, valaddr
, offset
, address
, stream
,
850 recurse
, original_value
, options
);
854 ada_print_floating (valaddr
+ offset
, type
, stream
);
857 case TYPE_CODE_UNION
:
858 case TYPE_CODE_STRUCT
:
859 if (ada_is_bogus_array_descriptor (type
))
861 fprintf_filtered (stream
, "(...?)");
866 print_record (type
, valaddr
, offset_aligned
,
867 stream
, recurse
, original_value
, options
);
871 case TYPE_CODE_ARRAY
:
872 ada_val_print_array (type
, valaddr
, offset_aligned
,
873 address
, stream
, recurse
, original_value
,
878 /* For references, the debugger is expected to print the value as
879 an address if DEREF_REF is null. But printing an address in place
880 of the object value would be confusing to an Ada programmer.
881 So, for Ada values, we print the actual dereferenced value
883 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
885 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
887 CORE_ADDR deref_val_int
;
888 struct value
*deref_val
;
890 deref_val
= coerce_ref_if_computed (original_value
);
893 if (ada_is_tagged_type (value_type (deref_val
), 1))
894 deref_val
= ada_tag_value_at_base_address (deref_val
);
896 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
901 deref_val_int
= unpack_pointer (type
, valaddr
+ offset_aligned
);
902 if (deref_val_int
!= 0)
905 ada_value_ind (value_from_pointer
906 (lookup_pointer_type (elttype
),
909 if (ada_is_tagged_type (value_type (deref_val
), 1))
910 deref_val
= ada_tag_value_at_base_address (deref_val
);
912 val_print (value_type (deref_val
),
913 value_contents_for_printing (deref_val
),
914 value_embedded_offset (deref_val
),
915 value_address (deref_val
), stream
, recurse
+ 1,
916 deref_val
, options
, current_language
);
919 fputs_filtered ("(null)", stream
);
922 fputs_filtered ("???", stream
);
930 print_variant_part (struct type
*type
, int field_num
,
931 const gdb_byte
*valaddr
, int offset
,
932 struct ui_file
*stream
, int recurse
,
933 const struct value
*val
,
934 const struct value_print_options
*options
,
936 struct type
*outer_type
, int outer_offset
)
938 struct type
*var_type
= TYPE_FIELD_TYPE (type
, field_num
);
939 int which
= ada_which_variant_applies (var_type
, outer_type
,
940 valaddr
+ outer_offset
);
945 return print_field_values
946 (TYPE_FIELD_TYPE (var_type
, which
),
948 offset
+ TYPE_FIELD_BITPOS (type
, field_num
) / HOST_CHAR_BIT
949 + TYPE_FIELD_BITPOS (var_type
, which
) / HOST_CHAR_BIT
,
950 stream
, recurse
, val
, options
,
951 comma_needed
, outer_type
, outer_offset
);
955 ada_value_print (struct value
*val0
, struct ui_file
*stream
,
956 const struct value_print_options
*options
)
958 struct value
*val
= ada_to_fixed_value (val0
);
959 CORE_ADDR address
= value_address (val
);
960 struct type
*type
= ada_check_typedef (value_type (val
));
961 struct value_print_options opts
;
963 /* If it is a pointer, indicate what it points to. */
964 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
966 /* Hack: don't print (char *) for char strings. Their
967 type is indicated by the quoted string anyway. */
968 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) != sizeof (char)
969 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_INT
970 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
972 fprintf_filtered (stream
, "(");
973 type_print (type
, "", stream
, -1);
974 fprintf_filtered (stream
, ") ");
977 else if (ada_is_array_descriptor_type (type
))
979 /* We do not print the type description unless TYPE is an array
980 access type (this is encoded by the compiler as a typedef to
981 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
982 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
984 fprintf_filtered (stream
, "(");
985 type_print (type
, "", stream
, -1);
986 fprintf_filtered (stream
, ") ");
989 else if (ada_is_bogus_array_descriptor (type
))
991 fprintf_filtered (stream
, "(");
992 type_print (type
, "", stream
, -1);
993 fprintf_filtered (stream
, ") (...?)");
999 val_print (type
, value_contents_for_printing (val
),
1000 value_embedded_offset (val
), address
,
1001 stream
, 0, val
, &opts
, current_language
);
1005 print_record (struct type
*type
, const gdb_byte
*valaddr
,
1007 struct ui_file
*stream
, int recurse
,
1008 const struct value
*val
,
1009 const struct value_print_options
*options
)
1011 type
= ada_check_typedef (type
);
1013 fprintf_filtered (stream
, "(");
1015 if (print_field_values (type
, valaddr
, offset
,
1016 stream
, recurse
, val
, options
,
1017 0, type
, offset
) != 0 && options
->pretty
)
1019 fprintf_filtered (stream
, "\n");
1020 print_spaces_filtered (2 * recurse
, stream
);
1023 fprintf_filtered (stream
, ")");
1026 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
1028 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
1029 meanings as in ada_print_value and ada_val_print.
1031 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
1032 record (used to get discriminant values when printing variant
1035 COMMA_NEEDED is 1 if fields have been printed at the current recursion
1036 level, so that a comma is needed before any field printed by this
1039 Returns 1 if COMMA_NEEDED or any fields were printed. */
1042 print_field_values (struct type
*type
, const gdb_byte
*valaddr
,
1043 int offset
, struct ui_file
*stream
, int recurse
,
1044 const struct value
*val
,
1045 const struct value_print_options
*options
,
1047 struct type
*outer_type
, int outer_offset
)
1051 len
= TYPE_NFIELDS (type
);
1053 for (i
= 0; i
< len
; i
+= 1)
1055 if (ada_is_ignored_field (type
, i
))
1058 if (ada_is_wrapper_field (type
, i
))
1061 print_field_values (TYPE_FIELD_TYPE (type
, i
),
1064 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
1065 stream
, recurse
, val
, options
,
1066 comma_needed
, type
, offset
);
1069 else if (ada_is_variant_part (type
, i
))
1072 print_variant_part (type
, i
, valaddr
,
1073 offset
, stream
, recurse
, val
,
1074 options
, comma_needed
,
1075 outer_type
, outer_offset
);
1080 fprintf_filtered (stream
, ", ");
1083 if (options
->pretty
)
1085 fprintf_filtered (stream
, "\n");
1086 print_spaces_filtered (2 + 2 * recurse
, stream
);
1090 wrap_here (n_spaces (2 + 2 * recurse
));
1092 if (options
->inspect_it
)
1094 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
1095 fputs_filtered ("\"( ptr \"", stream
);
1097 fputs_filtered ("\"( nodef \"", stream
);
1098 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1099 language_cplus
, DMGL_NO_OPTS
);
1100 fputs_filtered ("\" \"", stream
);
1101 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
1102 language_cplus
, DMGL_NO_OPTS
);
1103 fputs_filtered ("\") \"", stream
);
1107 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
1108 fprintf_filtered (stream
, "%.*s",
1109 ada_name_prefix_len (TYPE_FIELD_NAME (type
, i
)),
1110 TYPE_FIELD_NAME (type
, i
));
1111 annotate_field_name_end ();
1112 fputs_filtered (" => ", stream
);
1113 annotate_field_value ();
1116 if (TYPE_FIELD_PACKED (type
, i
))
1120 /* Bitfields require special handling, especially due to byte
1122 if (HAVE_CPLUS_STRUCT (type
) && TYPE_FIELD_IGNORE (type
, i
))
1124 fputs_filtered (_("<optimized out or zero length>"), stream
);
1128 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
1129 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
1130 struct value_print_options opts
;
1132 adjust_type_signedness (TYPE_FIELD_TYPE (type
, i
));
1133 v
= ada_value_primitive_packed_val
1135 offset
+ bit_pos
/ HOST_CHAR_BIT
,
1136 bit_pos
% HOST_CHAR_BIT
,
1137 bit_size
, TYPE_FIELD_TYPE (type
, i
));
1140 val_print (TYPE_FIELD_TYPE (type
, i
),
1141 value_contents_for_printing (v
),
1142 value_embedded_offset (v
), 0,
1143 stream
, recurse
+ 1, v
,
1144 &opts
, current_language
);
1149 struct value_print_options opts
= *options
;
1152 ada_val_print (TYPE_FIELD_TYPE (type
, i
),
1155 + TYPE_FIELD_BITPOS (type
, i
) / HOST_CHAR_BIT
),
1156 0, stream
, recurse
+ 1, val
, &opts
);
1158 annotate_field_end ();
1161 return comma_needed
;