Commit | Line | Data |
---|---|---|
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, |
9b254dd1 | 4 | 1998, 1999, 2000, 2001, 2003, 2005, 2006, 2007, 2008 |
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 | ||
38 | static void | |
39 | print_function_pointer_address (CORE_ADDR address, struct ui_file *stream) | |
40 | { | |
e2d0e7eb AC |
41 | CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch, |
42 | address, | |
43 | ¤t_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); | |
ed49a04f | 50 | fputs_filtered (paddress (address), stream); |
6e778545 PS |
51 | fputs_filtered (": ", stream); |
52 | } | |
53 | print_address_demangle (func_addr, stream, demangle); | |
54 | } | |
55 | ||
56 | ||
ea37ba09 DJ |
57 | /* Apply a heuristic to decide whether an array of TYPE or a pointer |
58 | to TYPE should be printed as a textual string. Return non-zero if | |
59 | it should, or zero if it should be treated as an array of integers | |
60 | or pointer to integers. FORMAT is the current format letter, | |
61 | or 0 if none. | |
62 | ||
63 | We guess that "char" is a character. Explicitly signed and | |
64 | unsigned character types are also characters. Integer data from | |
65 | vector types is not. The user can override this by using the /s | |
66 | format letter. */ | |
67 | ||
68 | static int | |
69 | textual_element_type (struct type *type, char format) | |
70 | { | |
71 | struct type *true_type = check_typedef (type); | |
72 | ||
73 | if (format != 0 && format != 's') | |
74 | return 0; | |
75 | ||
76 | /* TYPE_CODE_CHAR is always textual. */ | |
77 | if (TYPE_CODE (true_type) == TYPE_CODE_CHAR) | |
78 | return 1; | |
79 | ||
80 | if (format == 's') | |
81 | { | |
82 | /* Print this as a string if we can manage it. For now, no | |
83 | wide character support. */ | |
84 | if (TYPE_CODE (true_type) == TYPE_CODE_INT | |
85 | && TYPE_LENGTH (true_type) == 1) | |
86 | return 1; | |
87 | } | |
88 | else | |
89 | { | |
90 | /* If a one-byte TYPE_CODE_INT is missing the not-a-character | |
91 | flag, then we treat it as text; otherwise, we assume it's | |
92 | being used as data. */ | |
93 | if (TYPE_CODE (true_type) == TYPE_CODE_INT | |
94 | && TYPE_LENGTH (true_type) == 1 | |
95 | && !TYPE_NOTTEXT (true_type)) | |
96 | return 1; | |
97 | } | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
102 | ||
c906108c SS |
103 | /* Print data of type TYPE located at VALADDR (within GDB), which came from |
104 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
105 | FORMAT (a letter or 0 for natural format). The data at VALADDR is in | |
106 | target byte order. | |
107 | ||
108 | If the data are a string pointer, returns the number of string characters | |
109 | printed. | |
110 | ||
111 | If DEREF_REF is nonzero, then dereference references, otherwise just print | |
112 | them like pointers. | |
113 | ||
114 | The PRETTY parameter controls prettyprinting. */ | |
115 | ||
116 | int | |
fc1a4b47 | 117 | c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, |
fba45db2 KB |
118 | CORE_ADDR address, struct ui_file *stream, int format, |
119 | int deref_ref, int recurse, enum val_prettyprint pretty) | |
c906108c | 120 | { |
52f0bd74 | 121 | unsigned int i = 0; /* Number of characters printed */ |
c906108c SS |
122 | unsigned len; |
123 | struct type *elttype; | |
124 | unsigned eltlen; | |
125 | LONGEST val; | |
126 | CORE_ADDR addr; | |
127 | ||
128 | CHECK_TYPEDEF (type); | |
129 | switch (TYPE_CODE (type)) | |
130 | { | |
131 | case TYPE_CODE_ARRAY: | |
132 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
133 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
134 | { | |
135 | eltlen = TYPE_LENGTH (elttype); | |
136 | len = TYPE_LENGTH (type) / eltlen; | |
137 | if (prettyprint_arrays) | |
138 | { | |
139 | print_spaces_filtered (2 + 2 * recurse, stream); | |
140 | } | |
ea37ba09 DJ |
141 | |
142 | /* Print arrays of textual chars with a string syntax. */ | |
143 | if (textual_element_type (elttype, format)) | |
c906108c SS |
144 | { |
145 | /* If requested, look for the first null char and only print | |
c5aa993b | 146 | elements up to it. */ |
c906108c SS |
147 | if (stop_print_at_null) |
148 | { | |
745b8ca0 | 149 | unsigned int temp_len; |
c5aa993b | 150 | |
c906108c SS |
151 | /* Look for a NULL char. */ |
152 | for (temp_len = 0; | |
153 | (valaddr + embedded_offset)[temp_len] | |
154 | && temp_len < len && temp_len < print_max; | |
155 | temp_len++); | |
156 | len = temp_len; | |
157 | } | |
c5aa993b | 158 | |
c906108c SS |
159 | LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0); |
160 | i = len; | |
161 | } | |
162 | else | |
163 | { | |
164 | fprintf_filtered (stream, "{"); | |
165 | /* If this is a virtual function table, print the 0th | |
c5aa993b | 166 | entry specially, and the rest of the members normally. */ |
c906108c SS |
167 | if (cp_is_vtbl_ptr_type (elttype)) |
168 | { | |
169 | i = 1; | |
3d263c1d | 170 | fprintf_filtered (stream, _("%d vtable entries"), len - 1); |
c906108c SS |
171 | } |
172 | else | |
173 | { | |
174 | i = 0; | |
175 | } | |
176 | val_print_array_elements (type, valaddr + embedded_offset, address, stream, | |
c5aa993b | 177 | format, deref_ref, recurse, pretty, i); |
c906108c SS |
178 | fprintf_filtered (stream, "}"); |
179 | } | |
180 | break; | |
181 | } | |
182 | /* Array of unspecified length: treat like pointer to first elt. */ | |
183 | addr = address; | |
184 | goto print_unpacked_pointer; | |
185 | ||
0d5de010 DJ |
186 | case TYPE_CODE_MEMBERPTR: |
187 | if (format) | |
188 | { | |
189 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
190 | break; | |
191 | } | |
192 | cp_print_class_member (valaddr + embedded_offset, | |
193 | TYPE_DOMAIN_TYPE (type), | |
194 | stream, "&"); | |
195 | break; | |
196 | ||
197 | case TYPE_CODE_METHODPTR: | |
198 | cplus_print_method_ptr (valaddr + embedded_offset, type, stream); | |
199 | break; | |
200 | ||
c906108c SS |
201 | case TYPE_CODE_PTR: |
202 | if (format && format != 's') | |
203 | { | |
204 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
205 | break; | |
206 | } | |
c5aa993b | 207 | if (vtblprint && cp_is_vtbl_ptr_type (type)) |
c906108c | 208 | { |
c5aa993b | 209 | /* Print the unmangled name if desired. */ |
c906108c SS |
210 | /* Print vtable entry - we only get here if we ARE using |
211 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ | |
4478b372 JB |
212 | CORE_ADDR addr |
213 | = extract_typed_address (valaddr + embedded_offset, type); | |
6e778545 | 214 | print_function_pointer_address (addr, stream); |
c906108c SS |
215 | break; |
216 | } | |
217 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
c906108c SS |
218 | { |
219 | addr = unpack_pointer (type, valaddr + embedded_offset); | |
220 | print_unpacked_pointer: | |
c906108c SS |
221 | |
222 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
223 | { | |
224 | /* Try to print what function it points to. */ | |
6e778545 | 225 | print_function_pointer_address (addr, stream); |
c906108c SS |
226 | /* Return value is irrelevant except for string pointers. */ |
227 | return (0); | |
228 | } | |
229 | ||
ea37ba09 | 230 | if (addressprint) |
ed49a04f | 231 | fputs_filtered (paddress (addr), stream); |
c906108c | 232 | |
ea37ba09 | 233 | /* For a pointer to a textual type, also print the string |
c906108c SS |
234 | pointed to, unless pointer is null. */ |
235 | /* FIXME: need to handle wchar_t here... */ | |
236 | ||
ea37ba09 | 237 | if (textual_element_type (elttype, format) && addr != 0) |
c906108c SS |
238 | { |
239 | i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); | |
240 | } | |
c5aa993b JM |
241 | else if (cp_is_vtbl_member (type)) |
242 | { | |
c906108c SS |
243 | /* print vtbl's nicely */ |
244 | CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); | |
245 | ||
246 | struct minimal_symbol *msymbol = | |
c5aa993b | 247 | lookup_minimal_symbol_by_pc (vt_address); |
c906108c SS |
248 | if ((msymbol != NULL) && |
249 | (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) | |
250 | { | |
251 | fputs_filtered (" <", stream); | |
de5ad195 | 252 | fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); |
c906108c SS |
253 | fputs_filtered (">", stream); |
254 | } | |
255 | if (vt_address && vtblprint) | |
c5aa993b | 256 | { |
6943961c | 257 | struct value *vt_val; |
c5aa993b JM |
258 | struct symbol *wsym = (struct symbol *) NULL; |
259 | struct type *wtype; | |
c5aa993b | 260 | struct block *block = (struct block *) NULL; |
c906108c SS |
261 | int is_this_fld; |
262 | ||
263 | if (msymbol != NULL) | |
22abf04a | 264 | wsym = lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol), block, |
cdef89d0 | 265 | VAR_DOMAIN, &is_this_fld, NULL); |
c5aa993b | 266 | |
c906108c SS |
267 | if (wsym) |
268 | { | |
c5aa993b | 269 | wtype = SYMBOL_TYPE (wsym); |
c906108c SS |
270 | } |
271 | else | |
272 | { | |
c5aa993b | 273 | wtype = TYPE_TARGET_TYPE (type); |
c906108c | 274 | } |
00a4c844 | 275 | vt_val = value_at (wtype, vt_address); |
806048c6 DJ |
276 | common_val_print (vt_val, stream, format, |
277 | deref_ref, recurse + 1, pretty); | |
c906108c SS |
278 | if (pretty) |
279 | { | |
280 | fprintf_filtered (stream, "\n"); | |
281 | print_spaces_filtered (2 + 2 * recurse, stream); | |
282 | } | |
c5aa993b JM |
283 | } |
284 | } | |
c906108c SS |
285 | |
286 | /* Return number of characters printed, including the terminating | |
287 | '\0' if we reached the end. val_print_string takes care including | |
288 | the terminating '\0' if necessary. */ | |
289 | return i; | |
290 | } | |
291 | break; | |
292 | ||
c906108c SS |
293 | case TYPE_CODE_REF: |
294 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
c906108c | 295 | if (addressprint) |
c5aa993b | 296 | { |
4478b372 JB |
297 | CORE_ADDR addr |
298 | = extract_typed_address (valaddr + embedded_offset, type); | |
c906108c | 299 | fprintf_filtered (stream, "@"); |
ed49a04f | 300 | fputs_filtered (paddress (addr), stream); |
c906108c SS |
301 | if (deref_ref) |
302 | fputs_filtered (": ", stream); | |
c5aa993b | 303 | } |
c906108c SS |
304 | /* De-reference the reference. */ |
305 | if (deref_ref) | |
306 | { | |
307 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
308 | { | |
6943961c | 309 | struct value *deref_val = |
c5aa993b JM |
310 | value_at |
311 | (TYPE_TARGET_TYPE (type), | |
312 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
00a4c844 | 313 | valaddr + embedded_offset)); |
806048c6 DJ |
314 | common_val_print (deref_val, stream, format, deref_ref, |
315 | recurse, pretty); | |
c906108c SS |
316 | } |
317 | else | |
318 | fputs_filtered ("???", stream); | |
319 | } | |
320 | break; | |
321 | ||
322 | case TYPE_CODE_UNION: | |
323 | if (recurse && !unionprint) | |
324 | { | |
325 | fprintf_filtered (stream, "{...}"); | |
326 | break; | |
327 | } | |
328 | /* Fall through. */ | |
329 | case TYPE_CODE_STRUCT: | |
015a42b4 | 330 | /*FIXME: Abstract this away */ |
c5aa993b | 331 | if (vtblprint && cp_is_vtbl_ptr_type (type)) |
c906108c | 332 | { |
c5aa993b | 333 | /* Print the unmangled name if desired. */ |
c906108c SS |
334 | /* Print vtable entry - we only get here if NOT using |
335 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ | |
4478b372 JB |
336 | int offset = (embedded_offset + |
337 | TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8); | |
338 | struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET); | |
339 | CORE_ADDR addr | |
340 | = extract_typed_address (valaddr + offset, field_type); | |
341 | ||
6e778545 | 342 | print_function_pointer_address (addr, stream); |
c906108c SS |
343 | } |
344 | else | |
345 | cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format, | |
346 | recurse, pretty, NULL, 0); | |
347 | break; | |
348 | ||
349 | case TYPE_CODE_ENUM: | |
350 | if (format) | |
351 | { | |
352 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
353 | break; | |
354 | } | |
355 | len = TYPE_NFIELDS (type); | |
356 | val = unpack_long (type, valaddr + embedded_offset); | |
357 | for (i = 0; i < len; i++) | |
358 | { | |
359 | QUIT; | |
360 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
361 | { | |
362 | break; | |
363 | } | |
364 | } | |
365 | if (i < len) | |
366 | { | |
367 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
368 | } | |
369 | else | |
370 | { | |
371 | print_longest (stream, 'd', 0, val); | |
372 | } | |
373 | break; | |
374 | ||
4f2aea11 MK |
375 | case TYPE_CODE_FLAGS: |
376 | if (format) | |
377 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
378 | else | |
379 | val_print_type_code_flags (type, valaddr + embedded_offset, stream); | |
380 | break; | |
381 | ||
c906108c | 382 | case TYPE_CODE_FUNC: |
0d5de010 | 383 | case TYPE_CODE_METHOD: |
c906108c SS |
384 | if (format) |
385 | { | |
386 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
387 | break; | |
388 | } | |
389 | /* FIXME, we should consider, at least for ANSI C language, eliminating | |
c5aa993b | 390 | the distinction made between FUNCs and POINTERs to FUNCs. */ |
c906108c SS |
391 | fprintf_filtered (stream, "{"); |
392 | type_print (type, "", stream, -1); | |
393 | fprintf_filtered (stream, "} "); | |
394 | /* Try to print what function it points to, and its address. */ | |
395 | print_address_demangle (address, stream, demangle); | |
396 | break; | |
397 | ||
398 | case TYPE_CODE_BOOL: | |
399 | format = format ? format : output_format; | |
400 | if (format) | |
401 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
402 | else | |
403 | { | |
404 | val = unpack_long (type, valaddr + embedded_offset); | |
405 | if (val == 0) | |
406 | fputs_filtered ("false", stream); | |
407 | else if (val == 1) | |
408 | fputs_filtered ("true", stream); | |
409 | else | |
410 | print_longest (stream, 'd', 0, val); | |
411 | } | |
412 | break; | |
413 | ||
414 | case TYPE_CODE_RANGE: | |
415 | /* FIXME: create_range_type does not set the unsigned bit in a | |
c5aa993b JM |
416 | range type (I think it probably should copy it from the target |
417 | type), so we won't print values which are too large to | |
418 | fit in a signed integer correctly. */ | |
c906108c | 419 | /* FIXME: Doesn't handle ranges of enums correctly. (Can't just |
c5aa993b JM |
420 | print with the target type, though, because the size of our type |
421 | and the target type might differ). */ | |
c906108c SS |
422 | /* FALLTHROUGH */ |
423 | ||
424 | case TYPE_CODE_INT: | |
425 | format = format ? format : output_format; | |
426 | if (format) | |
427 | { | |
428 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
429 | } | |
430 | else | |
431 | { | |
432 | val_print_type_code_int (type, valaddr + embedded_offset, stream); | |
433 | /* C and C++ has no single byte int type, char is used instead. | |
434 | Since we don't know whether the value is really intended to | |
435 | be used as an integer or a character, print the character | |
ea37ba09 DJ |
436 | equivalent as well. */ |
437 | if (textual_element_type (type, format)) | |
c906108c SS |
438 | { |
439 | fputs_filtered (" ", stream); | |
440 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset), | |
441 | stream); | |
442 | } | |
443 | } | |
444 | break; | |
445 | ||
446 | case TYPE_CODE_CHAR: | |
447 | format = format ? format : output_format; | |
448 | if (format) | |
449 | { | |
450 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
451 | } | |
452 | else | |
453 | { | |
96baa820 JM |
454 | val = unpack_long (type, valaddr + embedded_offset); |
455 | if (TYPE_UNSIGNED (type)) | |
456 | fprintf_filtered (stream, "%u", (unsigned int) val); | |
457 | else | |
458 | fprintf_filtered (stream, "%d", (int) val); | |
c906108c | 459 | fputs_filtered (" ", stream); |
96baa820 | 460 | LA_PRINT_CHAR ((unsigned char) val, stream); |
c906108c SS |
461 | } |
462 | break; | |
463 | ||
464 | case TYPE_CODE_FLT: | |
465 | if (format) | |
466 | { | |
467 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
468 | } | |
469 | else | |
470 | { | |
471 | print_floating (valaddr + embedded_offset, type, stream); | |
472 | } | |
473 | break; | |
474 | ||
7678ef8f TJB |
475 | case TYPE_CODE_DECFLOAT: |
476 | if (format) | |
477 | print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); | |
478 | else | |
479 | print_decimal_floating (valaddr + embedded_offset, type, stream); | |
480 | break; | |
481 | ||
c906108c SS |
482 | case TYPE_CODE_VOID: |
483 | fprintf_filtered (stream, "void"); | |
484 | break; | |
485 | ||
486 | case TYPE_CODE_ERROR: | |
3d263c1d | 487 | fprintf_filtered (stream, _("<error type>")); |
c906108c SS |
488 | break; |
489 | ||
490 | case TYPE_CODE_UNDEF: | |
491 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
c5aa993b JM |
492 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" |
493 | and no complete type for struct foo in that file. */ | |
3d263c1d | 494 | fprintf_filtered (stream, _("<incomplete type>")); |
c906108c SS |
495 | break; |
496 | ||
fca9e603 DJ |
497 | case TYPE_CODE_COMPLEX: |
498 | if (format) | |
499 | print_scalar_formatted (valaddr + embedded_offset, | |
500 | TYPE_TARGET_TYPE (type), | |
501 | format, 0, stream); | |
502 | else | |
503 | print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type), | |
504 | stream); | |
505 | fprintf_filtered (stream, " + "); | |
506 | if (format) | |
507 | print_scalar_formatted (valaddr + embedded_offset | |
508 | + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), | |
509 | TYPE_TARGET_TYPE (type), | |
510 | format, 0, stream); | |
511 | else | |
512 | print_floating (valaddr + embedded_offset | |
513 | + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), | |
514 | TYPE_TARGET_TYPE (type), | |
515 | stream); | |
516 | fprintf_filtered (stream, " * I"); | |
517 | break; | |
518 | ||
c906108c | 519 | default: |
3d263c1d | 520 | error (_("Invalid C/C++ type code %d in symbol table."), TYPE_CODE (type)); |
c906108c SS |
521 | } |
522 | gdb_flush (stream); | |
523 | return (0); | |
524 | } | |
525 | \f | |
526 | int | |
6943961c | 527 | c_value_print (struct value *val, struct ui_file *stream, int format, |
fba45db2 | 528 | enum val_prettyprint pretty) |
c906108c | 529 | { |
88750304 | 530 | struct type *type, *real_type; |
c906108c | 531 | int full, top, using_enc; |
c5aa993b | 532 | |
c906108c SS |
533 | /* If it is a pointer, indicate what it points to. |
534 | ||
535 | Print type also if it is a reference. | |
536 | ||
537 | C++: if it is a member pointer, we will take care | |
538 | of that when we print it. */ | |
88750304 DJ |
539 | |
540 | type = check_typedef (value_type (val)); | |
541 | ||
542 | if (TYPE_CODE (type) == TYPE_CODE_PTR | |
543 | || TYPE_CODE (type) == TYPE_CODE_REF) | |
c906108c SS |
544 | { |
545 | /* Hack: remove (char *) for char strings. Their | |
ea37ba09 DJ |
546 | type is indicated by the quoted string anyway. |
547 | (Don't use textual_element_type here; quoted strings | |
548 | are always exactly (char *). */ | |
88750304 DJ |
549 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
550 | && TYPE_NAME (type) == NULL | |
551 | && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL | |
552 | && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) | |
c906108c SS |
553 | { |
554 | /* Print nothing */ | |
555 | } | |
556 | else if (objectprint && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) | |
c5aa993b | 557 | { |
070ad9f0 DB |
558 | |
559 | if (TYPE_CODE(type) == TYPE_CODE_REF) | |
560 | { | |
561 | /* Copy value, change to pointer, so we don't get an | |
562 | * error about a non-pointer type in value_rtti_target_type | |
563 | */ | |
6943961c | 564 | struct value *temparg; |
070ad9f0 | 565 | temparg=value_copy(val); |
04624583 | 566 | deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type))); |
070ad9f0 DB |
567 | val=temparg; |
568 | } | |
c5aa993b | 569 | /* Pointer to class, check real type of object */ |
c906108c | 570 | fprintf_filtered (stream, "("); |
c4093a6a JM |
571 | real_type = value_rtti_target_type (val, &full, &top, &using_enc); |
572 | if (real_type) | |
c5aa993b JM |
573 | { |
574 | /* RTTI entry found */ | |
c4093a6a JM |
575 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
576 | { | |
577 | /* create a pointer type pointing to the real type */ | |
578 | type = lookup_pointer_type (real_type); | |
579 | } | |
580 | else | |
581 | { | |
582 | /* create a reference type referencing the real type */ | |
583 | type = lookup_reference_type (real_type); | |
584 | } | |
070ad9f0 | 585 | /* JYG: Need to adjust pointer value. */ |
5086187c AC |
586 | /* NOTE: cagney/2005-01-02: THIS IS BOGUS. */ |
587 | value_contents_writeable (val)[0] -= top; | |
070ad9f0 | 588 | |
c4093a6a JM |
589 | /* Note: When we look up RTTI entries, we don't get any |
590 | information on const or volatile attributes */ | |
591 | } | |
592 | type_print (type, "", stream, -1); | |
c906108c | 593 | fprintf_filtered (stream, ") "); |
c5aa993b | 594 | } |
c906108c SS |
595 | else |
596 | { | |
c5aa993b | 597 | /* normal case */ |
c906108c | 598 | fprintf_filtered (stream, "("); |
88750304 | 599 | type_print (value_type (val), "", stream, -1); |
c906108c SS |
600 | fprintf_filtered (stream, ") "); |
601 | } | |
602 | } | |
88750304 | 603 | |
42be36b3 CT |
604 | if (!value_initialized (val)) |
605 | fprintf_filtered (stream, " [uninitialized] "); | |
606 | ||
88750304 | 607 | if (objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS)) |
c906108c SS |
608 | { |
609 | /* Attempt to determine real type of object */ | |
610 | real_type = value_rtti_type (val, &full, &top, &using_enc); | |
c5aa993b JM |
611 | if (real_type) |
612 | { | |
613 | /* We have RTTI information, so use it */ | |
614 | val = value_full_object (val, real_type, full, top, using_enc); | |
615 | fprintf_filtered (stream, "(%s%s) ", | |
616 | TYPE_NAME (real_type), | |
3d263c1d | 617 | full ? "" : _(" [incomplete object]")); |
c5aa993b | 618 | /* Print out object: enclosing type is same as real_type if full */ |
46615f07 AC |
619 | return val_print (value_enclosing_type (val), |
620 | value_contents_all (val), 0, | |
621 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty); | |
c4093a6a JM |
622 | /* Note: When we look up RTTI entries, we don't get any information on |
623 | const or volatile attributes */ | |
c5aa993b | 624 | } |
88750304 | 625 | else if (type != check_typedef (value_enclosing_type (val))) |
c5aa993b JM |
626 | { |
627 | /* No RTTI information, so let's do our best */ | |
628 | fprintf_filtered (stream, "(%s ?) ", | |
4754a64e | 629 | TYPE_NAME (value_enclosing_type (val))); |
46615f07 AC |
630 | return val_print (value_enclosing_type (val), |
631 | value_contents_all (val), 0, | |
632 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty); | |
c5aa993b | 633 | } |
c906108c SS |
634 | /* Otherwise, we end up at the return outside this "if" */ |
635 | } | |
c5aa993b | 636 | |
46615f07 | 637 | return val_print (type, value_contents_all (val), |
13c3b5f5 | 638 | value_embedded_offset (val), |
df407dfe | 639 | VALUE_ADDRESS (val) + value_offset (val), |
c906108c SS |
640 | stream, format, 1, 0, pretty); |
641 | } |