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