* value.h (val_print): Return void.
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
CommitLineData
c906108c 1/* Support for printing C values for GDB, the GNU debugger.
1bac305b 2
0b302171
JB
3 Copyright (C) 1986, 1988-1989, 1991-2001, 2003, 2005-2012 Free
4 Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#include "defs.h"
309367d4 22#include "gdb_string.h"
c906108c
SS
23#include "symtab.h"
24#include "gdbtypes.h"
25#include "expression.h"
26#include "value.h"
c906108c
SS
27#include "valprint.h"
28#include "language.h"
29#include "c-lang.h"
015a42b4 30#include "cp-abi.h"
e2d0e7eb 31#include "target.h"
c906108c 32\f
c5aa993b 33
96c07c5b 34/* A helper for c_textual_element_type. This checks the name of the
6c7a06a3
TT
35 typedef. This is bogus but it isn't apparent that the compiler
36 provides us the help we may need. */
37
38static int
39textual_name (const char *name)
40{
41 return (!strcmp (name, "wchar_t")
42 || !strcmp (name, "char16_t")
43 || !strcmp (name, "char32_t"));
44}
45
ea37ba09
DJ
46/* Apply a heuristic to decide whether an array of TYPE or a pointer
47 to TYPE should be printed as a textual string. Return non-zero if
48 it should, or zero if it should be treated as an array of integers
aff410f1
MS
49 or pointer to integers. FORMAT is the current format letter, or 0
50 if none.
ea37ba09
DJ
51
52 We guess that "char" is a character. Explicitly signed and
53 unsigned character types are also characters. Integer data from
54 vector types is not. The user can override this by using the /s
55 format letter. */
56
96c07c5b
TT
57int
58c_textual_element_type (struct type *type, char format)
ea37ba09 59{
85e306ed 60 struct type *true_type, *iter_type;
ea37ba09
DJ
61
62 if (format != 0 && format != 's')
63 return 0;
64
85e306ed
TT
65 /* We also rely on this for its side effect of setting up all the
66 typedef pointers. */
67 true_type = check_typedef (type);
68
ea37ba09
DJ
69 /* TYPE_CODE_CHAR is always textual. */
70 if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
71 return 1;
85e306ed 72
6c7a06a3
TT
73 /* Any other character-like types must be integral. */
74 if (TYPE_CODE (true_type) != TYPE_CODE_INT)
75 return 0;
76
85e306ed
TT
77 /* We peel typedefs one by one, looking for a match. */
78 iter_type = type;
79 while (iter_type)
80 {
81 /* Check the name of the type. */
82 if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
83 return 1;
84
85 if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
86 break;
87
88 /* Peel a single typedef. If the typedef doesn't have a target
89 type, we use check_typedef and hope the result is ok -- it
90 might be for C++, where wchar_t is a built-in type. */
91 if (TYPE_TARGET_TYPE (iter_type))
92 iter_type = TYPE_TARGET_TYPE (iter_type);
93 else
94 iter_type = check_typedef (iter_type);
95 }
ea37ba09
DJ
96
97 if (format == 's')
98 {
aff410f1
MS
99 /* Print this as a string if we can manage it. For now, no wide
100 character support. */
ea37ba09
DJ
101 if (TYPE_CODE (true_type) == TYPE_CODE_INT
102 && TYPE_LENGTH (true_type) == 1)
103 return 1;
104 }
105 else
106 {
107 /* If a one-byte TYPE_CODE_INT is missing the not-a-character
108 flag, then we treat it as text; otherwise, we assume it's
109 being used as data. */
110 if (TYPE_CODE (true_type) == TYPE_CODE_INT
111 && TYPE_LENGTH (true_type) == 1
112 && !TYPE_NOTTEXT (true_type))
113 return 1;
114 }
115
116 return 0;
117}
118
32b72a42
PA
119/* See val_print for a description of the various parameters of this
120 function; they are identical. The semantics of the return value is
121 also identical to val_print. */
c906108c
SS
122
123int
aff410f1
MS
124c_val_print (struct type *type, const gdb_byte *valaddr,
125 int embedded_offset, CORE_ADDR address,
126 struct ui_file *stream, int recurse,
0e03807e 127 const struct value *original_value,
79a45b7d 128 const struct value_print_options *options)
c906108c 129{
50810684 130 struct gdbarch *gdbarch = get_type_arch (type);
e17a4113 131 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
aff410f1 132 unsigned int i = 0; /* Number of characters printed. */
c906108c 133 unsigned len;
6c7a06a3
TT
134 struct type *elttype, *unresolved_elttype;
135 struct type *unresolved_type = type;
c906108c
SS
136 unsigned eltlen;
137 LONGEST val;
138 CORE_ADDR addr;
139
140 CHECK_TYPEDEF (type);
141 switch (TYPE_CODE (type))
142 {
143 case TYPE_CODE_ARRAY:
6c7a06a3
TT
144 unresolved_elttype = TYPE_TARGET_TYPE (type);
145 elttype = check_typedef (unresolved_elttype);
146 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
c906108c 147 {
dbc98a8b
KW
148 LONGEST low_bound, high_bound;
149
150 if (!get_array_bounds (type, &low_bound, &high_bound))
151 error (_("Could not determine the array high bound"));
152
c906108c 153 eltlen = TYPE_LENGTH (elttype);
dbc98a8b 154 len = high_bound - low_bound + 1;
79a45b7d 155 if (options->prettyprint_arrays)
c906108c
SS
156 {
157 print_spaces_filtered (2 + 2 * recurse, stream);
158 }
ea37ba09 159
0e03807e
TT
160 /* Print arrays of textual chars with a string syntax, as
161 long as the entire array is valid. */
aff410f1
MS
162 if (c_textual_element_type (unresolved_elttype,
163 options->format)
9fc6d940
PA
164 && value_bytes_available (original_value, embedded_offset,
165 TYPE_LENGTH (type))
0e03807e
TT
166 && value_bits_valid (original_value,
167 TARGET_CHAR_BIT * embedded_offset,
168 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
c906108c 169 {
aff410f1
MS
170 /* If requested, look for the first null char and only
171 print elements up to it. */
79a45b7d 172 if (options->stop_print_at_null)
c906108c 173 {
745b8ca0 174 unsigned int temp_len;
c5aa993b 175
c906108c 176 for (temp_len = 0;
6c7a06a3
TT
177 (temp_len < len
178 && temp_len < options->print_max
179 && extract_unsigned_integer (valaddr + embedded_offset
180 + temp_len * eltlen,
421d5d99 181 eltlen, byte_order) != 0);
6c7a06a3
TT
182 ++temp_len)
183 ;
c906108c
SS
184 len = temp_len;
185 }
c5aa993b 186
6c7a06a3 187 LA_PRINT_STRING (stream, unresolved_elttype,
be759fcf
PM
188 valaddr + embedded_offset, len,
189 NULL, 0, options);
c906108c
SS
190 i = len;
191 }
192 else
193 {
194 fprintf_filtered (stream, "{");
195 /* If this is a virtual function table, print the 0th
aff410f1
MS
196 entry specially, and the rest of the members
197 normally. */
c906108c
SS
198 if (cp_is_vtbl_ptr_type (elttype))
199 {
200 i = 1;
aff410f1
MS
201 fprintf_filtered (stream, _("%d vtable entries"),
202 len - 1);
c906108c
SS
203 }
204 else
205 {
206 i = 0;
207 }
490f124f
PA
208 val_print_array_elements (type, valaddr, embedded_offset,
209 address, stream,
210 recurse, original_value, options, i);
c906108c
SS
211 fprintf_filtered (stream, "}");
212 }
213 break;
214 }
aff410f1
MS
215 /* Array of unspecified length: treat like pointer to first
216 elt. */
13163d80 217 addr = address + embedded_offset;
c906108c
SS
218 goto print_unpacked_pointer;
219
0d5de010 220 case TYPE_CODE_MEMBERPTR:
79a45b7d 221 if (options->format)
0d5de010 222 {
ab2188aa
PA
223 val_print_scalar_formatted (type, valaddr, embedded_offset,
224 original_value, options, 0, stream);
0d5de010
DJ
225 break;
226 }
ad4820ab 227 cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
0d5de010
DJ
228 break;
229
230 case TYPE_CODE_METHODPTR:
231 cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
232 break;
233
c906108c 234 case TYPE_CODE_PTR:
79a45b7d 235 if (options->format && options->format != 's')
c906108c 236 {
ab2188aa
PA
237 val_print_scalar_formatted (type, valaddr, embedded_offset,
238 original_value, options, 0, stream);
c906108c
SS
239 break;
240 }
79a45b7d 241 if (options->vtblprint && cp_is_vtbl_ptr_type (type))
c906108c 242 {
c5aa993b 243 /* Print the unmangled name if desired. */
c906108c 244 /* Print vtable entry - we only get here if we ARE using
aff410f1
MS
245 -fvtable_thunks. (Otherwise, look under
246 TYPE_CODE_STRUCT.) */
4478b372
JB
247 CORE_ADDR addr
248 = extract_typed_address (valaddr + embedded_offset, type);
c5504eaf 249
50810684
UW
250 print_function_pointer_address (gdbarch, addr, stream,
251 options->addressprint);
c906108c
SS
252 break;
253 }
6c7a06a3
TT
254 unresolved_elttype = TYPE_TARGET_TYPE (type);
255 elttype = check_typedef (unresolved_elttype);
c906108c
SS
256 {
257 addr = unpack_pointer (type, valaddr + embedded_offset);
258 print_unpacked_pointer:
c906108c
SS
259
260 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
261 {
262 /* Try to print what function it points to. */
50810684 263 print_function_pointer_address (gdbarch, addr, stream,
79a45b7d 264 options->addressprint);
aff410f1
MS
265 /* Return value is irrelevant except for string
266 pointers. */
c906108c
SS
267 return (0);
268 }
269
79a45b7d 270 if (options->addressprint)
5af949e3 271 fputs_filtered (paddress (gdbarch, addr), stream);
c906108c 272
ea37ba09 273 /* For a pointer to a textual type, also print the string
c906108c 274 pointed to, unless pointer is null. */
c906108c 275
aff410f1
MS
276 if (c_textual_element_type (unresolved_elttype,
277 options->format)
79a45b7d 278 && addr != 0)
c906108c 279 {
aff410f1
MS
280 i = val_print_string (unresolved_elttype, NULL,
281 addr, -1,
282 stream, options);
c906108c 283 }
c5aa993b
JM
284 else if (cp_is_vtbl_member (type))
285 {
aff410f1
MS
286 /* Print vtbl's nicely. */
287 CORE_ADDR vt_address = unpack_pointer (type,
288 valaddr
289 + embedded_offset);
c906108c
SS
290
291 struct minimal_symbol *msymbol =
c5aa993b 292 lookup_minimal_symbol_by_pc (vt_address);
5aafa1cc
PM
293 if ((msymbol != NULL)
294 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
c906108c
SS
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)
aff410f1
MS
309 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol),
310 block, VAR_DOMAIN,
311 &is_this_fld);
c5aa993b 312
c906108c
SS
313 if (wsym)
314 {
c5aa993b 315 wtype = SYMBOL_TYPE (wsym);
c906108c
SS
316 }
317 else
318 {
6c7a06a3 319 wtype = unresolved_elttype;
c906108c 320 }
00a4c844 321 vt_val = value_at (wtype, vt_address);
aff410f1
MS
322 common_val_print (vt_val, stream, recurse + 1,
323 options, current_language);
79a45b7d 324 if (options->pretty)
c906108c
SS
325 {
326 fprintf_filtered (stream, "\n");
327 print_spaces_filtered (2 + 2 * recurse, stream);
328 }
c5aa993b
JM
329 }
330 }
c906108c 331
aff410f1
MS
332 /* Return number of characters printed, including the
333 terminating '\0' if we reached the end. val_print_string
334 takes care including the terminating '\0' if
335 necessary. */
c906108c
SS
336 return i;
337 }
338 break;
339
c906108c
SS
340 case TYPE_CODE_REF:
341 elttype = check_typedef (TYPE_TARGET_TYPE (type));
79a45b7d 342 if (options->addressprint)
c5aa993b 343 {
4478b372
JB
344 CORE_ADDR addr
345 = extract_typed_address (valaddr + embedded_offset, type);
c5504eaf 346
c906108c 347 fprintf_filtered (stream, "@");
5af949e3 348 fputs_filtered (paddress (gdbarch, addr), stream);
79a45b7d 349 if (options->deref_ref)
c906108c 350 fputs_filtered (": ", stream);
c5aa993b 351 }
c906108c 352 /* De-reference the reference. */
79a45b7d 353 if (options->deref_ref)
c906108c
SS
354 {
355 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
356 {
a471c594
JK
357 struct value *deref_val;
358
359 deref_val = coerce_ref_if_computed (original_value);
360 if (deref_val != NULL)
361 {
362 /* More complicated computed references are not supported. */
363 gdb_assert (embedded_offset == 0);
364 }
365 else
366 deref_val = value_at (TYPE_TARGET_TYPE (type),
367 unpack_pointer (type,
368 (valaddr
369 + embedded_offset)));
c5504eaf 370
79a45b7d
TT
371 common_val_print (deref_val, stream, recurse, options,
372 current_language);
c906108c
SS
373 }
374 else
375 fputs_filtered ("???", stream);
376 }
377 break;
378
379 case TYPE_CODE_UNION:
79a45b7d 380 if (recurse && !options->unionprint)
c906108c
SS
381 {
382 fprintf_filtered (stream, "{...}");
383 break;
384 }
385 /* Fall through. */
386 case TYPE_CODE_STRUCT:
0963b4bd 387 /*FIXME: Abstract this away. */
79a45b7d 388 if (options->vtblprint && cp_is_vtbl_ptr_type (type))
c906108c 389 {
c5aa993b 390 /* Print the unmangled name if desired. */
c906108c 391 /* Print vtable entry - we only get here if NOT using
aff410f1
MS
392 -fvtable_thunks. (Otherwise, look under
393 TYPE_CODE_PTR.) */
394 int offset = (embedded_offset
395 + TYPE_FIELD_BITPOS (type,
396 VTBL_FNADDR_OFFSET) / 8);
397 struct type *field_type = TYPE_FIELD_TYPE (type,
398 VTBL_FNADDR_OFFSET);
4478b372
JB
399 CORE_ADDR addr
400 = extract_typed_address (valaddr + offset, field_type);
401
50810684
UW
402 print_function_pointer_address (gdbarch, addr, stream,
403 options->addressprint);
c906108c
SS
404 }
405 else
edf3d5f3 406 cp_print_value_fields_rtti (type, valaddr,
aff410f1
MS
407 embedded_offset, address,
408 stream, recurse,
409 original_value, options,
410 NULL, 0);
c906108c
SS
411 break;
412
413 case TYPE_CODE_ENUM:
79a45b7d 414 if (options->format)
c906108c 415 {
ab2188aa
PA
416 val_print_scalar_formatted (type, valaddr, embedded_offset,
417 original_value, options, 0, stream);
c906108c
SS
418 break;
419 }
420 len = TYPE_NFIELDS (type);
421 val = unpack_long (type, valaddr + embedded_offset);
422 for (i = 0; i < len; i++)
423 {
424 QUIT;
425 if (val == TYPE_FIELD_BITPOS (type, i))
426 {
427 break;
428 }
429 }
430 if (i < len)
431 {
432 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
433 }
cafec441 434 else if (TYPE_FLAG_ENUM (type))
c906108c 435 {
cafec441
TT
436 int first = 1;
437
438 /* We have a "flag" enum, so we try to decompose it into
439 pieces as appropriate. A flag enum has disjoint
440 constants by definition. */
441 fputs_filtered ("(", stream);
442 for (i = 0; i < len; ++i)
443 {
444 QUIT;
445
446 if ((val & TYPE_FIELD_BITPOS (type, i)) != 0)
447 {
448 if (!first)
449 fputs_filtered (" | ", stream);
450 first = 0;
451
452 val &= ~TYPE_FIELD_BITPOS (type, i);
453 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
454 }
455 }
456
457 if (first || val != 0)
458 {
459 if (!first)
460 fputs_filtered (" | ", stream);
461 fputs_filtered ("unknown: ", stream);
462 print_longest (stream, 'd', 0, val);
463 }
464
465 fputs_filtered (")", stream);
c906108c 466 }
cafec441
TT
467 else
468 print_longest (stream, 'd', 0, val);
c906108c
SS
469 break;
470
4f2aea11 471 case TYPE_CODE_FLAGS:
79a45b7d 472 if (options->format)
ab2188aa
PA
473 val_print_scalar_formatted (type, valaddr, embedded_offset,
474 original_value, options, 0, stream);
4f2aea11 475 else
aff410f1
MS
476 val_print_type_code_flags (type, valaddr + embedded_offset,
477 stream);
4f2aea11
MK
478 break;
479
c906108c 480 case TYPE_CODE_FUNC:
0d5de010 481 case TYPE_CODE_METHOD:
79a45b7d 482 if (options->format)
c906108c 483 {
ab2188aa
PA
484 val_print_scalar_formatted (type, valaddr, embedded_offset,
485 original_value, options, 0, stream);
c906108c
SS
486 break;
487 }
aff410f1
MS
488 /* FIXME, we should consider, at least for ANSI C language,
489 eliminating the distinction made between FUNCs and POINTERs
490 to FUNCs. */
c906108c
SS
491 fprintf_filtered (stream, "{");
492 type_print (type, "", stream, -1);
493 fprintf_filtered (stream, "} ");
494 /* Try to print what function it points to, and its address. */
5af949e3 495 print_address_demangle (gdbarch, address, stream, demangle);
c906108c
SS
496 break;
497
498 case TYPE_CODE_BOOL:
79a45b7d
TT
499 if (options->format || options->output_format)
500 {
501 struct value_print_options opts = *options;
502 opts.format = (options->format ? options->format
503 : options->output_format);
ab2188aa
PA
504 val_print_scalar_formatted (type, valaddr, embedded_offset,
505 original_value, &opts, 0, stream);
79a45b7d 506 }
c906108c
SS
507 else
508 {
509 val = unpack_long (type, valaddr + embedded_offset);
510 if (val == 0)
511 fputs_filtered ("false", stream);
512 else if (val == 1)
513 fputs_filtered ("true", stream);
514 else
515 print_longest (stream, 'd', 0, val);
516 }
517 break;
518
519 case TYPE_CODE_RANGE:
520 /* FIXME: create_range_type does not set the unsigned bit in a
aff410f1
MS
521 range type (I think it probably should copy it from the
522 target type), so we won't print values which are too large to
c5aa993b 523 fit in a signed integer correctly. */
c906108c 524 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
aff410f1
MS
525 print with the target type, though, because the size of our
526 type and the target type might differ). */
c906108c
SS
527 /* FALLTHROUGH */
528
529 case TYPE_CODE_INT:
79a45b7d 530 if (options->format || options->output_format)
c906108c 531 {
79a45b7d 532 struct value_print_options opts = *options;
c5504eaf 533
79a45b7d
TT
534 opts.format = (options->format ? options->format
535 : options->output_format);
ab2188aa
PA
536 val_print_scalar_formatted (type, valaddr, embedded_offset,
537 original_value, &opts, 0, stream);
c906108c
SS
538 }
539 else
540 {
aff410f1
MS
541 val_print_type_code_int (type, valaddr + embedded_offset,
542 stream);
543 /* C and C++ has no single byte int type, char is used
544 instead. Since we don't know whether the value is really
545 intended to be used as an integer or a character, print
546 the character equivalent as well. */
96c07c5b 547 if (c_textual_element_type (unresolved_type, options->format))
c906108c
SS
548 {
549 fputs_filtered (" ", stream);
447b483c 550 LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset),
6c7a06a3 551 unresolved_type, stream);
c906108c
SS
552 }
553 }
554 break;
555
556 case TYPE_CODE_CHAR:
79a45b7d 557 if (options->format || options->output_format)
c906108c 558 {
79a45b7d
TT
559 struct value_print_options opts = *options;
560 opts.format = (options->format ? options->format
561 : options->output_format);
ab2188aa
PA
562 val_print_scalar_formatted (type, valaddr, embedded_offset,
563 original_value, &opts, 0, stream);
c906108c
SS
564 }
565 else
566 {
96baa820
JM
567 val = unpack_long (type, valaddr + embedded_offset);
568 if (TYPE_UNSIGNED (type))
569 fprintf_filtered (stream, "%u", (unsigned int) val);
570 else
571 fprintf_filtered (stream, "%d", (int) val);
c906108c 572 fputs_filtered (" ", stream);
447b483c 573 LA_PRINT_CHAR (val, unresolved_type, stream);
c906108c
SS
574 }
575 break;
576
577 case TYPE_CODE_FLT:
79a45b7d 578 if (options->format)
c906108c 579 {
ab2188aa
PA
580 val_print_scalar_formatted (type, valaddr, embedded_offset,
581 original_value, options, 0, stream);
c906108c
SS
582 }
583 else
584 {
585 print_floating (valaddr + embedded_offset, type, stream);
586 }
587 break;
588
7678ef8f 589 case TYPE_CODE_DECFLOAT:
79a45b7d 590 if (options->format)
ab2188aa
PA
591 val_print_scalar_formatted (type, valaddr, embedded_offset,
592 original_value, options, 0, stream);
7678ef8f 593 else
aff410f1
MS
594 print_decimal_floating (valaddr + embedded_offset,
595 type, stream);
7678ef8f
TJB
596 break;
597
c906108c
SS
598 case TYPE_CODE_VOID:
599 fprintf_filtered (stream, "void");
600 break;
601
602 case TYPE_CODE_ERROR:
b00fdb78 603 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
c906108c
SS
604 break;
605
606 case TYPE_CODE_UNDEF:
aff410f1
MS
607 /* This happens (without TYPE_FLAG_STUB set) on systems which
608 don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a
609 "struct foo *bar" and no complete type for struct foo in that
610 file. */
3d263c1d 611 fprintf_filtered (stream, _("<incomplete type>"));
c906108c
SS
612 break;
613
fca9e603 614 case TYPE_CODE_COMPLEX:
79a45b7d 615 if (options->format)
ab2188aa
PA
616 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
617 valaddr, embedded_offset,
618 original_value, options, 0, stream);
fca9e603 619 else
aff410f1
MS
620 print_floating (valaddr + embedded_offset,
621 TYPE_TARGET_TYPE (type),
fca9e603
DJ
622 stream);
623 fprintf_filtered (stream, " + ");
79a45b7d 624 if (options->format)
ab2188aa
PA
625 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
626 valaddr,
627 embedded_offset
628 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
629 original_value,
630 options, 0, stream);
fca9e603
DJ
631 else
632 print_floating (valaddr + embedded_offset
633 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
634 TYPE_TARGET_TYPE (type),
635 stream);
636 fprintf_filtered (stream, " * I");
637 break;
638
c906108c 639 default:
aff410f1
MS
640 error (_("Invalid C/C++ type code %d in symbol table."),
641 TYPE_CODE (type));
c906108c
SS
642 }
643 gdb_flush (stream);
644 return (0);
645}
646\f
8e069a98 647void
79a45b7d
TT
648c_value_print (struct value *val, struct ui_file *stream,
649 const struct value_print_options *options)
c906108c 650{
6c7a06a3 651 struct type *type, *real_type, *val_type;
c906108c 652 int full, top, using_enc;
79a45b7d
TT
653 struct value_print_options opts = *options;
654
655 opts.deref_ref = 1;
c5aa993b 656
c906108c
SS
657 /* If it is a pointer, indicate what it points to.
658
659 Print type also if it is a reference.
660
661 C++: if it is a member pointer, we will take care
662 of that when we print it. */
88750304 663
6c7a06a3
TT
664 /* Preserve the original type before stripping typedefs. We prefer
665 to pass down the original type when possible, but for local
666 checks it is better to look past the typedefs. */
667 val_type = value_type (val);
668 type = check_typedef (val_type);
88750304
DJ
669
670 if (TYPE_CODE (type) == TYPE_CODE_PTR
671 || TYPE_CODE (type) == TYPE_CODE_REF)
c906108c
SS
672 {
673 /* Hack: remove (char *) for char strings. Their
ea37ba09 674 type is indicated by the quoted string anyway.
96c07c5b 675 (Don't use c_textual_element_type here; quoted strings
6c7a06a3
TT
676 are always exactly (char *), (wchar_t *), or the like. */
677 if (TYPE_CODE (val_type) == TYPE_CODE_PTR
678 && TYPE_NAME (val_type) == NULL
679 && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
aff410f1
MS
680 && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
681 "char") == 0
6c7a06a3 682 || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
c906108c 683 {
aff410f1 684 /* Print nothing. */
c906108c 685 }
79a45b7d
TT
686 else if (options->objectprint
687 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
c5aa993b 688 {
070ad9f0
DB
689
690 if (TYPE_CODE(type) == TYPE_CODE_REF)
691 {
692 /* Copy value, change to pointer, so we don't get an
aff410f1
MS
693 error about a non-pointer type in
694 value_rtti_target_type. */
6943961c 695 struct value *temparg;
070ad9f0 696 temparg=value_copy(val);
aff410f1
MS
697 deprecated_set_value_type
698 (temparg, lookup_pointer_type (TYPE_TARGET_TYPE (type)));
699 val = temparg;
070ad9f0 700 }
aff410f1 701 /* Pointer to class, check real type of object. */
c906108c 702 fprintf_filtered (stream, "(");
ec0a52e1
PA
703
704 if (value_entirely_available (val))
705 {
dfcee124
AG
706 real_type = value_rtti_indirect_type (val, &full, &top,
707 &using_enc);
ec0a52e1
PA
708 if (real_type)
709 {
710 /* RTTI entry found. */
dfcee124
AG
711 type = real_type;
712
ec0a52e1
PA
713 /* Need to adjust pointer value. */
714 val = value_from_pointer (type, value_as_address (val) - top);
715
716 /* Note: When we look up RTTI entries, we don't get
717 any information on const or volatile
718 attributes. */
719 }
720 }
c4093a6a 721 type_print (type, "", stream, -1);
c906108c 722 fprintf_filtered (stream, ") ");
6c7a06a3 723 val_type = type;
c5aa993b 724 }
c906108c
SS
725 else
726 {
c5aa993b 727 /* normal case */
c906108c 728 fprintf_filtered (stream, "(");
88750304 729 type_print (value_type (val), "", stream, -1);
c906108c
SS
730 fprintf_filtered (stream, ") ");
731 }
732 }
88750304 733
42be36b3
CT
734 if (!value_initialized (val))
735 fprintf_filtered (stream, " [uninitialized] ");
736
79a45b7d 737 if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
c906108c 738 {
aff410f1 739 /* Attempt to determine real type of object. */
c906108c 740 real_type = value_rtti_type (val, &full, &top, &using_enc);
c5aa993b
JM
741 if (real_type)
742 {
aff410f1
MS
743 /* We have RTTI information, so use it. */
744 val = value_full_object (val, real_type,
745 full, top, using_enc);
c5aa993b
JM
746 fprintf_filtered (stream, "(%s%s) ",
747 TYPE_NAME (real_type),
3d263c1d 748 full ? "" : _(" [incomplete object]"));
aff410f1
MS
749 /* Print out object: enclosing type is same as real_type if
750 full. */
8e069a98
TT
751 val_print (value_enclosing_type (val),
752 value_contents_for_printing (val), 0,
753 value_address (val), stream, 0,
754 val, &opts, current_language);
755 return;
aff410f1
MS
756 /* Note: When we look up RTTI entries, we don't get any
757 information on const or volatile attributes. */
c5aa993b 758 }
88750304 759 else if (type != check_typedef (value_enclosing_type (val)))
c5aa993b 760 {
aff410f1 761 /* No RTTI information, so let's do our best. */
c5aa993b 762 fprintf_filtered (stream, "(%s ?) ",
4754a64e 763 TYPE_NAME (value_enclosing_type (val)));
8e069a98
TT
764 val_print (value_enclosing_type (val),
765 value_contents_for_printing (val), 0,
766 value_address (val), stream, 0,
767 val, &opts, current_language);
768 return;
c5aa993b 769 }
aff410f1 770 /* Otherwise, we end up at the return outside this "if". */
c906108c 771 }
c5aa993b 772
8e069a98
TT
773 val_print (val_type, value_contents_for_printing (val),
774 value_embedded_offset (val),
775 value_address (val),
776 stream, 0,
777 val, &opts, current_language);
c906108c 778}
This page took 0.81673 seconds and 4 git commands to generate.