Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
1 /* Support for printing C++ values for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2019 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 3 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, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21
22 /* Local non-gdb includes. */
23 #include "annotate.h"
24 #include "c-lang.h"
25 #include "command.h"
26 #include "common/byte-vector.h"
27 #include "cp-abi.h"
28 #include "cp-support.h"
29 #include "demangle.h"
30 #include "expression.h"
31 #include "extension.h"
32 #include "gdb_obstack.h"
33 #include "gdbcmd.h"
34 #include "gdbtypes.h"
35 #include "language.h"
36 #include "symtab.h"
37 #include "target.h"
38 #include "typeprint.h"
39 #include "valprint.h"
40 #include "value.h"
41
42 /* Controls printing of vtbl's. */
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 static void
55 show_objectprint (struct ui_file *file, int from_tty,
56 struct cmd_list_element *c,
57 const char *value)
58 {
59 fprintf_filtered (file, _("\
60 Printing of object's derived type based on vtable info is %s.\n"),
61 value);
62 }
63
64 static void
65 show_static_field_print (struct ui_file *file, int from_tty,
66 struct cmd_list_element *c,
67 const char *value)
68 {
69 fprintf_filtered (file,
70 _("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 static struct obstack dont_print_stat_array_obstack;
78
79 static void cp_print_static_field (struct type *, struct value *,
80 struct ui_file *, int,
81 const struct value_print_options *);
82
83 static void cp_print_value (struct type *, struct type *,
84 LONGEST,
85 CORE_ADDR, struct ui_file *,
86 int, struct value *,
87 const struct value_print_options *,
88 struct type **);
89
90
91 /* GCC versions after 2.4.5 use this. */
92 extern const char vtbl_ptr_name[] = "__vtbl_ptr_type";
93
94 /* Return truth value for assertion that TYPE is of the type
95 "pointer to virtual function". */
96
97 int
98 cp_is_vtbl_ptr_type (struct type *type)
99 {
100 const char *type_name = TYPE_NAME (type);
101
102 return (type_name != NULL && !strcmp (type_name, vtbl_ptr_name));
103 }
104
105 /* Return truth value for the assertion that TYPE is of the type
106 "pointer to virtual function table". */
107
108 int
109 cp_is_vtbl_member (struct type *type)
110 {
111 /* With older versions of g++, the vtbl field pointed to an array of
112 structures. Nowadays it points directly to the structure. */
113 if (TYPE_CODE (type) == TYPE_CODE_PTR)
114 {
115 type = TYPE_TARGET_TYPE (type);
116 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
117 {
118 type = TYPE_TARGET_TYPE (type);
119 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */
120 || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
121 {
122 /* Virtual functions tables are full of pointers
123 to virtual functions. */
124 return cp_is_vtbl_ptr_type (type);
125 }
126 }
127 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) /* if not using thunks */
128 {
129 return cp_is_vtbl_ptr_type (type);
130 }
131 else if (TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
132 {
133 /* The type name of the thunk pointer is NULL when using
134 dwarf2. We could test for a pointer to a function, but
135 there is no type info for the virtual table either, so it
136 wont help. */
137 return cp_is_vtbl_ptr_type (type);
138 }
139 }
140 return 0;
141 }
142
143 /* Mutually recursive subroutines of cp_print_value and c_val_print to
144 print out a structure's fields: cp_print_value_fields and
145 cp_print_value.
146
147 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the same
148 meanings as in cp_print_value and c_val_print.
149
150 2nd argument REAL_TYPE is used to carry over the type of the
151 derived class across the recursion to base classes.
152
153 DONT_PRINT is an array of baseclass types that we should not print,
154 or zero if called from top level. */
155
156 void
157 cp_print_value_fields (struct type *type, struct type *real_type,
158 LONGEST offset,
159 CORE_ADDR address, struct ui_file *stream,
160 int recurse, struct value *val,
161 const struct value_print_options *options,
162 struct type **dont_print_vb,
163 int dont_print_statmem)
164 {
165 int i, len, n_baseclasses;
166 int fields_seen = 0;
167 static int last_set_recurse = -1;
168
169 type = check_typedef (type);
170
171 if (recurse == 0)
172 {
173 /* Any object can be left on obstacks only during an unexpected
174 error. */
175
176 if (obstack_object_size (&dont_print_statmem_obstack) > 0)
177 {
178 obstack_free (&dont_print_statmem_obstack, NULL);
179 obstack_begin (&dont_print_statmem_obstack,
180 32 * sizeof (CORE_ADDR));
181 }
182 if (obstack_object_size (&dont_print_stat_array_obstack) > 0)
183 {
184 obstack_free (&dont_print_stat_array_obstack, NULL);
185 obstack_begin (&dont_print_stat_array_obstack,
186 32 * sizeof (struct type *));
187 }
188 }
189
190 fprintf_filtered (stream, "{");
191 len = TYPE_NFIELDS (type);
192 n_baseclasses = TYPE_N_BASECLASSES (type);
193
194 /* First, print out baseclasses such that we don't print
195 duplicates of virtual baseclasses. */
196
197 if (n_baseclasses > 0)
198 cp_print_value (type, real_type,
199 offset, address, stream,
200 recurse + 1, val, options,
201 dont_print_vb);
202
203 /* Second, print out data fields */
204
205 /* If there are no data fields, skip this part */
206 if (len == n_baseclasses || !len)
207 fprintf_filtered (stream, "<No data fields>");
208 else
209 {
210 size_t statmem_obstack_initial_size = 0;
211 size_t stat_array_obstack_initial_size = 0;
212 struct type *vptr_basetype = NULL;
213 int vptr_fieldno;
214
215 if (dont_print_statmem == 0)
216 {
217 statmem_obstack_initial_size =
218 obstack_object_size (&dont_print_statmem_obstack);
219
220 if (last_set_recurse != recurse)
221 {
222 stat_array_obstack_initial_size =
223 obstack_object_size (&dont_print_stat_array_obstack);
224
225 last_set_recurse = recurse;
226 }
227 }
228
229 vptr_fieldno = get_vptr_fieldno (type, &vptr_basetype);
230 for (i = n_baseclasses; i < len; i++)
231 {
232 const gdb_byte *valaddr = value_contents_for_printing (val);
233
234 /* If requested, skip printing of static fields. */
235 if (!options->static_field_print
236 && field_is_static (&TYPE_FIELD (type, i)))
237 continue;
238
239 if (fields_seen)
240 {
241 fputs_filtered (",", stream);
242 if (!options->prettyformat)
243 fputs_filtered (" ", stream);
244 }
245 else if (n_baseclasses > 0)
246 {
247 if (options->prettyformat)
248 {
249 fprintf_filtered (stream, "\n");
250 print_spaces_filtered (2 + 2 * recurse, stream);
251 fputs_filtered ("members of ", stream);
252 fputs_filtered (TYPE_NAME (type), stream);
253 fputs_filtered (":", stream);
254 }
255 }
256 fields_seen = 1;
257
258 if (options->prettyformat)
259 {
260 fprintf_filtered (stream, "\n");
261 print_spaces_filtered (2 + 2 * recurse, stream);
262 }
263 else
264 {
265 wrap_here (n_spaces (2 + 2 * recurse));
266 }
267
268 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
269
270 if (field_is_static (&TYPE_FIELD (type, i)))
271 fputs_filtered ("static ", stream);
272 fprintf_symbol_filtered (stream,
273 TYPE_FIELD_NAME (type, i),
274 current_language->la_language,
275 DMGL_PARAMS | DMGL_ANSI);
276 annotate_field_name_end ();
277 /* Do not print leading '=' in case of anonymous
278 unions. */
279 if (strcmp (TYPE_FIELD_NAME (type, i), ""))
280 fputs_filtered (" = ", stream);
281 annotate_field_value ();
282
283 if (!field_is_static (&TYPE_FIELD (type, i))
284 && TYPE_FIELD_PACKED (type, i))
285 {
286 struct value *v;
287
288 /* Bitfields require special handling, especially due to
289 byte order problems. */
290 if (TYPE_FIELD_IGNORE (type, i))
291 {
292 fputs_filtered ("<optimized out or zero length>", stream);
293 }
294 else if (value_bits_synthetic_pointer (val,
295 TYPE_FIELD_BITPOS (type,
296 i),
297 TYPE_FIELD_BITSIZE (type,
298 i)))
299 {
300 fputs_filtered (_("<synthetic pointer>"), stream);
301 }
302 else
303 {
304 struct value_print_options opts = *options;
305
306 opts.deref_ref = 0;
307
308 v = value_field_bitfield (type, i, valaddr, offset, val);
309
310 common_val_print (v, stream, recurse + 1, &opts,
311 current_language);
312 }
313 }
314 else
315 {
316 if (TYPE_FIELD_IGNORE (type, i))
317 {
318 fputs_filtered ("<optimized out or zero length>",
319 stream);
320 }
321 else if (field_is_static (&TYPE_FIELD (type, i)))
322 {
323 struct value *v = NULL;
324
325 TRY
326 {
327 v = value_static_field (type, i);
328 }
329
330 CATCH (ex, RETURN_MASK_ERROR)
331 {
332 fprintf_filtered (stream,
333 _("<error reading variable: %s>"),
334 ex.message);
335 }
336 END_CATCH
337
338 cp_print_static_field (TYPE_FIELD_TYPE (type, i),
339 v, stream, recurse + 1,
340 options);
341 }
342 else if (i == vptr_fieldno && type == vptr_basetype)
343 {
344 int i_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
345 struct type *i_type = TYPE_FIELD_TYPE (type, i);
346
347 if (valprint_check_validity (stream, i_type, i_offset, val))
348 {
349 CORE_ADDR addr;
350
351 addr = extract_typed_address (valaddr + i_offset, i_type);
352 print_function_pointer_address (options,
353 get_type_arch (type),
354 addr, stream);
355 }
356 }
357 else
358 {
359 struct value_print_options opts = *options;
360
361 opts.deref_ref = 0;
362 val_print (TYPE_FIELD_TYPE (type, i),
363 offset + TYPE_FIELD_BITPOS (type, i) / 8,
364 address,
365 stream, recurse + 1, val, &opts,
366 current_language);
367 }
368 }
369 annotate_field_end ();
370 }
371
372 if (dont_print_statmem == 0)
373 {
374 size_t obstack_final_size =
375 obstack_object_size (&dont_print_statmem_obstack);
376
377 if (obstack_final_size > statmem_obstack_initial_size)
378 {
379 /* In effect, a pop of the printed-statics stack. */
380 size_t shrink_bytes
381 = statmem_obstack_initial_size - obstack_final_size;
382 obstack_blank_fast (&dont_print_statmem_obstack, shrink_bytes);
383 }
384
385 if (last_set_recurse != recurse)
386 {
387 obstack_final_size =
388 obstack_object_size (&dont_print_stat_array_obstack);
389
390 if (obstack_final_size > stat_array_obstack_initial_size)
391 {
392 void *free_to_ptr =
393 (char *) obstack_next_free (&dont_print_stat_array_obstack)
394 - (obstack_final_size
395 - stat_array_obstack_initial_size);
396
397 obstack_free (&dont_print_stat_array_obstack,
398 free_to_ptr);
399 }
400 last_set_recurse = -1;
401 }
402 }
403
404 if (options->prettyformat)
405 {
406 fprintf_filtered (stream, "\n");
407 print_spaces_filtered (2 * recurse, stream);
408 }
409 } /* if there are data fields */
410
411 fprintf_filtered (stream, "}");
412 }
413
414 /* Like cp_print_value_fields, but find the runtime type of the object
415 and pass it as the `real_type' argument to cp_print_value_fields.
416 This function is a hack to work around the fact that
417 common_val_print passes the embedded offset to val_print, but not
418 the enclosing type. */
419
420 void
421 cp_print_value_fields_rtti (struct type *type,
422 const gdb_byte *valaddr, LONGEST offset,
423 CORE_ADDR address,
424 struct ui_file *stream, int recurse,
425 struct value *val,
426 const struct value_print_options *options,
427 struct type **dont_print_vb,
428 int dont_print_statmem)
429 {
430 struct type *real_type = NULL;
431
432 /* We require all bits to be valid in order to attempt a
433 conversion. */
434 if (!value_bits_any_optimized_out (val,
435 TARGET_CHAR_BIT * offset,
436 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
437 {
438 struct value *value;
439 int full, using_enc;
440 LONGEST top;
441
442 /* Ugh, we have to convert back to a value here. */
443 value = value_from_contents_and_address (type, valaddr + offset,
444 address + offset);
445 type = value_type (value);
446 /* We don't actually care about most of the result here -- just
447 the type. We already have the correct offset, due to how
448 val_print was initially called. */
449 real_type = value_rtti_type (value, &full, &top, &using_enc);
450 }
451
452 if (!real_type)
453 real_type = type;
454
455 cp_print_value_fields (type, real_type, offset,
456 address, stream, recurse, val, options,
457 dont_print_vb, dont_print_statmem);
458 }
459
460 /* Special val_print routine to avoid printing multiple copies of
461 virtual baseclasses. */
462
463 static void
464 cp_print_value (struct type *type, struct type *real_type,
465 LONGEST offset,
466 CORE_ADDR address, struct ui_file *stream,
467 int recurse, struct value *val,
468 const struct value_print_options *options,
469 struct type **dont_print_vb)
470 {
471 struct type **last_dont_print
472 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
473 struct obstack tmp_obstack = dont_print_vb_obstack;
474 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
475 LONGEST thisoffset;
476 struct type *thistype;
477 const gdb_byte *valaddr = value_contents_for_printing (val);
478
479 if (dont_print_vb == 0)
480 {
481 /* If we're at top level, carve out a completely fresh chunk of
482 the obstack and use that until this particular invocation
483 returns. */
484 /* Bump up the high-water mark. Now alpha is omega. */
485 obstack_finish (&dont_print_vb_obstack);
486 }
487
488 for (i = 0; i < n_baseclasses; i++)
489 {
490 LONGEST boffset = 0;
491 int skip = 0;
492 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
493 const char *basename = TYPE_NAME (baseclass);
494 struct value *base_val = NULL;
495
496 if (BASETYPE_VIA_VIRTUAL (type, i))
497 {
498 struct type **first_dont_print
499 = (struct type **) obstack_base (&dont_print_vb_obstack);
500
501 int j = (struct type **)
502 obstack_next_free (&dont_print_vb_obstack) - first_dont_print;
503
504 while (--j >= 0)
505 if (baseclass == first_dont_print[j])
506 goto flush_it;
507
508 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
509 }
510
511 thisoffset = offset;
512 thistype = real_type;
513
514 TRY
515 {
516 boffset = baseclass_offset (type, i, valaddr, offset, address, val);
517 }
518 CATCH (ex, RETURN_MASK_ERROR)
519 {
520 if (ex.error == NOT_AVAILABLE_ERROR)
521 skip = -1;
522 else
523 skip = 1;
524 }
525 END_CATCH
526
527 if (skip == 0)
528 {
529 if (BASETYPE_VIA_VIRTUAL (type, i))
530 {
531 /* The virtual base class pointer might have been
532 clobbered by the user program. Make sure that it
533 still points to a valid memory location. */
534
535 if ((boffset + offset) < 0
536 || (boffset + offset) >= TYPE_LENGTH (real_type))
537 {
538 gdb::byte_vector buf (TYPE_LENGTH (baseclass));
539
540 if (target_read_memory (address + boffset, buf.data (),
541 TYPE_LENGTH (baseclass)) != 0)
542 skip = 1;
543 base_val = value_from_contents_and_address (baseclass,
544 buf.data (),
545 address + boffset);
546 baseclass = value_type (base_val);
547 thisoffset = 0;
548 boffset = 0;
549 thistype = baseclass;
550 }
551 else
552 {
553 base_val = val;
554 }
555 }
556 else
557 {
558 base_val = val;
559 }
560 }
561
562 /* Now do the printing. */
563 if (options->prettyformat)
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
570 no baseclass name. */
571 fputs_filtered (basename ? basename : "", stream);
572 fputs_filtered ("> = ", stream);
573
574 if (skip < 0)
575 val_print_unavailable (stream);
576 else if (skip > 0)
577 val_print_invalid_address (stream);
578 else
579 {
580 int result = 0;
581
582 /* Attempt to run an extension language pretty-printer on the
583 baseclass if possible. */
584 if (!options->raw)
585 result
586 = apply_ext_lang_val_pretty_printer (baseclass,
587 thisoffset + boffset,
588 value_address (base_val),
589 stream, recurse,
590 base_val, options,
591 current_language);
592
593 if (!result)
594 cp_print_value_fields (baseclass, thistype,
595 thisoffset + boffset,
596 value_address (base_val),
597 stream, recurse, base_val, options,
598 ((struct type **)
599 obstack_base (&dont_print_vb_obstack)),
600 0);
601 }
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
611 of this type from top level. */
612 obstack_free (&dont_print_vb_obstack, last_dont_print);
613 /* Reset watermark so that we can continue protecting
614 ourselves from whatever we were protecting ourselves. */
615 dont_print_vb_obstack = tmp_obstack;
616 }
617 }
618
619 /* Print value of a static member. To avoid infinite recursion when
620 printing a class that contains a static instance of the class, we
621 keep the addresses of all printed static member classes in an
622 obstack and refuse to print them more than once.
623
624 VAL contains the value to print, TYPE, STREAM, RECURSE, and OPTIONS
625 have the same meanings as in c_val_print. */
626
627 static void
628 cp_print_static_field (struct type *type,
629 struct value *val,
630 struct ui_file *stream,
631 int recurse,
632 const struct value_print_options *options)
633 {
634 struct value_print_options opts;
635
636 if (value_entirely_optimized_out (val))
637 {
638 val_print_optimized_out (val, stream);
639 return;
640 }
641
642 struct type *real_type = check_typedef (type);
643 if (TYPE_CODE (real_type) == TYPE_CODE_STRUCT)
644 {
645 CORE_ADDR *first_dont_print;
646 CORE_ADDR addr;
647 int i;
648
649 first_dont_print
650 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
651 i = obstack_object_size (&dont_print_statmem_obstack)
652 / sizeof (CORE_ADDR);
653
654 while (--i >= 0)
655 {
656 if (value_address (val) == first_dont_print[i])
657 {
658 fputs_filtered ("<same as static member of an already"
659 " seen type>",
660 stream);
661 return;
662 }
663 }
664
665 addr = value_address (val);
666 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
667 sizeof (CORE_ADDR));
668 cp_print_value_fields (type, value_enclosing_type (val),
669 value_embedded_offset (val), addr,
670 stream, recurse, val,
671 options, NULL, 1);
672 return;
673 }
674
675 if (TYPE_CODE (real_type) == TYPE_CODE_ARRAY)
676 {
677 struct type **first_dont_print;
678 int i;
679 struct type *target_type = TYPE_TARGET_TYPE (type);
680
681 first_dont_print
682 = (struct type **) obstack_base (&dont_print_stat_array_obstack);
683 i = obstack_object_size (&dont_print_stat_array_obstack)
684 / sizeof (struct type *);
685
686 while (--i >= 0)
687 {
688 if (target_type == first_dont_print[i])
689 {
690 fputs_filtered ("<same as static member of an already"
691 " seen type>",
692 stream);
693 return;
694 }
695 }
696
697 obstack_grow (&dont_print_stat_array_obstack,
698 (char *) &target_type,
699 sizeof (struct type *));
700 }
701
702 opts = *options;
703 opts.deref_ref = 0;
704 val_print (type,
705 value_embedded_offset (val),
706 value_address (val),
707 stream, recurse, val,
708 &opts, current_language);
709 }
710
711 /* Find the field in *SELF, or its non-virtual base classes, with
712 bit offset OFFSET. Set *SELF to the containing type and *FIELDNO
713 to the containing field number. If OFFSET is not exactly at the
714 start of some field, set *SELF to NULL. */
715
716 static void
717 cp_find_class_member (struct type **self_p, int *fieldno,
718 LONGEST offset)
719 {
720 struct type *self;
721 unsigned int i;
722 unsigned len;
723
724 *self_p = check_typedef (*self_p);
725 self = *self_p;
726 len = TYPE_NFIELDS (self);
727
728 for (i = TYPE_N_BASECLASSES (self); i < len; i++)
729 {
730 LONGEST bitpos = TYPE_FIELD_BITPOS (self, i);
731
732 QUIT;
733 if (offset == bitpos)
734 {
735 *fieldno = i;
736 return;
737 }
738 }
739
740 for (i = 0; i < TYPE_N_BASECLASSES (self); i++)
741 {
742 LONGEST bitpos = TYPE_FIELD_BITPOS (self, i);
743 LONGEST bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (self, i));
744
745 if (offset >= bitpos && offset < bitpos + bitsize)
746 {
747 *self_p = TYPE_FIELD_TYPE (self, i);
748 cp_find_class_member (self_p, fieldno, offset - bitpos);
749 return;
750 }
751 }
752
753 *self_p = NULL;
754 }
755
756 void
757 cp_print_class_member (const gdb_byte *valaddr, struct type *type,
758 struct ui_file *stream, const char *prefix)
759 {
760 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
761
762 /* VAL is a byte offset into the structure type SELF_TYPE.
763 Find the name of the field for that offset and
764 print it. */
765 struct type *self_type = TYPE_SELF_TYPE (type);
766 LONGEST val;
767 int fieldno;
768
769 val = extract_signed_integer (valaddr,
770 TYPE_LENGTH (type),
771 byte_order);
772
773 /* Pointers to data members are usually byte offsets into an object.
774 Because a data member can have offset zero, and a NULL pointer to
775 member must be distinct from any valid non-NULL pointer to
776 member, either the value is biased or the NULL value has a
777 special representation; both are permitted by ISO C++. HP aCC
778 used a bias of 0x20000000; HP cfront used a bias of 1; g++ 3.x
779 and other compilers which use the Itanium ABI use -1 as the NULL
780 value. GDB only supports that last form; to add support for
781 another form, make this into a cp-abi hook. */
782
783 if (val == -1)
784 {
785 fprintf_filtered (stream, "NULL");
786 return;
787 }
788
789 cp_find_class_member (&self_type, &fieldno, val << 3);
790
791 if (self_type != NULL)
792 {
793 const char *name;
794
795 fputs_filtered (prefix, stream);
796 name = TYPE_NAME (self_type);
797 if (name)
798 fputs_filtered (name, stream);
799 else
800 c_type_print_base (self_type, stream, 0, 0, &type_print_raw_options);
801 fprintf_filtered (stream, "::");
802 fputs_filtered (TYPE_FIELD_NAME (self_type, fieldno), stream);
803 }
804 else
805 fprintf_filtered (stream, "%ld", (long) val);
806 }
807
808
809 void
810 _initialize_cp_valprint (void)
811 {
812 add_setshow_boolean_cmd ("static-members", class_support,
813 &user_print_options.static_field_print, _("\
814 Set printing of C++ static members."), _("\
815 Show printing of C++ static members."), NULL,
816 NULL,
817 show_static_field_print,
818 &setprintlist, &showprintlist);
819
820 add_setshow_boolean_cmd ("vtbl", class_support,
821 &user_print_options.vtblprint, _("\
822 Set printing of C++ virtual function tables."), _("\
823 Show printing of C++ virtual function tables."), NULL,
824 NULL,
825 show_vtblprint,
826 &setprintlist, &showprintlist);
827
828 add_setshow_boolean_cmd ("object", class_support,
829 &user_print_options.objectprint, _("\
830 Set printing of object's derived type based on vtable info."), _("\
831 Show printing of object's derived type based on vtable info."), NULL,
832 NULL,
833 show_objectprint,
834 &setprintlist, &showprintlist);
835
836 obstack_begin (&dont_print_stat_array_obstack,
837 32 * sizeof (struct type *));
838 obstack_begin (&dont_print_statmem_obstack,
839 32 * sizeof (CORE_ADDR));
840 obstack_begin (&dont_print_vb_obstack,
841 32 * sizeof (struct type *));
842 }
This page took 0.065583 seconds and 5 git commands to generate.