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