* cp-valprint.c (cp_print_value_fields, cp_print_value): Always
[deliverable/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 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
171 int fields_seen = 0;
172
173 CHECK_TYPEDEF (type);
174
175 fprintf_filtered (stream, "{");
176 len = TYPE_NFIELDS (type);
177 n_baseclasses = TYPE_N_BASECLASSES (type);
178
179 /* First, print out baseclasses such that we don't print
180 duplicates of virtual baseclasses. */
181
182 if (n_baseclasses > 0)
183 cp_print_value (type, real_type, valaddr, offset, address, stream,
184 format, recurse + 1, pretty, dont_print_vb);
185
186 /* Second, print out data fields */
187
188 /* If there are no data fields, or if the only field is the
189 * vtbl pointer, skip this part */
190 if ((len == n_baseclasses)
191 || ((len - n_baseclasses == 1)
192 && TYPE_HAS_VTABLE (type)
193 && strncmp (TYPE_FIELD_NAME (type, n_baseclasses),
194 hpacc_vtbl_ptr_name, 5) == 0)
195 || !len)
196 fprintf_filtered (stream, "<No data fields>");
197 else
198 {
199 struct obstack tmp_obstack = dont_print_statmem_obstack;
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 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 type **last_dont_print
430 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
431 struct obstack tmp_obstack = 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 /* Bump up the high-water mark. Now alpha is omega. */
442 obstack_finish (&dont_print_vb_obstack);
443 }
444
445 for (i = 0; i < n_baseclasses; i++)
446 {
447 int boffset;
448 int skip;
449 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
450 char *basename = TYPE_NAME (baseclass);
451 const gdb_byte *base_valaddr;
452
453 if (BASETYPE_VIA_VIRTUAL (type, i))
454 {
455 struct type **first_dont_print
456 = (struct type **) obstack_base (&dont_print_vb_obstack);
457
458 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
459 - first_dont_print;
460
461 while (--j >= 0)
462 if (baseclass == first_dont_print[j])
463 goto flush_it;
464
465 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
466 }
467
468 thisoffset = offset;
469 thistype = real_type;
470 if (TYPE_HAS_VTABLE (type) && BASETYPE_VIA_VIRTUAL (type, i))
471 {
472 /* Assume HP/Taligent runtime convention */
473 find_rt_vbase_offset (type, TYPE_BASECLASS (type, i),
474 valaddr, offset, &boffset, &skip);
475 if (skip >= 0)
476 error (_("Virtual base class offset not found from vtable while"
477 " printing"));
478 base_valaddr = valaddr;
479 }
480 else
481 {
482 boffset = baseclass_offset (type, i,
483 valaddr + offset,
484 address);
485 skip = ((boffset == -1) || (boffset + offset) < 0) ? 1 : -1;
486
487 if (BASETYPE_VIA_VIRTUAL (type, i))
488 {
489 /* The virtual base class pointer might have been
490 clobbered by the user program. Make sure that it
491 still points to a valid memory location. */
492
493 if (boffset != -1
494 && ((boffset + offset) < 0
495 || (boffset + offset) >= TYPE_LENGTH (type)))
496 {
497 /* FIXME (alloca): unsafe if baseclass is really really large. */
498 gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
499 base_valaddr = buf;
500 if (target_read_memory (address + boffset, buf,
501 TYPE_LENGTH (baseclass)) != 0)
502 skip = 1;
503 address = address + boffset;
504 thisoffset = 0;
505 boffset = 0;
506 thistype = baseclass;
507 }
508 else
509 base_valaddr = valaddr;
510 }
511 else
512 base_valaddr = valaddr;
513 }
514
515 /* now do the printing */
516 if (pretty)
517 {
518 fprintf_filtered (stream, "\n");
519 print_spaces_filtered (2 * recurse, stream);
520 }
521 fputs_filtered ("<", stream);
522 /* Not sure what the best notation is in the case where there is no
523 baseclass name. */
524 fputs_filtered (basename ? basename : "", stream);
525 fputs_filtered ("> = ", stream);
526
527
528 if (skip >= 1)
529 fprintf_filtered (stream, "<invalid address>");
530 else
531 cp_print_value_fields (baseclass, thistype, base_valaddr,
532 thisoffset + boffset, address + boffset,
533 stream, format,
534 recurse, pretty,
535 ((struct type **)
536 obstack_base (&dont_print_vb_obstack)),
537 0);
538 fputs_filtered (", ", stream);
539
540 flush_it:
541 ;
542 }
543
544 if (dont_print_vb == 0)
545 {
546 /* Free the space used to deal with the printing
547 of this type from top level. */
548 obstack_free (&dont_print_vb_obstack, last_dont_print);
549 /* Reset watermark so that we can continue protecting
550 ourselves from whatever we were protecting ourselves. */
551 dont_print_vb_obstack = tmp_obstack;
552 }
553 }
554
555 /* Print value of a static member.
556 To avoid infinite recursion when printing a class that contains
557 a static instance of the class, we keep the addresses of all printed
558 static member classes in an obstack and refuse to print them more
559 than once.
560
561 VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY
562 have the same meanings as in c_val_print. */
563
564 static void
565 cp_print_static_field (struct type *type,
566 struct value *val,
567 struct ui_file *stream,
568 int format,
569 int recurse,
570 enum val_prettyprint pretty)
571 {
572 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
573 {
574 CORE_ADDR *first_dont_print;
575 int i;
576
577 first_dont_print
578 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
579 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
580 - first_dont_print;
581
582 while (--i >= 0)
583 {
584 if (VALUE_ADDRESS (val) == first_dont_print[i])
585 {
586 fputs_filtered ("<same as static member of an already"
587 " seen type>",
588 stream);
589 return;
590 }
591 }
592
593 obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
594 sizeof (CORE_ADDR));
595
596 CHECK_TYPEDEF (type);
597 cp_print_value_fields (type, type, value_contents_all (val),
598 value_embedded_offset (val), VALUE_ADDRESS (val),
599 stream, format, recurse, pretty, NULL, 1);
600 return;
601 }
602 val_print (type, value_contents_all (val),
603 value_embedded_offset (val), VALUE_ADDRESS (val),
604 stream, format, 0, recurse, pretty);
605 }
606
607
608 /* Find the field in *DOMAIN, or its non-virtual base classes, with bit offset
609 OFFSET. Set *DOMAIN to the containing type and *FIELDNO to the containing
610 field number. If OFFSET is not exactly at the start of some field, set
611 *DOMAIN to NULL. */
612
613 void
614 cp_find_class_member (struct type **domain_p, int *fieldno,
615 LONGEST offset)
616 {
617 struct type *domain;
618 unsigned int i;
619 unsigned len;
620
621 *domain_p = check_typedef (*domain_p);
622 domain = *domain_p;
623 len = TYPE_NFIELDS (domain);
624
625 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
626 {
627 LONGEST bitpos = TYPE_FIELD_BITPOS (domain, i);
628
629 QUIT;
630 if (offset == bitpos)
631 {
632 *fieldno = i;
633 return;
634 }
635 }
636
637 for (i = 0; i < TYPE_N_BASECLASSES (domain); i++)
638 {
639 LONGEST bitpos = TYPE_FIELD_BITPOS (domain, i);
640 LONGEST bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (domain, i));
641
642 if (offset >= bitpos && offset < bitpos + bitsize)
643 {
644 *domain_p = TYPE_FIELD_TYPE (domain, i);
645 cp_find_class_member (domain_p, fieldno, offset - bitpos);
646 return;
647 }
648 }
649
650 *domain_p = NULL;
651 }
652
653 void
654 cp_print_class_member (const gdb_byte *valaddr, struct type *domain,
655 struct ui_file *stream, char *prefix)
656 {
657 /* VAL is a byte offset into the structure type DOMAIN.
658 Find the name of the field for that offset and
659 print it. */
660 unsigned int fieldno;
661
662 LONGEST val = unpack_long (builtin_type_long, valaddr);
663
664 /* Pointers to data members are usually byte offsets into an object.
665 Because a data member can have offset zero, and a NULL pointer to
666 member must be distinct from any valid non-NULL pointer to
667 member, either the value is biased or the NULL value has a
668 special representation; both are permitted by ISO C++. HP aCC
669 used a bias of 0x20000000; HP cfront used a bias of 1; g++ 3.x
670 and other compilers which use the Itanium ABI use -1 as the NULL
671 value. GDB only supports that last form; to add support for
672 another form, make this into a cp-abi hook. */
673
674 if (val == -1)
675 {
676 fprintf_filtered (stream, "NULL");
677 return;
678 }
679
680 cp_find_class_member (&domain, &fieldno, val << 3);
681
682 if (domain != NULL)
683 {
684 char *name;
685 fputs_filtered (prefix, stream);
686 name = type_name_no_tag (domain);
687 if (name)
688 fputs_filtered (name, stream);
689 else
690 c_type_print_base (domain, stream, 0, 0);
691 fprintf_filtered (stream, "::");
692 fputs_filtered (TYPE_FIELD_NAME (domain, fieldno), stream);
693 }
694 else
695 fprintf_filtered (stream, "%ld", (long) val);
696 }
697
698
699 /* This function prints out virtual table entries for a class; it
700 * recurses on the base classes to find all virtual functions
701 * available in a class.
702 *
703 * pai/1997-05-21 Note: As the name suggests, it's currently
704 * implemented for HP aCC runtime only. g++ objects are handled
705 * differently and I have made no attempt to fold that logic in
706 * here. The runtime layout is different for the two cases. Also,
707 * this currently has only the code for non-RRBC layouts generated by
708 * the HP aCC compiler; RRBC code is stubbed out and will have to be
709 * added later. */
710
711
712 static void
713 cp_print_hpacc_virtual_table_entries (struct type *type, int *vfuncs,
714 struct value *v, struct ui_file *stream,
715 int format, int recurse,
716 enum val_prettyprint pretty)
717 {
718 int fn, oi;
719
720 /* pai: FIXME this function doesn't work. It should handle a given
721 * virtual function only once (latest redefinition in class hierarchy)
722 */
723
724 /* Recursion on other classes that can share the same vtable */
725 struct type *pbc = primary_base_class (type);
726 if (pbc)
727 cp_print_hpacc_virtual_table_entries (pbc, vfuncs, v, stream, format,
728 recurse, pretty);
729
730 /* Now deal with vfuncs declared in this class */
731 for (fn = 0; fn < TYPE_NFN_FIELDS (type); fn++)
732 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (type, fn); oi++)
733 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (type, fn), oi))
734 {
735 char *vf_name;
736 const char *field_physname;
737
738 /* virtual function offset */
739 int vx = (TYPE_FN_FIELD_VOFFSET (TYPE_FN_FIELDLIST1 (type, fn), oi)
740 - 1);
741
742 /* Get the address of the vfunction entry */
743 struct value *vf = value_copy (v);
744 if (value_lazy (vf))
745 (void) value_fetch_lazy (vf);
746 /* adjust by offset */
747 /* NOTE: cagney/2005-01-02: THIS IS BOGUS. */
748 value_contents_writeable (vf)[0] += 4 * (HP_ACC_VFUNC_START + vx);
749 vf = value_ind (vf); /* get the entry */
750 /* make it a pointer */
751 deprecated_set_value_type (vf, value_type (v));
752
753 /* print out the entry */
754 common_val_print (vf, stream, format, 0, recurse + 1, pretty);
755 field_physname
756 = TYPE_FN_FIELD_PHYSNAME (TYPE_FN_FIELDLIST1 (type, fn), oi);
757 /* pai: (temp) FIXME Maybe this should be DMGL_ANSI */
758 vf_name = cplus_demangle (field_physname, DMGL_ARM);
759 fprintf_filtered (stream, " %s", vf_name);
760 if (--(*vfuncs) > 0)
761 fputs_filtered (", ", stream);
762 }
763 }
764
765
766
767 void
768 _initialize_cp_valprint (void)
769 {
770 add_setshow_boolean_cmd ("static-members", class_support,
771 &static_field_print, _("\
772 Set printing of C++ static members."), _("\
773 Show printing of C++ static members."), NULL,
774 NULL,
775 show_static_field_print,
776 &setprintlist, &showprintlist);
777 /* Turn on printing of static fields. */
778 static_field_print = 1;
779
780 add_setshow_boolean_cmd ("vtbl", class_support, &vtblprint, _("\
781 Set printing of C++ virtual function tables."), _("\
782 Show printing of C++ virtual function tables."), NULL,
783 NULL,
784 show_vtblprint,
785 &setprintlist, &showprintlist);
786
787 add_setshow_boolean_cmd ("object", class_support, &objectprint, _("\
788 Set printing of object's derived type based on vtable info."), _("\
789 Show printing of object's derived type based on vtable info."), NULL,
790 NULL,
791 show_objectprint,
792 &setprintlist, &showprintlist);
793
794 /* Give people the defaults which they are used to. */
795 objectprint = 0;
796 vtblprint = 0;
797 obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *));
798 obstack_specify_allocation (&dont_print_statmem_obstack,
799 32 * sizeof (CORE_ADDR), sizeof (CORE_ADDR),
800 xmalloc, xfree);
801 }
This page took 0.061911 seconds and 5 git commands to generate.