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