1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
3 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_obstack.h"
23 #include "bfd.h" /* Binary File Description. */
26 #include "expression.h"
33 #include "typeprint.h"
36 #include "gdb_string.h"
39 static void c_type_print_varspec_prefix (struct type
*,
43 /* Print "const", "volatile", or address space modifiers. */
44 static void c_type_print_modifier (struct type
*,
48 /* LEVEL is the depth to indent lines by. */
51 c_print_type (struct type
*type
,
52 const char *varstring
,
53 struct ui_file
*stream
,
63 c_type_print_base (type
, stream
, show
, level
);
64 code
= TYPE_CODE (type
);
65 if ((varstring
!= NULL
&& *varstring
!= '\0')
66 /* Need a space if going to print stars or brackets;
67 but not if we will print just a type name. */
68 || ((show
> 0 || TYPE_NAME (type
) == 0)
69 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
70 || code
== TYPE_CODE_METHOD
71 || code
== TYPE_CODE_ARRAY
72 || code
== TYPE_CODE_MEMBERPTR
73 || code
== TYPE_CODE_METHODPTR
74 || code
== TYPE_CODE_REF
)))
75 fputs_filtered (" ", stream
);
76 need_post_space
= (varstring
!= NULL
&& strcmp (varstring
, "") != 0);
77 c_type_print_varspec_prefix (type
, stream
, show
, 0, need_post_space
);
79 if (varstring
!= NULL
)
81 fputs_filtered (varstring
, stream
);
83 /* For demangled function names, we have the arglist as part of
84 the name, so don't print an additional pair of ()'s. */
86 demangled_args
= strchr (varstring
, '(') != NULL
;
87 c_type_print_varspec_suffix (type
, stream
, show
,
92 /* Print a typedef using C syntax. TYPE is the underlying type.
93 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
97 c_print_typedef (struct type
*type
,
98 struct symbol
*new_symbol
,
99 struct ui_file
*stream
)
101 CHECK_TYPEDEF (type
);
102 fprintf_filtered (stream
, "typedef ");
103 type_print (type
, "", stream
, 0);
104 if (TYPE_NAME ((SYMBOL_TYPE (new_symbol
))) == 0
105 || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol
))),
106 SYMBOL_LINKAGE_NAME (new_symbol
)) != 0
107 || TYPE_CODE (SYMBOL_TYPE (new_symbol
)) == TYPE_CODE_TYPEDEF
)
108 fprintf_filtered (stream
, " %s", SYMBOL_PRINT_NAME (new_symbol
));
109 fprintf_filtered (stream
, ";\n");
112 /* If TYPE is a derived type, then print out derivation information.
113 Print only the actual base classes of this type, not the base
114 classes of the base classes. I.e. for the derivation hierarchy:
117 class B : public A {int b; };
118 class C : public B {int c; };
120 Print the type of class C as:
126 Not as the following (like gdb used to), which is not legal C++
127 syntax for derived types and may be confused with the multiple
130 class C : public B : public A {
134 In general, gdb should try to print the types as closely as
135 possible to the form that they appear in the source code.
137 Note that in case of protected derivation gcc will not say
138 'protected' but 'private'. The HP's aCC compiler emits specific
139 information for derivation via protected inheritance, so gdb can
143 cp_type_print_derivation_info (struct ui_file
*stream
,
149 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
151 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
152 fprintf_filtered (stream
, "%s%s ",
153 BASETYPE_VIA_PUBLIC (type
, i
)
154 ? "public" : (TYPE_FIELD_PROTECTED (type
, i
)
155 ? "protected" : "private"),
156 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
157 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
158 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
162 fputs_filtered (" ", stream
);
166 /* Print the C++ method arguments ARGS to the file STREAM. */
169 cp_type_print_method_args (struct type
*mtype
, char *prefix
,
170 char *varstring
, int staticp
,
171 struct ui_file
*stream
)
173 struct field
*args
= TYPE_FIELDS (mtype
);
174 int nargs
= TYPE_NFIELDS (mtype
);
175 int varargs
= TYPE_VARARGS (mtype
);
178 fprintf_symbol_filtered (stream
, prefix
,
179 language_cplus
, DMGL_ANSI
);
180 fprintf_symbol_filtered (stream
, varstring
,
181 language_cplus
, DMGL_ANSI
);
182 fputs_filtered ("(", stream
);
184 /* Skip the class variable. */
190 type_print (args
[i
++].type
, "", stream
, 0);
192 if (i
== nargs
&& varargs
)
193 fprintf_filtered (stream
, ", ...");
195 fprintf_filtered (stream
, ", ");
199 fprintf_filtered (stream
, "...");
200 else if (current_language
->la_language
== language_cplus
)
201 fprintf_filtered (stream
, "void");
203 fprintf_filtered (stream
, ")");
205 /* For non-static methods, read qualifiers from the type of
211 gdb_assert (nargs
> 0);
212 gdb_assert (TYPE_CODE (args
[0].type
) == TYPE_CODE_PTR
);
213 domain
= TYPE_TARGET_TYPE (args
[0].type
);
215 if (TYPE_CONST (domain
))
216 fprintf_filtered (stream
, " const");
218 if (TYPE_VOLATILE (domain
))
219 fprintf_filtered (stream
, " volatile");
224 /* Print any asterisks or open-parentheses needed before the
225 variable name (to describe its type).
227 On outermost call, pass 0 for PASSED_A_PTR.
228 On outermost call, SHOW > 0 means should ignore
229 any typename for TYPE and show its details.
230 SHOW is always zero on recursive calls.
232 NEED_POST_SPACE is non-zero when a space will be be needed
233 between a trailing qualifier and a field, variable, or function
237 c_type_print_varspec_prefix (struct type
*type
,
238 struct ui_file
*stream
,
239 int show
, int passed_a_ptr
,
247 if (TYPE_NAME (type
) && show
<= 0)
252 switch (TYPE_CODE (type
))
255 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
257 fprintf_filtered (stream
, "*");
258 c_type_print_modifier (type
, stream
, 1, need_post_space
);
261 case TYPE_CODE_MEMBERPTR
:
262 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
264 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
266 fputs_filtered (name
, stream
);
268 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
269 stream
, 0, passed_a_ptr
);
270 fprintf_filtered (stream
, "::*");
273 case TYPE_CODE_METHODPTR
:
274 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
276 fprintf_filtered (stream
, "(");
277 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
279 fputs_filtered (name
, stream
);
281 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
282 stream
, 0, passed_a_ptr
);
283 fprintf_filtered (stream
, "::*");
287 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
289 fprintf_filtered (stream
, "&");
290 c_type_print_modifier (type
, stream
, 1, need_post_space
);
293 case TYPE_CODE_METHOD
:
295 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
298 fprintf_filtered (stream
, "(");
301 case TYPE_CODE_ARRAY
:
302 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
305 fprintf_filtered (stream
, "(");
308 case TYPE_CODE_TYPEDEF
:
309 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
313 case TYPE_CODE_UNDEF
:
314 case TYPE_CODE_STRUCT
:
315 case TYPE_CODE_UNION
:
320 case TYPE_CODE_ERROR
:
324 case TYPE_CODE_RANGE
:
325 case TYPE_CODE_STRING
:
326 case TYPE_CODE_BITSTRING
:
327 case TYPE_CODE_COMPLEX
:
328 case TYPE_CODE_NAMESPACE
:
329 case TYPE_CODE_DECFLOAT
:
330 /* These types need no prefix. They are listed here so that
331 gcc -Wall will reveal any types that haven't been handled. */
334 error (_("type not handled in c_type_print_varspec_prefix()"));
339 /* Print out "const" and "volatile" attributes,
340 and address space id if present.
341 TYPE is a pointer to the type being printed out.
342 STREAM is the output destination.
343 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
344 NEED_POST_SPACE = 1 indicates a final white space is needed. */
347 c_type_print_modifier (struct type
*type
, struct ui_file
*stream
,
348 int need_pre_space
, int need_post_space
)
350 int did_print_modifier
= 0;
351 const char *address_space_id
;
353 /* We don't print `const' qualifiers for references --- since all
354 operators affect the thing referenced, not the reference itself,
355 every reference is `const'. */
356 if (TYPE_CONST (type
)
357 && TYPE_CODE (type
) != TYPE_CODE_REF
)
360 fprintf_filtered (stream
, " ");
361 fprintf_filtered (stream
, "const");
362 did_print_modifier
= 1;
365 if (TYPE_VOLATILE (type
))
367 if (did_print_modifier
|| need_pre_space
)
368 fprintf_filtered (stream
, " ");
369 fprintf_filtered (stream
, "volatile");
370 did_print_modifier
= 1;
373 address_space_id
= address_space_int_to_name (get_type_arch (type
),
374 TYPE_INSTANCE_FLAGS (type
));
375 if (address_space_id
)
377 if (did_print_modifier
|| need_pre_space
)
378 fprintf_filtered (stream
, " ");
379 fprintf_filtered (stream
, "@%s", address_space_id
);
380 did_print_modifier
= 1;
383 if (did_print_modifier
&& need_post_space
)
384 fprintf_filtered (stream
, " ");
388 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
389 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
390 in non-static methods, are displayed if SHOW_ARTIFICIAL is
391 non-zero. If SHOW_ARTIFICIAL is zero and LANGUAGE is language_cplus
392 the topmost parameter types get removed their possible const and volatile
393 qualifiers to match demangled linkage name parameters part of such function
394 type. LANGUAGE is the language in which TYPE was defined. This is
395 a necessary evil since this code is used by the C, C++, and Java backends.
399 c_type_print_args (struct type
*type
, struct ui_file
*stream
,
400 int show_artificial
, enum language language
)
406 fprintf_filtered (stream
, "(");
407 args
= TYPE_FIELDS (type
);
408 len
= TYPE_NFIELDS (type
);
410 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
412 struct type
*param_type
;
414 if (TYPE_FIELD_ARTIFICIAL (type
, i
) && !show_artificial
)
419 fprintf_filtered (stream
, ", ");
423 param_type
= TYPE_FIELD_TYPE (type
, i
);
425 if (language
== language_cplus
&& !show_artificial
)
427 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
428 - Parameter declarations that differ only in the presence or
429 absence of const and/or volatile are equivalent.
431 And the const/volatile qualifiers are not present in the mangled
432 names as produced by GCC. */
434 param_type
= make_cv_type (0, 0, param_type
, NULL
);
437 if (language
== language_java
)
438 java_print_type (param_type
, "", stream
, -1, 0);
440 c_print_type (param_type
, "", stream
, -1, 0);
444 if (printed_any
&& TYPE_VARARGS (type
))
446 /* Print out a trailing ellipsis for varargs functions. Ignore
447 TYPE_VARARGS if the function has no named arguments; that
448 represents unprototyped (K&R style) C functions. */
449 if (printed_any
&& TYPE_VARARGS (type
))
451 fprintf_filtered (stream
, ", ");
453 fprintf_filtered (stream
, "...");
456 else if (!printed_any
457 && ((TYPE_PROTOTYPED (type
) && language
!= language_java
)
458 || language
== language_cplus
))
459 fprintf_filtered (stream
, "void");
461 fprintf_filtered (stream
, ")");
464 /* Return true iff the j'th overloading of the i'th method of TYPE
465 is a type conversion operator, like `operator int () { ... }'.
466 When listing a class's methods, we don't print the return type of
470 is_type_conversion_operator (struct type
*type
, int i
, int j
)
472 /* I think the whole idea of recognizing type conversion operators
473 by their name is pretty terrible. But I don't think our present
474 data structure gives us any other way to tell. If you know of
475 some other way, feel free to rewrite this function. */
476 char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
478 if (strncmp (name
, "operator", 8) != 0)
482 if (! strchr (" \t\f\n\r", *name
))
485 while (strchr (" \t\f\n\r", *name
))
488 if (!('a' <= *name
&& *name
<= 'z')
489 && !('A' <= *name
&& *name
<= 'Z')
491 /* If this doesn't look like the start of an identifier, then it
492 isn't a type conversion operator. */
494 else if (strncmp (name
, "new", 3) == 0)
496 else if (strncmp (name
, "delete", 6) == 0)
499 /* If it doesn't look like new or delete, it's a type conversion
503 /* Is that really the end of the name? */
504 if (('a' <= *name
&& *name
<= 'z')
505 || ('A' <= *name
&& *name
<= 'Z')
506 || ('0' <= *name
&& *name
<= '9')
508 /* No, so the identifier following "operator" must be a type name,
509 and this is a type conversion operator. */
512 /* That was indeed the end of the name, so it was `operator new' or
513 `operator delete', neither of which are type conversion
518 /* Given a C++ qualified identifier QID, strip off the qualifiers,
519 yielding the unqualified name. The return value is a pointer into
522 It's a pity we don't have this information in some more structured
523 form. Even the author of this function feels that writing little
524 parsers like this everywhere is stupid. */
527 remove_qualifiers (char *qid
)
529 int quoted
= 0; /* Zero if we're not in quotes;
530 '"' if we're in a double-quoted string;
531 '\'' if we're in a single-quoted string. */
532 int depth
= 0; /* Number of unclosed parens we've seen. */
533 char *parenstack
= (char *) alloca (strlen (qid
));
535 char *last
= 0; /* The character after the rightmost
536 `::' token we've seen so far. */
538 for (scan
= qid
; *scan
; scan
++)
544 else if (*scan
== '\\' && *(scan
+ 1))
547 else if (scan
[0] == ':' && scan
[1] == ':')
549 /* If we're inside parenthesis (i.e., an argument list) or
550 angle brackets (i.e., a list of template arguments), then
551 we don't record the position of this :: token, since it's
552 not relevant to the top-level structure we're trying to
560 else if (*scan
== '"' || *scan
== '\'')
562 else if (*scan
== '(')
563 parenstack
[depth
++] = ')';
564 else if (*scan
== '[')
565 parenstack
[depth
++] = ']';
566 /* We're going to treat <> as a pair of matching characters,
567 since we're more likely to see those in template id's than
568 real less-than characters. What a crock. */
569 else if (*scan
== '<')
570 parenstack
[depth
++] = '>';
571 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
573 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
577 /* We're going to do a little error recovery here. If
578 we don't find a match for *scan on the paren stack,
579 but there is something lower on the stack that does
580 match, we pop the stack to that point. */
583 for (i
= depth
- 1; i
>= 0; i
--)
584 if (parenstack
[i
] == *scan
)
596 /* We didn't find any :: tokens at the top level, so declare the
597 whole thing an unqualified identifier. */
601 /* Print any array sizes, function arguments or close parentheses
602 needed after the variable name (to describe its type).
603 Args work like c_type_print_varspec_prefix. */
606 c_type_print_varspec_suffix (struct type
*type
,
607 struct ui_file
*stream
,
608 int show
, int passed_a_ptr
,
614 if (TYPE_NAME (type
) && show
<= 0)
619 switch (TYPE_CODE (type
))
621 case TYPE_CODE_ARRAY
:
623 LONGEST low_bound
, high_bound
;
626 fprintf_filtered (stream
, ")");
628 fprintf_filtered (stream
, "[");
629 if (get_array_bounds (type
, &low_bound
, &high_bound
))
630 fprintf_filtered (stream
, "%d",
631 (int) (high_bound
- low_bound
+ 1));
632 fprintf_filtered (stream
, "]");
634 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
639 case TYPE_CODE_MEMBERPTR
:
640 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
644 case TYPE_CODE_METHODPTR
:
645 fprintf_filtered (stream
, ")");
646 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
652 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
656 case TYPE_CODE_METHOD
:
659 fprintf_filtered (stream
, ")");
661 c_type_print_args (type
, stream
, 1,
662 current_language
->la_language
);
663 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
664 show
, passed_a_ptr
, 0);
667 case TYPE_CODE_TYPEDEF
:
668 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
669 show
, passed_a_ptr
, 0);
672 case TYPE_CODE_UNDEF
:
673 case TYPE_CODE_STRUCT
:
674 case TYPE_CODE_UNION
:
679 case TYPE_CODE_ERROR
:
683 case TYPE_CODE_RANGE
:
684 case TYPE_CODE_STRING
:
685 case TYPE_CODE_BITSTRING
:
686 case TYPE_CODE_COMPLEX
:
687 case TYPE_CODE_NAMESPACE
:
688 case TYPE_CODE_DECFLOAT
:
689 /* These types do not need a suffix. They are listed so that
690 gcc -Wall will report types that may not have been
694 error (_("type not handled in c_type_print_varspec_suffix()"));
699 /* Print the name of the type (or the ultimate pointer target,
700 function value or array element), or the description of a structure
703 SHOW positive means print details about the type (e.g. enum
704 values), and print structure elements passing SHOW - 1 for show.
706 SHOW negative means just print the type name or struct tag if there
707 is one. If there is no name, print something sensible but concise
710 SHOW zero means just print the type name or struct tag if there is
711 one. If there is no name, print something sensible but not as
712 concise like "struct {int x; int y;}".
714 LEVEL is the number of spaces to indent by.
715 We increase it for some recursive calls. */
718 c_type_print_base (struct type
*type
, struct ui_file
*stream
,
725 char *demangled_name
;
726 char *demangled_no_static
;
729 s_none
, s_public
, s_private
, s_protected
732 int need_access_label
= 0;
740 fputs_filtered (_("<type unknown>"), stream
);
744 /* When SHOW is zero or less, and there is a valid type name, then
745 always just print the type name directly from the type. */
746 /* If we have "typedef struct foo {. . .} bar;" do we want to print
747 it as "struct foo" or as "bar"? Pick the latter, because C++
748 folk tend to expect things like "class5 *foo" rather than "struct
752 && TYPE_NAME (type
) != NULL
)
754 c_type_print_modifier (type
, stream
, 0, 1);
755 fputs_filtered (TYPE_NAME (type
), stream
);
759 CHECK_TYPEDEF (type
);
761 switch (TYPE_CODE (type
))
763 case TYPE_CODE_TYPEDEF
:
764 /* If we get here, the typedef doesn't have a name, and we
765 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
766 gdb_assert (TYPE_NAME (type
) == NULL
);
767 gdb_assert (TYPE_TARGET_TYPE (type
) == NULL
);
768 fprintf_filtered (stream
, _("<unnamed typedef>"));
771 case TYPE_CODE_ARRAY
:
773 case TYPE_CODE_MEMBERPTR
:
776 case TYPE_CODE_METHOD
:
777 case TYPE_CODE_METHODPTR
:
778 c_type_print_base (TYPE_TARGET_TYPE (type
),
779 stream
, show
, level
);
782 case TYPE_CODE_STRUCT
:
783 c_type_print_modifier (type
, stream
, 0, 1);
784 if (TYPE_DECLARED_CLASS (type
))
785 fprintf_filtered (stream
, "class ");
787 fprintf_filtered (stream
, "struct ");
790 case TYPE_CODE_UNION
:
791 c_type_print_modifier (type
, stream
, 0, 1);
792 fprintf_filtered (stream
, "union ");
796 /* Print the tag if it exists. The HP aCC compiler emits a
797 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
798 enum}" tag for unnamed struct/union/enum's, which we don't
800 if (TYPE_TAG_NAME (type
) != NULL
801 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
803 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
805 fputs_filtered (" ", stream
);
810 /* If we just printed a tag name, no need to print anything
812 if (TYPE_TAG_NAME (type
) == NULL
)
813 fprintf_filtered (stream
, "{...}");
815 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
817 struct type
*basetype
;
820 cp_type_print_derivation_info (stream
, type
);
822 fprintf_filtered (stream
, "{\n");
823 if (TYPE_NFIELDS (type
) == 0 && TYPE_NFN_FIELDS (type
) == 0
824 && TYPE_TYPEDEF_FIELD_COUNT (type
) == 0)
826 if (TYPE_STUB (type
))
827 fprintfi_filtered (level
+ 4, stream
,
828 _("<incomplete type>\n"));
830 fprintfi_filtered (level
+ 4, stream
,
831 _("<no data fields>\n"));
834 /* Start off with no specific section type, so we can print
835 one for the first field we find, and use that section type
836 thereafter until we find another type. */
838 section_type
= s_none
;
840 /* For a class, if all members are private, there's no need
841 for a "private:" label; similarly, for a struct or union
842 masquerading as a class, if all members are public, there's
843 no need for a "public:" label. */
845 if (TYPE_DECLARED_CLASS (type
))
848 len
= TYPE_NFIELDS (type
);
849 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
850 if (!TYPE_FIELD_PRIVATE (type
, i
))
852 need_access_label
= 1;
856 if (!need_access_label
)
858 len2
= TYPE_NFN_FIELDS (type
);
859 for (j
= 0; j
< len2
; j
++)
861 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
862 for (i
= 0; i
< len
; i
++)
863 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
866 need_access_label
= 1;
869 if (need_access_label
)
877 len
= TYPE_NFIELDS (type
);
878 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
879 if (TYPE_FIELD_PRIVATE (type
, i
)
880 || TYPE_FIELD_PROTECTED (type
, i
))
882 need_access_label
= 1;
886 if (!need_access_label
)
888 len2
= TYPE_NFN_FIELDS (type
);
889 for (j
= 0; j
< len2
; j
++)
892 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
893 for (i
= 0; i
< len
; i
++)
894 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
,
896 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
900 need_access_label
= 1;
903 if (need_access_label
)
909 /* If there is a base class for this type,
910 do not print the field that it occupies. */
912 len
= TYPE_NFIELDS (type
);
913 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
914 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
918 /* If we have a virtual table pointer, omit it. Even if
919 virtual table pointers are not specifically marked in
920 the debug info, they should be artificial. */
921 if ((i
== vptr_fieldno
&& type
== basetype
)
922 || TYPE_FIELD_ARTIFICIAL (type
, i
))
925 if (need_access_label
)
927 if (TYPE_FIELD_PROTECTED (type
, i
))
929 if (section_type
!= s_protected
)
931 section_type
= s_protected
;
932 fprintfi_filtered (level
+ 2, stream
,
936 else if (TYPE_FIELD_PRIVATE (type
, i
))
938 if (section_type
!= s_private
)
940 section_type
= s_private
;
941 fprintfi_filtered (level
+ 2, stream
,
947 if (section_type
!= s_public
)
949 section_type
= s_public
;
950 fprintfi_filtered (level
+ 2, stream
,
956 print_spaces_filtered (level
+ 4, stream
);
957 if (field_is_static (&TYPE_FIELD (type
, i
)))
958 fprintf_filtered (stream
, "static ");
959 c_print_type (TYPE_FIELD_TYPE (type
, i
),
960 TYPE_FIELD_NAME (type
, i
),
961 stream
, show
- 1, level
+ 4);
962 if (!field_is_static (&TYPE_FIELD (type
, i
))
963 && TYPE_FIELD_PACKED (type
, i
))
965 /* It is a bitfield. This code does not attempt
966 to look at the bitpos and reconstruct filler,
967 unnamed fields. This would lead to misleading
968 results if the compiler does not put out fields
969 for such things (I don't know what it does). */
970 fprintf_filtered (stream
, " : %d",
971 TYPE_FIELD_BITSIZE (type
, i
));
973 fprintf_filtered (stream
, ";\n");
976 /* If there are both fields and methods, put a blank line
977 between them. Make sure to count only method that we
978 will display; artificial methods will be hidden. */
979 len
= TYPE_NFN_FIELDS (type
);
981 for (i
= 0; i
< len
; i
++)
983 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
984 int len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
987 for (j
= 0; j
< len2
; j
++)
988 if (!TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
991 if (real_len
> 0 && section_type
!= s_none
)
992 fprintf_filtered (stream
, "\n");
994 /* C++: print out the methods. */
995 for (i
= 0; i
< len
; i
++)
997 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
998 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
999 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1000 char *name
= type_name_no_tag (type
);
1001 int is_constructor
= name
&& strcmp (method_name
,
1004 for (j
= 0; j
< len2
; j
++)
1006 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1007 int is_full_physname_constructor
=
1008 is_constructor_name (physname
)
1009 || is_destructor_name (physname
)
1010 || method_name
[0] == '~';
1012 /* Do not print out artificial methods. */
1013 if (TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1017 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
1019 if (section_type
!= s_protected
)
1021 section_type
= s_protected
;
1022 fprintfi_filtered (level
+ 2, stream
,
1026 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
1028 if (section_type
!= s_private
)
1030 section_type
= s_private
;
1031 fprintfi_filtered (level
+ 2, stream
,
1037 if (section_type
!= s_public
)
1039 section_type
= s_public
;
1040 fprintfi_filtered (level
+ 2, stream
,
1045 print_spaces_filtered (level
+ 4, stream
);
1046 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1047 fprintf_filtered (stream
, "virtual ");
1048 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1049 fprintf_filtered (stream
, "static ");
1050 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1052 /* Keep GDB from crashing here. */
1053 fprintf_filtered (stream
,
1054 _("<undefined type> %s;\n"),
1055 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1058 else if (!is_constructor
/* Constructors don't
1061 && !is_full_physname_constructor
/* " " */
1062 && !is_type_conversion_operator (type
, i
, j
))
1064 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1066 fputs_filtered (" ", stream
);
1068 if (TYPE_FN_FIELD_STUB (f
, j
))
1069 /* Build something we can demangle. */
1070 mangled_name
= gdb_mangle_name (type
, i
, j
);
1072 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1075 cplus_demangle (mangled_name
,
1076 DMGL_ANSI
| DMGL_PARAMS
);
1077 if (demangled_name
== NULL
)
1079 /* In some cases (for instance with the HP
1080 demangling), if a function has more than 10
1081 arguments, the demangling will fail.
1082 Let's try to reconstruct the function
1083 signature from the symbol information. */
1084 if (!TYPE_FN_FIELD_STUB (f
, j
))
1086 int staticp
= TYPE_FN_FIELD_STATIC_P (f
, j
);
1087 struct type
*mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
1089 cp_type_print_method_args (mtype
,
1096 fprintf_filtered (stream
,
1097 _("<badly mangled name '%s'>"),
1103 char *demangled_no_class
1104 = remove_qualifiers (demangled_name
);
1106 /* Get rid of the `static' appended by the
1108 p
= strstr (demangled_no_class
, " static");
1111 int length
= p
- demangled_no_class
;
1114 = (char *) xmalloc (length
+ 1);
1115 strncpy (demangled_no_static
,
1116 demangled_no_class
, length
);
1117 *(demangled_no_static
+ length
) = '\0';
1118 fputs_filtered (demangled_no_static
, stream
);
1119 xfree (demangled_no_static
);
1122 fputs_filtered (demangled_no_class
, stream
);
1123 xfree (demangled_name
);
1126 if (TYPE_FN_FIELD_STUB (f
, j
))
1127 xfree (mangled_name
);
1129 fprintf_filtered (stream
, ";\n");
1133 /* Print typedefs defined in this class. */
1135 if (TYPE_TYPEDEF_FIELD_COUNT (type
) != 0)
1137 if (TYPE_NFIELDS (type
) != 0 || TYPE_NFN_FIELDS (type
) != 0)
1138 fprintf_filtered (stream
, "\n");
1140 for (i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); i
++)
1142 struct type
*target
= TYPE_TYPEDEF_FIELD_TYPE (type
, i
);
1144 /* Dereference the typedef declaration itself. */
1145 gdb_assert (TYPE_CODE (target
) == TYPE_CODE_TYPEDEF
);
1146 target
= TYPE_TARGET_TYPE (target
);
1148 print_spaces_filtered (level
+ 4, stream
);
1149 fprintf_filtered (stream
, "typedef ");
1150 c_print_type (target
, TYPE_TYPEDEF_FIELD_NAME (type
, i
),
1151 stream
, show
- 1, level
+ 4);
1152 fprintf_filtered (stream
, ";\n");
1156 fprintfi_filtered (level
, stream
, "}");
1158 if (TYPE_LOCALTYPE_PTR (type
) && show
>= 0)
1159 fprintfi_filtered (level
,
1160 stream
, _(" (Local at %s:%d)\n"),
1161 TYPE_LOCALTYPE_FILE (type
),
1162 TYPE_LOCALTYPE_LINE (type
));
1166 case TYPE_CODE_ENUM
:
1167 c_type_print_modifier (type
, stream
, 0, 1);
1168 fprintf_filtered (stream
, "enum ");
1169 /* Print the tag name if it exists.
1170 The aCC compiler emits a spurious
1171 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1172 tag for unnamed struct/union/enum's, which we don't
1174 if (TYPE_TAG_NAME (type
) != NULL
1175 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
1177 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1179 fputs_filtered (" ", stream
);
1185 /* If we just printed a tag name, no need to print anything
1187 if (TYPE_TAG_NAME (type
) == NULL
)
1188 fprintf_filtered (stream
, "{...}");
1190 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
1192 fprintf_filtered (stream
, "{");
1193 len
= TYPE_NFIELDS (type
);
1195 for (i
= 0; i
< len
; i
++)
1199 fprintf_filtered (stream
, ", ");
1201 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1202 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1204 fprintf_filtered (stream
, " = %d",
1205 TYPE_FIELD_BITPOS (type
, i
));
1206 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1210 fprintf_filtered (stream
, "}");
1214 case TYPE_CODE_VOID
:
1215 fprintf_filtered (stream
, "void");
1218 case TYPE_CODE_UNDEF
:
1219 fprintf_filtered (stream
, _("struct <unknown>"));
1222 case TYPE_CODE_ERROR
:
1223 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
1226 case TYPE_CODE_RANGE
:
1227 /* This should not occur. */
1228 fprintf_filtered (stream
, _("<range type>"));
1231 case TYPE_CODE_NAMESPACE
:
1232 fputs_filtered ("namespace ", stream
);
1233 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1237 /* Handle types not explicitly handled by the other cases, such
1238 as fundamental types. For these, just print whatever the
1239 type name is, as recorded in the type itself. If there is no
1240 type name, then complain. */
1241 if (TYPE_NAME (type
) != NULL
)
1243 c_type_print_modifier (type
, stream
, 0, 1);
1244 fputs_filtered (TYPE_NAME (type
), stream
);
1248 /* At least for dump_symtab, it is important that this not
1250 fprintf_filtered (stream
, _("<invalid type code %d>"),