2009-03-20 Tom Tromey <tromey@redhat.com>
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
CommitLineData
c906108c 1/* Support for printing C values for GDB, the GNU debugger.
1bac305b 2
6aba47ca 3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
0fb0cc75 4 1998, 1999, 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009
4f2aea11 5 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
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.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
309367d4 23#include "gdb_string.h"
c906108c
SS
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "value.h"
c906108c
SS
28#include "valprint.h"
29#include "language.h"
30#include "c-lang.h"
015a42b4 31#include "cp-abi.h"
e2d0e7eb 32#include "target.h"
c906108c 33\f
c5aa993b 34
6e778545
PS
35/* Print function pointer with inferior address ADDRESS onto stdio
36 stream STREAM. */
37
38static void
79a45b7d
TT
39print_function_pointer_address (CORE_ADDR address, struct ui_file *stream,
40 int addressprint)
6e778545 41{
e2d0e7eb
AC
42 CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
43 address,
44 &current_target);
6e778545
PS
45
46 /* If the function pointer is represented by a description, print the
47 address of the description. */
48 if (addressprint && func_addr != address)
49 {
50 fputs_filtered ("@", stream);
ed49a04f 51 fputs_filtered (paddress (address), stream);
6e778545
PS
52 fputs_filtered (": ", stream);
53 }
54 print_address_demangle (func_addr, stream, demangle);
55}
56
57
ea37ba09
DJ
58/* Apply a heuristic to decide whether an array of TYPE or a pointer
59 to TYPE should be printed as a textual string. Return non-zero if
60 it should, or zero if it should be treated as an array of integers
61 or pointer to integers. FORMAT is the current format letter,
62 or 0 if none.
63
64 We guess that "char" is a character. Explicitly signed and
65 unsigned character types are also characters. Integer data from
66 vector types is not. The user can override this by using the /s
67 format letter. */
68
69static int
70textual_element_type (struct type *type, char format)
71{
72 struct type *true_type = check_typedef (type);
73
74 if (format != 0 && format != 's')
75 return 0;
76
77 /* TYPE_CODE_CHAR is always textual. */
78 if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
79 return 1;
80
81 if (format == 's')
82 {
83 /* Print this as a string if we can manage it. For now, no
84 wide character support. */
85 if (TYPE_CODE (true_type) == TYPE_CODE_INT
86 && TYPE_LENGTH (true_type) == 1)
87 return 1;
88 }
89 else
90 {
91 /* If a one-byte TYPE_CODE_INT is missing the not-a-character
92 flag, then we treat it as text; otherwise, we assume it's
93 being used as data. */
94 if (TYPE_CODE (true_type) == TYPE_CODE_INT
95 && TYPE_LENGTH (true_type) == 1
96 && !TYPE_NOTTEXT (true_type))
97 return 1;
98 }
99
100 return 0;
101}
102
103
c906108c
SS
104/* Print data of type TYPE located at VALADDR (within GDB), which came from
105 the inferior at address ADDRESS, onto stdio stream STREAM according to
79a45b7d 106 OPTIONS. The data at VALADDR is in target byte order.
c906108c
SS
107
108 If the data are a string pointer, returns the number of string characters
79a45b7d 109 printed. */
c906108c
SS
110
111int
fc1a4b47 112c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
79a45b7d
TT
113 CORE_ADDR address, struct ui_file *stream, int recurse,
114 const struct value_print_options *options)
c906108c 115{
52f0bd74 116 unsigned int i = 0; /* Number of characters printed */
c906108c
SS
117 unsigned len;
118 struct type *elttype;
119 unsigned eltlen;
120 LONGEST val;
121 CORE_ADDR addr;
122
123 CHECK_TYPEDEF (type);
124 switch (TYPE_CODE (type))
125 {
126 case TYPE_CODE_ARRAY:
127 elttype = check_typedef (TYPE_TARGET_TYPE (type));
128 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
129 {
130 eltlen = TYPE_LENGTH (elttype);
131 len = TYPE_LENGTH (type) / eltlen;
79a45b7d 132 if (options->prettyprint_arrays)
c906108c
SS
133 {
134 print_spaces_filtered (2 + 2 * recurse, stream);
135 }
ea37ba09
DJ
136
137 /* Print arrays of textual chars with a string syntax. */
79a45b7d 138 if (textual_element_type (elttype, options->format))
c906108c
SS
139 {
140 /* If requested, look for the first null char and only print
c5aa993b 141 elements up to it. */
79a45b7d 142 if (options->stop_print_at_null)
c906108c 143 {
745b8ca0 144 unsigned int temp_len;
c5aa993b 145
c906108c
SS
146 /* Look for a NULL char. */
147 for (temp_len = 0;
148 (valaddr + embedded_offset)[temp_len]
79a45b7d 149 && temp_len < len && temp_len < options->print_max;
c906108c
SS
150 temp_len++);
151 len = temp_len;
152 }
c5aa993b 153
79a45b7d 154 LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0, options);
c906108c
SS
155 i = len;
156 }
157 else
158 {
159 fprintf_filtered (stream, "{");
160 /* If this is a virtual function table, print the 0th
c5aa993b 161 entry specially, and the rest of the members normally. */
c906108c
SS
162 if (cp_is_vtbl_ptr_type (elttype))
163 {
164 i = 1;
3d263c1d 165 fprintf_filtered (stream, _("%d vtable entries"), len - 1);
c906108c
SS
166 }
167 else
168 {
169 i = 0;
170 }
171 val_print_array_elements (type, valaddr + embedded_offset, address, stream,
79a45b7d 172 recurse, options, i);
c906108c
SS
173 fprintf_filtered (stream, "}");
174 }
175 break;
176 }
177 /* Array of unspecified length: treat like pointer to first elt. */
178 addr = address;
179 goto print_unpacked_pointer;
180
0d5de010 181 case TYPE_CODE_MEMBERPTR:
79a45b7d 182 if (options->format)
0d5de010 183 {
79a45b7d
TT
184 print_scalar_formatted (valaddr + embedded_offset, type,
185 options, 0, stream);
0d5de010
DJ
186 break;
187 }
ad4820ab 188 cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
0d5de010
DJ
189 break;
190
191 case TYPE_CODE_METHODPTR:
192 cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
193 break;
194
c906108c 195 case TYPE_CODE_PTR:
79a45b7d 196 if (options->format && options->format != 's')
c906108c 197 {
79a45b7d
TT
198 print_scalar_formatted (valaddr + embedded_offset, type,
199 options, 0, stream);
c906108c
SS
200 break;
201 }
79a45b7d 202 if (options->vtblprint && cp_is_vtbl_ptr_type (type))
c906108c 203 {
c5aa993b 204 /* Print the unmangled name if desired. */
c906108c
SS
205 /* Print vtable entry - we only get here if we ARE using
206 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
4478b372
JB
207 CORE_ADDR addr
208 = extract_typed_address (valaddr + embedded_offset, type);
79a45b7d 209 print_function_pointer_address (addr, stream, options->addressprint);
c906108c
SS
210 break;
211 }
212 elttype = check_typedef (TYPE_TARGET_TYPE (type));
c906108c
SS
213 {
214 addr = unpack_pointer (type, valaddr + embedded_offset);
215 print_unpacked_pointer:
c906108c
SS
216
217 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
218 {
219 /* Try to print what function it points to. */
79a45b7d
TT
220 print_function_pointer_address (addr, stream,
221 options->addressprint);
c906108c
SS
222 /* Return value is irrelevant except for string pointers. */
223 return (0);
224 }
225
79a45b7d 226 if (options->addressprint)
ed49a04f 227 fputs_filtered (paddress (addr), stream);
c906108c 228
ea37ba09 229 /* For a pointer to a textual type, also print the string
c906108c
SS
230 pointed to, unless pointer is null. */
231 /* FIXME: need to handle wchar_t here... */
232
79a45b7d
TT
233 if (textual_element_type (elttype, options->format)
234 && addr != 0)
c906108c 235 {
79a45b7d
TT
236 i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream,
237 options);
c906108c 238 }
c5aa993b
JM
239 else if (cp_is_vtbl_member (type))
240 {
c906108c
SS
241 /* print vtbl's nicely */
242 CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
243
244 struct minimal_symbol *msymbol =
c5aa993b 245 lookup_minimal_symbol_by_pc (vt_address);
c906108c
SS
246 if ((msymbol != NULL) &&
247 (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
248 {
249 fputs_filtered (" <", stream);
de5ad195 250 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
c906108c
SS
251 fputs_filtered (">", stream);
252 }
79a45b7d 253 if (vt_address && options->vtblprint)
c5aa993b 254 {
6943961c 255 struct value *vt_val;
c5aa993b
JM
256 struct symbol *wsym = (struct symbol *) NULL;
257 struct type *wtype;
c5aa993b 258 struct block *block = (struct block *) NULL;
c906108c
SS
259 int is_this_fld;
260
261 if (msymbol != NULL)
3567439c 262 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
2570f2b7 263 VAR_DOMAIN, &is_this_fld);
c5aa993b 264
c906108c
SS
265 if (wsym)
266 {
c5aa993b 267 wtype = SYMBOL_TYPE (wsym);
c906108c
SS
268 }
269 else
270 {
c5aa993b 271 wtype = TYPE_TARGET_TYPE (type);
c906108c 272 }
00a4c844 273 vt_val = value_at (wtype, vt_address);
79a45b7d 274 common_val_print (vt_val, stream, recurse + 1, options,
d8ca156b 275 current_language);
79a45b7d 276 if (options->pretty)
c906108c
SS
277 {
278 fprintf_filtered (stream, "\n");
279 print_spaces_filtered (2 + 2 * recurse, stream);
280 }
c5aa993b
JM
281 }
282 }
c906108c
SS
283
284 /* Return number of characters printed, including the terminating
285 '\0' if we reached the end. val_print_string takes care including
286 the terminating '\0' if necessary. */
287 return i;
288 }
289 break;
290
c906108c
SS
291 case TYPE_CODE_REF:
292 elttype = check_typedef (TYPE_TARGET_TYPE (type));
79a45b7d 293 if (options->addressprint)
c5aa993b 294 {
4478b372
JB
295 CORE_ADDR addr
296 = extract_typed_address (valaddr + embedded_offset, type);
c906108c 297 fprintf_filtered (stream, "@");
ed49a04f 298 fputs_filtered (paddress (addr), stream);
79a45b7d 299 if (options->deref_ref)
c906108c 300 fputs_filtered (": ", stream);
c5aa993b 301 }
c906108c 302 /* De-reference the reference. */
79a45b7d 303 if (options->deref_ref)
c906108c
SS
304 {
305 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
306 {
6943961c 307 struct value *deref_val =
c5aa993b
JM
308 value_at
309 (TYPE_TARGET_TYPE (type),
d8631d21 310 unpack_pointer (type, valaddr + embedded_offset));
79a45b7d
TT
311 common_val_print (deref_val, stream, recurse, options,
312 current_language);
c906108c
SS
313 }
314 else
315 fputs_filtered ("???", stream);
316 }
317 break;
318
319 case TYPE_CODE_UNION:
79a45b7d 320 if (recurse && !options->unionprint)
c906108c
SS
321 {
322 fprintf_filtered (stream, "{...}");
323 break;
324 }
325 /* Fall through. */
326 case TYPE_CODE_STRUCT:
015a42b4 327 /*FIXME: Abstract this away */
79a45b7d 328 if (options->vtblprint && cp_is_vtbl_ptr_type (type))
c906108c 329 {
c5aa993b 330 /* Print the unmangled name if desired. */
c906108c
SS
331 /* Print vtable entry - we only get here if NOT using
332 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
4478b372
JB
333 int offset = (embedded_offset +
334 TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8);
335 struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
336 CORE_ADDR addr
337 = extract_typed_address (valaddr + offset, field_type);
338
79a45b7d 339 print_function_pointer_address (addr, stream, options->addressprint);
c906108c
SS
340 }
341 else
79a45b7d
TT
342 cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream,
343 recurse, options, NULL, 0);
c906108c
SS
344 break;
345
346 case TYPE_CODE_ENUM:
79a45b7d 347 if (options->format)
c906108c 348 {
79a45b7d
TT
349 print_scalar_formatted (valaddr + embedded_offset, type,
350 options, 0, stream);
c906108c
SS
351 break;
352 }
353 len = TYPE_NFIELDS (type);
354 val = unpack_long (type, valaddr + embedded_offset);
355 for (i = 0; i < len; i++)
356 {
357 QUIT;
358 if (val == TYPE_FIELD_BITPOS (type, i))
359 {
360 break;
361 }
362 }
363 if (i < len)
364 {
365 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
366 }
367 else
368 {
369 print_longest (stream, 'd', 0, val);
370 }
371 break;
372
4f2aea11 373 case TYPE_CODE_FLAGS:
79a45b7d
TT
374 if (options->format)
375 print_scalar_formatted (valaddr + embedded_offset, type,
376 options, 0, stream);
4f2aea11
MK
377 else
378 val_print_type_code_flags (type, valaddr + embedded_offset, stream);
379 break;
380
c906108c 381 case TYPE_CODE_FUNC:
0d5de010 382 case TYPE_CODE_METHOD:
79a45b7d 383 if (options->format)
c906108c 384 {
79a45b7d
TT
385 print_scalar_formatted (valaddr + embedded_offset, type,
386 options, 0, stream);
c906108c
SS
387 break;
388 }
389 /* FIXME, we should consider, at least for ANSI C language, eliminating
c5aa993b 390 the distinction made between FUNCs and POINTERs to FUNCs. */
c906108c
SS
391 fprintf_filtered (stream, "{");
392 type_print (type, "", stream, -1);
393 fprintf_filtered (stream, "} ");
394 /* Try to print what function it points to, and its address. */
395 print_address_demangle (address, stream, demangle);
396 break;
397
398 case TYPE_CODE_BOOL:
79a45b7d
TT
399 if (options->format || options->output_format)
400 {
401 struct value_print_options opts = *options;
402 opts.format = (options->format ? options->format
403 : options->output_format);
404 print_scalar_formatted (valaddr + embedded_offset, type,
405 &opts, 0, stream);
406 }
c906108c
SS
407 else
408 {
409 val = unpack_long (type, valaddr + embedded_offset);
410 if (val == 0)
411 fputs_filtered ("false", stream);
412 else if (val == 1)
413 fputs_filtered ("true", stream);
414 else
415 print_longest (stream, 'd', 0, val);
416 }
417 break;
418
419 case TYPE_CODE_RANGE:
420 /* FIXME: create_range_type does not set the unsigned bit in a
c5aa993b
JM
421 range type (I think it probably should copy it from the target
422 type), so we won't print values which are too large to
423 fit in a signed integer correctly. */
c906108c 424 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
c5aa993b
JM
425 print with the target type, though, because the size of our type
426 and the target type might differ). */
c906108c
SS
427 /* FALLTHROUGH */
428
429 case TYPE_CODE_INT:
79a45b7d 430 if (options->format || options->output_format)
c906108c 431 {
79a45b7d
TT
432 struct value_print_options opts = *options;
433 opts.format = (options->format ? options->format
434 : options->output_format);
435 print_scalar_formatted (valaddr + embedded_offset, type,
436 &opts, 0, stream);
c906108c
SS
437 }
438 else
439 {
440 val_print_type_code_int (type, valaddr + embedded_offset, stream);
441 /* C and C++ has no single byte int type, char is used instead.
442 Since we don't know whether the value is really intended to
443 be used as an integer or a character, print the character
ea37ba09 444 equivalent as well. */
79a45b7d 445 if (textual_element_type (type, options->format))
c906108c
SS
446 {
447 fputs_filtered (" ", stream);
448 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
449 stream);
450 }
451 }
452 break;
453
454 case TYPE_CODE_CHAR:
79a45b7d 455 if (options->format || options->output_format)
c906108c 456 {
79a45b7d
TT
457 struct value_print_options opts = *options;
458 opts.format = (options->format ? options->format
459 : options->output_format);
460 print_scalar_formatted (valaddr + embedded_offset, type,
461 &opts, 0, stream);
c906108c
SS
462 }
463 else
464 {
96baa820
JM
465 val = unpack_long (type, valaddr + embedded_offset);
466 if (TYPE_UNSIGNED (type))
467 fprintf_filtered (stream, "%u", (unsigned int) val);
468 else
469 fprintf_filtered (stream, "%d", (int) val);
c906108c 470 fputs_filtered (" ", stream);
96baa820 471 LA_PRINT_CHAR ((unsigned char) val, stream);
c906108c
SS
472 }
473 break;
474
475 case TYPE_CODE_FLT:
79a45b7d 476 if (options->format)
c906108c 477 {
79a45b7d
TT
478 print_scalar_formatted (valaddr + embedded_offset, type,
479 options, 0, stream);
c906108c
SS
480 }
481 else
482 {
483 print_floating (valaddr + embedded_offset, type, stream);
484 }
485 break;
486
7678ef8f 487 case TYPE_CODE_DECFLOAT:
79a45b7d
TT
488 if (options->format)
489 print_scalar_formatted (valaddr + embedded_offset, type,
490 options, 0, stream);
7678ef8f
TJB
491 else
492 print_decimal_floating (valaddr + embedded_offset, type, stream);
493 break;
494
c906108c
SS
495 case TYPE_CODE_VOID:
496 fprintf_filtered (stream, "void");
497 break;
498
499 case TYPE_CODE_ERROR:
3d263c1d 500 fprintf_filtered (stream, _("<error type>"));
c906108c
SS
501 break;
502
503 case TYPE_CODE_UNDEF:
504 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
c5aa993b
JM
505 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
506 and no complete type for struct foo in that file. */
3d263c1d 507 fprintf_filtered (stream, _("<incomplete type>"));
c906108c
SS
508 break;
509
fca9e603 510 case TYPE_CODE_COMPLEX:
79a45b7d 511 if (options->format)
fca9e603
DJ
512 print_scalar_formatted (valaddr + embedded_offset,
513 TYPE_TARGET_TYPE (type),
79a45b7d 514 options, 0, stream);
fca9e603
DJ
515 else
516 print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
517 stream);
518 fprintf_filtered (stream, " + ");
79a45b7d 519 if (options->format)
fca9e603
DJ
520 print_scalar_formatted (valaddr + embedded_offset
521 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
522 TYPE_TARGET_TYPE (type),
79a45b7d 523 options, 0, stream);
fca9e603
DJ
524 else
525 print_floating (valaddr + embedded_offset
526 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
527 TYPE_TARGET_TYPE (type),
528 stream);
529 fprintf_filtered (stream, " * I");
530 break;
531
c906108c 532 default:
3d263c1d 533 error (_("Invalid C/C++ type code %d in symbol table."), TYPE_CODE (type));
c906108c
SS
534 }
535 gdb_flush (stream);
536 return (0);
537}
538\f
539int
79a45b7d
TT
540c_value_print (struct value *val, struct ui_file *stream,
541 const struct value_print_options *options)
c906108c 542{
88750304 543 struct type *type, *real_type;
c906108c 544 int full, top, using_enc;
79a45b7d
TT
545 struct value_print_options opts = *options;
546
547 opts.deref_ref = 1;
c5aa993b 548
c906108c
SS
549 /* If it is a pointer, indicate what it points to.
550
551 Print type also if it is a reference.
552
553 C++: if it is a member pointer, we will take care
554 of that when we print it. */
88750304
DJ
555
556 type = check_typedef (value_type (val));
557
558 if (TYPE_CODE (type) == TYPE_CODE_PTR
559 || TYPE_CODE (type) == TYPE_CODE_REF)
c906108c
SS
560 {
561 /* Hack: remove (char *) for char strings. Their
ea37ba09
DJ
562 type is indicated by the quoted string anyway.
563 (Don't use textual_element_type here; quoted strings
564 are always exactly (char *). */
88750304
DJ
565 if (TYPE_CODE (type) == TYPE_CODE_PTR
566 && TYPE_NAME (type) == NULL
567 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
568 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
c906108c
SS
569 {
570 /* Print nothing */
571 }
79a45b7d
TT
572 else if (options->objectprint
573 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
c5aa993b 574 {
070ad9f0
DB
575
576 if (TYPE_CODE(type) == TYPE_CODE_REF)
577 {
578 /* Copy value, change to pointer, so we don't get an
579 * error about a non-pointer type in value_rtti_target_type
580 */
6943961c 581 struct value *temparg;
070ad9f0 582 temparg=value_copy(val);
04624583 583 deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
070ad9f0
DB
584 val=temparg;
585 }
c5aa993b 586 /* Pointer to class, check real type of object */
c906108c 587 fprintf_filtered (stream, "(");
c4093a6a
JM
588 real_type = value_rtti_target_type (val, &full, &top, &using_enc);
589 if (real_type)
c5aa993b
JM
590 {
591 /* RTTI entry found */
c4093a6a
JM
592 if (TYPE_CODE (type) == TYPE_CODE_PTR)
593 {
594 /* create a pointer type pointing to the real type */
595 type = lookup_pointer_type (real_type);
596 }
597 else
598 {
599 /* create a reference type referencing the real type */
600 type = lookup_reference_type (real_type);
601 }
070ad9f0 602 /* JYG: Need to adjust pointer value. */
5086187c
AC
603 /* NOTE: cagney/2005-01-02: THIS IS BOGUS. */
604 value_contents_writeable (val)[0] -= top;
070ad9f0 605
c4093a6a
JM
606 /* Note: When we look up RTTI entries, we don't get any
607 information on const or volatile attributes */
608 }
609 type_print (type, "", stream, -1);
c906108c 610 fprintf_filtered (stream, ") ");
c5aa993b 611 }
c906108c
SS
612 else
613 {
c5aa993b 614 /* normal case */
c906108c 615 fprintf_filtered (stream, "(");
88750304 616 type_print (value_type (val), "", stream, -1);
c906108c
SS
617 fprintf_filtered (stream, ") ");
618 }
619 }
88750304 620
42be36b3
CT
621 if (!value_initialized (val))
622 fprintf_filtered (stream, " [uninitialized] ");
623
79a45b7d 624 if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
c906108c
SS
625 {
626 /* Attempt to determine real type of object */
627 real_type = value_rtti_type (val, &full, &top, &using_enc);
c5aa993b
JM
628 if (real_type)
629 {
630 /* We have RTTI information, so use it */
631 val = value_full_object (val, real_type, full, top, using_enc);
632 fprintf_filtered (stream, "(%s%s) ",
633 TYPE_NAME (real_type),
3d263c1d 634 full ? "" : _(" [incomplete object]"));
c5aa993b 635 /* Print out object: enclosing type is same as real_type if full */
46615f07
AC
636 return val_print (value_enclosing_type (val),
637 value_contents_all (val), 0,
79a45b7d
TT
638 VALUE_ADDRESS (val), stream, 0,
639 &opts, current_language);
c4093a6a
JM
640 /* Note: When we look up RTTI entries, we don't get any information on
641 const or volatile attributes */
c5aa993b 642 }
88750304 643 else if (type != check_typedef (value_enclosing_type (val)))
c5aa993b
JM
644 {
645 /* No RTTI information, so let's do our best */
646 fprintf_filtered (stream, "(%s ?) ",
4754a64e 647 TYPE_NAME (value_enclosing_type (val)));
46615f07
AC
648 return val_print (value_enclosing_type (val),
649 value_contents_all (val), 0,
79a45b7d
TT
650 VALUE_ADDRESS (val), stream, 0,
651 &opts, current_language);
c5aa993b 652 }
c906108c
SS
653 /* Otherwise, we end up at the return outside this "if" */
654 }
c5aa993b 655
46615f07 656 return val_print (type, value_contents_all (val),
13c3b5f5 657 value_embedded_offset (val),
df407dfe 658 VALUE_ADDRESS (val) + value_offset (val),
79a45b7d 659 stream, 0, &opts, current_language);
c906108c 660}
This page took 0.802947 seconds and 4 git commands to generate.