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