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           eltlen = TYPE_LENGTH (elttype);
175           len = TYPE_LENGTH (type) / eltlen;
176           if (options->prettyprint_arrays)
177             {
178               print_spaces_filtered (2 + 2 * recurse, stream);
179             }
180
181           /* Print arrays of textual chars with a string syntax, as
182              long as the entire array is valid.  */
183           if (c_textual_element_type (unresolved_elttype, options->format)
184               && value_bits_valid (original_value,
185                                    TARGET_CHAR_BIT * embedded_offset,
186                                    TARGET_CHAR_BIT * TYPE_LENGTH (type)))
187             {
188               /* If requested, look for the first null char and only print
189                  elements up to it.  */
190               if (options->stop_print_at_null)
191                 {
192                   unsigned int temp_len;
193
194                   for (temp_len = 0;
195                        (temp_len < len
196                         && temp_len < options->print_max
197                         && extract_unsigned_integer (valaddr + embedded_offset
198                                                      + temp_len * eltlen,
199                                                      eltlen, byte_order) != 0);
200                        ++temp_len)
201                     ;
202                   len = temp_len;
203                 }
204
205               LA_PRINT_STRING (stream, unresolved_elttype,
206                                valaddr + embedded_offset, len,
207                                NULL, 0, options);
208               i = len;
209             }
210           else
211             {
212               fprintf_filtered (stream, "{");
213               /* If this is a virtual function table, print the 0th
214                  entry specially, and the rest of the members normally.  */
215               if (cp_is_vtbl_ptr_type (elttype))
216                 {
217                   i = 1;
218                   fprintf_filtered (stream, _("%d vtable entries"), len - 1);
219                 }
220               else
221                 {
222                   i = 0;
223                 }
224               val_print_array_elements (type, valaddr + embedded_offset, address, stream,
225                                         recurse, original_value, options, i);
226               fprintf_filtered (stream, "}");
227             }
228           break;
229         }
230       /* Array of unspecified length: treat like pointer to first elt.  */
231       addr = address;
232       goto print_unpacked_pointer;
233
234     case TYPE_CODE_MEMBERPTR:
235       if (options->format)
236         {
237           print_scalar_formatted (valaddr + embedded_offset, type,
238                                   options, 0, stream);
239           break;
240         }
241       cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
242       break;
243
244     case TYPE_CODE_METHODPTR:
245       cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
246       break;
247
248     case TYPE_CODE_PTR:
249       if (options->format && options->format != 's')
250         {
251           print_scalar_formatted (valaddr + embedded_offset, type,
252                                   options, 0, stream);
253           break;
254         }
255       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
256         {
257           /* Print the unmangled name if desired.  */
258           /* Print vtable entry - we only get here if we ARE using
259              -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
260           CORE_ADDR addr
261             = extract_typed_address (valaddr + embedded_offset, type);
262
263           print_function_pointer_address (gdbarch, addr, stream,
264                                           options->addressprint);
265           break;
266         }
267       unresolved_elttype = TYPE_TARGET_TYPE (type);
268       elttype = check_typedef (unresolved_elttype);
269         {
270           addr = unpack_pointer (type, valaddr + embedded_offset);
271         print_unpacked_pointer:
272
273           if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
274             {
275               /* Try to print what function it points to.  */
276               print_function_pointer_address (gdbarch, addr, stream,
277                                               options->addressprint);
278               /* Return value is irrelevant except for string pointers.  */
279               return (0);
280             }
281
282           if (options->addressprint)
283             fputs_filtered (paddress (gdbarch, addr), stream);
284
285           /* For a pointer to a textual type, also print the string
286              pointed to, unless pointer is null.  */
287
288           if (c_textual_element_type (unresolved_elttype, options->format)
289               && addr != 0)
290             {
291               i = val_print_string (unresolved_elttype, addr, -1, stream,
292                                     options);
293             }
294           else if (cp_is_vtbl_member (type))
295             {
296               /* print vtbl's nicely */
297               CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
298
299               struct minimal_symbol *msymbol =
300               lookup_minimal_symbol_by_pc (vt_address);
301               if ((msymbol != NULL)
302                   && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
303                 {
304                   fputs_filtered (" <", stream);
305                   fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
306                   fputs_filtered (">", stream);
307                 }
308               if (vt_address && options->vtblprint)
309                 {
310                   struct value *vt_val;
311                   struct symbol *wsym = (struct symbol *) NULL;
312                   struct type *wtype;
313                   struct block *block = (struct block *) NULL;
314                   int is_this_fld;
315
316                   if (msymbol != NULL)
317                     wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
318                                           VAR_DOMAIN, &is_this_fld);
319
320                   if (wsym)
321                     {
322                       wtype = SYMBOL_TYPE (wsym);
323                     }
324                   else
325                     {
326                       wtype = unresolved_elttype;
327                     }
328                   vt_val = value_at (wtype, vt_address);
329                   common_val_print (vt_val, stream, recurse + 1, options,
330                                     current_language);
331                   if (options->pretty)
332                     {
333                       fprintf_filtered (stream, "\n");
334                       print_spaces_filtered (2 + 2 * recurse, stream);
335                     }
336                 }
337             }
338
339           /* Return number of characters printed, including the terminating
340              '\0' if we reached the end.  val_print_string takes care including
341              the terminating '\0' if necessary.  */
342           return i;
343         }
344       break;
345
346     case TYPE_CODE_REF:
347       elttype = check_typedef (TYPE_TARGET_TYPE (type));
348       if (options->addressprint)
349         {
350           CORE_ADDR addr
351             = extract_typed_address (valaddr + embedded_offset, type);
352
353           fprintf_filtered (stream, "@");
354           fputs_filtered (paddress (gdbarch, addr), stream);
355           if (options->deref_ref)
356             fputs_filtered (": ", stream);
357         }
358       /* De-reference the reference.  */
359       if (options->deref_ref)
360         {
361           if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
362             {
363               struct value *deref_val =
364                 value_at
365                 (TYPE_TARGET_TYPE (type),
366                  unpack_pointer (type, valaddr + embedded_offset));
367
368               common_val_print (deref_val, stream, recurse, options,
369                                 current_language);
370             }
371           else
372             fputs_filtered ("???", stream);
373         }
374       break;
375
376     case TYPE_CODE_UNION:
377       if (recurse && !options->unionprint)
378         {
379           fprintf_filtered (stream, "{...}");
380           break;
381         }
382       /* Fall through.  */
383     case TYPE_CODE_STRUCT:
384       /*FIXME: Abstract this away */
385       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
386         {
387           /* Print the unmangled name if desired.  */
388           /* Print vtable entry - we only get here if NOT using
389              -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.) */
390           int offset = (embedded_offset +
391                         TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8);
392           struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
393           CORE_ADDR addr
394             = extract_typed_address (valaddr + offset, field_type);
395
396           print_function_pointer_address (gdbarch, addr, stream,
397                                           options->addressprint);
398         }
399       else
400         cp_print_value_fields_rtti (type, valaddr,
401                                     embedded_offset, address, stream,
402                                     recurse, original_value, options, NULL, 0);
403       break;
404
405     case TYPE_CODE_ENUM:
406       if (options->format)
407         {
408           print_scalar_formatted (valaddr + embedded_offset, type,
409                                   options, 0, stream);
410           break;
411         }
412       len = TYPE_NFIELDS (type);
413       val = unpack_long (type, valaddr + embedded_offset);
414       for (i = 0; i < len; i++)
415         {
416           QUIT;
417           if (val == TYPE_FIELD_BITPOS (type, i))
418             {
419               break;
420             }
421         }
422       if (i < len)
423         {
424           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
425         }
426       else
427         {
428           print_longest (stream, 'd', 0, val);
429         }
430       break;
431
432     case TYPE_CODE_FLAGS:
433       if (options->format)
434           print_scalar_formatted (valaddr + embedded_offset, type,
435                                   options, 0, stream);
436       else
437         val_print_type_code_flags (type, valaddr + embedded_offset, stream);
438       break;
439
440     case TYPE_CODE_FUNC:
441     case TYPE_CODE_METHOD:
442       if (options->format)
443         {
444           print_scalar_formatted (valaddr + embedded_offset, type,
445                                   options, 0, stream);
446           break;
447         }
448       /* FIXME, we should consider, at least for ANSI C language, eliminating
449          the distinction made between FUNCs and POINTERs to FUNCs.  */
450       fprintf_filtered (stream, "{");
451       type_print (type, "", stream, -1);
452       fprintf_filtered (stream, "} ");
453       /* Try to print what function it points to, and its address.  */
454       print_address_demangle (gdbarch, address, stream, demangle);
455       break;
456
457     case TYPE_CODE_BOOL:
458       if (options->format || options->output_format)
459         {
460           struct value_print_options opts = *options;
461           opts.format = (options->format ? options->format
462                          : options->output_format);
463           print_scalar_formatted (valaddr + embedded_offset, type,
464                                   &opts, 0, stream);
465         }
466       else
467         {
468           val = unpack_long (type, valaddr + embedded_offset);
469           if (val == 0)
470             fputs_filtered ("false", stream);
471           else if (val == 1)
472             fputs_filtered ("true", stream);
473           else
474             print_longest (stream, 'd', 0, val);
475         }
476       break;
477
478     case TYPE_CODE_RANGE:
479       /* FIXME: create_range_type does not set the unsigned bit in a
480          range type (I think it probably should copy it from the target
481          type), so we won't print values which are too large to
482          fit in a signed integer correctly.  */
483       /* FIXME: Doesn't handle ranges of enums correctly.  (Can't just
484          print with the target type, though, because the size of our type
485          and the target type might differ).  */
486       /* FALLTHROUGH */
487
488     case TYPE_CODE_INT:
489       if (options->format || options->output_format)
490         {
491           struct value_print_options opts = *options;
492
493           opts.format = (options->format ? options->format
494                          : options->output_format);
495           print_scalar_formatted (valaddr + embedded_offset, type,
496                                   &opts, 0, stream);
497         }
498       else
499         {
500           val_print_type_code_int (type, valaddr + embedded_offset, stream);
501           /* C and C++ has no single byte int type, char is used instead.
502              Since we don't know whether the value is really intended to
503              be used as an integer or a character, print the character
504              equivalent as well.  */
505           if (c_textual_element_type (unresolved_type, options->format))
506             {
507               fputs_filtered (" ", stream);
508               LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
509                              unresolved_type, stream);
510             }
511         }
512       break;
513
514     case TYPE_CODE_CHAR:
515       if (options->format || options->output_format)
516         {
517           struct value_print_options opts = *options;
518           opts.format = (options->format ? options->format
519                          : options->output_format);
520           print_scalar_formatted (valaddr + embedded_offset, type,
521                                   &opts, 0, stream);
522         }
523       else
524         {
525           val = unpack_long (type, valaddr + embedded_offset);
526           if (TYPE_UNSIGNED (type))
527             fprintf_filtered (stream, "%u", (unsigned int) val);
528           else
529             fprintf_filtered (stream, "%d", (int) val);
530           fputs_filtered (" ", stream);
531           LA_PRINT_CHAR ((unsigned char) val, unresolved_type, stream);
532         }
533       break;
534
535     case TYPE_CODE_FLT:
536       if (options->format)
537         {
538           print_scalar_formatted (valaddr + embedded_offset, type,
539                                   options, 0, stream);
540         }
541       else
542         {
543           print_floating (valaddr + embedded_offset, type, stream);
544         }
545       break;
546
547     case TYPE_CODE_DECFLOAT:
548       if (options->format)
549         print_scalar_formatted (valaddr + embedded_offset, type,
550                                 options, 0, stream);
551       else
552         print_decimal_floating (valaddr + embedded_offset, type, stream);
553       break;
554
555     case TYPE_CODE_VOID:
556       fprintf_filtered (stream, "void");
557       break;
558
559     case TYPE_CODE_ERROR:
560       fprintf_filtered (stream, _("<error type>"));
561       break;
562
563     case TYPE_CODE_UNDEF:
564       /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
565          dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
566          and no complete type for struct foo in that file.  */
567       fprintf_filtered (stream, _("<incomplete type>"));
568       break;
569
570     case TYPE_CODE_COMPLEX:
571       if (options->format)
572         print_scalar_formatted (valaddr + embedded_offset,
573                                 TYPE_TARGET_TYPE (type),
574                                 options, 0, stream);
575       else
576         print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
577                         stream);
578       fprintf_filtered (stream, " + ");
579       if (options->format)
580         print_scalar_formatted (valaddr + embedded_offset
581                                 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
582                                 TYPE_TARGET_TYPE (type),
583                                 options, 0, stream);
584       else
585         print_floating (valaddr + embedded_offset
586                         + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
587                         TYPE_TARGET_TYPE (type),
588                         stream);
589       fprintf_filtered (stream, " * I");
590       break;
591
592     default:
593       error (_("Invalid C/C++ type code %d in symbol table."), TYPE_CODE (type));
594     }
595   gdb_flush (stream);
596   return (0);
597 }
598 \f
599 int
600 c_value_print (struct value *val, struct ui_file *stream, 
601                const struct value_print_options *options)
602 {
603   struct type *type, *real_type, *val_type;
604   int full, top, using_enc;
605   struct value_print_options opts = *options;
606
607   opts.deref_ref = 1;
608
609   /* If it is a pointer, indicate what it points to.
610
611      Print type also if it is a reference.
612
613      C++: if it is a member pointer, we will take care
614      of that when we print it.  */
615
616   /* Preserve the original type before stripping typedefs.  We prefer
617      to pass down the original type when possible, but for local
618      checks it is better to look past the typedefs.  */
619   val_type = value_type (val);
620   type = check_typedef (val_type);
621
622   if (TYPE_CODE (type) == TYPE_CODE_PTR
623       || TYPE_CODE (type) == TYPE_CODE_REF)
624     {
625       /* Hack:  remove (char *) for char strings.  Their
626          type is indicated by the quoted string anyway.
627          (Don't use c_textual_element_type here; quoted strings
628          are always exactly (char *), (wchar_t *), or the like.  */
629       if (TYPE_CODE (val_type) == TYPE_CODE_PTR
630           && TYPE_NAME (val_type) == NULL
631           && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
632           && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)), "char") == 0
633               || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
634         {
635           /* Print nothing */
636         }
637       else if (options->objectprint
638                && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
639         {
640
641           if (TYPE_CODE(type) == TYPE_CODE_REF)
642             {
643               /* Copy value, change to pointer, so we don't get an
644                * error about a non-pointer type in value_rtti_target_type
645                */
646               struct value *temparg;
647               temparg=value_copy(val);
648               deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
649               val=temparg;
650             }
651           /* Pointer to class, check real type of object */
652           fprintf_filtered (stream, "(");
653           real_type = value_rtti_target_type (val, &full, &top, &using_enc);
654           if (real_type)
655             {
656               /* RTTI entry found */
657               if (TYPE_CODE (type) == TYPE_CODE_PTR)
658                 {
659                   /* create a pointer type pointing to the real type */
660                   type = lookup_pointer_type (real_type);
661                 }
662               else
663                 {
664                   /* create a reference type referencing the real type */
665                   type = lookup_reference_type (real_type);
666                 }
667               /* JYG: Need to adjust pointer value. */
668               /* NOTE: cagney/2005-01-02: THIS IS BOGUS.  */
669               value_contents_writeable (val)[0] -= top;
670
671               /* Note: When we look up RTTI entries, we don't get any 
672                  information on const or volatile attributes */
673             }
674           type_print (type, "", stream, -1);
675           fprintf_filtered (stream, ") ");
676           val_type = type;
677         }
678       else
679         {
680           /* normal case */
681           fprintf_filtered (stream, "(");
682           type_print (value_type (val), "", stream, -1);
683           fprintf_filtered (stream, ") ");
684         }
685     }
686
687   if (!value_initialized (val))
688     fprintf_filtered (stream, " [uninitialized] ");
689
690   if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
691     {
692       /* Attempt to determine real type of object */
693       real_type = value_rtti_type (val, &full, &top, &using_enc);
694       if (real_type)
695         {
696           /* We have RTTI information, so use it */
697           val = value_full_object (val, real_type, full, top, using_enc);
698           fprintf_filtered (stream, "(%s%s) ",
699                             TYPE_NAME (real_type),
700                             full ? "" : _(" [incomplete object]"));
701           /* Print out object: enclosing type is same as real_type if full */
702           return val_print (value_enclosing_type (val),
703                             value_contents_for_printing (val), 0,
704                             value_address (val), stream, 0,
705                             val, &opts, current_language);
706           /* Note: When we look up RTTI entries, we don't get any information on
707              const or volatile attributes */
708         }
709       else if (type != check_typedef (value_enclosing_type (val)))
710         {
711           /* No RTTI information, so let's do our best */
712           fprintf_filtered (stream, "(%s ?) ",
713                             TYPE_NAME (value_enclosing_type (val)));
714           return val_print (value_enclosing_type (val),
715                             value_contents_for_printing (val), 0,
716                             value_address (val), stream, 0,
717                             val, &opts, current_language);
718         }
719       /* Otherwise, we end up at the return outside this "if" */
720     }
721
722   return val_print (val_type, value_contents_for_printing (val),
723                     value_embedded_offset (val),
724                     value_address (val),
725                     stream, 0,
726                     val, &opts, current_language);
727 }