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