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