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