1 1.1 christos /* Support for printing C values for GDB, the GNU debugger. 2 1.1 christos 3 1.11 christos Copyright (C) 1986-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.11 christos #include "extract-store-integer.h" 21 1.1 christos #include "symtab.h" 22 1.1 christos #include "gdbtypes.h" 23 1.1 christos #include "expression.h" 24 1.1 christos #include "value.h" 25 1.1 christos #include "valprint.h" 26 1.1 christos #include "language.h" 27 1.1 christos #include "c-lang.h" 28 1.1 christos #include "cp-abi.h" 29 1.1 christos #include "target.h" 30 1.3 christos #include "objfiles.h" 31 1.1 christos 32 1.1 christos 34 1.1 christos /* A helper for c_textual_element_type. This checks the name of the 35 1.1 christos typedef. This is bogus but it isn't apparent that the compiler 36 1.1 christos provides us the help we may need. */ 37 1.1 christos 38 1.1 christos static int 39 1.1 christos textual_name (const char *name) 40 1.1 christos { 41 1.1 christos return (!strcmp (name, "wchar_t") 42 1.1 christos || !strcmp (name, "char16_t") 43 1.1 christos || !strcmp (name, "char32_t")); 44 1.1 christos } 45 1.1 christos 46 1.1 christos /* Apply a heuristic to decide whether an array of TYPE or a pointer 47 1.1 christos to TYPE should be printed as a textual string. Return non-zero if 48 1.1 christos it should, or zero if it should be treated as an array of integers 49 1.1 christos or pointer to integers. FORMAT is the current format letter, or 0 50 1.1 christos if none. 51 1.1 christos 52 1.1 christos We guess that "char" is a character. Explicitly signed and 53 1.1 christos unsigned character types are also characters. Integer data from 54 1.1 christos vector types is not. The user can override this by using the /s 55 1.1 christos format letter. */ 56 1.1 christos 57 1.1 christos int 58 1.1 christos c_textual_element_type (struct type *type, char format) 59 1.1 christos { 60 1.1 christos struct type *true_type, *iter_type; 61 1.1 christos 62 1.1 christos if (format != 0 && format != 's') 63 1.1 christos return 0; 64 1.1 christos 65 1.1 christos /* We also rely on this for its side effect of setting up all the 66 1.1 christos typedef pointers. */ 67 1.1 christos true_type = check_typedef (type); 68 1.1 christos 69 1.9 christos /* TYPE_CODE_CHAR is always textual. */ 70 1.1 christos if (true_type->code () == TYPE_CODE_CHAR) 71 1.1 christos return 1; 72 1.1 christos 73 1.9 christos /* Any other character-like types must be integral. */ 74 1.1 christos if (true_type->code () != TYPE_CODE_INT) 75 1.1 christos return 0; 76 1.1 christos 77 1.1 christos /* We peel typedefs one by one, looking for a match. */ 78 1.1 christos iter_type = type; 79 1.1 christos while (iter_type) 80 1.1 christos { 81 1.9 christos /* Check the name of the type. */ 82 1.1 christos if (iter_type->name () && textual_name (iter_type->name ())) 83 1.1 christos return 1; 84 1.9 christos 85 1.1 christos if (iter_type->code () != TYPE_CODE_TYPEDEF) 86 1.1 christos break; 87 1.1 christos 88 1.1 christos /* Peel a single typedef. If the typedef doesn't have a target 89 1.1 christos type, we use check_typedef and hope the result is ok -- it 90 1.10 christos might be for C++, where wchar_t is a built-in type. */ 91 1.10 christos if (iter_type->target_type ()) 92 1.1 christos iter_type = iter_type->target_type (); 93 1.1 christos else 94 1.1 christos iter_type = check_typedef (iter_type); 95 1.1 christos } 96 1.1 christos 97 1.1 christos if (format == 's') 98 1.1 christos { 99 1.1 christos /* Print this as a string if we can manage it. For now, no wide 100 1.9 christos character support. */ 101 1.10 christos if (true_type->code () == TYPE_CODE_INT 102 1.1 christos && true_type->length () == 1) 103 1.1 christos return 1; 104 1.1 christos } 105 1.1 christos else 106 1.1 christos { 107 1.1 christos /* If a one-byte TYPE_CODE_INT is missing the not-a-character 108 1.1 christos flag, then we treat it as text; otherwise, we assume it's 109 1.9 christos being used as data. */ 110 1.10 christos if (true_type->code () == TYPE_CODE_INT 111 1.1 christos && true_type->length () == 1 112 1.1 christos && !TYPE_NOTTEXT (true_type)) 113 1.1 christos return 1; 114 1.1 christos } 115 1.1 christos 116 1.1 christos return 0; 117 1.1 christos } 118 1.1 christos 119 1.1 christos /* Decorations for C. */ 120 1.1 christos 121 1.1 christos static const struct generic_val_print_decorations c_decorations = 122 1.1 christos { 123 1.1 christos "", 124 1.9 christos " + ", 125 1.1 christos "i", 126 1.1 christos "true", 127 1.6 christos "false", 128 1.6 christos "void", 129 1.6 christos "{", 130 1.1 christos "}" 131 1.1 christos }; 132 1.6 christos 133 1.1 christos /* Print a pointer based on the type of its target. 134 1.6 christos 135 1.6 christos Arguments to this functions are roughly the same as those in c_val_print. 136 1.6 christos A difference is that ADDRESS is the address to print, with embedded_offset 137 1.6 christos already added. UNRESOLVED_ELTTYPE and ELTTYPE represent the pointed type, 138 1.6 christos respectively before and after check_typedef. */ 139 1.6 christos 140 1.6 christos static void 141 1.6 christos print_unpacked_pointer (struct type *type, struct type *elttype, 142 1.6 christos struct type *unresolved_elttype, 143 1.6 christos const gdb_byte *valaddr, int embedded_offset, 144 1.6 christos CORE_ADDR address, struct ui_file *stream, int recurse, 145 1.1 christos const struct value_print_options *options) 146 1.6 christos { 147 1.10 christos int want_space = 0; 148 1.1 christos struct gdbarch *gdbarch = type->arch (); 149 1.9 christos 150 1.6 christos if (elttype->code () == TYPE_CODE_FUNC) 151 1.6 christos { 152 1.6 christos /* Try to print what function it points to. */ 153 1.6 christos print_function_pointer_address (options, gdbarch, address, stream); 154 1.6 christos return; 155 1.6 christos } 156 1.6 christos 157 1.6 christos if (options->symbol_print) 158 1.6 christos want_space = print_address_demangle (options, gdbarch, address, stream, 159 1.6 christos demangle); 160 1.6 christos else if (options->addressprint) 161 1.10 christos { 162 1.6 christos gdb_puts (paddress (gdbarch, address), stream); 163 1.6 christos want_space = 1; 164 1.6 christos } 165 1.6 christos 166 1.6 christos /* For a pointer to a textual type, also print the string 167 1.6 christos pointed to, unless pointer is null. */ 168 1.6 christos 169 1.6 christos if (c_textual_element_type (unresolved_elttype, options->format) 170 1.6 christos && address != 0) 171 1.6 christos { 172 1.10 christos if (want_space) 173 1.6 christos gdb_puts (" ", stream); 174 1.6 christos val_print_string (unresolved_elttype, NULL, address, -1, stream, options); 175 1.6 christos } 176 1.1 christos else if (cp_is_vtbl_member (type)) 177 1.6 christos { 178 1.6 christos /* Print vtbl's nicely. */ 179 1.12 christos CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); 180 1.6 christos bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (vt_address); 181 1.6 christos 182 1.6 christos /* If 'symbol_print' is set, we did the work above. */ 183 1.6 christos if (!options->symbol_print 184 1.10 christos && (msymbol.minsym != NULL) 185 1.6 christos && (vt_address == msymbol.value_address ())) 186 1.6 christos { 187 1.10 christos if (want_space) 188 1.10 christos gdb_puts (" ", stream); 189 1.10 christos gdb_puts (" <", stream); 190 1.10 christos gdb_puts (msymbol.minsym->print_name (), stream); 191 1.6 christos gdb_puts (">", stream); 192 1.6 christos want_space = 1; 193 1.6 christos } 194 1.6 christos 195 1.6 christos if (vt_address && options->vtblprint) 196 1.6 christos { 197 1.6 christos struct value *vt_val; 198 1.6 christos struct symbol *wsym = NULL; 199 1.6 christos struct type *wtype; 200 1.6 christos 201 1.10 christos if (want_space) 202 1.6 christos gdb_puts (" ", stream); 203 1.6 christos 204 1.8 christos if (msymbol.minsym != NULL) 205 1.9 christos { 206 1.9 christos const char *search_name = msymbol.minsym->search_name (); 207 1.11 christos wsym = lookup_symbol_search_name (search_name, NULL, 208 1.8 christos SEARCH_VAR_DOMAIN).symbol; 209 1.6 christos } 210 1.6 christos 211 1.6 christos if (wsym) 212 1.10 christos { 213 1.6 christos wtype = wsym->type (); 214 1.6 christos } 215 1.6 christos else 216 1.6 christos { 217 1.6 christos wtype = unresolved_elttype; 218 1.6 christos } 219 1.6 christos vt_val = value_at (wtype, vt_address); 220 1.6 christos common_val_print (vt_val, stream, recurse + 1, options, 221 1.6 christos current_language); 222 1.1 christos if (options->prettyformat) 223 1.10 christos { 224 1.10 christos gdb_printf (stream, "\n"); 225 1.1 christos print_spaces (2 + 2 * recurse, stream); 226 1.6 christos } 227 1.6 christos } 228 1.6 christos } 229 1.6 christos } 230 1.9 christos 231 1.6 christos /* c_value_print helper for TYPE_CODE_ARRAY. */ 232 1.6 christos 233 1.9 christos static void 234 1.9 christos c_value_print_array (struct value *val, 235 1.9 christos struct ui_file *stream, int recurse, 236 1.9 christos const struct value_print_options *options) 237 1.11 christos { 238 1.11 christos struct type *type = check_typedef (val->type ()); 239 1.11 christos CORE_ADDR address = val->address (); 240 1.10 christos const gdb_byte *valaddr = val->contents_for_printing ().data (); 241 1.6 christos struct type *unresolved_elttype = type->target_type (); 242 1.1 christos struct type *elttype = check_typedef (unresolved_elttype); 243 1.10 christos 244 1.6 christos if (type->length () > 0 && unresolved_elttype->length () > 0) 245 1.6 christos { 246 1.6 christos LONGEST low_bound, high_bound; 247 1.9 christos int eltlen, len; 248 1.6 christos enum bfd_endian byte_order = type_byte_order (type); 249 1.6 christos 250 1.6 christos if (!get_array_bounds (type, &low_bound, &high_bound)) 251 1.6 christos error (_("Could not determine the array high bound")); 252 1.10 christos 253 1.6 christos eltlen = elttype->length (); 254 1.6 christos len = high_bound - low_bound + 1; 255 1.6 christos 256 1.6 christos /* Print arrays of textual chars with a string syntax, as 257 1.6 christos long as the entire array is valid. */ 258 1.6 christos if (c_textual_element_type (unresolved_elttype, 259 1.11 christos options->format) 260 1.11 christos && val->bytes_available (0, type->length ()) 261 1.11 christos && !val->bits_any_optimized_out (0, 262 1.6 christos TARGET_CHAR_BIT * type->length ())) 263 1.6 christos { 264 1.6 christos int force_ellipses = 0; 265 1.6 christos 266 1.6 christos /* If requested, look for the first null char and only 267 1.6 christos print elements up to it. */ 268 1.1 christos if (options->stop_print_at_null) 269 1.11 christos { 270 1.6 christos unsigned int print_max_chars = get_print_max_chars (options); 271 1.1 christos unsigned int temp_len; 272 1.6 christos 273 1.6 christos for (temp_len = 0; 274 1.11 christos (temp_len < len 275 1.9 christos && temp_len < print_max_chars 276 1.6 christos && extract_unsigned_integer (valaddr + temp_len * eltlen, 277 1.6 christos eltlen, byte_order) != 0); 278 1.6 christos ++temp_len) 279 1.6 christos ; 280 1.10 christos 281 1.6 christos /* Force printstr to print ellipses if 282 1.6 christos we've printed the maximum characters and 283 1.11 christos the next character is not \000. */ 284 1.1 christos if (temp_len == print_max_chars && temp_len < len) 285 1.9 christos { 286 1.9 christos ULONGEST ival 287 1.6 christos = extract_unsigned_integer (valaddr + temp_len * eltlen, 288 1.9 christos eltlen, byte_order); 289 1.6 christos if (ival != 0) 290 1.6 christos force_ellipses = 1; 291 1.1 christos } 292 1.6 christos 293 1.6 christos len = temp_len; 294 1.1 christos } 295 1.10 christos 296 1.10 christos current_language->printstr (stream, unresolved_elttype, valaddr, len, 297 1.6 christos NULL, force_ellipses, options); 298 1.6 christos } 299 1.6 christos else 300 1.9 christos { 301 1.10 christos unsigned int i = 0; 302 1.6 christos gdb_printf (stream, "{"); 303 1.6 christos /* If this is a virtual function table, print the 0th 304 1.6 christos entry specially, and the rest of the members 305 1.6 christos normally. */ 306 1.6 christos if (cp_is_vtbl_ptr_type (elttype)) 307 1.6 christos { 308 1.10 christos i = 1; 309 1.10 christos gdb_printf (stream, _("%d vtable entries"), 310 1.1 christos len - 1); 311 1.9 christos } 312 1.10 christos value_print_array_elements (val, stream, recurse, options, i); 313 1.1 christos gdb_printf (stream, "}"); 314 1.6 christos } 315 1.6 christos } 316 1.6 christos else 317 1.6 christos { 318 1.6 christos /* Array of unspecified length: treat like pointer to first elt. */ 319 1.9 christos print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, 320 1.6 christos 0, address, stream, recurse, options); 321 1.6 christos } 322 1.6 christos } 323 1.9 christos 324 1.6 christos /* c_value_print_inner helper for TYPE_CODE_PTR. */ 325 1.6 christos 326 1.9 christos static void 327 1.9 christos c_value_print_ptr (struct value *val, struct ui_file *stream, int recurse, 328 1.6 christos const struct value_print_options *options) 329 1.6 christos { 330 1.6 christos if (options->format && options->format != 's') 331 1.9 christos { 332 1.9 christos value_print_scalar_formatted (val, options, 0, stream); 333 1.6 christos return; 334 1.9 christos } 335 1.11 christos 336 1.11 christos struct type *type = check_typedef (val->type ()); 337 1.9 christos const gdb_byte *valaddr = val->contents_for_printing ().data (); 338 1.9 christos 339 1.6 christos if (options->vtblprint && cp_is_vtbl_ptr_type (type)) 340 1.6 christos { 341 1.6 christos /* Print the unmangled name if desired. */ 342 1.6 christos /* Print vtable entry - we only get here if we ARE using 343 1.6 christos -fvtable_thunks. (Otherwise, look under 344 1.9 christos TYPE_CODE_STRUCT.) */ 345 1.6 christos CORE_ADDR addr = extract_typed_address (valaddr, type); 346 1.10 christos 347 1.6 christos print_function_pointer_address (options, type->arch (), addr, stream); 348 1.6 christos } 349 1.6 christos else 350 1.10 christos { 351 1.6 christos struct type *unresolved_elttype = type->target_type (); 352 1.9 christos struct type *elttype = check_typedef (unresolved_elttype); 353 1.6 christos CORE_ADDR addr = unpack_pointer (type, valaddr); 354 1.6 christos 355 1.9 christos print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, 356 1.6 christos 0, addr, stream, recurse, options); 357 1.6 christos } 358 1.6 christos } 359 1.9 christos 360 1.6 christos /* c_value_print helper for TYPE_CODE_STRUCT and TYPE_CODE_UNION. */ 361 1.6 christos 362 1.9 christos static void 363 1.9 christos c_value_print_struct (struct value *val, struct ui_file *stream, int recurse, 364 1.6 christos const struct value_print_options *options) 365 1.11 christos { 366 1.9 christos struct type *type = check_typedef (val->type ()); 367 1.9 christos 368 1.10 christos if (type->code () == TYPE_CODE_UNION && recurse && !options->unionprint) 369 1.9 christos gdb_printf (stream, "{...}"); 370 1.6 christos else if (options->vtblprint && cp_is_vtbl_ptr_type (type)) 371 1.6 christos { 372 1.6 christos /* Print the unmangled name if desired. */ 373 1.6 christos /* Print vtable entry - we only get here if NOT using 374 1.6 christos -fvtable_thunks. (Otherwise, look under 375 1.10 christos TYPE_CODE_PTR.) */ 376 1.9 christos int offset = type->field (VTBL_FNADDR_OFFSET).loc_bitpos () / 8; 377 1.11 christos struct type *field_type = type->field (VTBL_FNADDR_OFFSET).type (); 378 1.6 christos const gdb_byte *valaddr = val->contents_for_printing ().data (); 379 1.6 christos CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type); 380 1.10 christos 381 1.6 christos print_function_pointer_address (options, type->arch (), addr, stream); 382 1.6 christos } 383 1.9 christos else 384 1.6 christos cp_print_value_fields (val, stream, recurse, options, NULL, 0); 385 1.6 christos } 386 1.9 christos 387 1.6 christos /* c_value_print helper for TYPE_CODE_INT. */ 388 1.6 christos 389 1.9 christos static void 390 1.6 christos c_value_print_int (struct value *val, struct ui_file *stream, 391 1.6 christos const struct value_print_options *options) 392 1.6 christos { 393 1.6 christos if (options->format || options->output_format) 394 1.6 christos { 395 1.1 christos struct value_print_options opts = *options; 396 1.6 christos 397 1.6 christos opts.format = (options->format ? options->format 398 1.9 christos : options->output_format); 399 1.6 christos value_print_scalar_formatted (val, &opts, 0, stream); 400 1.6 christos } 401 1.6 christos else 402 1.9 christos { 403 1.6 christos value_print_scalar_formatted (val, options, 0, stream); 404 1.6 christos /* C and C++ has no single byte int type, char is used 405 1.6 christos instead. Since we don't know whether the value is really 406 1.6 christos intended to be used as an integer or a character, print 407 1.11 christos the character equivalent as well. */ 408 1.11 christos struct type *type = val->type (); 409 1.9 christos const gdb_byte *valaddr = val->contents_for_printing ().data (); 410 1.6 christos if (c_textual_element_type (type, options->format)) 411 1.10 christos { 412 1.10 christos gdb_puts (" ", stream); 413 1.10 christos current_language->printchar (unpack_long (type, valaddr), type, 414 1.1 christos stream); 415 1.6 christos } 416 1.6 christos } 417 1.1 christos } 418 1.9 christos 419 1.1 christos /* See c-lang.h. */ 420 1.6 christos 421 1.9 christos void 422 1.9 christos c_value_print_inner (struct value *val, struct ui_file *stream, int recurse, 423 1.6 christos const struct value_print_options *options) 424 1.11 christos { 425 1.1 christos struct type *type = val->type (); 426 1.6 christos 427 1.9 christos type = check_typedef (type); 428 1.6 christos switch (type->code ()) 429 1.6 christos { 430 1.9 christos case TYPE_CODE_ARRAY: 431 1.6 christos c_value_print_array (val, stream, recurse, options); 432 1.1 christos break; 433 1.6 christos 434 1.9 christos case TYPE_CODE_PTR: 435 1.1 christos c_value_print_ptr (val, stream, recurse, options); 436 1.1 christos break; 437 1.1 christos 438 1.1 christos case TYPE_CODE_UNION: 439 1.9 christos case TYPE_CODE_STRUCT: 440 1.1 christos c_value_print_struct (val, stream, recurse, options); 441 1.1 christos break; 442 1.10 christos 443 1.1 christos case TYPE_CODE_CHAR: 444 1.9 christos case TYPE_CODE_INT: 445 1.1 christos c_value_print_int (val, stream, options); 446 1.1 christos break; 447 1.10 christos 448 1.1 christos case TYPE_CODE_METHODPTR: 449 1.1 christos case TYPE_CODE_MEMBERPTR: 450 1.7 christos case TYPE_CODE_REF: 451 1.1 christos case TYPE_CODE_RVALUE_REF: 452 1.1 christos case TYPE_CODE_ENUM: 453 1.1 christos case TYPE_CODE_FLAGS: 454 1.1 christos case TYPE_CODE_FUNC: 455 1.1 christos case TYPE_CODE_METHOD: 456 1.1 christos case TYPE_CODE_BOOL: 457 1.1 christos case TYPE_CODE_RANGE: 458 1.1 christos case TYPE_CODE_FLT: 459 1.1 christos case TYPE_CODE_DECFLOAT: 460 1.1 christos case TYPE_CODE_VOID: 461 1.1 christos case TYPE_CODE_ERROR: 462 1.1 christos case TYPE_CODE_UNDEF: 463 1.1 christos case TYPE_CODE_COMPLEX: 464 1.9 christos default: 465 1.1 christos generic_value_print (val, stream, recurse, options, &c_decorations); 466 1.1 christos break; 467 1.1 christos } 468 1.9 christos } 469 1.1 christos 470 1.1 christos 471 1.1 christos void 473 1.1 christos c_value_print (struct value *val, struct ui_file *stream, 474 1.9 christos const struct value_print_options *options) 475 1.6 christos { 476 1.6 christos struct type *type, *real_type; 477 1.1 christos int full, using_enc; 478 1.1 christos LONGEST top; 479 1.11 christos struct value_print_options opts = *options; 480 1.1 christos 481 1.1 christos opts.deref_ref = true; 482 1.1 christos 483 1.1 christos /* If it is a pointer, indicate what it points to. 484 1.1 christos 485 1.1 christos Print type also if it is a reference. 486 1.1 christos 487 1.1 christos C++: if it is a member pointer, we will take care 488 1.11 christos of that when we print it. */ 489 1.1 christos 490 1.10 christos type = check_typedef (val->type ()); 491 1.1 christos 492 1.11 christos if (type->is_pointer_or_reference ()) 493 1.9 christos { 494 1.1 christos struct type *original_type = val->type (); 495 1.10 christos 496 1.10 christos /* Hack: remove (char *) for char strings. Their 497 1.10 christos type is indicated by the quoted string anyway. 498 1.9 christos (Don't use c_textual_element_type here; quoted strings 499 1.9 christos are always exactly (char *), (wchar_t *), or the like. */ 500 1.10 christos if (original_type->code () == TYPE_CODE_PTR 501 1.10 christos && original_type->name () == NULL 502 1.1 christos && original_type->target_type ()->name () != NULL 503 1.10 christos && (strcmp (original_type->target_type ()->name (), 504 1.1 christos "char") == 0 505 1.1 christos || textual_name (original_type->target_type ()->name ()))) 506 1.1 christos { 507 1.1 christos /* Print nothing. */ 508 1.10 christos } 509 1.1 christos else if (options->objectprint 510 1.7 christos && (type->target_type ()->code () == TYPE_CODE_STRUCT)) 511 1.7 christos { 512 1.1 christos int is_ref = TYPE_IS_REFERENCE (type); 513 1.1 christos enum type_code refcode = TYPE_CODE_UNDEF; 514 1.7 christos 515 1.7 christos if (is_ref) 516 1.9 christos { 517 1.7 christos val = value_addr (val); 518 1.1 christos refcode = type->code (); 519 1.1 christos } 520 1.10 christos 521 1.1 christos /* Pointer to class, check real type of object. */ 522 1.11 christos gdb_printf (stream, "("); 523 1.6 christos 524 1.1 christos if (val->entirely_available ()) 525 1.1 christos { 526 1.1 christos real_type = value_rtti_indirect_type (val, &full, &top, 527 1.1 christos &using_enc); 528 1.1 christos if (real_type) 529 1.1 christos { 530 1.1 christos /* RTTI entry found. */ 531 1.1 christos 532 1.1 christos /* Need to adjust pointer value. */ 533 1.1 christos val = value_from_pointer (real_type, 534 1.1 christos value_as_address (val) - top); 535 1.1 christos 536 1.1 christos /* Note: When we look up RTTI entries, we don't get 537 1.1 christos any information on const or volatile 538 1.1 christos attributes. */ 539 1.6 christos } 540 1.6 christos } 541 1.9 christos 542 1.6 christos if (is_ref) 543 1.11 christos val = value_ref (value_ind (val), refcode); 544 1.6 christos 545 1.10 christos type = val->type (); 546 1.1 christos type_print (type, "", stream, -1); 547 1.1 christos gdb_printf (stream, ") "); 548 1.1 christos } 549 1.1 christos else 550 1.10 christos { 551 1.11 christos /* normal case */ 552 1.10 christos gdb_printf (stream, "("); 553 1.1 christos type_print (val->type (), "", stream, -1); 554 1.1 christos gdb_printf (stream, ") "); 555 1.1 christos } 556 1.11 christos } 557 1.10 christos 558 1.1 christos if (!val->initialized ()) 559 1.9 christos gdb_printf (stream, " [uninitialized] "); 560 1.1 christos 561 1.1 christos if (options->objectprint && (type->code () == TYPE_CODE_STRUCT)) 562 1.1 christos { 563 1.1 christos /* Attempt to determine real type of object. */ 564 1.1 christos real_type = value_rtti_type (val, &full, &top, &using_enc); 565 1.1 christos if (real_type) 566 1.1 christos { 567 1.1 christos /* We have RTTI information, so use it. */ 568 1.9 christos val = value_full_object (val, real_type, 569 1.9 christos full, top, using_enc); 570 1.9 christos /* In a destructor we might see a real type that is a 571 1.9 christos superclass of the object's type. In this case it is 572 1.10 christos better to leave the object as-is. */ 573 1.11 christos if (!(full 574 1.9 christos && (real_type->length () 575 1.10 christos < val->enclosing_type ()->length ()))) 576 1.10 christos val = value_cast (real_type, val); 577 1.10 christos gdb_printf (stream, "(%s%s) ", 578 1.1 christos real_type->name (), 579 1.11 christos full ? "" : _(" [incomplete object]")); 580 1.1 christos } 581 1.1 christos else if (type != check_typedef (val->enclosing_type ())) 582 1.10 christos { 583 1.11 christos /* No RTTI information, so let's do our best. */ 584 1.11 christos gdb_printf (stream, "(%s ?) ", 585 1.1 christos val->enclosing_type ()->name ()); 586 1.1 christos val = value_cast (val->enclosing_type (), val); 587 1.1 christos } 588 1.9 christos } 589 1.1 christos 590 common_val_print (val, stream, 0, &opts, current_language); 591 } 592