Commit | Line | Data |
---|---|---|
a8a69e63 FF |
1 | /* Support for printing C and C++ types for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "obstack.h" | |
22 | #include "bfd.h" /* Binary File Description */ | |
23 | #include "symtab.h" | |
24 | #include "gdbtypes.h" | |
25 | #include "expression.h" | |
26 | #include "value.h" | |
27 | #include "gdbcore.h" | |
28 | #include "target.h" | |
29 | #include "command.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "language.h" | |
32 | #include "demangle.h" | |
33 | #include "c-lang.h" | |
34 | #include "typeprint.h" | |
35 | ||
36 | #include <string.h> | |
37 | #include <errno.h> | |
38 | ||
a8a69e63 | 39 | static void |
199b2450 | 40 | c_type_print_args PARAMS ((struct type *, GDB_FILE *)); |
a8a69e63 FF |
41 | |
42 | static void | |
199b2450 | 43 | c_type_print_varspec_suffix PARAMS ((struct type *, GDB_FILE *, int, int, int)); |
a8a69e63 FF |
44 | |
45 | static void | |
199b2450 | 46 | cp_type_print_derivation_info PARAMS ((GDB_FILE *, struct type *)); |
a8a69e63 FF |
47 | |
48 | void | |
199b2450 | 49 | c_type_print_varspec_prefix PARAMS ((struct type *, GDB_FILE *, int, int)); |
a8a69e63 FF |
50 | |
51 | void | |
199b2450 | 52 | c_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int)); |
a8a69e63 FF |
53 | |
54 | \f | |
55 | /* Print a description of a type in the format of a | |
56 | typedef for the current language. | |
57 | NEW is the new name for a type TYPE. */ | |
58 | ||
59 | void | |
60 | c_typedef_print (type, new, stream) | |
61 | struct type *type; | |
62 | struct symbol *new; | |
199b2450 | 63 | GDB_FILE *stream; |
a8a69e63 FF |
64 | { |
65 | switch (current_language->la_language) | |
66 | { | |
67 | #ifdef _LANG_c | |
68 | case language_c: | |
69 | case language_cplus: | |
70 | fprintf_filtered(stream, "typedef "); | |
71 | type_print(type,"",stream,0); | |
72 | if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0 | |
2e4964ad FF |
73 | || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new))) |
74 | fprintf_filtered(stream, " %s", SYMBOL_SOURCE_NAME(new)); | |
a8a69e63 FF |
75 | break; |
76 | #endif | |
77 | #ifdef _LANG_m2 | |
78 | case language_m2: | |
79 | fprintf_filtered(stream, "TYPE "); | |
80 | if(!TYPE_NAME(SYMBOL_TYPE(new)) || | |
2e4964ad FF |
81 | !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new))) |
82 | fprintf_filtered(stream, "%s = ", SYMBOL_SOURCE_NAME(new)); | |
a8a69e63 FF |
83 | else |
84 | fprintf_filtered(stream, "<builtin> = "); | |
85 | type_print(type,"",stream,0); | |
86 | break; | |
87 | #endif | |
a8a69e63 FF |
88 | #ifdef _LANG_chill |
89 | case language_chill: | |
90 | error ("Missing Chill support in function c_typedef_print."); /*FIXME*/ | |
91 | #endif | |
a8a69e63 FF |
92 | default: |
93 | error("Language not supported."); | |
94 | } | |
95 | fprintf_filtered(stream, ";\n"); | |
96 | } | |
97 | ||
98 | ||
99 | /* LEVEL is the depth to indent lines by. */ | |
100 | ||
101 | void | |
102 | c_print_type (type, varstring, stream, show, level) | |
103 | struct type *type; | |
104 | char *varstring; | |
199b2450 | 105 | GDB_FILE *stream; |
a8a69e63 FF |
106 | int show; |
107 | int level; | |
108 | { | |
109 | register enum type_code code; | |
a8a69e63 FF |
110 | int demangled_args; |
111 | ||
112 | c_type_print_base (type, stream, show, level); | |
113 | code = TYPE_CODE (type); | |
114 | if ((varstring != NULL && *varstring != '\0') | |
115 | || | |
116 | /* Need a space if going to print stars or brackets; | |
117 | but not if we will print just a type name. */ | |
118 | ((show > 0 || TYPE_NAME (type) == 0) | |
119 | && | |
120 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
121 | || code == TYPE_CODE_METHOD | |
122 | || code == TYPE_CODE_ARRAY | |
123 | || code == TYPE_CODE_MEMBER | |
124 | || code == TYPE_CODE_REF))) | |
125 | fputs_filtered (" ", stream); | |
126 | c_type_print_varspec_prefix (type, stream, show, 0); | |
127 | ||
2e4964ad | 128 | fputs_filtered (varstring, stream); |
a8a69e63 FF |
129 | |
130 | /* For demangled function names, we have the arglist as part of the name, | |
131 | so don't print an additional pair of ()'s */ | |
132 | ||
f3806e3b | 133 | demangled_args = strchr(varstring, '(') != NULL; |
a8a69e63 FF |
134 | c_type_print_varspec_suffix (type, stream, show, 0, demangled_args); |
135 | ||
a8a69e63 FF |
136 | } |
137 | ||
138 | /* Print the C++ method arguments ARGS to the file STREAM. */ | |
139 | ||
140 | void | |
141 | cp_type_print_method_args (args, prefix, varstring, staticp, stream) | |
142 | struct type **args; | |
143 | char *prefix; | |
144 | char *varstring; | |
145 | int staticp; | |
199b2450 | 146 | GDB_FILE *stream; |
a8a69e63 FF |
147 | { |
148 | int i; | |
149 | ||
5e81259d FF |
150 | fprintf_symbol_filtered (stream, prefix, language_cplus, DMGL_ANSI); |
151 | fprintf_symbol_filtered (stream, varstring, language_cplus, DMGL_ANSI); | |
a8a69e63 FF |
152 | fputs_filtered (" (", stream); |
153 | if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID) | |
154 | { | |
155 | i = !staticp; /* skip the class variable */ | |
156 | while (1) | |
157 | { | |
158 | type_print (args[i++], "", stream, 0); | |
159 | if (!args[i]) | |
160 | { | |
161 | fprintf_filtered (stream, " ..."); | |
162 | break; | |
163 | } | |
164 | else if (args[i]->code != TYPE_CODE_VOID) | |
165 | { | |
166 | fprintf_filtered (stream, ", "); | |
167 | } | |
168 | else break; | |
169 | } | |
170 | } | |
171 | fprintf_filtered (stream, ")"); | |
172 | } | |
173 | ||
174 | /* If TYPE is a derived type, then print out derivation information. | |
175 | Print only the actual base classes of this type, not the base classes | |
176 | of the base classes. I.E. for the derivation hierarchy: | |
177 | ||
178 | class A { int a; }; | |
179 | class B : public A {int b; }; | |
180 | class C : public B {int c; }; | |
181 | ||
182 | Print the type of class C as: | |
183 | ||
184 | class C : public B { | |
185 | int c; | |
186 | } | |
187 | ||
188 | Not as the following (like gdb used to), which is not legal C++ syntax for | |
189 | derived types and may be confused with the multiple inheritance form: | |
190 | ||
191 | class C : public B : public A { | |
192 | int c; | |
193 | } | |
194 | ||
195 | In general, gdb should try to print the types as closely as possible to | |
196 | the form that they appear in the source code. */ | |
197 | ||
198 | static void | |
199 | cp_type_print_derivation_info (stream, type) | |
199b2450 | 200 | GDB_FILE *stream; |
a8a69e63 FF |
201 | struct type *type; |
202 | { | |
203 | char *name; | |
204 | int i; | |
205 | ||
206 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) | |
207 | { | |
208 | fputs_filtered (i == 0 ? ": " : ", ", stream); | |
209 | fprintf_filtered (stream, "%s%s ", | |
210 | BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private", | |
211 | BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : ""); | |
212 | name = type_name_no_tag (TYPE_BASECLASS (type, i)); | |
213 | fprintf_filtered (stream, "%s", name ? name : "(null)"); | |
214 | } | |
215 | if (i > 0) | |
216 | { | |
217 | fputs_filtered (" ", stream); | |
218 | } | |
219 | } | |
220 | ||
221 | /* Print any asterisks or open-parentheses needed before the | |
222 | variable name (to describe its type). | |
223 | ||
224 | On outermost call, pass 0 for PASSED_A_PTR. | |
225 | On outermost call, SHOW > 0 means should ignore | |
226 | any typename for TYPE and show its details. | |
227 | SHOW is always zero on recursive calls. */ | |
228 | ||
229 | void | |
230 | c_type_print_varspec_prefix (type, stream, show, passed_a_ptr) | |
231 | struct type *type; | |
199b2450 | 232 | GDB_FILE *stream; |
a8a69e63 FF |
233 | int show; |
234 | int passed_a_ptr; | |
235 | { | |
236 | char *name; | |
237 | if (type == 0) | |
238 | return; | |
239 | ||
240 | if (TYPE_NAME (type) && show <= 0) | |
241 | return; | |
242 | ||
243 | QUIT; | |
244 | ||
245 | switch (TYPE_CODE (type)) | |
246 | { | |
247 | case TYPE_CODE_PTR: | |
248 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
249 | fprintf_filtered (stream, "*"); | |
250 | break; | |
251 | ||
252 | case TYPE_CODE_MEMBER: | |
253 | if (passed_a_ptr) | |
254 | fprintf_filtered (stream, "("); | |
255 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
256 | fprintf_filtered (stream, " "); | |
257 | name = type_name_no_tag (TYPE_DOMAIN_TYPE (type)); | |
258 | if (name) | |
259 | fputs_filtered (name, stream); | |
260 | else | |
261 | c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr); | |
262 | fprintf_filtered (stream, "::"); | |
263 | break; | |
264 | ||
265 | case TYPE_CODE_METHOD: | |
266 | if (passed_a_ptr) | |
199b2450 | 267 | fprintf_unfiltered (stream, "("); |
a8a69e63 FF |
268 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); |
269 | if (passed_a_ptr) | |
270 | { | |
271 | fprintf_filtered (stream, " "); | |
272 | c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr); | |
273 | fprintf_filtered (stream, "::"); | |
274 | } | |
275 | break; | |
276 | ||
277 | case TYPE_CODE_REF: | |
278 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
279 | fprintf_filtered (stream, "&"); | |
280 | break; | |
281 | ||
282 | case TYPE_CODE_FUNC: | |
283 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
284 | if (passed_a_ptr) | |
285 | fprintf_filtered (stream, "("); | |
286 | break; | |
287 | ||
288 | case TYPE_CODE_ARRAY: | |
289 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
290 | if (passed_a_ptr) | |
291 | fprintf_filtered (stream, "("); | |
292 | break; | |
293 | ||
294 | case TYPE_CODE_UNDEF: | |
295 | case TYPE_CODE_STRUCT: | |
296 | case TYPE_CODE_UNION: | |
297 | case TYPE_CODE_ENUM: | |
298 | case TYPE_CODE_INT: | |
299 | case TYPE_CODE_FLT: | |
300 | case TYPE_CODE_VOID: | |
301 | case TYPE_CODE_ERROR: | |
302 | case TYPE_CODE_CHAR: | |
303 | case TYPE_CODE_BOOL: | |
304 | case TYPE_CODE_SET: | |
305 | case TYPE_CODE_RANGE: | |
c4413e2c | 306 | case TYPE_CODE_STRING: |
72cd0384 | 307 | case TYPE_CODE_BITSTRING: |
a8a69e63 FF |
308 | /* These types need no prefix. They are listed here so that |
309 | gcc -Wall will reveal any types that haven't been handled. */ | |
310 | break; | |
311 | } | |
312 | } | |
313 | ||
314 | static void | |
315 | c_type_print_args (type, stream) | |
316 | struct type *type; | |
199b2450 | 317 | GDB_FILE *stream; |
a8a69e63 FF |
318 | { |
319 | int i; | |
320 | struct type **args; | |
321 | ||
322 | fprintf_filtered (stream, "("); | |
323 | args = TYPE_ARG_TYPES (type); | |
324 | if (args != NULL) | |
325 | { | |
326 | if (args[1] == NULL) | |
327 | { | |
328 | fprintf_filtered (stream, "..."); | |
329 | } | |
330 | else | |
331 | { | |
332 | for (i = 1; | |
333 | args[i] != NULL && args[i]->code != TYPE_CODE_VOID; | |
334 | i++) | |
335 | { | |
336 | c_print_type (args[i], "", stream, -1, 0); | |
337 | if (args[i+1] == NULL) | |
338 | { | |
339 | fprintf_filtered (stream, "..."); | |
340 | } | |
341 | else if (args[i+1]->code != TYPE_CODE_VOID) | |
342 | { | |
343 | fprintf_filtered (stream, ","); | |
344 | wrap_here (" "); | |
345 | } | |
346 | } | |
347 | } | |
348 | } | |
349 | fprintf_filtered (stream, ")"); | |
350 | } | |
351 | ||
352 | /* Print any array sizes, function arguments or close parentheses | |
353 | needed after the variable name (to describe its type). | |
354 | Args work like c_type_print_varspec_prefix. */ | |
355 | ||
356 | static void | |
357 | c_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args) | |
358 | struct type *type; | |
199b2450 | 359 | GDB_FILE *stream; |
a8a69e63 FF |
360 | int show; |
361 | int passed_a_ptr; | |
362 | int demangled_args; | |
363 | { | |
364 | if (type == 0) | |
365 | return; | |
366 | ||
367 | if (TYPE_NAME (type) && show <= 0) | |
368 | return; | |
369 | ||
370 | QUIT; | |
371 | ||
372 | switch (TYPE_CODE (type)) | |
373 | { | |
374 | case TYPE_CODE_ARRAY: | |
375 | if (passed_a_ptr) | |
376 | fprintf_filtered (stream, ")"); | |
377 | ||
378 | fprintf_filtered (stream, "["); | |
379 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
380 | fprintf_filtered (stream, "%d", | |
381 | (TYPE_LENGTH (type) | |
382 | / TYPE_LENGTH (TYPE_TARGET_TYPE (type)))); | |
383 | fprintf_filtered (stream, "]"); | |
384 | ||
385 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
386 | break; | |
387 | ||
388 | case TYPE_CODE_MEMBER: | |
389 | if (passed_a_ptr) | |
390 | fprintf_filtered (stream, ")"); | |
391 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
392 | break; | |
393 | ||
394 | case TYPE_CODE_METHOD: | |
395 | if (passed_a_ptr) | |
396 | fprintf_filtered (stream, ")"); | |
397 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
398 | if (passed_a_ptr) | |
399 | { | |
400 | c_type_print_args (type, stream); | |
401 | } | |
402 | break; | |
403 | ||
404 | case TYPE_CODE_PTR: | |
405 | case TYPE_CODE_REF: | |
406 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0); | |
407 | break; | |
408 | ||
409 | case TYPE_CODE_FUNC: | |
a8a69e63 FF |
410 | if (passed_a_ptr) |
411 | fprintf_filtered (stream, ")"); | |
412 | if (!demangled_args) | |
413 | fprintf_filtered (stream, "()"); | |
dac317dc JK |
414 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, |
415 | passed_a_ptr, 0); | |
a8a69e63 FF |
416 | break; |
417 | ||
418 | case TYPE_CODE_UNDEF: | |
419 | case TYPE_CODE_STRUCT: | |
420 | case TYPE_CODE_UNION: | |
421 | case TYPE_CODE_ENUM: | |
422 | case TYPE_CODE_INT: | |
423 | case TYPE_CODE_FLT: | |
424 | case TYPE_CODE_VOID: | |
425 | case TYPE_CODE_ERROR: | |
426 | case TYPE_CODE_CHAR: | |
427 | case TYPE_CODE_BOOL: | |
428 | case TYPE_CODE_SET: | |
429 | case TYPE_CODE_RANGE: | |
c4413e2c | 430 | case TYPE_CODE_STRING: |
72cd0384 | 431 | case TYPE_CODE_BITSTRING: |
a8a69e63 FF |
432 | /* These types do not need a suffix. They are listed so that |
433 | gcc -Wall will report types that may not have been considered. */ | |
434 | break; | |
435 | } | |
436 | } | |
437 | ||
438 | /* Print the name of the type (or the ultimate pointer target, | |
439 | function value or array element), or the description of a | |
440 | structure or union. | |
441 | ||
875fc229 JK |
442 | SHOW positive means print details about the type (e.g. enum values), |
443 | and print structure elements passing SHOW - 1 for show. | |
0e4ad984 | 444 | SHOW negative means just print the type name or struct tag if there is one. |
875fc229 JK |
445 | If there is no name, print something sensible but concise like |
446 | "struct {...}". | |
0e4ad984 JK |
447 | SHOW zero means just print the type name or struct tag if there is one. |
448 | If there is no name, print something sensible but not as concise like | |
449 | "struct {int x; int y;}". | |
875fc229 JK |
450 | |
451 | LEVEL is the number of spaces to indent by. | |
a8a69e63 FF |
452 | We increase it for some recursive calls. */ |
453 | ||
454 | void | |
455 | c_type_print_base (type, stream, show, level) | |
456 | struct type *type; | |
199b2450 | 457 | GDB_FILE *stream; |
a8a69e63 FF |
458 | int show; |
459 | int level; | |
460 | { | |
a8a69e63 FF |
461 | register int i; |
462 | register int len; | |
463 | register int lastval; | |
464 | char *mangled_name; | |
465 | char *demangled_name; | |
466 | enum {s_none, s_public, s_private, s_protected} section_type; | |
467 | QUIT; | |
468 | ||
469 | wrap_here (" "); | |
470 | if (type == NULL) | |
471 | { | |
472 | fputs_filtered ("<type unknown>", stream); | |
473 | return; | |
474 | } | |
475 | ||
476 | /* When SHOW is zero or less, and there is a valid type name, then always | |
b2bebdb0 JK |
477 | just print the type name directly from the type. */ |
478 | /* If we have "typedef struct foo {. . .} bar;" do we want to print it | |
479 | as "struct foo" or as "bar"? Pick the latter, because C++ folk tend | |
480 | to expect things like "class5 *foo" rather than "struct class5 *foo". */ | |
a8a69e63 | 481 | |
b2bebdb0 JK |
482 | if (show <= 0 |
483 | && TYPE_NAME (type) != NULL) | |
a8a69e63 FF |
484 | { |
485 | fputs_filtered (TYPE_NAME (type), stream); | |
486 | return; | |
487 | } | |
488 | ||
dda398c3 JK |
489 | check_stub_type (type); |
490 | ||
a8a69e63 FF |
491 | switch (TYPE_CODE (type)) |
492 | { | |
493 | case TYPE_CODE_ARRAY: | |
494 | case TYPE_CODE_PTR: | |
495 | case TYPE_CODE_MEMBER: | |
496 | case TYPE_CODE_REF: | |
497 | case TYPE_CODE_FUNC: | |
498 | case TYPE_CODE_METHOD: | |
499 | c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
500 | break; | |
501 | ||
502 | case TYPE_CODE_STRUCT: | |
8789d972 JK |
503 | if (HAVE_CPLUS_STRUCT (type)) |
504 | { | |
8789d972 | 505 | fprintf_filtered (stream, "class "); |
8789d972 JK |
506 | } |
507 | else | |
508 | { | |
509 | fprintf_filtered (stream, "struct "); | |
8789d972 | 510 | } |
a8a69e63 FF |
511 | goto struct_union; |
512 | ||
513 | case TYPE_CODE_UNION: | |
514 | fprintf_filtered (stream, "union "); | |
b2bebdb0 JK |
515 | |
516 | struct_union: | |
517 | if (TYPE_TAG_NAME (type) != NULL) | |
8789d972 | 518 | { |
b2bebdb0 JK |
519 | fputs_filtered (TYPE_TAG_NAME (type), stream); |
520 | if (show > 0) | |
521 | fputs_filtered (" ", stream); | |
8789d972 | 522 | } |
8789d972 | 523 | wrap_here (" "); |
0e4ad984 | 524 | if (show < 0) |
b2bebdb0 JK |
525 | { |
526 | /* If we just printed a tag name, no need to print anything else. */ | |
527 | if (TYPE_TAG_NAME (type) == NULL) | |
528 | fprintf_filtered (stream, "{...}"); | |
529 | } | |
0e4ad984 | 530 | else if (show > 0 || TYPE_TAG_NAME (type) == NULL) |
a8a69e63 | 531 | { |
a8a69e63 FF |
532 | cp_type_print_derivation_info (stream, type); |
533 | ||
534 | fprintf_filtered (stream, "{\n"); | |
535 | if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) | |
536 | { | |
537 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
538 | fprintfi_filtered (level + 4, stream, "<incomplete type>\n"); | |
539 | else | |
540 | fprintfi_filtered (level + 4, stream, "<no data fields>\n"); | |
541 | } | |
542 | ||
543 | /* Start off with no specific section type, so we can print | |
544 | one for the first field we find, and use that section type | |
545 | thereafter until we find another type. */ | |
546 | ||
547 | section_type = s_none; | |
548 | ||
549 | /* If there is a base class for this type, | |
550 | do not print the field that it occupies. */ | |
551 | ||
552 | len = TYPE_NFIELDS (type); | |
553 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
554 | { | |
555 | QUIT; | |
556 | /* Don't print out virtual function table. */ | |
557 | if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER && | |
558 | !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5)) | |
559 | continue; | |
560 | ||
561 | /* If this is a C++ class we can print the various C++ section | |
562 | labels. */ | |
563 | ||
564 | if (HAVE_CPLUS_STRUCT (type)) | |
565 | { | |
566 | if (TYPE_FIELD_PROTECTED (type, i)) | |
567 | { | |
568 | if (section_type != s_protected) | |
569 | { | |
570 | section_type = s_protected; | |
571 | fprintfi_filtered (level + 2, stream, | |
572 | "protected:\n"); | |
573 | } | |
574 | } | |
575 | else if (TYPE_FIELD_PRIVATE (type, i)) | |
576 | { | |
577 | if (section_type != s_private) | |
578 | { | |
579 | section_type = s_private; | |
580 | fprintfi_filtered (level + 2, stream, "private:\n"); | |
581 | } | |
582 | } | |
583 | else | |
584 | { | |
585 | if (section_type != s_public) | |
586 | { | |
587 | section_type = s_public; | |
588 | fprintfi_filtered (level + 2, stream, "public:\n"); | |
589 | } | |
590 | } | |
591 | } | |
592 | ||
593 | print_spaces_filtered (level + 4, stream); | |
594 | if (TYPE_FIELD_STATIC (type, i)) | |
595 | { | |
596 | fprintf_filtered (stream, "static "); | |
597 | } | |
598 | c_print_type (TYPE_FIELD_TYPE (type, i), | |
599 | TYPE_FIELD_NAME (type, i), | |
600 | stream, show - 1, level + 4); | |
601 | if (!TYPE_FIELD_STATIC (type, i) | |
602 | && TYPE_FIELD_PACKED (type, i)) | |
603 | { | |
604 | /* It is a bitfield. This code does not attempt | |
605 | to look at the bitpos and reconstruct filler, | |
606 | unnamed fields. This would lead to misleading | |
607 | results if the compiler does not put out fields | |
608 | for such things (I don't know what it does). */ | |
609 | fprintf_filtered (stream, " : %d", | |
610 | TYPE_FIELD_BITSIZE (type, i)); | |
611 | } | |
612 | fprintf_filtered (stream, ";\n"); | |
613 | } | |
614 | ||
615 | /* If there are both fields and methods, put a space between. */ | |
616 | len = TYPE_NFN_FIELDS (type); | |
617 | if (len && section_type != s_none) | |
618 | fprintf_filtered (stream, "\n"); | |
619 | ||
620 | /* C++: print out the methods */ | |
621 | ||
622 | for (i = 0; i < len; i++) | |
623 | { | |
624 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
625 | int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); | |
626 | char *method_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
b2bebdb0 | 627 | char *name = type_name_no_tag (type); |
2e4964ad | 628 | int is_constructor = name && STREQ(method_name, name); |
a8a69e63 FF |
629 | for (j = 0; j < len2; j++) |
630 | { | |
631 | QUIT; | |
632 | if (TYPE_FN_FIELD_PROTECTED (f, j)) | |
633 | { | |
634 | if (section_type != s_protected) | |
635 | { | |
636 | section_type = s_protected; | |
637 | fprintfi_filtered (level + 2, stream, | |
638 | "protected:\n"); | |
639 | } | |
640 | } | |
641 | else if (TYPE_FN_FIELD_PRIVATE (f, j)) | |
642 | { | |
643 | if (section_type != s_private) | |
644 | { | |
645 | section_type = s_private; | |
646 | fprintfi_filtered (level + 2, stream, "private:\n"); | |
647 | } | |
648 | } | |
649 | else | |
650 | { | |
651 | if (section_type != s_public) | |
652 | { | |
653 | section_type = s_public; | |
654 | fprintfi_filtered (level + 2, stream, "public:\n"); | |
655 | } | |
656 | } | |
657 | ||
658 | print_spaces_filtered (level + 4, stream); | |
659 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) | |
660 | fprintf_filtered (stream, "virtual "); | |
661 | else if (TYPE_FN_FIELD_STATIC_P (f, j)) | |
662 | fprintf_filtered (stream, "static "); | |
663 | if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) | |
664 | { | |
665 | /* Keep GDB from crashing here. */ | |
199b2450 | 666 | fprintf_unfiltered (stream, "<undefined type> %s;\n", |
a8a69e63 FF |
667 | TYPE_FN_FIELD_PHYSNAME (f, j)); |
668 | break; | |
669 | } | |
670 | else if (!is_constructor) | |
671 | { | |
672 | type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), | |
673 | "", stream, 0); | |
674 | fputs_filtered (" ", stream); | |
675 | } | |
676 | if (TYPE_FN_FIELD_STUB (f, j)) | |
677 | { | |
678 | /* Build something we can demangle. */ | |
679 | mangled_name = gdb_mangle_name (type, i, j); | |
680 | demangled_name = | |
4f9bddb4 JK |
681 | cplus_demangle (mangled_name, |
682 | DMGL_ANSI | DMGL_PARAMS); | |
a8a69e63 FF |
683 | if (demangled_name == NULL) |
684 | fprintf_filtered (stream, "<badly mangled name %s>", | |
4f9bddb4 JK |
685 | mangled_name); |
686 | else | |
a8a69e63 | 687 | { |
4f9bddb4 JK |
688 | char *demangled_no_class = |
689 | strchr (demangled_name, ':'); | |
690 | ||
691 | if (demangled_no_class == NULL) | |
692 | demangled_no_class = demangled_name; | |
693 | else | |
694 | { | |
695 | if (*++demangled_no_class == ':') | |
696 | ++demangled_no_class; | |
697 | } | |
698 | fputs_filtered (demangled_no_class, stream); | |
a8a69e63 FF |
699 | free (demangled_name); |
700 | } | |
701 | free (mangled_name); | |
702 | } | |
703 | else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' | |
704 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) | |
705 | cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j) + 1, | |
706 | "~", method_name, 0, stream); | |
707 | else | |
708 | cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "", | |
709 | method_name, | |
710 | TYPE_FN_FIELD_STATIC_P (f, j), | |
711 | stream); | |
712 | ||
713 | fprintf_filtered (stream, ";\n"); | |
714 | } | |
715 | } | |
716 | ||
717 | fprintfi_filtered (level, stream, "}"); | |
718 | } | |
719 | break; | |
720 | ||
721 | case TYPE_CODE_ENUM: | |
722 | fprintf_filtered (stream, "enum "); | |
b2bebdb0 | 723 | if (TYPE_TAG_NAME (type) != NULL) |
a8a69e63 | 724 | { |
b2bebdb0 JK |
725 | fputs_filtered (TYPE_TAG_NAME (type), stream); |
726 | if (show > 0) | |
727 | fputs_filtered (" ", stream); | |
a8a69e63 | 728 | } |
8789d972 | 729 | |
a8a69e63 | 730 | wrap_here (" "); |
0e4ad984 | 731 | if (show < 0) |
b2bebdb0 JK |
732 | { |
733 | /* If we just printed a tag name, no need to print anything else. */ | |
734 | if (TYPE_TAG_NAME (type) == NULL) | |
735 | fprintf_filtered (stream, "{...}"); | |
736 | } | |
0e4ad984 | 737 | else if (show > 0 || TYPE_TAG_NAME (type) == NULL) |
a8a69e63 FF |
738 | { |
739 | fprintf_filtered (stream, "{"); | |
740 | len = TYPE_NFIELDS (type); | |
741 | lastval = 0; | |
742 | for (i = 0; i < len; i++) | |
743 | { | |
744 | QUIT; | |
745 | if (i) fprintf_filtered (stream, ", "); | |
746 | wrap_here (" "); | |
747 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
748 | if (lastval != TYPE_FIELD_BITPOS (type, i)) | |
749 | { | |
750 | fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); | |
751 | lastval = TYPE_FIELD_BITPOS (type, i); | |
752 | } | |
753 | lastval++; | |
754 | } | |
755 | fprintf_filtered (stream, "}"); | |
756 | } | |
757 | break; | |
758 | ||
759 | case TYPE_CODE_VOID: | |
760 | fprintf_filtered (stream, "void"); | |
761 | break; | |
762 | ||
763 | case TYPE_CODE_UNDEF: | |
764 | fprintf_filtered (stream, "struct <unknown>"); | |
765 | break; | |
766 | ||
767 | case TYPE_CODE_ERROR: | |
768 | fprintf_filtered (stream, "<unknown type>"); | |
769 | break; | |
770 | ||
771 | case TYPE_CODE_RANGE: | |
772 | /* This should not occur */ | |
773 | fprintf_filtered (stream, "<range type>"); | |
774 | break; | |
775 | ||
776 | default: | |
777 | /* Handle types not explicitly handled by the other cases, | |
778 | such as fundamental types. For these, just print whatever | |
779 | the type name is, as recorded in the type itself. If there | |
780 | is no type name, then complain. */ | |
781 | if (TYPE_NAME (type) != NULL) | |
782 | { | |
783 | fputs_filtered (TYPE_NAME (type), stream); | |
784 | } | |
785 | else | |
786 | { | |
fd09c963 JK |
787 | /* At least for dump_symtab, it is important that this not be |
788 | an error (). */ | |
789 | fprintf_filtered (stream, "<invalid type code %d>", | |
790 | TYPE_CODE (type)); | |
a8a69e63 FF |
791 | } |
792 | break; | |
793 | } | |
794 | } | |
795 |