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