Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
CommitLineData
c906108c 1/* Support for printing C values for GDB, the GNU debugger.
1bac305b 2
42a4f53d 3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
d55e5aa6
TT
21
22/* Local non-gdb includes. */
c906108c 23#include "c-lang.h"
015a42b4 24#include "cp-abi.h"
d55e5aa6
TT
25#include "expression.h"
26#include "gdbtypes.h"
27#include "language.h"
77e371c0 28#include "objfiles.h"
d55e5aa6
TT
29#include "symtab.h"
30#include "target.h"
31#include "valprint.h"
32#include "value.h"
33
c906108c 34\f
c5aa993b 35
96c07c5b 36/* A helper for c_textual_element_type. This checks the name of the
6c7a06a3
TT
37 typedef. This is bogus but it isn't apparent that the compiler
38 provides us the help we may need. */
39
40static int
41textual_name (const char *name)
42{
43 return (!strcmp (name, "wchar_t")
44 || !strcmp (name, "char16_t")
45 || !strcmp (name, "char32_t"));
46}
47
ea37ba09
DJ
48/* Apply a heuristic to decide whether an array of TYPE or a pointer
49 to TYPE should be printed as a textual string. Return non-zero if
50 it should, or zero if it should be treated as an array of integers
aff410f1
MS
51 or pointer to integers. FORMAT is the current format letter, or 0
52 if none.
ea37ba09
DJ
53
54 We guess that "char" is a character. Explicitly signed and
55 unsigned character types are also characters. Integer data from
56 vector types is not. The user can override this by using the /s
57 format letter. */
58
96c07c5b
TT
59int
60c_textual_element_type (struct type *type, char format)
ea37ba09 61{
85e306ed 62 struct type *true_type, *iter_type;
ea37ba09
DJ
63
64 if (format != 0 && format != 's')
65 return 0;
66
85e306ed
TT
67 /* We also rely on this for its side effect of setting up all the
68 typedef pointers. */
69 true_type = check_typedef (type);
70
ea37ba09
DJ
71 /* TYPE_CODE_CHAR is always textual. */
72 if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
73 return 1;
85e306ed 74
6c7a06a3
TT
75 /* Any other character-like types must be integral. */
76 if (TYPE_CODE (true_type) != TYPE_CODE_INT)
77 return 0;
78
85e306ed
TT
79 /* We peel typedefs one by one, looking for a match. */
80 iter_type = type;
81 while (iter_type)
82 {
83 /* Check the name of the type. */
84 if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
85 return 1;
86
87 if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
88 break;
89
90 /* Peel a single typedef. If the typedef doesn't have a target
91 type, we use check_typedef and hope the result is ok -- it
92 might be for C++, where wchar_t is a built-in type. */
93 if (TYPE_TARGET_TYPE (iter_type))
94 iter_type = TYPE_TARGET_TYPE (iter_type);
95 else
96 iter_type = check_typedef (iter_type);
97 }
ea37ba09
DJ
98
99 if (format == 's')
100 {
aff410f1
MS
101 /* Print this as a string if we can manage it. For now, no wide
102 character support. */
ea37ba09
DJ
103 if (TYPE_CODE (true_type) == TYPE_CODE_INT
104 && TYPE_LENGTH (true_type) == 1)
105 return 1;
106 }
107 else
108 {
109 /* If a one-byte TYPE_CODE_INT is missing the not-a-character
110 flag, then we treat it as text; otherwise, we assume it's
111 being used as data. */
112 if (TYPE_CODE (true_type) == TYPE_CODE_INT
113 && TYPE_LENGTH (true_type) == 1
114 && !TYPE_NOTTEXT (true_type))
115 return 1;
116 }
117
118 return 0;
119}
120
e88acd96
TT
121/* Decorations for C. */
122
123static const struct generic_val_print_decorations c_decorations =
124{
125 "",
126 " + ",
127 " * I",
128 "true",
129 "false",
00272ec4
TT
130 "void",
131 "{",
132 "}"
e88acd96
TT
133};
134
1033c33c
SM
135/* Print a pointer based on the type of its target.
136
137 Arguments to this functions are roughly the same as those in c_val_print.
138 A difference is that ADDRESS is the address to print, with embedded_offset
139 already added. UNRESOLVED_ELTTYPE and ELTTYPE represent the pointed type,
140 respectively before and after check_typedef. */
141
142static void
143print_unpacked_pointer (struct type *type, struct type *elttype,
144 struct type *unresolved_elttype,
145 const gdb_byte *valaddr, int embedded_offset,
146 CORE_ADDR address, struct ui_file *stream, int recurse,
147 const struct value_print_options *options)
148{
149 int want_space = 0;
150 struct gdbarch *gdbarch = get_type_arch (type);
151
152 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
153 {
154 /* Try to print what function it points to. */
155 print_function_pointer_address (options, gdbarch, address, stream);
156 return;
157 }
158
159 if (options->symbol_print)
160 want_space = print_address_demangle (options, gdbarch, address, stream,
161 demangle);
162 else if (options->addressprint)
163 {
164 fputs_filtered (paddress (gdbarch, address), stream);
165 want_space = 1;
166 }
167
168 /* For a pointer to a textual type, also print the string
169 pointed to, unless pointer is null. */
170
171 if (c_textual_element_type (unresolved_elttype, options->format)
172 && address != 0)
173 {
174 if (want_space)
175 fputs_filtered (" ", stream);
176 val_print_string (unresolved_elttype, NULL, address, -1, stream, options);
177 }
178 else if (cp_is_vtbl_member (type))
179 {
180 /* Print vtbl's nicely. */
181 CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
182 struct bound_minimal_symbol msymbol =
183 lookup_minimal_symbol_by_pc (vt_address);
184
185 /* If 'symbol_print' is set, we did the work above. */
186 if (!options->symbol_print
187 && (msymbol.minsym != NULL)
188 && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
189 {
190 if (want_space)
191 fputs_filtered (" ", stream);
192 fputs_filtered (" <", stream);
193 fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream);
194 fputs_filtered (">", stream);
195 want_space = 1;
196 }
197
198 if (vt_address && options->vtblprint)
199 {
200 struct value *vt_val;
be903358 201 struct symbol *wsym = NULL;
1033c33c 202 struct type *wtype;
1033c33c
SM
203
204 if (want_space)
205 fputs_filtered (" ", stream);
206
207 if (msymbol.minsym != NULL)
de63c46b
PA
208 {
209 const char *search_name
210 = MSYMBOL_SEARCH_NAME (msymbol.minsym);
582942f4 211 wsym = lookup_symbol_search_name (search_name, NULL,
de63c46b
PA
212 VAR_DOMAIN).symbol;
213 }
1033c33c
SM
214
215 if (wsym)
216 {
217 wtype = SYMBOL_TYPE (wsym);
218 }
219 else
220 {
221 wtype = unresolved_elttype;
222 }
223 vt_val = value_at (wtype, vt_address);
224 common_val_print (vt_val, stream, recurse + 1, options,
225 current_language);
226 if (options->prettyformat)
227 {
228 fprintf_filtered (stream, "\n");
229 print_spaces_filtered (2 + 2 * recurse, stream);
230 }
231 }
232 }
233}
234
0b6ef777 235/* c_val_print helper for TYPE_CODE_ARRAY. */
c906108c 236
0b6ef777
SM
237static void
238c_val_print_array (struct type *type, const gdb_byte *valaddr,
239 int embedded_offset, CORE_ADDR address,
240 struct ui_file *stream, int recurse,
e8b24d9f 241 struct value *original_value,
0b6ef777 242 const struct value_print_options *options)
c906108c 243{
0b6ef777
SM
244 struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
245 struct type *elttype = check_typedef (unresolved_elttype);
3ae385af
SM
246 struct gdbarch *arch = get_type_arch (type);
247 int unit_size = gdbarch_addressable_memory_unit_size (arch);
c906108c 248
0b6ef777 249 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
c906108c 250 {
0b6ef777
SM
251 LONGEST low_bound, high_bound;
252 int eltlen, len;
253 struct gdbarch *gdbarch = get_type_arch (type);
254 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
255 unsigned int i = 0; /* Number of characters printed. */
256
257 if (!get_array_bounds (type, &low_bound, &high_bound))
258 error (_("Could not determine the array high bound"));
259
260 eltlen = TYPE_LENGTH (elttype);
261 len = high_bound - low_bound + 1;
262 if (options->prettyformat_arrays)
c906108c 263 {
0b6ef777
SM
264 print_spaces_filtered (2 + 2 * recurse, stream);
265 }
dbc98a8b 266
0b6ef777
SM
267 /* Print arrays of textual chars with a string syntax, as
268 long as the entire array is valid. */
269 if (c_textual_element_type (unresolved_elttype,
270 options->format)
271 && value_bytes_available (original_value, embedded_offset,
272 TYPE_LENGTH (type))
273 && !value_bits_any_optimized_out (original_value,
274 TARGET_CHAR_BIT * embedded_offset,
275 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
276 {
277 int force_ellipses = 0;
ea37ba09 278
0b6ef777
SM
279 /* If requested, look for the first null char and only
280 print elements up to it. */
281 if (options->stop_print_at_null)
c906108c 282 {
0b6ef777
SM
283 unsigned int temp_len;
284
285 for (temp_len = 0;
286 (temp_len < len
287 && temp_len < options->print_max
3ae385af
SM
288 && extract_unsigned_integer (valaddr
289 + embedded_offset * unit_size
0b6ef777
SM
290 + temp_len * eltlen,
291 eltlen, byte_order) != 0);
292 ++temp_len)
293 ;
294
295 /* Force LA_PRINT_STRING to print ellipses if
296 we've printed the maximum characters and
297 the next character is not \000. */
298 if (temp_len == options->print_max && temp_len < len)
c906108c 299 {
0b6ef777 300 ULONGEST val
3ae385af
SM
301 = extract_unsigned_integer (valaddr
302 + embedded_offset * unit_size
0b6ef777
SM
303 + temp_len * eltlen,
304 eltlen, byte_order);
305 if (val != 0)
306 force_ellipses = 1;
c906108c 307 }
c5aa993b 308
0b6ef777
SM
309 len = temp_len;
310 }
311
312 LA_PRINT_STRING (stream, unresolved_elttype,
3ae385af 313 valaddr + embedded_offset * unit_size, len,
0b6ef777
SM
314 NULL, force_ellipses, options);
315 i = len;
316 }
317 else
318 {
319 fprintf_filtered (stream, "{");
320 /* If this is a virtual function table, print the 0th
321 entry specially, and the rest of the members
322 normally. */
323 if (cp_is_vtbl_ptr_type (elttype))
324 {
325 i = 1;
326 fprintf_filtered (stream, _("%d vtable entries"),
327 len - 1);
c906108c
SS
328 }
329 else
330 {
0b6ef777 331 i = 0;
c906108c 332 }
e8b24d9f 333 val_print_array_elements (type, embedded_offset,
0b6ef777
SM
334 address, stream,
335 recurse, original_value, options, i);
336 fprintf_filtered (stream, "}");
c906108c 337 }
0b6ef777
SM
338 }
339 else
340 {
1033c33c
SM
341 /* Array of unspecified length: treat like pointer to first elt. */
342 print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
343 embedded_offset, address + embedded_offset,
344 stream, recurse, options);
0b6ef777
SM
345 }
346}
347
1c67f032
SM
348/* c_val_print helper for TYPE_CODE_PTR. */
349
350static void
351c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
352 int embedded_offset, struct ui_file *stream, int recurse,
e8b24d9f 353 struct value *original_value,
1c67f032
SM
354 const struct value_print_options *options)
355{
3ae385af
SM
356 struct gdbarch *arch = get_type_arch (type);
357 int unit_size = gdbarch_addressable_memory_unit_size (arch);
358
1c67f032
SM
359 if (options->format && options->format != 's')
360 {
e8b24d9f 361 val_print_scalar_formatted (type, embedded_offset,
1c67f032
SM
362 original_value, options, 0, stream);
363 }
364 else if (options->vtblprint && cp_is_vtbl_ptr_type (type))
365 {
366 /* Print the unmangled name if desired. */
367 /* Print vtable entry - we only get here if we ARE using
368 -fvtable_thunks. (Otherwise, look under
369 TYPE_CODE_STRUCT.) */
370 CORE_ADDR addr
371 = extract_typed_address (valaddr + embedded_offset, type);
372 struct gdbarch *gdbarch = get_type_arch (type);
373
374 print_function_pointer_address (options, gdbarch, addr, stream);
375 }
376 else
377 {
378 struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
379 struct type *elttype = check_typedef (unresolved_elttype);
3ae385af
SM
380 CORE_ADDR addr = unpack_pointer (type,
381 valaddr + embedded_offset * unit_size);
1c67f032
SM
382
383 print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
384 embedded_offset, addr, stream, recurse, options);
385 }
386}
387
9e4f353c
SM
388/* c_val_print helper for TYPE_CODE_STRUCT. */
389
390static void
391c_val_print_struct (struct type *type, const gdb_byte *valaddr,
392 int embedded_offset, CORE_ADDR address,
393 struct ui_file *stream, int recurse,
e8b24d9f 394 struct value *original_value,
9e4f353c
SM
395 const struct value_print_options *options)
396{
397 if (options->vtblprint && cp_is_vtbl_ptr_type (type))
398 {
399 /* Print the unmangled name if desired. */
400 /* Print vtable entry - we only get here if NOT using
401 -fvtable_thunks. (Otherwise, look under
402 TYPE_CODE_PTR.) */
403 struct gdbarch *gdbarch = get_type_arch (type);
404 int offset = (embedded_offset
405 + TYPE_FIELD_BITPOS (type,
406 VTBL_FNADDR_OFFSET) / 8);
407 struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
408 CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
409
410 print_function_pointer_address (options, gdbarch, addr, stream);
411 }
412 else
413 cp_print_value_fields_rtti (type, valaddr,
414 embedded_offset, address,
415 stream, recurse,
416 original_value, options,
417 NULL, 0);
418}
419
420/* c_val_print helper for TYPE_CODE_UNION. */
421
422static void
423c_val_print_union (struct type *type, const gdb_byte *valaddr,
424 int embedded_offset, CORE_ADDR address,
425 struct ui_file *stream, int recurse,
e8b24d9f 426 struct value *original_value,
9e4f353c
SM
427 const struct value_print_options *options)
428{
429 if (recurse && !options->unionprint)
430 {
431 fprintf_filtered (stream, "{...}");
432 }
433 else
434 {
435 c_val_print_struct (type, valaddr, embedded_offset, address, stream,
436 recurse, original_value, options);
437 }
438}
439
49f7fe28
SM
440/* c_val_print helper for TYPE_CODE_INT. */
441
442static void
443c_val_print_int (struct type *type, struct type *unresolved_type,
444 const gdb_byte *valaddr, int embedded_offset,
e8b24d9f 445 struct ui_file *stream, struct value *original_value,
49f7fe28
SM
446 const struct value_print_options *options)
447{
3ae385af
SM
448 struct gdbarch *arch = get_type_arch (type);
449 int unit_size = gdbarch_addressable_memory_unit_size (arch);
450
49f7fe28
SM
451 if (options->format || options->output_format)
452 {
453 struct value_print_options opts = *options;
454
455 opts.format = (options->format ? options->format
456 : options->output_format);
e8b24d9f 457 val_print_scalar_formatted (type, embedded_offset,
49f7fe28
SM
458 original_value, &opts, 0, stream);
459 }
460 else
461 {
f12f6bad
TT
462 val_print_scalar_formatted (type, embedded_offset,
463 original_value, options, 0, stream);
49f7fe28
SM
464 /* C and C++ has no single byte int type, char is used
465 instead. Since we don't know whether the value is really
466 intended to be used as an integer or a character, print
467 the character equivalent as well. */
468 if (c_textual_element_type (unresolved_type, options->format))
469 {
470 fputs_filtered (" ", stream);
3ae385af
SM
471 LA_PRINT_CHAR (unpack_long (type,
472 valaddr + embedded_offset * unit_size),
49f7fe28
SM
473 unresolved_type, stream);
474 }
475 }
476}
477
938c69a1
SM
478/* c_val_print helper for TYPE_CODE_MEMBERPTR. */
479
480static void
481c_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
482 int embedded_offset, CORE_ADDR address,
483 struct ui_file *stream, int recurse,
e8b24d9f 484 struct value *original_value,
938c69a1
SM
485 const struct value_print_options *options)
486{
487 if (!options->format)
488 {
489 cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
490 }
491 else
492 {
e8b24d9f 493 generic_val_print (type, embedded_offset, address, stream,
938c69a1
SM
494 recurse, original_value, options, &c_decorations);
495 }
496}
497
0b6ef777
SM
498/* See val_print for a description of the various parameters of this
499 function; they are identical. */
500
501void
e8b24d9f 502c_val_print (struct type *type,
0b6ef777
SM
503 int embedded_offset, CORE_ADDR address,
504 struct ui_file *stream, int recurse,
e8b24d9f 505 struct value *original_value,
0b6ef777
SM
506 const struct value_print_options *options)
507{
0b6ef777 508 struct type *unresolved_type = type;
e8b24d9f 509 const gdb_byte *valaddr = value_contents_for_printing (original_value);
0b6ef777 510
f168693b 511 type = check_typedef (type);
0b6ef777
SM
512 switch (TYPE_CODE (type))
513 {
514 case TYPE_CODE_ARRAY:
515 c_val_print_array (type, valaddr, embedded_offset, address, stream,
516 recurse, original_value, options);
1033c33c 517 break;
c906108c 518
0d5de010
DJ
519 case TYPE_CODE_METHODPTR:
520 cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
521 break;
522
c906108c 523 case TYPE_CODE_PTR:
1c67f032
SM
524 c_val_print_ptr (type, valaddr, embedded_offset, stream, recurse,
525 original_value, options);
c906108c
SS
526 break;
527
c906108c 528 case TYPE_CODE_UNION:
9e4f353c
SM
529 c_val_print_union (type, valaddr, embedded_offset, address, stream,
530 recurse, original_value, options);
531 break;
532
c906108c 533 case TYPE_CODE_STRUCT:
9e4f353c
SM
534 c_val_print_struct (type, valaddr, embedded_offset, address, stream,
535 recurse, original_value, options);
c906108c
SS
536 break;
537
c906108c 538 case TYPE_CODE_INT:
49f7fe28
SM
539 c_val_print_int (type, unresolved_type, valaddr, embedded_offset, stream,
540 original_value, options);
c906108c
SS
541 break;
542
e88acd96 543 case TYPE_CODE_MEMBERPTR:
938c69a1
SM
544 c_val_print_memberptr (type, valaddr, embedded_offset, address, stream,
545 recurse, original_value, options);
546 break;
c906108c 547
e88acd96 548 case TYPE_CODE_REF:
e1cb3213 549 case TYPE_CODE_RVALUE_REF:
e88acd96
TT
550 case TYPE_CODE_ENUM:
551 case TYPE_CODE_FLAGS:
552 case TYPE_CODE_FUNC:
553 case TYPE_CODE_METHOD:
554 case TYPE_CODE_BOOL:
555 case TYPE_CODE_RANGE:
c906108c 556 case TYPE_CODE_FLT:
7678ef8f 557 case TYPE_CODE_DECFLOAT:
c906108c 558 case TYPE_CODE_VOID:
c906108c 559 case TYPE_CODE_ERROR:
c906108c 560 case TYPE_CODE_UNDEF:
fca9e603 561 case TYPE_CODE_COMPLEX:
e88acd96 562 case TYPE_CODE_CHAR:
c906108c 563 default:
e8b24d9f 564 generic_val_print (type, embedded_offset, address,
e88acd96
TT
565 stream, recurse, original_value, options,
566 &c_decorations);
567 break;
c906108c 568 }
c906108c
SS
569}
570\f
8e069a98 571void
79a45b7d
TT
572c_value_print (struct value *val, struct ui_file *stream,
573 const struct value_print_options *options)
c906108c 574{
6c7a06a3 575 struct type *type, *real_type, *val_type;
6b850546
DT
576 int full, using_enc;
577 LONGEST top;
79a45b7d
TT
578 struct value_print_options opts = *options;
579
580 opts.deref_ref = 1;
c5aa993b 581
c906108c
SS
582 /* If it is a pointer, indicate what it points to.
583
584 Print type also if it is a reference.
585
586 C++: if it is a member pointer, we will take care
587 of that when we print it. */
88750304 588
6c7a06a3
TT
589 /* Preserve the original type before stripping typedefs. We prefer
590 to pass down the original type when possible, but for local
591 checks it is better to look past the typedefs. */
592 val_type = value_type (val);
593 type = check_typedef (val_type);
88750304 594
e1cb3213 595 if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
c906108c
SS
596 {
597 /* Hack: remove (char *) for char strings. Their
ea37ba09 598 type is indicated by the quoted string anyway.
96c07c5b 599 (Don't use c_textual_element_type here; quoted strings
6c7a06a3
TT
600 are always exactly (char *), (wchar_t *), or the like. */
601 if (TYPE_CODE (val_type) == TYPE_CODE_PTR
602 && TYPE_NAME (val_type) == NULL
603 && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
aff410f1
MS
604 && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
605 "char") == 0
6c7a06a3 606 || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
c906108c 607 {
aff410f1 608 /* Print nothing. */
c906108c 609 }
79a45b7d 610 else if (options->objectprint
4753d33b 611 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
c5aa993b 612 {
a65cfae5
AV
613 int is_ref = TYPE_IS_REFERENCE (type);
614 enum type_code refcode = TYPE_CODE_UNDEF;
5f2e6b00
TT
615
616 if (is_ref)
a65cfae5
AV
617 {
618 val = value_addr (val);
619 refcode = TYPE_CODE (type);
620 }
070ad9f0 621
aff410f1 622 /* Pointer to class, check real type of object. */
c906108c 623 fprintf_filtered (stream, "(");
ec0a52e1
PA
624
625 if (value_entirely_available (val))
476350ba 626 {
dfcee124
AG
627 real_type = value_rtti_indirect_type (val, &full, &top,
628 &using_enc);
ec0a52e1
PA
629 if (real_type)
630 {
631 /* RTTI entry found. */
dfcee124
AG
632 type = real_type;
633
ec0a52e1 634 /* Need to adjust pointer value. */
5f2e6b00
TT
635 val = value_from_pointer (real_type,
636 value_as_address (val) - top);
637
ec0a52e1
PA
638 /* Note: When we look up RTTI entries, we don't get
639 any information on const or volatile
640 attributes. */
641 }
642 }
476350ba
MG
643
644 if (is_ref)
645 {
a65cfae5 646 val = value_ref (value_ind (val), refcode);
476350ba
MG
647 type = value_type (val);
648 }
649
650 type_print (type, "", stream, -1);
c906108c 651 fprintf_filtered (stream, ") ");
6c7a06a3 652 val_type = type;
c5aa993b 653 }
c906108c
SS
654 else
655 {
c5aa993b 656 /* normal case */
c906108c 657 fprintf_filtered (stream, "(");
88750304 658 type_print (value_type (val), "", stream, -1);
c906108c
SS
659 fprintf_filtered (stream, ") ");
660 }
661 }
88750304 662
42be36b3
CT
663 if (!value_initialized (val))
664 fprintf_filtered (stream, " [uninitialized] ");
665
4753d33b 666 if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_STRUCT))
c906108c 667 {
aff410f1 668 /* Attempt to determine real type of object. */
c906108c 669 real_type = value_rtti_type (val, &full, &top, &using_enc);
c5aa993b
JM
670 if (real_type)
671 {
aff410f1
MS
672 /* We have RTTI information, so use it. */
673 val = value_full_object (val, real_type,
674 full, top, using_enc);
c5aa993b
JM
675 fprintf_filtered (stream, "(%s%s) ",
676 TYPE_NAME (real_type),
3d263c1d 677 full ? "" : _(" [incomplete object]"));
aff410f1
MS
678 /* Print out object: enclosing type is same as real_type if
679 full. */
8e069a98 680 val_print (value_enclosing_type (val),
e8b24d9f 681 0,
8e069a98
TT
682 value_address (val), stream, 0,
683 val, &opts, current_language);
684 return;
aff410f1
MS
685 /* Note: When we look up RTTI entries, we don't get any
686 information on const or volatile attributes. */
c5aa993b 687 }
88750304 688 else if (type != check_typedef (value_enclosing_type (val)))
c5aa993b 689 {
aff410f1 690 /* No RTTI information, so let's do our best. */
c5aa993b 691 fprintf_filtered (stream, "(%s ?) ",
4754a64e 692 TYPE_NAME (value_enclosing_type (val)));
8e069a98 693 val_print (value_enclosing_type (val),
e8b24d9f 694 0,
8e069a98
TT
695 value_address (val), stream, 0,
696 val, &opts, current_language);
697 return;
c5aa993b 698 }
aff410f1 699 /* Otherwise, we end up at the return outside this "if". */
c906108c 700 }
c5aa993b 701
e8b24d9f 702 val_print (val_type,
8e069a98
TT
703 value_embedded_offset (val),
704 value_address (val),
705 stream, 0,
706 val, &opts, current_language);
c906108c 707}
This page took 1.261078 seconds and 4 git commands to generate.