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/>. */
19 #include "event-top.h"
23 #include "cli/cli-style.h"
24 #include "typeprint.h"
28 static int print_selected_record_field_types (struct type
*, struct type
*,
30 struct ui_file
*, int, int,
31 const struct type_print_options
*);
33 static int print_record_field_types (struct type
*, struct type
*,
34 struct ui_file
*, int, int,
35 const struct type_print_options
*);
39 static char *name_buffer
;
40 static int name_buffer_len
;
42 /* The (decoded) Ada name of TYPE. This value persists until the
46 decoded_type_name (struct type
*type
)
48 if (ada_type_name (type
) == NULL
)
52 const char *raw_name
= ada_type_name (type
);
55 if (name_buffer
== NULL
|| name_buffer_len
<= strlen (raw_name
))
57 name_buffer_len
= 16 + 2 * strlen (raw_name
);
58 name_buffer
= (char *) xrealloc (name_buffer
, name_buffer_len
);
60 strcpy (name_buffer
, raw_name
);
62 s
= (char *) strstr (name_buffer
, "___");
66 s
= name_buffer
+ strlen (name_buffer
) - 1;
67 while (s
> name_buffer
&& (s
[0] != '_' || s
[-1] != '_'))
76 for (s
= q
= name_buffer
; *s
!= '\0'; q
+= 1)
78 if (s
[0] == '_' && s
[1] == '_')
94 /* Return nonzero if TYPE is a subrange type, and its bounds
95 are identical to the bounds of its subtype. */
98 type_is_full_subrange_of_target_type (struct type
*type
)
100 struct type
*subtype
;
102 if (type
->code () != TYPE_CODE_RANGE
)
105 subtype
= type
->target_type ();
109 if (is_dynamic_type (type
))
112 if (ada_discrete_type_low_bound (type
)
113 != ada_discrete_type_low_bound (subtype
))
116 if (ada_discrete_type_high_bound (type
)
117 != ada_discrete_type_high_bound (subtype
))
123 /* Print TYPE on STREAM, preferably as a range if BOUNDS_PREFERRED_P
127 print_range (struct type
*type
, struct ui_file
*stream
,
128 int bounds_preferred_p
)
130 if (!bounds_preferred_p
)
132 /* Try stripping all TYPE_CODE_RANGE layers whose bounds
133 are identical to the bounds of their subtype. When
134 the bounds of both types match, it can allow us to
135 print a range using the name of its base type, which
136 is easier to read. For instance, we would print...
138 array (character) of ...
142 array ('["00"]' .. '["ff"]') of ... */
143 while (type_is_full_subrange_of_target_type (type
))
144 type
= type
->target_type ();
147 switch (type
->code ())
149 case TYPE_CODE_RANGE
:
152 LONGEST lo
= 0, hi
= 0; /* init for gcc -Wall */
157 lo
= ada_discrete_type_low_bound (type
);
158 hi
= ada_discrete_type_high_bound (type
);
160 catch (const gdb_exception_error
&e
)
162 /* This can happen when the range is dynamic. Sometimes,
163 resolving dynamic property values requires us to have
164 access to an actual object, which is not available
165 when the user is using the "ptype" command on a type.
166 Print the range as an unbounded range. */
167 gdb_printf (stream
, "<>");
173 ada_print_scalar (type
, lo
, stream
);
174 gdb_printf (stream
, " .. ");
175 ada_print_scalar (type
, hi
, stream
);
180 gdb_printf (stream
, "%.*s",
181 ada_name_prefix_len (type
->name ()),
187 /* Print the number or discriminant bound at BOUNDS+*N on STREAM, and
188 set *N past the bound and its delimiter, if any. */
191 print_range_bound (struct type
*type
, const char *bounds
, int *n
,
192 struct ui_file
*stream
)
196 if (ada_scan_number (bounds
, *n
, &B
, n
))
198 /* STABS decodes all range types which bounds are 0 .. -1 as
199 unsigned integers (ie. the type code is TYPE_CODE_INT, not
200 TYPE_CODE_RANGE). Unfortunately, ada_print_scalar() relies
201 on the unsigned flag to determine whether the bound should
202 be printed as a signed or an unsigned value. This causes
203 the upper bound of the 0 .. -1 range types to be printed as
204 a very large unsigned number instead of -1.
205 To workaround this stabs deficiency, we replace the TYPE by NULL
206 to indicate default output when we detect that the bound is negative,
207 and the type is a TYPE_CODE_INT. The bound is negative when
208 'm' is the last character of the number scanned in BOUNDS. */
209 if (bounds
[*n
- 1] == 'm' && type
->code () == TYPE_CODE_INT
)
211 ada_print_scalar (type
, B
, stream
);
212 if (bounds
[*n
] == '_')
218 const char *bound
= bounds
+ *n
;
221 pend
= strstr (bound
, "__");
223 *n
+= bound_len
= strlen (bound
);
226 bound_len
= pend
- bound
;
229 gdb_printf (stream
, "%.*s", bound_len
, bound
);
233 /* Assuming NAME[0 .. NAME_LEN-1] is the name of a range type, print
234 the value (if found) of the bound indicated by SUFFIX ("___L" or
235 "___U") according to the ___XD conventions. */
238 print_dynamic_range_bound (struct type
*type
, const char *name
, int name_len
,
239 const char *suffix
, struct ui_file
*stream
)
242 std::string
name_buf (name
, name_len
);
245 if (get_int_var_value (name_buf
.c_str (), B
))
246 ada_print_scalar (type
, B
, stream
);
248 gdb_printf (stream
, "?");
251 /* Print RAW_TYPE as a range type, using any bound information
252 following the GNAT encoding (if available).
254 If BOUNDS_PREFERRED_P is nonzero, force the printing of the range
255 using its bounds. Otherwise, try printing the range without
256 printing the value of the bounds, if possible (this is only
257 considered a hint, not a guaranty). */
260 print_range_type (struct type
*raw_type
, struct ui_file
*stream
,
261 int bounds_preferred_p
)
264 struct type
*base_type
;
265 const char *subtype_info
;
267 gdb_assert (raw_type
!= NULL
);
268 name
= raw_type
->name ();
269 gdb_assert (name
!= NULL
);
271 if (raw_type
->code () == TYPE_CODE_RANGE
)
272 base_type
= raw_type
->target_type ();
274 base_type
= raw_type
;
276 subtype_info
= strstr (name
, "___XD");
277 if (subtype_info
== NULL
)
278 print_range (raw_type
, stream
, bounds_preferred_p
);
281 int prefix_len
= subtype_info
- name
;
282 const char *bounds_str
;
286 bounds_str
= strchr (subtype_info
, '_');
289 if (*subtype_info
== 'L')
291 print_range_bound (base_type
, bounds_str
, &n
, stream
);
295 print_dynamic_range_bound (base_type
, name
, prefix_len
, "___L",
298 gdb_printf (stream
, " .. ");
300 if (*subtype_info
== 'U')
301 print_range_bound (base_type
, bounds_str
, &n
, stream
);
303 print_dynamic_range_bound (base_type
, name
, prefix_len
, "___U",
308 /* Print enumerated type TYPE on STREAM. */
311 print_enum_type (struct type
*type
, struct ui_file
*stream
)
313 int len
= type
->num_fields ();
317 gdb_printf (stream
, "(");
318 stream
->wrap_here (1);
321 for (i
= 0; i
< len
; i
++)
325 gdb_printf (stream
, ", ");
326 stream
->wrap_here (4);
327 fputs_styled (ada_enum_name (type
->field (i
).name ()),
328 variable_name_style
.style (), stream
);
329 if (lastval
!= type
->field (i
).loc_enumval ())
331 gdb_printf (stream
, " => %s",
332 plongest (type
->field (i
).loc_enumval ()));
333 lastval
= type
->field (i
).loc_enumval ();
337 gdb_printf (stream
, ")");
340 /* Print simple (constrained) array type TYPE on STREAM. LEVEL is the
341 recursion (indentation) level, in case the element type itself has
342 nested structure, and SHOW is the number of levels of internal
343 structure to show (see ada_print_type). */
346 print_array_type (struct type
*type
, struct ui_file
*stream
, int show
,
347 int level
, const struct type_print_options
*flags
)
351 struct type
*elt_type
= NULL
;
353 if (ada_is_constrained_packed_array_type (type
))
354 type
= ada_coerce_to_simple_array_type (type
);
357 gdb_printf (stream
, "array (");
361 fprintf_styled (stream
, metadata_style
.style (),
362 _("<undecipherable array type>"));
367 if (ada_is_simple_array_type (type
))
369 struct type
*range_desc_type
;
370 struct type
*arr_type
;
372 range_desc_type
= ada_find_parallel_type (type
, "___XA");
373 ada_fixup_array_indexes_type (range_desc_type
);
376 if (range_desc_type
== NULL
)
378 for (arr_type
= type
; arr_type
->code () == TYPE_CODE_ARRAY
; )
380 if (arr_type
!= type
)
381 gdb_printf (stream
, ", ");
382 print_range (arr_type
->index_type (), stream
,
383 0 /* bounds_preferred_p */);
384 if (arr_type
->field (0).bitsize () > 0)
385 bitsize
= arr_type
->field (0).bitsize ();
386 /* A multi-dimensional array is represented using a
387 sequence of array types. If one of these types has a
388 name, then it is not another dimension of the outer
389 array, but rather the element type of the outermost
391 arr_type
= arr_type
->target_type ();
392 if (arr_type
->name () != nullptr)
400 n_indices
= range_desc_type
->num_fields ();
401 for (k
= 0, arr_type
= type
;
403 k
+= 1, arr_type
= arr_type
->target_type ())
406 gdb_printf (stream
, ", ");
407 print_range_type (range_desc_type
->field (k
).type (),
408 stream
, 0 /* bounds_preferred_p */);
409 if (arr_type
->field (0).bitsize () > 0)
410 bitsize
= arr_type
->field (0).bitsize ();
418 for (i
= i0
= ada_array_arity (type
); i
> 0; i
-= 1)
419 gdb_printf (stream
, "%s<>", i
== i0
? "" : ", ");
422 elt_type
= ada_array_element_type (type
, n_indices
);
423 gdb_printf (stream
, ") of ");
424 stream
->wrap_here (0);
425 ada_print_type (elt_type
, "", stream
, show
== 0 ? 0 : show
- 1, level
+ 1,
427 /* Arrays with variable-length elements are never bit-packed in practice but
428 compilers have to describe their stride so that we can properly fetch
429 individual elements. Do not say the array is packed in this case. */
430 if (bitsize
> 0 && !is_dynamic_type (elt_type
))
431 gdb_printf (stream
, " <packed: %d-bit elements>", bitsize
);
434 /* Print the choices encoded by field FIELD_NUM of variant-part TYPE on
435 STREAM, assuming that VAL_TYPE (if non-NULL) is the type of the
436 values. Return non-zero if the field is an encoding of
437 discriminant values, as in a standard variant record, and 0 if the
438 field is not so encoded (as happens with single-component variants
439 in types annotated with pragma Unchecked_Union). */
442 print_choices (struct type
*type
, int field_num
, struct ui_file
*stream
,
443 struct type
*val_type
)
447 const char *name
= type
->field (field_num
).name ();
451 /* Skip over leading 'V': NOTE soon to be obsolete. */
454 if (!ada_scan_number (name
, 1, NULL
, &p
))
468 gdb_printf (stream
, " =>");
474 gdb_printf (stream
, " | ");
485 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
487 ada_print_scalar (val_type
, W
, stream
);
494 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
495 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
497 ada_print_scalar (val_type
, L
, stream
);
498 gdb_printf (stream
, " .. ");
499 ada_print_scalar (val_type
, U
, stream
);
503 gdb_printf (stream
, "others");
510 gdb_printf (stream
, "? =>");
514 /* A helper for print_variant_clauses that prints the members of
515 VAR_TYPE. DISCR_TYPE is the type of the discriminant (or nullptr
516 if not available). The discriminant is contained in OUTER_TYPE.
517 STREAM, LEVEL, SHOW, and FLAGS are the same as for
521 print_variant_clauses (struct type
*var_type
, struct type
*discr_type
,
522 struct type
*outer_type
, struct ui_file
*stream
,
524 const struct type_print_options
*flags
)
526 for (int i
= 0; i
< var_type
->num_fields (); i
+= 1)
528 gdb_printf (stream
, "\n%*swhen ", level
, "");
529 if (print_choices (var_type
, i
, stream
, discr_type
))
531 if (print_record_field_types (var_type
->field (i
).type (),
532 outer_type
, stream
, show
, level
,
535 gdb_printf (stream
, " null;");
538 print_selected_record_field_types (var_type
, outer_type
, i
, i
,
539 stream
, show
, level
, flags
);
543 /* Assuming that field FIELD_NUM of TYPE represents variants whose
544 discriminant is contained in OUTER_TYPE, print its components on STREAM.
545 LEVEL is the recursion (indentation) level, in case any of the fields
546 themselves have nested structure, and SHOW is the number of levels of
547 internal structure to show (see ada_print_type). For this purpose,
548 fields nested in a variant part are taken to be at the same level as
549 the fields immediately outside the variant part. */
552 print_variant_clauses (struct type
*type
, int field_num
,
553 struct type
*outer_type
, struct ui_file
*stream
,
555 const struct type_print_options
*flags
)
557 struct type
*var_type
, *par_type
;
558 struct type
*discr_type
;
560 var_type
= type
->field (field_num
).type ();
561 discr_type
= ada_variant_discrim_type (var_type
, outer_type
);
563 if (var_type
->code () == TYPE_CODE_PTR
)
565 var_type
= var_type
->target_type ();
566 if (var_type
== NULL
|| var_type
->code () != TYPE_CODE_UNION
)
570 par_type
= ada_find_parallel_type (var_type
, "___XVU");
571 if (par_type
!= NULL
)
574 print_variant_clauses (var_type
, discr_type
, outer_type
, stream
, show
,
578 /* Assuming that field FIELD_NUM of TYPE is a variant part whose
579 discriminants are contained in OUTER_TYPE, print a description of it
580 on STREAM. LEVEL is the recursion (indentation) level, in case any of
581 the fields themselves have nested structure, and SHOW is the number of
582 levels of internal structure to show (see ada_print_type). For this
583 purpose, fields nested in a variant part are taken to be at the same
584 level as the fields immediately outside the variant part. */
587 print_variant_part (struct type
*type
, int field_num
, struct type
*outer_type
,
588 struct ui_file
*stream
, int show
, int level
,
589 const struct type_print_options
*flags
)
592 = ada_variant_discrim_name (type
->field (field_num
).type ());
593 if (*variant
== '\0')
596 gdb_printf (stream
, "\n%*scase %s is", level
+ 4, "", variant
);
597 print_variant_clauses (type
, field_num
, outer_type
, stream
, show
,
599 gdb_printf (stream
, "\n%*send case;", level
+ 4, "");
602 /* Print a description on STREAM of the fields FLD0 through FLD1 in
603 record or union type TYPE, whose discriminants are in OUTER_TYPE.
604 LEVEL is the recursion (indentation) level, in case any of the
605 fields themselves have nested structure, and SHOW is the number of
606 levels of internal structure to show (see ada_print_type). Does
607 not print parent type information of TYPE. Returns 0 if no fields
608 printed, -1 for an incomplete type, else > 0. Prints each field
609 beginning on a new line, but does not put a new line at end. */
612 print_selected_record_field_types (struct type
*type
, struct type
*outer_type
,
614 struct ui_file
*stream
, int show
, int level
,
615 const struct type_print_options
*flags
)
621 if (fld0
> fld1
&& type
->is_stub ())
624 for (i
= fld0
; i
<= fld1
; i
+= 1)
628 if (ada_is_parent_field (type
, i
) || ada_is_ignored_field (type
, i
))
630 else if (ada_is_wrapper_field (type
, i
))
631 flds
+= print_record_field_types (type
->field (i
).type (), type
,
632 stream
, show
, level
, flags
);
633 else if (ada_is_variant_part (type
, i
))
635 print_variant_part (type
, i
, outer_type
, stream
, show
, level
, flags
);
641 gdb_printf (stream
, "\n%*s", level
+ 4, "");
642 ada_print_type (type
->field (i
).type (),
643 type
->field (i
).name (),
644 stream
, show
- 1, level
+ 4, flags
);
645 gdb_printf (stream
, ";");
652 static void print_record_field_types_dynamic
653 (const gdb::array_view
<variant_part
> &parts
,
654 int from
, int to
, struct type
*type
, struct ui_file
*stream
,
655 int show
, int level
, const struct type_print_options
*flags
);
657 /* Print the choices encoded by VARIANT on STREAM. LEVEL is the
658 indentation level. The type of the discriminant for VARIANT is
659 given by DISR_TYPE. */
662 print_choices (struct type
*discr_type
, const variant
&variant
,
663 struct ui_file
*stream
, int level
)
665 gdb_printf (stream
, "\n%*swhen ", level
, "");
666 if (variant
.is_default ())
667 gdb_printf (stream
, "others");
671 for (const discriminant_range
&range
: variant
.discriminants
)
674 gdb_printf (stream
, " | ");
677 ada_print_scalar (discr_type
, range
.low
, stream
);
678 if (range
.low
!= range
.high
)
679 ada_print_scalar (discr_type
, range
.high
, stream
);
683 gdb_printf (stream
, " =>");
686 /* Print a single variant part, PART, on STREAM. TYPE is the
687 enclosing type. SHOW, LEVEL, and FLAGS are the usual type-printing
688 settings. This prints information about PART and the fields it
689 controls. It returns the index of the next field that should be
690 shown -- that is, one after the last field printed by this
694 print_variant_part (const variant_part
&part
,
695 struct type
*type
, struct ui_file
*stream
,
697 const struct type_print_options
*flags
)
699 struct type
*discr_type
= nullptr;
701 if (part
.discriminant_index
== -1)
705 name
= type
->field (part
.discriminant_index
).name ();;
706 discr_type
= type
->field (part
.discriminant_index
).type ();
709 gdb_printf (stream
, "\n%*scase %s is", level
+ 4, "", name
);
712 for (const variant
&variant
: part
.variants
)
714 print_choices (discr_type
, variant
, stream
, level
+ 8);
716 if (variant
.first_field
== variant
.last_field
)
717 gdb_printf (stream
, " null;");
720 print_record_field_types_dynamic (variant
.parts
,
722 variant
.last_field
, type
, stream
,
723 show
, level
+ 8, flags
);
724 last_field
= variant
.last_field
;
728 gdb_printf (stream
, "\n%*send case;", level
+ 4, "");
733 /* Print some fields of TYPE to STREAM. SHOW, LEVEL, and FLAGS are
734 the usual type-printing settings. PARTS is the array of variant
735 parts that correspond to the range of fields to be printed. FROM
736 and TO are the range of fields to print. */
739 print_record_field_types_dynamic (const gdb::array_view
<variant_part
> &parts
,
741 struct type
*type
, struct ui_file
*stream
,
743 const struct type_print_options
*flags
)
747 for (const variant_part
&part
: parts
)
749 if (part
.variants
.empty ())
752 /* Print any non-varying fields. */
753 int first_varying
= part
.variants
[0].first_field
;
754 print_selected_record_field_types (type
, type
, field
,
755 first_varying
- 1, stream
,
758 field
= print_variant_part (part
, type
, stream
, show
, level
, flags
);
761 /* Print any trailing fields that we were asked to print. */
762 print_selected_record_field_types (type
, type
, field
, to
- 1, stream
, show
,
766 /* Print a description on STREAM of all fields of record or union type
767 TYPE, as for print_selected_record_field_types, above. */
770 print_record_field_types (struct type
*type
, struct type
*outer_type
,
771 struct ui_file
*stream
, int show
, int level
,
772 const struct type_print_options
*flags
)
774 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
777 if (prop
->kind () == PROP_TYPE
)
779 type
= prop
->original_type ();
780 prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
782 gdb_assert (prop
->kind () == PROP_VARIANT_PARTS
);
783 print_record_field_types_dynamic (*prop
->variant_parts (),
784 0, type
->num_fields (),
785 type
, stream
, show
, level
, flags
);
786 return type
->num_fields ();
789 return print_selected_record_field_types (type
, outer_type
,
790 0, type
->num_fields () - 1,
791 stream
, show
, level
, flags
);
795 /* Print record type TYPE on STREAM. LEVEL is the recursion (indentation)
796 level, in case the element type itself has nested structure, and SHOW is
797 the number of levels of internal structure to show (see ada_print_type). */
800 print_record_type (struct type
*type0
, struct ui_file
*stream
, int show
,
801 int level
, const struct type_print_options
*flags
)
803 struct type
*parent_type
;
806 type
= ada_find_parallel_type (type0
, "___XVE");
810 parent_type
= ada_parent_type (type
);
811 if (ada_type_name (parent_type
) != NULL
)
813 const char *parent_name
= decoded_type_name (parent_type
);
815 /* If we fail to decode the parent type name, then use the parent
816 type name as is. Not pretty, but should never happen except
817 when the debugging info is incomplete or incorrect. This
818 prevents a crash trying to print a NULL pointer. */
819 if (parent_name
== NULL
)
820 parent_name
= ada_type_name (parent_type
);
821 gdb_printf (stream
, "new %s with record", parent_name
);
823 else if (parent_type
== NULL
&& ada_is_tagged_type (type
, 0))
824 gdb_printf (stream
, "tagged record");
826 gdb_printf (stream
, "record");
829 gdb_printf (stream
, " ... end record");
835 if (parent_type
!= NULL
&& ada_type_name (parent_type
) == NULL
)
836 flds
+= print_record_field_types (parent_type
, parent_type
,
837 stream
, show
, level
, flags
);
838 flds
+= print_record_field_types (type
, type
, stream
, show
, level
,
842 gdb_printf (stream
, "\n%*send record", level
, "");
844 gdb_printf (stream
, _(" <incomplete type> end record"));
846 gdb_printf (stream
, " null; end record");
850 /* Print the unchecked union type TYPE in something resembling Ada
851 format on STREAM. LEVEL is the recursion (indentation) level
852 in case the element type itself has nested structure, and SHOW is the
853 number of levels of internal structure to show (see ada_print_type). */
855 print_unchecked_union_type (struct type
*type
, struct ui_file
*stream
,
857 const struct type_print_options
*flags
)
860 gdb_printf (stream
, "record (?) is ... end record");
861 else if (type
->num_fields () == 0)
862 gdb_printf (stream
, "record (?) is null; end record");
865 gdb_printf (stream
, "record (?) is\n%*scase ? is", level
+ 4, "");
867 print_variant_clauses (type
, nullptr, type
, stream
, show
, level
+ 8, flags
);
869 gdb_printf (stream
, "\n%*send case;\n%*send record",
870 level
+ 4, "", level
, "");
876 /* Print function or procedure type TYPE on STREAM. Make it a header
877 for function or procedure NAME if NAME is not null. */
880 print_func_type (struct type
*type
, struct ui_file
*stream
, const char *name
,
881 const struct type_print_options
*flags
)
883 int i
, len
= type
->num_fields ();
885 if (type
->target_type () != NULL
886 && type
->target_type ()->code () == TYPE_CODE_VOID
)
887 gdb_printf (stream
, "procedure");
889 gdb_printf (stream
, "function");
891 if (name
!= NULL
&& name
[0] != '\0')
893 gdb_puts (" ", stream
);
894 fputs_styled (name
, function_name_style
.style (), stream
);
899 gdb_printf (stream
, " (");
900 for (i
= 0; i
< len
; i
+= 1)
904 gdb_puts ("; ", stream
);
905 stream
->wrap_here (4);
907 gdb_printf (stream
, "a%d: ", i
+ 1);
908 ada_print_type (type
->field (i
).type (), "", stream
, -1, 0,
911 gdb_printf (stream
, ")");
914 if (type
->target_type () == NULL
)
915 gdb_printf (stream
, " return <unknown return type>");
916 else if (type
->target_type ()->code () != TYPE_CODE_VOID
)
918 gdb_printf (stream
, " return ");
919 ada_print_type (type
->target_type (), "", stream
, 0, 0, flags
);
924 /* Print a description of a type TYPE0.
925 Output goes to STREAM (via stdio).
926 If VARSTRING is a non-NULL, non-empty string, print as an Ada
927 variable/field declaration.
928 SHOW+1 is the maximum number of levels of internal type structure
929 to show (this applies to record types, enumerated types, and
931 SHOW is the number of levels of internal type structure to show
932 when there is a type name for the SHOWth deepest level (0th is
934 When SHOW<0, no inner structure is shown.
935 LEVEL indicates level of recursion (for nested definitions). */
938 ada_print_type (struct type
*type0
, const char *varstring
,
939 struct ui_file
*stream
, int show
, int level
,
940 const struct type_print_options
*flags
)
942 if (type0
->code () == TYPE_CODE_INTERNAL_FUNCTION
)
944 c_print_type (type0
, "", stream
, show
, level
,
945 language_ada
, flags
);
949 struct type
*type
= ada_check_typedef (ada_get_base_type (type0
));
950 /* If we can decode the original type name, use it. However, there
951 are cases where the original type is an internally-generated type
952 with a name that can't be decoded (and whose encoded name might
953 not actually bear any relation to the type actually declared in
954 the sources). In that case, try using the name of the base type
957 Note that we looked at the possibility of always using the name
958 of the base type. This does not always work, unfortunately, as
959 there are situations where it's the base type which has an
960 internally-generated name. */
961 const char *type_name
= decoded_type_name (type0
);
962 if (type_name
== nullptr)
963 type_name
= decoded_type_name (type
);
964 int is_var_decl
= (varstring
!= NULL
&& varstring
[0] != '\0');
969 gdb_printf (stream
, "%.*s: ",
970 ada_name_prefix_len (varstring
), varstring
);
971 fprintf_styled (stream
, metadata_style
.style (), "<null type?>");
975 if (is_var_decl
&& type
->code () != TYPE_CODE_FUNC
)
976 gdb_printf (stream
, "%.*s: ",
977 ada_name_prefix_len (varstring
), varstring
);
979 if (type_name
!= NULL
&& show
<= 0 && !ada_is_aligner_type (type
))
981 gdb_printf (stream
, "%.*s",
982 ada_name_prefix_len (type_name
), type_name
);
986 if (ada_is_aligner_type (type
))
987 ada_print_type (ada_aligned_type (type
), "", stream
, show
, level
, flags
);
988 else if (ada_is_constrained_packed_array_type (type
)
989 && type
->code () != TYPE_CODE_PTR
)
990 print_array_type (type
, stream
, show
, level
, flags
);
992 switch (type
->code ())
995 gdb_printf (stream
, "<");
996 c_print_type (type
, "", stream
, show
, level
, language_ada
, flags
);
997 gdb_printf (stream
, ">");
1000 case TYPE_CODE_TYPEDEF
:
1001 /* An __XVL field is not truly a pointer, so don't print
1002 "access" in this case. */
1003 if (type
->code () != TYPE_CODE_PTR
1004 || (varstring
!= nullptr
1005 && strstr (varstring
, "___XVL") == nullptr))
1006 gdb_printf (stream
, "access ");
1007 ada_print_type (type
->target_type (), "", stream
, show
, level
,
1011 gdb_printf (stream
, "<ref> ");
1012 ada_print_type (type
->target_type (), "", stream
, show
, level
,
1015 case TYPE_CODE_ARRAY
:
1016 print_array_type (type
, stream
, show
, level
, flags
);
1018 case TYPE_CODE_BOOL
:
1019 gdb_printf (stream
, "(false, true)");
1023 const char *name
= ada_type_name (type
);
1025 if (!ada_is_range_type_name (name
))
1026 fprintf_styled (stream
, metadata_style
.style (),
1027 _("<%s-byte integer>"),
1028 pulongest (type
->length ()));
1031 gdb_printf (stream
, "range ");
1032 print_range_type (type
, stream
, 1 /* bounds_preferred_p */);
1036 case TYPE_CODE_RANGE
:
1037 if (is_fixed_point_type (type
))
1039 gdb_printf (stream
, "<");
1040 print_type_fixed_point (type
, stream
);
1041 gdb_printf (stream
, ">");
1043 else if (ada_is_modular_type (type
))
1044 gdb_printf (stream
, "mod %s",
1045 int_string (ada_modulus (type
), 10, 0, 0, 1));
1048 gdb_printf (stream
, "range ");
1049 print_range (type
, stream
, 1 /* bounds_preferred_p */);
1053 fprintf_styled (stream
, metadata_style
.style (),
1054 _("<%s-byte float>"),
1055 pulongest (type
->length ()));
1057 case TYPE_CODE_ENUM
:
1059 gdb_printf (stream
, "(...)");
1061 print_enum_type (type
, stream
);
1063 case TYPE_CODE_STRUCT
:
1064 if (ada_is_array_descriptor_type (type
))
1065 print_array_type (type
, stream
, show
, level
, flags
);
1067 print_record_type (type
, stream
, show
, level
, flags
);
1069 case TYPE_CODE_UNION
:
1070 print_unchecked_union_type (type
, stream
, show
, level
, flags
);
1072 case TYPE_CODE_FUNC
:
1073 print_func_type (type
, stream
, varstring
, flags
);
1078 /* Implement the la_print_typedef language method for Ada. */
1081 ada_print_typedef (struct type
*type
, struct symbol
*new_symbol
,
1082 struct ui_file
*stream
)
1084 type
= ada_check_typedef (type
);
1085 ada_print_type (type
, "", stream
, 0, 0, &type_print_raw_options
);