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