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. */
137 cp_type_print_derivation_info (struct ui_file
*stream
,
143 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
145 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
146 fprintf_filtered (stream
, "%s%s ",
147 BASETYPE_VIA_PUBLIC (type
, i
)
148 ? "public" : (TYPE_FIELD_PROTECTED (type
, i
)
149 ? "protected" : "private"),
150 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
151 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
152 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
156 fputs_filtered (" ", stream
);
160 /* Print the C++ method arguments ARGS to the file STREAM. */
163 cp_type_print_method_args (struct type
*mtype
, const char *prefix
,
164 const char *varstring
, int staticp
,
165 struct ui_file
*stream
)
167 struct field
*args
= TYPE_FIELDS (mtype
);
168 int nargs
= TYPE_NFIELDS (mtype
);
169 int varargs
= TYPE_VARARGS (mtype
);
172 fprintf_symbol_filtered (stream
, prefix
,
173 language_cplus
, DMGL_ANSI
);
174 fprintf_symbol_filtered (stream
, varstring
,
175 language_cplus
, DMGL_ANSI
);
176 fputs_filtered ("(", stream
);
178 /* Skip the class variable. */
184 type_print (args
[i
++].type
, "", stream
, 0);
186 if (i
== nargs
&& varargs
)
187 fprintf_filtered (stream
, ", ...");
189 fprintf_filtered (stream
, ", ");
193 fprintf_filtered (stream
, "...");
194 else if (current_language
->la_language
== language_cplus
)
195 fprintf_filtered (stream
, "void");
197 fprintf_filtered (stream
, ")");
199 /* For non-static methods, read qualifiers from the type of
205 gdb_assert (nargs
> 0);
206 gdb_assert (TYPE_CODE (args
[0].type
) == TYPE_CODE_PTR
);
207 domain
= TYPE_TARGET_TYPE (args
[0].type
);
209 if (TYPE_CONST (domain
))
210 fprintf_filtered (stream
, " const");
212 if (TYPE_VOLATILE (domain
))
213 fprintf_filtered (stream
, " volatile");
218 /* Print any asterisks or open-parentheses needed before the
219 variable name (to describe its type).
221 On outermost call, pass 0 for PASSED_A_PTR.
222 On outermost call, SHOW > 0 means should ignore
223 any typename for TYPE and show its details.
224 SHOW is always zero on recursive calls.
226 NEED_POST_SPACE is non-zero when a space will be be needed
227 between a trailing qualifier and a field, variable, or function
231 c_type_print_varspec_prefix (struct type
*type
,
232 struct ui_file
*stream
,
233 int show
, int passed_a_ptr
,
241 if (TYPE_NAME (type
) && show
<= 0)
246 switch (TYPE_CODE (type
))
249 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
251 fprintf_filtered (stream
, "*");
252 c_type_print_modifier (type
, stream
, 1, need_post_space
);
255 case TYPE_CODE_MEMBERPTR
:
256 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
258 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
260 fputs_filtered (name
, stream
);
262 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
263 stream
, -1, passed_a_ptr
);
264 fprintf_filtered (stream
, "::*");
267 case TYPE_CODE_METHODPTR
:
268 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
270 fprintf_filtered (stream
, "(");
271 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
273 fputs_filtered (name
, stream
);
275 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
276 stream
, -1, passed_a_ptr
);
277 fprintf_filtered (stream
, "::*");
281 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
283 fprintf_filtered (stream
, "&");
284 c_type_print_modifier (type
, stream
, 1, need_post_space
);
287 case TYPE_CODE_METHOD
:
289 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
292 fprintf_filtered (stream
, "(");
295 case TYPE_CODE_ARRAY
:
296 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
299 fprintf_filtered (stream
, "(");
302 case TYPE_CODE_TYPEDEF
:
303 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
304 stream
, show
, passed_a_ptr
, 0);
307 case TYPE_CODE_UNDEF
:
308 case TYPE_CODE_STRUCT
:
309 case TYPE_CODE_UNION
:
314 case TYPE_CODE_ERROR
:
318 case TYPE_CODE_RANGE
:
319 case TYPE_CODE_STRING
:
320 case TYPE_CODE_COMPLEX
:
321 case TYPE_CODE_NAMESPACE
:
322 case TYPE_CODE_DECFLOAT
:
323 /* These types need no prefix. They are listed here so that
324 gcc -Wall will reveal any types that haven't been handled. */
327 error (_("type not handled in c_type_print_varspec_prefix()"));
332 /* Print out "const" and "volatile" attributes,
333 and address space id if present.
334 TYPE is a pointer to the type being printed out.
335 STREAM is the output destination.
336 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
337 NEED_POST_SPACE = 1 indicates a final white space is needed. */
340 c_type_print_modifier (struct type
*type
, struct ui_file
*stream
,
341 int need_pre_space
, int need_post_space
)
343 int did_print_modifier
= 0;
344 const char *address_space_id
;
346 /* We don't print `const' qualifiers for references --- since all
347 operators affect the thing referenced, not the reference itself,
348 every reference is `const'. */
349 if (TYPE_CONST (type
)
350 && TYPE_CODE (type
) != TYPE_CODE_REF
)
353 fprintf_filtered (stream
, " ");
354 fprintf_filtered (stream
, "const");
355 did_print_modifier
= 1;
358 if (TYPE_VOLATILE (type
))
360 if (did_print_modifier
|| need_pre_space
)
361 fprintf_filtered (stream
, " ");
362 fprintf_filtered (stream
, "volatile");
363 did_print_modifier
= 1;
366 address_space_id
= address_space_int_to_name (get_type_arch (type
),
367 TYPE_INSTANCE_FLAGS (type
));
368 if (address_space_id
)
370 if (did_print_modifier
|| need_pre_space
)
371 fprintf_filtered (stream
, " ");
372 fprintf_filtered (stream
, "@%s", address_space_id
);
373 did_print_modifier
= 1;
376 if (did_print_modifier
&& need_post_space
)
377 fprintf_filtered (stream
, " ");
381 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
382 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
383 in non-static methods, are displayed if LINKAGE_NAME is zero. If
384 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
385 parameter types get removed their possible const and volatile qualifiers to
386 match demangled linkage name parameters part of such function type.
387 LANGUAGE is the language in which TYPE was defined. This is a necessary
388 evil since this code is used by the C, C++, and Java backends. */
391 c_type_print_args (struct type
*type
, struct ui_file
*stream
,
392 int linkage_name
, enum language language
)
398 fprintf_filtered (stream
, "(");
399 args
= TYPE_FIELDS (type
);
400 len
= TYPE_NFIELDS (type
);
402 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
404 struct type
*param_type
;
406 if (TYPE_FIELD_ARTIFICIAL (type
, i
) && linkage_name
)
411 fprintf_filtered (stream
, ", ");
415 param_type
= TYPE_FIELD_TYPE (type
, i
);
417 if (language
== language_cplus
&& linkage_name
)
419 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
420 - Parameter declarations that differ only in the presence or
421 absence of const and/or volatile are equivalent.
423 And the const/volatile qualifiers are not present in the mangled
424 names as produced by GCC. */
426 param_type
= make_cv_type (0, 0, param_type
, NULL
);
429 if (language
== language_java
)
430 java_print_type (param_type
, "", stream
, -1, 0);
432 c_print_type (param_type
, "", stream
, -1, 0);
436 if (printed_any
&& TYPE_VARARGS (type
))
438 /* Print out a trailing ellipsis for varargs functions. Ignore
439 TYPE_VARARGS if the function has no named arguments; that
440 represents unprototyped (K&R style) C functions. */
441 if (printed_any
&& TYPE_VARARGS (type
))
443 fprintf_filtered (stream
, ", ");
445 fprintf_filtered (stream
, "...");
448 else if (!printed_any
449 && ((TYPE_PROTOTYPED (type
) && language
!= language_java
)
450 || language
== language_cplus
))
451 fprintf_filtered (stream
, "void");
453 fprintf_filtered (stream
, ")");
456 /* Return true iff the j'th overloading of the i'th method of TYPE
457 is a type conversion operator, like `operator int () { ... }'.
458 When listing a class's methods, we don't print the return type of
462 is_type_conversion_operator (struct type
*type
, int i
, int j
)
464 /* I think the whole idea of recognizing type conversion operators
465 by their name is pretty terrible. But I don't think our present
466 data structure gives us any other way to tell. If you know of
467 some other way, feel free to rewrite this function. */
468 const char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
470 if (strncmp (name
, "operator", 8) != 0)
474 if (! strchr (" \t\f\n\r", *name
))
477 while (strchr (" \t\f\n\r", *name
))
480 if (!('a' <= *name
&& *name
<= 'z')
481 && !('A' <= *name
&& *name
<= 'Z')
483 /* If this doesn't look like the start of an identifier, then it
484 isn't a type conversion operator. */
486 else if (strncmp (name
, "new", 3) == 0)
488 else if (strncmp (name
, "delete", 6) == 0)
491 /* If it doesn't look like new or delete, it's a type conversion
495 /* Is that really the end of the name? */
496 if (('a' <= *name
&& *name
<= 'z')
497 || ('A' <= *name
&& *name
<= 'Z')
498 || ('0' <= *name
&& *name
<= '9')
500 /* No, so the identifier following "operator" must be a type name,
501 and this is a type conversion operator. */
504 /* That was indeed the end of the name, so it was `operator new' or
505 `operator delete', neither of which are type conversion
510 /* Given a C++ qualified identifier QID, strip off the qualifiers,
511 yielding the unqualified name. The return value is a pointer into
514 It's a pity we don't have this information in some more structured
515 form. Even the author of this function feels that writing little
516 parsers like this everywhere is stupid. */
519 remove_qualifiers (char *qid
)
521 int quoted
= 0; /* Zero if we're not in quotes;
522 '"' if we're in a double-quoted string;
523 '\'' if we're in a single-quoted string. */
524 int depth
= 0; /* Number of unclosed parens we've seen. */
525 char *parenstack
= (char *) alloca (strlen (qid
));
527 char *last
= 0; /* The character after the rightmost
528 `::' token we've seen so far. */
530 for (scan
= qid
; *scan
; scan
++)
536 else if (*scan
== '\\' && *(scan
+ 1))
539 else if (scan
[0] == ':' && scan
[1] == ':')
541 /* If we're inside parenthesis (i.e., an argument list) or
542 angle brackets (i.e., a list of template arguments), then
543 we don't record the position of this :: token, since it's
544 not relevant to the top-level structure we're trying to
552 else if (*scan
== '"' || *scan
== '\'')
554 else if (*scan
== '(')
555 parenstack
[depth
++] = ')';
556 else if (*scan
== '[')
557 parenstack
[depth
++] = ']';
558 /* We're going to treat <> as a pair of matching characters,
559 since we're more likely to see those in template id's than
560 real less-than characters. What a crock. */
561 else if (*scan
== '<')
562 parenstack
[depth
++] = '>';
563 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
565 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
569 /* We're going to do a little error recovery here. If
570 we don't find a match for *scan on the paren stack,
571 but there is something lower on the stack that does
572 match, we pop the stack to that point. */
575 for (i
= depth
- 1; i
>= 0; i
--)
576 if (parenstack
[i
] == *scan
)
588 /* We didn't find any :: tokens at the top level, so declare the
589 whole thing an unqualified identifier. */
593 /* Print any array sizes, function arguments or close parentheses
594 needed after the variable name (to describe its type).
595 Args work like c_type_print_varspec_prefix. */
598 c_type_print_varspec_suffix (struct type
*type
,
599 struct ui_file
*stream
,
600 int show
, int passed_a_ptr
,
606 if (TYPE_NAME (type
) && show
<= 0)
611 switch (TYPE_CODE (type
))
613 case TYPE_CODE_ARRAY
:
615 LONGEST low_bound
, high_bound
;
616 int is_vector
= TYPE_VECTOR (type
);
619 fprintf_filtered (stream
, ")");
621 fprintf_filtered (stream
, (is_vector
?
622 "__attribute__ ((vector_size(" : "["));
623 if (get_array_bounds (type
, &low_bound
, &high_bound
))
624 fprintf_filtered (stream
, "%d",
625 (int) (high_bound
- low_bound
+ 1));
626 fprintf_filtered (stream
, (is_vector
? ")))" : "]"));
628 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
633 case TYPE_CODE_MEMBERPTR
:
634 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
638 case TYPE_CODE_METHODPTR
:
639 fprintf_filtered (stream
, ")");
640 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
646 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
650 case TYPE_CODE_METHOD
:
653 fprintf_filtered (stream
, ")");
655 c_type_print_args (type
, stream
, 0, current_language
->la_language
);
656 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
657 show
, passed_a_ptr
, 0);
660 case TYPE_CODE_TYPEDEF
:
661 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
662 show
, passed_a_ptr
, 0);
665 case TYPE_CODE_UNDEF
:
666 case TYPE_CODE_STRUCT
:
667 case TYPE_CODE_UNION
:
672 case TYPE_CODE_ERROR
:
676 case TYPE_CODE_RANGE
:
677 case TYPE_CODE_STRING
:
678 case TYPE_CODE_COMPLEX
:
679 case TYPE_CODE_NAMESPACE
:
680 case TYPE_CODE_DECFLOAT
:
681 /* These types do not need a suffix. They are listed so that
682 gcc -Wall will report types that may not have been
686 error (_("type not handled in c_type_print_varspec_suffix()"));
691 /* Print the name of the type (or the ultimate pointer target,
692 function value or array element), or the description of a structure
695 SHOW positive means print details about the type (e.g. enum
696 values), and print structure elements passing SHOW - 1 for show.
698 SHOW negative means just print the type name or struct tag if there
699 is one. If there is no name, print something sensible but concise
702 SHOW zero means just print the type name or struct tag if there is
703 one. If there is no name, print something sensible but not as
704 concise like "struct {int x; int y;}".
706 LEVEL is the number of spaces to indent by.
707 We increase it for some recursive calls. */
710 c_type_print_base (struct type
*type
, struct ui_file
*stream
,
717 s_none
, s_public
, s_private
, s_protected
720 int need_access_label
= 0;
728 fputs_filtered (_("<type unknown>"), stream
);
732 /* When SHOW is zero or less, and there is a valid type name, then
733 always just print the type name directly from the type. */
734 /* If we have "typedef struct foo {. . .} bar;" do we want to print
735 it as "struct foo" or as "bar"? Pick the latter, because C++
736 folk tend to expect things like "class5 *foo" rather than "struct
740 && TYPE_NAME (type
) != NULL
)
742 c_type_print_modifier (type
, stream
, 0, 1);
743 fputs_filtered (TYPE_NAME (type
), stream
);
747 CHECK_TYPEDEF (type
);
749 switch (TYPE_CODE (type
))
751 case TYPE_CODE_TYPEDEF
:
752 /* If we get here, the typedef doesn't have a name, and we
753 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
754 gdb_assert (TYPE_NAME (type
) == NULL
);
755 gdb_assert (TYPE_TARGET_TYPE (type
) == NULL
);
756 fprintf_filtered (stream
, _("<unnamed typedef>"));
759 case TYPE_CODE_ARRAY
:
761 case TYPE_CODE_MEMBERPTR
:
764 case TYPE_CODE_METHOD
:
765 case TYPE_CODE_METHODPTR
:
766 c_type_print_base (TYPE_TARGET_TYPE (type
),
767 stream
, show
, level
);
770 case TYPE_CODE_STRUCT
:
771 c_type_print_modifier (type
, stream
, 0, 1);
772 if (TYPE_DECLARED_CLASS (type
))
773 fprintf_filtered (stream
, "class ");
775 fprintf_filtered (stream
, "struct ");
778 case TYPE_CODE_UNION
:
779 c_type_print_modifier (type
, stream
, 0, 1);
780 fprintf_filtered (stream
, "union ");
784 /* Print the tag if it exists. The HP aCC compiler emits a
785 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
786 enum}" tag for unnamed struct/union/enum's, which we don't
788 if (TYPE_TAG_NAME (type
) != NULL
789 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
791 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
793 fputs_filtered (" ", stream
);
798 /* If we just printed a tag name, no need to print anything
800 if (TYPE_TAG_NAME (type
) == NULL
)
801 fprintf_filtered (stream
, "{...}");
803 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
805 struct type
*basetype
;
808 cp_type_print_derivation_info (stream
, type
);
810 fprintf_filtered (stream
, "{\n");
811 if (TYPE_NFIELDS (type
) == 0 && TYPE_NFN_FIELDS (type
) == 0
812 && TYPE_TYPEDEF_FIELD_COUNT (type
) == 0)
814 if (TYPE_STUB (type
))
815 fprintfi_filtered (level
+ 4, stream
,
816 _("<incomplete type>\n"));
818 fprintfi_filtered (level
+ 4, stream
,
819 _("<no data fields>\n"));
822 /* Start off with no specific section type, so we can print
823 one for the first field we find, and use that section type
824 thereafter until we find another type. */
826 section_type
= s_none
;
828 /* For a class, if all members are private, there's no need
829 for a "private:" label; similarly, for a struct or union
830 masquerading as a class, if all members are public, there's
831 no need for a "public:" label. */
833 if (TYPE_DECLARED_CLASS (type
))
836 len
= TYPE_NFIELDS (type
);
837 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
838 if (!TYPE_FIELD_PRIVATE (type
, i
))
840 need_access_label
= 1;
844 if (!need_access_label
)
846 len2
= TYPE_NFN_FIELDS (type
);
847 for (j
= 0; j
< len2
; j
++)
849 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
850 for (i
= 0; i
< len
; i
++)
851 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
854 need_access_label
= 1;
857 if (need_access_label
)
865 len
= TYPE_NFIELDS (type
);
866 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
867 if (TYPE_FIELD_PRIVATE (type
, i
)
868 || TYPE_FIELD_PROTECTED (type
, i
))
870 need_access_label
= 1;
874 if (!need_access_label
)
876 len2
= TYPE_NFN_FIELDS (type
);
877 for (j
= 0; j
< len2
; j
++)
880 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
881 for (i
= 0; i
< len
; i
++)
882 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
,
884 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
888 need_access_label
= 1;
891 if (need_access_label
)
897 /* If there is a base class for this type,
898 do not print the field that it occupies. */
900 len
= TYPE_NFIELDS (type
);
901 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
902 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
906 /* If we have a virtual table pointer, omit it. Even if
907 virtual table pointers are not specifically marked in
908 the debug info, they should be artificial. */
909 if ((i
== vptr_fieldno
&& type
== basetype
)
910 || TYPE_FIELD_ARTIFICIAL (type
, i
))
913 if (need_access_label
)
915 if (TYPE_FIELD_PROTECTED (type
, i
))
917 if (section_type
!= s_protected
)
919 section_type
= s_protected
;
920 fprintfi_filtered (level
+ 2, stream
,
924 else if (TYPE_FIELD_PRIVATE (type
, i
))
926 if (section_type
!= s_private
)
928 section_type
= s_private
;
929 fprintfi_filtered (level
+ 2, stream
,
935 if (section_type
!= s_public
)
937 section_type
= s_public
;
938 fprintfi_filtered (level
+ 2, stream
,
944 print_spaces_filtered (level
+ 4, stream
);
945 if (field_is_static (&TYPE_FIELD (type
, i
)))
946 fprintf_filtered (stream
, "static ");
947 c_print_type (TYPE_FIELD_TYPE (type
, i
),
948 TYPE_FIELD_NAME (type
, i
),
949 stream
, show
- 1, level
+ 4);
950 if (!field_is_static (&TYPE_FIELD (type
, i
))
951 && TYPE_FIELD_PACKED (type
, i
))
953 /* It is a bitfield. This code does not attempt
954 to look at the bitpos and reconstruct filler,
955 unnamed fields. This would lead to misleading
956 results if the compiler does not put out fields
957 for such things (I don't know what it does). */
958 fprintf_filtered (stream
, " : %d",
959 TYPE_FIELD_BITSIZE (type
, i
));
961 fprintf_filtered (stream
, ";\n");
964 /* If there are both fields and methods, put a blank line
965 between them. Make sure to count only method that we
966 will display; artificial methods will be hidden. */
967 len
= TYPE_NFN_FIELDS (type
);
969 for (i
= 0; i
< len
; i
++)
971 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
972 int len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
975 for (j
= 0; j
< len2
; j
++)
976 if (!TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
979 if (real_len
> 0 && section_type
!= s_none
)
980 fprintf_filtered (stream
, "\n");
982 /* C++: print out the methods. */
983 for (i
= 0; i
< len
; i
++)
985 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
986 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
987 const char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
988 const char *name
= type_name_no_tag (type
);
989 int is_constructor
= name
&& strcmp (method_name
,
992 for (j
= 0; j
< len2
; j
++)
994 const char *mangled_name
;
995 char *demangled_name
;
996 struct cleanup
*inner_cleanup
;
997 const char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
998 int is_full_physname_constructor
=
999 is_constructor_name (physname
)
1000 || is_destructor_name (physname
)
1001 || method_name
[0] == '~';
1003 /* Do not print out artificial methods. */
1004 if (TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1007 inner_cleanup
= make_cleanup (null_cleanup
, NULL
);
1010 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
1012 if (section_type
!= s_protected
)
1014 section_type
= s_protected
;
1015 fprintfi_filtered (level
+ 2, stream
,
1019 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
1021 if (section_type
!= s_private
)
1023 section_type
= s_private
;
1024 fprintfi_filtered (level
+ 2, stream
,
1030 if (section_type
!= s_public
)
1032 section_type
= s_public
;
1033 fprintfi_filtered (level
+ 2, stream
,
1038 print_spaces_filtered (level
+ 4, stream
);
1039 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1040 fprintf_filtered (stream
, "virtual ");
1041 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1042 fprintf_filtered (stream
, "static ");
1043 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1045 /* Keep GDB from crashing here. */
1046 fprintf_filtered (stream
,
1047 _("<undefined type> %s;\n"),
1048 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1051 else if (!is_constructor
/* Constructors don't
1054 && !is_full_physname_constructor
/* " " */
1055 && !is_type_conversion_operator (type
, i
, j
))
1057 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1059 fputs_filtered (" ", stream
);
1061 if (TYPE_FN_FIELD_STUB (f
, j
))
1065 /* Build something we can demangle. */
1066 tem
= gdb_mangle_name (type
, i
, j
);
1067 make_cleanup (xfree
, tem
);
1071 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1074 cplus_demangle (mangled_name
,
1075 DMGL_ANSI
| DMGL_PARAMS
);
1076 if (demangled_name
== NULL
)
1078 /* In some cases (for instance with the HP
1079 demangling), if a function has more than 10
1080 arguments, the demangling will fail.
1081 Let's try to reconstruct the function
1082 signature from the symbol information. */
1083 if (!TYPE_FN_FIELD_STUB (f
, j
))
1085 int staticp
= TYPE_FN_FIELD_STATIC_P (f
, j
);
1086 struct type
*mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
1088 cp_type_print_method_args (mtype
,
1095 fprintf_filtered (stream
,
1096 _("<badly mangled name '%s'>"),
1102 char *demangled_no_class
1103 = remove_qualifiers (demangled_name
);
1105 /* Get rid of the `static' appended by the
1107 p
= strstr (demangled_no_class
, " static");
1110 int length
= p
- demangled_no_class
;
1111 char *demangled_no_static
;
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 do_cleanups (inner_cleanup
);
1128 fprintf_filtered (stream
, ";\n");
1132 /* Print typedefs defined in this class. */
1134 if (TYPE_TYPEDEF_FIELD_COUNT (type
) != 0)
1136 if (TYPE_NFIELDS (type
) != 0 || TYPE_NFN_FIELDS (type
) != 0)
1137 fprintf_filtered (stream
, "\n");
1139 for (i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); i
++)
1141 struct type
*target
= TYPE_TYPEDEF_FIELD_TYPE (type
, i
);
1143 /* Dereference the typedef declaration itself. */
1144 gdb_assert (TYPE_CODE (target
) == TYPE_CODE_TYPEDEF
);
1145 target
= TYPE_TARGET_TYPE (target
);
1147 print_spaces_filtered (level
+ 4, stream
);
1148 fprintf_filtered (stream
, "typedef ");
1149 c_print_type (target
, TYPE_TYPEDEF_FIELD_NAME (type
, i
),
1150 stream
, show
- 1, level
+ 4);
1151 fprintf_filtered (stream
, ";\n");
1155 fprintfi_filtered (level
, stream
, "}");
1157 if (TYPE_LOCALTYPE_PTR (type
) && show
>= 0)
1158 fprintfi_filtered (level
,
1159 stream
, _(" (Local at %s:%d)\n"),
1160 TYPE_LOCALTYPE_FILE (type
),
1161 TYPE_LOCALTYPE_LINE (type
));
1165 case TYPE_CODE_ENUM
:
1166 c_type_print_modifier (type
, stream
, 0, 1);
1167 fprintf_filtered (stream
, "enum ");
1168 /* Print the tag name if it exists.
1169 The aCC compiler emits a spurious
1170 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1171 tag for unnamed struct/union/enum's, which we don't
1173 if (TYPE_TAG_NAME (type
) != NULL
1174 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
1176 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1178 fputs_filtered (" ", stream
);
1184 /* If we just printed a tag name, no need to print anything
1186 if (TYPE_TAG_NAME (type
) == NULL
)
1187 fprintf_filtered (stream
, "{...}");
1189 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
1191 LONGEST lastval
= 0;
1193 fprintf_filtered (stream
, "{");
1194 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_ENUMVAL (type
, i
))
1204 fprintf_filtered (stream
, " = %s",
1205 plongest (TYPE_FIELD_ENUMVAL (type
, i
)));
1206 lastval
= TYPE_FIELD_ENUMVAL (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>"),