* cp-valprint.c (cp_print_static_field): Members of
[platform/upstream/binutils.git] / 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       if (obstack_object_size (&dont_print_statmem_obstack) > 0)
168         obstack_free (&dont_print_statmem_obstack, NULL);
169       if (obstack_object_size (&dont_print_stat_array_obstack) > 0)
170         obstack_free (&dont_print_stat_array_obstack, NULL);
171     }
172
173   fprintf_filtered (stream, "{");
174   len = TYPE_NFIELDS (type);
175   n_baseclasses = TYPE_N_BASECLASSES (type);
176
177   /* First, print out baseclasses such that we don't print
178      duplicates of virtual baseclasses.  */
179
180   if (n_baseclasses > 0)
181     cp_print_value (type, real_type, valaddr, offset, address, stream,
182                     recurse + 1, val, options, dont_print_vb);
183
184   /* Second, print out data fields */
185
186   /* If there are no data fields, skip this part */
187   if (len == n_baseclasses || !len)
188     fprintf_filtered (stream, "<No data fields>");
189   else
190     {
191       int statmem_obstack_initial_size = 0;
192       int stat_array_obstack_initial_size = 0;
193       
194       if (dont_print_statmem == 0)
195         {
196           statmem_obstack_initial_size =
197             obstack_object_size (&dont_print_statmem_obstack);
198
199           if (last_set_recurse != recurse)
200             {
201               stat_array_obstack_initial_size =
202                 obstack_object_size (&dont_print_stat_array_obstack);
203
204               last_set_recurse = recurse;
205             }
206         }
207
208       for (i = n_baseclasses; i < len; i++)
209         {
210           /* If requested, skip printing of static fields.  */
211           if (!options->static_field_print
212               && field_is_static (&TYPE_FIELD (type, i)))
213             continue;
214
215           if (fields_seen)
216             fprintf_filtered (stream, ", ");
217           else if (n_baseclasses > 0)
218             {
219               if (options->pretty)
220                 {
221                   fprintf_filtered (stream, "\n");
222                   print_spaces_filtered (2 + 2 * recurse, stream);
223                   fputs_filtered ("members of ", stream);
224                   fputs_filtered (type_name_no_tag (type), stream);
225                   fputs_filtered (": ", stream);
226                 }
227             }
228           fields_seen = 1;
229
230           if (options->pretty)
231             {
232               fprintf_filtered (stream, "\n");
233               print_spaces_filtered (2 + 2 * recurse, stream);
234             }
235           else
236             {
237               wrap_here (n_spaces (2 + 2 * recurse));
238             }
239           if (options->inspect_it)
240             {
241               if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
242                 fputs_filtered ("\"( ptr \"", stream);
243               else
244                 fputs_filtered ("\"( nodef \"", stream);
245               if (field_is_static (&TYPE_FIELD (type, i)))
246                 fputs_filtered ("static ", stream);
247               fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
248                                        current_language->la_language,
249                                        DMGL_PARAMS | DMGL_ANSI);
250               fputs_filtered ("\" \"", stream);
251               fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
252                                        current_language->la_language,
253                                        DMGL_PARAMS | DMGL_ANSI);
254               fputs_filtered ("\") \"", stream);
255             }
256           else
257             {
258               annotate_field_begin (TYPE_FIELD_TYPE (type, i));
259
260               if (field_is_static (&TYPE_FIELD (type, i)))
261                 fputs_filtered ("static ", stream);
262               fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
263                                        current_language->la_language,
264                                        DMGL_PARAMS | DMGL_ANSI);
265               annotate_field_name_end ();
266               /* do not print leading '=' in case of anonymous unions */
267               if (strcmp (TYPE_FIELD_NAME (type, i), ""))
268                 fputs_filtered (" = ", stream);
269               annotate_field_value ();
270             }
271
272           if (!field_is_static (&TYPE_FIELD (type, i))
273               && TYPE_FIELD_PACKED (type, i))
274             {
275               struct value *v;
276
277               /* Bitfields require special handling, especially due to byte
278                  order problems.  */
279               if (TYPE_FIELD_IGNORE (type, i))
280                 {
281                   fputs_filtered ("<optimized out or zero length>", stream);
282                 }
283               else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i),
284                                           TYPE_FIELD_BITSIZE (type, i)))
285                 {
286                   fputs_filtered (_("<value optimized out>"), stream);
287                 }
288               else
289                 {
290                   struct value_print_options opts = *options;
291
292                   opts.deref_ref = 0;
293                   v = value_from_longest
294                     (TYPE_FIELD_TYPE (type, i), 
295                      unpack_field_as_long (type, valaddr + offset, i));
296
297                   common_val_print (v, stream, recurse + 1, &opts,
298                                     current_language);
299                 }
300             }
301           else
302             {
303               if (TYPE_FIELD_IGNORE (type, i))
304                 {
305                   fputs_filtered ("<optimized out or zero length>", stream);
306                 }
307               else if (field_is_static (&TYPE_FIELD (type, i)))
308                 {
309                   struct value *v = value_static_field (type, i);
310
311                   if (v == NULL)
312                     fputs_filtered ("<optimized out>", stream);
313                   else
314                     cp_print_static_field (TYPE_FIELD_TYPE (type, i), v,
315                                            stream, recurse + 1, options);
316                 }
317               else
318                 {
319                   struct value_print_options opts = *options;
320
321                   opts.deref_ref = 0;
322                   val_print (TYPE_FIELD_TYPE (type, i),
323                              valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
324                              address,
325                              stream, recurse + 1, val, &opts,
326                              current_language);
327                 }
328             }
329           annotate_field_end ();
330         }
331
332       if (dont_print_statmem == 0)
333         {
334           int obstack_final_size =
335            obstack_object_size (&dont_print_statmem_obstack);
336
337           if (obstack_final_size > statmem_obstack_initial_size) {
338             /* In effect, a pop of the printed-statics stack.  */
339
340             void *free_to_ptr =
341               obstack_next_free (&dont_print_statmem_obstack) -
342               (obstack_final_size - statmem_obstack_initial_size);
343
344             obstack_free (&dont_print_statmem_obstack,
345                           free_to_ptr);
346           }
347
348           if (last_set_recurse != recurse)
349             {
350               int obstack_final_size =
351                 obstack_object_size (&dont_print_stat_array_obstack);
352               
353               if (obstack_final_size > stat_array_obstack_initial_size)
354                 {
355                   void *free_to_ptr =
356                     obstack_next_free (&dont_print_stat_array_obstack) -
357                     (obstack_final_size - stat_array_obstack_initial_size);
358
359                   obstack_free (&dont_print_stat_array_obstack,
360                                 free_to_ptr);
361                 }
362               last_set_recurse = -1;
363             }
364         }
365
366       if (options->pretty)
367         {
368           fprintf_filtered (stream, "\n");
369           print_spaces_filtered (2 * recurse, stream);
370         }
371     }                           /* if there are data fields */
372
373   fprintf_filtered (stream, "}");
374 }
375
376 /* Like cp_print_value_fields, but find the runtime type of the object
377    and pass it as the `real_type' argument to cp_print_value_fields.
378    This function is a hack to work around the fact that
379    common_val_print passes the embedded offset to val_print, but not
380    the enclosing type.  */
381
382 void
383 cp_print_value_fields_rtti (struct type *type,
384                             const gdb_byte *valaddr, int offset,
385                             CORE_ADDR address,
386                             struct ui_file *stream, int recurse,
387                             const struct value *val,
388                             const struct value_print_options *options,
389                             struct type **dont_print_vb, 
390                             int dont_print_statmem)
391 {
392   struct type *real_type = NULL;
393
394   /* We require all bits to be valid in order to attempt a
395      conversion.  */
396   if (value_bits_valid (val, TARGET_CHAR_BIT * offset,
397                         TARGET_CHAR_BIT * TYPE_LENGTH (type)))
398     {
399       struct value *value;
400       int full, top, using_enc;
401
402       /* Ugh, we have to convert back to a value here.  */
403       value = value_from_contents_and_address (type, valaddr + offset,
404                                                address + offset);
405       /* We don't actually care about most of the result here -- just the
406          type.  We already have the correct offset, due to how val_print
407          was initially called.  */
408       real_type = value_rtti_type (value, &full, &top, &using_enc);
409     }
410
411   if (!real_type)
412     real_type = type;
413
414   cp_print_value_fields (type, real_type, valaddr, offset,
415                          address, stream, recurse, val, options,
416                          dont_print_vb, dont_print_statmem);
417 }
418
419 /* Special val_print routine to avoid printing multiple copies of virtual
420    baseclasses.  */
421
422 static void
423 cp_print_value (struct type *type, struct type *real_type,
424                 const gdb_byte *valaddr, int offset, CORE_ADDR address,
425                 struct ui_file *stream, int recurse,
426                 const struct value *val,
427                 const struct value_print_options *options,
428                 struct type **dont_print_vb)
429 {
430   struct type **last_dont_print
431     = (struct type **) obstack_next_free (&dont_print_vb_obstack);
432   struct obstack tmp_obstack = dont_print_vb_obstack;
433   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
434   int thisoffset;
435   struct type *thistype;
436
437   if (dont_print_vb == 0)
438     {
439       /* If we're at top level, carve out a completely fresh
440          chunk of the obstack and use that until this particular
441          invocation returns.  */
442       /* Bump up the high-water mark.  Now alpha is omega.  */
443       obstack_finish (&dont_print_vb_obstack);
444     }
445
446   for (i = 0; i < n_baseclasses; i++)
447     {
448       int boffset;
449       int skip;
450       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
451       char *basename = TYPE_NAME (baseclass);
452       const gdb_byte *base_valaddr;
453
454       if (BASETYPE_VIA_VIRTUAL (type, i))
455         {
456           struct type **first_dont_print
457             = (struct type **) obstack_base (&dont_print_vb_obstack);
458
459           int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
460             - first_dont_print;
461
462           while (--j >= 0)
463             if (baseclass == first_dont_print[j])
464               goto flush_it;
465
466           obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
467         }
468
469       thisoffset = offset;
470       thistype = real_type;
471
472       boffset = baseclass_offset (type, i, valaddr + offset, address + offset);
473       skip = ((boffset == -1) || (boffset + offset) < 0) ? 1 : -1;
474
475       if (BASETYPE_VIA_VIRTUAL (type, i))
476         {
477           /* The virtual base class pointer might have been
478              clobbered by the user program. Make sure that it
479              still points to a valid memory location.  */
480
481           if (boffset != -1
482               && ((boffset + offset) < 0
483                   || (boffset + offset) >= TYPE_LENGTH (real_type)))
484             {
485               /* FIXME (alloca): unsafe if baseclass is really really large. */
486               gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
487
488               base_valaddr = buf;
489               if (target_read_memory (address + boffset, buf,
490                                       TYPE_LENGTH (baseclass)) != 0)
491                 skip = 1;
492               address = address + boffset;
493               thisoffset = 0;
494               boffset = 0;
495               thistype = baseclass;
496             }
497           else
498             base_valaddr = valaddr;
499         }
500       else
501         base_valaddr = valaddr;
502
503       /* now do the printing */
504       if (options->pretty)
505         {
506           fprintf_filtered (stream, "\n");
507           print_spaces_filtered (2 * recurse, stream);
508         }
509       fputs_filtered ("<", stream);
510       /* Not sure what the best notation is in the case where there is no
511          baseclass name.  */
512       fputs_filtered (basename ? basename : "", stream);
513       fputs_filtered ("> = ", stream);
514
515
516       if (skip >= 1)
517         fprintf_filtered (stream, "<invalid address>");
518       else
519         {
520           int result = 0;
521
522           /* Attempt to run the Python pretty-printers on the
523              baseclass if possible.  */
524           if (!options->raw)
525             result = apply_val_pretty_printer (baseclass, base_valaddr,
526                                                thisoffset + boffset,
527                                                address,
528                                                stream, recurse, val, 
529                                                options,
530                                                current_language);
531                   
532           if (!result)
533             cp_print_value_fields (baseclass, thistype, base_valaddr,
534                                    thisoffset + boffset, address,
535                                    stream, recurse, val, options,
536                                    ((struct type **)
537                                     obstack_base (&dont_print_vb_obstack)),
538                                    0);
539         }
540       fputs_filtered (", ", stream);
541
542     flush_it:
543       ;
544     }
545
546   if (dont_print_vb == 0)
547     {
548       /* Free the space used to deal with the printing
549          of this type from top level.  */
550       obstack_free (&dont_print_vb_obstack, last_dont_print);
551       /* Reset watermark so that we can continue protecting
552          ourselves from whatever we were protecting ourselves.  */
553       dont_print_vb_obstack = tmp_obstack;
554     }
555 }
556
557 /* Print value of a static member.
558    To avoid infinite recursion when printing a class that contains
559    a static instance of the class, we keep the addresses of all printed
560    static member classes in an obstack and refuse to print them more
561    than once.
562
563    VAL contains the value to print, TYPE, STREAM, RECURSE, and OPTIONS
564    have the same meanings as in c_val_print.  */
565
566 static void
567 cp_print_static_field (struct type *type,
568                        struct value *val,
569                        struct ui_file *stream,
570                        int recurse,
571                        const struct value_print_options *options)
572 {
573   struct value_print_options opts;
574   
575   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
576     {
577       CORE_ADDR *first_dont_print;
578       CORE_ADDR addr;
579       int i;
580
581       first_dont_print
582         = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
583       i = obstack_object_size (&dont_print_statmem_obstack)
584         / sizeof (CORE_ADDR);
585
586       while (--i >= 0)
587         {
588           if (value_address (val) == first_dont_print[i])
589             {
590               fputs_filtered ("<same as static member of an already"
591                               " seen type>",
592                               stream);
593               return;
594             }
595         }
596
597       addr = value_address (val);
598       obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
599                     sizeof (CORE_ADDR));
600       CHECK_TYPEDEF (type);
601       cp_print_value_fields (type, value_enclosing_type (val),
602                              value_contents_for_printing (val),
603                              value_embedded_offset (val), addr,
604                              stream, recurse,
605                              val, options, NULL, 1);
606       return;
607     }
608
609   if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
610     {
611       struct type **first_dont_print;
612       int i;
613       struct type *target_type = TYPE_TARGET_TYPE (type);
614
615       first_dont_print
616         = (struct type **) obstack_base (&dont_print_stat_array_obstack);
617       i = obstack_object_size (&dont_print_stat_array_obstack)
618         / sizeof (struct type *);
619
620       while (--i >= 0)
621         {
622           if (target_type == first_dont_print[i])
623             {
624               fputs_filtered ("<same as static member of an already"
625                               " seen type>",
626                               stream);
627               return;
628             }
629         }
630
631       obstack_grow (&dont_print_stat_array_obstack, (char *) &target_type,
632                     sizeof (struct type *));
633     }
634
635   opts = *options;
636   opts.deref_ref = 0;
637   val_print (type, value_contents_for_printing (val), 
638              value_embedded_offset (val), value_address (val),
639              stream, recurse,
640              val, &opts, current_language);
641 }
642
643
644 /* Find the field in *DOMAIN, or its non-virtual base classes, with bit offset
645    OFFSET.  Set *DOMAIN to the containing type and *FIELDNO to the containing
646    field number.  If OFFSET is not exactly at the start of some field, set
647    *DOMAIN to NULL.  */
648
649 static void
650 cp_find_class_member (struct type **domain_p, int *fieldno,
651                       LONGEST offset)
652 {
653   struct type *domain;
654   unsigned int i;
655   unsigned len;
656
657   *domain_p = check_typedef (*domain_p);
658   domain = *domain_p;
659   len = TYPE_NFIELDS (domain);
660
661   for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
662     {
663       LONGEST bitpos = TYPE_FIELD_BITPOS (domain, i);
664
665       QUIT;
666       if (offset == bitpos)
667         {
668           *fieldno = i;
669           return;
670         }
671     }
672
673   for (i = 0; i < TYPE_N_BASECLASSES (domain); i++)
674     {
675       LONGEST bitpos = TYPE_FIELD_BITPOS (domain, i);
676       LONGEST bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (domain, i));
677
678       if (offset >= bitpos && offset < bitpos + bitsize)
679         {
680           *domain_p = TYPE_FIELD_TYPE (domain, i);
681           cp_find_class_member (domain_p, fieldno, offset - bitpos);
682           return;
683         }
684     }
685
686   *domain_p = NULL;
687 }
688
689 void
690 cp_print_class_member (const gdb_byte *valaddr, struct type *type,
691                        struct ui_file *stream, char *prefix)
692 {
693   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
694
695   /* VAL is a byte offset into the structure type DOMAIN.
696      Find the name of the field for that offset and
697      print it.  */
698   struct type *domain = TYPE_DOMAIN_TYPE (type);
699   LONGEST val;
700   unsigned int fieldno;
701
702   val = extract_signed_integer (valaddr, TYPE_LENGTH (type), byte_order);
703
704   /* Pointers to data members are usually byte offsets into an object.
705      Because a data member can have offset zero, and a NULL pointer to
706      member must be distinct from any valid non-NULL pointer to
707      member, either the value is biased or the NULL value has a
708      special representation; both are permitted by ISO C++.  HP aCC
709      used a bias of 0x20000000; HP cfront used a bias of 1; g++ 3.x
710      and other compilers which use the Itanium ABI use -1 as the NULL
711      value.  GDB only supports that last form; to add support for
712      another form, make this into a cp-abi hook.  */
713
714   if (val == -1)
715     {
716       fprintf_filtered (stream, "NULL");
717       return;
718     }
719
720   cp_find_class_member (&domain, &fieldno, val << 3);
721
722   if (domain != NULL)
723     {
724       char *name;
725
726       fputs_filtered (prefix, stream);
727       name = type_name_no_tag (domain);
728       if (name)
729         fputs_filtered (name, stream);
730       else
731         c_type_print_base (domain, stream, 0, 0);
732       fprintf_filtered (stream, "::");
733       fputs_filtered (TYPE_FIELD_NAME (domain, fieldno), stream);
734     }
735   else
736     fprintf_filtered (stream, "%ld", (long) val);
737 }
738
739
740 void
741 _initialize_cp_valprint (void)
742 {
743   add_setshow_boolean_cmd ("static-members", class_support,
744                            &user_print_options.static_field_print, _("\
745 Set printing of C++ static members."), _("\
746 Show printing of C++ static members."), NULL,
747                            NULL,
748                            show_static_field_print,
749                            &setprintlist, &showprintlist);
750
751   add_setshow_boolean_cmd ("vtbl", class_support,
752                            &user_print_options.vtblprint, _("\
753 Set printing of C++ virtual function tables."), _("\
754 Show printing of C++ virtual function tables."), NULL,
755                            NULL,
756                            show_vtblprint,
757                            &setprintlist, &showprintlist);
758
759   add_setshow_boolean_cmd ("object", class_support,
760                            &user_print_options.objectprint, _("\
761 Set printing of object's derived type based on vtable info."), _("\
762 Show printing of object's derived type based on vtable info."), NULL,
763                            NULL,
764                            show_objectprint,
765                            &setprintlist, &showprintlist);
766
767   obstack_begin (&dont_print_stat_array_obstack, 32 * sizeof (struct type *));
768   obstack_begin (&dont_print_statmem_obstack, 32 * sizeof (CORE_ADDR));
769   obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *));
770 }