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