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 && !TYPE_VECTOR (type
))
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. */
138 cp_type_print_derivation_info (struct ui_file
*stream
,
144 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
146 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
147 fprintf_filtered (stream
, "%s%s ",
148 BASETYPE_VIA_PUBLIC (type
, i
)
149 ? "public" : (TYPE_FIELD_PROTECTED (type
, i
)
150 ? "protected" : "private"),
151 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
152 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
153 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
157 fputs_filtered (" ", stream
);
161 /* Print the C++ method arguments ARGS to the file STREAM. */
164 cp_type_print_method_args (struct type
*mtype
, const char *prefix
,
165 const char *varstring
, int staticp
,
166 struct ui_file
*stream
)
168 struct field
*args
= TYPE_FIELDS (mtype
);
169 int nargs
= TYPE_NFIELDS (mtype
);
170 int varargs
= TYPE_VARARGS (mtype
);
173 fprintf_symbol_filtered (stream
, prefix
,
174 language_cplus
, DMGL_ANSI
);
175 fprintf_symbol_filtered (stream
, varstring
,
176 language_cplus
, DMGL_ANSI
);
177 fputs_filtered ("(", stream
);
179 /* Skip the class variable. */
185 type_print (args
[i
++].type
, "", stream
, 0);
187 if (i
== nargs
&& varargs
)
188 fprintf_filtered (stream
, ", ...");
190 fprintf_filtered (stream
, ", ");
194 fprintf_filtered (stream
, "...");
195 else if (current_language
->la_language
== language_cplus
)
196 fprintf_filtered (stream
, "void");
198 fprintf_filtered (stream
, ")");
200 /* For non-static methods, read qualifiers from the type of
206 gdb_assert (nargs
> 0);
207 gdb_assert (TYPE_CODE (args
[0].type
) == TYPE_CODE_PTR
);
208 domain
= TYPE_TARGET_TYPE (args
[0].type
);
210 if (TYPE_CONST (domain
))
211 fprintf_filtered (stream
, " const");
213 if (TYPE_VOLATILE (domain
))
214 fprintf_filtered (stream
, " volatile");
219 /* Print any asterisks or open-parentheses needed before the
220 variable name (to describe its type).
222 On outermost call, pass 0 for PASSED_A_PTR.
223 On outermost call, SHOW > 0 means should ignore
224 any typename for TYPE and show its details.
225 SHOW is always zero on recursive calls.
227 NEED_POST_SPACE is non-zero when a space will be be needed
228 between a trailing qualifier and a field, variable, or function
232 c_type_print_varspec_prefix (struct type
*type
,
233 struct ui_file
*stream
,
234 int show
, int passed_a_ptr
,
242 if (TYPE_NAME (type
) && show
<= 0)
247 switch (TYPE_CODE (type
))
250 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
252 fprintf_filtered (stream
, "*");
253 c_type_print_modifier (type
, stream
, 1, need_post_space
);
256 case TYPE_CODE_MEMBERPTR
:
257 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
259 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
261 fputs_filtered (name
, stream
);
263 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
264 stream
, -1, passed_a_ptr
);
265 fprintf_filtered (stream
, "::*");
268 case TYPE_CODE_METHODPTR
:
269 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
271 fprintf_filtered (stream
, "(");
272 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
274 fputs_filtered (name
, stream
);
276 c_type_print_base (TYPE_DOMAIN_TYPE (type
),
277 stream
, -1, passed_a_ptr
);
278 fprintf_filtered (stream
, "::*");
282 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
284 fprintf_filtered (stream
, "&");
285 c_type_print_modifier (type
, stream
, 1, need_post_space
);
288 case TYPE_CODE_METHOD
:
290 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
293 fprintf_filtered (stream
, "(");
296 case TYPE_CODE_ARRAY
:
297 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
300 fprintf_filtered (stream
, "(");
303 case TYPE_CODE_TYPEDEF
:
304 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
305 stream
, show
, passed_a_ptr
, 0);
308 case TYPE_CODE_UNDEF
:
309 case TYPE_CODE_STRUCT
:
310 case TYPE_CODE_UNION
:
315 case TYPE_CODE_ERROR
:
319 case TYPE_CODE_RANGE
:
320 case TYPE_CODE_STRING
:
321 case TYPE_CODE_COMPLEX
:
322 case TYPE_CODE_NAMESPACE
:
323 case TYPE_CODE_DECFLOAT
:
324 /* These types need no prefix. They are listed here so that
325 gcc -Wall will reveal any types that haven't been handled. */
328 error (_("type not handled in c_type_print_varspec_prefix()"));
333 /* Print out "const" and "volatile" attributes,
334 and address space id if present.
335 TYPE is a pointer to the type being printed out.
336 STREAM is the output destination.
337 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
338 NEED_POST_SPACE = 1 indicates a final white space is needed. */
341 c_type_print_modifier (struct type
*type
, struct ui_file
*stream
,
342 int need_pre_space
, int need_post_space
)
344 int did_print_modifier
= 0;
345 const char *address_space_id
;
347 /* We don't print `const' qualifiers for references --- since all
348 operators affect the thing referenced, not the reference itself,
349 every reference is `const'. */
350 if (TYPE_CONST (type
)
351 && TYPE_CODE (type
) != TYPE_CODE_REF
)
354 fprintf_filtered (stream
, " ");
355 fprintf_filtered (stream
, "const");
356 did_print_modifier
= 1;
359 if (TYPE_VOLATILE (type
))
361 if (did_print_modifier
|| need_pre_space
)
362 fprintf_filtered (stream
, " ");
363 fprintf_filtered (stream
, "volatile");
364 did_print_modifier
= 1;
367 address_space_id
= address_space_int_to_name (get_type_arch (type
),
368 TYPE_INSTANCE_FLAGS (type
));
369 if (address_space_id
)
371 if (did_print_modifier
|| need_pre_space
)
372 fprintf_filtered (stream
, " ");
373 fprintf_filtered (stream
, "@%s", address_space_id
);
374 did_print_modifier
= 1;
377 if (did_print_modifier
&& need_post_space
)
378 fprintf_filtered (stream
, " ");
382 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
383 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
384 in non-static methods, are displayed if LINKAGE_NAME is zero. If
385 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
386 parameter types get removed their possible const and volatile qualifiers to
387 match demangled linkage name parameters part of such function type.
388 LANGUAGE is the language in which TYPE was defined. This is a necessary
389 evil since this code is used by the C, C++, and Java backends. */
392 c_type_print_args (struct type
*type
, struct ui_file
*stream
,
393 int linkage_name
, enum language language
)
399 fprintf_filtered (stream
, "(");
400 args
= TYPE_FIELDS (type
);
401 len
= TYPE_NFIELDS (type
);
403 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
405 struct type
*param_type
;
407 if (TYPE_FIELD_ARTIFICIAL (type
, i
) && linkage_name
)
412 fprintf_filtered (stream
, ", ");
416 param_type
= TYPE_FIELD_TYPE (type
, i
);
418 if (language
== language_cplus
&& linkage_name
)
420 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
421 - Parameter declarations that differ only in the presence or
422 absence of const and/or volatile are equivalent.
424 And the const/volatile qualifiers are not present in the mangled
425 names as produced by GCC. */
427 param_type
= make_cv_type (0, 0, param_type
, NULL
);
430 if (language
== language_java
)
431 java_print_type (param_type
, "", stream
, -1, 0);
433 c_print_type (param_type
, "", stream
, -1, 0);
437 if (printed_any
&& TYPE_VARARGS (type
))
439 /* Print out a trailing ellipsis for varargs functions. Ignore
440 TYPE_VARARGS if the function has no named arguments; that
441 represents unprototyped (K&R style) C functions. */
442 if (printed_any
&& TYPE_VARARGS (type
))
444 fprintf_filtered (stream
, ", ");
446 fprintf_filtered (stream
, "...");
449 else if (!printed_any
450 && ((TYPE_PROTOTYPED (type
) && language
!= language_java
)
451 || language
== language_cplus
))
452 fprintf_filtered (stream
, "void");
454 fprintf_filtered (stream
, ")");
457 /* Return true iff the j'th overloading of the i'th method of TYPE
458 is a type conversion operator, like `operator int () { ... }'.
459 When listing a class's methods, we don't print the return type of
463 is_type_conversion_operator (struct type
*type
, int i
, int j
)
465 /* I think the whole idea of recognizing type conversion operators
466 by their name is pretty terrible. But I don't think our present
467 data structure gives us any other way to tell. If you know of
468 some other way, feel free to rewrite this function. */
469 const char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
471 if (strncmp (name
, "operator", 8) != 0)
475 if (! strchr (" \t\f\n\r", *name
))
478 while (strchr (" \t\f\n\r", *name
))
481 if (!('a' <= *name
&& *name
<= 'z')
482 && !('A' <= *name
&& *name
<= 'Z')
484 /* If this doesn't look like the start of an identifier, then it
485 isn't a type conversion operator. */
487 else if (strncmp (name
, "new", 3) == 0)
489 else if (strncmp (name
, "delete", 6) == 0)
492 /* If it doesn't look like new or delete, it's a type conversion
496 /* Is that really the end of the name? */
497 if (('a' <= *name
&& *name
<= 'z')
498 || ('A' <= *name
&& *name
<= 'Z')
499 || ('0' <= *name
&& *name
<= '9')
501 /* No, so the identifier following "operator" must be a type name,
502 and this is a type conversion operator. */
505 /* That was indeed the end of the name, so it was `operator new' or
506 `operator delete', neither of which are type conversion
511 /* Given a C++ qualified identifier QID, strip off the qualifiers,
512 yielding the unqualified name. The return value is a pointer into
515 It's a pity we don't have this information in some more structured
516 form. Even the author of this function feels that writing little
517 parsers like this everywhere is stupid. */
520 remove_qualifiers (char *qid
)
522 int quoted
= 0; /* Zero if we're not in quotes;
523 '"' if we're in a double-quoted string;
524 '\'' if we're in a single-quoted string. */
525 int depth
= 0; /* Number of unclosed parens we've seen. */
526 char *parenstack
= (char *) alloca (strlen (qid
));
528 char *last
= 0; /* The character after the rightmost
529 `::' token we've seen so far. */
531 for (scan
= qid
; *scan
; scan
++)
537 else if (*scan
== '\\' && *(scan
+ 1))
540 else if (scan
[0] == ':' && scan
[1] == ':')
542 /* If we're inside parenthesis (i.e., an argument list) or
543 angle brackets (i.e., a list of template arguments), then
544 we don't record the position of this :: token, since it's
545 not relevant to the top-level structure we're trying to
553 else if (*scan
== '"' || *scan
== '\'')
555 else if (*scan
== '(')
556 parenstack
[depth
++] = ')';
557 else if (*scan
== '[')
558 parenstack
[depth
++] = ']';
559 /* We're going to treat <> as a pair of matching characters,
560 since we're more likely to see those in template id's than
561 real less-than characters. What a crock. */
562 else if (*scan
== '<')
563 parenstack
[depth
++] = '>';
564 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
566 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
570 /* We're going to do a little error recovery here. If
571 we don't find a match for *scan on the paren stack,
572 but there is something lower on the stack that does
573 match, we pop the stack to that point. */
576 for (i
= depth
- 1; i
>= 0; i
--)
577 if (parenstack
[i
] == *scan
)
589 /* We didn't find any :: tokens at the top level, so declare the
590 whole thing an unqualified identifier. */
594 /* Print any array sizes, function arguments or close parentheses
595 needed after the variable name (to describe its type).
596 Args work like c_type_print_varspec_prefix. */
599 c_type_print_varspec_suffix (struct type
*type
,
600 struct ui_file
*stream
,
601 int show
, int passed_a_ptr
,
607 if (TYPE_NAME (type
) && show
<= 0)
612 switch (TYPE_CODE (type
))
614 case TYPE_CODE_ARRAY
:
616 LONGEST low_bound
, high_bound
;
617 int is_vector
= TYPE_VECTOR (type
);
620 fprintf_filtered (stream
, ")");
622 fprintf_filtered (stream
, (is_vector
?
623 " __attribute__ ((vector_size(" : "["));
624 if (get_array_bounds (type
, &low_bound
, &high_bound
))
625 fprintf_filtered (stream
, "%s",
626 plongest (high_bound
- low_bound
+ 1));
627 fprintf_filtered (stream
, (is_vector
? ")))" : "]"));
629 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
634 case TYPE_CODE_MEMBERPTR
:
635 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
639 case TYPE_CODE_METHODPTR
:
640 fprintf_filtered (stream
, ")");
641 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
647 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
651 case TYPE_CODE_METHOD
:
654 fprintf_filtered (stream
, ")");
656 c_type_print_args (type
, stream
, 0, current_language
->la_language
);
657 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
658 show
, passed_a_ptr
, 0);
661 case TYPE_CODE_TYPEDEF
:
662 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
663 show
, passed_a_ptr
, 0);
666 case TYPE_CODE_UNDEF
:
667 case TYPE_CODE_STRUCT
:
668 case TYPE_CODE_UNION
:
673 case TYPE_CODE_ERROR
:
677 case TYPE_CODE_RANGE
:
678 case TYPE_CODE_STRING
:
679 case TYPE_CODE_COMPLEX
:
680 case TYPE_CODE_NAMESPACE
:
681 case TYPE_CODE_DECFLOAT
:
682 /* These types do not need a suffix. They are listed so that
683 gcc -Wall will report types that may not have been
687 error (_("type not handled in c_type_print_varspec_suffix()"));
692 /* Print the name of the type (or the ultimate pointer target,
693 function value or array element), or the description of a structure
696 SHOW positive means print details about the type (e.g. enum
697 values), and print structure elements passing SHOW - 1 for show.
699 SHOW negative means just print the type name or struct tag if there
700 is one. If there is no name, print something sensible but concise
703 SHOW zero means just print the type name or struct tag if there is
704 one. If there is no name, print something sensible but not as
705 concise like "struct {int x; int y;}".
707 LEVEL is the number of spaces to indent by.
708 We increase it for some recursive calls. */
711 c_type_print_base (struct type
*type
, struct ui_file
*stream
,
718 s_none
, s_public
, s_private
, s_protected
721 int need_access_label
= 0;
729 fputs_filtered (_("<type unknown>"), stream
);
733 /* When SHOW is zero or less, and there is a valid type name, then
734 always just print the type name directly from the type. */
735 /* If we have "typedef struct foo {. . .} bar;" do we want to print
736 it as "struct foo" or as "bar"? Pick the latter, because C++
737 folk tend to expect things like "class5 *foo" rather than "struct
741 && TYPE_NAME (type
) != NULL
)
743 c_type_print_modifier (type
, stream
, 0, 1);
744 fputs_filtered (TYPE_NAME (type
), stream
);
748 CHECK_TYPEDEF (type
);
750 switch (TYPE_CODE (type
))
752 case TYPE_CODE_TYPEDEF
:
753 /* If we get here, the typedef doesn't have a name, and we
754 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
755 gdb_assert (TYPE_NAME (type
) == NULL
);
756 gdb_assert (TYPE_TARGET_TYPE (type
) == NULL
);
757 fprintf_filtered (stream
, _("<unnamed typedef>"));
760 case TYPE_CODE_ARRAY
:
762 case TYPE_CODE_MEMBERPTR
:
765 case TYPE_CODE_METHOD
:
766 case TYPE_CODE_METHODPTR
:
767 c_type_print_base (TYPE_TARGET_TYPE (type
),
768 stream
, show
, level
);
771 case TYPE_CODE_STRUCT
:
772 case TYPE_CODE_UNION
:
773 c_type_print_modifier (type
, stream
, 0, 1);
774 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
775 fprintf_filtered (stream
, "union ");
776 else if (TYPE_DECLARED_CLASS (type
))
777 fprintf_filtered (stream
, "class ");
779 fprintf_filtered (stream
, "struct ");
781 /* Print the tag if it exists. The HP aCC compiler emits a
782 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
783 enum}" tag for unnamed struct/union/enum's, which we don't
785 if (TYPE_TAG_NAME (type
) != NULL
786 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
788 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
790 fputs_filtered (" ", stream
);
795 /* If we just printed a tag name, no need to print anything
797 if (TYPE_TAG_NAME (type
) == NULL
)
798 fprintf_filtered (stream
, "{...}");
800 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
802 struct type
*basetype
;
805 cp_type_print_derivation_info (stream
, type
);
807 fprintf_filtered (stream
, "{\n");
808 if (TYPE_NFIELDS (type
) == 0 && TYPE_NFN_FIELDS (type
) == 0
809 && TYPE_TYPEDEF_FIELD_COUNT (type
) == 0)
811 if (TYPE_STUB (type
))
812 fprintfi_filtered (level
+ 4, stream
,
813 _("<incomplete type>\n"));
815 fprintfi_filtered (level
+ 4, stream
,
816 _("<no data fields>\n"));
819 /* Start off with no specific section type, so we can print
820 one for the first field we find, and use that section type
821 thereafter until we find another type. */
823 section_type
= s_none
;
825 /* For a class, if all members are private, there's no need
826 for a "private:" label; similarly, for a struct or union
827 masquerading as a class, if all members are public, there's
828 no need for a "public:" label. */
830 if (TYPE_DECLARED_CLASS (type
))
833 len
= TYPE_NFIELDS (type
);
834 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
835 if (!TYPE_FIELD_PRIVATE (type
, i
))
837 need_access_label
= 1;
841 if (!need_access_label
)
843 len2
= TYPE_NFN_FIELDS (type
);
844 for (j
= 0; j
< len2
; j
++)
846 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
847 for (i
= 0; i
< len
; i
++)
848 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
851 need_access_label
= 1;
854 if (need_access_label
)
862 len
= TYPE_NFIELDS (type
);
863 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
864 if (TYPE_FIELD_PRIVATE (type
, i
)
865 || TYPE_FIELD_PROTECTED (type
, i
))
867 need_access_label
= 1;
871 if (!need_access_label
)
873 len2
= TYPE_NFN_FIELDS (type
);
874 for (j
= 0; j
< len2
; j
++)
877 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
878 for (i
= 0; i
< len
; i
++)
879 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
,
881 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
885 need_access_label
= 1;
888 if (need_access_label
)
894 /* If there is a base class for this type,
895 do not print the field that it occupies. */
897 len
= TYPE_NFIELDS (type
);
898 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
899 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
903 /* If we have a virtual table pointer, omit it. Even if
904 virtual table pointers are not specifically marked in
905 the debug info, they should be artificial. */
906 if ((i
== vptr_fieldno
&& type
== basetype
)
907 || TYPE_FIELD_ARTIFICIAL (type
, i
))
910 if (need_access_label
)
912 if (TYPE_FIELD_PROTECTED (type
, i
))
914 if (section_type
!= s_protected
)
916 section_type
= s_protected
;
917 fprintfi_filtered (level
+ 2, stream
,
921 else if (TYPE_FIELD_PRIVATE (type
, i
))
923 if (section_type
!= s_private
)
925 section_type
= s_private
;
926 fprintfi_filtered (level
+ 2, stream
,
932 if (section_type
!= s_public
)
934 section_type
= s_public
;
935 fprintfi_filtered (level
+ 2, stream
,
941 print_spaces_filtered (level
+ 4, stream
);
942 if (field_is_static (&TYPE_FIELD (type
, i
)))
943 fprintf_filtered (stream
, "static ");
944 c_print_type (TYPE_FIELD_TYPE (type
, i
),
945 TYPE_FIELD_NAME (type
, i
),
946 stream
, show
- 1, level
+ 4);
947 if (!field_is_static (&TYPE_FIELD (type
, i
))
948 && TYPE_FIELD_PACKED (type
, i
))
950 /* It is a bitfield. This code does not attempt
951 to look at the bitpos and reconstruct filler,
952 unnamed fields. This would lead to misleading
953 results if the compiler does not put out fields
954 for such things (I don't know what it does). */
955 fprintf_filtered (stream
, " : %d",
956 TYPE_FIELD_BITSIZE (type
, i
));
958 fprintf_filtered (stream
, ";\n");
961 /* If there are both fields and methods, put a blank line
962 between them. Make sure to count only method that we
963 will display; artificial methods will be hidden. */
964 len
= TYPE_NFN_FIELDS (type
);
966 for (i
= 0; i
< len
; i
++)
968 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
969 int len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
972 for (j
= 0; j
< len2
; j
++)
973 if (!TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
976 if (real_len
> 0 && section_type
!= s_none
)
977 fprintf_filtered (stream
, "\n");
979 /* C++: print out the methods. */
980 for (i
= 0; i
< len
; i
++)
982 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
983 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
984 const char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
985 const char *name
= type_name_no_tag (type
);
986 int is_constructor
= name
&& strcmp (method_name
,
989 for (j
= 0; j
< len2
; j
++)
991 const char *mangled_name
;
992 char *demangled_name
;
993 struct cleanup
*inner_cleanup
;
994 const char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
995 int is_full_physname_constructor
=
996 is_constructor_name (physname
)
997 || is_destructor_name (physname
)
998 || method_name
[0] == '~';
1000 /* Do not print out artificial methods. */
1001 if (TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1004 inner_cleanup
= make_cleanup (null_cleanup
, NULL
);
1007 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
1009 if (section_type
!= s_protected
)
1011 section_type
= s_protected
;
1012 fprintfi_filtered (level
+ 2, stream
,
1016 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
1018 if (section_type
!= s_private
)
1020 section_type
= s_private
;
1021 fprintfi_filtered (level
+ 2, stream
,
1027 if (section_type
!= s_public
)
1029 section_type
= s_public
;
1030 fprintfi_filtered (level
+ 2, stream
,
1035 print_spaces_filtered (level
+ 4, stream
);
1036 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1037 fprintf_filtered (stream
, "virtual ");
1038 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1039 fprintf_filtered (stream
, "static ");
1040 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1042 /* Keep GDB from crashing here. */
1043 fprintf_filtered (stream
,
1044 _("<undefined type> %s;\n"),
1045 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1048 else if (!is_constructor
/* Constructors don't
1051 && !is_full_physname_constructor
/* " " */
1052 && !is_type_conversion_operator (type
, i
, j
))
1054 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1056 fputs_filtered (" ", stream
);
1058 if (TYPE_FN_FIELD_STUB (f
, j
))
1062 /* Build something we can demangle. */
1063 tem
= gdb_mangle_name (type
, i
, j
);
1064 make_cleanup (xfree
, tem
);
1068 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1071 cplus_demangle (mangled_name
,
1072 DMGL_ANSI
| DMGL_PARAMS
);
1073 if (demangled_name
== NULL
)
1075 /* In some cases (for instance with the HP
1076 demangling), if a function has more than 10
1077 arguments, the demangling will fail.
1078 Let's try to reconstruct the function
1079 signature from the symbol information. */
1080 if (!TYPE_FN_FIELD_STUB (f
, j
))
1082 int staticp
= TYPE_FN_FIELD_STATIC_P (f
, j
);
1083 struct type
*mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
1085 cp_type_print_method_args (mtype
,
1092 fprintf_filtered (stream
,
1093 _("<badly mangled name '%s'>"),
1099 char *demangled_no_class
1100 = remove_qualifiers (demangled_name
);
1102 /* Get rid of the `static' appended by the
1104 p
= strstr (demangled_no_class
, " static");
1107 int length
= p
- demangled_no_class
;
1108 char *demangled_no_static
;
1111 = (char *) xmalloc (length
+ 1);
1112 strncpy (demangled_no_static
,
1113 demangled_no_class
, length
);
1114 *(demangled_no_static
+ length
) = '\0';
1115 fputs_filtered (demangled_no_static
, stream
);
1116 xfree (demangled_no_static
);
1119 fputs_filtered (demangled_no_class
, stream
);
1120 xfree (demangled_name
);
1123 do_cleanups (inner_cleanup
);
1125 fprintf_filtered (stream
, ";\n");
1129 /* Print typedefs defined in this class. */
1131 if (TYPE_TYPEDEF_FIELD_COUNT (type
) != 0)
1133 if (TYPE_NFIELDS (type
) != 0 || TYPE_NFN_FIELDS (type
) != 0)
1134 fprintf_filtered (stream
, "\n");
1136 for (i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); i
++)
1138 struct type
*target
= TYPE_TYPEDEF_FIELD_TYPE (type
, i
);
1140 /* Dereference the typedef declaration itself. */
1141 gdb_assert (TYPE_CODE (target
) == TYPE_CODE_TYPEDEF
);
1142 target
= TYPE_TARGET_TYPE (target
);
1144 print_spaces_filtered (level
+ 4, stream
);
1145 fprintf_filtered (stream
, "typedef ");
1146 c_print_type (target
, TYPE_TYPEDEF_FIELD_NAME (type
, i
),
1147 stream
, show
- 1, level
+ 4);
1148 fprintf_filtered (stream
, ";\n");
1152 fprintfi_filtered (level
, stream
, "}");
1154 if (TYPE_LOCALTYPE_PTR (type
) && show
>= 0)
1155 fprintfi_filtered (level
,
1156 stream
, _(" (Local at %s:%d)\n"),
1157 TYPE_LOCALTYPE_FILE (type
),
1158 TYPE_LOCALTYPE_LINE (type
));
1162 case TYPE_CODE_ENUM
:
1163 c_type_print_modifier (type
, stream
, 0, 1);
1164 fprintf_filtered (stream
, "enum ");
1165 /* Print the tag name if it exists.
1166 The aCC compiler emits a spurious
1167 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1168 tag for unnamed struct/union/enum's, which we don't
1170 if (TYPE_TAG_NAME (type
) != NULL
1171 && strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
1173 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1175 fputs_filtered (" ", stream
);
1181 /* If we just printed a tag name, no need to print anything
1183 if (TYPE_TAG_NAME (type
) == NULL
)
1184 fprintf_filtered (stream
, "{...}");
1186 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
1188 LONGEST lastval
= 0;
1190 fprintf_filtered (stream
, "{");
1191 len
= TYPE_NFIELDS (type
);
1192 for (i
= 0; i
< len
; i
++)
1196 fprintf_filtered (stream
, ", ");
1198 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1199 if (lastval
!= TYPE_FIELD_ENUMVAL (type
, i
))
1201 fprintf_filtered (stream
, " = %s",
1202 plongest (TYPE_FIELD_ENUMVAL (type
, i
)));
1203 lastval
= TYPE_FIELD_ENUMVAL (type
, i
);
1207 fprintf_filtered (stream
, "}");
1211 case TYPE_CODE_VOID
:
1212 fprintf_filtered (stream
, "void");
1215 case TYPE_CODE_UNDEF
:
1216 fprintf_filtered (stream
, _("struct <unknown>"));
1219 case TYPE_CODE_ERROR
:
1220 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
1223 case TYPE_CODE_RANGE
:
1224 /* This should not occur. */
1225 fprintf_filtered (stream
, _("<range type>"));
1228 case TYPE_CODE_NAMESPACE
:
1229 fputs_filtered ("namespace ", stream
);
1230 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1234 /* Handle types not explicitly handled by the other cases, such
1235 as fundamental types. For these, just print whatever the
1236 type name is, as recorded in the type itself. If there is no
1237 type name, then complain. */
1238 if (TYPE_NAME (type
) != NULL
)
1240 c_type_print_modifier (type
, stream
, 0, 1);
1241 fputs_filtered (TYPE_NAME (type
), stream
);
1245 /* At least for dump_symtab, it is important that this not
1247 fprintf_filtered (stream
, _("<invalid type code %d>"),