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