gdb:
[external/binutils.git] / gdb / c-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    1998, 1999, 2000, 2001, 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_string.h"
24 #include "symtab.h"
25 #include "gdbtypes.h"
26 #include "expression.h"
27 #include "value.h"
28 #include "valprint.h"
29 #include "language.h"
30 #include "c-lang.h"
31 #include "cp-abi.h"
32 #include "target.h"
33 \f
34
35 /* Print function pointer with inferior address ADDRESS onto stdio
36    stream STREAM.  */
37
38 static void
39 print_function_pointer_address (struct gdbarch *gdbarch, CORE_ADDR address,
40                                 struct ui_file *stream, int addressprint)
41 {
42   CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
43                                                             &current_target);
44
45   /* If the function pointer is represented by a description, print the
46      address of the description.  */
47   if (addressprint && func_addr != address)
48     {
49       fputs_filtered ("@", stream);
50       fputs_filtered (paddress (gdbarch, address), stream);
51       fputs_filtered (": ", stream);
52     }
53   print_address_demangle (gdbarch, func_addr, stream, demangle);
54 }
55
56
57 /* A helper for c_textual_element_type.  This checks the name of the
58    typedef.  This is bogus but it isn't apparent that the compiler
59    provides us the help we may need.  */
60
61 static int
62 textual_name (const char *name)
63 {
64   return (!strcmp (name, "wchar_t")
65           || !strcmp (name, "char16_t")
66           || !strcmp (name, "char32_t"));
67 }
68
69 /* Apply a heuristic to decide whether an array of TYPE or a pointer
70    to TYPE should be printed as a textual string.  Return non-zero if
71    it should, or zero if it should be treated as an array of integers
72    or pointer to integers.  FORMAT is the current format letter,
73    or 0 if none.
74
75    We guess that "char" is a character.  Explicitly signed and
76    unsigned character types are also characters.  Integer data from
77    vector types is not.  The user can override this by using the /s
78    format letter.  */
79
80 int
81 c_textual_element_type (struct type *type, char format)
82 {
83   struct type *true_type, *iter_type;
84
85   if (format != 0 && format != 's')
86     return 0;
87
88   /* We also rely on this for its side effect of setting up all the
89      typedef pointers.  */
90   true_type = check_typedef (type);
91
92   /* TYPE_CODE_CHAR is always textual.  */
93   if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
94     return 1;
95
96   /* Any other character-like types must be integral.  */
97   if (TYPE_CODE (true_type) != TYPE_CODE_INT)
98     return 0;
99
100   /* We peel typedefs one by one, looking for a match.  */
101   iter_type = type;
102   while (iter_type)
103     {
104       /* Check the name of the type.  */
105       if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
106         return 1;
107
108       if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
109         break;
110
111       /* Peel a single typedef.  If the typedef doesn't have a target
112          type, we use check_typedef and hope the result is ok -- it
113          might be for C++, where wchar_t is a built-in type.  */
114       if (TYPE_TARGET_TYPE (iter_type))
115         iter_type = TYPE_TARGET_TYPE (iter_type);
116       else
117         iter_type = check_typedef (iter_type);
118     }
119
120   if (format == 's')
121     {
122       /* Print this as a string if we can manage it.  For now, no
123          wide character support.  */
124       if (TYPE_CODE (true_type) == TYPE_CODE_INT
125           && TYPE_LENGTH (true_type) == 1)
126         return 1;
127     }
128   else
129     {
130       /* If a one-byte TYPE_CODE_INT is missing the not-a-character
131          flag, then we treat it as text; otherwise, we assume it's
132          being used as data.  */
133       if (TYPE_CODE (true_type) == TYPE_CODE_INT
134           && TYPE_LENGTH (true_type) == 1
135           && !TYPE_NOTTEXT (true_type))
136         return 1;
137     }
138
139   return 0;
140 }
141
142
143 /* Print data of type TYPE located at VALADDR (within GDB), which came from
144    the inferior at address ADDRESS, onto stdio stream STREAM according to
145    OPTIONS.  The data at VALADDR is in target byte order.
146
147    If the data are a string pointer, returns the number of string characters
148    printed.  */
149
150 int
151 c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
152              CORE_ADDR address, struct ui_file *stream, int recurse,
153              const struct value *original_value,
154              const struct value_print_options *options)
155 {
156   struct gdbarch *gdbarch = get_type_arch (type);
157   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
158   unsigned int i = 0;   /* Number of characters printed */
159   unsigned len;
160   struct type *elttype, *unresolved_elttype;
161   struct type *unresolved_type = type;
162   unsigned eltlen;
163   LONGEST val;
164   CORE_ADDR addr;
165
166   CHECK_TYPEDEF (type);
167   switch (TYPE_CODE (type))
168     {
169     case TYPE_CODE_ARRAY:
170       unresolved_elttype = TYPE_TARGET_TYPE (type);
171       elttype = check_typedef (unresolved_elttype);
172       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
173         {
174           LONGEST low_bound, high_bound;
175
176           if (!get_array_bounds (type, &low_bound, &high_bound))
177             error (_("Could not determine the array high bound"));
178
179           eltlen = TYPE_LENGTH (elttype);
180           len = high_bound - low_bound + 1;
181           if (options->prettyprint_arrays)
182             {
183               print_spaces_filtered (2 + 2 * recurse, stream);
184             }
185
186           /* Print arrays of textual chars with a string syntax, as
187              long as the entire array is valid.  */
188           if (c_textual_element_type (unresolved_elttype, options->format)
189               && value_bits_valid (original_value,
190                                    TARGET_CHAR_BIT * embedded_offset,
191                                    TARGET_CHAR_BIT * TYPE_LENGTH (type)))
192             {
193               /* If requested, look for the first null char and only print
194                  elements up to it.  */
195               if (options->stop_print_at_null)
196                 {
197                   unsigned int temp_len;
198
199                   for (temp_len = 0;
200                        (temp_len < len
201                         && temp_len < options->print_max
202                         && extract_unsigned_integer (valaddr + embedded_offset
203                                                      + temp_len * eltlen,
204                                                      eltlen, byte_order) != 0);
205                        ++temp_len)
206                     ;
207                   len = temp_len;
208                 }
209
210               LA_PRINT_STRING (stream, unresolved_elttype,
211                                valaddr + embedded_offset, len,
212                                NULL, 0, options);
213               i = len;
214             }
215           else
216             {
217               fprintf_filtered (stream, "{");
218               /* If this is a virtual function table, print the 0th
219                  entry specially, and the rest of the members normally.  */
220               if (cp_is_vtbl_ptr_type (elttype))
221                 {
222                   i = 1;
223                   fprintf_filtered (stream, _("%d vtable entries"), len - 1);
224                 }
225               else
226                 {
227                   i = 0;
228                 }
229               val_print_array_elements (type, valaddr + embedded_offset,
230                                         address + embedded_offset, stream,
231                                         recurse, original_value, options, i);
232               fprintf_filtered (stream, "}");
233             }
234           break;
235         }
236       /* Array of unspecified length: treat like pointer to first elt.  */
237       addr = address;
238       goto print_unpacked_pointer;
239
240     case TYPE_CODE_MEMBERPTR:
241       if (options->format)
242         {
243           print_scalar_formatted (valaddr + embedded_offset, type,
244                                   options, 0, stream);
245           break;
246         }
247       cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
248       break;
249
250     case TYPE_CODE_METHODPTR:
251       cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
252       break;
253
254     case TYPE_CODE_PTR:
255       if (options->format && options->format != 's')
256         {
257           print_scalar_formatted (valaddr + embedded_offset, type,
258                                   options, 0, stream);
259           break;
260         }
261       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
262         {
263           /* Print the unmangled name if desired.  */
264           /* Print vtable entry - we only get here if we ARE using
265              -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
266           CORE_ADDR addr
267             = extract_typed_address (valaddr + embedded_offset, type);
268
269           print_function_pointer_address (gdbarch, addr, stream,
270                                           options->addressprint);
271           break;
272         }
273       unresolved_elttype = TYPE_TARGET_TYPE (type);
274       elttype = check_typedef (unresolved_elttype);
275         {
276           addr = unpack_pointer (type, valaddr + embedded_offset);
277         print_unpacked_pointer:
278
279           if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
280             {
281               /* Try to print what function it points to.  */
282               print_function_pointer_address (gdbarch, addr, stream,
283                                               options->addressprint);
284               /* Return value is irrelevant except for string pointers.  */
285               return (0);
286             }
287
288           if (options->addressprint)
289             fputs_filtered (paddress (gdbarch, addr), stream);
290
291           /* For a pointer to a textual type, also print the string
292              pointed to, unless pointer is null.  */
293
294           if (c_textual_element_type (unresolved_elttype, options->format)
295               && addr != 0)
296             {
297               i = val_print_string (unresolved_elttype, NULL, addr, -1, stream,
298                                     options);
299             }
300           else if (cp_is_vtbl_member (type))
301             {
302               /* print vtbl's nicely */
303               CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
304
305               struct minimal_symbol *msymbol =
306               lookup_minimal_symbol_by_pc (vt_address);
307               if ((msymbol != NULL)
308                   && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
309                 {
310                   fputs_filtered (" <", stream);
311                   fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
312                   fputs_filtered (">", stream);
313                 }
314               if (vt_address && options->vtblprint)
315                 {
316                   struct value *vt_val;
317                   struct symbol *wsym = (struct symbol *) NULL;
318                   struct type *wtype;
319                   struct block *block = (struct block *) NULL;
320                   int is_this_fld;
321
322                   if (msymbol != NULL)
323                     wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
324                                           VAR_DOMAIN, &is_this_fld);
325
326                   if (wsym)
327                     {
328                       wtype = SYMBOL_TYPE (wsym);
329                     }
330                   else
331                     {
332                       wtype = unresolved_elttype;
333                     }
334                   vt_val = value_at (wtype, vt_address);
335                   common_val_print (vt_val, stream, recurse + 1, options,
336                                     current_language);
337                   if (options->pretty)
338                     {
339                       fprintf_filtered (stream, "\n");
340                       print_spaces_filtered (2 + 2 * recurse, stream);
341                     }
342                 }
343             }
344
345           /* Return number of characters printed, including the terminating
346              '\0' if we reached the end.  val_print_string takes care including
347              the terminating '\0' if necessary.  */
348           return i;
349         }
350       break;
351
352     case TYPE_CODE_REF:
353       elttype = check_typedef (TYPE_TARGET_TYPE (type));
354       if (options->addressprint)
355         {
356           CORE_ADDR addr
357             = extract_typed_address (valaddr + embedded_offset, type);
358
359           fprintf_filtered (stream, "@");
360           fputs_filtered (paddress (gdbarch, addr), stream);
361           if (options->deref_ref)
362             fputs_filtered (": ", stream);
363         }
364       /* De-reference the reference.  */
365       if (options->deref_ref)
366         {
367           if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
368             {
369               struct value *deref_val =
370                 value_at
371                 (TYPE_TARGET_TYPE (type),
372                  unpack_pointer (type, valaddr + embedded_offset));
373
374               common_val_print (deref_val, stream, recurse, options,
375                                 current_language);
376             }
377           else
378             fputs_filtered ("???", stream);
379         }
380       break;
381
382     case TYPE_CODE_UNION:
383       if (recurse && !options->unionprint)
384         {
385           fprintf_filtered (stream, "{...}");
386           break;
387         }
388       /* Fall through.  */
389     case TYPE_CODE_STRUCT:
390       /*FIXME: Abstract this away */
391       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
392         {
393           /* Print the unmangled name if desired.  */
394           /* Print vtable entry - we only get here if NOT using
395              -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.) */
396           int offset = (embedded_offset +
397                         TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8);
398           struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
399           CORE_ADDR addr
400             = extract_typed_address (valaddr + offset, field_type);
401
402           print_function_pointer_address (gdbarch, addr, stream,
403                                           options->addressprint);
404         }
405       else
406         cp_print_value_fields_rtti (type, valaddr,
407                                     embedded_offset, address, stream,
408                                     recurse, original_value, options, NULL, 0);
409       break;
410
411     case TYPE_CODE_ENUM:
412       if (options->format)
413         {
414           print_scalar_formatted (valaddr + embedded_offset, type,
415                                   options, 0, stream);
416           break;
417         }
418       len = TYPE_NFIELDS (type);
419       val = unpack_long (type, valaddr + embedded_offset);
420       for (i = 0; i < len; i++)
421         {
422           QUIT;
423           if (val == TYPE_FIELD_BITPOS (type, i))
424             {
425               break;
426             }
427         }
428       if (i < len)
429         {
430           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
431         }
432       else
433         {
434           print_longest (stream, 'd', 0, val);
435         }
436       break;
437
438     case TYPE_CODE_FLAGS:
439       if (options->format)
440           print_scalar_formatted (valaddr + embedded_offset, type,
441                                   options, 0, stream);
442       else
443         val_print_type_code_flags (type, valaddr + embedded_offset, stream);
444       break;
445
446     case TYPE_CODE_FUNC:
447     case TYPE_CODE_METHOD:
448       if (options->format)
449         {
450           print_scalar_formatted (valaddr + embedded_offset, type,
451                                   options, 0, stream);
452           break;
453         }
454       /* FIXME, we should consider, at least for ANSI C language, eliminating
455          the distinction made between FUNCs and POINTERs to FUNCs.  */
456       fprintf_filtered (stream, "{");
457       type_print (type, "", stream, -1);
458       fprintf_filtered (stream, "} ");
459       /* Try to print what function it points to, and its address.  */
460       print_address_demangle (gdbarch, address, stream, demangle);
461       break;
462
463     case TYPE_CODE_BOOL:
464       if (options->format || options->output_format)
465         {
466           struct value_print_options opts = *options;
467           opts.format = (options->format ? options->format
468                          : options->output_format);
469           print_scalar_formatted (valaddr + embedded_offset, type,
470                                   &opts, 0, stream);
471         }
472       else
473         {
474           val = unpack_long (type, valaddr + embedded_offset);
475           if (val == 0)
476             fputs_filtered ("false", stream);
477           else if (val == 1)
478             fputs_filtered ("true", stream);
479           else
480             print_longest (stream, 'd', 0, val);
481         }
482       break;
483
484     case TYPE_CODE_RANGE:
485       /* FIXME: create_range_type does not set the unsigned bit in a
486          range type (I think it probably should copy it from the target
487          type), so we won't print values which are too large to
488          fit in a signed integer correctly.  */
489       /* FIXME: Doesn't handle ranges of enums correctly.  (Can't just
490          print with the target type, though, because the size of our type
491          and the target type might differ).  */
492       /* FALLTHROUGH */
493
494     case TYPE_CODE_INT:
495       if (options->format || options->output_format)
496         {
497           struct value_print_options opts = *options;
498
499           opts.format = (options->format ? options->format
500                          : options->output_format);
501           print_scalar_formatted (valaddr + embedded_offset, type,
502                                   &opts, 0, stream);
503         }
504       else
505         {
506           val_print_type_code_int (type, valaddr + embedded_offset, stream);
507           /* C and C++ has no single byte int type, char is used instead.
508              Since we don't know whether the value is really intended to
509              be used as an integer or a character, print the character
510              equivalent as well.  */
511           if (c_textual_element_type (unresolved_type, options->format))
512             {
513               fputs_filtered (" ", stream);
514               LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
515                              unresolved_type, stream);
516             }
517         }
518       break;
519
520     case TYPE_CODE_CHAR:
521       if (options->format || options->output_format)
522         {
523           struct value_print_options opts = *options;
524           opts.format = (options->format ? options->format
525                          : options->output_format);
526           print_scalar_formatted (valaddr + embedded_offset, type,
527                                   &opts, 0, stream);
528         }
529       else
530         {
531           val = unpack_long (type, valaddr + embedded_offset);
532           if (TYPE_UNSIGNED (type))
533             fprintf_filtered (stream, "%u", (unsigned int) val);
534           else
535             fprintf_filtered (stream, "%d", (int) val);
536           fputs_filtered (" ", stream);
537           LA_PRINT_CHAR ((unsigned char) val, unresolved_type, stream);
538         }
539       break;
540
541     case TYPE_CODE_FLT:
542       if (options->format)
543         {
544           print_scalar_formatted (valaddr + embedded_offset, type,
545                                   options, 0, stream);
546         }
547       else
548         {
549           print_floating (valaddr + embedded_offset, type, stream);
550         }
551       break;
552
553     case TYPE_CODE_DECFLOAT:
554       if (options->format)
555         print_scalar_formatted (valaddr + embedded_offset, type,
556                                 options, 0, stream);
557       else
558         print_decimal_floating (valaddr + embedded_offset, type, stream);
559       break;
560
561     case TYPE_CODE_VOID:
562       fprintf_filtered (stream, "void");
563       break;
564
565     case TYPE_CODE_ERROR:
566       fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
567       break;
568
569     case TYPE_CODE_UNDEF:
570       /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
571          dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
572          and no complete type for struct foo in that file.  */
573       fprintf_filtered (stream, _("<incomplete type>"));
574       break;
575
576     case TYPE_CODE_COMPLEX:
577       if (options->format)
578         print_scalar_formatted (valaddr + embedded_offset,
579                                 TYPE_TARGET_TYPE (type),
580                                 options, 0, stream);
581       else
582         print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
583                         stream);
584       fprintf_filtered (stream, " + ");
585       if (options->format)
586         print_scalar_formatted (valaddr + embedded_offset
587                                 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
588                                 TYPE_TARGET_TYPE (type),
589                                 options, 0, stream);
590       else
591         print_floating (valaddr + embedded_offset
592                         + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
593                         TYPE_TARGET_TYPE (type),
594                         stream);
595       fprintf_filtered (stream, " * I");
596       break;
597
598     default:
599       error (_("Invalid C/C++ type code %d in symbol table."), TYPE_CODE (type));
600     }
601   gdb_flush (stream);
602   return (0);
603 }
604 \f
605 int
606 c_value_print (struct value *val, struct ui_file *stream, 
607                const struct value_print_options *options)
608 {
609   struct type *type, *real_type, *val_type;
610   int full, top, using_enc;
611   struct value_print_options opts = *options;
612
613   opts.deref_ref = 1;
614
615   /* If it is a pointer, indicate what it points to.
616
617      Print type also if it is a reference.
618
619      C++: if it is a member pointer, we will take care
620      of that when we print it.  */
621
622   /* Preserve the original type before stripping typedefs.  We prefer
623      to pass down the original type when possible, but for local
624      checks it is better to look past the typedefs.  */
625   val_type = value_type (val);
626   type = check_typedef (val_type);
627
628   if (TYPE_CODE (type) == TYPE_CODE_PTR
629       || TYPE_CODE (type) == TYPE_CODE_REF)
630     {
631       /* Hack:  remove (char *) for char strings.  Their
632          type is indicated by the quoted string anyway.
633          (Don't use c_textual_element_type here; quoted strings
634          are always exactly (char *), (wchar_t *), or the like.  */
635       if (TYPE_CODE (val_type) == TYPE_CODE_PTR
636           && TYPE_NAME (val_type) == NULL
637           && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
638           && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)), "char") == 0
639               || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
640         {
641           /* Print nothing */
642         }
643       else if (options->objectprint
644                && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
645         {
646
647           if (TYPE_CODE(type) == TYPE_CODE_REF)
648             {
649               /* Copy value, change to pointer, so we don't get an
650                * error about a non-pointer type in value_rtti_target_type
651                */
652               struct value *temparg;
653               temparg=value_copy(val);
654               deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
655               val=temparg;
656             }
657           /* Pointer to class, check real type of object */
658           fprintf_filtered (stream, "(");
659           real_type = value_rtti_target_type (val, &full, &top, &using_enc);
660           if (real_type)
661             {
662               /* RTTI entry found */
663               if (TYPE_CODE (type) == TYPE_CODE_PTR)
664                 {
665                   /* create a pointer type pointing to the real type */
666                   type = lookup_pointer_type (real_type);
667                 }
668               else
669                 {
670                   /* create a reference type referencing the real type */
671                   type = lookup_reference_type (real_type);
672                 }
673               /* JYG: Need to adjust pointer value. */
674               /* NOTE: cagney/2005-01-02: THIS IS BOGUS.  */
675               value_contents_writeable (val)[0] -= top;
676
677               /* Note: When we look up RTTI entries, we don't get any 
678                  information on const or volatile attributes */
679             }
680           type_print (type, "", stream, -1);
681           fprintf_filtered (stream, ") ");
682           val_type = type;
683         }
684       else
685         {
686           /* normal case */
687           fprintf_filtered (stream, "(");
688           type_print (value_type (val), "", stream, -1);
689           fprintf_filtered (stream, ") ");
690         }
691     }
692
693   if (!value_initialized (val))
694     fprintf_filtered (stream, " [uninitialized] ");
695
696   if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
697     {
698       /* Attempt to determine real type of object */
699       real_type = value_rtti_type (val, &full, &top, &using_enc);
700       if (real_type)
701         {
702           /* We have RTTI information, so use it */
703           val = value_full_object (val, real_type, full, top, using_enc);
704           fprintf_filtered (stream, "(%s%s) ",
705                             TYPE_NAME (real_type),
706                             full ? "" : _(" [incomplete object]"));
707           /* Print out object: enclosing type is same as real_type if full */
708           return val_print (value_enclosing_type (val),
709                             value_contents_for_printing (val), 0,
710                             value_address (val), stream, 0,
711                             val, &opts, current_language);
712           /* Note: When we look up RTTI entries, we don't get any information on
713              const or volatile attributes */
714         }
715       else if (type != check_typedef (value_enclosing_type (val)))
716         {
717           /* No RTTI information, so let's do our best */
718           fprintf_filtered (stream, "(%s ?) ",
719                             TYPE_NAME (value_enclosing_type (val)));
720           return val_print (value_enclosing_type (val),
721                             value_contents_for_printing (val), 0,
722                             value_address (val), stream, 0,
723                             val, &opts, current_language);
724         }
725       /* Otherwise, we end up at the return outside this "if" */
726     }
727
728   return val_print (val_type, value_contents_for_printing (val),
729                     value_embedded_offset (val),
730                     value_address (val),
731                     stream, 0,
732                     val, &opts, current_language);
733 }