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