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