1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright (C) 1986-2022 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/>. */
20 #include "gdbsupport/gdb_obstack.h"
21 #include "bfd.h" /* Binary File Description. */
24 #include "expression.h"
31 #include "cli/cli-style.h"
32 #include "typeprint.h"
34 #include "cp-support.h"
36 /* A list of access specifiers used for printing. */
46 static void c_type_print_varspec_suffix (struct type
*, struct ui_file
*, int,
49 const struct type_print_options
*);
51 static void c_type_print_varspec_prefix (struct type
*,
55 const struct type_print_options
*,
56 struct print_offset_data
*);
58 /* Print "const", "volatile", or address space modifiers. */
59 static void c_type_print_modifier (struct type
*,
61 int, int, enum language
);
63 static void c_type_print_base_1 (struct type
*type
, struct ui_file
*stream
,
64 int show
, int level
, enum language language
,
65 const struct type_print_options
*flags
,
66 struct print_offset_data
*podata
);
69 /* A callback function for cp_canonicalize_string_full that uses
70 typedef_hash_table::find_typedef. */
73 find_typedef_for_canonicalize (struct type
*t
, void *data
)
75 return typedef_hash_table::find_typedef
76 ((const struct type_print_options
*) data
, t
);
79 /* Print NAME on STREAM. If the 'raw' field of FLAGS is not set,
80 canonicalize NAME using the local typedefs first. */
83 print_name_maybe_canonical (const char *name
,
84 const struct type_print_options
*flags
,
85 struct ui_file
*stream
)
87 gdb::unique_xmalloc_ptr
<char> s
;
90 s
= cp_canonicalize_string_full (name
,
91 find_typedef_for_canonicalize
,
94 gdb_puts (s
!= nullptr ? s
.get () : name
, stream
);
99 /* Helper function for c_print_type. */
102 c_print_type_1 (struct type
*type
,
103 const char *varstring
,
104 struct ui_file
*stream
,
106 enum language language
,
107 const struct type_print_options
*flags
,
108 struct print_offset_data
*podata
)
113 const char *local_name
;
116 type
= check_typedef (type
);
118 local_name
= typedef_hash_table::find_typedef (flags
, type
);
119 code
= type
->code ();
120 if (local_name
!= NULL
)
122 c_type_print_modifier (type
, stream
, 0, 1, language
);
123 gdb_puts (local_name
, stream
);
124 if (varstring
!= NULL
&& *varstring
!= '\0')
125 gdb_puts (" ", stream
);
129 c_type_print_base_1 (type
, stream
, show
, level
, language
, flags
, podata
);
130 if ((varstring
!= NULL
&& *varstring
!= '\0')
131 /* Need a space if going to print stars or brackets;
132 but not if we will print just a type name. */
133 || ((show
> 0 || type
->name () == 0)
134 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
135 || code
== TYPE_CODE_METHOD
136 || (code
== TYPE_CODE_ARRAY
137 && !type
->is_vector ())
138 || code
== TYPE_CODE_MEMBERPTR
139 || code
== TYPE_CODE_METHODPTR
140 || TYPE_IS_REFERENCE (type
))))
141 gdb_puts (" ", stream
);
142 need_post_space
= (varstring
!= NULL
&& strcmp (varstring
, "") != 0);
143 c_type_print_varspec_prefix (type
, stream
, show
, 0, need_post_space
,
144 language
, flags
, podata
);
147 if (varstring
!= NULL
)
149 if (code
== TYPE_CODE_FUNC
|| code
== TYPE_CODE_METHOD
)
150 fputs_styled (varstring
, function_name_style
.style (), stream
);
152 fputs_styled (varstring
, variable_name_style
.style (), stream
);
154 /* For demangled function names, we have the arglist as part of
155 the name, so don't print an additional pair of ()'s. */
156 if (local_name
== NULL
)
158 demangled_args
= strchr (varstring
, '(') != NULL
;
159 c_type_print_varspec_suffix (type
, stream
, show
,
166 /* LEVEL is the depth to indent lines by. */
169 c_print_type (struct type
*type
,
170 const char *varstring
,
171 struct ui_file
*stream
,
173 const struct type_print_options
*flags
)
175 struct print_offset_data
podata (flags
);
177 c_print_type_1 (type
, varstring
, stream
, show
, level
,
178 current_language
->la_language
, flags
, &podata
);
185 c_print_type (struct type
*type
,
186 const char *varstring
,
187 struct ui_file
*stream
,
189 enum language language
,
190 const struct type_print_options
*flags
)
192 struct print_offset_data
podata (flags
);
194 c_print_type_1 (type
, varstring
, stream
, show
, level
, language
, flags
,
198 /* Print a typedef using C syntax. TYPE is the underlying type.
199 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
203 c_print_typedef (struct type
*type
,
204 struct symbol
*new_symbol
,
205 struct ui_file
*stream
)
207 type
= check_typedef (type
);
208 gdb_printf (stream
, "typedef ");
209 type_print (type
, "", stream
, -1);
210 if ((new_symbol
->type ())->name () == 0
211 || strcmp ((new_symbol
->type ())->name (),
212 new_symbol
->linkage_name ()) != 0
213 || new_symbol
->type ()->code () == TYPE_CODE_TYPEDEF
)
214 gdb_printf (stream
, " %s", new_symbol
->print_name ());
215 gdb_printf (stream
, ";");
218 /* If TYPE is a derived type, then print out derivation information.
219 Print only the actual base classes of this type, not the base
220 classes of the base classes. I.e. for the derivation hierarchy:
223 class B : public A {int b; };
224 class C : public B {int c; };
226 Print the type of class C as:
232 Not as the following (like gdb used to), which is not legal C++
233 syntax for derived types and may be confused with the multiple
236 class C : public B : public A {
240 In general, gdb should try to print the types as closely as
241 possible to the form that they appear in the source code. */
244 cp_type_print_derivation_info (struct ui_file
*stream
,
246 const struct type_print_options
*flags
)
251 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
253 stream
->wrap_here (8);
254 gdb_puts (i
== 0 ? ": " : ", ", stream
);
255 gdb_printf (stream
, "%s%s ",
256 BASETYPE_VIA_PUBLIC (type
, i
)
257 ? "public" : (TYPE_FIELD_PROTECTED (type
, i
)
258 ? "protected" : "private"),
259 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
260 name
= TYPE_BASECLASS (type
, i
)->name ();
262 print_name_maybe_canonical (name
, flags
, stream
);
264 gdb_printf (stream
, "(null)");
268 gdb_puts (" ", stream
);
272 /* Print the C++ method arguments ARGS to the file STREAM. */
275 cp_type_print_method_args (struct type
*mtype
, const char *prefix
,
276 const char *varstring
, int staticp
,
277 struct ui_file
*stream
,
278 enum language language
,
279 const struct type_print_options
*flags
)
281 struct field
*args
= mtype
->fields ();
282 int nargs
= mtype
->num_fields ();
283 int varargs
= mtype
->has_varargs ();
286 fprintf_symbol (stream
, prefix
,
287 language_cplus
, DMGL_ANSI
);
288 fprintf_symbol (stream
, varstring
,
289 language_cplus
, DMGL_ANSI
);
290 gdb_puts ("(", stream
);
292 /* Skip the class variable. We keep this here to accommodate older
293 compilers and debug formats which may not support artificial
300 struct field arg
= args
[i
++];
302 /* Skip any artificial arguments. */
303 if (FIELD_ARTIFICIAL (arg
))
306 c_print_type (arg
.type (), "", stream
, 0, 0, flags
);
308 if (i
== nargs
&& varargs
)
309 gdb_printf (stream
, ", ...");
312 gdb_printf (stream
, ", ");
313 stream
->wrap_here (8);
318 gdb_printf (stream
, "...");
319 else if (language
== language_cplus
)
320 gdb_printf (stream
, "void");
322 gdb_printf (stream
, ")");
324 /* For non-static methods, read qualifiers from the type of
330 gdb_assert (nargs
> 0);
331 gdb_assert (args
[0].type ()->code () == TYPE_CODE_PTR
);
332 domain
= TYPE_TARGET_TYPE (args
[0].type ());
334 if (TYPE_CONST (domain
))
335 gdb_printf (stream
, " const");
337 if (TYPE_VOLATILE (domain
))
338 gdb_printf (stream
, " volatile");
340 if (TYPE_RESTRICT (domain
))
341 gdb_printf (stream
, (language
== language_cplus
345 if (TYPE_ATOMIC (domain
))
346 gdb_printf (stream
, " _Atomic");
351 /* Print any asterisks or open-parentheses needed before the
352 variable name (to describe its type).
354 On outermost call, pass 0 for PASSED_A_PTR.
355 On outermost call, SHOW > 0 means should ignore
356 any typename for TYPE and show its details.
357 SHOW is always zero on recursive calls.
359 NEED_POST_SPACE is non-zero when a space will be be needed
360 between a trailing qualifier and a field, variable, or function
364 c_type_print_varspec_prefix (struct type
*type
,
365 struct ui_file
*stream
,
366 int show
, int passed_a_ptr
,
368 enum language language
,
369 const struct type_print_options
*flags
,
370 struct print_offset_data
*podata
)
377 if (type
->name () && show
<= 0)
382 switch (type
->code ())
385 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
386 stream
, show
, 1, 1, language
, flags
,
388 gdb_printf (stream
, "*");
389 c_type_print_modifier (type
, stream
, 1, need_post_space
, language
);
392 case TYPE_CODE_MEMBERPTR
:
393 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
394 stream
, show
, 0, 0, language
, flags
, podata
);
395 name
= TYPE_SELF_TYPE (type
)->name ();
397 print_name_maybe_canonical (name
, flags
, stream
);
399 c_type_print_base_1 (TYPE_SELF_TYPE (type
),
400 stream
, -1, passed_a_ptr
, language
, flags
,
402 gdb_printf (stream
, "::*");
405 case TYPE_CODE_METHODPTR
:
406 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
407 stream
, show
, 0, 0, language
, flags
,
409 gdb_printf (stream
, "(");
410 name
= TYPE_SELF_TYPE (type
)->name ();
412 print_name_maybe_canonical (name
, flags
, stream
);
414 c_type_print_base_1 (TYPE_SELF_TYPE (type
),
415 stream
, -1, passed_a_ptr
, language
, flags
,
417 gdb_printf (stream
, "::*");
421 case TYPE_CODE_RVALUE_REF
:
422 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
423 stream
, show
, 1, 0, language
, flags
,
425 gdb_printf (stream
, type
->code () == TYPE_CODE_REF
? "&" : "&&");
426 c_type_print_modifier (type
, stream
, 1, need_post_space
, language
);
429 case TYPE_CODE_METHOD
:
431 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
432 stream
, show
, 0, 0, language
, flags
,
435 gdb_printf (stream
, "(");
438 case TYPE_CODE_ARRAY
:
439 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
440 stream
, show
, 0, need_post_space
,
441 language
, flags
, podata
);
443 gdb_printf (stream
, "(");
446 case TYPE_CODE_TYPEDEF
:
447 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
448 stream
, show
, passed_a_ptr
, 0,
449 language
, flags
, podata
);
452 case TYPE_CODE_UNDEF
:
453 case TYPE_CODE_STRUCT
:
454 case TYPE_CODE_UNION
:
456 case TYPE_CODE_FLAGS
:
460 case TYPE_CODE_ERROR
:
464 case TYPE_CODE_RANGE
:
465 case TYPE_CODE_STRING
:
466 case TYPE_CODE_COMPLEX
:
467 case TYPE_CODE_NAMESPACE
:
468 case TYPE_CODE_DECFLOAT
:
469 case TYPE_CODE_FIXED_POINT
:
470 /* These types need no prefix. They are listed here so that
471 gcc -Wall will reveal any types that haven't been handled. */
474 error (_("type not handled in c_type_print_varspec_prefix()"));
479 /* Print out "const" and "volatile" attributes,
480 and address space id if present.
481 TYPE is a pointer to the type being printed out.
482 STREAM is the output destination.
483 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
484 NEED_POST_SPACE = 1 indicates a final white space is needed. */
487 c_type_print_modifier (struct type
*type
, struct ui_file
*stream
,
488 int need_pre_space
, int need_post_space
,
489 enum language language
)
491 int did_print_modifier
= 0;
492 const char *address_space_id
;
494 /* We don't print `const' qualifiers for references --- since all
495 operators affect the thing referenced, not the reference itself,
496 every reference is `const'. */
497 if (TYPE_CONST (type
) && !TYPE_IS_REFERENCE (type
))
500 gdb_printf (stream
, " ");
501 gdb_printf (stream
, "const");
502 did_print_modifier
= 1;
505 if (TYPE_VOLATILE (type
))
507 if (did_print_modifier
|| need_pre_space
)
508 gdb_printf (stream
, " ");
509 gdb_printf (stream
, "volatile");
510 did_print_modifier
= 1;
513 if (TYPE_RESTRICT (type
))
515 if (did_print_modifier
|| need_pre_space
)
516 gdb_printf (stream
, " ");
517 gdb_printf (stream
, (language
== language_cplus
520 did_print_modifier
= 1;
523 if (TYPE_ATOMIC (type
))
525 if (did_print_modifier
|| need_pre_space
)
526 gdb_printf (stream
, " ");
527 gdb_printf (stream
, "_Atomic");
528 did_print_modifier
= 1;
532 = address_space_type_instance_flags_to_name (type
->arch (),
533 type
->instance_flags ());
534 if (address_space_id
)
536 if (did_print_modifier
|| need_pre_space
)
537 gdb_printf (stream
, " ");
538 gdb_printf (stream
, "@%s", address_space_id
);
539 did_print_modifier
= 1;
542 if (did_print_modifier
&& need_post_space
)
543 gdb_printf (stream
, " ");
547 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
548 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
549 in non-static methods, are displayed if LINKAGE_NAME is zero. If
550 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
551 parameter types get removed their possible const and volatile qualifiers to
552 match demangled linkage name parameters part of such function type.
553 LANGUAGE is the language in which TYPE was defined. This is a necessary
554 evil since this code is used by the C and C++. */
557 c_type_print_args (struct type
*type
, struct ui_file
*stream
,
558 int linkage_name
, enum language language
,
559 const struct type_print_options
*flags
)
564 gdb_printf (stream
, "(");
566 for (i
= 0; i
< type
->num_fields (); i
++)
568 struct type
*param_type
;
570 if (TYPE_FIELD_ARTIFICIAL (type
, i
) && linkage_name
)
575 gdb_printf (stream
, ", ");
576 stream
->wrap_here (4);
579 param_type
= type
->field (i
).type ();
581 if (language
== language_cplus
&& linkage_name
)
583 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
584 - Parameter declarations that differ only in the presence or
585 absence of const and/or volatile are equivalent.
587 And the const/volatile qualifiers are not present in the mangled
588 names as produced by GCC. */
590 param_type
= make_cv_type (0, 0, param_type
, NULL
);
593 c_print_type (param_type
, "", stream
, -1, 0, language
, flags
);
597 if (printed_any
&& type
->has_varargs ())
599 /* Print out a trailing ellipsis for varargs functions. Ignore
600 TYPE_VARARGS if the function has no named arguments; that
601 represents unprototyped (K&R style) C functions. */
602 if (printed_any
&& type
->has_varargs ())
604 gdb_printf (stream
, ", ");
605 stream
->wrap_here (4);
606 gdb_printf (stream
, "...");
609 else if (!printed_any
610 && (type
->is_prototyped () || language
== language_cplus
))
611 gdb_printf (stream
, "void");
613 gdb_printf (stream
, ")");
616 /* Return true iff the j'th overloading of the i'th method of TYPE
617 is a type conversion operator, like `operator int () { ... }'.
618 When listing a class's methods, we don't print the return type of
622 is_type_conversion_operator (struct type
*type
, int i
, int j
)
624 /* I think the whole idea of recognizing type conversion operators
625 by their name is pretty terrible. But I don't think our present
626 data structure gives us any other way to tell. If you know of
627 some other way, feel free to rewrite this function. */
628 const char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
630 if (!startswith (name
, CP_OPERATOR_STR
))
634 if (! strchr (" \t\f\n\r", *name
))
637 while (strchr (" \t\f\n\r", *name
))
640 if (!('a' <= *name
&& *name
<= 'z')
641 && !('A' <= *name
&& *name
<= 'Z')
643 /* If this doesn't look like the start of an identifier, then it
644 isn't a type conversion operator. */
646 else if (startswith (name
, "new"))
648 else if (startswith (name
, "delete"))
651 /* If it doesn't look like new or delete, it's a type conversion
655 /* Is that really the end of the name? */
656 if (('a' <= *name
&& *name
<= 'z')
657 || ('A' <= *name
&& *name
<= 'Z')
658 || ('0' <= *name
&& *name
<= '9')
660 /* No, so the identifier following "operator" must be a type name,
661 and this is a type conversion operator. */
664 /* That was indeed the end of the name, so it was `operator new' or
665 `operator delete', neither of which are type conversion
670 /* Given a C++ qualified identifier QID, strip off the qualifiers,
671 yielding the unqualified name. The return value is a pointer into
674 It's a pity we don't have this information in some more structured
675 form. Even the author of this function feels that writing little
676 parsers like this everywhere is stupid. */
679 remove_qualifiers (const char *qid
)
681 int quoted
= 0; /* Zero if we're not in quotes;
682 '"' if we're in a double-quoted string;
683 '\'' if we're in a single-quoted string. */
684 int depth
= 0; /* Number of unclosed parens we've seen. */
685 char *parenstack
= (char *) alloca (strlen (qid
));
687 const char *last
= 0; /* The character after the rightmost
688 `::' token we've seen so far. */
690 for (scan
= qid
; *scan
; scan
++)
696 else if (*scan
== '\\' && *(scan
+ 1))
699 else if (scan
[0] == ':' && scan
[1] == ':')
701 /* If we're inside parenthesis (i.e., an argument list) or
702 angle brackets (i.e., a list of template arguments), then
703 we don't record the position of this :: token, since it's
704 not relevant to the top-level structure we're trying to
712 else if (*scan
== '"' || *scan
== '\'')
714 else if (*scan
== '(')
715 parenstack
[depth
++] = ')';
716 else if (*scan
== '[')
717 parenstack
[depth
++] = ']';
718 /* We're going to treat <> as a pair of matching characters,
719 since we're more likely to see those in template id's than
720 real less-than characters. What a crock. */
721 else if (*scan
== '<')
722 parenstack
[depth
++] = '>';
723 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
725 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
729 /* We're going to do a little error recovery here. If
730 we don't find a match for *scan on the paren stack,
731 but there is something lower on the stack that does
732 match, we pop the stack to that point. */
735 for (i
= depth
- 1; i
>= 0; i
--)
736 if (parenstack
[i
] == *scan
)
748 /* We didn't find any :: tokens at the top level, so declare the
749 whole thing an unqualified identifier. */
753 /* Print any array sizes, function arguments or close parentheses
754 needed after the variable name (to describe its type).
755 Args work like c_type_print_varspec_prefix. */
758 c_type_print_varspec_suffix (struct type
*type
,
759 struct ui_file
*stream
,
760 int show
, int passed_a_ptr
,
762 enum language language
,
763 const struct type_print_options
*flags
)
768 if (type
->name () && show
<= 0)
773 switch (type
->code ())
775 case TYPE_CODE_ARRAY
:
777 LONGEST low_bound
, high_bound
;
778 int is_vector
= type
->is_vector ();
781 gdb_printf (stream
, ")");
783 gdb_printf (stream
, (is_vector
?
784 " __attribute__ ((vector_size(" : "["));
785 /* Bounds are not yet resolved, print a bounds placeholder instead. */
786 if (type
->bounds ()->high
.kind () == PROP_LOCEXPR
787 || type
->bounds ()->high
.kind () == PROP_LOCLIST
)
788 gdb_printf (stream
, "variable length");
789 else if (get_array_bounds (type
, &low_bound
, &high_bound
))
790 gdb_printf (stream
, "%s",
791 plongest (high_bound
- low_bound
+ 1));
792 gdb_printf (stream
, (is_vector
? ")))" : "]"));
794 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
795 show
, 0, 0, language
, flags
);
799 case TYPE_CODE_MEMBERPTR
:
800 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
801 show
, 0, 0, language
, flags
);
804 case TYPE_CODE_METHODPTR
:
805 gdb_printf (stream
, ")");
806 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
807 show
, 0, 0, language
, flags
);
812 case TYPE_CODE_RVALUE_REF
:
813 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
814 show
, 1, 0, language
, flags
);
817 case TYPE_CODE_METHOD
:
820 gdb_printf (stream
, ")");
822 c_type_print_args (type
, stream
, 0, language
, flags
);
823 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
824 show
, passed_a_ptr
, 0, language
, flags
);
827 case TYPE_CODE_TYPEDEF
:
828 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
829 show
, passed_a_ptr
, 0, language
, flags
);
832 case TYPE_CODE_UNDEF
:
833 case TYPE_CODE_STRUCT
:
834 case TYPE_CODE_UNION
:
835 case TYPE_CODE_FLAGS
:
840 case TYPE_CODE_ERROR
:
844 case TYPE_CODE_RANGE
:
845 case TYPE_CODE_STRING
:
846 case TYPE_CODE_COMPLEX
:
847 case TYPE_CODE_NAMESPACE
:
848 case TYPE_CODE_DECFLOAT
:
849 case TYPE_CODE_FIXED_POINT
:
850 /* These types do not need a suffix. They are listed so that
851 gcc -Wall will report types that may not have been
855 error (_("type not handled in c_type_print_varspec_suffix()"));
860 /* A helper for c_type_print_base that displays template
861 parameters and their bindings, if needed.
863 TABLE is the local bindings table to use. If NULL, no printing is
864 done. Note that, at this point, TABLE won't have any useful
865 information in it -- but it is also used as a flag to
866 print_name_maybe_canonical to activate searching the global typedef
869 TYPE is the type whose template arguments are being displayed.
871 STREAM is the stream on which to print. */
874 c_type_print_template_args (const struct type_print_options
*flags
,
875 struct type
*type
, struct ui_file
*stream
)
882 for (i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
884 struct symbol
*sym
= TYPE_TEMPLATE_ARGUMENT (type
, i
);
886 if (sym
->aclass () != LOC_TYPEDEF
)
891 stream
->wrap_here (4);
892 gdb_printf (stream
, _("[with %s = "), sym
->linkage_name ());
897 gdb_puts (", ", stream
);
898 stream
->wrap_here (9);
899 gdb_printf (stream
, "%s = ", sym
->linkage_name ());
902 c_print_type (sym
->type (), "", stream
, -1, 0, flags
);
906 gdb_puts (_("] "), stream
);
909 /* Use 'print_spaces', but take into consideration the
910 type_print_options FLAGS in order to determine how many whitespaces
914 print_spaces_filtered_with_print_options
915 (int level
, struct ui_file
*stream
, const struct type_print_options
*flags
)
917 if (!flags
->print_offsets
)
918 print_spaces (level
, stream
);
920 print_spaces (level
+ print_offset_data::indentation
, stream
);
923 /* Output an access specifier to STREAM, if needed. LAST_ACCESS is the
924 last access specifier output (typically returned by this function). */
926 static enum access_specifier
927 output_access_specifier (struct ui_file
*stream
,
928 enum access_specifier last_access
,
929 int level
, bool is_protected
, bool is_private
,
930 const struct type_print_options
*flags
)
934 if (last_access
!= s_protected
)
936 last_access
= s_protected
;
937 print_spaces_filtered_with_print_options (level
+ 2, stream
, flags
);
938 gdb_printf (stream
, "protected:\n");
943 if (last_access
!= s_private
)
945 last_access
= s_private
;
946 print_spaces_filtered_with_print_options (level
+ 2, stream
, flags
);
947 gdb_printf (stream
, "private:\n");
952 if (last_access
!= s_public
)
954 last_access
= s_public
;
955 print_spaces_filtered_with_print_options (level
+ 2, stream
, flags
);
956 gdb_printf (stream
, "public:\n");
963 /* Return true if an access label (i.e., "public:", "private:",
964 "protected:") needs to be printed for TYPE. */
967 need_access_label_p (struct type
*type
)
969 if (type
->is_declared_class ())
972 for (int i
= TYPE_N_BASECLASSES (type
); i
< type
->num_fields (); i
++)
973 if (!TYPE_FIELD_PRIVATE (type
, i
))
976 for (int j
= 0; j
< TYPE_NFN_FIELDS (type
); j
++)
977 for (int i
= 0; i
< TYPE_FN_FIELDLIST_LENGTH (type
, j
); i
++)
978 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
982 for (int i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); ++i
)
983 if (!TYPE_TYPEDEF_FIELD_PRIVATE (type
, i
))
989 for (int i
= TYPE_N_BASECLASSES (type
); i
< type
->num_fields (); i
++)
990 if (TYPE_FIELD_PRIVATE (type
, i
) || TYPE_FIELD_PROTECTED (type
, i
))
993 for (int j
= 0; j
< TYPE_NFN_FIELDS (type
); j
++)
996 for (int i
= 0; i
< TYPE_FN_FIELDLIST_LENGTH (type
, j
); i
++)
997 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
,
999 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
1005 for (int i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); ++i
)
1006 if (TYPE_TYPEDEF_FIELD_PROTECTED (type
, i
)
1007 || TYPE_TYPEDEF_FIELD_PRIVATE (type
, i
))
1014 /* Helper function that temporarily disables FLAGS->PRINT_OFFSETS,
1015 calls 'c_print_type_1', and then reenables FLAGS->PRINT_OFFSETS if
1019 c_print_type_no_offsets (struct type
*type
,
1020 const char *varstring
,
1021 struct ui_file
*stream
,
1022 int show
, int level
,
1023 enum language language
,
1024 struct type_print_options
*flags
,
1025 struct print_offset_data
*podata
)
1027 unsigned int old_po
= flags
->print_offsets
;
1029 /* Temporarily disable print_offsets, because it would mess with
1031 flags
->print_offsets
= 0;
1032 c_print_type_1 (type
, varstring
, stream
, show
, level
, language
, flags
,
1034 flags
->print_offsets
= old_po
;
1037 /* Helper for 'c_type_print_base' that handles structs and unions.
1038 For a description of the arguments, see 'c_type_print_base'. */
1041 c_type_print_base_struct_union (struct type
*type
, struct ui_file
*stream
,
1042 int show
, int level
,
1043 enum language language
,
1044 const struct type_print_options
*flags
,
1045 struct print_offset_data
*podata
)
1047 struct type_print_options local_flags
= *flags
;
1048 local_flags
.local_typedefs
= NULL
;
1050 std::unique_ptr
<typedef_hash_table
> hash_holder
;
1053 if (flags
->local_typedefs
)
1054 local_flags
.local_typedefs
1055 = new typedef_hash_table (*flags
->local_typedefs
);
1057 local_flags
.local_typedefs
= new typedef_hash_table ();
1059 hash_holder
.reset (local_flags
.local_typedefs
);
1062 c_type_print_modifier (type
, stream
, 0, 1, language
);
1063 if (type
->code () == TYPE_CODE_UNION
)
1064 gdb_printf (stream
, "union ");
1065 else if (type
->is_declared_class ())
1066 gdb_printf (stream
, "class ");
1068 gdb_printf (stream
, "struct ");
1070 /* Print the tag if it exists. The HP aCC compiler emits a
1071 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
1072 enum}" tag for unnamed struct/union/enum's, which we don't
1074 if (type
->name () != NULL
1075 && !startswith (type
->name (), "{unnamed"))
1077 /* When printing the tag name, we are still effectively
1078 printing in the outer context, hence the use of FLAGS
1080 print_name_maybe_canonical (type
->name (), flags
, stream
);
1082 gdb_puts (" ", stream
);
1087 /* If we just printed a tag name, no need to print anything
1089 if (type
->name () == NULL
)
1090 gdb_printf (stream
, "{...}");
1092 else if (show
> 0 || type
->name () == NULL
)
1094 struct type
*basetype
;
1097 c_type_print_template_args (&local_flags
, type
, stream
);
1099 /* Add in template parameters when printing derivation info. */
1100 if (local_flags
.local_typedefs
!= NULL
)
1101 local_flags
.local_typedefs
->add_template_parameters (type
);
1102 cp_type_print_derivation_info (stream
, type
, &local_flags
);
1104 /* This holds just the global typedefs and the template
1106 struct type_print_options semi_local_flags
= *flags
;
1107 semi_local_flags
.local_typedefs
= NULL
;
1109 std::unique_ptr
<typedef_hash_table
> semi_holder
;
1110 if (local_flags
.local_typedefs
!= nullptr)
1112 semi_local_flags
.local_typedefs
1113 = new typedef_hash_table (*local_flags
.local_typedefs
);
1114 semi_holder
.reset (semi_local_flags
.local_typedefs
);
1116 /* Now add in the local typedefs. */
1117 local_flags
.local_typedefs
->recursively_update (type
);
1120 gdb_printf (stream
, "{\n");
1122 if (type
->num_fields () == 0 && TYPE_NFN_FIELDS (type
) == 0
1123 && TYPE_TYPEDEF_FIELD_COUNT (type
) == 0)
1125 print_spaces_filtered_with_print_options (level
+ 4, stream
, flags
);
1126 if (type
->is_stub ())
1127 gdb_printf (stream
, _("%p[<incomplete type>%p]\n"),
1128 metadata_style
.style ().ptr (), nullptr);
1130 gdb_printf (stream
, _("%p[<no data fields>%p]\n"),
1131 metadata_style
.style ().ptr (), nullptr);
1134 /* Start off with no specific section type, so we can print
1135 one for the first field we find, and use that section type
1136 thereafter until we find another type. */
1138 enum access_specifier section_type
= s_none
;
1140 /* For a class, if all members are private, there's no need
1141 for a "private:" label; similarly, for a struct or union
1142 masquerading as a class, if all members are public, there's
1143 no need for a "public:" label. */
1144 bool need_access_label
= need_access_label_p (type
);
1146 /* If there is a base class for this type,
1147 do not print the field that it occupies. */
1149 int len
= type
->num_fields ();
1150 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
1152 struct print_offset_data
local_podata (flags
);
1154 for (int i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1158 /* If we have a virtual table pointer, omit it. Even if
1159 virtual table pointers are not specifically marked in
1160 the debug info, they should be artificial. */
1161 if ((i
== vptr_fieldno
&& type
== basetype
)
1162 || TYPE_FIELD_ARTIFICIAL (type
, i
))
1165 if (need_access_label
)
1167 section_type
= output_access_specifier
1168 (stream
, section_type
, level
,
1169 TYPE_FIELD_PROTECTED (type
, i
),
1170 TYPE_FIELD_PRIVATE (type
, i
), flags
);
1173 bool is_static
= field_is_static (&type
->field (i
));
1175 if (flags
->print_offsets
)
1176 podata
->update (type
, i
, stream
);
1178 print_spaces (level
+ 4, stream
);
1180 gdb_printf (stream
, "static ");
1182 int newshow
= show
- 1;
1184 if (!is_static
&& flags
->print_offsets
1185 && (type
->field (i
).type ()->code () == TYPE_CODE_STRUCT
1186 || type
->field (i
).type ()->code () == TYPE_CODE_UNION
))
1188 /* If we're printing offsets and this field's type is
1189 either a struct or an union, then we're interested in
1193 /* Make sure we carry our offset when we expand the
1195 local_podata
.offset_bitpos
1196 = podata
->offset_bitpos
+ type
->field (i
).loc_bitpos ();
1197 /* We're entering a struct/union. Right now,
1198 PODATA->END_BITPOS points right *after* the
1199 struct/union. However, when printing the first field
1200 of this inner struct/union, the end_bitpos we're
1201 expecting is exactly at the beginning of the
1202 struct/union. Therefore, we subtract the length of
1203 the whole struct/union. */
1204 local_podata
.end_bitpos
1205 = podata
->end_bitpos
1206 - TYPE_LENGTH (type
->field (i
).type ()) * TARGET_CHAR_BIT
;
1209 c_print_type_1 (type
->field (i
).type (),
1210 type
->field (i
).name (),
1211 stream
, newshow
, level
+ 4,
1212 language
, &local_flags
, &local_podata
);
1214 if (!is_static
&& TYPE_FIELD_PACKED (type
, i
))
1216 /* It is a bitfield. This code does not attempt
1217 to look at the bitpos and reconstruct filler,
1218 unnamed fields. This would lead to misleading
1219 results if the compiler does not put out fields
1220 for such things (I don't know what it does). */
1221 gdb_printf (stream
, " : %d",
1222 TYPE_FIELD_BITSIZE (type
, i
));
1224 gdb_printf (stream
, ";\n");
1227 /* If there are both fields and methods, put a blank line
1228 between them. Make sure to count only method that we
1229 will display; artificial methods will be hidden. */
1230 len
= TYPE_NFN_FIELDS (type
);
1231 if (!flags
->print_methods
)
1234 for (int i
= 0; i
< len
; i
++)
1236 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1237 int len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1240 for (j
= 0; j
< len2
; j
++)
1241 if (!TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1244 if (real_len
> 0 && section_type
!= s_none
)
1245 gdb_printf (stream
, "\n");
1247 /* C++: print out the methods. */
1248 for (int i
= 0; i
< len
; i
++)
1250 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1251 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1252 const char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1253 const char *name
= type
->name ();
1254 int is_constructor
= name
&& strcmp (method_name
,
1257 for (j
= 0; j
< len2
; j
++)
1259 const char *mangled_name
;
1260 gdb::unique_xmalloc_ptr
<char> mangled_name_holder
;
1261 const char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1262 int is_full_physname_constructor
=
1263 TYPE_FN_FIELD_CONSTRUCTOR (f
, j
)
1264 || is_constructor_name (physname
)
1265 || is_destructor_name (physname
)
1266 || method_name
[0] == '~';
1268 /* Do not print out artificial methods. */
1269 if (TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1273 section_type
= output_access_specifier
1274 (stream
, section_type
, level
,
1275 TYPE_FN_FIELD_PROTECTED (f
, j
),
1276 TYPE_FN_FIELD_PRIVATE (f
, j
), flags
);
1278 print_spaces_filtered_with_print_options (level
+ 4, stream
,
1280 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1281 gdb_printf (stream
, "virtual ");
1282 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1283 gdb_printf (stream
, "static ");
1284 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1286 /* Keep GDB from crashing here. */
1288 _("%p[<undefined type>%p] %s;\n"),
1289 metadata_style
.style ().ptr (), nullptr,
1290 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1293 else if (!is_constructor
/* Constructors don't
1296 && !is_full_physname_constructor
/* " " */
1297 && !is_type_conversion_operator (type
, i
, j
))
1299 c_print_type_no_offsets
1300 (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1301 "", stream
, -1, 0, language
, &local_flags
, podata
);
1303 gdb_puts (" ", stream
);
1305 if (TYPE_FN_FIELD_STUB (f
, j
))
1307 /* Build something we can demangle. */
1308 mangled_name_holder
.reset (gdb_mangle_name (type
, i
, j
));
1309 mangled_name
= mangled_name_holder
.get ();
1312 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1314 gdb::unique_xmalloc_ptr
<char> demangled_name
1315 = gdb_demangle (mangled_name
,
1316 DMGL_ANSI
| DMGL_PARAMS
);
1317 if (demangled_name
== NULL
)
1319 /* In some cases (for instance with the HP
1320 demangling), if a function has more than 10
1321 arguments, the demangling will fail.
1322 Let's try to reconstruct the function
1323 signature from the symbol information. */
1324 if (!TYPE_FN_FIELD_STUB (f
, j
))
1326 int staticp
= TYPE_FN_FIELD_STATIC_P (f
, j
);
1327 struct type
*mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
1329 cp_type_print_method_args (mtype
,
1337 fprintf_styled (stream
, metadata_style
.style (),
1338 _("<badly mangled name '%s'>"),
1344 const char *demangled_no_class
1345 = remove_qualifiers (demangled_name
.get ());
1347 /* Get rid of the `static' appended by the
1349 p
= strstr (demangled_no_class
, " static");
1352 int length
= p
- demangled_no_class
;
1353 std::string
demangled_no_static (demangled_no_class
,
1355 gdb_puts (demangled_no_static
.c_str (), stream
);
1358 gdb_puts (demangled_no_class
, stream
);
1361 gdb_printf (stream
, ";\n");
1365 /* Print out nested types. */
1366 if (TYPE_NESTED_TYPES_COUNT (type
) != 0
1367 && semi_local_flags
.print_nested_type_limit
!= 0)
1369 if (semi_local_flags
.print_nested_type_limit
> 0)
1370 --semi_local_flags
.print_nested_type_limit
;
1372 if (type
->num_fields () != 0 || TYPE_NFN_FIELDS (type
) != 0)
1373 gdb_printf (stream
, "\n");
1375 for (int i
= 0; i
< TYPE_NESTED_TYPES_COUNT (type
); ++i
)
1377 print_spaces_filtered_with_print_options (level
+ 4, stream
,
1379 c_print_type_no_offsets (TYPE_NESTED_TYPES_FIELD_TYPE (type
, i
),
1380 "", stream
, show
, level
+ 4,
1381 language
, &semi_local_flags
, podata
);
1382 gdb_printf (stream
, ";\n");
1386 /* Print typedefs defined in this class. */
1388 if (TYPE_TYPEDEF_FIELD_COUNT (type
) != 0 && flags
->print_typedefs
)
1390 if (type
->num_fields () != 0 || TYPE_NFN_FIELDS (type
) != 0
1391 || TYPE_NESTED_TYPES_COUNT (type
) != 0)
1392 gdb_printf (stream
, "\n");
1394 for (int i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); i
++)
1396 struct type
*target
= TYPE_TYPEDEF_FIELD_TYPE (type
, i
);
1398 /* Dereference the typedef declaration itself. */
1399 gdb_assert (target
->code () == TYPE_CODE_TYPEDEF
);
1400 target
= TYPE_TARGET_TYPE (target
);
1402 if (need_access_label
)
1404 section_type
= output_access_specifier
1405 (stream
, section_type
, level
,
1406 TYPE_TYPEDEF_FIELD_PROTECTED (type
, i
),
1407 TYPE_TYPEDEF_FIELD_PRIVATE (type
, i
), flags
);
1409 print_spaces_filtered_with_print_options (level
+ 4, stream
,
1411 gdb_printf (stream
, "typedef ");
1413 /* We want to print typedefs with substitutions
1414 from the template parameters or globally-known
1415 typedefs but not local typedefs. */
1416 c_print_type_no_offsets (target
,
1417 TYPE_TYPEDEF_FIELD_NAME (type
, i
),
1418 stream
, show
- 1, level
+ 4,
1419 language
, &semi_local_flags
, podata
);
1420 gdb_printf (stream
, ";\n");
1424 if (flags
->print_offsets
)
1427 podata
->finish (type
, level
, stream
);
1429 print_spaces (print_offset_data::indentation
, stream
);
1431 print_spaces (2, stream
);
1434 gdb_printf (stream
, "%*s}", level
, "");
1438 /* Print the name of the type (or the ultimate pointer target,
1439 function value or array element), or the description of a structure
1442 SHOW positive means print details about the type (e.g. enum
1443 values), and print structure elements passing SHOW - 1 for show.
1445 SHOW negative means just print the type name or struct tag if there
1446 is one. If there is no name, print something sensible but concise
1447 like "struct {...}".
1449 SHOW zero means just print the type name or struct tag if there is
1450 one. If there is no name, print something sensible but not as
1451 concise like "struct {int x; int y;}".
1453 LEVEL is the number of spaces to indent by.
1454 We increase it for some recursive calls. */
1457 c_type_print_base_1 (struct type
*type
, struct ui_file
*stream
,
1458 int show
, int level
,
1459 enum language language
,
1460 const struct type_print_options
*flags
,
1461 struct print_offset_data
*podata
)
1470 fputs_styled (_("<type unknown>"), metadata_style
.style (), stream
);
1474 /* When SHOW is zero or less, and there is a valid type name, then
1475 always just print the type name directly from the type. */
1478 && type
->name () != NULL
)
1480 c_type_print_modifier (type
, stream
, 0, 1, language
);
1482 /* If we have "typedef struct foo {. . .} bar;" do we want to
1483 print it as "struct foo" or as "bar"? Pick the latter for
1484 C++, because C++ folk tend to expect things like "class5
1485 *foo" rather than "struct class5 *foo". We rather
1486 arbitrarily choose to make language_minimal work in a C-like
1488 if (language
== language_c
|| language
== language_minimal
)
1490 if (type
->code () == TYPE_CODE_UNION
)
1491 gdb_printf (stream
, "union ");
1492 else if (type
->code () == TYPE_CODE_STRUCT
)
1494 if (type
->is_declared_class ())
1495 gdb_printf (stream
, "class ");
1497 gdb_printf (stream
, "struct ");
1499 else if (type
->code () == TYPE_CODE_ENUM
)
1500 gdb_printf (stream
, "enum ");
1503 print_name_maybe_canonical (type
->name (), flags
, stream
);
1507 type
= check_typedef (type
);
1509 switch (type
->code ())
1511 case TYPE_CODE_TYPEDEF
:
1512 /* If we get here, the typedef doesn't have a name, and we
1513 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
1514 gdb_assert (type
->name () == NULL
);
1515 gdb_assert (TYPE_TARGET_TYPE (type
) == NULL
);
1516 fprintf_styled (stream
, metadata_style
.style (),
1517 _("<unnamed typedef>"));
1520 case TYPE_CODE_FUNC
:
1521 case TYPE_CODE_METHOD
:
1522 if (TYPE_TARGET_TYPE (type
) == NULL
)
1523 type_print_unknown_return_type (stream
);
1525 c_type_print_base_1 (TYPE_TARGET_TYPE (type
),
1526 stream
, show
, level
, language
, flags
, podata
);
1528 case TYPE_CODE_ARRAY
:
1530 case TYPE_CODE_MEMBERPTR
:
1532 case TYPE_CODE_RVALUE_REF
:
1533 case TYPE_CODE_METHODPTR
:
1534 c_type_print_base_1 (TYPE_TARGET_TYPE (type
),
1535 stream
, show
, level
, language
, flags
, podata
);
1538 case TYPE_CODE_STRUCT
:
1539 case TYPE_CODE_UNION
:
1540 c_type_print_base_struct_union (type
, stream
, show
, level
,
1541 language
, flags
, podata
);
1544 case TYPE_CODE_ENUM
:
1545 c_type_print_modifier (type
, stream
, 0, 1, language
);
1546 gdb_printf (stream
, "enum ");
1547 if (type
->is_declared_class ())
1548 gdb_printf (stream
, "class ");
1549 /* Print the tag name if it exists.
1550 The aCC compiler emits a spurious
1551 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1552 tag for unnamed struct/union/enum's, which we don't
1554 if (type
->name () != NULL
1555 && !startswith (type
->name (), "{unnamed"))
1557 print_name_maybe_canonical (type
->name (), flags
, stream
);
1559 gdb_puts (" ", stream
);
1562 stream
->wrap_here (4);
1565 /* If we just printed a tag name, no need to print anything
1567 if (type
->name () == NULL
)
1568 gdb_printf (stream
, "{...}");
1570 else if (show
> 0 || type
->name () == NULL
)
1572 LONGEST lastval
= 0;
1574 /* We can't handle this case perfectly, as DWARF does not
1575 tell us whether or not the underlying type was specified
1576 in the source (and other debug formats don't provide this
1577 at all). We choose to print the underlying type, if it
1578 has a name, when in C++ on the theory that it's better to
1579 print too much than too little; but conversely not to
1580 print something egregiously outside the current
1581 language's syntax. */
1582 if (language
== language_cplus
&& TYPE_TARGET_TYPE (type
) != NULL
)
1584 struct type
*underlying
= check_typedef (TYPE_TARGET_TYPE (type
));
1586 if (underlying
->name () != NULL
)
1587 gdb_printf (stream
, ": %s ", underlying
->name ());
1590 gdb_printf (stream
, "{");
1591 len
= type
->num_fields ();
1592 for (i
= 0; i
< len
; i
++)
1596 gdb_printf (stream
, ", ");
1597 stream
->wrap_here (4);
1598 fputs_styled (type
->field (i
).name (),
1599 variable_name_style
.style (), stream
);
1600 if (lastval
!= type
->field (i
).loc_enumval ())
1602 gdb_printf (stream
, " = %s",
1603 plongest (type
->field (i
).loc_enumval ()));
1604 lastval
= type
->field (i
).loc_enumval ();
1608 gdb_printf (stream
, "}");
1612 case TYPE_CODE_FLAGS
:
1614 struct type_print_options local_flags
= *flags
;
1616 local_flags
.local_typedefs
= NULL
;
1618 c_type_print_modifier (type
, stream
, 0, 1, language
);
1619 gdb_printf (stream
, "flag ");
1620 print_name_maybe_canonical (type
->name (), flags
, stream
);
1623 gdb_puts (" ", stream
);
1624 gdb_printf (stream
, "{\n");
1625 if (type
->num_fields () == 0)
1627 if (type
->is_stub ())
1629 _("%*s%p[<incomplete type>%p]\n"),
1631 metadata_style
.style ().ptr (), nullptr);
1634 _("%*s%p[<no data fields>%p]\n"),
1636 metadata_style
.style ().ptr (), nullptr);
1638 len
= type
->num_fields ();
1639 for (i
= 0; i
< len
; i
++)
1642 print_spaces (level
+ 4, stream
);
1643 /* We pass "show" here and not "show - 1" to get enum types
1644 printed. There's no other way to see them. */
1645 c_print_type_1 (type
->field (i
).type (),
1646 type
->field (i
).name (),
1647 stream
, show
, level
+ 4,
1648 language
, &local_flags
, podata
);
1649 gdb_printf (stream
, " @%s",
1650 plongest (type
->field (i
).loc_bitpos ()));
1651 if (TYPE_FIELD_BITSIZE (type
, i
) > 1)
1653 gdb_printf (stream
, "-%s",
1654 plongest (type
->field (i
).loc_bitpos ()
1655 + TYPE_FIELD_BITSIZE (type
, i
)
1658 gdb_printf (stream
, ";\n");
1660 gdb_printf (stream
, "%*s}", level
, "");
1665 case TYPE_CODE_VOID
:
1666 gdb_printf (stream
, "void");
1669 case TYPE_CODE_UNDEF
:
1670 gdb_printf (stream
, _("struct <unknown>"));
1673 case TYPE_CODE_ERROR
:
1674 gdb_printf (stream
, "%s", TYPE_ERROR_NAME (type
));
1677 case TYPE_CODE_RANGE
:
1678 /* This should not occur. */
1679 fprintf_styled (stream
, metadata_style
.style (), _("<range type>"));
1682 case TYPE_CODE_FIXED_POINT
:
1683 print_type_fixed_point (type
, stream
);
1686 case TYPE_CODE_NAMESPACE
:
1687 gdb_puts ("namespace ", stream
);
1688 gdb_puts (type
->name (), stream
);
1692 /* Handle types not explicitly handled by the other cases, such
1693 as fundamental types. For these, just print whatever the
1694 type name is, as recorded in the type itself. If there is no
1695 type name, then complain. */
1696 if (type
->name () != NULL
)
1698 c_type_print_modifier (type
, stream
, 0, 1, language
);
1699 print_name_maybe_canonical (type
->name (), flags
, stream
);
1703 /* At least for dump_symtab, it is important that this not
1705 fprintf_styled (stream
, metadata_style
.style (),
1706 _("<invalid type code %d>"), type
->code ());
1712 /* See c_type_print_base_1. */
1715 c_type_print_base (struct type
*type
, struct ui_file
*stream
,
1716 int show
, int level
,
1717 const struct type_print_options
*flags
)
1719 struct print_offset_data
podata (flags
);
1721 c_type_print_base_1 (type
, stream
, show
, level
,
1722 current_language
->la_language
, flags
, &podata
);