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