]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Support for printing C++ values for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1989, 1991, 1994, 1995, 1996 | |
3 | Free Software Foundation, Inc. | |
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "defs.h" | |
22 | #include "obstack.h" | |
23 | #include "symtab.h" | |
24 | #include "gdbtypes.h" | |
25 | #include "expression.h" | |
26 | #include "value.h" | |
27 | #include "command.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "demangle.h" | |
30 | #include "annotate.h" | |
31 | #include "gdb_string.h" | |
32 | #include "c-lang.h" | |
33 | #include "target.h" | |
34 | ||
35 | /* Indication of presence of HP-compiled object files */ | |
36 | extern int hp_som_som_object_present; /* defined in symtab.c */ | |
37 | ||
38 | ||
39 | int vtblprint; /* Controls printing of vtbl's */ | |
40 | int objectprint; /* Controls looking up an object's derived type | |
41 | using what we find in its vtables. */ | |
42 | int static_field_print; /* Controls printing of static fields. */ | |
43 | ||
44 | static struct obstack dont_print_vb_obstack; | |
45 | static struct obstack dont_print_statmem_obstack; | |
46 | ||
392a587b JM |
47 | extern void _initialize_cp_valprint PARAMS ((void)); |
48 | ||
c906108c SS |
49 | static void |
50 | cp_print_static_field PARAMS ((struct type *, value_ptr, GDB_FILE *, int, int, | |
51 | enum val_prettyprint)); | |
52 | ||
53 | static void | |
54 | cp_print_value PARAMS ((struct type *, struct type *, char *, int, CORE_ADDR, GDB_FILE *, | |
55 | int, int, enum val_prettyprint, struct type **)); | |
56 | ||
57 | static void | |
58 | cp_print_hpacc_virtual_table_entries PARAMS ((struct type *, int *, value_ptr, GDB_FILE *, | |
59 | int, int, enum val_prettyprint)); | |
60 | ||
61 | ||
62 | void | |
63 | cp_print_class_method (valaddr, type, stream) | |
64 | char *valaddr; | |
65 | struct type *type; | |
66 | GDB_FILE *stream; | |
67 | { | |
68 | struct type *domain; | |
69 | struct fn_field *f = NULL; | |
70 | int j = 0; | |
71 | int len2; | |
72 | int offset; | |
73 | char *kind = ""; | |
74 | CORE_ADDR addr; | |
75 | struct symbol *sym; | |
76 | unsigned len; | |
77 | unsigned int i; | |
78 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
79 | ||
80 | domain = TYPE_DOMAIN_TYPE (target_type); | |
81 | if (domain == (struct type *)NULL) | |
82 | { | |
83 | fprintf_filtered (stream, "<unknown>"); | |
84 | return; | |
85 | } | |
86 | addr = unpack_pointer (lookup_pointer_type (builtin_type_void), valaddr); | |
87 | if (METHOD_PTR_IS_VIRTUAL (addr)) | |
88 | { | |
89 | offset = METHOD_PTR_TO_VOFFSET (addr); | |
90 | len = TYPE_NFN_FIELDS (domain); | |
91 | for (i = 0; i < len; i++) | |
92 | { | |
93 | f = TYPE_FN_FIELDLIST1 (domain, i); | |
94 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); | |
95 | ||
96 | for (j = 0; j < len2; j++) | |
97 | { | |
98 | QUIT; | |
99 | if (TYPE_FN_FIELD_VOFFSET (f, j) == offset) | |
100 | { | |
101 | if (TYPE_FN_FIELD_STUB (f, j)) | |
102 | check_stub_method (domain, i, j); | |
103 | kind = "virtual "; | |
104 | goto common; | |
105 | } | |
106 | } | |
107 | } | |
108 | } | |
109 | else | |
110 | { | |
111 | sym = find_pc_function (addr); | |
112 | if (sym == 0) | |
113 | { | |
114 | /* 1997-08-01 Currently unsupported with HP aCC */ | |
115 | if (hp_som_som_object_present) | |
116 | { | |
117 | fputs_filtered ("?? <not supported with HP aCC>", stream); | |
118 | return; | |
119 | } | |
120 | error ("invalid pointer to member function"); | |
121 | } | |
122 | len = TYPE_NFN_FIELDS (domain); | |
123 | for (i = 0; i < len; i++) | |
124 | { | |
125 | f = TYPE_FN_FIELDLIST1 (domain, i); | |
126 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); | |
127 | ||
128 | for (j = 0; j < len2; j++) | |
129 | { | |
130 | QUIT; | |
131 | if (TYPE_FN_FIELD_STUB (f, j)) | |
132 | check_stub_method (domain, i, j); | |
133 | if (STREQ (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j))) | |
134 | { | |
135 | goto common; | |
136 | } | |
137 | } | |
138 | } | |
139 | } | |
140 | common: | |
141 | if (i < len) | |
142 | { | |
143 | char *demangled_name; | |
144 | ||
145 | fprintf_filtered (stream, "&"); | |
146 | fprintf_filtered (stream, kind); | |
147 | demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j), | |
148 | DMGL_ANSI | DMGL_PARAMS); | |
149 | if (demangled_name == NULL) | |
150 | fprintf_filtered (stream, "<badly mangled name %s>", | |
151 | TYPE_FN_FIELD_PHYSNAME (f, j)); | |
152 | else | |
153 | { | |
154 | fputs_filtered (demangled_name, stream); | |
155 | free (demangled_name); | |
156 | } | |
157 | } | |
158 | else | |
159 | { | |
160 | fprintf_filtered (stream, "("); | |
161 | type_print (type, "", stream, -1); | |
162 | fprintf_filtered (stream, ") %d", (int) addr >> 3); | |
163 | } | |
164 | } | |
165 | ||
166 | /* This was what it was for gcc 2.4.5 and earlier. */ | |
167 | static const char vtbl_ptr_name_old[] = | |
168 | { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 }; | |
169 | /* It was changed to this after 2.4.5. */ | |
170 | const char vtbl_ptr_name[] = | |
171 | { '_','_','v','t','b','l','_','p','t','r','_','t','y','p','e', 0 }; | |
172 | ||
173 | /* HP aCC uses different names */ | |
174 | const char hpacc_vtbl_ptr_name[] = | |
175 | { '_', '_', 'v', 'f', 'p', 0 }; | |
176 | const char hpacc_vtbl_ptr_type_name[] = | |
177 | { '_', '_', 'v', 'f', 't', 'y', 'p', 0 }; | |
178 | ||
179 | ||
180 | /* Return truth value for assertion that TYPE is of the type | |
181 | "pointer to virtual function". */ | |
182 | ||
183 | int | |
184 | cp_is_vtbl_ptr_type(type) | |
185 | struct type *type; | |
186 | { | |
187 | char *typename = type_name_no_tag (type); | |
188 | ||
189 | return (typename != NULL | |
190 | && (STREQ (typename, vtbl_ptr_name) | |
191 | || STREQ (typename, vtbl_ptr_name_old))); | |
192 | } | |
193 | ||
194 | /* Return truth value for the assertion that TYPE is of the type | |
195 | "pointer to virtual function table". */ | |
196 | ||
197 | int | |
198 | cp_is_vtbl_member(type) | |
199 | struct type *type; | |
200 | { | |
201 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
202 | { | |
203 | type = TYPE_TARGET_TYPE (type); | |
204 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
205 | { | |
206 | type = TYPE_TARGET_TYPE (type); | |
207 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */ | |
208 | || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */ | |
209 | { | |
210 | /* Virtual functions tables are full of pointers | |
211 | to virtual functions. */ | |
212 | return cp_is_vtbl_ptr_type (type); | |
213 | } | |
214 | } | |
215 | } | |
216 | return 0; | |
217 | } | |
218 | ||
219 | /* Mutually recursive subroutines of cp_print_value and c_val_print to | |
220 | print out a structure's fields: cp_print_value_fields and cp_print_value. | |
221 | ||
222 | TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the | |
223 | same meanings as in cp_print_value and c_val_print. | |
224 | ||
225 | 2nd argument REAL_TYPE is used to carry over the type of the derived | |
226 | class across the recursion to base classes. | |
227 | ||
228 | DONT_PRINT is an array of baseclass types that we | |
229 | should not print, or zero if called from top level. */ | |
230 | ||
231 | void | |
232 | cp_print_value_fields (type, real_type, valaddr, offset, address, stream, format, recurse, pretty, | |
233 | dont_print_vb, dont_print_statmem) | |
234 | struct type *type; | |
235 | struct type *real_type; | |
236 | char *valaddr; | |
237 | int offset; | |
238 | CORE_ADDR address; | |
239 | GDB_FILE *stream; | |
240 | int format; | |
241 | int recurse; | |
242 | enum val_prettyprint pretty; | |
243 | struct type **dont_print_vb; | |
244 | int dont_print_statmem; | |
245 | { | |
246 | int i, len, n_baseclasses; | |
247 | struct obstack tmp_obstack; | |
248 | char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack); | |
249 | int fields_seen = 0; | |
250 | ||
251 | CHECK_TYPEDEF (type); | |
252 | ||
253 | fprintf_filtered (stream, "{"); | |
254 | len = TYPE_NFIELDS (type); | |
255 | n_baseclasses = TYPE_N_BASECLASSES (type); | |
256 | ||
257 | /* First, print out baseclasses such that we don't print | |
258 | duplicates of virtual baseclasses. */ | |
259 | ||
260 | if (n_baseclasses > 0) | |
261 | cp_print_value (type, real_type, valaddr, offset, address, stream, | |
262 | format, recurse+1, pretty, dont_print_vb); | |
263 | ||
264 | /* Second, print out data fields */ | |
265 | ||
266 | /* If there are no data fields, or if the only field is the | |
267 | * vtbl pointer, skip this part */ | |
268 | if ((len == n_baseclasses) || | |
269 | ((len - n_baseclasses == 1) && | |
270 | TYPE_HAS_VTABLE(type) && | |
271 | STREQN(TYPE_FIELD_NAME (type, n_baseclasses), hpacc_vtbl_ptr_name, 5)) || | |
272 | !len) | |
273 | fprintf_filtered (stream, "<No data fields>"); | |
274 | else | |
275 | { | |
276 | extern int inspect_it; | |
277 | ||
278 | if (dont_print_statmem == 0) | |
279 | { | |
280 | /* If we're at top level, carve out a completely fresh | |
281 | chunk of the obstack and use that until this particular | |
282 | invocation returns. */ | |
283 | tmp_obstack = dont_print_statmem_obstack; | |
284 | obstack_finish (&dont_print_statmem_obstack); | |
285 | } | |
286 | ||
287 | for (i = n_baseclasses; i < len; i++) | |
288 | { | |
289 | /* If requested, skip printing of static fields. */ | |
290 | if (!static_field_print && TYPE_FIELD_STATIC (type, i)) | |
291 | continue; | |
292 | ||
293 | /* If a vtable pointer appears, we'll print it out later */ | |
294 | if (TYPE_HAS_VTABLE(type) && STREQN(TYPE_FIELD_NAME (type, i), hpacc_vtbl_ptr_name, 5)) | |
295 | continue; | |
296 | ||
297 | if (fields_seen) | |
298 | fprintf_filtered (stream, ", "); | |
299 | else if (n_baseclasses > 0) | |
300 | { | |
301 | if (pretty) | |
302 | { | |
303 | fprintf_filtered (stream, "\n"); | |
304 | print_spaces_filtered (2 + 2 * recurse, stream); | |
305 | fputs_filtered ("members of ", stream); | |
306 | fputs_filtered (type_name_no_tag (type), stream); | |
307 | fputs_filtered (": ", stream); | |
308 | } | |
309 | } | |
310 | fields_seen = 1; | |
311 | ||
312 | if (pretty) | |
313 | { | |
314 | fprintf_filtered (stream, "\n"); | |
315 | print_spaces_filtered (2 + 2 * recurse, stream); | |
316 | } | |
317 | else | |
318 | { | |
319 | wrap_here (n_spaces (2 + 2 * recurse)); | |
320 | } | |
321 | if (inspect_it) | |
322 | { | |
323 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
324 | fputs_filtered ("\"( ptr \"", stream); | |
325 | else | |
326 | fputs_filtered ("\"( nodef \"", stream); | |
327 | if (TYPE_FIELD_STATIC (type, i)) | |
328 | fputs_filtered ("static ", stream); | |
329 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
330 | language_cplus, | |
331 | DMGL_PARAMS | DMGL_ANSI); | |
332 | fputs_filtered ("\" \"", stream); | |
333 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
334 | language_cplus, | |
335 | DMGL_PARAMS | DMGL_ANSI); | |
336 | fputs_filtered ("\") \"", stream); | |
337 | } | |
338 | else | |
339 | { | |
340 | annotate_field_begin (TYPE_FIELD_TYPE (type, i)); | |
341 | ||
342 | if (TYPE_FIELD_STATIC (type, i)) | |
343 | fputs_filtered ("static ", stream); | |
344 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
345 | language_cplus, | |
346 | DMGL_PARAMS | DMGL_ANSI); | |
347 | annotate_field_name_end (); | |
348 | /* do not print leading '=' in case of anonymous unions */ | |
349 | if (strcmp (TYPE_FIELD_NAME (type, i), "")) | |
350 | fputs_filtered (" = ", stream); | |
351 | annotate_field_value (); | |
352 | } | |
353 | ||
354 | if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i)) | |
355 | { | |
356 | value_ptr v; | |
357 | ||
358 | /* Bitfields require special handling, especially due to byte | |
359 | order problems. */ | |
360 | if (TYPE_FIELD_IGNORE (type, i)) | |
361 | { | |
362 | fputs_filtered ("<optimized out or zero length>", stream); | |
363 | } | |
364 | else | |
365 | { | |
366 | v = value_from_longest (TYPE_FIELD_TYPE (type, i), | |
367 | unpack_field_as_long (type, valaddr + offset, i)); | |
368 | ||
369 | val_print (TYPE_FIELD_TYPE(type, i), VALUE_CONTENTS (v), 0, 0, | |
370 | stream, format, 0, recurse + 1, pretty); | |
371 | } | |
372 | } | |
373 | else | |
374 | { | |
375 | if (TYPE_FIELD_IGNORE (type, i)) | |
376 | { | |
377 | fputs_filtered ("<optimized out or zero length>", stream); | |
378 | } | |
379 | else if (TYPE_FIELD_STATIC (type, i)) | |
380 | { | |
381 | value_ptr v = value_static_field (type, i); | |
382 | if (v == NULL) | |
383 | fputs_filtered ("<optimized out>", stream); | |
384 | else | |
385 | cp_print_static_field (TYPE_FIELD_TYPE (type, i), v, | |
386 | stream, format, recurse + 1, | |
387 | pretty); | |
388 | } | |
389 | else | |
390 | { | |
391 | val_print (TYPE_FIELD_TYPE (type, i), | |
392 | valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, | |
393 | address + TYPE_FIELD_BITPOS (type, i) / 8, | |
394 | stream, format, 0, recurse + 1, pretty); | |
395 | } | |
396 | } | |
397 | annotate_field_end (); | |
398 | } | |
399 | ||
400 | if (dont_print_statmem == 0) | |
401 | { | |
402 | /* Free the space used to deal with the printing | |
403 | of the members from top level. */ | |
404 | obstack_free (&dont_print_statmem_obstack, last_dont_print); | |
405 | dont_print_statmem_obstack = tmp_obstack; | |
406 | } | |
407 | ||
408 | if (pretty) | |
409 | { | |
410 | fprintf_filtered (stream, "\n"); | |
411 | print_spaces_filtered (2 * recurse, stream); | |
412 | } | |
413 | } /* if there are data fields */ | |
414 | /* Now print out the virtual table pointer if there is one */ | |
415 | if (TYPE_HAS_VTABLE(type) && STREQN(TYPE_FIELD_NAME (type, n_baseclasses), hpacc_vtbl_ptr_name, 5)) | |
416 | { | |
417 | value_ptr v; | |
418 | /* First get the virtual table pointer and print it out*/ | |
419 | ||
420 | #if 0 | |
421 | fputs_filtered ("__vfp = ", stream); | |
422 | #endif | |
423 | ||
424 | fputs_filtered (", Virtual table at ", stream); | |
425 | ||
426 | /* pai: FIXME 32x64 problem? */ | |
427 | /* Not sure what the best notation is in the case where there is no | |
428 | baseclass name. */ | |
429 | v = value_from_longest (lookup_pointer_type (builtin_type_unsigned_long), | |
430 | * (unsigned long *) (valaddr + offset)); | |
431 | ||
432 | val_print (VALUE_TYPE (v), VALUE_CONTENTS (v), 0, 0, | |
433 | stream, format, 0, recurse + 1, pretty); | |
434 | fields_seen = 1; | |
435 | ||
436 | if (vtblprint) | |
437 | { | |
438 | /* Print out function pointers in vtable. */ | |
439 | ||
440 | /* FIXME: then-clause is for non-RRBC layout of virtual | |
441 | * table. The RRBC case in the else-clause is yet to be | |
442 | * implemented. The if (1) below should be changed to a | |
443 | * test for whether the executable we have was compiled | |
444 | * with a version of HP aCC that doesn't have RRBC | |
445 | * support. */ | |
446 | ||
447 | if (1) | |
448 | { | |
449 | /* no RRBC support; function pointers embedded directly in vtable */ | |
450 | ||
451 | int vfuncs = count_virtual_fns (real_type); | |
452 | ||
453 | fputs_filtered (" {", stream); | |
454 | ||
455 | /* FIXME : doesn't work at present */ | |
456 | #if 0 | |
457 | fprintf_filtered (stream, "%d entr%s: ", vfuncs, vfuncs == 1 ? "y" : "ies"); | |
458 | #else | |
459 | fputs_filtered ("not implemented", stream); | |
460 | ||
461 | ||
462 | #endif | |
463 | ||
464 | /* recursive function that prints all virtual function entries */ | |
465 | #if 0 | |
466 | cp_print_hpacc_virtual_table_entries (real_type, &vfuncs, v, stream, format, recurse, pretty); | |
467 | #endif | |
468 | fputs_filtered ("}", stream); | |
469 | } /* non-RRBC case */ | |
470 | else | |
471 | { | |
472 | /* FIXME -- seem comments above */ | |
473 | /* RRBC support present; function pointers are found | |
474 | * by indirection through the class segment entries. */ | |
475 | ||
476 | ||
477 | } /* RRBC case */ | |
478 | } /* if vtblprint */ | |
479 | ||
480 | if (pretty) | |
481 | { | |
482 | fprintf_filtered (stream, "\n"); | |
483 | print_spaces_filtered (2 * recurse, stream); | |
484 | } | |
485 | ||
486 | } /* if vtable exists */ | |
487 | ||
488 | fprintf_filtered (stream, "}"); | |
489 | } | |
490 | ||
491 | /* Special val_print routine to avoid printing multiple copies of virtual | |
492 | baseclasses. */ | |
493 | ||
494 | static void | |
495 | cp_print_value (type, real_type, valaddr, offset, address, stream, format, recurse, pretty, | |
496 | dont_print_vb) | |
497 | struct type *type; | |
498 | struct type *real_type; | |
499 | char *valaddr; | |
500 | int offset; | |
501 | CORE_ADDR address; | |
502 | GDB_FILE *stream; | |
503 | int format; | |
504 | int recurse; | |
505 | enum val_prettyprint pretty; | |
506 | struct type **dont_print_vb; | |
507 | { | |
508 | struct obstack tmp_obstack; | |
509 | struct type **last_dont_print | |
510 | = (struct type **)obstack_next_free (&dont_print_vb_obstack); | |
511 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); | |
512 | ||
513 | if (dont_print_vb == 0) | |
514 | { | |
515 | /* If we're at top level, carve out a completely fresh | |
516 | chunk of the obstack and use that until this particular | |
517 | invocation returns. */ | |
518 | tmp_obstack = dont_print_vb_obstack; | |
519 | /* Bump up the high-water mark. Now alpha is omega. */ | |
520 | obstack_finish (&dont_print_vb_obstack); | |
521 | } | |
522 | ||
523 | for (i = 0; i < n_baseclasses; i++) | |
524 | { | |
525 | int boffset; | |
526 | int skip; | |
527 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); | |
528 | char *basename = TYPE_NAME (baseclass); | |
529 | char *base_valaddr; | |
530 | ||
531 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
532 | { | |
533 | struct type **first_dont_print | |
534 | = (struct type **)obstack_base (&dont_print_vb_obstack); | |
535 | ||
536 | int j = (struct type **)obstack_next_free (&dont_print_vb_obstack) | |
537 | - first_dont_print; | |
538 | ||
539 | while (--j >= 0) | |
540 | if (baseclass == first_dont_print[j]) | |
541 | goto flush_it; | |
542 | ||
543 | obstack_ptr_grow (&dont_print_vb_obstack, baseclass); | |
544 | } | |
545 | ||
546 | if (TYPE_HAS_VTABLE (type) && BASETYPE_VIA_VIRTUAL (type, i)) | |
547 | { | |
548 | /* Assume HP/Taligent runtime convention */ | |
549 | find_rt_vbase_offset (type, TYPE_BASECLASS (type, i), | |
550 | valaddr, offset, &boffset, &skip); | |
551 | if (skip >= 0) | |
552 | error ("Virtual base class offset not found from vtable while printing"); | |
553 | base_valaddr = valaddr; | |
554 | } | |
555 | else | |
556 | { | |
557 | boffset = baseclass_offset (type, i , valaddr + offset, address + offset); | |
558 | skip = ((boffset == -1) || (boffset+offset) < 0 ) ? 1 : -1; | |
559 | ||
560 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
561 | { | |
562 | /* The virtual base class pointer might have been clobbered by the | |
563 | user program. Make sure that it still points to a valid memory | |
564 | location. */ | |
565 | ||
566 | if (boffset != -1 && ((boffset+offset) < 0 || (boffset+offset) >= TYPE_LENGTH (type))) | |
567 | { | |
568 | base_valaddr = (char *) alloca (TYPE_LENGTH (baseclass)); | |
569 | if (target_read_memory (address + boffset, base_valaddr, | |
570 | TYPE_LENGTH (baseclass)) != 0) | |
571 | skip = 1; | |
572 | } | |
573 | else | |
574 | base_valaddr = valaddr; | |
575 | } | |
576 | else | |
577 | base_valaddr = valaddr; | |
578 | } | |
579 | ||
580 | /* now do the printing */ | |
581 | if (pretty) | |
582 | { | |
583 | fprintf_filtered (stream, "\n"); | |
584 | print_spaces_filtered (2 * recurse, stream); | |
585 | } | |
586 | fputs_filtered ("<", stream); | |
587 | /* Not sure what the best notation is in the case where there is no | |
588 | baseclass name. */ | |
589 | fputs_filtered (basename ? basename : "", stream); | |
590 | fputs_filtered ("> = ", stream); | |
591 | ||
592 | ||
593 | if (skip >= 1) | |
594 | fprintf_filtered (stream, "<invalid address>"); | |
595 | else | |
596 | cp_print_value_fields (baseclass, real_type, base_valaddr, offset + boffset, address, | |
597 | stream, format, recurse, pretty, | |
598 | (struct type **) obstack_base (&dont_print_vb_obstack), | |
599 | 0); | |
600 | fputs_filtered (", ", stream); | |
601 | ||
602 | flush_it: | |
603 | ; | |
604 | } | |
605 | ||
606 | if (dont_print_vb == 0) | |
607 | { | |
608 | /* Free the space used to deal with the printing | |
609 | of this type from top level. */ | |
610 | obstack_free (&dont_print_vb_obstack, last_dont_print); | |
611 | /* Reset watermark so that we can continue protecting | |
612 | ourselves from whatever we were protecting ourselves. */ | |
613 | dont_print_vb_obstack = tmp_obstack; | |
614 | } | |
615 | } | |
616 | ||
617 | /* Print value of a static member. | |
618 | To avoid infinite recursion when printing a class that contains | |
619 | a static instance of the class, we keep the addresses of all printed | |
620 | static member classes in an obstack and refuse to print them more | |
621 | than once. | |
622 | ||
623 | VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY | |
624 | have the same meanings as in c_val_print. */ | |
625 | ||
626 | static void | |
627 | cp_print_static_field (type, val, stream, format, recurse, pretty) | |
628 | struct type *type; | |
629 | value_ptr val; | |
630 | GDB_FILE *stream; | |
631 | int format; | |
632 | int recurse; | |
633 | enum val_prettyprint pretty; | |
634 | { | |
635 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
636 | { | |
637 | CORE_ADDR *first_dont_print; | |
638 | int i; | |
639 | ||
640 | first_dont_print | |
641 | = (CORE_ADDR *)obstack_base (&dont_print_statmem_obstack); | |
642 | i = (CORE_ADDR *)obstack_next_free (&dont_print_statmem_obstack) | |
643 | - first_dont_print; | |
644 | ||
645 | while (--i >= 0) | |
646 | { | |
647 | if (VALUE_ADDRESS (val) == first_dont_print[i]) | |
648 | { | |
649 | fputs_filtered ("<same as static member of an already seen type>", | |
650 | stream); | |
651 | return; | |
652 | } | |
653 | } | |
654 | ||
655 | obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val), | |
656 | sizeof (CORE_ADDR)); | |
657 | ||
658 | CHECK_TYPEDEF (type); | |
659 | cp_print_value_fields (type, type, VALUE_CONTENTS_ALL (val), VALUE_EMBEDDED_OFFSET (val), VALUE_ADDRESS (val), | |
660 | stream, format, recurse, pretty, NULL, 1); | |
661 | return; | |
662 | } | |
663 | val_print (type, VALUE_CONTENTS_ALL (val), VALUE_EMBEDDED_OFFSET (val), VALUE_ADDRESS (val), | |
664 | stream, format, 0, recurse, pretty); | |
665 | } | |
666 | ||
667 | void | |
668 | cp_print_class_member (valaddr, domain, stream, prefix) | |
669 | char *valaddr; | |
670 | struct type *domain; | |
671 | GDB_FILE *stream; | |
672 | char *prefix; | |
673 | { | |
674 | ||
675 | /* VAL is a byte offset into the structure type DOMAIN. | |
676 | Find the name of the field for that offset and | |
677 | print it. */ | |
678 | int extra = 0; | |
679 | int bits = 0; | |
680 | register unsigned int i; | |
681 | unsigned len = TYPE_NFIELDS (domain); | |
682 | ||
683 | /* @@ Make VAL into bit offset */ | |
684 | ||
685 | /* Note: HP aCC generates offsets that are the real byte offsets added | |
686 | to a constant bias 0x20000000 (1 << 29). This constant bias gets | |
687 | shifted out in the code below -- joyous happenstance! */ | |
688 | ||
689 | /* Note: HP cfront uses a constant bias of 1; if we support this | |
690 | compiler ever, we will have to adjust the computation below */ | |
691 | ||
692 | LONGEST val = unpack_long (builtin_type_int, valaddr) << 3; | |
693 | for (i = TYPE_N_BASECLASSES (domain); i < len; i++) | |
694 | { | |
695 | int bitpos = TYPE_FIELD_BITPOS (domain, i); | |
696 | QUIT; | |
697 | if (val == bitpos) | |
698 | break; | |
699 | if (val < bitpos && i != 0) | |
700 | { | |
701 | /* Somehow pointing into a field. */ | |
702 | i -= 1; | |
703 | extra = (val - TYPE_FIELD_BITPOS (domain, i)); | |
704 | if (extra & 0x7) | |
705 | bits = 1; | |
706 | else | |
707 | extra >>= 3; | |
708 | break; | |
709 | } | |
710 | } | |
711 | if (i < len) | |
712 | { | |
713 | char *name; | |
714 | fprintf_filtered (stream, prefix); | |
715 | name = type_name_no_tag (domain); | |
716 | if (name) | |
717 | fputs_filtered (name, stream); | |
718 | else | |
719 | c_type_print_base (domain, stream, 0, 0); | |
720 | fprintf_filtered (stream, "::"); | |
721 | fputs_filtered (TYPE_FIELD_NAME (domain, i), stream); | |
722 | if (extra) | |
723 | fprintf_filtered (stream, " + %d bytes", extra); | |
724 | if (bits) | |
725 | fprintf_filtered (stream, " (offset in bits)"); | |
726 | } | |
727 | else | |
728 | fprintf_filtered (stream, "%d", val >> 3); | |
729 | } | |
730 | ||
731 | ||
732 | /* This function prints out virtual table entries for a class; it | |
733 | * recurses on the base classes to find all virtual functions | |
734 | * available in a class. | |
735 | * | |
736 | * pai/1997-05-21 Note: As the name suggests, it's currently | |
737 | * implemented for HP aCC runtime only. g++ objects are handled | |
738 | * differently and I have made no attempt to fold that logic in | |
739 | * here. The runtime layout is different for the two cases. Also, | |
740 | * this currently has only the code for non-RRBC layouts generated by | |
741 | * the HP aCC compiler; RRBC code is stubbed out and will have to be | |
742 | * added later. */ | |
743 | ||
744 | ||
745 | static void | |
746 | cp_print_hpacc_virtual_table_entries (type, vfuncs, v, stream, format, recurse, pretty) | |
747 | struct type * type; | |
748 | int * vfuncs; | |
749 | value_ptr v; | |
750 | GDB_FILE *stream; | |
751 | int format; | |
752 | int recurse; | |
753 | enum val_prettyprint pretty; | |
754 | { | |
755 | int fn, oi; | |
756 | ||
757 | /* pai: FIXME this function doesn't work. It should handle a given | |
758 | * virtual function only once (latest redefinition in class hierarchy) | |
759 | */ | |
760 | ||
761 | /* Recursion on other classes that can share the same vtable */ | |
762 | struct type * pbc = primary_base_class (type); | |
763 | if (pbc) | |
764 | cp_print_hpacc_virtual_table_entries (pbc, vfuncs, v, stream, format, recurse, pretty); | |
765 | ||
766 | /* Now deal with vfuncs declared in this class */ | |
767 | for (fn = 0; fn < TYPE_NFN_FIELDS (type); fn++) | |
768 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (type, fn); oi++) | |
769 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (type, fn), oi)) | |
770 | { | |
771 | char * vf_name; | |
772 | ||
773 | /* virtual function offset */ | |
774 | int vx = TYPE_FN_FIELD_VOFFSET (TYPE_FN_FIELDLIST1 (type, fn), oi) - 1; | |
775 | ||
776 | /* Get the address of the vfunction entry */ | |
777 | value_ptr vf = value_copy (v); | |
778 | if (VALUE_LAZY (vf)) | |
779 | (void) value_fetch_lazy (vf); | |
780 | vf->aligner.contents[0] += 4 * (HP_ACC_VFUNC_START + vx); /* adjust by offset */ | |
781 | vf = value_ind (vf); /* get the entry */ | |
782 | VALUE_TYPE (vf) = VALUE_TYPE (v); /* make it a pointer */ | |
783 | ||
784 | /* print out the entry */ | |
785 | val_print (VALUE_TYPE (vf), VALUE_CONTENTS (vf), 0, 0, | |
786 | stream, format, 0, recurse + 1, pretty); | |
787 | vf_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (TYPE_FN_FIELDLIST1 (type, fn), oi), | |
788 | DMGL_ARM); /* pai: (temp) FIXME Maybe this should be DMGL_ANSI */ | |
789 | fprintf_filtered (stream, " %s", vf_name); | |
790 | if (--(*vfuncs) > 0) | |
791 | fputs_filtered (", ", stream); | |
792 | } | |
793 | } | |
794 | ||
795 | ||
796 | ||
797 | void | |
798 | _initialize_cp_valprint () | |
799 | { | |
800 | add_show_from_set | |
801 | (add_set_cmd ("static-members", class_support, var_boolean, | |
802 | (char *)&static_field_print, | |
803 | "Set printing of C++ static members.", | |
804 | &setprintlist), | |
805 | &showprintlist); | |
806 | /* Turn on printing of static fields. */ | |
807 | static_field_print = 1; | |
808 | ||
809 | add_show_from_set | |
810 | (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint, | |
811 | "Set printing of C++ virtual function tables.", | |
812 | &setprintlist), | |
813 | &showprintlist); | |
814 | ||
815 | add_show_from_set | |
816 | (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint, | |
817 | "Set printing of object's derived type based on vtable info.", | |
818 | &setprintlist), | |
819 | &showprintlist); | |
820 | ||
821 | /* Give people the defaults which they are used to. */ | |
822 | objectprint = 0; | |
823 | vtblprint = 0; | |
824 | obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *)); | |
825 | obstack_specify_allocation (&dont_print_statmem_obstack, | |
826 | 32 * sizeof (CORE_ADDR), sizeof (CORE_ADDR), | |
827 | xmalloc, free); | |
828 | } |