1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright (C) 1986, 1988-1989, 1991-1996, 1998-2003, 2006-2012 Free
3 Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdb_obstack.h"
22 #include "bfd.h" /* Binary File Description. */
25 #include "expression.h"
32 #include "typeprint.h"
35 #include "gdb_string.h"
38 static void c_type_print_varspec_prefix (struct type
*,
42 /* Print "const", "volatile", or address space modifiers. */
43 static void c_type_print_modifier (struct type
*,
47 /* LEVEL is the depth to indent lines by. */
50 c_print_type (struct type
*type
,
51 const char *varstring
,
52 struct ui_file
*stream
,
62 c_type_print_base (type
, stream
, show
, level
);
63 code
= TYPE_CODE (type
);
64 if ((varstring
!= NULL
&& *varstring
!= '\0')
65 /* Need a space if going to print stars or brackets;
66 but not if we will print just a type name. */
67 || ((show
> 0 || TYPE_NAME (type
) == 0)
68 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
69 || code
== TYPE_CODE_METHOD
70 || code
== TYPE_CODE_ARRAY
71 || code
== TYPE_CODE_MEMBERPTR
72 || code
== TYPE_CODE_METHODPTR
73 || code
== TYPE_CODE_REF
)))
74 fputs_filtered (" ", stream
);
75 need_post_space
= (varstring
!= NULL
&& strcmp (varstring
, "") != 0);
76 c_type_print_varspec_prefix (type
, stream
, show
, 0, need_post_space
);
78 if (varstring
!= NULL
)
80 fputs_filtered (varstring
, stream
);
82 /* For demangled function names, we have the arglist as part of
83 the name, so don't print an additional pair of ()'s. */
85 demangled_args
= strchr (varstring
, '(') != NULL
;
86 c_type_print_varspec_suffix (type
, stream
, show
,
91 /* Print a typedef using C syntax. TYPE is the underlying type.
92 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
96 c_print_typedef (struct type
*type
,
97 struct symbol
*new_symbol
,
98 struct ui_file
*stream
)
100 CHECK_TYPEDEF (type
);
101 fprintf_filtered (stream
, "typedef ");
102 type_print (type
, "", stream
, 0);
103 if (TYPE_NAME ((SYMBOL_TYPE (new_symbol
))) == 0
104 || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol
))),
105 SYMBOL_LINKAGE_NAME (new_symbol
)) != 0
106 || TYPE_CODE (SYMBOL_TYPE (new_symbol
)) == TYPE_CODE_TYPEDEF
)
107 fprintf_filtered (stream
, " %s", SYMBOL_PRINT_NAME (new_symbol
));
108 fprintf_filtered (stream
, ";\n");
111 /* If TYPE is a derived type, then print out derivation information.
112 Print only the actual base classes of this type, not the base
113 classes of the base classes. I.e. for the derivation hierarchy:
116 class B : public A {int b; };
117 class C : public B {int c; };
119 Print the type of class C as:
125 Not as the following (like gdb used to), which is not legal C++
126 syntax for derived types and may be confused with the multiple
129 class C : public B : public A {
133 In general, gdb should try to print the types as closely as
134 possible to the form that they appear in the source code.
136 Note that in case of protected derivation gcc will not say
137 'protected' but 'private'. The HP's aCC compiler emits specific
138 information for derivation via protected inheritance, so gdb can
142 cp_type_print_derivation_info (struct ui_file
*stream
,
148 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
150 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
151 fprintf_filtered (stream
, "%s%s ",
152 BASETYPE_VIA_PUBLIC (type
, i
)
153 ? "public" : (TYPE_FIELD_PROTECTED (type
, i
)
154 ? "protected" : "private"),
155 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
156 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
157 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
161 fputs_filtered (" ", stream
);
165 /* Print the C++ method arguments ARGS to the file STREAM. */
168 cp_type_print_method_args (struct type
*mtype
, const char *prefix
,
169 const char *varstring
, int staticp
,
170 struct ui_file
*stream
)
172 struct field
*args
= TYPE_FIELDS (mtype
);
173 int nargs
= TYPE_NFIELDS (mtype
);
174 int varargs
= TYPE_VARARGS (mtype
);
177 fprintf_symbol_filtered (stream
, prefix
,
178 language_cplus
, DMGL_ANSI
);
179 fprintf_symbol_filtered (stream
, varstring
,
180 language_cplus
, DMGL_ANSI
);
181 fputs_filtered ("(", stream
);
183 /* Skip the class variable. */
189 type_print (args
[i
++].type
, "", stream
, 0);
191 if (i
== nargs
&& varargs
)
192 fprintf_filtered (stream
, ", ...");
194 fprintf_filtered (stream
, ", ");
198 fprintf_filtered (stream
, "...");
199 else if (current_language
->la_language
== language_cplus
)
200 fprintf_filtered (stream
, "void");
202 fprintf_filtered (stream
, ")");
204 /* For non-static methods, read qualifiers from the type of
210 gdb_assert (nargs
> 0);
211 gdb_assert (TYPE_CODE (args
[0].type
) == TYPE_CODE_PTR
);
212 domain
= TYPE_TARGET_TYPE (args
[0].type
);
214 if (TYPE_CONST (domain
))
215 fprintf_filtered (stream
, " const");
217 if (TYPE_VOLATILE (domain
))
218 fprintf_filtered (stream
, " volatile");
223 /* Print any asterisks or open-parentheses needed before the
224 variable name (to describe its type).
226 On outermost call, pass 0 for PASSED_A_PTR.
227 On outermost call, SHOW > 0 means should ignore
228 any typename for TYPE and show its details.
229 SHOW is always zero on recursive calls.
231 NEED_POST_SPACE is non-zero when a space will be be needed
232 between a trailing qualifier and a field, variable, or function
236 c_type_print_varspec_prefix (struct type
*type
,
237 struct ui_file
*stream
,
238 int show
, int passed_a_ptr
,
246 if (TYPE_NAME (type
) && show
<= 0)
251 switch (TYPE_CODE (type
))
254 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
256 fprintf_filtered (stream
, "*");
257 c_type_print_modifier (type
, stream
, 1, need_post_space
);
260 case TYPE_CODE_MEMBERPTR
:
261 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
263 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
265 fputs_filtered (name
, stream
);
267 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
268 stream
, -1, passed_a_ptr
);
269 fprintf_filtered (stream
, "::*");
272 case TYPE_CODE_METHODPTR
:
273 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
275 fprintf_filtered (stream
, "(");
276 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
278 fputs_filtered (name
, stream
);
280 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
281 stream
, -1, passed_a_ptr
);
282 fprintf_filtered (stream
, "::*");
286 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
288 fprintf_filtered (stream
, "&");
289 c_type_print_modifier (type
, stream
, 1, need_post_space
);
292 case TYPE_CODE_METHOD
:
294 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
297 fprintf_filtered (stream
, "(");
300 case TYPE_CODE_ARRAY
:
301 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
304 fprintf_filtered (stream
, "(");
307 case TYPE_CODE_TYPEDEF
:
308 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
309 stream
, show
, passed_a_ptr
, 0);
312 case TYPE_CODE_UNDEF
:
313 case TYPE_CODE_STRUCT
:
314 case TYPE_CODE_UNION
:
319 case TYPE_CODE_ERROR
:
323 case TYPE_CODE_RANGE
:
324 case TYPE_CODE_STRING
:
325 case TYPE_CODE_COMPLEX
:
326 case TYPE_CODE_NAMESPACE
:
327 case TYPE_CODE_DECFLOAT
:
328 /* These types need no prefix. They are listed here so that
329 gcc -Wall will reveal any types that haven't been handled. */
332 error (_("type not handled in c_type_print_varspec_prefix()"));
337 /* Print out "const" and "volatile" attributes,
338 and address space id if present.
339 TYPE is a pointer to the type being printed out.
340 STREAM is the output destination.
341 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
342 NEED_POST_SPACE = 1 indicates a final white space is needed. */
345 c_type_print_modifier (struct type
*type
, struct ui_file
*stream
,
346 int need_pre_space
, int need_post_space
)
348 int did_print_modifier
= 0;
349 const char *address_space_id
;
351 /* We don't print `const' qualifiers for references --- since all
352 operators affect the thing referenced, not the reference itself,
353 every reference is `const'. */
354 if (TYPE_CONST (type
)
355 && TYPE_CODE (type
) != TYPE_CODE_REF
)
358 fprintf_filtered (stream
, " ");
359 fprintf_filtered (stream
, "const");
360 did_print_modifier
= 1;
363 if (TYPE_VOLATILE (type
))
365 if (did_print_modifier
|| need_pre_space
)
366 fprintf_filtered (stream
, " ");
367 fprintf_filtered (stream
, "volatile");
368 did_print_modifier
= 1;
371 address_space_id
= address_space_int_to_name (get_type_arch (type
),
372 TYPE_INSTANCE_FLAGS (type
));
373 if (address_space_id
)
375 if (did_print_modifier
|| need_pre_space
)
376 fprintf_filtered (stream
, " ");
377 fprintf_filtered (stream
, "@%s", address_space_id
);
378 did_print_modifier
= 1;
381 if (did_print_modifier
&& need_post_space
)
382 fprintf_filtered (stream
, " ");
386 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
387 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
388 in non-static methods, are displayed if LINKAGE_NAME is zero. If
389 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
390 parameter types get removed their possible const and volatile qualifiers to
391 match demangled linkage name parameters part of such function type.
392 LANGUAGE is the language in which TYPE was defined. This is a necessary
393 evil since this code is used by the C, C++, and Java backends. */
396 c_type_print_args (struct type
*type
, struct ui_file
*stream
,
397 int linkage_name
, enum language language
)
403 fprintf_filtered (stream
, "(");
404 args
= TYPE_FIELDS (type
);
405 len
= TYPE_NFIELDS (type
);
407 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
409 struct type
*param_type
;
411 if (TYPE_FIELD_ARTIFICIAL (type
, i
) && linkage_name
)
416 fprintf_filtered (stream
, ", ");
420 param_type
= TYPE_FIELD_TYPE (type
, i
);
422 if (language
== language_cplus
&& linkage_name
)
424 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
425 - Parameter declarations that differ only in the presence or
426 absence of const and/or volatile are equivalent.
428 And the const/volatile qualifiers are not present in the mangled
429 names as produced by GCC. */
431 param_type
= make_cv_type (0, 0, param_type
, NULL
);
434 if (language
== language_java
)
435 java_print_type (param_type
, "", stream
, -1, 0);
437 c_print_type (param_type
, "", stream
, -1, 0);
441 if (printed_any
&& TYPE_VARARGS (type
))
443 /* Print out a trailing ellipsis for varargs functions. Ignore
444 TYPE_VARARGS if the function has no named arguments; that
445 represents unprototyped (K&R style) C functions. */
446 if (printed_any
&& TYPE_VARARGS (type
))
448 fprintf_filtered (stream
, ", ");
450 fprintf_filtered (stream
, "...");
453 else if (!printed_any
454 && ((TYPE_PROTOTYPED (type
) && language
!= language_java
)
455 || language
== language_cplus
))
456 fprintf_filtered (stream
, "void");
458 fprintf_filtered (stream
, ")");
461 /* Return true iff the j'th overloading of the i'th method of TYPE
462 is a type conversion operator, like `operator int () { ... }'.
463 When listing a class's methods, we don't print the return type of
467 is_type_conversion_operator (struct type
*type
, int i
, int j
)
469 /* I think the whole idea of recognizing type conversion operators
470 by their name is pretty terrible. But I don't think our present
471 data structure gives us any other way to tell. If you know of
472 some other way, feel free to rewrite this function. */
473 const char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
475 if (strncmp (name
, "operator", 8) != 0)
479 if (! strchr (" \t\f\n\r", *name
))
482 while (strchr (" \t\f\n\r", *name
))
485 if (!('a' <= *name
&& *name
<= 'z')
486 && !('A' <= *name
&& *name
<= 'Z')
488 /* If this doesn't look like the start of an identifier, then it
489 isn't a type conversion operator. */
491 else if (strncmp (name
, "new", 3) == 0)
493 else if (strncmp (name
, "delete", 6) == 0)
496 /* If it doesn't look like new or delete, it's a type conversion
500 /* Is that really the end of the name? */
501 if (('a' <= *name
&& *name
<= 'z')
502 || ('A' <= *name
&& *name
<= 'Z')
503 || ('0' <= *name
&& *name
<= '9')
505 /* No, so the identifier following "operator" must be a type name,
506 and this is a type conversion operator. */
509 /* That was indeed the end of the name, so it was `operator new' or
510 `operator delete', neither of which are type conversion
515 /* Given a C++ qualified identifier QID, strip off the qualifiers,
516 yielding the unqualified name. The return value is a pointer into
519 It's a pity we don't have this information in some more structured
520 form. Even the author of this function feels that writing little
521 parsers like this everywhere is stupid. */
524 remove_qualifiers (char *qid
)
526 int quoted
= 0; /* Zero if we're not in quotes;
527 '"' if we're in a double-quoted string;
528 '\'' if we're in a single-quoted string. */
529 int depth
= 0; /* Number of unclosed parens we've seen. */
530 char *parenstack
= (char *) alloca (strlen (qid
));
532 char *last
= 0; /* The character after the rightmost
533 `::' token we've seen so far. */
535 for (scan
= qid
; *scan
; scan
++)
541 else if (*scan
== '\\' && *(scan
+ 1))
544 else if (scan
[0] == ':' && scan
[1] == ':')
546 /* If we're inside parenthesis (i.e., an argument list) or
547 angle brackets (i.e., a list of template arguments), then
548 we don't record the position of this :: token, since it's
549 not relevant to the top-level structure we're trying to
557 else if (*scan
== '"' || *scan
== '\'')
559 else if (*scan
== '(')
560 parenstack
[depth
++] = ')';
561 else if (*scan
== '[')
562 parenstack
[depth
++] = ']';
563 /* We're going to treat <> as a pair of matching characters,
564 since we're more likely to see those in template id's than
565 real less-than characters. What a crock. */
566 else if (*scan
== '<')
567 parenstack
[depth
++] = '>';
568 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
570 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
574 /* We're going to do a little error recovery here. If
575 we don't find a match for *scan on the paren stack,
576 but there is something lower on the stack that does
577 match, we pop the stack to that point. */
580 for (i
= depth
- 1; i
>= 0; i
--)
581 if (parenstack
[i
] == *scan
)
593 /* We didn't find any :: tokens at the top level, so declare the
594 whole thing an unqualified identifier. */
598 /* Print any array sizes, function arguments or close parentheses
599 needed after the variable name (to describe its type).
600 Args work like c_type_print_varspec_prefix. */
603 c_type_print_varspec_suffix (struct type
*type
,
604 struct ui_file
*stream
,
605 int show
, int passed_a_ptr
,
611 if (TYPE_NAME (type
) && show
<= 0)
616 switch (TYPE_CODE (type
))
618 case TYPE_CODE_ARRAY
:
620 LONGEST low_bound
, high_bound
;
621 int is_vector
= TYPE_VECTOR (type
);
624 fprintf_filtered (stream
, ")");
626 fprintf_filtered (stream
, (is_vector
?
627 "__attribute__ ((vector_size(" : "["));
628 if (get_array_bounds (type
, &low_bound
, &high_bound
))
629 fprintf_filtered (stream
, "%d",
630 (int) (high_bound
- low_bound
+ 1));
631 fprintf_filtered (stream
, (is_vector
? ")))" : "]"));
633 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
638 case TYPE_CODE_MEMBERPTR
:
639 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
643 case TYPE_CODE_METHODPTR
:
644 fprintf_filtered (stream
, ")");
645 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
651 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
655 case TYPE_CODE_METHOD
:
658 fprintf_filtered (stream
, ")");
660 c_type_print_args (type
, stream
, 0, current_language
->la_language
);
661 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
662 show
, passed_a_ptr
, 0);
665 case TYPE_CODE_TYPEDEF
:
666 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
667 show
, passed_a_ptr
, 0);
670 case TYPE_CODE_UNDEF
:
671 case TYPE_CODE_STRUCT
:
672 case TYPE_CODE_UNION
:
677 case TYPE_CODE_ERROR
:
681 case TYPE_CODE_RANGE
:
682 case TYPE_CODE_STRING
:
683 case TYPE_CODE_COMPLEX
:
684 case TYPE_CODE_NAMESPACE
:
685 case TYPE_CODE_DECFLOAT
:
686 /* These types do not need a suffix. They are listed so that
687 gcc -Wall will report types that may not have been
691 error (_("type not handled in c_type_print_varspec_suffix()"));
696 /* Print the name of the type (or the ultimate pointer target,
697 function value or array element), or the description of a structure
700 SHOW positive means print details about the type (e.g. enum
701 values), and print structure elements passing SHOW - 1 for show.
703 SHOW negative means just print the type name or struct tag if there
704 is one. If there is no name, print something sensible but concise
707 SHOW zero means just print the type name or struct tag if there is
708 one. If there is no name, print something sensible but not as
709 concise like "struct {int x; int y;}".
711 LEVEL is the number of spaces to indent by.
712 We increase it for some recursive calls. */
715 c_type_print_base (struct type
*type
, struct ui_file
*stream
,
722 s_none
, s_public
, s_private
, s_protected
725 int need_access_label
= 0;
733 fputs_filtered (_("<type unknown>"), stream
);
737 /* When SHOW is zero or less, and there is a valid type name, then
738 always just print the type name directly from the type. */
739 /* If we have "typedef struct foo {. . .} bar;" do we want to print
740 it as "struct foo" or as "bar"? Pick the latter, because C++
741 folk tend to expect things like "class5 *foo" rather than "struct
745 && TYPE_NAME (type
) != NULL
)
747 c_type_print_modifier (type
, stream
, 0, 1);
748 fputs_filtered (TYPE_NAME (type
), stream
);
752 CHECK_TYPEDEF (type
);
754 switch (TYPE_CODE (type
))
756 case TYPE_CODE_TYPEDEF
:
757 /* If we get here, the typedef doesn't have a name, and we
758 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
759 gdb_assert (TYPE_NAME (type
) == NULL
);
760 gdb_assert (TYPE_TARGET_TYPE (type
) == NULL
);
761 fprintf_filtered (stream
, _("<unnamed typedef>"));
764 case TYPE_CODE_ARRAY
:
766 case TYPE_CODE_MEMBERPTR
:
769 case TYPE_CODE_METHOD
:
770 case TYPE_CODE_METHODPTR
:
771 c_type_print_base (TYPE_TARGET_TYPE (type
),
772 stream
, show
, level
);
775 case TYPE_CODE_STRUCT
:
776 c_type_print_modifier (type
, stream
, 0, 1);
777 if (TYPE_DECLARED_CLASS (type
))
778 fprintf_filtered (stream
, "class ");
780 fprintf_filtered (stream
, "struct ");
783 case TYPE_CODE_UNION
:
784 c_type_print_modifier (type
, stream
, 0, 1);
785 fprintf_filtered (stream
, "union ");
789 /* Print the tag if it exists. The HP aCC compiler emits a
790 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
791 enum}" tag for unnamed struct/union/enum's, which we don't
793 if (TYPE_TAG_NAME (type
) != NULL
794 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
796 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
798 fputs_filtered (" ", stream
);
803 /* If we just printed a tag name, no need to print anything
805 if (TYPE_TAG_NAME (type
) == NULL
)
806 fprintf_filtered (stream
, "{...}");
808 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
810 struct type
*basetype
;
813 cp_type_print_derivation_info (stream
, type
);
815 fprintf_filtered (stream
, "{\n");
816 if (TYPE_NFIELDS (type
) == 0 && TYPE_NFN_FIELDS (type
) == 0
817 && TYPE_TYPEDEF_FIELD_COUNT (type
) == 0)
819 if (TYPE_STUB (type
))
820 fprintfi_filtered (level
+ 4, stream
,
821 _("<incomplete type>\n"));
823 fprintfi_filtered (level
+ 4, stream
,
824 _("<no data fields>\n"));
827 /* Start off with no specific section type, so we can print
828 one for the first field we find, and use that section type
829 thereafter until we find another type. */
831 section_type
= s_none
;
833 /* For a class, if all members are private, there's no need
834 for a "private:" label; similarly, for a struct or union
835 masquerading as a class, if all members are public, there's
836 no need for a "public:" label. */
838 if (TYPE_DECLARED_CLASS (type
))
841 len
= TYPE_NFIELDS (type
);
842 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
843 if (!TYPE_FIELD_PRIVATE (type
, i
))
845 need_access_label
= 1;
849 if (!need_access_label
)
851 len2
= TYPE_NFN_FIELDS (type
);
852 for (j
= 0; j
< len2
; j
++)
854 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
855 for (i
= 0; i
< len
; i
++)
856 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
859 need_access_label
= 1;
862 if (need_access_label
)
870 len
= TYPE_NFIELDS (type
);
871 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
872 if (TYPE_FIELD_PRIVATE (type
, i
)
873 || TYPE_FIELD_PROTECTED (type
, i
))
875 need_access_label
= 1;
879 if (!need_access_label
)
881 len2
= TYPE_NFN_FIELDS (type
);
882 for (j
= 0; j
< len2
; j
++)
885 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
886 for (i
= 0; i
< len
; i
++)
887 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
,
889 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
893 need_access_label
= 1;
896 if (need_access_label
)
902 /* If there is a base class for this type,
903 do not print the field that it occupies. */
905 len
= TYPE_NFIELDS (type
);
906 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
907 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
911 /* If we have a virtual table pointer, omit it. Even if
912 virtual table pointers are not specifically marked in
913 the debug info, they should be artificial. */
914 if ((i
== vptr_fieldno
&& type
== basetype
)
915 || TYPE_FIELD_ARTIFICIAL (type
, i
))
918 if (need_access_label
)
920 if (TYPE_FIELD_PROTECTED (type
, i
))
922 if (section_type
!= s_protected
)
924 section_type
= s_protected
;
925 fprintfi_filtered (level
+ 2, stream
,
929 else if (TYPE_FIELD_PRIVATE (type
, i
))
931 if (section_type
!= s_private
)
933 section_type
= s_private
;
934 fprintfi_filtered (level
+ 2, stream
,
940 if (section_type
!= s_public
)
942 section_type
= s_public
;
943 fprintfi_filtered (level
+ 2, stream
,
949 print_spaces_filtered (level
+ 4, stream
);
950 if (field_is_static (&TYPE_FIELD (type
, i
)))
951 fprintf_filtered (stream
, "static ");
952 c_print_type (TYPE_FIELD_TYPE (type
, i
),
953 TYPE_FIELD_NAME (type
, i
),
954 stream
, show
- 1, level
+ 4);
955 if (!field_is_static (&TYPE_FIELD (type
, i
))
956 && TYPE_FIELD_PACKED (type
, i
))
958 /* It is a bitfield. This code does not attempt
959 to look at the bitpos and reconstruct filler,
960 unnamed fields. This would lead to misleading
961 results if the compiler does not put out fields
962 for such things (I don't know what it does). */
963 fprintf_filtered (stream
, " : %d",
964 TYPE_FIELD_BITSIZE (type
, i
));
966 fprintf_filtered (stream
, ";\n");
969 /* If there are both fields and methods, put a blank line
970 between them. Make sure to count only method that we
971 will display; artificial methods will be hidden. */
972 len
= TYPE_NFN_FIELDS (type
);
974 for (i
= 0; i
< len
; i
++)
976 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
977 int len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
980 for (j
= 0; j
< len2
; j
++)
981 if (!TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
984 if (real_len
> 0 && section_type
!= s_none
)
985 fprintf_filtered (stream
, "\n");
987 /* C++: print out the methods. */
988 for (i
= 0; i
< len
; i
++)
990 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
991 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
992 const char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
993 const char *name
= type_name_no_tag (type
);
994 int is_constructor
= name
&& strcmp (method_name
,
997 for (j
= 0; j
< len2
; j
++)
999 const char *mangled_name
;
1000 char *demangled_name
;
1001 struct cleanup
*inner_cleanup
;
1002 const char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1003 int is_full_physname_constructor
=
1004 is_constructor_name (physname
)
1005 || is_destructor_name (physname
)
1006 || method_name
[0] == '~';
1008 /* Do not print out artificial methods. */
1009 if (TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1012 inner_cleanup
= make_cleanup (null_cleanup
, NULL
);
1015 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
1017 if (section_type
!= s_protected
)
1019 section_type
= s_protected
;
1020 fprintfi_filtered (level
+ 2, stream
,
1024 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
1026 if (section_type
!= s_private
)
1028 section_type
= s_private
;
1029 fprintfi_filtered (level
+ 2, stream
,
1035 if (section_type
!= s_public
)
1037 section_type
= s_public
;
1038 fprintfi_filtered (level
+ 2, stream
,
1043 print_spaces_filtered (level
+ 4, stream
);
1044 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1045 fprintf_filtered (stream
, "virtual ");
1046 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1047 fprintf_filtered (stream
, "static ");
1048 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1050 /* Keep GDB from crashing here. */
1051 fprintf_filtered (stream
,
1052 _("<undefined type> %s;\n"),
1053 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1056 else if (!is_constructor
/* Constructors don't
1059 && !is_full_physname_constructor
/* " " */
1060 && !is_type_conversion_operator (type
, i
, j
))
1062 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1064 fputs_filtered (" ", stream
);
1066 if (TYPE_FN_FIELD_STUB (f
, j
))
1070 /* Build something we can demangle. */
1071 tem
= gdb_mangle_name (type
, i
, j
);
1072 make_cleanup (xfree
, tem
);
1076 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1079 cplus_demangle (mangled_name
,
1080 DMGL_ANSI
| DMGL_PARAMS
);
1081 if (demangled_name
== NULL
)
1083 /* In some cases (for instance with the HP
1084 demangling), if a function has more than 10
1085 arguments, the demangling will fail.
1086 Let's try to reconstruct the function
1087 signature from the symbol information. */
1088 if (!TYPE_FN_FIELD_STUB (f
, j
))
1090 int staticp
= TYPE_FN_FIELD_STATIC_P (f
, j
);
1091 struct type
*mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
1093 cp_type_print_method_args (mtype
,
1100 fprintf_filtered (stream
,
1101 _("<badly mangled name '%s'>"),
1107 char *demangled_no_class
1108 = remove_qualifiers (demangled_name
);
1110 /* Get rid of the `static' appended by the
1112 p
= strstr (demangled_no_class
, " static");
1115 int length
= p
- demangled_no_class
;
1116 char *demangled_no_static
;
1119 = (char *) xmalloc (length
+ 1);
1120 strncpy (demangled_no_static
,
1121 demangled_no_class
, length
);
1122 *(demangled_no_static
+ length
) = '\0';
1123 fputs_filtered (demangled_no_static
, stream
);
1124 xfree (demangled_no_static
);
1127 fputs_filtered (demangled_no_class
, stream
);
1128 xfree (demangled_name
);
1131 do_cleanups (inner_cleanup
);
1133 fprintf_filtered (stream
, ";\n");
1137 /* Print typedefs defined in this class. */
1139 if (TYPE_TYPEDEF_FIELD_COUNT (type
) != 0)
1141 if (TYPE_NFIELDS (type
) != 0 || TYPE_NFN_FIELDS (type
) != 0)
1142 fprintf_filtered (stream
, "\n");
1144 for (i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); i
++)
1146 struct type
*target
= TYPE_TYPEDEF_FIELD_TYPE (type
, i
);
1148 /* Dereference the typedef declaration itself. */
1149 gdb_assert (TYPE_CODE (target
) == TYPE_CODE_TYPEDEF
);
1150 target
= TYPE_TARGET_TYPE (target
);
1152 print_spaces_filtered (level
+ 4, stream
);
1153 fprintf_filtered (stream
, "typedef ");
1154 c_print_type (target
, TYPE_TYPEDEF_FIELD_NAME (type
, i
),
1155 stream
, show
- 1, level
+ 4);
1156 fprintf_filtered (stream
, ";\n");
1160 fprintfi_filtered (level
, stream
, "}");
1162 if (TYPE_LOCALTYPE_PTR (type
) && show
>= 0)
1163 fprintfi_filtered (level
,
1164 stream
, _(" (Local at %s:%d)\n"),
1165 TYPE_LOCALTYPE_FILE (type
),
1166 TYPE_LOCALTYPE_LINE (type
));
1170 case TYPE_CODE_ENUM
:
1171 c_type_print_modifier (type
, stream
, 0, 1);
1172 fprintf_filtered (stream
, "enum ");
1173 /* Print the tag name if it exists.
1174 The aCC compiler emits a spurious
1175 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1176 tag for unnamed struct/union/enum's, which we don't
1178 if (TYPE_TAG_NAME (type
) != NULL
1179 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
1181 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1183 fputs_filtered (" ", stream
);
1189 /* If we just printed a tag name, no need to print anything
1191 if (TYPE_TAG_NAME (type
) == NULL
)
1192 fprintf_filtered (stream
, "{...}");
1194 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
1196 LONGEST lastval
= 0;
1198 fprintf_filtered (stream
, "{");
1199 len
= TYPE_NFIELDS (type
);
1200 for (i
= 0; i
< len
; i
++)
1204 fprintf_filtered (stream
, ", ");
1206 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1207 if (lastval
!= TYPE_FIELD_ENUMVAL (type
, i
))
1209 fprintf_filtered (stream
, " = %s",
1210 plongest (TYPE_FIELD_ENUMVAL (type
, i
)));
1211 lastval
= TYPE_FIELD_ENUMVAL (type
, i
);
1215 fprintf_filtered (stream
, "}");
1219 case TYPE_CODE_VOID
:
1220 fprintf_filtered (stream
, "void");
1223 case TYPE_CODE_UNDEF
:
1224 fprintf_filtered (stream
, _("struct <unknown>"));
1227 case TYPE_CODE_ERROR
:
1228 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
1231 case TYPE_CODE_RANGE
:
1232 /* This should not occur. */
1233 fprintf_filtered (stream
, _("<range type>"));
1236 case TYPE_CODE_NAMESPACE
:
1237 fputs_filtered ("namespace ", stream
);
1238 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1242 /* Handle types not explicitly handled by the other cases, such
1243 as fundamental types. For these, just print whatever the
1244 type name is, as recorded in the type itself. If there is no
1245 type name, then complain. */
1246 if (TYPE_NAME (type
) != NULL
)
1248 c_type_print_modifier (type
, stream
, 0, 1);
1249 fputs_filtered (TYPE_NAME (type
), stream
);
1253 /* At least for dump_symtab, it is important that this not
1255 fprintf_filtered (stream
, _("<invalid type code %d>"),