1 /* Support for printing Ada types for GDB, the GNU debugger.
2 Copyright (C) 1986-2024 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "cli/cli-style.h"
24 #include "typeprint.h"
25 #include "target-float.h"
29 static int print_selected_record_field_types (struct type
*, struct type
*,
31 struct ui_file
*, int, int,
32 const struct type_print_options
*);
34 static int print_record_field_types (struct type
*, struct type
*,
35 struct ui_file
*, int, int,
36 const struct type_print_options
*);
40 static char *name_buffer
;
41 static int name_buffer_len
;
43 /* The (decoded) Ada name of TYPE. This value persists until the
47 decoded_type_name (struct type
*type
)
49 if (ada_type_name (type
) == NULL
)
53 const char *raw_name
= ada_type_name (type
);
56 if (name_buffer
== NULL
|| name_buffer_len
<= strlen (raw_name
))
58 name_buffer_len
= 16 + 2 * strlen (raw_name
);
59 name_buffer
= (char *) xrealloc (name_buffer
, name_buffer_len
);
61 strcpy (name_buffer
, raw_name
);
63 s
= (char *) strstr (name_buffer
, "___");
67 s
= name_buffer
+ strlen (name_buffer
) - 1;
68 while (s
> name_buffer
&& (s
[0] != '_' || s
[-1] != '_'))
77 for (s
= q
= name_buffer
; *s
!= '\0'; q
+= 1)
79 if (s
[0] == '_' && s
[1] == '_')
95 /* Return nonzero if TYPE is a subrange type, and its bounds
96 are identical to the bounds of its subtype. */
99 type_is_full_subrange_of_target_type (struct type
*type
)
101 struct type
*subtype
;
103 if (type
->code () != TYPE_CODE_RANGE
)
106 subtype
= type
->target_type ();
110 if (is_dynamic_type (type
))
113 if (ada_discrete_type_low_bound (type
)
114 != ada_discrete_type_low_bound (subtype
))
117 if (ada_discrete_type_high_bound (type
)
118 != ada_discrete_type_high_bound (subtype
))
124 /* Print TYPE on STREAM, preferably as a range if BOUNDS_PREFERRED_P
128 print_range (struct type
*type
, struct ui_file
*stream
,
129 int bounds_preferred_p
)
131 if (!bounds_preferred_p
)
133 /* Try stripping all TYPE_CODE_RANGE layers whose bounds
134 are identical to the bounds of their subtype. When
135 the bounds of both types match, it can allow us to
136 print a range using the name of its base type, which
137 is easier to read. For instance, we would print...
139 array (character) of ...
143 array ('["00"]' .. '["ff"]') of ... */
144 while (type_is_full_subrange_of_target_type (type
))
145 type
= type
->target_type ();
148 switch (type
->code ())
150 case TYPE_CODE_RANGE
:
153 LONGEST lo
= 0, hi
= 0; /* init for gcc -Wall */
158 lo
= ada_discrete_type_low_bound (type
);
159 hi
= ada_discrete_type_high_bound (type
);
161 catch (const gdb_exception_error
&e
)
163 /* This can happen when the range is dynamic. Sometimes,
164 resolving dynamic property values requires us to have
165 access to an actual object, which is not available
166 when the user is using the "ptype" command on a type.
167 Print the range as an unbounded range. */
168 gdb_printf (stream
, "<>");
174 ada_print_scalar (type
, lo
, stream
);
175 gdb_printf (stream
, " .. ");
176 ada_print_scalar (type
, hi
, stream
);
181 gdb_printf (stream
, "%.*s",
182 ada_name_prefix_len (type
->name ()),
188 /* Print the number or discriminant bound at BOUNDS+*N on STREAM, and
189 set *N past the bound and its delimiter, if any. */
192 print_range_bound (struct type
*type
, const char *bounds
, int *n
,
193 struct ui_file
*stream
)
197 if (ada_scan_number (bounds
, *n
, &B
, n
))
199 /* STABS decodes all range types which bounds are 0 .. -1 as
200 unsigned integers (ie. the type code is TYPE_CODE_INT, not
201 TYPE_CODE_RANGE). Unfortunately, ada_print_scalar() relies
202 on the unsigned flag to determine whether the bound should
203 be printed as a signed or an unsigned value. This causes
204 the upper bound of the 0 .. -1 range types to be printed as
205 a very large unsigned number instead of -1.
206 To workaround this stabs deficiency, we replace the TYPE by NULL
207 to indicate default output when we detect that the bound is negative,
208 and the type is a TYPE_CODE_INT. The bound is negative when
209 'm' is the last character of the number scanned in BOUNDS. */
210 if (bounds
[*n
- 1] == 'm' && type
->code () == TYPE_CODE_INT
)
212 ada_print_scalar (type
, B
, stream
);
213 if (bounds
[*n
] == '_')
219 const char *bound
= bounds
+ *n
;
222 pend
= strstr (bound
, "__");
224 *n
+= bound_len
= strlen (bound
);
227 bound_len
= pend
- bound
;
230 gdb_printf (stream
, "%.*s", bound_len
, bound
);
234 /* Assuming NAME[0 .. NAME_LEN-1] is the name of a range type, print
235 the value (if found) of the bound indicated by SUFFIX ("___L" or
236 "___U") according to the ___XD conventions. */
239 print_dynamic_range_bound (struct type
*type
, const char *name
, int name_len
,
240 const char *suffix
, struct ui_file
*stream
)
243 std::string
name_buf (name
, name_len
);
246 if (get_int_var_value (name_buf
.c_str (), B
))
247 ada_print_scalar (type
, B
, stream
);
249 gdb_printf (stream
, "?");
252 /* Print RAW_TYPE as a range type, using any bound information
253 following the GNAT encoding (if available).
255 If BOUNDS_PREFERRED_P is nonzero, force the printing of the range
256 using its bounds. Otherwise, try printing the range without
257 printing the value of the bounds, if possible (this is only
258 considered a hint, not a guaranty). */
261 print_range_type (struct type
*raw_type
, struct ui_file
*stream
,
262 int bounds_preferred_p
)
265 struct type
*base_type
;
266 const char *subtype_info
;
268 gdb_assert (raw_type
!= NULL
);
269 name
= raw_type
->name ();
270 gdb_assert (name
!= NULL
);
272 if (raw_type
->code () == TYPE_CODE_RANGE
)
273 base_type
= raw_type
->target_type ();
275 base_type
= raw_type
;
277 subtype_info
= strstr (name
, "___XD");
278 if (subtype_info
== NULL
)
279 print_range (raw_type
, stream
, bounds_preferred_p
);
282 int prefix_len
= subtype_info
- name
;
283 const char *bounds_str
;
287 bounds_str
= strchr (subtype_info
, '_');
290 if (*subtype_info
== 'L')
292 print_range_bound (base_type
, bounds_str
, &n
, stream
);
296 print_dynamic_range_bound (base_type
, name
, prefix_len
, "___L",
299 gdb_printf (stream
, " .. ");
301 if (*subtype_info
== 'U')
302 print_range_bound (base_type
, bounds_str
, &n
, stream
);
304 print_dynamic_range_bound (base_type
, name
, prefix_len
, "___U",
309 /* Print enumerated type TYPE on STREAM. */
312 print_enum_type (struct type
*type
, struct ui_file
*stream
)
314 int len
= type
->num_fields ();
318 gdb_printf (stream
, "(");
319 stream
->wrap_here (1);
322 for (i
= 0; i
< len
; i
++)
326 gdb_printf (stream
, ", ");
327 stream
->wrap_here (4);
328 fputs_styled (ada_enum_name (type
->field (i
).name ()),
329 variable_name_style
.style (), stream
);
330 if (lastval
!= type
->field (i
).loc_enumval ())
332 gdb_printf (stream
, " => %s",
333 plongest (type
->field (i
).loc_enumval ()));
334 lastval
= type
->field (i
).loc_enumval ();
338 gdb_printf (stream
, ")");
341 /* Print simple (constrained) array type TYPE on STREAM. LEVEL is the
342 recursion (indentation) level, in case the element type itself has
343 nested structure, and SHOW is the number of levels of internal
344 structure to show (see ada_print_type). */
347 print_array_type (struct type
*type
, struct ui_file
*stream
, int show
,
348 int level
, const struct type_print_options
*flags
)
352 struct type
*elt_type
= NULL
;
354 if (ada_is_constrained_packed_array_type (type
))
355 type
= ada_coerce_to_simple_array_type (type
);
358 gdb_printf (stream
, "array (");
362 fprintf_styled (stream
, metadata_style
.style (),
363 _("<undecipherable array type>"));
368 if (ada_is_simple_array_type (type
))
370 struct type
*range_desc_type
;
371 struct type
*arr_type
;
373 range_desc_type
= ada_find_parallel_type (type
, "___XA");
374 ada_fixup_array_indexes_type (range_desc_type
);
377 if (range_desc_type
== NULL
)
379 for (arr_type
= type
; arr_type
->code () == TYPE_CODE_ARRAY
; )
381 if (arr_type
!= type
)
382 gdb_printf (stream
, ", ");
383 print_range (arr_type
->index_type (), stream
,
384 0 /* bounds_preferred_p */);
385 if (arr_type
->field (0).bitsize () > 0)
386 bitsize
= arr_type
->field (0).bitsize ();
387 /* A multi-dimensional array is represented using a
388 sequence of array types. If one of these types has a
389 name, then it is not another dimension of the outer
390 array, but rather the element type of the outermost
392 arr_type
= arr_type
->target_type ();
393 if (arr_type
->name () != nullptr)
401 n_indices
= range_desc_type
->num_fields ();
402 for (k
= 0, arr_type
= type
;
404 k
+= 1, arr_type
= arr_type
->target_type ())
407 gdb_printf (stream
, ", ");
408 print_range_type (range_desc_type
->field (k
).type (),
409 stream
, 0 /* bounds_preferred_p */);
410 if (arr_type
->field (0).bitsize () > 0)
411 bitsize
= arr_type
->field (0).bitsize ();
419 for (i
= i0
= ada_array_arity (type
); i
> 0; i
-= 1)
420 gdb_printf (stream
, "%s<>", i
== i0
? "" : ", ");
423 elt_type
= ada_array_element_type (type
, n_indices
);
424 gdb_printf (stream
, ") of ");
425 stream
->wrap_here (0);
426 ada_print_type (elt_type
, "", stream
, show
== 0 ? 0 : show
- 1, level
+ 1,
428 /* Arrays with variable-length elements are never bit-packed in practice but
429 compilers have to describe their stride so that we can properly fetch
430 individual elements. Do not say the array is packed in this case. */
431 if (bitsize
> 0 && !is_dynamic_type (elt_type
))
432 gdb_printf (stream
, " <packed: %d-bit elements>", bitsize
);
435 /* Print the choices encoded by field FIELD_NUM of variant-part TYPE on
436 STREAM, assuming that VAL_TYPE (if non-NULL) is the type of the
437 values. Return non-zero if the field is an encoding of
438 discriminant values, as in a standard variant record, and 0 if the
439 field is not so encoded (as happens with single-component variants
440 in types annotated with pragma Unchecked_Union). */
443 print_choices (struct type
*type
, int field_num
, struct ui_file
*stream
,
444 struct type
*val_type
)
448 const char *name
= type
->field (field_num
).name ();
452 /* Skip over leading 'V': NOTE soon to be obsolete. */
455 if (!ada_scan_number (name
, 1, NULL
, &p
))
469 gdb_printf (stream
, " =>");
475 gdb_printf (stream
, " | ");
486 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
488 ada_print_scalar (val_type
, W
, stream
);
495 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
496 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
498 ada_print_scalar (val_type
, L
, stream
);
499 gdb_printf (stream
, " .. ");
500 ada_print_scalar (val_type
, U
, stream
);
504 gdb_printf (stream
, "others");
511 gdb_printf (stream
, "? =>");
515 /* A helper for print_variant_clauses that prints the members of
516 VAR_TYPE. DISCR_TYPE is the type of the discriminant (or nullptr
517 if not available). The discriminant is contained in OUTER_TYPE.
518 STREAM, LEVEL, SHOW, and FLAGS are the same as for
522 print_variant_clauses (struct type
*var_type
, struct type
*discr_type
,
523 struct type
*outer_type
, struct ui_file
*stream
,
525 const struct type_print_options
*flags
)
527 for (int i
= 0; i
< var_type
->num_fields (); i
+= 1)
529 gdb_printf (stream
, "\n%*swhen ", level
, "");
530 if (print_choices (var_type
, i
, stream
, discr_type
))
532 if (print_record_field_types (var_type
->field (i
).type (),
533 outer_type
, stream
, show
, level
,
536 gdb_printf (stream
, " null;");
539 print_selected_record_field_types (var_type
, outer_type
, i
, i
,
540 stream
, show
, level
, flags
);
544 /* Assuming that field FIELD_NUM of TYPE represents variants whose
545 discriminant is contained in OUTER_TYPE, print its components on STREAM.
546 LEVEL is the recursion (indentation) level, in case any of the fields
547 themselves have nested structure, and SHOW is the number of levels of
548 internal structure to show (see ada_print_type). For this purpose,
549 fields nested in a variant part are taken to be at the same level as
550 the fields immediately outside the variant part. */
553 print_variant_clauses (struct type
*type
, int field_num
,
554 struct type
*outer_type
, struct ui_file
*stream
,
556 const struct type_print_options
*flags
)
558 struct type
*var_type
, *par_type
;
559 struct type
*discr_type
;
561 var_type
= type
->field (field_num
).type ();
562 discr_type
= ada_variant_discrim_type (var_type
, outer_type
);
564 if (var_type
->code () == TYPE_CODE_PTR
)
566 var_type
= var_type
->target_type ();
567 if (var_type
== NULL
|| var_type
->code () != TYPE_CODE_UNION
)
571 par_type
= ada_find_parallel_type (var_type
, "___XVU");
572 if (par_type
!= NULL
)
575 print_variant_clauses (var_type
, discr_type
, outer_type
, stream
, show
,
579 /* Assuming that field FIELD_NUM of TYPE is a variant part whose
580 discriminants are contained in OUTER_TYPE, print a description of it
581 on STREAM. LEVEL is the recursion (indentation) level, in case any of
582 the fields themselves have nested structure, and SHOW is the number of
583 levels of internal structure to show (see ada_print_type). For this
584 purpose, fields nested in a variant part are taken to be at the same
585 level as the fields immediately outside the variant part. */
588 print_variant_part (struct type
*type
, int field_num
, struct type
*outer_type
,
589 struct ui_file
*stream
, int show
, int level
,
590 const struct type_print_options
*flags
)
593 = ada_variant_discrim_name (type
->field (field_num
).type ());
594 if (*variant
== '\0')
597 gdb_printf (stream
, "\n%*scase %s is", level
+ 4, "", variant
);
598 print_variant_clauses (type
, field_num
, outer_type
, stream
, show
,
600 gdb_printf (stream
, "\n%*send case;", level
+ 4, "");
603 /* Print a description on STREAM of the fields FLD0 through FLD1 in
604 record or union type TYPE, whose discriminants are in OUTER_TYPE.
605 LEVEL is the recursion (indentation) level, in case any of the
606 fields themselves have nested structure, and SHOW is the number of
607 levels of internal structure to show (see ada_print_type). Does
608 not print parent type information of TYPE. Returns 0 if no fields
609 printed, -1 for an incomplete type, else > 0. Prints each field
610 beginning on a new line, but does not put a new line at end. */
613 print_selected_record_field_types (struct type
*type
, struct type
*outer_type
,
615 struct ui_file
*stream
, int show
, int level
,
616 const struct type_print_options
*flags
)
622 if (fld0
> fld1
&& type
->is_stub ())
625 for (i
= fld0
; i
<= fld1
; i
+= 1)
629 if (ada_is_parent_field (type
, i
) || ada_is_ignored_field (type
, i
))
631 else if (ada_is_wrapper_field (type
, i
))
632 flds
+= print_record_field_types (type
->field (i
).type (), type
,
633 stream
, show
, level
, flags
);
634 else if (ada_is_variant_part (type
, i
))
636 print_variant_part (type
, i
, outer_type
, stream
, show
, level
, flags
);
642 gdb_printf (stream
, "\n%*s", level
+ 4, "");
643 ada_print_type (type
->field (i
).type (),
644 type
->field (i
).name (),
645 stream
, show
- 1, level
+ 4, flags
);
646 gdb_printf (stream
, ";");
653 static void print_record_field_types_dynamic
654 (const gdb::array_view
<variant_part
> &parts
,
655 int from
, int to
, struct type
*type
, struct ui_file
*stream
,
656 int show
, int level
, const struct type_print_options
*flags
);
658 /* Print the choices encoded by VARIANT on STREAM. LEVEL is the
659 indentation level. The type of the discriminant for VARIANT is
660 given by DISR_TYPE. */
663 print_choices (struct type
*discr_type
, const variant
&variant
,
664 struct ui_file
*stream
, int level
)
666 gdb_printf (stream
, "\n%*swhen ", level
, "");
667 if (variant
.is_default ())
668 gdb_printf (stream
, "others");
672 for (const discriminant_range
&range
: variant
.discriminants
)
675 gdb_printf (stream
, " | ");
678 ada_print_scalar (discr_type
, range
.low
, stream
);
679 if (range
.low
!= range
.high
)
680 ada_print_scalar (discr_type
, range
.high
, stream
);
684 gdb_printf (stream
, " =>");
687 /* Print a single variant part, PART, on STREAM. TYPE is the
688 enclosing type. SHOW, LEVEL, and FLAGS are the usual type-printing
689 settings. This prints information about PART and the fields it
690 controls. It returns the index of the next field that should be
691 shown -- that is, one after the last field printed by this
695 print_variant_part (const variant_part
&part
,
696 struct type
*type
, struct ui_file
*stream
,
698 const struct type_print_options
*flags
)
700 struct type
*discr_type
= nullptr;
702 if (part
.discriminant_index
== -1)
706 name
= type
->field (part
.discriminant_index
).name ();;
707 discr_type
= type
->field (part
.discriminant_index
).type ();
710 gdb_printf (stream
, "\n%*scase %s is", level
+ 4, "", name
);
713 for (const variant
&variant
: part
.variants
)
715 print_choices (discr_type
, variant
, stream
, level
+ 8);
717 if (variant
.first_field
== variant
.last_field
)
718 gdb_printf (stream
, " null;");
721 print_record_field_types_dynamic (variant
.parts
,
723 variant
.last_field
, type
, stream
,
724 show
, level
+ 8, flags
);
725 last_field
= variant
.last_field
;
729 gdb_printf (stream
, "\n%*send case;", level
+ 4, "");
734 /* Print some fields of TYPE to STREAM. SHOW, LEVEL, and FLAGS are
735 the usual type-printing settings. PARTS is the array of variant
736 parts that correspond to the range of fields to be printed. FROM
737 and TO are the range of fields to print. */
740 print_record_field_types_dynamic (const gdb::array_view
<variant_part
> &parts
,
742 struct type
*type
, struct ui_file
*stream
,
744 const struct type_print_options
*flags
)
748 for (const variant_part
&part
: parts
)
750 if (part
.variants
.empty ())
753 /* Print any non-varying fields. */
754 int first_varying
= part
.variants
[0].first_field
;
755 print_selected_record_field_types (type
, type
, field
,
756 first_varying
- 1, stream
,
759 field
= print_variant_part (part
, type
, stream
, show
, level
, flags
);
762 /* Print any trailing fields that we were asked to print. */
763 print_selected_record_field_types (type
, type
, field
, to
- 1, stream
, show
,
767 /* Print a description on STREAM of all fields of record or union type
768 TYPE, as for print_selected_record_field_types, above. */
771 print_record_field_types (struct type
*type
, struct type
*outer_type
,
772 struct ui_file
*stream
, int show
, int level
,
773 const struct type_print_options
*flags
)
775 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
778 if (prop
->kind () == PROP_TYPE
)
780 type
= prop
->original_type ();
781 prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
783 gdb_assert (prop
->kind () == PROP_VARIANT_PARTS
);
784 print_record_field_types_dynamic (*prop
->variant_parts (),
785 0, type
->num_fields (),
786 type
, stream
, show
, level
, flags
);
787 return type
->num_fields ();
790 return print_selected_record_field_types (type
, outer_type
,
791 0, type
->num_fields () - 1,
792 stream
, show
, level
, flags
);
796 /* Print record type TYPE on STREAM. LEVEL is the recursion (indentation)
797 level, in case the element type itself has nested structure, and SHOW is
798 the number of levels of internal structure to show (see ada_print_type). */
801 print_record_type (struct type
*type0
, struct ui_file
*stream
, int show
,
802 int level
, const struct type_print_options
*flags
)
804 struct type
*parent_type
;
807 type
= ada_find_parallel_type (type0
, "___XVE");
811 parent_type
= ada_parent_type (type
);
812 if (ada_type_name (parent_type
) != NULL
)
814 const char *parent_name
= decoded_type_name (parent_type
);
816 /* If we fail to decode the parent type name, then use the parent
817 type name as is. Not pretty, but should never happen except
818 when the debugging info is incomplete or incorrect. This
819 prevents a crash trying to print a NULL pointer. */
820 if (parent_name
== NULL
)
821 parent_name
= ada_type_name (parent_type
);
822 gdb_printf (stream
, "new %s with record", parent_name
);
824 else if (parent_type
== NULL
&& ada_is_tagged_type (type
, 0))
825 gdb_printf (stream
, "tagged record");
827 gdb_printf (stream
, "record");
830 gdb_printf (stream
, " ... end record");
836 if (parent_type
!= NULL
&& ada_type_name (parent_type
) == NULL
)
837 flds
+= print_record_field_types (parent_type
, parent_type
,
838 stream
, show
, level
, flags
);
839 flds
+= print_record_field_types (type
, type
, stream
, show
, level
,
843 gdb_printf (stream
, "\n%*send record", level
, "");
845 gdb_printf (stream
, _(" <incomplete type> end record"));
847 gdb_printf (stream
, " null; end record");
851 /* Print the unchecked union type TYPE in something resembling Ada
852 format on STREAM. LEVEL is the recursion (indentation) level
853 in case the element type itself has nested structure, and SHOW is the
854 number of levels of internal structure to show (see ada_print_type). */
856 print_unchecked_union_type (struct type
*type
, struct ui_file
*stream
,
858 const struct type_print_options
*flags
)
861 gdb_printf (stream
, "record (?) is ... end record");
862 else if (type
->num_fields () == 0)
863 gdb_printf (stream
, "record (?) is null; end record");
866 gdb_printf (stream
, "record (?) is\n%*scase ? is", level
+ 4, "");
868 print_variant_clauses (type
, nullptr, type
, stream
, show
, level
+ 8, flags
);
870 gdb_printf (stream
, "\n%*send case;\n%*send record",
871 level
+ 4, "", level
, "");
877 /* Print function or procedure type TYPE on STREAM. Make it a header
878 for function or procedure NAME if NAME is not null. */
881 print_func_type (struct type
*type
, struct ui_file
*stream
, const char *name
,
882 const struct type_print_options
*flags
)
884 int i
, len
= type
->num_fields ();
886 if (type
->target_type () != NULL
887 && type
->target_type ()->code () == TYPE_CODE_VOID
)
888 gdb_printf (stream
, "procedure");
890 gdb_printf (stream
, "function");
892 if (name
!= NULL
&& name
[0] != '\0')
894 gdb_puts (" ", stream
);
895 fputs_styled (name
, function_name_style
.style (), stream
);
900 gdb_printf (stream
, " (");
901 for (i
= 0; i
< len
; i
+= 1)
905 gdb_puts ("; ", stream
);
906 stream
->wrap_here (4);
908 gdb_printf (stream
, "a%d: ", i
+ 1);
909 ada_print_type (type
->field (i
).type (), "", stream
, -1, 0,
912 gdb_printf (stream
, ")");
915 if (type
->target_type () == NULL
)
916 gdb_printf (stream
, " return <unknown return type>");
917 else if (type
->target_type ()->code () != TYPE_CODE_VOID
)
919 gdb_printf (stream
, " return ");
920 ada_print_type (type
->target_type (), "", stream
, 0, 0, flags
);
925 /* Print a description of a type TYPE0.
926 Output goes to STREAM (via stdio).
927 If VARSTRING is a non-NULL, non-empty string, print as an Ada
928 variable/field declaration.
929 SHOW+1 is the maximum number of levels of internal type structure
930 to show (this applies to record types, enumerated types, and
932 SHOW is the number of levels of internal type structure to show
933 when there is a type name for the SHOWth deepest level (0th is
935 When SHOW<0, no inner structure is shown.
936 LEVEL indicates level of recursion (for nested definitions). */
939 ada_print_type (struct type
*type0
, const char *varstring
,
940 struct ui_file
*stream
, int show
, int level
,
941 const struct type_print_options
*flags
)
943 if (type0
->code () == TYPE_CODE_INTERNAL_FUNCTION
)
945 c_print_type (type0
, "", stream
, show
, level
,
946 language_ada
, flags
);
950 struct type
*type
= ada_check_typedef (ada_get_base_type (type0
));
951 /* If we can decode the original type name, use it. However, there
952 are cases where the original type is an internally-generated type
953 with a name that can't be decoded (and whose encoded name might
954 not actually bear any relation to the type actually declared in
955 the sources). In that case, try using the name of the base type
958 Note that we looked at the possibility of always using the name
959 of the base type. This does not always work, unfortunately, as
960 there are situations where it's the base type which has an
961 internally-generated name. */
962 const char *type_name
= decoded_type_name (type0
);
963 if (type_name
== nullptr)
964 type_name
= decoded_type_name (type
);
965 int is_var_decl
= (varstring
!= NULL
&& varstring
[0] != '\0');
970 gdb_printf (stream
, "%.*s: ",
971 ada_name_prefix_len (varstring
), varstring
);
972 fprintf_styled (stream
, metadata_style
.style (), "<null type?>");
976 if (is_var_decl
&& type
->code () != TYPE_CODE_FUNC
)
977 gdb_printf (stream
, "%.*s: ",
978 ada_name_prefix_len (varstring
), varstring
);
980 if (type_name
!= NULL
&& show
<= 0 && !ada_is_aligner_type (type
))
982 gdb_printf (stream
, "%.*s",
983 ada_name_prefix_len (type_name
), type_name
);
987 if (ada_is_aligner_type (type
))
988 ada_print_type (ada_aligned_type (type
), "", stream
, show
, level
, flags
);
989 else if (ada_is_constrained_packed_array_type (type
)
990 && type
->code () != TYPE_CODE_PTR
)
991 print_array_type (type
, stream
, show
, level
, flags
);
993 switch (type
->code ())
996 gdb_printf (stream
, "<");
997 c_print_type (type
, "", stream
, show
, level
, language_ada
, flags
);
998 gdb_printf (stream
, ">");
1001 case TYPE_CODE_TYPEDEF
:
1002 /* An __XVL field is not truly a pointer, so don't print
1003 "access" in this case. */
1004 if (type
->code () != TYPE_CODE_PTR
1005 || (varstring
!= nullptr
1006 && strstr (varstring
, "___XVL") == nullptr))
1007 gdb_printf (stream
, "access ");
1008 ada_print_type (type
->target_type (), "", stream
, show
, level
,
1012 gdb_printf (stream
, "<ref> ");
1013 ada_print_type (type
->target_type (), "", stream
, show
, level
,
1016 case TYPE_CODE_ARRAY
:
1017 print_array_type (type
, stream
, show
, level
, flags
);
1019 case TYPE_CODE_BOOL
:
1020 gdb_printf (stream
, "(false, true)");
1024 const char *name
= ada_type_name (type
);
1026 if (!ada_is_range_type_name (name
))
1027 fprintf_styled (stream
, metadata_style
.style (),
1028 _("<%s-byte integer>"),
1029 pulongest (type
->length ()));
1032 gdb_printf (stream
, "range ");
1033 print_range_type (type
, stream
, 1 /* bounds_preferred_p */);
1037 case TYPE_CODE_RANGE
:
1038 if (is_fixed_point_type (type
))
1040 gdb_printf (stream
, "<");
1041 print_type_fixed_point (type
, stream
);
1042 gdb_printf (stream
, ">");
1044 else if (ada_is_modular_type (type
))
1045 gdb_printf (stream
, "mod %s",
1046 int_string (ada_modulus (type
), 10, 0, 0, 1));
1049 gdb_printf (stream
, "range ");
1050 print_range (type
, stream
, 1 /* bounds_preferred_p */);
1054 fprintf_styled (stream
, metadata_style
.style (),
1055 _("<%s-byte float>"),
1056 pulongest (type
->length ()));
1058 case TYPE_CODE_ENUM
:
1060 gdb_printf (stream
, "(...)");
1062 print_enum_type (type
, stream
);
1064 case TYPE_CODE_STRUCT
:
1065 if (ada_is_array_descriptor_type (type
))
1066 print_array_type (type
, stream
, show
, level
, flags
);
1068 print_record_type (type
, stream
, show
, level
, flags
);
1070 case TYPE_CODE_UNION
:
1071 print_unchecked_union_type (type
, stream
, show
, level
, flags
);
1073 case TYPE_CODE_FUNC
:
1074 print_func_type (type
, stream
, varstring
, flags
);
1079 /* Implement the la_print_typedef language method for Ada. */
1082 ada_print_typedef (struct type
*type
, struct symbol
*new_symbol
,
1083 struct ui_file
*stream
)
1085 type
= ada_check_typedef (type
);
1086 ada_print_type (type
, "", stream
, 0, 0, &type_print_raw_options
);