1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright (C) 1986-2018 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 "gdb_obstack.h"
21 #include "bfd.h" /* Binary File Description. */
24 #include "expression.h"
31 #include "typeprint.h"
33 #include "cp-support.h"
35 /* When printing the offsets of a struct and its fields (i.e., 'ptype
36 /o'; type_print_options::print_offsets), we use this many
37 characters when printing the offset information at the beginning of
38 the line. This is needed in order to generate the correct amount
39 of whitespaces when no offset info should be printed for a certain
41 #define OFFSET_SPC_LEN 23
43 /* A list of access specifiers used for printing. */
53 static void c_type_print_varspec_prefix (struct type *,
56 const struct type_print_options *,
57 struct print_offset_data *);
59 /* Print "const", "volatile", or address space modifiers. */
60 static void c_type_print_modifier (struct type *,
64 static void c_type_print_base_1 (struct type *type, struct ui_file *stream,
66 const struct type_print_options *flags,
67 struct print_offset_data *podata);
70 /* A callback function for cp_canonicalize_string_full that uses
71 typedef_hash_table::find_typedef. */
74 find_typedef_for_canonicalize (struct type *t, void *data)
76 return typedef_hash_table::find_typedef
77 ((const struct type_print_options *) data, t);
80 /* Print NAME on STREAM. If the 'raw' field of FLAGS is not set,
81 canonicalize NAME using the local typedefs first. */
84 print_name_maybe_canonical (const char *name,
85 const struct type_print_options *flags,
86 struct ui_file *stream)
91 s = cp_canonicalize_string_full (name,
92 find_typedef_for_canonicalize,
95 fputs_filtered (!s.empty () ? s.c_str () : name, stream);
100 /* Helper function for c_print_type. */
103 c_print_type_1 (struct type *type,
104 const char *varstring,
105 struct ui_file *stream,
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 if (local_name != NULL)
121 fputs_filtered (local_name, stream);
122 if (varstring != NULL && *varstring != '\0')
123 fputs_filtered (" ", stream);
127 c_type_print_base_1 (type, stream, show, level, flags, podata);
128 code = TYPE_CODE (type);
129 if ((varstring != NULL && *varstring != '\0')
130 /* Need a space if going to print stars or brackets;
131 but not if we will print just a type name. */
132 || ((show > 0 || TYPE_NAME (type) == 0)
133 && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
134 || code == TYPE_CODE_METHOD
135 || (code == TYPE_CODE_ARRAY
136 && !TYPE_VECTOR (type))
137 || code == TYPE_CODE_MEMBERPTR
138 || code == TYPE_CODE_METHODPTR
139 || TYPE_IS_REFERENCE (type))))
140 fputs_filtered (" ", stream);
141 need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
142 c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
146 if (varstring != NULL)
148 fputs_filtered (varstring, stream);
150 /* For demangled function names, we have the arglist as part of
151 the name, so don't print an additional pair of ()'s. */
152 if (local_name == NULL)
154 demangled_args = strchr (varstring, '(') != NULL;
155 c_type_print_varspec_suffix (type, stream, show,
162 /* LEVEL is the depth to indent lines by. */
165 c_print_type (struct type *type,
166 const char *varstring,
167 struct ui_file *stream,
169 const struct type_print_options *flags)
171 struct print_offset_data podata;
173 c_print_type_1 (type, varstring, stream, show, level, flags, &podata);
176 /* Print a typedef using C syntax. TYPE is the underlying type.
177 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
181 c_print_typedef (struct type *type,
182 struct symbol *new_symbol,
183 struct ui_file *stream)
185 type = check_typedef (type);
186 fprintf_filtered (stream, "typedef ");
187 type_print (type, "", stream, 0);
188 if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
189 || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
190 SYMBOL_LINKAGE_NAME (new_symbol)) != 0
191 || TYPE_CODE (SYMBOL_TYPE (new_symbol)) == TYPE_CODE_TYPEDEF)
192 fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
193 fprintf_filtered (stream, ";\n");
196 /* If TYPE is a derived type, then print out derivation information.
197 Print only the actual base classes of this type, not the base
198 classes of the base classes. I.e. for the derivation hierarchy:
201 class B : public A {int b; };
202 class C : public B {int c; };
204 Print the type of class C as:
210 Not as the following (like gdb used to), which is not legal C++
211 syntax for derived types and may be confused with the multiple
214 class C : public B : public A {
218 In general, gdb should try to print the types as closely as
219 possible to the form that they appear in the source code. */
222 cp_type_print_derivation_info (struct ui_file *stream,
224 const struct type_print_options *flags)
229 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
232 fputs_filtered (i == 0 ? ": " : ", ", stream);
233 fprintf_filtered (stream, "%s%s ",
234 BASETYPE_VIA_PUBLIC (type, i)
235 ? "public" : (TYPE_FIELD_PROTECTED (type, i)
236 ? "protected" : "private"),
237 BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
238 name = type_name_no_tag (TYPE_BASECLASS (type, i));
240 print_name_maybe_canonical (name, flags, stream);
242 fprintf_filtered (stream, "(null)");
246 fputs_filtered (" ", stream);
250 /* Print the C++ method arguments ARGS to the file STREAM. */
253 cp_type_print_method_args (struct type *mtype, const char *prefix,
254 const char *varstring, int staticp,
255 struct ui_file *stream,
256 const struct type_print_options *flags)
258 struct field *args = TYPE_FIELDS (mtype);
259 int nargs = TYPE_NFIELDS (mtype);
260 int varargs = TYPE_VARARGS (mtype);
263 fprintf_symbol_filtered (stream, prefix,
264 language_cplus, DMGL_ANSI);
265 fprintf_symbol_filtered (stream, varstring,
266 language_cplus, DMGL_ANSI);
267 fputs_filtered ("(", stream);
269 /* Skip the class variable. We keep this here to accommodate older
270 compilers and debug formats which may not support artificial
277 struct field arg = args[i++];
279 /* Skip any artificial arguments. */
280 if (FIELD_ARTIFICIAL (arg))
283 c_print_type (arg.type, "", stream, 0, 0, flags);
285 if (i == nargs && varargs)
286 fprintf_filtered (stream, ", ...");
289 fprintf_filtered (stream, ", ");
295 fprintf_filtered (stream, "...");
296 else if (current_language->la_language == language_cplus)
297 fprintf_filtered (stream, "void");
299 fprintf_filtered (stream, ")");
301 /* For non-static methods, read qualifiers from the type of
307 gdb_assert (nargs > 0);
308 gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
309 domain = TYPE_TARGET_TYPE (args[0].type);
311 if (TYPE_CONST (domain))
312 fprintf_filtered (stream, " const");
314 if (TYPE_VOLATILE (domain))
315 fprintf_filtered (stream, " volatile");
317 if (TYPE_RESTRICT (domain))
318 fprintf_filtered (stream, " restrict");
320 if (TYPE_ATOMIC (domain))
321 fprintf_filtered (stream, " _Atomic");
326 /* Print any asterisks or open-parentheses needed before the
327 variable name (to describe its type).
329 On outermost call, pass 0 for PASSED_A_PTR.
330 On outermost call, SHOW > 0 means should ignore
331 any typename for TYPE and show its details.
332 SHOW is always zero on recursive calls.
334 NEED_POST_SPACE is non-zero when a space will be be needed
335 between a trailing qualifier and a field, variable, or function
339 c_type_print_varspec_prefix (struct type *type,
340 struct ui_file *stream,
341 int show, int passed_a_ptr,
343 const struct type_print_options *flags,
344 struct print_offset_data *podata)
351 if (TYPE_NAME (type) && show <= 0)
356 switch (TYPE_CODE (type))
359 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
360 stream, show, 1, 1, flags, podata);
361 fprintf_filtered (stream, "*");
362 c_type_print_modifier (type, stream, 1, need_post_space);
365 case TYPE_CODE_MEMBERPTR:
366 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
367 stream, show, 0, 0, flags, podata);
368 name = type_name_no_tag (TYPE_SELF_TYPE (type));
370 print_name_maybe_canonical (name, flags, stream);
372 c_type_print_base_1 (TYPE_SELF_TYPE (type),
373 stream, -1, passed_a_ptr, flags, podata);
374 fprintf_filtered (stream, "::*");
377 case TYPE_CODE_METHODPTR:
378 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
379 stream, show, 0, 0, flags, podata);
380 fprintf_filtered (stream, "(");
381 name = type_name_no_tag (TYPE_SELF_TYPE (type));
383 print_name_maybe_canonical (name, flags, stream);
385 c_type_print_base_1 (TYPE_SELF_TYPE (type),
386 stream, -1, passed_a_ptr, flags, podata);
387 fprintf_filtered (stream, "::*");
391 case TYPE_CODE_RVALUE_REF:
392 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
393 stream, show, 1, 0, flags, podata);
394 fprintf_filtered (stream, TYPE_CODE(type) == TYPE_CODE_REF ? "&" : "&&");
395 c_type_print_modifier (type, stream, 1, need_post_space);
398 case TYPE_CODE_METHOD:
400 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
401 stream, show, 0, 0, flags, podata);
403 fprintf_filtered (stream, "(");
406 case TYPE_CODE_ARRAY:
407 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
408 stream, show, 0, 0, flags, podata);
410 fprintf_filtered (stream, "(");
413 case TYPE_CODE_TYPEDEF:
414 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
415 stream, show, passed_a_ptr, 0, flags,
419 case TYPE_CODE_UNDEF:
420 case TYPE_CODE_STRUCT:
421 case TYPE_CODE_UNION:
423 case TYPE_CODE_FLAGS:
427 case TYPE_CODE_ERROR:
431 case TYPE_CODE_RANGE:
432 case TYPE_CODE_STRING:
433 case TYPE_CODE_COMPLEX:
434 case TYPE_CODE_NAMESPACE:
435 case TYPE_CODE_DECFLOAT:
436 /* These types need no prefix. They are listed here so that
437 gcc -Wall will reveal any types that haven't been handled. */
440 error (_("type not handled in c_type_print_varspec_prefix()"));
445 /* Print out "const" and "volatile" attributes,
446 and address space id if present.
447 TYPE is a pointer to the type being printed out.
448 STREAM is the output destination.
449 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
450 NEED_POST_SPACE = 1 indicates a final white space is needed. */
453 c_type_print_modifier (struct type *type, struct ui_file *stream,
454 int need_pre_space, int need_post_space)
456 int did_print_modifier = 0;
457 const char *address_space_id;
459 /* We don't print `const' qualifiers for references --- since all
460 operators affect the thing referenced, not the reference itself,
461 every reference is `const'. */
462 if (TYPE_CONST (type) && !TYPE_IS_REFERENCE (type))
465 fprintf_filtered (stream, " ");
466 fprintf_filtered (stream, "const");
467 did_print_modifier = 1;
470 if (TYPE_VOLATILE (type))
472 if (did_print_modifier || need_pre_space)
473 fprintf_filtered (stream, " ");
474 fprintf_filtered (stream, "volatile");
475 did_print_modifier = 1;
478 if (TYPE_RESTRICT (type))
480 if (did_print_modifier || need_pre_space)
481 fprintf_filtered (stream, " ");
482 fprintf_filtered (stream, "restrict");
483 did_print_modifier = 1;
486 if (TYPE_ATOMIC (type))
488 if (did_print_modifier || need_pre_space)
489 fprintf_filtered (stream, " ");
490 fprintf_filtered (stream, "_Atomic");
491 did_print_modifier = 1;
494 address_space_id = address_space_int_to_name (get_type_arch (type),
495 TYPE_INSTANCE_FLAGS (type));
496 if (address_space_id)
498 if (did_print_modifier || need_pre_space)
499 fprintf_filtered (stream, " ");
500 fprintf_filtered (stream, "@%s", address_space_id);
501 did_print_modifier = 1;
504 if (did_print_modifier && need_post_space)
505 fprintf_filtered (stream, " ");
509 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
510 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
511 in non-static methods, are displayed if LINKAGE_NAME is zero. If
512 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
513 parameter types get removed their possible const and volatile qualifiers to
514 match demangled linkage name parameters part of such function type.
515 LANGUAGE is the language in which TYPE was defined. This is a necessary
516 evil since this code is used by the C and C++. */
519 c_type_print_args (struct type *type, struct ui_file *stream,
520 int linkage_name, enum language language,
521 const struct type_print_options *flags)
526 fprintf_filtered (stream, "(");
528 for (i = 0; i < TYPE_NFIELDS (type); i++)
530 struct type *param_type;
532 if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
537 fprintf_filtered (stream, ", ");
541 param_type = TYPE_FIELD_TYPE (type, i);
543 if (language == language_cplus && linkage_name)
545 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
546 - Parameter declarations that differ only in the presence or
547 absence of const and/or volatile are equivalent.
549 And the const/volatile qualifiers are not present in the mangled
550 names as produced by GCC. */
552 param_type = make_cv_type (0, 0, param_type, NULL);
555 c_print_type (param_type, "", stream, -1, 0, flags);
559 if (printed_any && TYPE_VARARGS (type))
561 /* Print out a trailing ellipsis for varargs functions. Ignore
562 TYPE_VARARGS if the function has no named arguments; that
563 represents unprototyped (K&R style) C functions. */
564 if (printed_any && TYPE_VARARGS (type))
566 fprintf_filtered (stream, ", ");
568 fprintf_filtered (stream, "...");
571 else if (!printed_any
572 && (TYPE_PROTOTYPED (type) || language == language_cplus))
573 fprintf_filtered (stream, "void");
575 fprintf_filtered (stream, ")");
578 /* Return true iff the j'th overloading of the i'th method of TYPE
579 is a type conversion operator, like `operator int () { ... }'.
580 When listing a class's methods, we don't print the return type of
584 is_type_conversion_operator (struct type *type, int i, int j)
586 /* I think the whole idea of recognizing type conversion operators
587 by their name is pretty terrible. But I don't think our present
588 data structure gives us any other way to tell. If you know of
589 some other way, feel free to rewrite this function. */
590 const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
592 if (!startswith (name, CP_OPERATOR_STR))
596 if (! strchr (" \t\f\n\r", *name))
599 while (strchr (" \t\f\n\r", *name))
602 if (!('a' <= *name && *name <= 'z')
603 && !('A' <= *name && *name <= 'Z')
605 /* If this doesn't look like the start of an identifier, then it
606 isn't a type conversion operator. */
608 else if (startswith (name, "new"))
610 else if (startswith (name, "delete"))
613 /* If it doesn't look like new or delete, it's a type conversion
617 /* Is that really the end of the name? */
618 if (('a' <= *name && *name <= 'z')
619 || ('A' <= *name && *name <= 'Z')
620 || ('0' <= *name && *name <= '9')
622 /* No, so the identifier following "operator" must be a type name,
623 and this is a type conversion operator. */
626 /* That was indeed the end of the name, so it was `operator new' or
627 `operator delete', neither of which are type conversion
632 /* Given a C++ qualified identifier QID, strip off the qualifiers,
633 yielding the unqualified name. The return value is a pointer into
636 It's a pity we don't have this information in some more structured
637 form. Even the author of this function feels that writing little
638 parsers like this everywhere is stupid. */
641 remove_qualifiers (char *qid)
643 int quoted = 0; /* Zero if we're not in quotes;
644 '"' if we're in a double-quoted string;
645 '\'' if we're in a single-quoted string. */
646 int depth = 0; /* Number of unclosed parens we've seen. */
647 char *parenstack = (char *) alloca (strlen (qid));
649 char *last = 0; /* The character after the rightmost
650 `::' token we've seen so far. */
652 for (scan = qid; *scan; scan++)
658 else if (*scan == '\\' && *(scan + 1))
661 else if (scan[0] == ':' && scan[1] == ':')
663 /* If we're inside parenthesis (i.e., an argument list) or
664 angle brackets (i.e., a list of template arguments), then
665 we don't record the position of this :: token, since it's
666 not relevant to the top-level structure we're trying to
674 else if (*scan == '"' || *scan == '\'')
676 else if (*scan == '(')
677 parenstack[depth++] = ')';
678 else if (*scan == '[')
679 parenstack[depth++] = ']';
680 /* We're going to treat <> as a pair of matching characters,
681 since we're more likely to see those in template id's than
682 real less-than characters. What a crock. */
683 else if (*scan == '<')
684 parenstack[depth++] = '>';
685 else if (*scan == ')' || *scan == ']' || *scan == '>')
687 if (depth > 0 && parenstack[depth - 1] == *scan)
691 /* We're going to do a little error recovery here. If
692 we don't find a match for *scan on the paren stack,
693 but there is something lower on the stack that does
694 match, we pop the stack to that point. */
697 for (i = depth - 1; i >= 0; i--)
698 if (parenstack[i] == *scan)
710 /* We didn't find any :: tokens at the top level, so declare the
711 whole thing an unqualified identifier. */
715 /* Print any array sizes, function arguments or close parentheses
716 needed after the variable name (to describe its type).
717 Args work like c_type_print_varspec_prefix. */
720 c_type_print_varspec_suffix (struct type *type,
721 struct ui_file *stream,
722 int show, int passed_a_ptr,
724 const struct type_print_options *flags)
729 if (TYPE_NAME (type) && show <= 0)
734 switch (TYPE_CODE (type))
736 case TYPE_CODE_ARRAY:
738 LONGEST low_bound, high_bound;
739 int is_vector = TYPE_VECTOR (type);
742 fprintf_filtered (stream, ")");
744 fprintf_filtered (stream, (is_vector ?
745 " __attribute__ ((vector_size(" : "["));
746 /* Bounds are not yet resolved, print a bounds placeholder instead. */
747 if (TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCEXPR
748 || TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCLIST)
749 fprintf_filtered (stream, "variable length");
750 else if (get_array_bounds (type, &low_bound, &high_bound))
751 fprintf_filtered (stream, "%s",
752 plongest (high_bound - low_bound + 1));
753 fprintf_filtered (stream, (is_vector ? ")))" : "]"));
755 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
760 case TYPE_CODE_MEMBERPTR:
761 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
765 case TYPE_CODE_METHODPTR:
766 fprintf_filtered (stream, ")");
767 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
773 case TYPE_CODE_RVALUE_REF:
774 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
778 case TYPE_CODE_METHOD:
781 fprintf_filtered (stream, ")");
783 c_type_print_args (type, stream, 0, current_language->la_language,
785 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
786 show, passed_a_ptr, 0, flags);
789 case TYPE_CODE_TYPEDEF:
790 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
791 show, passed_a_ptr, 0, flags);
794 case TYPE_CODE_UNDEF:
795 case TYPE_CODE_STRUCT:
796 case TYPE_CODE_UNION:
797 case TYPE_CODE_FLAGS:
802 case TYPE_CODE_ERROR:
806 case TYPE_CODE_RANGE:
807 case TYPE_CODE_STRING:
808 case TYPE_CODE_COMPLEX:
809 case TYPE_CODE_NAMESPACE:
810 case TYPE_CODE_DECFLOAT:
811 /* These types do not need a suffix. They are listed so that
812 gcc -Wall will report types that may not have been
816 error (_("type not handled in c_type_print_varspec_suffix()"));
821 /* A helper for c_type_print_base that displays template
822 parameters and their bindings, if needed.
824 TABLE is the local bindings table to use. If NULL, no printing is
825 done. Note that, at this point, TABLE won't have any useful
826 information in it -- but it is also used as a flag to
827 print_name_maybe_canonical to activate searching the global typedef
830 TYPE is the type whose template arguments are being displayed.
832 STREAM is the stream on which to print. */
835 c_type_print_template_args (const struct type_print_options *flags,
836 struct type *type, struct ui_file *stream)
843 for (i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
845 struct symbol *sym = TYPE_TEMPLATE_ARGUMENT (type, i);
847 if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
853 fprintf_filtered (stream, _("[with %s = "),
854 SYMBOL_LINKAGE_NAME (sym));
859 fputs_filtered (", ", stream);
861 fprintf_filtered (stream, "%s = ", SYMBOL_LINKAGE_NAME (sym));
864 c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
868 fputs_filtered (_("] "), stream);
871 /* Use 'print_spaces_filtered', but take into consideration the
872 type_print_options FLAGS in order to determine how many whitespaces
876 print_spaces_filtered_with_print_options
877 (int level, struct ui_file *stream, const struct type_print_options *flags)
879 if (!flags->print_offsets)
880 print_spaces_filtered (level, stream);
882 print_spaces_filtered (level + OFFSET_SPC_LEN, stream);
885 /* Output an access specifier to STREAM, if needed. LAST_ACCESS is the
886 last access specifier output (typically returned by this function). */
888 static enum access_specifier
889 output_access_specifier (struct ui_file *stream,
890 enum access_specifier last_access,
891 int level, bool is_protected, bool is_private,
892 const struct type_print_options *flags)
896 if (last_access != s_protected)
898 last_access = s_protected;
899 print_spaces_filtered_with_print_options (level + 2, stream, flags);
900 fprintf_filtered (stream, "protected:\n");
905 if (last_access != s_private)
907 last_access = s_private;
908 print_spaces_filtered_with_print_options (level + 2, stream, flags);
909 fprintf_filtered (stream, "private:\n");
914 if (last_access != s_public)
916 last_access = s_public;
917 print_spaces_filtered_with_print_options (level + 2, stream, flags);
918 fprintf_filtered (stream, "public:\n");
925 /* Print information about field at index FIELD_IDX of the union type
926 TYPE. Since union fields don't have the concept of offsets, we
927 just print their sizes.
929 The output is strongly based on pahole(1). */
932 c_print_type_union_field_offset (struct type *type, unsigned int field_idx,
933 struct ui_file *stream)
935 struct type *ftype = check_typedef (TYPE_FIELD_TYPE (type, field_idx));
937 fprintf_filtered (stream, "/* %4u */", TYPE_LENGTH (ftype));
940 /* Helper function for ptype/o implementation that prints information
941 about a hole, if necessary. STREAM is where to print. BITPOS is
942 the bitpos of the current field. PODATA is the offset-printing
943 state. FOR_WHAT is a string describing the purpose of the
947 maybe_print_hole (struct ui_file *stream, unsigned int bitpos,
948 struct print_offset_data *podata, const char *for_what)
950 /* We check for PODATA->END_BITPOS > 0 because there is a specific
951 scenario when PODATA->END_BITPOS can be zero and BITPOS can be >
952 0: when we are dealing with a struct/class with a virtual method.
953 Because of the vtable, the first field of the struct/class will
954 have an offset of sizeof (void *) (the size of the vtable). If
955 we do not check for PODATA->END_BITPOS > 0 here, GDB will report
956 a hole before the first field, which is not accurate. */
957 if (podata->end_bitpos > 0 && podata->end_bitpos < bitpos)
959 /* If PODATA->END_BITPOS is smaller than the current type's
960 bitpos, it means there's a hole in the struct, so we report
962 unsigned int hole = bitpos - podata->end_bitpos;
963 unsigned int hole_byte = hole / TARGET_CHAR_BIT;
964 unsigned int hole_bit = hole % TARGET_CHAR_BIT;
967 fprintf_filtered (stream, "/* XXX %2u-bit %s */\n", hole_bit,
971 fprintf_filtered (stream, "/* XXX %2u-byte %s */\n", hole_byte,
976 /* Print information about field at index FIELD_IDX of the struct type
979 PODATA->END_BITPOS is the one-past-the-end bit position of the
980 previous field (where we expect this field to be if there is no
981 hole). At the end, ENDPOS is updated to the one-past-the-end bit
982 position of the current field.
984 PODATA->OFFSET_BITPOS is the offset value we carry over when we are
985 printing a struct that is inside another struct; this is useful so
986 that the offset is constantly incremented (if we didn't carry it
987 over, the offset would be reset to zero when printing the inner
990 The output is strongly based on pahole(1). */
993 c_print_type_struct_field_offset (struct type *type, unsigned int field_idx,
994 struct ui_file *stream,
995 struct print_offset_data *podata)
997 struct type *ftype = check_typedef (TYPE_FIELD_TYPE (type, field_idx));
998 unsigned int bitpos = TYPE_FIELD_BITPOS (type, field_idx);
999 unsigned int fieldsize_byte = TYPE_LENGTH (ftype);
1000 unsigned int fieldsize_bit = fieldsize_byte * TARGET_CHAR_BIT;
1002 maybe_print_hole (stream, bitpos, podata, "hole");
1004 if (TYPE_FIELD_PACKED (type, field_idx))
1006 /* We're dealing with a bitfield. Print how many bits are left
1008 unsigned int bitsize = TYPE_FIELD_BITSIZE (type, field_idx);
1009 /* The bitpos relative to the beginning of our container
1011 unsigned int relative_bitpos;
1013 /* The following was copied from
1014 value.c:value_primitive_field. */
1015 if ((bitpos % fieldsize_bit) + bitsize <= fieldsize_bit)
1016 relative_bitpos = bitpos % fieldsize_bit;
1018 relative_bitpos = bitpos % TARGET_CHAR_BIT;
1020 /* This is the exact offset (in bits) of this bitfield. */
1021 unsigned int bit_offset
1022 = (bitpos - relative_bitpos) + podata->offset_bitpos;
1024 /* The position of the field, relative to the beginning of the
1025 struct, and how many bits are left to be used in this
1027 fprintf_filtered (stream, "/* %4u:%2u", bit_offset / TARGET_CHAR_BIT,
1028 fieldsize_bit - (relative_bitpos + bitsize));
1029 fieldsize_bit = bitsize;
1033 /* The position of the field, relative to the beginning of the
1035 fprintf_filtered (stream, "/* %4u",
1036 (bitpos + podata->offset_bitpos) / TARGET_CHAR_BIT);
1038 fprintf_filtered (stream, " ");
1041 fprintf_filtered (stream, " | %4u */", fieldsize_byte);
1043 podata->end_bitpos = bitpos + fieldsize_bit;
1046 /* Return true if an access label (i.e., "public:", "private:",
1047 "protected:") needs to be printed for TYPE. */
1050 need_access_label_p (struct type *type)
1052 if (TYPE_DECLARED_CLASS (type))
1055 for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
1056 if (!TYPE_FIELD_PRIVATE (type, i))
1059 for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
1060 for (int i = 0; i < TYPE_FN_FIELDLIST_LENGTH (type, j); i++)
1061 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1065 for (int i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
1066 if (!TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
1072 for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
1073 if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
1076 for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
1079 for (int i = 0; i < TYPE_FN_FIELDLIST_LENGTH (type, j); i++)
1080 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
1082 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1088 for (int i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
1089 if (TYPE_TYPEDEF_FIELD_PROTECTED (type, i)
1090 || TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
1097 /* Helper function that temporarily disables FLAGS->PRINT_OFFSETS,
1098 calls 'c_print_type_1', and then reenables FLAGS->PRINT_OFFSETS if
1102 c_print_type_no_offsets (struct type *type,
1103 const char *varstring,
1104 struct ui_file *stream,
1105 int show, int level,
1106 struct type_print_options *flags,
1107 struct print_offset_data *podata)
1109 unsigned int old_po = flags->print_offsets;
1111 /* Temporarily disable print_offsets, because it would mess with
1113 flags->print_offsets = 0;
1114 c_print_type_1 (type, varstring, stream, show, level, flags, podata);
1115 flags->print_offsets = old_po;
1118 /* Helper for 'c_type_print_base' that handles structs and unions.
1119 For a description of the arguments, see 'c_type_print_base'. */
1122 c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
1123 int show, int level,
1124 const struct type_print_options *flags,
1125 struct print_offset_data *podata)
1127 struct type_print_options local_flags = *flags;
1128 local_flags.local_typedefs = NULL;
1130 std::unique_ptr<typedef_hash_table> hash_holder;
1133 if (flags->local_typedefs)
1134 local_flags.local_typedefs
1135 = new typedef_hash_table (*flags->local_typedefs);
1137 local_flags.local_typedefs = new typedef_hash_table ();
1139 hash_holder.reset (local_flags.local_typedefs);
1142 c_type_print_modifier (type, stream, 0, 1);
1143 if (TYPE_CODE (type) == TYPE_CODE_UNION)
1144 fprintf_filtered (stream, "union ");
1145 else if (TYPE_DECLARED_CLASS (type))
1146 fprintf_filtered (stream, "class ");
1148 fprintf_filtered (stream, "struct ");
1150 /* Print the tag if it exists. The HP aCC compiler emits a
1151 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
1152 enum}" tag for unnamed struct/union/enum's, which we don't
1154 if (TYPE_TAG_NAME (type) != NULL
1155 && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
1157 /* When printing the tag name, we are still effectively
1158 printing in the outer context, hence the use of FLAGS
1160 print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
1162 fputs_filtered (" ", stream);
1167 /* If we just printed a tag name, no need to print anything
1169 if (TYPE_TAG_NAME (type) == NULL)
1170 fprintf_filtered (stream, "{...}");
1172 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1174 struct type *basetype;
1177 c_type_print_template_args (&local_flags, type, stream);
1179 /* Add in template parameters when printing derivation info. */
1180 if (local_flags.local_typedefs != NULL)
1181 local_flags.local_typedefs->add_template_parameters (type);
1182 cp_type_print_derivation_info (stream, type, &local_flags);
1184 /* This holds just the global typedefs and the template
1186 struct type_print_options semi_local_flags = *flags;
1187 semi_local_flags.local_typedefs = NULL;
1189 std::unique_ptr<typedef_hash_table> semi_holder;
1190 if (local_flags.local_typedefs != nullptr)
1192 semi_local_flags.local_typedefs
1193 = new typedef_hash_table (*local_flags.local_typedefs);
1194 semi_holder.reset (semi_local_flags.local_typedefs);
1196 /* Now add in the local typedefs. */
1197 local_flags.local_typedefs->recursively_update (type);
1200 fprintf_filtered (stream, "{\n");
1202 if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
1203 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
1205 if (TYPE_STUB (type))
1206 fprintfi_filtered (level + 4, stream,
1207 _("<incomplete type>\n"));
1209 fprintfi_filtered (level + 4, stream,
1210 _("<no data fields>\n"));
1213 /* Start off with no specific section type, so we can print
1214 one for the first field we find, and use that section type
1215 thereafter until we find another type. */
1217 enum access_specifier section_type = s_none;
1219 /* For a class, if all members are private, there's no need
1220 for a "private:" label; similarly, for a struct or union
1221 masquerading as a class, if all members are public, there's
1222 no need for a "public:" label. */
1223 bool need_access_label = need_access_label_p (type);
1225 /* If there is a base class for this type,
1226 do not print the field that it occupies. */
1228 int len = TYPE_NFIELDS (type);
1229 vptr_fieldno = get_vptr_fieldno (type, &basetype);
1231 struct print_offset_data local_podata;
1233 for (int i = TYPE_N_BASECLASSES (type); i < len; i++)
1237 /* If we have a virtual table pointer, omit it. Even if
1238 virtual table pointers are not specifically marked in
1239 the debug info, they should be artificial. */
1240 if ((i == vptr_fieldno && type == basetype)
1241 || TYPE_FIELD_ARTIFICIAL (type, i))
1244 if (need_access_label)
1246 section_type = output_access_specifier
1247 (stream, section_type, level,
1248 TYPE_FIELD_PROTECTED (type, i),
1249 TYPE_FIELD_PRIVATE (type, i), flags);
1252 bool is_static = field_is_static (&TYPE_FIELD (type, i));
1254 if (flags->print_offsets)
1258 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1260 c_print_type_struct_field_offset
1261 (type, i, stream, podata);
1263 else if (TYPE_CODE (type) == TYPE_CODE_UNION)
1264 c_print_type_union_field_offset (type, i, stream);
1267 print_spaces_filtered (OFFSET_SPC_LEN, stream);
1270 print_spaces_filtered (level + 4, stream);
1272 fprintf_filtered (stream, "static ");
1274 int newshow = show - 1;
1276 if (flags->print_offsets
1277 && (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_STRUCT
1278 || TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION))
1280 /* If we're printing offsets and this field's type is
1281 either a struct or an union, then we're interested in
1285 /* Make sure we carry our offset when we expand the
1287 local_podata.offset_bitpos
1288 = podata->offset_bitpos + TYPE_FIELD_BITPOS (type, i);
1289 /* We're entering a struct/union. Right now,
1290 PODATA->END_BITPOS points right *after* the
1291 struct/union. However, when printing the first field
1292 of this inner struct/union, the end_bitpos we're
1293 expecting is exactly at the beginning of the
1294 struct/union. Therefore, we subtract the length of
1295 the whole struct/union. */
1296 local_podata.end_bitpos
1297 = podata->end_bitpos
1298 - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)) * TARGET_CHAR_BIT;
1301 c_print_type_1 (TYPE_FIELD_TYPE (type, i),
1302 TYPE_FIELD_NAME (type, i),
1303 stream, newshow, level + 4,
1304 &local_flags, &local_podata);
1306 if (!is_static && TYPE_FIELD_PACKED (type, i))
1308 /* It is a bitfield. This code does not attempt
1309 to look at the bitpos and reconstruct filler,
1310 unnamed fields. This would lead to misleading
1311 results if the compiler does not put out fields
1312 for such things (I don't know what it does). */
1313 fprintf_filtered (stream, " : %d",
1314 TYPE_FIELD_BITSIZE (type, i));
1316 fprintf_filtered (stream, ";\n");
1319 /* If there are both fields and methods, put a blank line
1320 between them. Make sure to count only method that we
1321 will display; artificial methods will be hidden. */
1322 len = TYPE_NFN_FIELDS (type);
1323 if (!flags->print_methods)
1326 for (int i = 0; i < len; i++)
1328 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1329 int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1332 for (j = 0; j < len2; j++)
1333 if (!TYPE_FN_FIELD_ARTIFICIAL (f, j))
1336 if (real_len > 0 && section_type != s_none)
1337 fprintf_filtered (stream, "\n");
1339 /* C++: print out the methods. */
1340 for (int i = 0; i < len; i++)
1342 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1343 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1344 const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1345 const char *name = type_name_no_tag (type);
1346 int is_constructor = name && strcmp (method_name,
1349 for (j = 0; j < len2; j++)
1351 const char *mangled_name;
1352 gdb::unique_xmalloc_ptr<char> mangled_name_holder;
1353 char *demangled_name;
1354 const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1355 int is_full_physname_constructor =
1356 TYPE_FN_FIELD_CONSTRUCTOR (f, j)
1357 || is_constructor_name (physname)
1358 || is_destructor_name (physname)
1359 || method_name[0] == '~';
1361 /* Do not print out artificial methods. */
1362 if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
1366 section_type = output_access_specifier
1367 (stream, section_type, level,
1368 TYPE_FN_FIELD_PROTECTED (f, j),
1369 TYPE_FN_FIELD_PRIVATE (f, j), flags);
1371 print_spaces_filtered_with_print_options (level + 4, stream,
1373 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1374 fprintf_filtered (stream, "virtual ");
1375 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1376 fprintf_filtered (stream, "static ");
1377 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1379 /* Keep GDB from crashing here. */
1380 fprintf_filtered (stream,
1381 _("<undefined type> %s;\n"),
1382 TYPE_FN_FIELD_PHYSNAME (f, j));
1385 else if (!is_constructor /* Constructors don't
1388 && !is_full_physname_constructor /* " " */
1389 && !is_type_conversion_operator (type, i, j))
1391 c_print_type_no_offsets
1392 (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1393 "", stream, -1, 0, &local_flags, podata);
1395 fputs_filtered (" ", stream);
1397 if (TYPE_FN_FIELD_STUB (f, j))
1399 /* Build something we can demangle. */
1400 mangled_name_holder.reset (gdb_mangle_name (type, i, j));
1401 mangled_name = mangled_name_holder.get ();
1404 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
1407 gdb_demangle (mangled_name,
1408 DMGL_ANSI | DMGL_PARAMS);
1409 if (demangled_name == NULL)
1411 /* In some cases (for instance with the HP
1412 demangling), if a function has more than 10
1413 arguments, the demangling will fail.
1414 Let's try to reconstruct the function
1415 signature from the symbol information. */
1416 if (!TYPE_FN_FIELD_STUB (f, j))
1418 int staticp = TYPE_FN_FIELD_STATIC_P (f, j);
1419 struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);
1421 cp_type_print_method_args (mtype,
1425 stream, &local_flags);
1428 fprintf_filtered (stream,
1429 _("<badly mangled name '%s'>"),
1435 char *demangled_no_class
1436 = remove_qualifiers (demangled_name);
1438 /* Get rid of the `static' appended by the
1440 p = strstr (demangled_no_class, " static");
1443 int length = p - demangled_no_class;
1444 char *demangled_no_static;
1447 = (char *) xmalloc (length + 1);
1448 strncpy (demangled_no_static,
1449 demangled_no_class, length);
1450 *(demangled_no_static + length) = '\0';
1451 fputs_filtered (demangled_no_static, stream);
1452 xfree (demangled_no_static);
1455 fputs_filtered (demangled_no_class, stream);
1456 xfree (demangled_name);
1459 fprintf_filtered (stream, ";\n");
1463 /* Print out nested types. */
1464 if (TYPE_NESTED_TYPES_COUNT (type) != 0
1465 && semi_local_flags.print_nested_type_limit != 0)
1467 if (semi_local_flags.print_nested_type_limit > 0)
1468 --semi_local_flags.print_nested_type_limit;
1470 if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
1471 fprintf_filtered (stream, "\n");
1473 for (int i = 0; i < TYPE_NESTED_TYPES_COUNT (type); ++i)
1475 print_spaces_filtered_with_print_options (level + 4, stream,
1477 c_print_type_no_offsets (TYPE_NESTED_TYPES_FIELD_TYPE (type, i),
1478 "", stream, show, level + 4,
1479 &semi_local_flags, podata);
1480 fprintf_filtered (stream, ";\n");
1484 /* Print typedefs defined in this class. */
1486 if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
1488 if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0
1489 || TYPE_NESTED_TYPES_COUNT (type) != 0)
1490 fprintf_filtered (stream, "\n");
1492 for (int i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++)
1494 struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i);
1496 /* Dereference the typedef declaration itself. */
1497 gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF);
1498 target = TYPE_TARGET_TYPE (target);
1500 if (need_access_label)
1502 section_type = output_access_specifier
1503 (stream, section_type, level,
1504 TYPE_TYPEDEF_FIELD_PROTECTED (type, i),
1505 TYPE_TYPEDEF_FIELD_PRIVATE (type, i), flags);
1507 print_spaces_filtered_with_print_options (level + 4, stream,
1509 fprintf_filtered (stream, "typedef ");
1511 /* We want to print typedefs with substitutions
1512 from the template parameters or globally-known
1513 typedefs but not local typedefs. */
1514 c_print_type_no_offsets (target,
1515 TYPE_TYPEDEF_FIELD_NAME (type, i),
1516 stream, show - 1, level + 4,
1517 &semi_local_flags, podata);
1518 fprintf_filtered (stream, ";\n");
1522 if (flags->print_offsets)
1526 unsigned int bitpos = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1527 maybe_print_hole (stream, bitpos, podata, "padding");
1529 fputs_filtered ("\n", stream);
1530 print_spaces_filtered_with_print_options (level + 4,
1533 fprintf_filtered (stream, "/* total size (bytes): %4u */\n",
1534 TYPE_LENGTH (type));
1537 print_spaces_filtered (OFFSET_SPC_LEN, stream);
1539 print_spaces_filtered (2, stream);
1542 fprintfi_filtered (level, stream, "}");
1546 /* Print the name of the type (or the ultimate pointer target,
1547 function value or array element), or the description of a structure
1550 SHOW positive means print details about the type (e.g. enum
1551 values), and print structure elements passing SHOW - 1 for show.
1553 SHOW negative means just print the type name or struct tag if there
1554 is one. If there is no name, print something sensible but concise
1555 like "struct {...}".
1557 SHOW zero means just print the type name or struct tag if there is
1558 one. If there is no name, print something sensible but not as
1559 concise like "struct {int x; int y;}".
1561 LEVEL is the number of spaces to indent by.
1562 We increase it for some recursive calls. */
1565 c_type_print_base_1 (struct type *type, struct ui_file *stream,
1566 int show, int level,
1567 const struct type_print_options *flags,
1568 struct print_offset_data *podata)
1577 fputs_filtered (_("<type unknown>"), stream);
1581 /* When SHOW is zero or less, and there is a valid type name, then
1582 always just print the type name directly from the type. */
1583 /* If we have "typedef struct foo {. . .} bar;" do we want to print
1584 it as "struct foo" or as "bar"? Pick the latter, because C++
1585 folk tend to expect things like "class5 *foo" rather than "struct
1589 && TYPE_NAME (type) != NULL)
1591 c_type_print_modifier (type, stream, 0, 1);
1592 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1596 type = check_typedef (type);
1598 switch (TYPE_CODE (type))
1600 case TYPE_CODE_TYPEDEF:
1601 /* If we get here, the typedef doesn't have a name, and we
1602 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
1603 gdb_assert (TYPE_NAME (type) == NULL);
1604 gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
1605 fprintf_filtered (stream, _("<unnamed typedef>"));
1608 case TYPE_CODE_FUNC:
1609 case TYPE_CODE_METHOD:
1610 if (TYPE_TARGET_TYPE (type) == NULL)
1611 type_print_unknown_return_type (stream);
1613 c_type_print_base_1 (TYPE_TARGET_TYPE (type),
1614 stream, show, level, flags, podata);
1616 case TYPE_CODE_ARRAY:
1618 case TYPE_CODE_MEMBERPTR:
1620 case TYPE_CODE_RVALUE_REF:
1621 case TYPE_CODE_METHODPTR:
1622 c_type_print_base_1 (TYPE_TARGET_TYPE (type),
1623 stream, show, level, flags, podata);
1626 case TYPE_CODE_STRUCT:
1627 case TYPE_CODE_UNION:
1628 c_type_print_base_struct_union (type, stream, show, level, flags,
1632 case TYPE_CODE_ENUM:
1633 c_type_print_modifier (type, stream, 0, 1);
1634 fprintf_filtered (stream, "enum ");
1635 if (TYPE_DECLARED_CLASS (type))
1636 fprintf_filtered (stream, "class ");
1637 /* Print the tag name if it exists.
1638 The aCC compiler emits a spurious
1639 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1640 tag for unnamed struct/union/enum's, which we don't
1642 if (TYPE_TAG_NAME (type) != NULL
1643 && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
1645 print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
1647 fputs_filtered (" ", stream);
1653 /* If we just printed a tag name, no need to print anything
1655 if (TYPE_TAG_NAME (type) == NULL)
1656 fprintf_filtered (stream, "{...}");
1658 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1660 LONGEST lastval = 0;
1662 /* We can't handle this case perfectly, as DWARF does not
1663 tell us whether or not the underlying type was specified
1664 in the source (and other debug formats don't provide this
1665 at all). We choose to print the underlying type, if it
1666 has a name, when in C++ on the theory that it's better to
1667 print too much than too little; but conversely not to
1668 print something egregiously outside the current
1669 language's syntax. */
1670 if (current_language->la_language == language_cplus
1671 && TYPE_TARGET_TYPE (type) != NULL)
1673 struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));
1675 if (TYPE_NAME (underlying) != NULL)
1676 fprintf_filtered (stream, ": %s ", TYPE_NAME (underlying));
1679 fprintf_filtered (stream, "{");
1680 len = TYPE_NFIELDS (type);
1681 for (i = 0; i < len; i++)
1685 fprintf_filtered (stream, ", ");
1687 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1688 if (lastval != TYPE_FIELD_ENUMVAL (type, i))
1690 fprintf_filtered (stream, " = %s",
1691 plongest (TYPE_FIELD_ENUMVAL (type, i)));
1692 lastval = TYPE_FIELD_ENUMVAL (type, i);
1696 fprintf_filtered (stream, "}");
1700 case TYPE_CODE_FLAGS:
1702 struct type_print_options local_flags = *flags;
1704 local_flags.local_typedefs = NULL;
1706 c_type_print_modifier (type, stream, 0, 1);
1707 fprintf_filtered (stream, "flag ");
1708 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1711 fputs_filtered (" ", stream);
1712 fprintf_filtered (stream, "{\n");
1713 if (TYPE_NFIELDS (type) == 0)
1715 if (TYPE_STUB (type))
1716 fprintfi_filtered (level + 4, stream,
1717 _("<incomplete type>\n"));
1719 fprintfi_filtered (level + 4, stream,
1720 _("<no data fields>\n"));
1722 len = TYPE_NFIELDS (type);
1723 for (i = 0; i < len; i++)
1726 print_spaces_filtered (level + 4, stream);
1727 /* We pass "show" here and not "show - 1" to get enum types
1728 printed. There's no other way to see them. */
1729 c_print_type_1 (TYPE_FIELD_TYPE (type, i),
1730 TYPE_FIELD_NAME (type, i),
1731 stream, show, level + 4,
1732 &local_flags, podata);
1733 fprintf_filtered (stream, " @%s",
1734 plongest (TYPE_FIELD_BITPOS (type, i)));
1735 if (TYPE_FIELD_BITSIZE (type, i) > 1)
1737 fprintf_filtered (stream, "-%s",
1738 plongest (TYPE_FIELD_BITPOS (type, i)
1739 + TYPE_FIELD_BITSIZE (type, i)
1742 fprintf_filtered (stream, ";\n");
1744 fprintfi_filtered (level, stream, "}");
1749 case TYPE_CODE_VOID:
1750 fprintf_filtered (stream, "void");
1753 case TYPE_CODE_UNDEF:
1754 fprintf_filtered (stream, _("struct <unknown>"));
1757 case TYPE_CODE_ERROR:
1758 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
1761 case TYPE_CODE_RANGE:
1762 /* This should not occur. */
1763 fprintf_filtered (stream, _("<range type>"));
1766 case TYPE_CODE_NAMESPACE:
1767 fputs_filtered ("namespace ", stream);
1768 fputs_filtered (TYPE_TAG_NAME (type), stream);
1772 /* Handle types not explicitly handled by the other cases, such
1773 as fundamental types. For these, just print whatever the
1774 type name is, as recorded in the type itself. If there is no
1775 type name, then complain. */
1776 if (TYPE_NAME (type) != NULL)
1778 c_type_print_modifier (type, stream, 0, 1);
1779 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1783 /* At least for dump_symtab, it is important that this not
1785 fprintf_filtered (stream, _("<invalid type code %d>"),
1792 /* See c_type_print_base_1. */
1795 c_type_print_base (struct type *type, struct ui_file *stream,
1796 int show, int level,
1797 const struct type_print_options *flags)
1799 struct print_offset_data podata;
1801 c_type_print_base_1 (type, stream, show, level, flags, &podata);