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