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