| 1 | /* DWARF 2 location expression support for GDB. |
| 2 | |
| 3 | Copyright (C) 2003-2018 Free Software Foundation, Inc. |
| 4 | |
| 5 | Contributed by Daniel Jacobowitz, MontaVista Software, Inc. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 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 |
| 11 | the Free Software Foundation; either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 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. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "ui-out.h" |
| 24 | #include "value.h" |
| 25 | #include "frame.h" |
| 26 | #include "gdbcore.h" |
| 27 | #include "target.h" |
| 28 | #include "inferior.h" |
| 29 | #include "ax.h" |
| 30 | #include "ax-gdb.h" |
| 31 | #include "regcache.h" |
| 32 | #include "objfiles.h" |
| 33 | #include "block.h" |
| 34 | #include "gdbcmd.h" |
| 35 | #include "complaints.h" |
| 36 | #include "dwarf2.h" |
| 37 | #include "dwarf2expr.h" |
| 38 | #include "dwarf2loc.h" |
| 39 | #include "dwarf2-frame.h" |
| 40 | #include "compile/compile.h" |
| 41 | #include "selftest.h" |
| 42 | #include <algorithm> |
| 43 | #include <vector> |
| 44 | #include <unordered_set> |
| 45 | #include "common/underlying.h" |
| 46 | #include "common/byte-vector.h" |
| 47 | |
| 48 | extern int dwarf_always_disassemble; |
| 49 | |
| 50 | static struct value *dwarf2_evaluate_loc_desc_full (struct type *type, |
| 51 | struct frame_info *frame, |
| 52 | const gdb_byte *data, |
| 53 | size_t size, |
| 54 | struct dwarf2_per_cu_data *per_cu, |
| 55 | struct type *subobj_type, |
| 56 | LONGEST subobj_byte_offset); |
| 57 | |
| 58 | static struct call_site_parameter *dwarf_expr_reg_to_entry_parameter |
| 59 | (struct frame_info *frame, |
| 60 | enum call_site_parameter_kind kind, |
| 61 | union call_site_parameter_u kind_u, |
| 62 | struct dwarf2_per_cu_data **per_cu_return); |
| 63 | |
| 64 | static struct value *indirect_synthetic_pointer |
| 65 | (sect_offset die, LONGEST byte_offset, |
| 66 | struct dwarf2_per_cu_data *per_cu, |
| 67 | struct frame_info *frame, |
| 68 | struct type *type, bool resolve_abstract_p = false); |
| 69 | |
| 70 | /* Until these have formal names, we define these here. |
| 71 | ref: http://gcc.gnu.org/wiki/DebugFission |
| 72 | Each entry in .debug_loc.dwo begins with a byte that describes the entry, |
| 73 | and is then followed by data specific to that entry. */ |
| 74 | |
| 75 | enum debug_loc_kind |
| 76 | { |
| 77 | /* Indicates the end of the list of entries. */ |
| 78 | DEBUG_LOC_END_OF_LIST = 0, |
| 79 | |
| 80 | /* This is followed by an unsigned LEB128 number that is an index into |
| 81 | .debug_addr and specifies the base address for all following entries. */ |
| 82 | DEBUG_LOC_BASE_ADDRESS = 1, |
| 83 | |
| 84 | /* This is followed by two unsigned LEB128 numbers that are indices into |
| 85 | .debug_addr and specify the beginning and ending addresses, and then |
| 86 | a normal location expression as in .debug_loc. */ |
| 87 | DEBUG_LOC_START_END = 2, |
| 88 | |
| 89 | /* This is followed by an unsigned LEB128 number that is an index into |
| 90 | .debug_addr and specifies the beginning address, and a 4 byte unsigned |
| 91 | number that specifies the length, and then a normal location expression |
| 92 | as in .debug_loc. */ |
| 93 | DEBUG_LOC_START_LENGTH = 3, |
| 94 | |
| 95 | /* An internal value indicating there is insufficient data. */ |
| 96 | DEBUG_LOC_BUFFER_OVERFLOW = -1, |
| 97 | |
| 98 | /* An internal value indicating an invalid kind of entry was found. */ |
| 99 | DEBUG_LOC_INVALID_ENTRY = -2 |
| 100 | }; |
| 101 | |
| 102 | /* Helper function which throws an error if a synthetic pointer is |
| 103 | invalid. */ |
| 104 | |
| 105 | static void |
| 106 | invalid_synthetic_pointer (void) |
| 107 | { |
| 108 | error (_("access outside bounds of object " |
| 109 | "referenced via synthetic pointer")); |
| 110 | } |
| 111 | |
| 112 | /* Decode the addresses in a non-dwo .debug_loc entry. |
| 113 | A pointer to the next byte to examine is returned in *NEW_PTR. |
| 114 | The encoded low,high addresses are return in *LOW,*HIGH. |
| 115 | The result indicates the kind of entry found. */ |
| 116 | |
| 117 | static enum debug_loc_kind |
| 118 | decode_debug_loc_addresses (const gdb_byte *loc_ptr, const gdb_byte *buf_end, |
| 119 | const gdb_byte **new_ptr, |
| 120 | CORE_ADDR *low, CORE_ADDR *high, |
| 121 | enum bfd_endian byte_order, |
| 122 | unsigned int addr_size, |
| 123 | int signed_addr_p) |
| 124 | { |
| 125 | CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 126 | |
| 127 | if (buf_end - loc_ptr < 2 * addr_size) |
| 128 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 129 | |
| 130 | if (signed_addr_p) |
| 131 | *low = extract_signed_integer (loc_ptr, addr_size, byte_order); |
| 132 | else |
| 133 | *low = extract_unsigned_integer (loc_ptr, addr_size, byte_order); |
| 134 | loc_ptr += addr_size; |
| 135 | |
| 136 | if (signed_addr_p) |
| 137 | *high = extract_signed_integer (loc_ptr, addr_size, byte_order); |
| 138 | else |
| 139 | *high = extract_unsigned_integer (loc_ptr, addr_size, byte_order); |
| 140 | loc_ptr += addr_size; |
| 141 | |
| 142 | *new_ptr = loc_ptr; |
| 143 | |
| 144 | /* A base-address-selection entry. */ |
| 145 | if ((*low & base_mask) == base_mask) |
| 146 | return DEBUG_LOC_BASE_ADDRESS; |
| 147 | |
| 148 | /* An end-of-list entry. */ |
| 149 | if (*low == 0 && *high == 0) |
| 150 | return DEBUG_LOC_END_OF_LIST; |
| 151 | |
| 152 | return DEBUG_LOC_START_END; |
| 153 | } |
| 154 | |
| 155 | /* Decode the addresses in .debug_loclists entry. |
| 156 | A pointer to the next byte to examine is returned in *NEW_PTR. |
| 157 | The encoded low,high addresses are return in *LOW,*HIGH. |
| 158 | The result indicates the kind of entry found. */ |
| 159 | |
| 160 | static enum debug_loc_kind |
| 161 | decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu, |
| 162 | const gdb_byte *loc_ptr, |
| 163 | const gdb_byte *buf_end, |
| 164 | const gdb_byte **new_ptr, |
| 165 | CORE_ADDR *low, CORE_ADDR *high, |
| 166 | enum bfd_endian byte_order, |
| 167 | unsigned int addr_size, |
| 168 | int signed_addr_p) |
| 169 | { |
| 170 | uint64_t u64; |
| 171 | |
| 172 | if (loc_ptr == buf_end) |
| 173 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 174 | |
| 175 | switch (*loc_ptr++) |
| 176 | { |
| 177 | case DW_LLE_end_of_list: |
| 178 | *new_ptr = loc_ptr; |
| 179 | return DEBUG_LOC_END_OF_LIST; |
| 180 | case DW_LLE_base_address: |
| 181 | if (loc_ptr + addr_size > buf_end) |
| 182 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 183 | if (signed_addr_p) |
| 184 | *high = extract_signed_integer (loc_ptr, addr_size, byte_order); |
| 185 | else |
| 186 | *high = extract_unsigned_integer (loc_ptr, addr_size, byte_order); |
| 187 | loc_ptr += addr_size; |
| 188 | *new_ptr = loc_ptr; |
| 189 | return DEBUG_LOC_BASE_ADDRESS; |
| 190 | case DW_LLE_offset_pair: |
| 191 | loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64); |
| 192 | if (loc_ptr == NULL) |
| 193 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 194 | *low = u64; |
| 195 | loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64); |
| 196 | if (loc_ptr == NULL) |
| 197 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 198 | *high = u64; |
| 199 | *new_ptr = loc_ptr; |
| 200 | return DEBUG_LOC_START_END; |
| 201 | default: |
| 202 | return DEBUG_LOC_INVALID_ENTRY; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /* Decode the addresses in .debug_loc.dwo entry. |
| 207 | A pointer to the next byte to examine is returned in *NEW_PTR. |
| 208 | The encoded low,high addresses are return in *LOW,*HIGH. |
| 209 | The result indicates the kind of entry found. */ |
| 210 | |
| 211 | static enum debug_loc_kind |
| 212 | decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu, |
| 213 | const gdb_byte *loc_ptr, |
| 214 | const gdb_byte *buf_end, |
| 215 | const gdb_byte **new_ptr, |
| 216 | CORE_ADDR *low, CORE_ADDR *high, |
| 217 | enum bfd_endian byte_order) |
| 218 | { |
| 219 | uint64_t low_index, high_index; |
| 220 | |
| 221 | if (loc_ptr == buf_end) |
| 222 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 223 | |
| 224 | switch (*loc_ptr++) |
| 225 | { |
| 226 | case DW_LLE_GNU_end_of_list_entry: |
| 227 | *new_ptr = loc_ptr; |
| 228 | return DEBUG_LOC_END_OF_LIST; |
| 229 | case DW_LLE_GNU_base_address_selection_entry: |
| 230 | *low = 0; |
| 231 | loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index); |
| 232 | if (loc_ptr == NULL) |
| 233 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 234 | *high = dwarf2_read_addr_index (per_cu, high_index); |
| 235 | *new_ptr = loc_ptr; |
| 236 | return DEBUG_LOC_BASE_ADDRESS; |
| 237 | case DW_LLE_GNU_start_end_entry: |
| 238 | loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index); |
| 239 | if (loc_ptr == NULL) |
| 240 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 241 | *low = dwarf2_read_addr_index (per_cu, low_index); |
| 242 | loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index); |
| 243 | if (loc_ptr == NULL) |
| 244 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 245 | *high = dwarf2_read_addr_index (per_cu, high_index); |
| 246 | *new_ptr = loc_ptr; |
| 247 | return DEBUG_LOC_START_END; |
| 248 | case DW_LLE_GNU_start_length_entry: |
| 249 | loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index); |
| 250 | if (loc_ptr == NULL) |
| 251 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 252 | *low = dwarf2_read_addr_index (per_cu, low_index); |
| 253 | if (loc_ptr + 4 > buf_end) |
| 254 | return DEBUG_LOC_BUFFER_OVERFLOW; |
| 255 | *high = *low; |
| 256 | *high += extract_unsigned_integer (loc_ptr, 4, byte_order); |
| 257 | *new_ptr = loc_ptr + 4; |
| 258 | return DEBUG_LOC_START_LENGTH; |
| 259 | default: |
| 260 | return DEBUG_LOC_INVALID_ENTRY; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /* A function for dealing with location lists. Given a |
| 265 | symbol baton (BATON) and a pc value (PC), find the appropriate |
| 266 | location expression, set *LOCEXPR_LENGTH, and return a pointer |
| 267 | to the beginning of the expression. Returns NULL on failure. |
| 268 | |
| 269 | For now, only return the first matching location expression; there |
| 270 | can be more than one in the list. */ |
| 271 | |
| 272 | const gdb_byte * |
| 273 | dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, |
| 274 | size_t *locexpr_length, CORE_ADDR pc) |
| 275 | { |
| 276 | struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu); |
| 277 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 278 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 279 | unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu); |
| 280 | int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd); |
| 281 | /* Adjust base_address for relocatable objects. */ |
| 282 | CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu); |
| 283 | CORE_ADDR base_address = baton->base_address + base_offset; |
| 284 | const gdb_byte *loc_ptr, *buf_end; |
| 285 | |
| 286 | loc_ptr = baton->data; |
| 287 | buf_end = baton->data + baton->size; |
| 288 | |
| 289 | while (1) |
| 290 | { |
| 291 | CORE_ADDR low = 0, high = 0; /* init for gcc -Wall */ |
| 292 | int length; |
| 293 | enum debug_loc_kind kind; |
| 294 | const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */ |
| 295 | |
| 296 | if (baton->from_dwo) |
| 297 | kind = decode_debug_loc_dwo_addresses (baton->per_cu, |
| 298 | loc_ptr, buf_end, &new_ptr, |
| 299 | &low, &high, byte_order); |
| 300 | else if (dwarf2_version (baton->per_cu) < 5) |
| 301 | kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr, |
| 302 | &low, &high, |
| 303 | byte_order, addr_size, |
| 304 | signed_addr_p); |
| 305 | else |
| 306 | kind = decode_debug_loclists_addresses (baton->per_cu, |
| 307 | loc_ptr, buf_end, &new_ptr, |
| 308 | &low, &high, byte_order, |
| 309 | addr_size, signed_addr_p); |
| 310 | |
| 311 | loc_ptr = new_ptr; |
| 312 | switch (kind) |
| 313 | { |
| 314 | case DEBUG_LOC_END_OF_LIST: |
| 315 | *locexpr_length = 0; |
| 316 | return NULL; |
| 317 | case DEBUG_LOC_BASE_ADDRESS: |
| 318 | base_address = high + base_offset; |
| 319 | continue; |
| 320 | case DEBUG_LOC_START_END: |
| 321 | case DEBUG_LOC_START_LENGTH: |
| 322 | break; |
| 323 | case DEBUG_LOC_BUFFER_OVERFLOW: |
| 324 | case DEBUG_LOC_INVALID_ENTRY: |
| 325 | error (_("dwarf2_find_location_expression: " |
| 326 | "Corrupted DWARF expression.")); |
| 327 | default: |
| 328 | gdb_assert_not_reached ("bad debug_loc_kind"); |
| 329 | } |
| 330 | |
| 331 | /* Otherwise, a location expression entry. |
| 332 | If the entry is from a DWO, don't add base address: the entry is from |
| 333 | .debug_addr which already has the DWARF "base address". We still add |
| 334 | base_offset in case we're debugging a PIE executable. */ |
| 335 | if (baton->from_dwo) |
| 336 | { |
| 337 | low += base_offset; |
| 338 | high += base_offset; |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | low += base_address; |
| 343 | high += base_address; |
| 344 | } |
| 345 | |
| 346 | if (dwarf2_version (baton->per_cu) < 5) |
| 347 | { |
| 348 | length = extract_unsigned_integer (loc_ptr, 2, byte_order); |
| 349 | loc_ptr += 2; |
| 350 | } |
| 351 | else |
| 352 | { |
| 353 | unsigned int bytes_read; |
| 354 | |
| 355 | length = read_unsigned_leb128 (NULL, loc_ptr, &bytes_read); |
| 356 | loc_ptr += bytes_read; |
| 357 | } |
| 358 | |
| 359 | if (low == high && pc == low) |
| 360 | { |
| 361 | /* This is entry PC record present only at entry point |
| 362 | of a function. Verify it is really the function entry point. */ |
| 363 | |
| 364 | const struct block *pc_block = block_for_pc (pc); |
| 365 | struct symbol *pc_func = NULL; |
| 366 | |
| 367 | if (pc_block) |
| 368 | pc_func = block_linkage_function (pc_block); |
| 369 | |
| 370 | if (pc_func && pc == BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func))) |
| 371 | { |
| 372 | *locexpr_length = length; |
| 373 | return loc_ptr; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | if (pc >= low && pc < high) |
| 378 | { |
| 379 | *locexpr_length = length; |
| 380 | return loc_ptr; |
| 381 | } |
| 382 | |
| 383 | loc_ptr += length; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /* This is the baton used when performing dwarf2 expression |
| 388 | evaluation. */ |
| 389 | struct dwarf_expr_baton |
| 390 | { |
| 391 | struct frame_info *frame; |
| 392 | struct dwarf2_per_cu_data *per_cu; |
| 393 | CORE_ADDR obj_address; |
| 394 | }; |
| 395 | |
| 396 | /* Implement find_frame_base_location method for LOC_BLOCK functions using |
| 397 | DWARF expression for its DW_AT_frame_base. */ |
| 398 | |
| 399 | static void |
| 400 | locexpr_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc, |
| 401 | const gdb_byte **start, size_t *length) |
| 402 | { |
| 403 | struct dwarf2_locexpr_baton *symbaton |
| 404 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (framefunc); |
| 405 | |
| 406 | *length = symbaton->size; |
| 407 | *start = symbaton->data; |
| 408 | } |
| 409 | |
| 410 | /* Implement the struct symbol_block_ops::get_frame_base method for |
| 411 | LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */ |
| 412 | |
| 413 | static CORE_ADDR |
| 414 | locexpr_get_frame_base (struct symbol *framefunc, struct frame_info *frame) |
| 415 | { |
| 416 | struct gdbarch *gdbarch; |
| 417 | struct type *type; |
| 418 | struct dwarf2_locexpr_baton *dlbaton; |
| 419 | const gdb_byte *start; |
| 420 | size_t length; |
| 421 | struct value *result; |
| 422 | |
| 423 | /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block. |
| 424 | Thus, it's supposed to provide the find_frame_base_location method as |
| 425 | well. */ |
| 426 | gdb_assert (SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location != NULL); |
| 427 | |
| 428 | gdbarch = get_frame_arch (frame); |
| 429 | type = builtin_type (gdbarch)->builtin_data_ptr; |
| 430 | dlbaton = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (framefunc); |
| 431 | |
| 432 | SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location |
| 433 | (framefunc, get_frame_pc (frame), &start, &length); |
| 434 | result = dwarf2_evaluate_loc_desc (type, frame, start, length, |
| 435 | dlbaton->per_cu); |
| 436 | |
| 437 | /* The DW_AT_frame_base attribute contains a location description which |
| 438 | computes the base address itself. However, the call to |
| 439 | dwarf2_evaluate_loc_desc returns a value representing a variable at |
| 440 | that address. The frame base address is thus this variable's |
| 441 | address. */ |
| 442 | return value_address (result); |
| 443 | } |
| 444 | |
| 445 | /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior |
| 446 | function uses DWARF expression for its DW_AT_frame_base. */ |
| 447 | |
| 448 | const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs = |
| 449 | { |
| 450 | locexpr_find_frame_base_location, |
| 451 | locexpr_get_frame_base |
| 452 | }; |
| 453 | |
| 454 | /* Implement find_frame_base_location method for LOC_BLOCK functions using |
| 455 | DWARF location list for its DW_AT_frame_base. */ |
| 456 | |
| 457 | static void |
| 458 | loclist_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc, |
| 459 | const gdb_byte **start, size_t *length) |
| 460 | { |
| 461 | struct dwarf2_loclist_baton *symbaton |
| 462 | = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (framefunc); |
| 463 | |
| 464 | *start = dwarf2_find_location_expression (symbaton, length, pc); |
| 465 | } |
| 466 | |
| 467 | /* Implement the struct symbol_block_ops::get_frame_base method for |
| 468 | LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */ |
| 469 | |
| 470 | static CORE_ADDR |
| 471 | loclist_get_frame_base (struct symbol *framefunc, struct frame_info *frame) |
| 472 | { |
| 473 | struct gdbarch *gdbarch; |
| 474 | struct type *type; |
| 475 | struct dwarf2_loclist_baton *dlbaton; |
| 476 | const gdb_byte *start; |
| 477 | size_t length; |
| 478 | struct value *result; |
| 479 | |
| 480 | /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block. |
| 481 | Thus, it's supposed to provide the find_frame_base_location method as |
| 482 | well. */ |
| 483 | gdb_assert (SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location != NULL); |
| 484 | |
| 485 | gdbarch = get_frame_arch (frame); |
| 486 | type = builtin_type (gdbarch)->builtin_data_ptr; |
| 487 | dlbaton = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (framefunc); |
| 488 | |
| 489 | SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location |
| 490 | (framefunc, get_frame_pc (frame), &start, &length); |
| 491 | result = dwarf2_evaluate_loc_desc (type, frame, start, length, |
| 492 | dlbaton->per_cu); |
| 493 | |
| 494 | /* The DW_AT_frame_base attribute contains a location description which |
| 495 | computes the base address itself. However, the call to |
| 496 | dwarf2_evaluate_loc_desc returns a value representing a variable at |
| 497 | that address. The frame base address is thus this variable's |
| 498 | address. */ |
| 499 | return value_address (result); |
| 500 | } |
| 501 | |
| 502 | /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior |
| 503 | function uses DWARF location list for its DW_AT_frame_base. */ |
| 504 | |
| 505 | const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs = |
| 506 | { |
| 507 | loclist_find_frame_base_location, |
| 508 | loclist_get_frame_base |
| 509 | }; |
| 510 | |
| 511 | /* See dwarf2loc.h. */ |
| 512 | |
| 513 | void |
| 514 | func_get_frame_base_dwarf_block (struct symbol *framefunc, CORE_ADDR pc, |
| 515 | const gdb_byte **start, size_t *length) |
| 516 | { |
| 517 | if (SYMBOL_BLOCK_OPS (framefunc) != NULL) |
| 518 | { |
| 519 | const struct symbol_block_ops *ops_block = SYMBOL_BLOCK_OPS (framefunc); |
| 520 | |
| 521 | ops_block->find_frame_base_location (framefunc, pc, start, length); |
| 522 | } |
| 523 | else |
| 524 | *length = 0; |
| 525 | |
| 526 | if (*length == 0) |
| 527 | error (_("Could not find the frame base for \"%s\"."), |
| 528 | SYMBOL_NATURAL_NAME (framefunc)); |
| 529 | } |
| 530 | |
| 531 | static CORE_ADDR |
| 532 | get_frame_pc_for_per_cu_dwarf_call (void *baton) |
| 533 | { |
| 534 | dwarf_expr_context *ctx = (dwarf_expr_context *) baton; |
| 535 | |
| 536 | return ctx->get_frame_pc (); |
| 537 | } |
| 538 | |
| 539 | static void |
| 540 | per_cu_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset, |
| 541 | struct dwarf2_per_cu_data *per_cu) |
| 542 | { |
| 543 | struct dwarf2_locexpr_baton block; |
| 544 | |
| 545 | block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu, |
| 546 | get_frame_pc_for_per_cu_dwarf_call, |
| 547 | ctx); |
| 548 | |
| 549 | /* DW_OP_call_ref is currently not supported. */ |
| 550 | gdb_assert (block.per_cu == per_cu); |
| 551 | |
| 552 | ctx->eval (block.data, block.size); |
| 553 | } |
| 554 | |
| 555 | /* Given context CTX, section offset SECT_OFF, and compilation unit |
| 556 | data PER_CU, execute the "variable value" operation on the DIE |
| 557 | found at SECT_OFF. */ |
| 558 | |
| 559 | static struct value * |
| 560 | sect_variable_value (struct dwarf_expr_context *ctx, sect_offset sect_off, |
| 561 | struct dwarf2_per_cu_data *per_cu) |
| 562 | { |
| 563 | struct type *die_type = dwarf2_fetch_die_type_sect_off (sect_off, per_cu); |
| 564 | |
| 565 | if (die_type == NULL) |
| 566 | error (_("Bad DW_OP_GNU_variable_value DIE.")); |
| 567 | |
| 568 | /* Note: Things still work when the following test is removed. This |
| 569 | test and error is here to conform to the proposed specification. */ |
| 570 | if (TYPE_CODE (die_type) != TYPE_CODE_INT |
| 571 | && TYPE_CODE (die_type) != TYPE_CODE_PTR) |
| 572 | error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer.")); |
| 573 | |
| 574 | struct type *type = lookup_pointer_type (die_type); |
| 575 | struct frame_info *frame = get_selected_frame (_("No frame selected.")); |
| 576 | return indirect_synthetic_pointer (sect_off, 0, per_cu, frame, type, true); |
| 577 | } |
| 578 | |
| 579 | class dwarf_evaluate_loc_desc : public dwarf_expr_context |
| 580 | { |
| 581 | public: |
| 582 | |
| 583 | struct frame_info *frame; |
| 584 | struct dwarf2_per_cu_data *per_cu; |
| 585 | CORE_ADDR obj_address; |
| 586 | |
| 587 | /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for |
| 588 | the frame in BATON. */ |
| 589 | |
| 590 | CORE_ADDR get_frame_cfa () override |
| 591 | { |
| 592 | return dwarf2_frame_cfa (frame); |
| 593 | } |
| 594 | |
| 595 | /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for |
| 596 | the frame in BATON. */ |
| 597 | |
| 598 | CORE_ADDR get_frame_pc () override |
| 599 | { |
| 600 | return get_frame_address_in_block (frame); |
| 601 | } |
| 602 | |
| 603 | /* Using the objfile specified in BATON, find the address for the |
| 604 | current thread's thread-local storage with offset OFFSET. */ |
| 605 | CORE_ADDR get_tls_address (CORE_ADDR offset) override |
| 606 | { |
| 607 | struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); |
| 608 | |
| 609 | return target_translate_tls_address (objfile, offset); |
| 610 | } |
| 611 | |
| 612 | /* Helper interface of per_cu_dwarf_call for |
| 613 | dwarf2_evaluate_loc_desc. */ |
| 614 | |
| 615 | void dwarf_call (cu_offset die_offset) override |
| 616 | { |
| 617 | per_cu_dwarf_call (this, die_offset, per_cu); |
| 618 | } |
| 619 | |
| 620 | /* Helper interface of sect_variable_value for |
| 621 | dwarf2_evaluate_loc_desc. */ |
| 622 | |
| 623 | struct value *dwarf_variable_value (sect_offset sect_off) override |
| 624 | { |
| 625 | return sect_variable_value (this, sect_off, per_cu); |
| 626 | } |
| 627 | |
| 628 | struct type *get_base_type (cu_offset die_offset, int size) override |
| 629 | { |
| 630 | struct type *result = dwarf2_get_die_type (die_offset, per_cu); |
| 631 | if (result == NULL) |
| 632 | error (_("Could not find type for DW_OP_const_type")); |
| 633 | if (size != 0 && TYPE_LENGTH (result) != size) |
| 634 | error (_("DW_OP_const_type has different sizes for type and data")); |
| 635 | return result; |
| 636 | } |
| 637 | |
| 638 | /* Callback function for dwarf2_evaluate_loc_desc. |
| 639 | Fetch the address indexed by DW_OP_GNU_addr_index. */ |
| 640 | |
| 641 | CORE_ADDR get_addr_index (unsigned int index) override |
| 642 | { |
| 643 | return dwarf2_read_addr_index (per_cu, index); |
| 644 | } |
| 645 | |
| 646 | /* Callback function for get_object_address. Return the address of the VLA |
| 647 | object. */ |
| 648 | |
| 649 | CORE_ADDR get_object_address () override |
| 650 | { |
| 651 | if (obj_address == 0) |
| 652 | error (_("Location address is not set.")); |
| 653 | return obj_address; |
| 654 | } |
| 655 | |
| 656 | /* Execute DWARF block of call_site_parameter which matches KIND and |
| 657 | KIND_U. Choose DEREF_SIZE value of that parameter. Search |
| 658 | caller of this objects's frame. |
| 659 | |
| 660 | The caller can be from a different CU - per_cu_dwarf_call |
| 661 | implementation can be more simple as it does not support cross-CU |
| 662 | DWARF executions. */ |
| 663 | |
| 664 | void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind, |
| 665 | union call_site_parameter_u kind_u, |
| 666 | int deref_size) override |
| 667 | { |
| 668 | struct frame_info *caller_frame; |
| 669 | struct dwarf2_per_cu_data *caller_per_cu; |
| 670 | struct call_site_parameter *parameter; |
| 671 | const gdb_byte *data_src; |
| 672 | size_t size; |
| 673 | |
| 674 | caller_frame = get_prev_frame (frame); |
| 675 | |
| 676 | parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u, |
| 677 | &caller_per_cu); |
| 678 | data_src = deref_size == -1 ? parameter->value : parameter->data_value; |
| 679 | size = deref_size == -1 ? parameter->value_size : parameter->data_value_size; |
| 680 | |
| 681 | /* DEREF_SIZE size is not verified here. */ |
| 682 | if (data_src == NULL) |
| 683 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 684 | _("Cannot resolve DW_AT_call_data_value")); |
| 685 | |
| 686 | scoped_restore save_frame = make_scoped_restore (&this->frame, |
| 687 | caller_frame); |
| 688 | scoped_restore save_per_cu = make_scoped_restore (&this->per_cu, |
| 689 | caller_per_cu); |
| 690 | scoped_restore save_obj_addr = make_scoped_restore (&this->obj_address, |
| 691 | (CORE_ADDR) 0); |
| 692 | |
| 693 | scoped_restore save_arch = make_scoped_restore (&this->gdbarch); |
| 694 | this->gdbarch |
| 695 | = get_objfile_arch (dwarf2_per_cu_objfile (per_cu)); |
| 696 | scoped_restore save_addr_size = make_scoped_restore (&this->addr_size); |
| 697 | this->addr_size = dwarf2_per_cu_addr_size (per_cu); |
| 698 | scoped_restore save_offset = make_scoped_restore (&this->offset); |
| 699 | this->offset = dwarf2_per_cu_text_offset (per_cu); |
| 700 | |
| 701 | this->eval (data_src, size); |
| 702 | } |
| 703 | |
| 704 | /* Using the frame specified in BATON, find the location expression |
| 705 | describing the frame base. Return a pointer to it in START and |
| 706 | its length in LENGTH. */ |
| 707 | void get_frame_base (const gdb_byte **start, size_t * length) override |
| 708 | { |
| 709 | /* FIXME: cagney/2003-03-26: This code should be using |
| 710 | get_frame_base_address(), and then implement a dwarf2 specific |
| 711 | this_base method. */ |
| 712 | struct symbol *framefunc; |
| 713 | const struct block *bl = get_frame_block (frame, NULL); |
| 714 | |
| 715 | if (bl == NULL) |
| 716 | error (_("frame address is not available.")); |
| 717 | |
| 718 | /* Use block_linkage_function, which returns a real (not inlined) |
| 719 | function, instead of get_frame_function, which may return an |
| 720 | inlined function. */ |
| 721 | framefunc = block_linkage_function (bl); |
| 722 | |
| 723 | /* If we found a frame-relative symbol then it was certainly within |
| 724 | some function associated with a frame. If we can't find the frame, |
| 725 | something has gone wrong. */ |
| 726 | gdb_assert (framefunc != NULL); |
| 727 | |
| 728 | func_get_frame_base_dwarf_block (framefunc, |
| 729 | get_frame_address_in_block (frame), |
| 730 | start, length); |
| 731 | } |
| 732 | |
| 733 | /* Read memory at ADDR (length LEN) into BUF. */ |
| 734 | |
| 735 | void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override |
| 736 | { |
| 737 | read_memory (addr, buf, len); |
| 738 | } |
| 739 | |
| 740 | /* Using the frame specified in BATON, return the value of register |
| 741 | REGNUM, treated as a pointer. */ |
| 742 | CORE_ADDR read_addr_from_reg (int dwarf_regnum) override |
| 743 | { |
| 744 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 745 | int regnum = dwarf_reg_to_regnum_or_error (gdbarch, dwarf_regnum); |
| 746 | |
| 747 | return address_from_register (regnum, frame); |
| 748 | } |
| 749 | |
| 750 | /* Implement "get_reg_value" callback. */ |
| 751 | |
| 752 | struct value *get_reg_value (struct type *type, int dwarf_regnum) override |
| 753 | { |
| 754 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 755 | int regnum = dwarf_reg_to_regnum_or_error (gdbarch, dwarf_regnum); |
| 756 | |
| 757 | return value_from_register (type, regnum, frame); |
| 758 | } |
| 759 | }; |
| 760 | |
| 761 | /* See dwarf2loc.h. */ |
| 762 | |
| 763 | unsigned int entry_values_debug = 0; |
| 764 | |
| 765 | /* Helper to set entry_values_debug. */ |
| 766 | |
| 767 | static void |
| 768 | show_entry_values_debug (struct ui_file *file, int from_tty, |
| 769 | struct cmd_list_element *c, const char *value) |
| 770 | { |
| 771 | fprintf_filtered (file, |
| 772 | _("Entry values and tail call frames debugging is %s.\n"), |
| 773 | value); |
| 774 | } |
| 775 | |
| 776 | /* Find DW_TAG_call_site's DW_AT_call_target address. |
| 777 | CALLER_FRAME (for registers) can be NULL if it is not known. This function |
| 778 | always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */ |
| 779 | |
| 780 | static CORE_ADDR |
| 781 | call_site_to_target_addr (struct gdbarch *call_site_gdbarch, |
| 782 | struct call_site *call_site, |
| 783 | struct frame_info *caller_frame) |
| 784 | { |
| 785 | switch (FIELD_LOC_KIND (call_site->target)) |
| 786 | { |
| 787 | case FIELD_LOC_KIND_DWARF_BLOCK: |
| 788 | { |
| 789 | struct dwarf2_locexpr_baton *dwarf_block; |
| 790 | struct value *val; |
| 791 | struct type *caller_core_addr_type; |
| 792 | struct gdbarch *caller_arch; |
| 793 | |
| 794 | dwarf_block = FIELD_DWARF_BLOCK (call_site->target); |
| 795 | if (dwarf_block == NULL) |
| 796 | { |
| 797 | struct bound_minimal_symbol msym; |
| 798 | |
| 799 | msym = lookup_minimal_symbol_by_pc (call_site->pc - 1); |
| 800 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 801 | _("DW_AT_call_target is not specified at %s in %s"), |
| 802 | paddress (call_site_gdbarch, call_site->pc), |
| 803 | (msym.minsym == NULL ? "???" |
| 804 | : MSYMBOL_PRINT_NAME (msym.minsym))); |
| 805 | |
| 806 | } |
| 807 | if (caller_frame == NULL) |
| 808 | { |
| 809 | struct bound_minimal_symbol msym; |
| 810 | |
| 811 | msym = lookup_minimal_symbol_by_pc (call_site->pc - 1); |
| 812 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 813 | _("DW_AT_call_target DWARF block resolving " |
| 814 | "requires known frame which is currently not " |
| 815 | "available at %s in %s"), |
| 816 | paddress (call_site_gdbarch, call_site->pc), |
| 817 | (msym.minsym == NULL ? "???" |
| 818 | : MSYMBOL_PRINT_NAME (msym.minsym))); |
| 819 | |
| 820 | } |
| 821 | caller_arch = get_frame_arch (caller_frame); |
| 822 | caller_core_addr_type = builtin_type (caller_arch)->builtin_func_ptr; |
| 823 | val = dwarf2_evaluate_loc_desc (caller_core_addr_type, caller_frame, |
| 824 | dwarf_block->data, dwarf_block->size, |
| 825 | dwarf_block->per_cu); |
| 826 | /* DW_AT_call_target is a DWARF expression, not a DWARF location. */ |
| 827 | if (VALUE_LVAL (val) == lval_memory) |
| 828 | return value_address (val); |
| 829 | else |
| 830 | return value_as_address (val); |
| 831 | } |
| 832 | |
| 833 | case FIELD_LOC_KIND_PHYSNAME: |
| 834 | { |
| 835 | const char *physname; |
| 836 | struct bound_minimal_symbol msym; |
| 837 | |
| 838 | physname = FIELD_STATIC_PHYSNAME (call_site->target); |
| 839 | |
| 840 | /* Handle both the mangled and demangled PHYSNAME. */ |
| 841 | msym = lookup_minimal_symbol (physname, NULL, NULL); |
| 842 | if (msym.minsym == NULL) |
| 843 | { |
| 844 | msym = lookup_minimal_symbol_by_pc (call_site->pc - 1); |
| 845 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 846 | _("Cannot find function \"%s\" for a call site target " |
| 847 | "at %s in %s"), |
| 848 | physname, paddress (call_site_gdbarch, call_site->pc), |
| 849 | (msym.minsym == NULL ? "???" |
| 850 | : MSYMBOL_PRINT_NAME (msym.minsym))); |
| 851 | |
| 852 | } |
| 853 | return BMSYMBOL_VALUE_ADDRESS (msym); |
| 854 | } |
| 855 | |
| 856 | case FIELD_LOC_KIND_PHYSADDR: |
| 857 | return FIELD_STATIC_PHYSADDR (call_site->target); |
| 858 | |
| 859 | default: |
| 860 | internal_error (__FILE__, __LINE__, _("invalid call site target kind")); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | /* Convert function entry point exact address ADDR to the function which is |
| 865 | compliant with TAIL_CALL_LIST_COMPLETE condition. Throw |
| 866 | NO_ENTRY_VALUE_ERROR otherwise. */ |
| 867 | |
| 868 | static struct symbol * |
| 869 | func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr) |
| 870 | { |
| 871 | struct symbol *sym = find_pc_function (addr); |
| 872 | struct type *type; |
| 873 | |
| 874 | if (sym == NULL || BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym)) != addr) |
| 875 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 876 | _("DW_TAG_call_site resolving failed to find function " |
| 877 | "name for address %s"), |
| 878 | paddress (gdbarch, addr)); |
| 879 | |
| 880 | type = SYMBOL_TYPE (sym); |
| 881 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_FUNC); |
| 882 | gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC); |
| 883 | |
| 884 | return sym; |
| 885 | } |
| 886 | |
| 887 | /* Verify function with entry point exact address ADDR can never call itself |
| 888 | via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it |
| 889 | can call itself via tail calls. |
| 890 | |
| 891 | If a funtion can tail call itself its entry value based parameters are |
| 892 | unreliable. There is no verification whether the value of some/all |
| 893 | parameters is unchanged through the self tail call, we expect if there is |
| 894 | a self tail call all the parameters can be modified. */ |
| 895 | |
| 896 | static void |
| 897 | func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr) |
| 898 | { |
| 899 | CORE_ADDR addr; |
| 900 | |
| 901 | /* The verification is completely unordered. Track here function addresses |
| 902 | which still need to be iterated. */ |
| 903 | std::vector<CORE_ADDR> todo; |
| 904 | |
| 905 | /* Track here CORE_ADDRs which were already visited. */ |
| 906 | std::unordered_set<CORE_ADDR> addr_hash; |
| 907 | |
| 908 | todo.push_back (verify_addr); |
| 909 | while (!todo.empty ()) |
| 910 | { |
| 911 | struct symbol *func_sym; |
| 912 | struct call_site *call_site; |
| 913 | |
| 914 | addr = todo.back (); |
| 915 | todo.pop_back (); |
| 916 | |
| 917 | func_sym = func_addr_to_tail_call_list (gdbarch, addr); |
| 918 | |
| 919 | for (call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym)); |
| 920 | call_site; call_site = call_site->tail_call_next) |
| 921 | { |
| 922 | CORE_ADDR target_addr; |
| 923 | |
| 924 | /* CALLER_FRAME with registers is not available for tail-call jumped |
| 925 | frames. */ |
| 926 | target_addr = call_site_to_target_addr (gdbarch, call_site, NULL); |
| 927 | |
| 928 | if (target_addr == verify_addr) |
| 929 | { |
| 930 | struct bound_minimal_symbol msym; |
| 931 | |
| 932 | msym = lookup_minimal_symbol_by_pc (verify_addr); |
| 933 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 934 | _("DW_OP_entry_value resolving has found " |
| 935 | "function \"%s\" at %s can call itself via tail " |
| 936 | "calls"), |
| 937 | (msym.minsym == NULL ? "???" |
| 938 | : MSYMBOL_PRINT_NAME (msym.minsym)), |
| 939 | paddress (gdbarch, verify_addr)); |
| 940 | } |
| 941 | |
| 942 | if (addr_hash.insert (target_addr).second) |
| 943 | todo.push_back (target_addr); |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for |
| 949 | ENTRY_VALUES_DEBUG. */ |
| 950 | |
| 951 | static void |
| 952 | tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site) |
| 953 | { |
| 954 | CORE_ADDR addr = call_site->pc; |
| 955 | struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (addr - 1); |
| 956 | |
| 957 | fprintf_unfiltered (gdb_stdlog, " %s(%s)", paddress (gdbarch, addr), |
| 958 | (msym.minsym == NULL ? "???" |
| 959 | : MSYMBOL_PRINT_NAME (msym.minsym))); |
| 960 | |
| 961 | } |
| 962 | |
| 963 | /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP |
| 964 | only top callers and bottom callees which are present in both. GDBARCH is |
| 965 | used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are |
| 966 | no remaining possibilities to provide unambiguous non-trivial result. |
| 967 | RESULTP should point to NULL on the first (initialization) call. Caller is |
| 968 | responsible for xfree of any RESULTP data. */ |
| 969 | |
| 970 | static void |
| 971 | chain_candidate (struct gdbarch *gdbarch, |
| 972 | gdb::unique_xmalloc_ptr<struct call_site_chain> *resultp, |
| 973 | std::vector<struct call_site *> *chain) |
| 974 | { |
| 975 | long length = chain->size (); |
| 976 | int callers, callees, idx; |
| 977 | |
| 978 | if (*resultp == NULL) |
| 979 | { |
| 980 | /* Create the initial chain containing all the passed PCs. */ |
| 981 | |
| 982 | struct call_site_chain *result |
| 983 | = ((struct call_site_chain *) |
| 984 | xmalloc (sizeof (*result) |
| 985 | + sizeof (*result->call_site) * (length - 1))); |
| 986 | result->length = length; |
| 987 | result->callers = result->callees = length; |
| 988 | if (!chain->empty ()) |
| 989 | memcpy (result->call_site, chain->data (), |
| 990 | sizeof (*result->call_site) * length); |
| 991 | resultp->reset (result); |
| 992 | |
| 993 | if (entry_values_debug) |
| 994 | { |
| 995 | fprintf_unfiltered (gdb_stdlog, "tailcall: initial:"); |
| 996 | for (idx = 0; idx < length; idx++) |
| 997 | tailcall_dump (gdbarch, result->call_site[idx]); |
| 998 | fputc_unfiltered ('\n', gdb_stdlog); |
| 999 | } |
| 1000 | |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | if (entry_values_debug) |
| 1005 | { |
| 1006 | fprintf_unfiltered (gdb_stdlog, "tailcall: compare:"); |
| 1007 | for (idx = 0; idx < length; idx++) |
| 1008 | tailcall_dump (gdbarch, chain->at (idx)); |
| 1009 | fputc_unfiltered ('\n', gdb_stdlog); |
| 1010 | } |
| 1011 | |
| 1012 | /* Intersect callers. */ |
| 1013 | |
| 1014 | callers = std::min ((long) (*resultp)->callers, length); |
| 1015 | for (idx = 0; idx < callers; idx++) |
| 1016 | if ((*resultp)->call_site[idx] != chain->at (idx)) |
| 1017 | { |
| 1018 | (*resultp)->callers = idx; |
| 1019 | break; |
| 1020 | } |
| 1021 | |
| 1022 | /* Intersect callees. */ |
| 1023 | |
| 1024 | callees = std::min ((long) (*resultp)->callees, length); |
| 1025 | for (idx = 0; idx < callees; idx++) |
| 1026 | if ((*resultp)->call_site[(*resultp)->length - 1 - idx] |
| 1027 | != chain->at (length - 1 - idx)) |
| 1028 | { |
| 1029 | (*resultp)->callees = idx; |
| 1030 | break; |
| 1031 | } |
| 1032 | |
| 1033 | if (entry_values_debug) |
| 1034 | { |
| 1035 | fprintf_unfiltered (gdb_stdlog, "tailcall: reduced:"); |
| 1036 | for (idx = 0; idx < (*resultp)->callers; idx++) |
| 1037 | tailcall_dump (gdbarch, (*resultp)->call_site[idx]); |
| 1038 | fputs_unfiltered (" |", gdb_stdlog); |
| 1039 | for (idx = 0; idx < (*resultp)->callees; idx++) |
| 1040 | tailcall_dump (gdbarch, |
| 1041 | (*resultp)->call_site[(*resultp)->length |
| 1042 | - (*resultp)->callees + idx]); |
| 1043 | fputc_unfiltered ('\n', gdb_stdlog); |
| 1044 | } |
| 1045 | |
| 1046 | if ((*resultp)->callers == 0 && (*resultp)->callees == 0) |
| 1047 | { |
| 1048 | /* There are no common callers or callees. It could be also a direct |
| 1049 | call (which has length 0) with ambiguous possibility of an indirect |
| 1050 | call - CALLERS == CALLEES == 0 is valid during the first allocation |
| 1051 | but any subsequence processing of such entry means ambiguity. */ |
| 1052 | resultp->reset (NULL); |
| 1053 | return; |
| 1054 | } |
| 1055 | |
| 1056 | /* See call_site_find_chain_1 why there is no way to reach the bottom callee |
| 1057 | PC again. In such case there must be two different code paths to reach |
| 1058 | it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */ |
| 1059 | gdb_assert ((*resultp)->callers + (*resultp)->callees <= (*resultp)->length); |
| 1060 | } |
| 1061 | |
| 1062 | /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the |
| 1063 | assumed frames between them use GDBARCH. Use depth first search so we can |
| 1064 | keep single CHAIN of call_site's back to CALLER_PC. Function recursion |
| 1065 | would have needless GDB stack overhead. Caller is responsible for xfree of |
| 1066 | the returned result. Any unreliability results in thrown |
| 1067 | NO_ENTRY_VALUE_ERROR. */ |
| 1068 | |
| 1069 | static struct call_site_chain * |
| 1070 | call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc, |
| 1071 | CORE_ADDR callee_pc) |
| 1072 | { |
| 1073 | CORE_ADDR save_callee_pc = callee_pc; |
| 1074 | gdb::unique_xmalloc_ptr<struct call_site_chain> retval; |
| 1075 | struct call_site *call_site; |
| 1076 | |
| 1077 | /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's |
| 1078 | call_site nor any possible call_site at CALLEE_PC's function is there. |
| 1079 | Any CALL_SITE in CHAIN will be iterated to its siblings - via |
| 1080 | TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */ |
| 1081 | std::vector<struct call_site *> chain; |
| 1082 | |
| 1083 | /* We are not interested in the specific PC inside the callee function. */ |
| 1084 | callee_pc = get_pc_function_start (callee_pc); |
| 1085 | if (callee_pc == 0) |
| 1086 | throw_error (NO_ENTRY_VALUE_ERROR, _("Unable to find function for PC %s"), |
| 1087 | paddress (gdbarch, save_callee_pc)); |
| 1088 | |
| 1089 | /* Mark CALL_SITEs so we do not visit the same ones twice. */ |
| 1090 | std::unordered_set<CORE_ADDR> addr_hash; |
| 1091 | |
| 1092 | /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site |
| 1093 | at the target's function. All the possible tail call sites in the |
| 1094 | target's function will get iterated as already pushed into CHAIN via their |
| 1095 | TAIL_CALL_NEXT. */ |
| 1096 | call_site = call_site_for_pc (gdbarch, caller_pc); |
| 1097 | |
| 1098 | while (call_site) |
| 1099 | { |
| 1100 | CORE_ADDR target_func_addr; |
| 1101 | struct call_site *target_call_site; |
| 1102 | |
| 1103 | /* CALLER_FRAME with registers is not available for tail-call jumped |
| 1104 | frames. */ |
| 1105 | target_func_addr = call_site_to_target_addr (gdbarch, call_site, NULL); |
| 1106 | |
| 1107 | if (target_func_addr == callee_pc) |
| 1108 | { |
| 1109 | chain_candidate (gdbarch, &retval, &chain); |
| 1110 | if (retval == NULL) |
| 1111 | break; |
| 1112 | |
| 1113 | /* There is no way to reach CALLEE_PC again as we would prevent |
| 1114 | entering it twice as being already marked in ADDR_HASH. */ |
| 1115 | target_call_site = NULL; |
| 1116 | } |
| 1117 | else |
| 1118 | { |
| 1119 | struct symbol *target_func; |
| 1120 | |
| 1121 | target_func = func_addr_to_tail_call_list (gdbarch, target_func_addr); |
| 1122 | target_call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func)); |
| 1123 | } |
| 1124 | |
| 1125 | do |
| 1126 | { |
| 1127 | /* Attempt to visit TARGET_CALL_SITE. */ |
| 1128 | |
| 1129 | if (target_call_site) |
| 1130 | { |
| 1131 | if (addr_hash.insert (target_call_site->pc).second) |
| 1132 | { |
| 1133 | /* Successfully entered TARGET_CALL_SITE. */ |
| 1134 | |
| 1135 | chain.push_back (target_call_site); |
| 1136 | break; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | /* Backtrack (without revisiting the originating call_site). Try the |
| 1141 | callers's sibling; if there isn't any try the callers's callers's |
| 1142 | sibling etc. */ |
| 1143 | |
| 1144 | target_call_site = NULL; |
| 1145 | while (!chain.empty ()) |
| 1146 | { |
| 1147 | call_site = chain.back (); |
| 1148 | chain.pop_back (); |
| 1149 | |
| 1150 | size_t removed = addr_hash.erase (call_site->pc); |
| 1151 | gdb_assert (removed == 1); |
| 1152 | |
| 1153 | target_call_site = call_site->tail_call_next; |
| 1154 | if (target_call_site) |
| 1155 | break; |
| 1156 | } |
| 1157 | } |
| 1158 | while (target_call_site); |
| 1159 | |
| 1160 | if (chain.empty ()) |
| 1161 | call_site = NULL; |
| 1162 | else |
| 1163 | call_site = chain.back (); |
| 1164 | } |
| 1165 | |
| 1166 | if (retval == NULL) |
| 1167 | { |
| 1168 | struct bound_minimal_symbol msym_caller, msym_callee; |
| 1169 | |
| 1170 | msym_caller = lookup_minimal_symbol_by_pc (caller_pc); |
| 1171 | msym_callee = lookup_minimal_symbol_by_pc (callee_pc); |
| 1172 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 1173 | _("There are no unambiguously determinable intermediate " |
| 1174 | "callers or callees between caller function \"%s\" at %s " |
| 1175 | "and callee function \"%s\" at %s"), |
| 1176 | (msym_caller.minsym == NULL |
| 1177 | ? "???" : MSYMBOL_PRINT_NAME (msym_caller.minsym)), |
| 1178 | paddress (gdbarch, caller_pc), |
| 1179 | (msym_callee.minsym == NULL |
| 1180 | ? "???" : MSYMBOL_PRINT_NAME (msym_callee.minsym)), |
| 1181 | paddress (gdbarch, callee_pc)); |
| 1182 | } |
| 1183 | |
| 1184 | return retval.release (); |
| 1185 | } |
| 1186 | |
| 1187 | /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the |
| 1188 | assumed frames between them use GDBARCH. If valid call_site_chain cannot be |
| 1189 | constructed return NULL. Caller is responsible for xfree of the returned |
| 1190 | result. */ |
| 1191 | |
| 1192 | struct call_site_chain * |
| 1193 | call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc, |
| 1194 | CORE_ADDR callee_pc) |
| 1195 | { |
| 1196 | struct call_site_chain *retval = NULL; |
| 1197 | |
| 1198 | TRY |
| 1199 | { |
| 1200 | retval = call_site_find_chain_1 (gdbarch, caller_pc, callee_pc); |
| 1201 | } |
| 1202 | CATCH (e, RETURN_MASK_ERROR) |
| 1203 | { |
| 1204 | if (e.error == NO_ENTRY_VALUE_ERROR) |
| 1205 | { |
| 1206 | if (entry_values_debug) |
| 1207 | exception_print (gdb_stdout, e); |
| 1208 | |
| 1209 | return NULL; |
| 1210 | } |
| 1211 | else |
| 1212 | throw_exception (e); |
| 1213 | } |
| 1214 | END_CATCH |
| 1215 | |
| 1216 | return retval; |
| 1217 | } |
| 1218 | |
| 1219 | /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */ |
| 1220 | |
| 1221 | static int |
| 1222 | call_site_parameter_matches (struct call_site_parameter *parameter, |
| 1223 | enum call_site_parameter_kind kind, |
| 1224 | union call_site_parameter_u kind_u) |
| 1225 | { |
| 1226 | if (kind == parameter->kind) |
| 1227 | switch (kind) |
| 1228 | { |
| 1229 | case CALL_SITE_PARAMETER_DWARF_REG: |
| 1230 | return kind_u.dwarf_reg == parameter->u.dwarf_reg; |
| 1231 | case CALL_SITE_PARAMETER_FB_OFFSET: |
| 1232 | return kind_u.fb_offset == parameter->u.fb_offset; |
| 1233 | case CALL_SITE_PARAMETER_PARAM_OFFSET: |
| 1234 | return kind_u.param_cu_off == parameter->u.param_cu_off; |
| 1235 | } |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
| 1239 | /* Fetch call_site_parameter from caller matching KIND and KIND_U. |
| 1240 | FRAME is for callee. |
| 1241 | |
| 1242 | Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR |
| 1243 | otherwise. */ |
| 1244 | |
| 1245 | static struct call_site_parameter * |
| 1246 | dwarf_expr_reg_to_entry_parameter (struct frame_info *frame, |
| 1247 | enum call_site_parameter_kind kind, |
| 1248 | union call_site_parameter_u kind_u, |
| 1249 | struct dwarf2_per_cu_data **per_cu_return) |
| 1250 | { |
| 1251 | CORE_ADDR func_addr, caller_pc; |
| 1252 | struct gdbarch *gdbarch; |
| 1253 | struct frame_info *caller_frame; |
| 1254 | struct call_site *call_site; |
| 1255 | int iparams; |
| 1256 | /* Initialize it just to avoid a GCC false warning. */ |
| 1257 | struct call_site_parameter *parameter = NULL; |
| 1258 | CORE_ADDR target_addr; |
| 1259 | |
| 1260 | while (get_frame_type (frame) == INLINE_FRAME) |
| 1261 | { |
| 1262 | frame = get_prev_frame (frame); |
| 1263 | gdb_assert (frame != NULL); |
| 1264 | } |
| 1265 | |
| 1266 | func_addr = get_frame_func (frame); |
| 1267 | gdbarch = get_frame_arch (frame); |
| 1268 | caller_frame = get_prev_frame (frame); |
| 1269 | if (gdbarch != frame_unwind_arch (frame)) |
| 1270 | { |
| 1271 | struct bound_minimal_symbol msym |
| 1272 | = lookup_minimal_symbol_by_pc (func_addr); |
| 1273 | struct gdbarch *caller_gdbarch = frame_unwind_arch (frame); |
| 1274 | |
| 1275 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 1276 | _("DW_OP_entry_value resolving callee gdbarch %s " |
| 1277 | "(of %s (%s)) does not match caller gdbarch %s"), |
| 1278 | gdbarch_bfd_arch_info (gdbarch)->printable_name, |
| 1279 | paddress (gdbarch, func_addr), |
| 1280 | (msym.minsym == NULL ? "???" |
| 1281 | : MSYMBOL_PRINT_NAME (msym.minsym)), |
| 1282 | gdbarch_bfd_arch_info (caller_gdbarch)->printable_name); |
| 1283 | } |
| 1284 | |
| 1285 | if (caller_frame == NULL) |
| 1286 | { |
| 1287 | struct bound_minimal_symbol msym |
| 1288 | = lookup_minimal_symbol_by_pc (func_addr); |
| 1289 | |
| 1290 | throw_error (NO_ENTRY_VALUE_ERROR, _("DW_OP_entry_value resolving " |
| 1291 | "requires caller of %s (%s)"), |
| 1292 | paddress (gdbarch, func_addr), |
| 1293 | (msym.minsym == NULL ? "???" |
| 1294 | : MSYMBOL_PRINT_NAME (msym.minsym))); |
| 1295 | } |
| 1296 | caller_pc = get_frame_pc (caller_frame); |
| 1297 | call_site = call_site_for_pc (gdbarch, caller_pc); |
| 1298 | |
| 1299 | target_addr = call_site_to_target_addr (gdbarch, call_site, caller_frame); |
| 1300 | if (target_addr != func_addr) |
| 1301 | { |
| 1302 | struct minimal_symbol *target_msym, *func_msym; |
| 1303 | |
| 1304 | target_msym = lookup_minimal_symbol_by_pc (target_addr).minsym; |
| 1305 | func_msym = lookup_minimal_symbol_by_pc (func_addr).minsym; |
| 1306 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 1307 | _("DW_OP_entry_value resolving expects callee %s at %s " |
| 1308 | "but the called frame is for %s at %s"), |
| 1309 | (target_msym == NULL ? "???" |
| 1310 | : MSYMBOL_PRINT_NAME (target_msym)), |
| 1311 | paddress (gdbarch, target_addr), |
| 1312 | func_msym == NULL ? "???" : MSYMBOL_PRINT_NAME (func_msym), |
| 1313 | paddress (gdbarch, func_addr)); |
| 1314 | } |
| 1315 | |
| 1316 | /* No entry value based parameters would be reliable if this function can |
| 1317 | call itself via tail calls. */ |
| 1318 | func_verify_no_selftailcall (gdbarch, func_addr); |
| 1319 | |
| 1320 | for (iparams = 0; iparams < call_site->parameter_count; iparams++) |
| 1321 | { |
| 1322 | parameter = &call_site->parameter[iparams]; |
| 1323 | if (call_site_parameter_matches (parameter, kind, kind_u)) |
| 1324 | break; |
| 1325 | } |
| 1326 | if (iparams == call_site->parameter_count) |
| 1327 | { |
| 1328 | struct minimal_symbol *msym |
| 1329 | = lookup_minimal_symbol_by_pc (caller_pc).minsym; |
| 1330 | |
| 1331 | /* DW_TAG_call_site_parameter will be missing just if GCC could not |
| 1332 | determine its value. */ |
| 1333 | throw_error (NO_ENTRY_VALUE_ERROR, _("Cannot find matching parameter " |
| 1334 | "at DW_TAG_call_site %s at %s"), |
| 1335 | paddress (gdbarch, caller_pc), |
| 1336 | msym == NULL ? "???" : MSYMBOL_PRINT_NAME (msym)); |
| 1337 | } |
| 1338 | |
| 1339 | *per_cu_return = call_site->per_cu; |
| 1340 | return parameter; |
| 1341 | } |
| 1342 | |
| 1343 | /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return |
| 1344 | the normal DW_AT_call_value block. Otherwise return the |
| 1345 | DW_AT_call_data_value (dereferenced) block. |
| 1346 | |
| 1347 | TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned |
| 1348 | struct value. |
| 1349 | |
| 1350 | Function always returns non-NULL, non-optimized out value. It throws |
| 1351 | NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */ |
| 1352 | |
| 1353 | static struct value * |
| 1354 | dwarf_entry_parameter_to_value (struct call_site_parameter *parameter, |
| 1355 | CORE_ADDR deref_size, struct type *type, |
| 1356 | struct frame_info *caller_frame, |
| 1357 | struct dwarf2_per_cu_data *per_cu) |
| 1358 | { |
| 1359 | const gdb_byte *data_src; |
| 1360 | gdb_byte *data; |
| 1361 | size_t size; |
| 1362 | |
| 1363 | data_src = deref_size == -1 ? parameter->value : parameter->data_value; |
| 1364 | size = deref_size == -1 ? parameter->value_size : parameter->data_value_size; |
| 1365 | |
| 1366 | /* DEREF_SIZE size is not verified here. */ |
| 1367 | if (data_src == NULL) |
| 1368 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 1369 | _("Cannot resolve DW_AT_call_data_value")); |
| 1370 | |
| 1371 | /* DW_AT_call_value is a DWARF expression, not a DWARF |
| 1372 | location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from |
| 1373 | DWARF block. */ |
| 1374 | data = (gdb_byte *) alloca (size + 1); |
| 1375 | memcpy (data, data_src, size); |
| 1376 | data[size] = DW_OP_stack_value; |
| 1377 | |
| 1378 | return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu); |
| 1379 | } |
| 1380 | |
| 1381 | /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform |
| 1382 | the indirect method on it, that is use its stored target value, the sole |
| 1383 | purpose of entry_data_value_funcs.. */ |
| 1384 | |
| 1385 | static struct value * |
| 1386 | entry_data_value_coerce_ref (const struct value *value) |
| 1387 | { |
| 1388 | struct type *checked_type = check_typedef (value_type (value)); |
| 1389 | struct value *target_val; |
| 1390 | |
| 1391 | if (!TYPE_IS_REFERENCE (checked_type)) |
| 1392 | return NULL; |
| 1393 | |
| 1394 | target_val = (struct value *) value_computed_closure (value); |
| 1395 | value_incref (target_val); |
| 1396 | return target_val; |
| 1397 | } |
| 1398 | |
| 1399 | /* Implement copy_closure. */ |
| 1400 | |
| 1401 | static void * |
| 1402 | entry_data_value_copy_closure (const struct value *v) |
| 1403 | { |
| 1404 | struct value *target_val = (struct value *) value_computed_closure (v); |
| 1405 | |
| 1406 | value_incref (target_val); |
| 1407 | return target_val; |
| 1408 | } |
| 1409 | |
| 1410 | /* Implement free_closure. */ |
| 1411 | |
| 1412 | static void |
| 1413 | entry_data_value_free_closure (struct value *v) |
| 1414 | { |
| 1415 | struct value *target_val = (struct value *) value_computed_closure (v); |
| 1416 | |
| 1417 | value_decref (target_val); |
| 1418 | } |
| 1419 | |
| 1420 | /* Vector for methods for an entry value reference where the referenced value |
| 1421 | is stored in the caller. On the first dereference use |
| 1422 | DW_AT_call_data_value in the caller. */ |
| 1423 | |
| 1424 | static const struct lval_funcs entry_data_value_funcs = |
| 1425 | { |
| 1426 | NULL, /* read */ |
| 1427 | NULL, /* write */ |
| 1428 | NULL, /* indirect */ |
| 1429 | entry_data_value_coerce_ref, |
| 1430 | NULL, /* check_synthetic_pointer */ |
| 1431 | entry_data_value_copy_closure, |
| 1432 | entry_data_value_free_closure |
| 1433 | }; |
| 1434 | |
| 1435 | /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U |
| 1436 | are used to match DW_AT_location at the caller's |
| 1437 | DW_TAG_call_site_parameter. |
| 1438 | |
| 1439 | Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it |
| 1440 | cannot resolve the parameter for any reason. */ |
| 1441 | |
| 1442 | static struct value * |
| 1443 | value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame, |
| 1444 | enum call_site_parameter_kind kind, |
| 1445 | union call_site_parameter_u kind_u) |
| 1446 | { |
| 1447 | struct type *checked_type = check_typedef (type); |
| 1448 | struct type *target_type = TYPE_TARGET_TYPE (checked_type); |
| 1449 | struct frame_info *caller_frame = get_prev_frame (frame); |
| 1450 | struct value *outer_val, *target_val, *val; |
| 1451 | struct call_site_parameter *parameter; |
| 1452 | struct dwarf2_per_cu_data *caller_per_cu; |
| 1453 | |
| 1454 | parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u, |
| 1455 | &caller_per_cu); |
| 1456 | |
| 1457 | outer_val = dwarf_entry_parameter_to_value (parameter, -1 /* deref_size */, |
| 1458 | type, caller_frame, |
| 1459 | caller_per_cu); |
| 1460 | |
| 1461 | /* Check if DW_AT_call_data_value cannot be used. If it should be |
| 1462 | used and it is not available do not fall back to OUTER_VAL - dereferencing |
| 1463 | TYPE_CODE_REF with non-entry data value would give current value - not the |
| 1464 | entry value. */ |
| 1465 | |
| 1466 | if (!TYPE_IS_REFERENCE (checked_type) |
| 1467 | || TYPE_TARGET_TYPE (checked_type) == NULL) |
| 1468 | return outer_val; |
| 1469 | |
| 1470 | target_val = dwarf_entry_parameter_to_value (parameter, |
| 1471 | TYPE_LENGTH (target_type), |
| 1472 | target_type, caller_frame, |
| 1473 | caller_per_cu); |
| 1474 | |
| 1475 | release_value (target_val).release (); |
| 1476 | val = allocate_computed_value (type, &entry_data_value_funcs, |
| 1477 | target_val /* closure */); |
| 1478 | |
| 1479 | /* Copy the referencing pointer to the new computed value. */ |
| 1480 | memcpy (value_contents_raw (val), value_contents_raw (outer_val), |
| 1481 | TYPE_LENGTH (checked_type)); |
| 1482 | set_value_lazy (val, 0); |
| 1483 | |
| 1484 | return val; |
| 1485 | } |
| 1486 | |
| 1487 | /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and |
| 1488 | SIZE are DWARF block used to match DW_AT_location at the caller's |
| 1489 | DW_TAG_call_site_parameter. |
| 1490 | |
| 1491 | Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it |
| 1492 | cannot resolve the parameter for any reason. */ |
| 1493 | |
| 1494 | static struct value * |
| 1495 | value_of_dwarf_block_entry (struct type *type, struct frame_info *frame, |
| 1496 | const gdb_byte *block, size_t block_len) |
| 1497 | { |
| 1498 | union call_site_parameter_u kind_u; |
| 1499 | |
| 1500 | kind_u.dwarf_reg = dwarf_block_to_dwarf_reg (block, block + block_len); |
| 1501 | if (kind_u.dwarf_reg != -1) |
| 1502 | return value_of_dwarf_reg_entry (type, frame, CALL_SITE_PARAMETER_DWARF_REG, |
| 1503 | kind_u); |
| 1504 | |
| 1505 | if (dwarf_block_to_fb_offset (block, block + block_len, &kind_u.fb_offset)) |
| 1506 | return value_of_dwarf_reg_entry (type, frame, CALL_SITE_PARAMETER_FB_OFFSET, |
| 1507 | kind_u); |
| 1508 | |
| 1509 | /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message |
| 1510 | suppressed during normal operation. The expression can be arbitrary if |
| 1511 | there is no caller-callee entry value binding expected. */ |
| 1512 | throw_error (NO_ENTRY_VALUE_ERROR, |
| 1513 | _("DWARF-2 expression error: DW_OP_entry_value is supported " |
| 1514 | "only for single DW_OP_reg* or for DW_OP_fbreg(*)")); |
| 1515 | } |
| 1516 | |
| 1517 | struct piece_closure |
| 1518 | { |
| 1519 | /* Reference count. */ |
| 1520 | int refc = 0; |
| 1521 | |
| 1522 | /* The CU from which this closure's expression came. */ |
| 1523 | struct dwarf2_per_cu_data *per_cu = NULL; |
| 1524 | |
| 1525 | /* The pieces describing this variable. */ |
| 1526 | std::vector<dwarf_expr_piece> pieces; |
| 1527 | |
| 1528 | /* Frame ID of frame to which a register value is relative, used |
| 1529 | only by DWARF_VALUE_REGISTER. */ |
| 1530 | struct frame_id frame_id; |
| 1531 | }; |
| 1532 | |
| 1533 | /* Allocate a closure for a value formed from separately-described |
| 1534 | PIECES. */ |
| 1535 | |
| 1536 | static struct piece_closure * |
| 1537 | allocate_piece_closure (struct dwarf2_per_cu_data *per_cu, |
| 1538 | std::vector<dwarf_expr_piece> &&pieces, |
| 1539 | struct frame_info *frame) |
| 1540 | { |
| 1541 | struct piece_closure *c = new piece_closure; |
| 1542 | |
| 1543 | c->refc = 1; |
| 1544 | c->per_cu = per_cu; |
| 1545 | c->pieces = std::move (pieces); |
| 1546 | if (frame == NULL) |
| 1547 | c->frame_id = null_frame_id; |
| 1548 | else |
| 1549 | c->frame_id = get_frame_id (frame); |
| 1550 | |
| 1551 | for (dwarf_expr_piece &piece : c->pieces) |
| 1552 | if (piece.location == DWARF_VALUE_STACK) |
| 1553 | value_incref (piece.v.value); |
| 1554 | |
| 1555 | return c; |
| 1556 | } |
| 1557 | |
| 1558 | /* Copy NBITS bits from SOURCE to DEST starting at the given bit |
| 1559 | offsets. Use the bit order as specified by BITS_BIG_ENDIAN. |
| 1560 | Source and destination buffers must not overlap. */ |
| 1561 | |
| 1562 | static void |
| 1563 | copy_bitwise (gdb_byte *dest, ULONGEST dest_offset, |
| 1564 | const gdb_byte *source, ULONGEST source_offset, |
| 1565 | ULONGEST nbits, int bits_big_endian) |
| 1566 | { |
| 1567 | unsigned int buf, avail; |
| 1568 | |
| 1569 | if (nbits == 0) |
| 1570 | return; |
| 1571 | |
| 1572 | if (bits_big_endian) |
| 1573 | { |
| 1574 | /* Start from the end, then work backwards. */ |
| 1575 | dest_offset += nbits - 1; |
| 1576 | dest += dest_offset / 8; |
| 1577 | dest_offset = 7 - dest_offset % 8; |
| 1578 | source_offset += nbits - 1; |
| 1579 | source += source_offset / 8; |
| 1580 | source_offset = 7 - source_offset % 8; |
| 1581 | } |
| 1582 | else |
| 1583 | { |
| 1584 | dest += dest_offset / 8; |
| 1585 | dest_offset %= 8; |
| 1586 | source += source_offset / 8; |
| 1587 | source_offset %= 8; |
| 1588 | } |
| 1589 | |
| 1590 | /* Fill BUF with DEST_OFFSET bits from the destination and 8 - |
| 1591 | SOURCE_OFFSET bits from the source. */ |
| 1592 | buf = *(bits_big_endian ? source-- : source++) >> source_offset; |
| 1593 | buf <<= dest_offset; |
| 1594 | buf |= *dest & ((1 << dest_offset) - 1); |
| 1595 | |
| 1596 | /* NBITS: bits yet to be written; AVAIL: BUF's fill level. */ |
| 1597 | nbits += dest_offset; |
| 1598 | avail = dest_offset + 8 - source_offset; |
| 1599 | |
| 1600 | /* Flush 8 bits from BUF, if appropriate. */ |
| 1601 | if (nbits >= 8 && avail >= 8) |
| 1602 | { |
| 1603 | *(bits_big_endian ? dest-- : dest++) = buf; |
| 1604 | buf >>= 8; |
| 1605 | avail -= 8; |
| 1606 | nbits -= 8; |
| 1607 | } |
| 1608 | |
| 1609 | /* Copy the middle part. */ |
| 1610 | if (nbits >= 8) |
| 1611 | { |
| 1612 | size_t len = nbits / 8; |
| 1613 | |
| 1614 | /* Use a faster method for byte-aligned copies. */ |
| 1615 | if (avail == 0) |
| 1616 | { |
| 1617 | if (bits_big_endian) |
| 1618 | { |
| 1619 | dest -= len; |
| 1620 | source -= len; |
| 1621 | memcpy (dest + 1, source + 1, len); |
| 1622 | } |
| 1623 | else |
| 1624 | { |
| 1625 | memcpy (dest, source, len); |
| 1626 | dest += len; |
| 1627 | source += len; |
| 1628 | } |
| 1629 | } |
| 1630 | else |
| 1631 | { |
| 1632 | while (len--) |
| 1633 | { |
| 1634 | buf |= *(bits_big_endian ? source-- : source++) << avail; |
| 1635 | *(bits_big_endian ? dest-- : dest++) = buf; |
| 1636 | buf >>= 8; |
| 1637 | } |
| 1638 | } |
| 1639 | nbits %= 8; |
| 1640 | } |
| 1641 | |
| 1642 | /* Write the last byte. */ |
| 1643 | if (nbits) |
| 1644 | { |
| 1645 | if (avail < nbits) |
| 1646 | buf |= *source << avail; |
| 1647 | |
| 1648 | buf &= (1 << nbits) - 1; |
| 1649 | *dest = (*dest & (~0 << nbits)) | buf; |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | #if GDB_SELF_TEST |
| 1654 | |
| 1655 | namespace selftests { |
| 1656 | |
| 1657 | /* Helper function for the unit test of copy_bitwise. Convert NBITS bits |
| 1658 | out of BITS, starting at OFFS, to the respective '0'/'1'-string. MSB0 |
| 1659 | specifies whether to assume big endian bit numbering. Store the |
| 1660 | resulting (not null-terminated) string at STR. */ |
| 1661 | |
| 1662 | static void |
| 1663 | bits_to_str (char *str, const gdb_byte *bits, ULONGEST offs, |
| 1664 | ULONGEST nbits, int msb0) |
| 1665 | { |
| 1666 | unsigned int j; |
| 1667 | size_t i; |
| 1668 | |
| 1669 | for (i = offs / 8, j = offs % 8; nbits; i++, j = 0) |
| 1670 | { |
| 1671 | unsigned int ch = bits[i]; |
| 1672 | for (; j < 8 && nbits; j++, nbits--) |
| 1673 | *str++ = (ch & (msb0 ? (1 << (7 - j)) : (1 << j))) ? '1' : '0'; |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | /* Check one invocation of copy_bitwise with the given parameters. */ |
| 1678 | |
| 1679 | static void |
| 1680 | check_copy_bitwise (const gdb_byte *dest, unsigned int dest_offset, |
| 1681 | const gdb_byte *source, unsigned int source_offset, |
| 1682 | unsigned int nbits, int msb0) |
| 1683 | { |
| 1684 | size_t len = align_up (dest_offset + nbits, 8); |
| 1685 | char *expected = (char *) alloca (len + 1); |
| 1686 | char *actual = (char *) alloca (len + 1); |
| 1687 | gdb_byte *buf = (gdb_byte *) alloca (len / 8); |
| 1688 | |
| 1689 | /* Compose a '0'/'1'-string that represents the expected result of |
| 1690 | copy_bitwise below: |
| 1691 | Bits from [0, DEST_OFFSET) are filled from DEST. |
| 1692 | Bits from [DEST_OFFSET, DEST_OFFSET + NBITS) are filled from SOURCE. |
| 1693 | Bits from [DEST_OFFSET + NBITS, LEN) are filled from DEST. |
| 1694 | |
| 1695 | E.g., with: |
| 1696 | dest_offset: 4 |
| 1697 | nbits: 2 |
| 1698 | len: 8 |
| 1699 | dest: 00000000 |
| 1700 | source: 11111111 |
| 1701 | |
| 1702 | We should end up with: |
| 1703 | buf: 00001100 |
| 1704 | DDDDSSDD (D=dest, S=source) |
| 1705 | */ |
| 1706 | bits_to_str (expected, dest, 0, len, msb0); |
| 1707 | bits_to_str (expected + dest_offset, source, source_offset, nbits, msb0); |
| 1708 | |
| 1709 | /* Fill BUF with data from DEST, apply copy_bitwise, and convert the |
| 1710 | result to a '0'/'1'-string. */ |
| 1711 | memcpy (buf, dest, len / 8); |
| 1712 | copy_bitwise (buf, dest_offset, source, source_offset, nbits, msb0); |
| 1713 | bits_to_str (actual, buf, 0, len, msb0); |
| 1714 | |
| 1715 | /* Compare the resulting strings. */ |
| 1716 | expected[len] = actual[len] = '\0'; |
| 1717 | if (strcmp (expected, actual) != 0) |
| 1718 | error (_("copy_bitwise %s != %s (%u+%u -> %u)"), |
| 1719 | expected, actual, source_offset, nbits, dest_offset); |
| 1720 | } |
| 1721 | |
| 1722 | /* Unit test for copy_bitwise. */ |
| 1723 | |
| 1724 | static void |
| 1725 | copy_bitwise_tests (void) |
| 1726 | { |
| 1727 | /* Data to be used as both source and destination buffers. The two |
| 1728 | arrays below represent the lsb0- and msb0- encoded versions of the |
| 1729 | following bit string, respectively: |
| 1730 | 00000000 00011111 11111111 01001000 10100101 11110010 |
| 1731 | This pattern is chosen such that it contains: |
| 1732 | - constant 0- and 1- chunks of more than a full byte; |
| 1733 | - 0/1- and 1/0 transitions on all bit positions within a byte; |
| 1734 | - several sufficiently asymmetric bytes. |
| 1735 | */ |
| 1736 | static const gdb_byte data_lsb0[] = { |
| 1737 | 0x00, 0xf8, 0xff, 0x12, 0xa5, 0x4f |
| 1738 | }; |
| 1739 | static const gdb_byte data_msb0[] = { |
| 1740 | 0x00, 0x1f, 0xff, 0x48, 0xa5, 0xf2 |
| 1741 | }; |
| 1742 | |
| 1743 | constexpr size_t data_nbits = 8 * sizeof (data_lsb0); |
| 1744 | constexpr unsigned max_nbits = 24; |
| 1745 | |
| 1746 | /* Try all combinations of: |
| 1747 | lsb0/msb0 bit order (using the respective data array) |
| 1748 | X [0, MAX_NBITS] copy bit width |
| 1749 | X feasible source offsets for the given copy bit width |
| 1750 | X feasible destination offsets |
| 1751 | */ |
| 1752 | for (int msb0 = 0; msb0 < 2; msb0++) |
| 1753 | { |
| 1754 | const gdb_byte *data = msb0 ? data_msb0 : data_lsb0; |
| 1755 | |
| 1756 | for (unsigned int nbits = 1; nbits <= max_nbits; nbits++) |
| 1757 | { |
| 1758 | const unsigned int max_offset = data_nbits - nbits; |
| 1759 | |
| 1760 | for (unsigned source_offset = 0; |
| 1761 | source_offset <= max_offset; |
| 1762 | source_offset++) |
| 1763 | { |
| 1764 | for (unsigned dest_offset = 0; |
| 1765 | dest_offset <= max_offset; |
| 1766 | dest_offset++) |
| 1767 | { |
| 1768 | check_copy_bitwise (data + dest_offset / 8, |
| 1769 | dest_offset % 8, |
| 1770 | data + source_offset / 8, |
| 1771 | source_offset % 8, |
| 1772 | nbits, msb0); |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | /* Special cases: copy all, copy nothing. */ |
| 1778 | check_copy_bitwise (data_lsb0, 0, data_msb0, 0, data_nbits, msb0); |
| 1779 | check_copy_bitwise (data_msb0, 0, data_lsb0, 0, data_nbits, msb0); |
| 1780 | check_copy_bitwise (data, data_nbits - 7, data, 9, 0, msb0); |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | } /* namespace selftests */ |
| 1785 | |
| 1786 | #endif /* GDB_SELF_TEST */ |
| 1787 | |
| 1788 | /* Return the number of bytes overlapping a contiguous chunk of N_BITS |
| 1789 | bits whose first bit is located at bit offset START. */ |
| 1790 | |
| 1791 | static size_t |
| 1792 | bits_to_bytes (ULONGEST start, ULONGEST n_bits) |
| 1793 | { |
| 1794 | return (start % 8 + n_bits + 7) / 8; |
| 1795 | } |
| 1796 | |
| 1797 | /* Read or write a pieced value V. If FROM != NULL, operate in "write |
| 1798 | mode": copy FROM into the pieces comprising V. If FROM == NULL, |
| 1799 | operate in "read mode": fetch the contents of the (lazy) value V by |
| 1800 | composing it from its pieces. */ |
| 1801 | |
| 1802 | static void |
| 1803 | rw_pieced_value (struct value *v, struct value *from) |
| 1804 | { |
| 1805 | int i; |
| 1806 | LONGEST offset = 0, max_offset; |
| 1807 | ULONGEST bits_to_skip; |
| 1808 | gdb_byte *v_contents; |
| 1809 | const gdb_byte *from_contents; |
| 1810 | struct piece_closure *c |
| 1811 | = (struct piece_closure *) value_computed_closure (v); |
| 1812 | gdb::byte_vector buffer; |
| 1813 | int bits_big_endian |
| 1814 | = gdbarch_bits_big_endian (get_type_arch (value_type (v))); |
| 1815 | |
| 1816 | if (from != NULL) |
| 1817 | { |
| 1818 | from_contents = value_contents (from); |
| 1819 | v_contents = NULL; |
| 1820 | } |
| 1821 | else |
| 1822 | { |
| 1823 | if (value_type (v) != value_enclosing_type (v)) |
| 1824 | internal_error (__FILE__, __LINE__, |
| 1825 | _("Should not be able to create a lazy value with " |
| 1826 | "an enclosing type")); |
| 1827 | v_contents = value_contents_raw (v); |
| 1828 | from_contents = NULL; |
| 1829 | } |
| 1830 | |
| 1831 | bits_to_skip = 8 * value_offset (v); |
| 1832 | if (value_bitsize (v)) |
| 1833 | { |
| 1834 | bits_to_skip += (8 * value_offset (value_parent (v)) |
| 1835 | + value_bitpos (v)); |
| 1836 | if (from != NULL |
| 1837 | && (gdbarch_byte_order (get_type_arch (value_type (from))) |
| 1838 | == BFD_ENDIAN_BIG)) |
| 1839 | { |
| 1840 | /* Use the least significant bits of FROM. */ |
| 1841 | max_offset = 8 * TYPE_LENGTH (value_type (from)); |
| 1842 | offset = max_offset - value_bitsize (v); |
| 1843 | } |
| 1844 | else |
| 1845 | max_offset = value_bitsize (v); |
| 1846 | } |
| 1847 | else |
| 1848 | max_offset = 8 * TYPE_LENGTH (value_type (v)); |
| 1849 | |
| 1850 | /* Advance to the first non-skipped piece. */ |
| 1851 | for (i = 0; i < c->pieces.size () && bits_to_skip >= c->pieces[i].size; i++) |
| 1852 | bits_to_skip -= c->pieces[i].size; |
| 1853 | |
| 1854 | for (; i < c->pieces.size () && offset < max_offset; i++) |
| 1855 | { |
| 1856 | struct dwarf_expr_piece *p = &c->pieces[i]; |
| 1857 | size_t this_size_bits, this_size; |
| 1858 | |
| 1859 | this_size_bits = p->size - bits_to_skip; |
| 1860 | if (this_size_bits > max_offset - offset) |
| 1861 | this_size_bits = max_offset - offset; |
| 1862 | |
| 1863 | switch (p->location) |
| 1864 | { |
| 1865 | case DWARF_VALUE_REGISTER: |
| 1866 | { |
| 1867 | struct frame_info *frame = frame_find_by_id (c->frame_id); |
| 1868 | struct gdbarch *arch = get_frame_arch (frame); |
| 1869 | int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, p->v.regno); |
| 1870 | ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum); |
| 1871 | int optim, unavail; |
| 1872 | |
| 1873 | if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG |
| 1874 | && p->offset + p->size < reg_bits) |
| 1875 | { |
| 1876 | /* Big-endian, and we want less than full size. */ |
| 1877 | bits_to_skip += reg_bits - (p->offset + p->size); |
| 1878 | } |
| 1879 | else |
| 1880 | bits_to_skip += p->offset; |
| 1881 | |
| 1882 | this_size = bits_to_bytes (bits_to_skip, this_size_bits); |
| 1883 | buffer.resize (this_size); |
| 1884 | |
| 1885 | if (from == NULL) |
| 1886 | { |
| 1887 | /* Read mode. */ |
| 1888 | if (!get_frame_register_bytes (frame, gdb_regnum, |
| 1889 | bits_to_skip / 8, |
| 1890 | this_size, buffer.data (), |
| 1891 | &optim, &unavail)) |
| 1892 | { |
| 1893 | if (optim) |
| 1894 | mark_value_bits_optimized_out (v, offset, |
| 1895 | this_size_bits); |
| 1896 | if (unavail) |
| 1897 | mark_value_bits_unavailable (v, offset, |
| 1898 | this_size_bits); |
| 1899 | break; |
| 1900 | } |
| 1901 | |
| 1902 | copy_bitwise (v_contents, offset, |
| 1903 | buffer.data (), bits_to_skip % 8, |
| 1904 | this_size_bits, bits_big_endian); |
| 1905 | } |
| 1906 | else |
| 1907 | { |
| 1908 | /* Write mode. */ |
| 1909 | if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) |
| 1910 | { |
| 1911 | /* Data is copied non-byte-aligned into the register. |
| 1912 | Need some bits from original register value. */ |
| 1913 | get_frame_register_bytes (frame, gdb_regnum, |
| 1914 | bits_to_skip / 8, |
| 1915 | this_size, buffer.data (), |
| 1916 | &optim, &unavail); |
| 1917 | if (optim) |
| 1918 | throw_error (OPTIMIZED_OUT_ERROR, |
| 1919 | _("Can't do read-modify-write to " |
| 1920 | "update bitfield; containing word " |
| 1921 | "has been optimized out")); |
| 1922 | if (unavail) |
| 1923 | throw_error (NOT_AVAILABLE_ERROR, |
| 1924 | _("Can't do read-modify-write to " |
| 1925 | "update bitfield; containing word " |
| 1926 | "is unavailable")); |
| 1927 | } |
| 1928 | |
| 1929 | copy_bitwise (buffer.data (), bits_to_skip % 8, |
| 1930 | from_contents, offset, |
| 1931 | this_size_bits, bits_big_endian); |
| 1932 | put_frame_register_bytes (frame, gdb_regnum, |
| 1933 | bits_to_skip / 8, |
| 1934 | this_size, buffer.data ()); |
| 1935 | } |
| 1936 | } |
| 1937 | break; |
| 1938 | |
| 1939 | case DWARF_VALUE_MEMORY: |
| 1940 | { |
| 1941 | bits_to_skip += p->offset; |
| 1942 | |
| 1943 | CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8; |
| 1944 | |
| 1945 | if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0 |
| 1946 | && offset % 8 == 0) |
| 1947 | { |
| 1948 | /* Everything is byte-aligned; no buffer needed. */ |
| 1949 | if (from != NULL) |
| 1950 | write_memory_with_notification (start_addr, |
| 1951 | (from_contents |
| 1952 | + offset / 8), |
| 1953 | this_size_bits / 8); |
| 1954 | else |
| 1955 | read_value_memory (v, offset, |
| 1956 | p->v.mem.in_stack_memory, |
| 1957 | p->v.mem.addr + bits_to_skip / 8, |
| 1958 | v_contents + offset / 8, |
| 1959 | this_size_bits / 8); |
| 1960 | break; |
| 1961 | } |
| 1962 | |
| 1963 | this_size = bits_to_bytes (bits_to_skip, this_size_bits); |
| 1964 | buffer.resize (this_size); |
| 1965 | |
| 1966 | if (from == NULL) |
| 1967 | { |
| 1968 | /* Read mode. */ |
| 1969 | read_value_memory (v, offset, |
| 1970 | p->v.mem.in_stack_memory, |
| 1971 | p->v.mem.addr + bits_to_skip / 8, |
| 1972 | buffer.data (), this_size); |
| 1973 | copy_bitwise (v_contents, offset, |
| 1974 | buffer.data (), bits_to_skip % 8, |
| 1975 | this_size_bits, bits_big_endian); |
| 1976 | } |
| 1977 | else |
| 1978 | { |
| 1979 | /* Write mode. */ |
| 1980 | if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) |
| 1981 | { |
| 1982 | if (this_size <= 8) |
| 1983 | { |
| 1984 | /* Perform a single read for small sizes. */ |
| 1985 | read_memory (start_addr, buffer.data (), |
| 1986 | this_size); |
| 1987 | } |
| 1988 | else |
| 1989 | { |
| 1990 | /* Only the first and last bytes can possibly have |
| 1991 | any bits reused. */ |
| 1992 | read_memory (start_addr, buffer.data (), 1); |
| 1993 | read_memory (start_addr + this_size - 1, |
| 1994 | &buffer[this_size - 1], 1); |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | copy_bitwise (buffer.data (), bits_to_skip % 8, |
| 1999 | from_contents, offset, |
| 2000 | this_size_bits, bits_big_endian); |
| 2001 | write_memory_with_notification (start_addr, |
| 2002 | buffer.data (), |
| 2003 | this_size); |
| 2004 | } |
| 2005 | } |
| 2006 | break; |
| 2007 | |
| 2008 | case DWARF_VALUE_STACK: |
| 2009 | { |
| 2010 | if (from != NULL) |
| 2011 | { |
| 2012 | mark_value_bits_optimized_out (v, offset, this_size_bits); |
| 2013 | break; |
| 2014 | } |
| 2015 | |
| 2016 | struct objfile *objfile = dwarf2_per_cu_objfile (c->per_cu); |
| 2017 | struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile); |
| 2018 | ULONGEST stack_value_size_bits |
| 2019 | = 8 * TYPE_LENGTH (value_type (p->v.value)); |
| 2020 | |
| 2021 | /* Use zeroes if piece reaches beyond stack value. */ |
| 2022 | if (p->offset + p->size > stack_value_size_bits) |
| 2023 | break; |
| 2024 | |
| 2025 | /* Piece is anchored at least significant bit end. */ |
| 2026 | if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG) |
| 2027 | bits_to_skip += stack_value_size_bits - p->offset - p->size; |
| 2028 | else |
| 2029 | bits_to_skip += p->offset; |
| 2030 | |
| 2031 | copy_bitwise (v_contents, offset, |
| 2032 | value_contents_all (p->v.value), |
| 2033 | bits_to_skip, |
| 2034 | this_size_bits, bits_big_endian); |
| 2035 | } |
| 2036 | break; |
| 2037 | |
| 2038 | case DWARF_VALUE_LITERAL: |
| 2039 | { |
| 2040 | if (from != NULL) |
| 2041 | { |
| 2042 | mark_value_bits_optimized_out (v, offset, this_size_bits); |
| 2043 | break; |
| 2044 | } |
| 2045 | |
| 2046 | ULONGEST literal_size_bits = 8 * p->v.literal.length; |
| 2047 | size_t n = this_size_bits; |
| 2048 | |
| 2049 | /* Cut off at the end of the implicit value. */ |
| 2050 | bits_to_skip += p->offset; |
| 2051 | if (bits_to_skip >= literal_size_bits) |
| 2052 | break; |
| 2053 | if (n > literal_size_bits - bits_to_skip) |
| 2054 | n = literal_size_bits - bits_to_skip; |
| 2055 | |
| 2056 | copy_bitwise (v_contents, offset, |
| 2057 | p->v.literal.data, bits_to_skip, |
| 2058 | n, bits_big_endian); |
| 2059 | } |
| 2060 | break; |
| 2061 | |
| 2062 | case DWARF_VALUE_IMPLICIT_POINTER: |
| 2063 | if (from != NULL) |
| 2064 | { |
| 2065 | mark_value_bits_optimized_out (v, offset, this_size_bits); |
| 2066 | break; |
| 2067 | } |
| 2068 | |
| 2069 | /* These bits show up as zeros -- but do not cause the value to |
| 2070 | be considered optimized-out. */ |
| 2071 | break; |
| 2072 | |
| 2073 | case DWARF_VALUE_OPTIMIZED_OUT: |
| 2074 | mark_value_bits_optimized_out (v, offset, this_size_bits); |
| 2075 | break; |
| 2076 | |
| 2077 | default: |
| 2078 | internal_error (__FILE__, __LINE__, _("invalid location type")); |
| 2079 | } |
| 2080 | |
| 2081 | offset += this_size_bits; |
| 2082 | bits_to_skip = 0; |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | static void |
| 2088 | read_pieced_value (struct value *v) |
| 2089 | { |
| 2090 | rw_pieced_value (v, NULL); |
| 2091 | } |
| 2092 | |
| 2093 | static void |
| 2094 | write_pieced_value (struct value *to, struct value *from) |
| 2095 | { |
| 2096 | rw_pieced_value (to, from); |
| 2097 | } |
| 2098 | |
| 2099 | /* An implementation of an lval_funcs method to see whether a value is |
| 2100 | a synthetic pointer. */ |
| 2101 | |
| 2102 | static int |
| 2103 | check_pieced_synthetic_pointer (const struct value *value, LONGEST bit_offset, |
| 2104 | int bit_length) |
| 2105 | { |
| 2106 | struct piece_closure *c |
| 2107 | = (struct piece_closure *) value_computed_closure (value); |
| 2108 | int i; |
| 2109 | |
| 2110 | bit_offset += 8 * value_offset (value); |
| 2111 | if (value_bitsize (value)) |
| 2112 | bit_offset += value_bitpos (value); |
| 2113 | |
| 2114 | for (i = 0; i < c->pieces.size () && bit_length > 0; i++) |
| 2115 | { |
| 2116 | struct dwarf_expr_piece *p = &c->pieces[i]; |
| 2117 | size_t this_size_bits = p->size; |
| 2118 | |
| 2119 | if (bit_offset > 0) |
| 2120 | { |
| 2121 | if (bit_offset >= this_size_bits) |
| 2122 | { |
| 2123 | bit_offset -= this_size_bits; |
| 2124 | continue; |
| 2125 | } |
| 2126 | |
| 2127 | bit_length -= this_size_bits - bit_offset; |
| 2128 | bit_offset = 0; |
| 2129 | } |
| 2130 | else |
| 2131 | bit_length -= this_size_bits; |
| 2132 | |
| 2133 | if (p->location != DWARF_VALUE_IMPLICIT_POINTER) |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
| 2137 | return 1; |
| 2138 | } |
| 2139 | |
| 2140 | /* A wrapper function for get_frame_address_in_block. */ |
| 2141 | |
| 2142 | static CORE_ADDR |
| 2143 | get_frame_address_in_block_wrapper (void *baton) |
| 2144 | { |
| 2145 | return get_frame_address_in_block ((struct frame_info *) baton); |
| 2146 | } |
| 2147 | |
| 2148 | /* Fetch a DW_AT_const_value through a synthetic pointer. */ |
| 2149 | |
| 2150 | static struct value * |
| 2151 | fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset, |
| 2152 | struct dwarf2_per_cu_data *per_cu, |
| 2153 | struct type *type) |
| 2154 | { |
| 2155 | struct value *result = NULL; |
| 2156 | const gdb_byte *bytes; |
| 2157 | LONGEST len; |
| 2158 | |
| 2159 | auto_obstack temp_obstack; |
| 2160 | bytes = dwarf2_fetch_constant_bytes (die, per_cu, &temp_obstack, &len); |
| 2161 | |
| 2162 | if (bytes != NULL) |
| 2163 | { |
| 2164 | if (byte_offset >= 0 |
| 2165 | && byte_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)) <= len) |
| 2166 | { |
| 2167 | bytes += byte_offset; |
| 2168 | result = value_from_contents (TYPE_TARGET_TYPE (type), bytes); |
| 2169 | } |
| 2170 | else |
| 2171 | invalid_synthetic_pointer (); |
| 2172 | } |
| 2173 | else |
| 2174 | result = allocate_optimized_out_value (TYPE_TARGET_TYPE (type)); |
| 2175 | |
| 2176 | return result; |
| 2177 | } |
| 2178 | |
| 2179 | /* Fetch the value pointed to by a synthetic pointer. */ |
| 2180 | |
| 2181 | static struct value * |
| 2182 | indirect_synthetic_pointer (sect_offset die, LONGEST byte_offset, |
| 2183 | struct dwarf2_per_cu_data *per_cu, |
| 2184 | struct frame_info *frame, struct type *type, |
| 2185 | bool resolve_abstract_p) |
| 2186 | { |
| 2187 | /* Fetch the location expression of the DIE we're pointing to. */ |
| 2188 | struct dwarf2_locexpr_baton baton |
| 2189 | = dwarf2_fetch_die_loc_sect_off (die, per_cu, |
| 2190 | get_frame_address_in_block_wrapper, frame, |
| 2191 | resolve_abstract_p); |
| 2192 | |
| 2193 | /* Get type of pointed-to DIE. */ |
| 2194 | struct type *orig_type = dwarf2_fetch_die_type_sect_off (die, per_cu); |
| 2195 | if (orig_type == NULL) |
| 2196 | invalid_synthetic_pointer (); |
| 2197 | |
| 2198 | /* If pointed-to DIE has a DW_AT_location, evaluate it and return the |
| 2199 | resulting value. Otherwise, it may have a DW_AT_const_value instead, |
| 2200 | or it may've been optimized out. */ |
| 2201 | if (baton.data != NULL) |
| 2202 | return dwarf2_evaluate_loc_desc_full (orig_type, frame, baton.data, |
| 2203 | baton.size, baton.per_cu, |
| 2204 | TYPE_TARGET_TYPE (type), |
| 2205 | byte_offset); |
| 2206 | else |
| 2207 | return fetch_const_value_from_synthetic_pointer (die, byte_offset, per_cu, |
| 2208 | type); |
| 2209 | } |
| 2210 | |
| 2211 | /* An implementation of an lval_funcs method to indirect through a |
| 2212 | pointer. This handles the synthetic pointer case when needed. */ |
| 2213 | |
| 2214 | static struct value * |
| 2215 | indirect_pieced_value (struct value *value) |
| 2216 | { |
| 2217 | struct piece_closure *c |
| 2218 | = (struct piece_closure *) value_computed_closure (value); |
| 2219 | struct type *type; |
| 2220 | struct frame_info *frame; |
| 2221 | int i, bit_length; |
| 2222 | LONGEST bit_offset; |
| 2223 | struct dwarf_expr_piece *piece = NULL; |
| 2224 | LONGEST byte_offset; |
| 2225 | enum bfd_endian byte_order; |
| 2226 | |
| 2227 | type = check_typedef (value_type (value)); |
| 2228 | if (TYPE_CODE (type) != TYPE_CODE_PTR) |
| 2229 | return NULL; |
| 2230 | |
| 2231 | bit_length = 8 * TYPE_LENGTH (type); |
| 2232 | bit_offset = 8 * value_offset (value); |
| 2233 | if (value_bitsize (value)) |
| 2234 | bit_offset += value_bitpos (value); |
| 2235 | |
| 2236 | for (i = 0; i < c->pieces.size () && bit_length > 0; i++) |
| 2237 | { |
| 2238 | struct dwarf_expr_piece *p = &c->pieces[i]; |
| 2239 | size_t this_size_bits = p->size; |
| 2240 | |
| 2241 | if (bit_offset > 0) |
| 2242 | { |
| 2243 | if (bit_offset >= this_size_bits) |
| 2244 | { |
| 2245 | bit_offset -= this_size_bits; |
| 2246 | continue; |
| 2247 | } |
| 2248 | |
| 2249 | bit_length -= this_size_bits - bit_offset; |
| 2250 | bit_offset = 0; |
| 2251 | } |
| 2252 | else |
| 2253 | bit_length -= this_size_bits; |
| 2254 | |
| 2255 | if (p->location != DWARF_VALUE_IMPLICIT_POINTER) |
| 2256 | return NULL; |
| 2257 | |
| 2258 | if (bit_length != 0) |
| 2259 | error (_("Invalid use of DW_OP_implicit_pointer")); |
| 2260 | |
| 2261 | piece = p; |
| 2262 | break; |
| 2263 | } |
| 2264 | |
| 2265 | gdb_assert (piece != NULL); |
| 2266 | frame = get_selected_frame (_("No frame selected.")); |
| 2267 | |
| 2268 | /* This is an offset requested by GDB, such as value subscripts. |
| 2269 | However, due to how synthetic pointers are implemented, this is |
| 2270 | always presented to us as a pointer type. This means we have to |
| 2271 | sign-extend it manually as appropriate. Use raw |
| 2272 | extract_signed_integer directly rather than value_as_address and |
| 2273 | sign extend afterwards on architectures that would need it |
| 2274 | (mostly everywhere except MIPS, which has signed addresses) as |
| 2275 | the later would go through gdbarch_pointer_to_address and thus |
| 2276 | return a CORE_ADDR with high bits set on architectures that |
| 2277 | encode address spaces and other things in CORE_ADDR. */ |
| 2278 | byte_order = gdbarch_byte_order (get_frame_arch (frame)); |
| 2279 | byte_offset = extract_signed_integer (value_contents (value), |
| 2280 | TYPE_LENGTH (type), byte_order); |
| 2281 | byte_offset += piece->v.ptr.offset; |
| 2282 | |
| 2283 | return indirect_synthetic_pointer (piece->v.ptr.die_sect_off, |
| 2284 | byte_offset, c->per_cu, |
| 2285 | frame, type); |
| 2286 | } |
| 2287 | |
| 2288 | /* Implementation of the coerce_ref method of lval_funcs for synthetic C++ |
| 2289 | references. */ |
| 2290 | |
| 2291 | static struct value * |
| 2292 | coerce_pieced_ref (const struct value *value) |
| 2293 | { |
| 2294 | struct type *type = check_typedef (value_type (value)); |
| 2295 | |
| 2296 | if (value_bits_synthetic_pointer (value, value_embedded_offset (value), |
| 2297 | TARGET_CHAR_BIT * TYPE_LENGTH (type))) |
| 2298 | { |
| 2299 | const struct piece_closure *closure |
| 2300 | = (struct piece_closure *) value_computed_closure (value); |
| 2301 | struct frame_info *frame |
| 2302 | = get_selected_frame (_("No frame selected.")); |
| 2303 | |
| 2304 | /* gdb represents synthetic pointers as pieced values with a single |
| 2305 | piece. */ |
| 2306 | gdb_assert (closure != NULL); |
| 2307 | gdb_assert (closure->pieces.size () == 1); |
| 2308 | |
| 2309 | return indirect_synthetic_pointer |
| 2310 | (closure->pieces[0].v.ptr.die_sect_off, |
| 2311 | closure->pieces[0].v.ptr.offset, |
| 2312 | closure->per_cu, frame, type); |
| 2313 | } |
| 2314 | else |
| 2315 | { |
| 2316 | /* Else: not a synthetic reference; do nothing. */ |
| 2317 | return NULL; |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | static void * |
| 2322 | copy_pieced_value_closure (const struct value *v) |
| 2323 | { |
| 2324 | struct piece_closure *c |
| 2325 | = (struct piece_closure *) value_computed_closure (v); |
| 2326 | |
| 2327 | ++c->refc; |
| 2328 | return c; |
| 2329 | } |
| 2330 | |
| 2331 | static void |
| 2332 | free_pieced_value_closure (struct value *v) |
| 2333 | { |
| 2334 | struct piece_closure *c |
| 2335 | = (struct piece_closure *) value_computed_closure (v); |
| 2336 | |
| 2337 | --c->refc; |
| 2338 | if (c->refc == 0) |
| 2339 | { |
| 2340 | for (dwarf_expr_piece &p : c->pieces) |
| 2341 | if (p.location == DWARF_VALUE_STACK) |
| 2342 | value_decref (p.v.value); |
| 2343 | |
| 2344 | delete c; |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | /* Functions for accessing a variable described by DW_OP_piece. */ |
| 2349 | static const struct lval_funcs pieced_value_funcs = { |
| 2350 | read_pieced_value, |
| 2351 | write_pieced_value, |
| 2352 | indirect_pieced_value, |
| 2353 | coerce_pieced_ref, |
| 2354 | check_pieced_synthetic_pointer, |
| 2355 | copy_pieced_value_closure, |
| 2356 | free_pieced_value_closure |
| 2357 | }; |
| 2358 | |
| 2359 | /* Evaluate a location description, starting at DATA and with length |
| 2360 | SIZE, to find the current location of variable of TYPE in the |
| 2361 | context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the |
| 2362 | location of the subobject of type SUBOBJ_TYPE at byte offset |
| 2363 | SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */ |
| 2364 | |
| 2365 | static struct value * |
| 2366 | dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, |
| 2367 | const gdb_byte *data, size_t size, |
| 2368 | struct dwarf2_per_cu_data *per_cu, |
| 2369 | struct type *subobj_type, |
| 2370 | LONGEST subobj_byte_offset) |
| 2371 | { |
| 2372 | struct value *retval; |
| 2373 | struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); |
| 2374 | |
| 2375 | if (subobj_type == NULL) |
| 2376 | { |
| 2377 | subobj_type = type; |
| 2378 | subobj_byte_offset = 0; |
| 2379 | } |
| 2380 | else if (subobj_byte_offset < 0) |
| 2381 | invalid_synthetic_pointer (); |
| 2382 | |
| 2383 | if (size == 0) |
| 2384 | return allocate_optimized_out_value (subobj_type); |
| 2385 | |
| 2386 | dwarf_evaluate_loc_desc ctx; |
| 2387 | ctx.frame = frame; |
| 2388 | ctx.per_cu = per_cu; |
| 2389 | ctx.obj_address = 0; |
| 2390 | |
| 2391 | scoped_value_mark free_values; |
| 2392 | |
| 2393 | ctx.gdbarch = get_objfile_arch (objfile); |
| 2394 | ctx.addr_size = dwarf2_per_cu_addr_size (per_cu); |
| 2395 | ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu); |
| 2396 | ctx.offset = dwarf2_per_cu_text_offset (per_cu); |
| 2397 | |
| 2398 | TRY |
| 2399 | { |
| 2400 | ctx.eval (data, size); |
| 2401 | } |
| 2402 | CATCH (ex, RETURN_MASK_ERROR) |
| 2403 | { |
| 2404 | if (ex.error == NOT_AVAILABLE_ERROR) |
| 2405 | { |
| 2406 | free_values.free_to_mark (); |
| 2407 | retval = allocate_value (subobj_type); |
| 2408 | mark_value_bytes_unavailable (retval, 0, |
| 2409 | TYPE_LENGTH (subobj_type)); |
| 2410 | return retval; |
| 2411 | } |
| 2412 | else if (ex.error == NO_ENTRY_VALUE_ERROR) |
| 2413 | { |
| 2414 | if (entry_values_debug) |
| 2415 | exception_print (gdb_stdout, ex); |
| 2416 | free_values.free_to_mark (); |
| 2417 | return allocate_optimized_out_value (subobj_type); |
| 2418 | } |
| 2419 | else |
| 2420 | throw_exception (ex); |
| 2421 | } |
| 2422 | END_CATCH |
| 2423 | |
| 2424 | if (ctx.pieces.size () > 0) |
| 2425 | { |
| 2426 | struct piece_closure *c; |
| 2427 | ULONGEST bit_size = 0; |
| 2428 | |
| 2429 | for (dwarf_expr_piece &piece : ctx.pieces) |
| 2430 | bit_size += piece.size; |
| 2431 | /* Complain if the expression is larger than the size of the |
| 2432 | outer type. */ |
| 2433 | if (bit_size > 8 * TYPE_LENGTH (type)) |
| 2434 | invalid_synthetic_pointer (); |
| 2435 | |
| 2436 | c = allocate_piece_closure (per_cu, std::move (ctx.pieces), frame); |
| 2437 | /* We must clean up the value chain after creating the piece |
| 2438 | closure but before allocating the result. */ |
| 2439 | free_values.free_to_mark (); |
| 2440 | retval = allocate_computed_value (subobj_type, |
| 2441 | &pieced_value_funcs, c); |
| 2442 | set_value_offset (retval, subobj_byte_offset); |
| 2443 | } |
| 2444 | else |
| 2445 | { |
| 2446 | switch (ctx.location) |
| 2447 | { |
| 2448 | case DWARF_VALUE_REGISTER: |
| 2449 | { |
| 2450 | struct gdbarch *arch = get_frame_arch (frame); |
| 2451 | int dwarf_regnum |
| 2452 | = longest_to_int (value_as_long (ctx.fetch (0))); |
| 2453 | int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, dwarf_regnum); |
| 2454 | |
| 2455 | if (subobj_byte_offset != 0) |
| 2456 | error (_("cannot use offset on synthetic pointer to register")); |
| 2457 | free_values.free_to_mark (); |
| 2458 | retval = value_from_register (subobj_type, gdb_regnum, frame); |
| 2459 | if (value_optimized_out (retval)) |
| 2460 | { |
| 2461 | struct value *tmp; |
| 2462 | |
| 2463 | /* This means the register has undefined value / was |
| 2464 | not saved. As we're computing the location of some |
| 2465 | variable etc. in the program, not a value for |
| 2466 | inspecting a register ($pc, $sp, etc.), return a |
| 2467 | generic optimized out value instead, so that we show |
| 2468 | <optimized out> instead of <not saved>. */ |
| 2469 | tmp = allocate_value (subobj_type); |
| 2470 | value_contents_copy (tmp, 0, retval, 0, |
| 2471 | TYPE_LENGTH (subobj_type)); |
| 2472 | retval = tmp; |
| 2473 | } |
| 2474 | } |
| 2475 | break; |
| 2476 | |
| 2477 | case DWARF_VALUE_MEMORY: |
| 2478 | { |
| 2479 | struct type *ptr_type; |
| 2480 | CORE_ADDR address = ctx.fetch_address (0); |
| 2481 | bool in_stack_memory = ctx.fetch_in_stack_memory (0); |
| 2482 | |
| 2483 | /* DW_OP_deref_size (and possibly other operations too) may |
| 2484 | create a pointer instead of an address. Ideally, the |
| 2485 | pointer to address conversion would be performed as part |
| 2486 | of those operations, but the type of the object to |
| 2487 | which the address refers is not known at the time of |
| 2488 | the operation. Therefore, we do the conversion here |
| 2489 | since the type is readily available. */ |
| 2490 | |
| 2491 | switch (TYPE_CODE (subobj_type)) |
| 2492 | { |
| 2493 | case TYPE_CODE_FUNC: |
| 2494 | case TYPE_CODE_METHOD: |
| 2495 | ptr_type = builtin_type (ctx.gdbarch)->builtin_func_ptr; |
| 2496 | break; |
| 2497 | default: |
| 2498 | ptr_type = builtin_type (ctx.gdbarch)->builtin_data_ptr; |
| 2499 | break; |
| 2500 | } |
| 2501 | address = value_as_address (value_from_pointer (ptr_type, address)); |
| 2502 | |
| 2503 | free_values.free_to_mark (); |
| 2504 | retval = value_at_lazy (subobj_type, |
| 2505 | address + subobj_byte_offset); |
| 2506 | if (in_stack_memory) |
| 2507 | set_value_stack (retval, 1); |
| 2508 | } |
| 2509 | break; |
| 2510 | |
| 2511 | case DWARF_VALUE_STACK: |
| 2512 | { |
| 2513 | struct value *value = ctx.fetch (0); |
| 2514 | size_t n = TYPE_LENGTH (value_type (value)); |
| 2515 | size_t len = TYPE_LENGTH (subobj_type); |
| 2516 | size_t max = TYPE_LENGTH (type); |
| 2517 | struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile); |
| 2518 | |
| 2519 | if (subobj_byte_offset + len > max) |
| 2520 | invalid_synthetic_pointer (); |
| 2521 | |
| 2522 | /* Preserve VALUE because we are going to free values back |
| 2523 | to the mark, but we still need the value contents |
| 2524 | below. */ |
| 2525 | value_ref_ptr value_holder = value_ref_ptr::new_reference (value); |
| 2526 | free_values.free_to_mark (); |
| 2527 | |
| 2528 | retval = allocate_value (subobj_type); |
| 2529 | |
| 2530 | /* The given offset is relative to the actual object. */ |
| 2531 | if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG) |
| 2532 | subobj_byte_offset += n - max; |
| 2533 | |
| 2534 | memcpy (value_contents_raw (retval), |
| 2535 | value_contents_all (value) + subobj_byte_offset, len); |
| 2536 | } |
| 2537 | break; |
| 2538 | |
| 2539 | case DWARF_VALUE_LITERAL: |
| 2540 | { |
| 2541 | bfd_byte *contents; |
| 2542 | size_t n = TYPE_LENGTH (subobj_type); |
| 2543 | |
| 2544 | if (subobj_byte_offset + n > ctx.len) |
| 2545 | invalid_synthetic_pointer (); |
| 2546 | |
| 2547 | free_values.free_to_mark (); |
| 2548 | retval = allocate_value (subobj_type); |
| 2549 | contents = value_contents_raw (retval); |
| 2550 | memcpy (contents, ctx.data + subobj_byte_offset, n); |
| 2551 | } |
| 2552 | break; |
| 2553 | |
| 2554 | case DWARF_VALUE_OPTIMIZED_OUT: |
| 2555 | free_values.free_to_mark (); |
| 2556 | retval = allocate_optimized_out_value (subobj_type); |
| 2557 | break; |
| 2558 | |
| 2559 | /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced |
| 2560 | operation by execute_stack_op. */ |
| 2561 | case DWARF_VALUE_IMPLICIT_POINTER: |
| 2562 | /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context -- |
| 2563 | it can only be encountered when making a piece. */ |
| 2564 | default: |
| 2565 | internal_error (__FILE__, __LINE__, _("invalid location type")); |
| 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | set_value_initialized (retval, ctx.initialized); |
| 2570 | |
| 2571 | return retval; |
| 2572 | } |
| 2573 | |
| 2574 | /* The exported interface to dwarf2_evaluate_loc_desc_full; it always |
| 2575 | passes 0 as the byte_offset. */ |
| 2576 | |
| 2577 | struct value * |
| 2578 | dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame, |
| 2579 | const gdb_byte *data, size_t size, |
| 2580 | struct dwarf2_per_cu_data *per_cu) |
| 2581 | { |
| 2582 | return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu, |
| 2583 | NULL, 0); |
| 2584 | } |
| 2585 | |
| 2586 | /* Evaluates a dwarf expression and stores the result in VAL, expecting |
| 2587 | that the dwarf expression only produces a single CORE_ADDR. FRAME is the |
| 2588 | frame in which the expression is evaluated. ADDR is a context (location of |
| 2589 | a variable) and might be needed to evaluate the location expression. |
| 2590 | Returns 1 on success, 0 otherwise. */ |
| 2591 | |
| 2592 | static int |
| 2593 | dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, |
| 2594 | struct frame_info *frame, |
| 2595 | CORE_ADDR addr, |
| 2596 | CORE_ADDR *valp) |
| 2597 | { |
| 2598 | struct objfile *objfile; |
| 2599 | |
| 2600 | if (dlbaton == NULL || dlbaton->size == 0) |
| 2601 | return 0; |
| 2602 | |
| 2603 | dwarf_evaluate_loc_desc ctx; |
| 2604 | |
| 2605 | ctx.frame = frame; |
| 2606 | ctx.per_cu = dlbaton->per_cu; |
| 2607 | ctx.obj_address = addr; |
| 2608 | |
| 2609 | objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); |
| 2610 | |
| 2611 | ctx.gdbarch = get_objfile_arch (objfile); |
| 2612 | ctx.addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 2613 | ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu); |
| 2614 | ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu); |
| 2615 | |
| 2616 | TRY |
| 2617 | { |
| 2618 | ctx.eval (dlbaton->data, dlbaton->size); |
| 2619 | } |
| 2620 | CATCH (ex, RETURN_MASK_ERROR) |
| 2621 | { |
| 2622 | if (ex.error == NOT_AVAILABLE_ERROR) |
| 2623 | { |
| 2624 | return 0; |
| 2625 | } |
| 2626 | else if (ex.error == NO_ENTRY_VALUE_ERROR) |
| 2627 | { |
| 2628 | if (entry_values_debug) |
| 2629 | exception_print (gdb_stdout, ex); |
| 2630 | return 0; |
| 2631 | } |
| 2632 | else |
| 2633 | throw_exception (ex); |
| 2634 | } |
| 2635 | END_CATCH |
| 2636 | |
| 2637 | switch (ctx.location) |
| 2638 | { |
| 2639 | case DWARF_VALUE_REGISTER: |
| 2640 | case DWARF_VALUE_MEMORY: |
| 2641 | case DWARF_VALUE_STACK: |
| 2642 | *valp = ctx.fetch_address (0); |
| 2643 | if (ctx.location == DWARF_VALUE_REGISTER) |
| 2644 | *valp = ctx.read_addr_from_reg (*valp); |
| 2645 | return 1; |
| 2646 | case DWARF_VALUE_LITERAL: |
| 2647 | *valp = extract_signed_integer (ctx.data, ctx.len, |
| 2648 | gdbarch_byte_order (ctx.gdbarch)); |
| 2649 | return 1; |
| 2650 | /* Unsupported dwarf values. */ |
| 2651 | case DWARF_VALUE_OPTIMIZED_OUT: |
| 2652 | case DWARF_VALUE_IMPLICIT_POINTER: |
| 2653 | break; |
| 2654 | } |
| 2655 | |
| 2656 | return 0; |
| 2657 | } |
| 2658 | |
| 2659 | /* See dwarf2loc.h. */ |
| 2660 | |
| 2661 | int |
| 2662 | dwarf2_evaluate_property (const struct dynamic_prop *prop, |
| 2663 | struct frame_info *frame, |
| 2664 | struct property_addr_info *addr_stack, |
| 2665 | CORE_ADDR *value) |
| 2666 | { |
| 2667 | if (prop == NULL) |
| 2668 | return 0; |
| 2669 | |
| 2670 | if (frame == NULL && has_stack_frames ()) |
| 2671 | frame = get_selected_frame (NULL); |
| 2672 | |
| 2673 | switch (prop->kind) |
| 2674 | { |
| 2675 | case PROP_LOCEXPR: |
| 2676 | { |
| 2677 | const struct dwarf2_property_baton *baton |
| 2678 | = (const struct dwarf2_property_baton *) prop->data.baton; |
| 2679 | |
| 2680 | if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, |
| 2681 | addr_stack ? addr_stack->addr : 0, |
| 2682 | value)) |
| 2683 | { |
| 2684 | if (baton->referenced_type) |
| 2685 | { |
| 2686 | struct value *val = value_at (baton->referenced_type, *value); |
| 2687 | |
| 2688 | *value = value_as_address (val); |
| 2689 | } |
| 2690 | return 1; |
| 2691 | } |
| 2692 | } |
| 2693 | break; |
| 2694 | |
| 2695 | case PROP_LOCLIST: |
| 2696 | { |
| 2697 | struct dwarf2_property_baton *baton |
| 2698 | = (struct dwarf2_property_baton *) prop->data.baton; |
| 2699 | CORE_ADDR pc = get_frame_address_in_block (frame); |
| 2700 | const gdb_byte *data; |
| 2701 | struct value *val; |
| 2702 | size_t size; |
| 2703 | |
| 2704 | data = dwarf2_find_location_expression (&baton->loclist, &size, pc); |
| 2705 | if (data != NULL) |
| 2706 | { |
| 2707 | val = dwarf2_evaluate_loc_desc (baton->referenced_type, frame, data, |
| 2708 | size, baton->loclist.per_cu); |
| 2709 | if (!value_optimized_out (val)) |
| 2710 | { |
| 2711 | *value = value_as_address (val); |
| 2712 | return 1; |
| 2713 | } |
| 2714 | } |
| 2715 | } |
| 2716 | break; |
| 2717 | |
| 2718 | case PROP_CONST: |
| 2719 | *value = prop->data.const_val; |
| 2720 | return 1; |
| 2721 | |
| 2722 | case PROP_ADDR_OFFSET: |
| 2723 | { |
| 2724 | struct dwarf2_property_baton *baton |
| 2725 | = (struct dwarf2_property_baton *) prop->data.baton; |
| 2726 | struct property_addr_info *pinfo; |
| 2727 | struct value *val; |
| 2728 | |
| 2729 | for (pinfo = addr_stack; pinfo != NULL; pinfo = pinfo->next) |
| 2730 | if (pinfo->type == baton->referenced_type) |
| 2731 | break; |
| 2732 | if (pinfo == NULL) |
| 2733 | error (_("cannot find reference address for offset property")); |
| 2734 | if (pinfo->valaddr != NULL) |
| 2735 | val = value_from_contents |
| 2736 | (baton->offset_info.type, |
| 2737 | pinfo->valaddr + baton->offset_info.offset); |
| 2738 | else |
| 2739 | val = value_at (baton->offset_info.type, |
| 2740 | pinfo->addr + baton->offset_info.offset); |
| 2741 | *value = value_as_address (val); |
| 2742 | return 1; |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | return 0; |
| 2747 | } |
| 2748 | |
| 2749 | /* See dwarf2loc.h. */ |
| 2750 | |
| 2751 | void |
| 2752 | dwarf2_compile_property_to_c (string_file *stream, |
| 2753 | const char *result_name, |
| 2754 | struct gdbarch *gdbarch, |
| 2755 | unsigned char *registers_used, |
| 2756 | const struct dynamic_prop *prop, |
| 2757 | CORE_ADDR pc, |
| 2758 | struct symbol *sym) |
| 2759 | { |
| 2760 | struct dwarf2_property_baton *baton |
| 2761 | = (struct dwarf2_property_baton *) prop->data.baton; |
| 2762 | const gdb_byte *data; |
| 2763 | size_t size; |
| 2764 | struct dwarf2_per_cu_data *per_cu; |
| 2765 | |
| 2766 | if (prop->kind == PROP_LOCEXPR) |
| 2767 | { |
| 2768 | data = baton->locexpr.data; |
| 2769 | size = baton->locexpr.size; |
| 2770 | per_cu = baton->locexpr.per_cu; |
| 2771 | } |
| 2772 | else |
| 2773 | { |
| 2774 | gdb_assert (prop->kind == PROP_LOCLIST); |
| 2775 | |
| 2776 | data = dwarf2_find_location_expression (&baton->loclist, &size, pc); |
| 2777 | per_cu = baton->loclist.per_cu; |
| 2778 | } |
| 2779 | |
| 2780 | compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc, |
| 2781 | gdbarch, registers_used, |
| 2782 | dwarf2_per_cu_addr_size (per_cu), |
| 2783 | data, data + size, per_cu); |
| 2784 | } |
| 2785 | |
| 2786 | \f |
| 2787 | /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */ |
| 2788 | |
| 2789 | class symbol_needs_eval_context : public dwarf_expr_context |
| 2790 | { |
| 2791 | public: |
| 2792 | |
| 2793 | enum symbol_needs_kind needs; |
| 2794 | struct dwarf2_per_cu_data *per_cu; |
| 2795 | |
| 2796 | /* Reads from registers do require a frame. */ |
| 2797 | CORE_ADDR read_addr_from_reg (int regnum) override |
| 2798 | { |
| 2799 | needs = SYMBOL_NEEDS_FRAME; |
| 2800 | return 1; |
| 2801 | } |
| 2802 | |
| 2803 | /* "get_reg_value" callback: Reads from registers do require a |
| 2804 | frame. */ |
| 2805 | |
| 2806 | struct value *get_reg_value (struct type *type, int regnum) override |
| 2807 | { |
| 2808 | needs = SYMBOL_NEEDS_FRAME; |
| 2809 | return value_zero (type, not_lval); |
| 2810 | } |
| 2811 | |
| 2812 | /* Reads from memory do not require a frame. */ |
| 2813 | void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override |
| 2814 | { |
| 2815 | memset (buf, 0, len); |
| 2816 | } |
| 2817 | |
| 2818 | /* Frame-relative accesses do require a frame. */ |
| 2819 | void get_frame_base (const gdb_byte **start, size_t *length) override |
| 2820 | { |
| 2821 | static gdb_byte lit0 = DW_OP_lit0; |
| 2822 | |
| 2823 | *start = &lit0; |
| 2824 | *length = 1; |
| 2825 | |
| 2826 | needs = SYMBOL_NEEDS_FRAME; |
| 2827 | } |
| 2828 | |
| 2829 | /* CFA accesses require a frame. */ |
| 2830 | CORE_ADDR get_frame_cfa () override |
| 2831 | { |
| 2832 | needs = SYMBOL_NEEDS_FRAME; |
| 2833 | return 1; |
| 2834 | } |
| 2835 | |
| 2836 | CORE_ADDR get_frame_pc () override |
| 2837 | { |
| 2838 | needs = SYMBOL_NEEDS_FRAME; |
| 2839 | return 1; |
| 2840 | } |
| 2841 | |
| 2842 | /* Thread-local accesses require registers, but not a frame. */ |
| 2843 | CORE_ADDR get_tls_address (CORE_ADDR offset) override |
| 2844 | { |
| 2845 | if (needs <= SYMBOL_NEEDS_REGISTERS) |
| 2846 | needs = SYMBOL_NEEDS_REGISTERS; |
| 2847 | return 1; |
| 2848 | } |
| 2849 | |
| 2850 | /* Helper interface of per_cu_dwarf_call for |
| 2851 | dwarf2_loc_desc_get_symbol_read_needs. */ |
| 2852 | |
| 2853 | void dwarf_call (cu_offset die_offset) override |
| 2854 | { |
| 2855 | per_cu_dwarf_call (this, die_offset, per_cu); |
| 2856 | } |
| 2857 | |
| 2858 | /* Helper interface of sect_variable_value for |
| 2859 | dwarf2_loc_desc_get_symbol_read_needs. */ |
| 2860 | |
| 2861 | struct value *dwarf_variable_value (sect_offset sect_off) override |
| 2862 | { |
| 2863 | return sect_variable_value (this, sect_off, per_cu); |
| 2864 | } |
| 2865 | |
| 2866 | /* DW_OP_entry_value accesses require a caller, therefore a |
| 2867 | frame. */ |
| 2868 | |
| 2869 | void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind, |
| 2870 | union call_site_parameter_u kind_u, |
| 2871 | int deref_size) override |
| 2872 | { |
| 2873 | needs = SYMBOL_NEEDS_FRAME; |
| 2874 | |
| 2875 | /* The expression may require some stub values on DWARF stack. */ |
| 2876 | push_address (0, 0); |
| 2877 | } |
| 2878 | |
| 2879 | /* DW_OP_GNU_addr_index doesn't require a frame. */ |
| 2880 | |
| 2881 | CORE_ADDR get_addr_index (unsigned int index) override |
| 2882 | { |
| 2883 | /* Nothing to do. */ |
| 2884 | return 1; |
| 2885 | } |
| 2886 | |
| 2887 | /* DW_OP_push_object_address has a frame already passed through. */ |
| 2888 | |
| 2889 | CORE_ADDR get_object_address () override |
| 2890 | { |
| 2891 | /* Nothing to do. */ |
| 2892 | return 1; |
| 2893 | } |
| 2894 | }; |
| 2895 | |
| 2896 | /* Compute the correct symbol_needs_kind value for the location |
| 2897 | expression at DATA (length SIZE). */ |
| 2898 | |
| 2899 | static enum symbol_needs_kind |
| 2900 | dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size, |
| 2901 | struct dwarf2_per_cu_data *per_cu) |
| 2902 | { |
| 2903 | int in_reg; |
| 2904 | struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); |
| 2905 | |
| 2906 | scoped_value_mark free_values; |
| 2907 | |
| 2908 | symbol_needs_eval_context ctx; |
| 2909 | |
| 2910 | ctx.needs = SYMBOL_NEEDS_NONE; |
| 2911 | ctx.per_cu = per_cu; |
| 2912 | ctx.gdbarch = get_objfile_arch (objfile); |
| 2913 | ctx.addr_size = dwarf2_per_cu_addr_size (per_cu); |
| 2914 | ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu); |
| 2915 | ctx.offset = dwarf2_per_cu_text_offset (per_cu); |
| 2916 | |
| 2917 | ctx.eval (data, size); |
| 2918 | |
| 2919 | in_reg = ctx.location == DWARF_VALUE_REGISTER; |
| 2920 | |
| 2921 | /* If the location has several pieces, and any of them are in |
| 2922 | registers, then we will need a frame to fetch them from. */ |
| 2923 | for (dwarf_expr_piece &p : ctx.pieces) |
| 2924 | if (p.location == DWARF_VALUE_REGISTER) |
| 2925 | in_reg = 1; |
| 2926 | |
| 2927 | if (in_reg) |
| 2928 | ctx.needs = SYMBOL_NEEDS_FRAME; |
| 2929 | return ctx.needs; |
| 2930 | } |
| 2931 | |
| 2932 | /* A helper function that throws an unimplemented error mentioning a |
| 2933 | given DWARF operator. */ |
| 2934 | |
| 2935 | static void ATTRIBUTE_NORETURN |
| 2936 | unimplemented (unsigned int op) |
| 2937 | { |
| 2938 | const char *name = get_DW_OP_name (op); |
| 2939 | |
| 2940 | if (name) |
| 2941 | error (_("DWARF operator %s cannot be translated to an agent expression"), |
| 2942 | name); |
| 2943 | else |
| 2944 | error (_("Unknown DWARF operator 0x%02x cannot be translated " |
| 2945 | "to an agent expression"), |
| 2946 | op); |
| 2947 | } |
| 2948 | |
| 2949 | /* See dwarf2loc.h. |
| 2950 | |
| 2951 | This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we |
| 2952 | can issue a complaint, which is better than having every target's |
| 2953 | implementation of dwarf2_reg_to_regnum do it. */ |
| 2954 | |
| 2955 | int |
| 2956 | dwarf_reg_to_regnum (struct gdbarch *arch, int dwarf_reg) |
| 2957 | { |
| 2958 | int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg); |
| 2959 | |
| 2960 | if (reg == -1) |
| 2961 | { |
| 2962 | complaint (_("bad DWARF register number %d"), dwarf_reg); |
| 2963 | } |
| 2964 | return reg; |
| 2965 | } |
| 2966 | |
| 2967 | /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it. |
| 2968 | Throw an error because DWARF_REG is bad. */ |
| 2969 | |
| 2970 | static void |
| 2971 | throw_bad_regnum_error (ULONGEST dwarf_reg) |
| 2972 | { |
| 2973 | /* Still want to print -1 as "-1". |
| 2974 | We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error |
| 2975 | but that's overkill for now. */ |
| 2976 | if ((int) dwarf_reg == dwarf_reg) |
| 2977 | error (_("Unable to access DWARF register number %d"), (int) dwarf_reg); |
| 2978 | error (_("Unable to access DWARF register number %s"), |
| 2979 | pulongest (dwarf_reg)); |
| 2980 | } |
| 2981 | |
| 2982 | /* See dwarf2loc.h. */ |
| 2983 | |
| 2984 | int |
| 2985 | dwarf_reg_to_regnum_or_error (struct gdbarch *arch, ULONGEST dwarf_reg) |
| 2986 | { |
| 2987 | int reg; |
| 2988 | |
| 2989 | if (dwarf_reg > INT_MAX) |
| 2990 | throw_bad_regnum_error (dwarf_reg); |
| 2991 | /* Yes, we will end up issuing a complaint and an error if DWARF_REG is |
| 2992 | bad, but that's ok. */ |
| 2993 | reg = dwarf_reg_to_regnum (arch, (int) dwarf_reg); |
| 2994 | if (reg == -1) |
| 2995 | throw_bad_regnum_error (dwarf_reg); |
| 2996 | return reg; |
| 2997 | } |
| 2998 | |
| 2999 | /* A helper function that emits an access to memory. ARCH is the |
| 3000 | target architecture. EXPR is the expression which we are building. |
| 3001 | NBITS is the number of bits we want to read. This emits the |
| 3002 | opcodes needed to read the memory and then extract the desired |
| 3003 | bits. */ |
| 3004 | |
| 3005 | static void |
| 3006 | access_memory (struct gdbarch *arch, struct agent_expr *expr, ULONGEST nbits) |
| 3007 | { |
| 3008 | ULONGEST nbytes = (nbits + 7) / 8; |
| 3009 | |
| 3010 | gdb_assert (nbytes > 0 && nbytes <= sizeof (LONGEST)); |
| 3011 | |
| 3012 | if (expr->tracing) |
| 3013 | ax_trace_quick (expr, nbytes); |
| 3014 | |
| 3015 | if (nbits <= 8) |
| 3016 | ax_simple (expr, aop_ref8); |
| 3017 | else if (nbits <= 16) |
| 3018 | ax_simple (expr, aop_ref16); |
| 3019 | else if (nbits <= 32) |
| 3020 | ax_simple (expr, aop_ref32); |
| 3021 | else |
| 3022 | ax_simple (expr, aop_ref64); |
| 3023 | |
| 3024 | /* If we read exactly the number of bytes we wanted, we're done. */ |
| 3025 | if (8 * nbytes == nbits) |
| 3026 | return; |
| 3027 | |
| 3028 | if (gdbarch_bits_big_endian (arch)) |
| 3029 | { |
| 3030 | /* On a bits-big-endian machine, we want the high-order |
| 3031 | NBITS. */ |
| 3032 | ax_const_l (expr, 8 * nbytes - nbits); |
| 3033 | ax_simple (expr, aop_rsh_unsigned); |
| 3034 | } |
| 3035 | else |
| 3036 | { |
| 3037 | /* On a bits-little-endian box, we want the low-order NBITS. */ |
| 3038 | ax_zero_ext (expr, nbits); |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | /* A helper function to return the frame's PC. */ |
| 3043 | |
| 3044 | static CORE_ADDR |
| 3045 | get_ax_pc (void *baton) |
| 3046 | { |
| 3047 | struct agent_expr *expr = (struct agent_expr *) baton; |
| 3048 | |
| 3049 | return expr->scope; |
| 3050 | } |
| 3051 | |
| 3052 | /* Compile a DWARF location expression to an agent expression. |
| 3053 | |
| 3054 | EXPR is the agent expression we are building. |
| 3055 | LOC is the agent value we modify. |
| 3056 | ARCH is the architecture. |
| 3057 | ADDR_SIZE is the size of addresses, in bytes. |
| 3058 | OP_PTR is the start of the location expression. |
| 3059 | OP_END is one past the last byte of the location expression. |
| 3060 | |
| 3061 | This will throw an exception for various kinds of errors -- for |
| 3062 | example, if the expression cannot be compiled, or if the expression |
| 3063 | is invalid. */ |
| 3064 | |
| 3065 | void |
| 3066 | dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, |
| 3067 | unsigned int addr_size, const gdb_byte *op_ptr, |
| 3068 | const gdb_byte *op_end, |
| 3069 | struct dwarf2_per_cu_data *per_cu) |
| 3070 | { |
| 3071 | gdbarch *arch = expr->gdbarch; |
| 3072 | int i; |
| 3073 | std::vector<int> dw_labels, patches; |
| 3074 | const gdb_byte * const base = op_ptr; |
| 3075 | const gdb_byte *previous_piece = op_ptr; |
| 3076 | enum bfd_endian byte_order = gdbarch_byte_order (arch); |
| 3077 | ULONGEST bits_collected = 0; |
| 3078 | unsigned int addr_size_bits = 8 * addr_size; |
| 3079 | int bits_big_endian = gdbarch_bits_big_endian (arch); |
| 3080 | |
| 3081 | std::vector<int> offsets (op_end - op_ptr, -1); |
| 3082 | |
| 3083 | /* By default we are making an address. */ |
| 3084 | loc->kind = axs_lvalue_memory; |
| 3085 | |
| 3086 | while (op_ptr < op_end) |
| 3087 | { |
| 3088 | enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr; |
| 3089 | uint64_t uoffset, reg; |
| 3090 | int64_t offset; |
| 3091 | int i; |
| 3092 | |
| 3093 | offsets[op_ptr - base] = expr->len; |
| 3094 | ++op_ptr; |
| 3095 | |
| 3096 | /* Our basic approach to code generation is to map DWARF |
| 3097 | operations directly to AX operations. However, there are |
| 3098 | some differences. |
| 3099 | |
| 3100 | First, DWARF works on address-sized units, but AX always uses |
| 3101 | LONGEST. For most operations we simply ignore this |
| 3102 | difference; instead we generate sign extensions as needed |
| 3103 | before division and comparison operations. It would be nice |
| 3104 | to omit the sign extensions, but there is no way to determine |
| 3105 | the size of the target's LONGEST. (This code uses the size |
| 3106 | of the host LONGEST in some cases -- that is a bug but it is |
| 3107 | difficult to fix.) |
| 3108 | |
| 3109 | Second, some DWARF operations cannot be translated to AX. |
| 3110 | For these we simply fail. See |
| 3111 | http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */ |
| 3112 | switch (op) |
| 3113 | { |
| 3114 | case DW_OP_lit0: |
| 3115 | case DW_OP_lit1: |
| 3116 | case DW_OP_lit2: |
| 3117 | case DW_OP_lit3: |
| 3118 | case DW_OP_lit4: |
| 3119 | case DW_OP_lit5: |
| 3120 | case DW_OP_lit6: |
| 3121 | case DW_OP_lit7: |
| 3122 | case DW_OP_lit8: |
| 3123 | case DW_OP_lit9: |
| 3124 | case DW_OP_lit10: |
| 3125 | case DW_OP_lit11: |
| 3126 | case DW_OP_lit12: |
| 3127 | case DW_OP_lit13: |
| 3128 | case DW_OP_lit14: |
| 3129 | case DW_OP_lit15: |
| 3130 | case DW_OP_lit16: |
| 3131 | case DW_OP_lit17: |
| 3132 | case DW_OP_lit18: |
| 3133 | case DW_OP_lit19: |
| 3134 | case DW_OP_lit20: |
| 3135 | case DW_OP_lit21: |
| 3136 | case DW_OP_lit22: |
| 3137 | case DW_OP_lit23: |
| 3138 | case DW_OP_lit24: |
| 3139 | case DW_OP_lit25: |
| 3140 | case DW_OP_lit26: |
| 3141 | case DW_OP_lit27: |
| 3142 | case DW_OP_lit28: |
| 3143 | case DW_OP_lit29: |
| 3144 | case DW_OP_lit30: |
| 3145 | case DW_OP_lit31: |
| 3146 | ax_const_l (expr, op - DW_OP_lit0); |
| 3147 | break; |
| 3148 | |
| 3149 | case DW_OP_addr: |
| 3150 | uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order); |
| 3151 | op_ptr += addr_size; |
| 3152 | /* Some versions of GCC emit DW_OP_addr before |
| 3153 | DW_OP_GNU_push_tls_address. In this case the value is an |
| 3154 | index, not an address. We don't support things like |
| 3155 | branching between the address and the TLS op. */ |
| 3156 | if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address) |
| 3157 | uoffset += dwarf2_per_cu_text_offset (per_cu); |
| 3158 | ax_const_l (expr, uoffset); |
| 3159 | break; |
| 3160 | |
| 3161 | case DW_OP_const1u: |
| 3162 | ax_const_l (expr, extract_unsigned_integer (op_ptr, 1, byte_order)); |
| 3163 | op_ptr += 1; |
| 3164 | break; |
| 3165 | case DW_OP_const1s: |
| 3166 | ax_const_l (expr, extract_signed_integer (op_ptr, 1, byte_order)); |
| 3167 | op_ptr += 1; |
| 3168 | break; |
| 3169 | case DW_OP_const2u: |
| 3170 | ax_const_l (expr, extract_unsigned_integer (op_ptr, 2, byte_order)); |
| 3171 | op_ptr += 2; |
| 3172 | break; |
| 3173 | case DW_OP_const2s: |
| 3174 | ax_const_l (expr, extract_signed_integer (op_ptr, 2, byte_order)); |
| 3175 | op_ptr += 2; |
| 3176 | break; |
| 3177 | case DW_OP_const4u: |
| 3178 | ax_const_l (expr, extract_unsigned_integer (op_ptr, 4, byte_order)); |
| 3179 | op_ptr += 4; |
| 3180 | break; |
| 3181 | case DW_OP_const4s: |
| 3182 | ax_const_l (expr, extract_signed_integer (op_ptr, 4, byte_order)); |
| 3183 | op_ptr += 4; |
| 3184 | break; |
| 3185 | case DW_OP_const8u: |
| 3186 | ax_const_l (expr, extract_unsigned_integer (op_ptr, 8, byte_order)); |
| 3187 | op_ptr += 8; |
| 3188 | break; |
| 3189 | case DW_OP_const8s: |
| 3190 | ax_const_l (expr, extract_signed_integer (op_ptr, 8, byte_order)); |
| 3191 | op_ptr += 8; |
| 3192 | break; |
| 3193 | case DW_OP_constu: |
| 3194 | op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset); |
| 3195 | ax_const_l (expr, uoffset); |
| 3196 | break; |
| 3197 | case DW_OP_consts: |
| 3198 | op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset); |
| 3199 | ax_const_l (expr, offset); |
| 3200 | break; |
| 3201 | |
| 3202 | case DW_OP_reg0: |
| 3203 | case DW_OP_reg1: |
| 3204 | case DW_OP_reg2: |
| 3205 | case DW_OP_reg3: |
| 3206 | case DW_OP_reg4: |
| 3207 | case DW_OP_reg5: |
| 3208 | case DW_OP_reg6: |
| 3209 | case DW_OP_reg7: |
| 3210 | case DW_OP_reg8: |
| 3211 | case DW_OP_reg9: |
| 3212 | case DW_OP_reg10: |
| 3213 | case DW_OP_reg11: |
| 3214 | case DW_OP_reg12: |
| 3215 | case DW_OP_reg13: |
| 3216 | case DW_OP_reg14: |
| 3217 | case DW_OP_reg15: |
| 3218 | case DW_OP_reg16: |
| 3219 | case DW_OP_reg17: |
| 3220 | case DW_OP_reg18: |
| 3221 | case DW_OP_reg19: |
| 3222 | case DW_OP_reg20: |
| 3223 | case DW_OP_reg21: |
| 3224 | case DW_OP_reg22: |
| 3225 | case DW_OP_reg23: |
| 3226 | case DW_OP_reg24: |
| 3227 | case DW_OP_reg25: |
| 3228 | case DW_OP_reg26: |
| 3229 | case DW_OP_reg27: |
| 3230 | case DW_OP_reg28: |
| 3231 | case DW_OP_reg29: |
| 3232 | case DW_OP_reg30: |
| 3233 | case DW_OP_reg31: |
| 3234 | dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx"); |
| 3235 | loc->u.reg = dwarf_reg_to_regnum_or_error (arch, op - DW_OP_reg0); |
| 3236 | loc->kind = axs_lvalue_register; |
| 3237 | break; |
| 3238 | |
| 3239 | case DW_OP_regx: |
| 3240 | op_ptr = safe_read_uleb128 (op_ptr, op_end, ®); |
| 3241 | dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx"); |
| 3242 | loc->u.reg = dwarf_reg_to_regnum_or_error (arch, reg); |
| 3243 | loc->kind = axs_lvalue_register; |
| 3244 | break; |
| 3245 | |
| 3246 | case DW_OP_implicit_value: |
| 3247 | { |
| 3248 | uint64_t len; |
| 3249 | |
| 3250 | op_ptr = safe_read_uleb128 (op_ptr, op_end, &len); |
| 3251 | if (op_ptr + len > op_end) |
| 3252 | error (_("DW_OP_implicit_value: too few bytes available.")); |
| 3253 | if (len > sizeof (ULONGEST)) |
| 3254 | error (_("Cannot translate DW_OP_implicit_value of %d bytes"), |
| 3255 | (int) len); |
| 3256 | |
| 3257 | ax_const_l (expr, extract_unsigned_integer (op_ptr, len, |
| 3258 | byte_order)); |
| 3259 | op_ptr += len; |
| 3260 | dwarf_expr_require_composition (op_ptr, op_end, |
| 3261 | "DW_OP_implicit_value"); |
| 3262 | |
| 3263 | loc->kind = axs_rvalue; |
| 3264 | } |
| 3265 | break; |
| 3266 | |
| 3267 | case DW_OP_stack_value: |
| 3268 | dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value"); |
| 3269 | loc->kind = axs_rvalue; |
| 3270 | break; |
| 3271 | |
| 3272 | case DW_OP_breg0: |
| 3273 | case DW_OP_breg1: |
| 3274 | case DW_OP_breg2: |
| 3275 | case DW_OP_breg3: |
| 3276 | case DW_OP_breg4: |
| 3277 | case DW_OP_breg5: |
| 3278 | case DW_OP_breg6: |
| 3279 | case DW_OP_breg7: |
| 3280 | case DW_OP_breg8: |
| 3281 | case DW_OP_breg9: |
| 3282 | case DW_OP_breg10: |
| 3283 | case DW_OP_breg11: |
| 3284 | case DW_OP_breg12: |
| 3285 | case DW_OP_breg13: |
| 3286 | case DW_OP_breg14: |
| 3287 | case DW_OP_breg15: |
| 3288 | case DW_OP_breg16: |
| 3289 | case DW_OP_breg17: |
| 3290 | case DW_OP_breg18: |
| 3291 | case DW_OP_breg19: |
| 3292 | case DW_OP_breg20: |
| 3293 | case DW_OP_breg21: |
| 3294 | case DW_OP_breg22: |
| 3295 | case DW_OP_breg23: |
| 3296 | case DW_OP_breg24: |
| 3297 | case DW_OP_breg25: |
| 3298 | case DW_OP_breg26: |
| 3299 | case DW_OP_breg27: |
| 3300 | case DW_OP_breg28: |
| 3301 | case DW_OP_breg29: |
| 3302 | case DW_OP_breg30: |
| 3303 | case DW_OP_breg31: |
| 3304 | op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset); |
| 3305 | i = dwarf_reg_to_regnum_or_error (arch, op - DW_OP_breg0); |
| 3306 | ax_reg (expr, i); |
| 3307 | if (offset != 0) |
| 3308 | { |
| 3309 | ax_const_l (expr, offset); |
| 3310 | ax_simple (expr, aop_add); |
| 3311 | } |
| 3312 | break; |
| 3313 | case DW_OP_bregx: |
| 3314 | { |
| 3315 | op_ptr = safe_read_uleb128 (op_ptr, op_end, ®); |
| 3316 | op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset); |
| 3317 | i = dwarf_reg_to_regnum_or_error (arch, reg); |
| 3318 | ax_reg (expr, i); |
| 3319 | if (offset != 0) |
| 3320 | { |
| 3321 | ax_const_l (expr, offset); |
| 3322 | ax_simple (expr, aop_add); |
| 3323 | } |
| 3324 | } |
| 3325 | break; |
| 3326 | case DW_OP_fbreg: |
| 3327 | { |
| 3328 | const gdb_byte *datastart; |
| 3329 | size_t datalen; |
| 3330 | const struct block *b; |
| 3331 | struct symbol *framefunc; |
| 3332 | |
| 3333 | b = block_for_pc (expr->scope); |
| 3334 | |
| 3335 | if (!b) |
| 3336 | error (_("No block found for address")); |
| 3337 | |
| 3338 | framefunc = block_linkage_function (b); |
| 3339 | |
| 3340 | if (!framefunc) |
| 3341 | error (_("No function found for block")); |
| 3342 | |
| 3343 | func_get_frame_base_dwarf_block (framefunc, expr->scope, |
| 3344 | &datastart, &datalen); |
| 3345 | |
| 3346 | op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset); |
| 3347 | dwarf2_compile_expr_to_ax (expr, loc, addr_size, datastart, |
| 3348 | datastart + datalen, per_cu); |
| 3349 | if (loc->kind == axs_lvalue_register) |
| 3350 | require_rvalue (expr, loc); |
| 3351 | |
| 3352 | if (offset != 0) |
| 3353 | { |
| 3354 | ax_const_l (expr, offset); |
| 3355 | ax_simple (expr, aop_add); |
| 3356 | } |
| 3357 | |
| 3358 | loc->kind = axs_lvalue_memory; |
| 3359 | } |
| 3360 | break; |
| 3361 | |
| 3362 | case DW_OP_dup: |
| 3363 | ax_simple (expr, aop_dup); |
| 3364 | break; |
| 3365 | |
| 3366 | case DW_OP_drop: |
| 3367 | ax_simple (expr, aop_pop); |
| 3368 | break; |
| 3369 | |
| 3370 | case DW_OP_pick: |
| 3371 | offset = *op_ptr++; |
| 3372 | ax_pick (expr, offset); |
| 3373 | break; |
| 3374 | |
| 3375 | case DW_OP_swap: |
| 3376 | ax_simple (expr, aop_swap); |
| 3377 | break; |
| 3378 | |
| 3379 | case DW_OP_over: |
| 3380 | ax_pick (expr, 1); |
| 3381 | break; |
| 3382 | |
| 3383 | case DW_OP_rot: |
| 3384 | ax_simple (expr, aop_rot); |
| 3385 | break; |
| 3386 | |
| 3387 | case DW_OP_deref: |
| 3388 | case DW_OP_deref_size: |
| 3389 | { |
| 3390 | int size; |
| 3391 | |
| 3392 | if (op == DW_OP_deref_size) |
| 3393 | size = *op_ptr++; |
| 3394 | else |
| 3395 | size = addr_size; |
| 3396 | |
| 3397 | if (size != 1 && size != 2 && size != 4 && size != 8) |
| 3398 | error (_("Unsupported size %d in %s"), |
| 3399 | size, get_DW_OP_name (op)); |
| 3400 | access_memory (arch, expr, size * TARGET_CHAR_BIT); |
| 3401 | } |
| 3402 | break; |
| 3403 | |
| 3404 | case DW_OP_abs: |
| 3405 | /* Sign extend the operand. */ |
| 3406 | ax_ext (expr, addr_size_bits); |
| 3407 | ax_simple (expr, aop_dup); |
| 3408 | ax_const_l (expr, 0); |
| 3409 | ax_simple (expr, aop_less_signed); |
| 3410 | ax_simple (expr, aop_log_not); |
| 3411 | i = ax_goto (expr, aop_if_goto); |
| 3412 | /* We have to emit 0 - X. */ |
| 3413 | ax_const_l (expr, 0); |
| 3414 | ax_simple (expr, aop_swap); |
| 3415 | ax_simple (expr, aop_sub); |
| 3416 | ax_label (expr, i, expr->len); |
| 3417 | break; |
| 3418 | |
| 3419 | case DW_OP_neg: |
| 3420 | /* No need to sign extend here. */ |
| 3421 | ax_const_l (expr, 0); |
| 3422 | ax_simple (expr, aop_swap); |
| 3423 | ax_simple (expr, aop_sub); |
| 3424 | break; |
| 3425 | |
| 3426 | case DW_OP_not: |
| 3427 | /* Sign extend the operand. */ |
| 3428 | ax_ext (expr, addr_size_bits); |
| 3429 | ax_simple (expr, aop_bit_not); |
| 3430 | break; |
| 3431 | |
| 3432 | case DW_OP_plus_uconst: |
| 3433 | op_ptr = safe_read_uleb128 (op_ptr, op_end, ®); |
| 3434 | /* It would be really weird to emit `DW_OP_plus_uconst 0', |
| 3435 | but we micro-optimize anyhow. */ |
| 3436 | if (reg != 0) |
| 3437 | { |
| 3438 | ax_const_l (expr, reg); |
| 3439 | ax_simple (expr, aop_add); |
| 3440 | } |
| 3441 | break; |
| 3442 | |
| 3443 | case DW_OP_and: |
| 3444 | ax_simple (expr, aop_bit_and); |
| 3445 | break; |
| 3446 | |
| 3447 | case DW_OP_div: |
| 3448 | /* Sign extend the operands. */ |
| 3449 | ax_ext (expr, addr_size_bits); |
| 3450 | ax_simple (expr, aop_swap); |
| 3451 | ax_ext (expr, addr_size_bits); |
| 3452 | ax_simple (expr, aop_swap); |
| 3453 | ax_simple (expr, aop_div_signed); |
| 3454 | break; |
| 3455 | |
| 3456 | case DW_OP_minus: |
| 3457 | ax_simple (expr, aop_sub); |
| 3458 | break; |
| 3459 | |
| 3460 | case DW_OP_mod: |
| 3461 | ax_simple (expr, aop_rem_unsigned); |
| 3462 | break; |
| 3463 | |
| 3464 | case DW_OP_mul: |
| 3465 | ax_simple (expr, aop_mul); |
| 3466 | break; |
| 3467 | |
| 3468 | case DW_OP_or: |
| 3469 | ax_simple (expr, aop_bit_or); |
| 3470 | break; |
| 3471 | |
| 3472 | case DW_OP_plus: |
| 3473 | ax_simple (expr, aop_add); |
| 3474 | break; |
| 3475 | |
| 3476 | case DW_OP_shl: |
| 3477 | ax_simple (expr, aop_lsh); |
| 3478 | break; |
| 3479 | |
| 3480 | case DW_OP_shr: |
| 3481 | ax_simple (expr, aop_rsh_unsigned); |
| 3482 | break; |
| 3483 | |
| 3484 | case DW_OP_shra: |
| 3485 | ax_simple (expr, aop_rsh_signed); |
| 3486 | break; |
| 3487 | |
| 3488 | case DW_OP_xor: |
| 3489 | ax_simple (expr, aop_bit_xor); |
| 3490 | break; |
| 3491 | |
| 3492 | case DW_OP_le: |
| 3493 | /* Sign extend the operands. */ |
| 3494 | ax_ext (expr, addr_size_bits); |
| 3495 | ax_simple (expr, aop_swap); |
| 3496 | ax_ext (expr, addr_size_bits); |
| 3497 | /* Note no swap here: A <= B is !(B < A). */ |
| 3498 | ax_simple (expr, aop_less_signed); |
| 3499 | ax_simple (expr, aop_log_not); |
| 3500 | break; |
| 3501 | |
| 3502 | case DW_OP_ge: |
| 3503 | /* Sign extend the operands. */ |
| 3504 | ax_ext (expr, addr_size_bits); |
| 3505 | ax_simple (expr, aop_swap); |
| 3506 | ax_ext (expr, addr_size_bits); |
| 3507 | ax_simple (expr, aop_swap); |
| 3508 | /* A >= B is !(A < B). */ |
| 3509 | ax_simple (expr, aop_less_signed); |
| 3510 | ax_simple (expr, aop_log_not); |
| 3511 | break; |
| 3512 | |
| 3513 | case DW_OP_eq: |
| 3514 | /* Sign extend the operands. */ |
| 3515 | ax_ext (expr, addr_size_bits); |
| 3516 | ax_simple (expr, aop_swap); |
| 3517 | ax_ext (expr, addr_size_bits); |
| 3518 | /* No need for a second swap here. */ |
| 3519 | ax_simple (expr, aop_equal); |
| 3520 | break; |
| 3521 | |
| 3522 | case DW_OP_lt: |
| 3523 | /* Sign extend the operands. */ |
| 3524 | ax_ext (expr, addr_size_bits); |
| 3525 | ax_simple (expr, aop_swap); |
| 3526 | ax_ext (expr, addr_size_bits); |
| 3527 | ax_simple (expr, aop_swap); |
| 3528 | ax_simple (expr, aop_less_signed); |
| 3529 | break; |
| 3530 | |
| 3531 | case DW_OP_gt: |
| 3532 | /* Sign extend the operands. */ |
| 3533 | ax_ext (expr, addr_size_bits); |
| 3534 | ax_simple (expr, aop_swap); |
| 3535 | ax_ext (expr, addr_size_bits); |
| 3536 | /* Note no swap here: A > B is B < A. */ |
| 3537 | ax_simple (expr, aop_less_signed); |
| 3538 | break; |
| 3539 | |
| 3540 | case DW_OP_ne: |
| 3541 | /* Sign extend the operands. */ |
| 3542 | ax_ext (expr, addr_size_bits); |
| 3543 | ax_simple (expr, aop_swap); |
| 3544 | ax_ext (expr, addr_size_bits); |
| 3545 | /* No need for a swap here. */ |
| 3546 | ax_simple (expr, aop_equal); |
| 3547 | ax_simple (expr, aop_log_not); |
| 3548 | break; |
| 3549 | |
| 3550 | case DW_OP_call_frame_cfa: |
| 3551 | { |
| 3552 | int regnum; |
| 3553 | CORE_ADDR text_offset; |
| 3554 | LONGEST off; |
| 3555 | const gdb_byte *cfa_start, *cfa_end; |
| 3556 | |
| 3557 | if (dwarf2_fetch_cfa_info (arch, expr->scope, per_cu, |
| 3558 | ®num, &off, |
| 3559 | &text_offset, &cfa_start, &cfa_end)) |
| 3560 | { |
| 3561 | /* Register. */ |
| 3562 | ax_reg (expr, regnum); |
| 3563 | if (off != 0) |
| 3564 | { |
| 3565 | ax_const_l (expr, off); |
| 3566 | ax_simple (expr, aop_add); |
| 3567 | } |
| 3568 | } |
| 3569 | else |
| 3570 | { |
| 3571 | /* Another expression. */ |
| 3572 | ax_const_l (expr, text_offset); |
| 3573 | dwarf2_compile_expr_to_ax (expr, loc, addr_size, cfa_start, |
| 3574 | cfa_end, per_cu); |
| 3575 | } |
| 3576 | |
| 3577 | loc->kind = axs_lvalue_memory; |
| 3578 | } |
| 3579 | break; |
| 3580 | |
| 3581 | case DW_OP_GNU_push_tls_address: |
| 3582 | case DW_OP_form_tls_address: |
| 3583 | unimplemented (op); |
| 3584 | break; |
| 3585 | |
| 3586 | case DW_OP_push_object_address: |
| 3587 | unimplemented (op); |
| 3588 | break; |
| 3589 | |
| 3590 | case DW_OP_skip: |
| 3591 | offset = extract_signed_integer (op_ptr, 2, byte_order); |
| 3592 | op_ptr += 2; |
| 3593 | i = ax_goto (expr, aop_goto); |
| 3594 | dw_labels.push_back (op_ptr + offset - base); |
| 3595 | patches.push_back (i); |
| 3596 | break; |
| 3597 | |
| 3598 | case DW_OP_bra: |
| 3599 | offset = extract_signed_integer (op_ptr, 2, byte_order); |
| 3600 | op_ptr += 2; |
| 3601 | /* Zero extend the operand. */ |
| 3602 | ax_zero_ext (expr, addr_size_bits); |
| 3603 | i = ax_goto (expr, aop_if_goto); |
| 3604 | dw_labels.push_back (op_ptr + offset - base); |
| 3605 | patches.push_back (i); |
| 3606 | break; |
| 3607 | |
| 3608 | case DW_OP_nop: |
| 3609 | break; |
| 3610 | |
| 3611 | case DW_OP_piece: |
| 3612 | case DW_OP_bit_piece: |
| 3613 | { |
| 3614 | uint64_t size, offset; |
| 3615 | |
| 3616 | if (op_ptr - 1 == previous_piece) |
| 3617 | error (_("Cannot translate empty pieces to agent expressions")); |
| 3618 | previous_piece = op_ptr - 1; |
| 3619 | |
| 3620 | op_ptr = safe_read_uleb128 (op_ptr, op_end, &size); |
| 3621 | if (op == DW_OP_piece) |
| 3622 | { |
| 3623 | size *= 8; |
| 3624 | offset = 0; |
| 3625 | } |
| 3626 | else |
| 3627 | op_ptr = safe_read_uleb128 (op_ptr, op_end, &offset); |
| 3628 | |
| 3629 | if (bits_collected + size > 8 * sizeof (LONGEST)) |
| 3630 | error (_("Expression pieces exceed word size")); |
| 3631 | |
| 3632 | /* Access the bits. */ |
| 3633 | switch (loc->kind) |
| 3634 | { |
| 3635 | case axs_lvalue_register: |
| 3636 | ax_reg (expr, loc->u.reg); |
| 3637 | break; |
| 3638 | |
| 3639 | case axs_lvalue_memory: |
| 3640 | /* Offset the pointer, if needed. */ |
| 3641 | if (offset > 8) |
| 3642 | { |
| 3643 | ax_const_l (expr, offset / 8); |
| 3644 | ax_simple (expr, aop_add); |
| 3645 | offset %= 8; |
| 3646 | } |
| 3647 | access_memory (arch, expr, size); |
| 3648 | break; |
| 3649 | } |
| 3650 | |
| 3651 | /* For a bits-big-endian target, shift up what we already |
| 3652 | have. For a bits-little-endian target, shift up the |
| 3653 | new data. Note that there is a potential bug here if |
| 3654 | the DWARF expression leaves multiple values on the |
| 3655 | stack. */ |
| 3656 | if (bits_collected > 0) |
| 3657 | { |
| 3658 | if (bits_big_endian) |
| 3659 | { |
| 3660 | ax_simple (expr, aop_swap); |
| 3661 | ax_const_l (expr, size); |
| 3662 | ax_simple (expr, aop_lsh); |
| 3663 | /* We don't need a second swap here, because |
| 3664 | aop_bit_or is symmetric. */ |
| 3665 | } |
| 3666 | else |
| 3667 | { |
| 3668 | ax_const_l (expr, size); |
| 3669 | ax_simple (expr, aop_lsh); |
| 3670 | } |
| 3671 | ax_simple (expr, aop_bit_or); |
| 3672 | } |
| 3673 | |
| 3674 | bits_collected += size; |
| 3675 | loc->kind = axs_rvalue; |
| 3676 | } |
| 3677 | break; |
| 3678 | |
| 3679 | case DW_OP_GNU_uninit: |
| 3680 | unimplemented (op); |
| 3681 | |
| 3682 | case DW_OP_call2: |
| 3683 | case DW_OP_call4: |
| 3684 | { |
| 3685 | struct dwarf2_locexpr_baton block; |
| 3686 | int size = (op == DW_OP_call2 ? 2 : 4); |
| 3687 | |
| 3688 | uoffset = extract_unsigned_integer (op_ptr, size, byte_order); |
| 3689 | op_ptr += size; |
| 3690 | |
| 3691 | cu_offset offset = (cu_offset) uoffset; |
| 3692 | block = dwarf2_fetch_die_loc_cu_off (offset, per_cu, |
| 3693 | get_ax_pc, expr); |
| 3694 | |
| 3695 | /* DW_OP_call_ref is currently not supported. */ |
| 3696 | gdb_assert (block.per_cu == per_cu); |
| 3697 | |
| 3698 | dwarf2_compile_expr_to_ax (expr, loc, addr_size, block.data, |
| 3699 | block.data + block.size, per_cu); |
| 3700 | } |
| 3701 | break; |
| 3702 | |
| 3703 | case DW_OP_call_ref: |
| 3704 | unimplemented (op); |
| 3705 | |
| 3706 | case DW_OP_GNU_variable_value: |
| 3707 | unimplemented (op); |
| 3708 | |
| 3709 | default: |
| 3710 | unimplemented (op); |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | /* Patch all the branches we emitted. */ |
| 3715 | for (i = 0; i < patches.size (); ++i) |
| 3716 | { |
| 3717 | int targ = offsets[dw_labels[i]]; |
| 3718 | if (targ == -1) |
| 3719 | internal_error (__FILE__, __LINE__, _("invalid label")); |
| 3720 | ax_label (expr, patches[i], targ); |
| 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | \f |
| 3725 | /* Return the value of SYMBOL in FRAME using the DWARF-2 expression |
| 3726 | evaluator to calculate the location. */ |
| 3727 | static struct value * |
| 3728 | locexpr_read_variable (struct symbol *symbol, struct frame_info *frame) |
| 3729 | { |
| 3730 | struct dwarf2_locexpr_baton *dlbaton |
| 3731 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 3732 | struct value *val; |
| 3733 | |
| 3734 | val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data, |
| 3735 | dlbaton->size, dlbaton->per_cu); |
| 3736 | |
| 3737 | return val; |
| 3738 | } |
| 3739 | |
| 3740 | /* Return the value of SYMBOL in FRAME at (callee) FRAME's function |
| 3741 | entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR |
| 3742 | will be thrown. */ |
| 3743 | |
| 3744 | static struct value * |
| 3745 | locexpr_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame) |
| 3746 | { |
| 3747 | struct dwarf2_locexpr_baton *dlbaton |
| 3748 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 3749 | |
| 3750 | return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, dlbaton->data, |
| 3751 | dlbaton->size); |
| 3752 | } |
| 3753 | |
| 3754 | /* Implementation of get_symbol_read_needs from |
| 3755 | symbol_computed_ops. */ |
| 3756 | |
| 3757 | static enum symbol_needs_kind |
| 3758 | locexpr_get_symbol_read_needs (struct symbol *symbol) |
| 3759 | { |
| 3760 | struct dwarf2_locexpr_baton *dlbaton |
| 3761 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 3762 | |
| 3763 | return dwarf2_loc_desc_get_symbol_read_needs (dlbaton->data, dlbaton->size, |
| 3764 | dlbaton->per_cu); |
| 3765 | } |
| 3766 | |
| 3767 | /* Return true if DATA points to the end of a piece. END is one past |
| 3768 | the last byte in the expression. */ |
| 3769 | |
| 3770 | static int |
| 3771 | piece_end_p (const gdb_byte *data, const gdb_byte *end) |
| 3772 | { |
| 3773 | return data == end || data[0] == DW_OP_piece || data[0] == DW_OP_bit_piece; |
| 3774 | } |
| 3775 | |
| 3776 | /* Helper for locexpr_describe_location_piece that finds the name of a |
| 3777 | DWARF register. */ |
| 3778 | |
| 3779 | static const char * |
| 3780 | locexpr_regname (struct gdbarch *gdbarch, int dwarf_regnum) |
| 3781 | { |
| 3782 | int regnum; |
| 3783 | |
| 3784 | /* This doesn't use dwarf_reg_to_regnum_or_error on purpose. |
| 3785 | We'd rather print *something* here than throw an error. */ |
| 3786 | regnum = dwarf_reg_to_regnum (gdbarch, dwarf_regnum); |
| 3787 | /* gdbarch_register_name may just return "", return something more |
| 3788 | descriptive for bad register numbers. */ |
| 3789 | if (regnum == -1) |
| 3790 | { |
| 3791 | /* The text is output as "$bad_register_number". |
| 3792 | That is why we use the underscores. */ |
| 3793 | return _("bad_register_number"); |
| 3794 | } |
| 3795 | return gdbarch_register_name (gdbarch, regnum); |
| 3796 | } |
| 3797 | |
| 3798 | /* Nicely describe a single piece of a location, returning an updated |
| 3799 | position in the bytecode sequence. This function cannot recognize |
| 3800 | all locations; if a location is not recognized, it simply returns |
| 3801 | DATA. If there is an error during reading, e.g. we run off the end |
| 3802 | of the buffer, an error is thrown. */ |
| 3803 | |
| 3804 | static const gdb_byte * |
| 3805 | locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream, |
| 3806 | CORE_ADDR addr, struct objfile *objfile, |
| 3807 | struct dwarf2_per_cu_data *per_cu, |
| 3808 | const gdb_byte *data, const gdb_byte *end, |
| 3809 | unsigned int addr_size) |
| 3810 | { |
| 3811 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 3812 | size_t leb128_size; |
| 3813 | |
| 3814 | if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31) |
| 3815 | { |
| 3816 | fprintf_filtered (stream, _("a variable in $%s"), |
| 3817 | locexpr_regname (gdbarch, data[0] - DW_OP_reg0)); |
| 3818 | data += 1; |
| 3819 | } |
| 3820 | else if (data[0] == DW_OP_regx) |
| 3821 | { |
| 3822 | uint64_t reg; |
| 3823 | |
| 3824 | data = safe_read_uleb128 (data + 1, end, ®); |
| 3825 | fprintf_filtered (stream, _("a variable in $%s"), |
| 3826 | locexpr_regname (gdbarch, reg)); |
| 3827 | } |
| 3828 | else if (data[0] == DW_OP_fbreg) |
| 3829 | { |
| 3830 | const struct block *b; |
| 3831 | struct symbol *framefunc; |
| 3832 | int frame_reg = 0; |
| 3833 | int64_t frame_offset; |
| 3834 | const gdb_byte *base_data, *new_data, *save_data = data; |
| 3835 | size_t base_size; |
| 3836 | int64_t base_offset = 0; |
| 3837 | |
| 3838 | new_data = safe_read_sleb128 (data + 1, end, &frame_offset); |
| 3839 | if (!piece_end_p (new_data, end)) |
| 3840 | return data; |
| 3841 | data = new_data; |
| 3842 | |
| 3843 | b = block_for_pc (addr); |
| 3844 | |
| 3845 | if (!b) |
| 3846 | error (_("No block found for address for symbol \"%s\"."), |
| 3847 | SYMBOL_PRINT_NAME (symbol)); |
| 3848 | |
| 3849 | framefunc = block_linkage_function (b); |
| 3850 | |
| 3851 | if (!framefunc) |
| 3852 | error (_("No function found for block for symbol \"%s\"."), |
| 3853 | SYMBOL_PRINT_NAME (symbol)); |
| 3854 | |
| 3855 | func_get_frame_base_dwarf_block (framefunc, addr, &base_data, &base_size); |
| 3856 | |
| 3857 | if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31) |
| 3858 | { |
| 3859 | const gdb_byte *buf_end; |
| 3860 | |
| 3861 | frame_reg = base_data[0] - DW_OP_breg0; |
| 3862 | buf_end = safe_read_sleb128 (base_data + 1, base_data + base_size, |
| 3863 | &base_offset); |
| 3864 | if (buf_end != base_data + base_size) |
| 3865 | error (_("Unexpected opcode after " |
| 3866 | "DW_OP_breg%u for symbol \"%s\"."), |
| 3867 | frame_reg, SYMBOL_PRINT_NAME (symbol)); |
| 3868 | } |
| 3869 | else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31) |
| 3870 | { |
| 3871 | /* The frame base is just the register, with no offset. */ |
| 3872 | frame_reg = base_data[0] - DW_OP_reg0; |
| 3873 | base_offset = 0; |
| 3874 | } |
| 3875 | else |
| 3876 | { |
| 3877 | /* We don't know what to do with the frame base expression, |
| 3878 | so we can't trace this variable; give up. */ |
| 3879 | return save_data; |
| 3880 | } |
| 3881 | |
| 3882 | fprintf_filtered (stream, |
| 3883 | _("a variable at frame base reg $%s offset %s+%s"), |
| 3884 | locexpr_regname (gdbarch, frame_reg), |
| 3885 | plongest (base_offset), plongest (frame_offset)); |
| 3886 | } |
| 3887 | else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31 |
| 3888 | && piece_end_p (data, end)) |
| 3889 | { |
| 3890 | int64_t offset; |
| 3891 | |
| 3892 | data = safe_read_sleb128 (data + 1, end, &offset); |
| 3893 | |
| 3894 | fprintf_filtered (stream, |
| 3895 | _("a variable at offset %s from base reg $%s"), |
| 3896 | plongest (offset), |
| 3897 | locexpr_regname (gdbarch, data[0] - DW_OP_breg0)); |
| 3898 | } |
| 3899 | |
| 3900 | /* The location expression for a TLS variable looks like this (on a |
| 3901 | 64-bit LE machine): |
| 3902 | |
| 3903 | DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0 |
| 3904 | (DW_OP_addr: 4; DW_OP_GNU_push_tls_address) |
| 3905 | |
| 3906 | 0x3 is the encoding for DW_OP_addr, which has an operand as long |
| 3907 | as the size of an address on the target machine (here is 8 |
| 3908 | bytes). Note that more recent version of GCC emit DW_OP_const4u |
| 3909 | or DW_OP_const8u, depending on address size, rather than |
| 3910 | DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address. |
| 3911 | The operand represents the offset at which the variable is within |
| 3912 | the thread local storage. */ |
| 3913 | |
| 3914 | else if (data + 1 + addr_size < end |
| 3915 | && (data[0] == DW_OP_addr |
| 3916 | || (addr_size == 4 && data[0] == DW_OP_const4u) |
| 3917 | || (addr_size == 8 && data[0] == DW_OP_const8u)) |
| 3918 | && (data[1 + addr_size] == DW_OP_GNU_push_tls_address |
| 3919 | || data[1 + addr_size] == DW_OP_form_tls_address) |
| 3920 | && piece_end_p (data + 2 + addr_size, end)) |
| 3921 | { |
| 3922 | ULONGEST offset; |
| 3923 | offset = extract_unsigned_integer (data + 1, addr_size, |
| 3924 | gdbarch_byte_order (gdbarch)); |
| 3925 | |
| 3926 | fprintf_filtered (stream, |
| 3927 | _("a thread-local variable at offset 0x%s " |
| 3928 | "in the thread-local storage for `%s'"), |
| 3929 | phex_nz (offset, addr_size), objfile_name (objfile)); |
| 3930 | |
| 3931 | data += 1 + addr_size + 1; |
| 3932 | } |
| 3933 | |
| 3934 | /* With -gsplit-dwarf a TLS variable can also look like this: |
| 3935 | DW_AT_location : 3 byte block: fc 4 e0 |
| 3936 | (DW_OP_GNU_const_index: 4; |
| 3937 | DW_OP_GNU_push_tls_address) */ |
| 3938 | else if (data + 3 <= end |
| 3939 | && data + 1 + (leb128_size = skip_leb128 (data + 1, end)) < end |
| 3940 | && data[0] == DW_OP_GNU_const_index |
| 3941 | && leb128_size > 0 |
| 3942 | && (data[1 + leb128_size] == DW_OP_GNU_push_tls_address |
| 3943 | || data[1 + leb128_size] == DW_OP_form_tls_address) |
| 3944 | && piece_end_p (data + 2 + leb128_size, end)) |
| 3945 | { |
| 3946 | uint64_t offset; |
| 3947 | |
| 3948 | data = safe_read_uleb128 (data + 1, end, &offset); |
| 3949 | offset = dwarf2_read_addr_index (per_cu, offset); |
| 3950 | fprintf_filtered (stream, |
| 3951 | _("a thread-local variable at offset 0x%s " |
| 3952 | "in the thread-local storage for `%s'"), |
| 3953 | phex_nz (offset, addr_size), objfile_name (objfile)); |
| 3954 | ++data; |
| 3955 | } |
| 3956 | |
| 3957 | else if (data[0] >= DW_OP_lit0 |
| 3958 | && data[0] <= DW_OP_lit31 |
| 3959 | && data + 1 < end |
| 3960 | && data[1] == DW_OP_stack_value) |
| 3961 | { |
| 3962 | fprintf_filtered (stream, _("the constant %d"), data[0] - DW_OP_lit0); |
| 3963 | data += 2; |
| 3964 | } |
| 3965 | |
| 3966 | return data; |
| 3967 | } |
| 3968 | |
| 3969 | /* Disassemble an expression, stopping at the end of a piece or at the |
| 3970 | end of the expression. Returns a pointer to the next unread byte |
| 3971 | in the input expression. If ALL is nonzero, then this function |
| 3972 | will keep going until it reaches the end of the expression. |
| 3973 | If there is an error during reading, e.g. we run off the end |
| 3974 | of the buffer, an error is thrown. */ |
| 3975 | |
| 3976 | static const gdb_byte * |
| 3977 | disassemble_dwarf_expression (struct ui_file *stream, |
| 3978 | struct gdbarch *arch, unsigned int addr_size, |
| 3979 | int offset_size, const gdb_byte *start, |
| 3980 | const gdb_byte *data, const gdb_byte *end, |
| 3981 | int indent, int all, |
| 3982 | struct dwarf2_per_cu_data *per_cu) |
| 3983 | { |
| 3984 | while (data < end |
| 3985 | && (all |
| 3986 | || (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece))) |
| 3987 | { |
| 3988 | enum dwarf_location_atom op = (enum dwarf_location_atom) *data++; |
| 3989 | uint64_t ul; |
| 3990 | int64_t l; |
| 3991 | const char *name; |
| 3992 | |
| 3993 | name = get_DW_OP_name (op); |
| 3994 | |
| 3995 | if (!name) |
| 3996 | error (_("Unrecognized DWARF opcode 0x%02x at %ld"), |
| 3997 | op, (long) (data - 1 - start)); |
| 3998 | fprintf_filtered (stream, " %*ld: %s", indent + 4, |
| 3999 | (long) (data - 1 - start), name); |
| 4000 | |
| 4001 | switch (op) |
| 4002 | { |
| 4003 | case DW_OP_addr: |
| 4004 | ul = extract_unsigned_integer (data, addr_size, |
| 4005 | gdbarch_byte_order (arch)); |
| 4006 | data += addr_size; |
| 4007 | fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size)); |
| 4008 | break; |
| 4009 | |
| 4010 | case DW_OP_const1u: |
| 4011 | ul = extract_unsigned_integer (data, 1, gdbarch_byte_order (arch)); |
| 4012 | data += 1; |
| 4013 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4014 | break; |
| 4015 | case DW_OP_const1s: |
| 4016 | l = extract_signed_integer (data, 1, gdbarch_byte_order (arch)); |
| 4017 | data += 1; |
| 4018 | fprintf_filtered (stream, " %s", plongest (l)); |
| 4019 | break; |
| 4020 | case DW_OP_const2u: |
| 4021 | ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch)); |
| 4022 | data += 2; |
| 4023 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4024 | break; |
| 4025 | case DW_OP_const2s: |
| 4026 | l = extract_signed_integer (data, 2, gdbarch_byte_order (arch)); |
| 4027 | data += 2; |
| 4028 | fprintf_filtered (stream, " %s", plongest (l)); |
| 4029 | break; |
| 4030 | case DW_OP_const4u: |
| 4031 | ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch)); |
| 4032 | data += 4; |
| 4033 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4034 | break; |
| 4035 | case DW_OP_const4s: |
| 4036 | l = extract_signed_integer (data, 4, gdbarch_byte_order (arch)); |
| 4037 | data += 4; |
| 4038 | fprintf_filtered (stream, " %s", plongest (l)); |
| 4039 | break; |
| 4040 | case DW_OP_const8u: |
| 4041 | ul = extract_unsigned_integer (data, 8, gdbarch_byte_order (arch)); |
| 4042 | data += 8; |
| 4043 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4044 | break; |
| 4045 | case DW_OP_const8s: |
| 4046 | l = extract_signed_integer (data, 8, gdbarch_byte_order (arch)); |
| 4047 | data += 8; |
| 4048 | fprintf_filtered (stream, " %s", plongest (l)); |
| 4049 | break; |
| 4050 | case DW_OP_constu: |
| 4051 | data = safe_read_uleb128 (data, end, &ul); |
| 4052 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4053 | break; |
| 4054 | case DW_OP_consts: |
| 4055 | data = safe_read_sleb128 (data, end, &l); |
| 4056 | fprintf_filtered (stream, " %s", plongest (l)); |
| 4057 | break; |
| 4058 | |
| 4059 | case DW_OP_reg0: |
| 4060 | case DW_OP_reg1: |
| 4061 | case DW_OP_reg2: |
| 4062 | case DW_OP_reg3: |
| 4063 | case DW_OP_reg4: |
| 4064 | case DW_OP_reg5: |
| 4065 | case DW_OP_reg6: |
| 4066 | case DW_OP_reg7: |
| 4067 | case DW_OP_reg8: |
| 4068 | case DW_OP_reg9: |
| 4069 | case DW_OP_reg10: |
| 4070 | case DW_OP_reg11: |
| 4071 | case DW_OP_reg12: |
| 4072 | case DW_OP_reg13: |
| 4073 | case DW_OP_reg14: |
| 4074 | case DW_OP_reg15: |
| 4075 | case DW_OP_reg16: |
| 4076 | case DW_OP_reg17: |
| 4077 | case DW_OP_reg18: |
| 4078 | case DW_OP_reg19: |
| 4079 | case DW_OP_reg20: |
| 4080 | case DW_OP_reg21: |
| 4081 | case DW_OP_reg22: |
| 4082 | case DW_OP_reg23: |
| 4083 | case DW_OP_reg24: |
| 4084 | case DW_OP_reg25: |
| 4085 | case DW_OP_reg26: |
| 4086 | case DW_OP_reg27: |
| 4087 | case DW_OP_reg28: |
| 4088 | case DW_OP_reg29: |
| 4089 | case DW_OP_reg30: |
| 4090 | case DW_OP_reg31: |
| 4091 | fprintf_filtered (stream, " [$%s]", |
| 4092 | locexpr_regname (arch, op - DW_OP_reg0)); |
| 4093 | break; |
| 4094 | |
| 4095 | case DW_OP_regx: |
| 4096 | data = safe_read_uleb128 (data, end, &ul); |
| 4097 | fprintf_filtered (stream, " %s [$%s]", pulongest (ul), |
| 4098 | locexpr_regname (arch, (int) ul)); |
| 4099 | break; |
| 4100 | |
| 4101 | case DW_OP_implicit_value: |
| 4102 | data = safe_read_uleb128 (data, end, &ul); |
| 4103 | data += ul; |
| 4104 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4105 | break; |
| 4106 | |
| 4107 | case DW_OP_breg0: |
| 4108 | case DW_OP_breg1: |
| 4109 | case DW_OP_breg2: |
| 4110 | case DW_OP_breg3: |
| 4111 | case DW_OP_breg4: |
| 4112 | case DW_OP_breg5: |
| 4113 | case DW_OP_breg6: |
| 4114 | case DW_OP_breg7: |
| 4115 | case DW_OP_breg8: |
| 4116 | case DW_OP_breg9: |
| 4117 | case DW_OP_breg10: |
| 4118 | case DW_OP_breg11: |
| 4119 | case DW_OP_breg12: |
| 4120 | case DW_OP_breg13: |
| 4121 | case DW_OP_breg14: |
| 4122 | case DW_OP_breg15: |
| 4123 | case DW_OP_breg16: |
| 4124 | case DW_OP_breg17: |
| 4125 | case DW_OP_breg18: |
| 4126 | case DW_OP_breg19: |
| 4127 | case DW_OP_breg20: |
| 4128 | case DW_OP_breg21: |
| 4129 | case DW_OP_breg22: |
| 4130 | case DW_OP_breg23: |
| 4131 | case DW_OP_breg24: |
| 4132 | case DW_OP_breg25: |
| 4133 | case DW_OP_breg26: |
| 4134 | case DW_OP_breg27: |
| 4135 | case DW_OP_breg28: |
| 4136 | case DW_OP_breg29: |
| 4137 | case DW_OP_breg30: |
| 4138 | case DW_OP_breg31: |
| 4139 | data = safe_read_sleb128 (data, end, &l); |
| 4140 | fprintf_filtered (stream, " %s [$%s]", plongest (l), |
| 4141 | locexpr_regname (arch, op - DW_OP_breg0)); |
| 4142 | break; |
| 4143 | |
| 4144 | case DW_OP_bregx: |
| 4145 | data = safe_read_uleb128 (data, end, &ul); |
| 4146 | data = safe_read_sleb128 (data, end, &l); |
| 4147 | fprintf_filtered (stream, " register %s [$%s] offset %s", |
| 4148 | pulongest (ul), |
| 4149 | locexpr_regname (arch, (int) ul), |
| 4150 | plongest (l)); |
| 4151 | break; |
| 4152 | |
| 4153 | case DW_OP_fbreg: |
| 4154 | data = safe_read_sleb128 (data, end, &l); |
| 4155 | fprintf_filtered (stream, " %s", plongest (l)); |
| 4156 | break; |
| 4157 | |
| 4158 | case DW_OP_xderef_size: |
| 4159 | case DW_OP_deref_size: |
| 4160 | case DW_OP_pick: |
| 4161 | fprintf_filtered (stream, " %d", *data); |
| 4162 | ++data; |
| 4163 | break; |
| 4164 | |
| 4165 | case DW_OP_plus_uconst: |
| 4166 | data = safe_read_uleb128 (data, end, &ul); |
| 4167 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4168 | break; |
| 4169 | |
| 4170 | case DW_OP_skip: |
| 4171 | l = extract_signed_integer (data, 2, gdbarch_byte_order (arch)); |
| 4172 | data += 2; |
| 4173 | fprintf_filtered (stream, " to %ld", |
| 4174 | (long) (data + l - start)); |
| 4175 | break; |
| 4176 | |
| 4177 | case DW_OP_bra: |
| 4178 | l = extract_signed_integer (data, 2, gdbarch_byte_order (arch)); |
| 4179 | data += 2; |
| 4180 | fprintf_filtered (stream, " %ld", |
| 4181 | (long) (data + l - start)); |
| 4182 | break; |
| 4183 | |
| 4184 | case DW_OP_call2: |
| 4185 | ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch)); |
| 4186 | data += 2; |
| 4187 | fprintf_filtered (stream, " offset %s", phex_nz (ul, 2)); |
| 4188 | break; |
| 4189 | |
| 4190 | case DW_OP_call4: |
| 4191 | ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch)); |
| 4192 | data += 4; |
| 4193 | fprintf_filtered (stream, " offset %s", phex_nz (ul, 4)); |
| 4194 | break; |
| 4195 | |
| 4196 | case DW_OP_call_ref: |
| 4197 | ul = extract_unsigned_integer (data, offset_size, |
| 4198 | gdbarch_byte_order (arch)); |
| 4199 | data += offset_size; |
| 4200 | fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size)); |
| 4201 | break; |
| 4202 | |
| 4203 | case DW_OP_piece: |
| 4204 | data = safe_read_uleb128 (data, end, &ul); |
| 4205 | fprintf_filtered (stream, " %s (bytes)", pulongest (ul)); |
| 4206 | break; |
| 4207 | |
| 4208 | case DW_OP_bit_piece: |
| 4209 | { |
| 4210 | uint64_t offset; |
| 4211 | |
| 4212 | data = safe_read_uleb128 (data, end, &ul); |
| 4213 | data = safe_read_uleb128 (data, end, &offset); |
| 4214 | fprintf_filtered (stream, " size %s offset %s (bits)", |
| 4215 | pulongest (ul), pulongest (offset)); |
| 4216 | } |
| 4217 | break; |
| 4218 | |
| 4219 | case DW_OP_implicit_pointer: |
| 4220 | case DW_OP_GNU_implicit_pointer: |
| 4221 | { |
| 4222 | ul = extract_unsigned_integer (data, offset_size, |
| 4223 | gdbarch_byte_order (arch)); |
| 4224 | data += offset_size; |
| 4225 | |
| 4226 | data = safe_read_sleb128 (data, end, &l); |
| 4227 | |
| 4228 | fprintf_filtered (stream, " DIE %s offset %s", |
| 4229 | phex_nz (ul, offset_size), |
| 4230 | plongest (l)); |
| 4231 | } |
| 4232 | break; |
| 4233 | |
| 4234 | case DW_OP_deref_type: |
| 4235 | case DW_OP_GNU_deref_type: |
| 4236 | { |
| 4237 | int addr_size = *data++; |
| 4238 | struct type *type; |
| 4239 | |
| 4240 | data = safe_read_uleb128 (data, end, &ul); |
| 4241 | cu_offset offset = (cu_offset) ul; |
| 4242 | type = dwarf2_get_die_type (offset, per_cu); |
| 4243 | fprintf_filtered (stream, "<"); |
| 4244 | type_print (type, "", stream, -1); |
| 4245 | fprintf_filtered (stream, " [0x%s]> %d", |
| 4246 | phex_nz (to_underlying (offset), 0), |
| 4247 | addr_size); |
| 4248 | } |
| 4249 | break; |
| 4250 | |
| 4251 | case DW_OP_const_type: |
| 4252 | case DW_OP_GNU_const_type: |
| 4253 | { |
| 4254 | struct type *type; |
| 4255 | |
| 4256 | data = safe_read_uleb128 (data, end, &ul); |
| 4257 | cu_offset type_die = (cu_offset) ul; |
| 4258 | type = dwarf2_get_die_type (type_die, per_cu); |
| 4259 | fprintf_filtered (stream, "<"); |
| 4260 | type_print (type, "", stream, -1); |
| 4261 | fprintf_filtered (stream, " [0x%s]>", |
| 4262 | phex_nz (to_underlying (type_die), 0)); |
| 4263 | } |
| 4264 | break; |
| 4265 | |
| 4266 | case DW_OP_regval_type: |
| 4267 | case DW_OP_GNU_regval_type: |
| 4268 | { |
| 4269 | uint64_t reg; |
| 4270 | struct type *type; |
| 4271 | |
| 4272 | data = safe_read_uleb128 (data, end, ®); |
| 4273 | data = safe_read_uleb128 (data, end, &ul); |
| 4274 | cu_offset type_die = (cu_offset) ul; |
| 4275 | |
| 4276 | type = dwarf2_get_die_type (type_die, per_cu); |
| 4277 | fprintf_filtered (stream, "<"); |
| 4278 | type_print (type, "", stream, -1); |
| 4279 | fprintf_filtered (stream, " [0x%s]> [$%s]", |
| 4280 | phex_nz (to_underlying (type_die), 0), |
| 4281 | locexpr_regname (arch, reg)); |
| 4282 | } |
| 4283 | break; |
| 4284 | |
| 4285 | case DW_OP_convert: |
| 4286 | case DW_OP_GNU_convert: |
| 4287 | case DW_OP_reinterpret: |
| 4288 | case DW_OP_GNU_reinterpret: |
| 4289 | { |
| 4290 | data = safe_read_uleb128 (data, end, &ul); |
| 4291 | cu_offset type_die = (cu_offset) ul; |
| 4292 | |
| 4293 | if (to_underlying (type_die) == 0) |
| 4294 | fprintf_filtered (stream, "<0>"); |
| 4295 | else |
| 4296 | { |
| 4297 | struct type *type; |
| 4298 | |
| 4299 | type = dwarf2_get_die_type (type_die, per_cu); |
| 4300 | fprintf_filtered (stream, "<"); |
| 4301 | type_print (type, "", stream, -1); |
| 4302 | fprintf_filtered (stream, " [0x%s]>", |
| 4303 | phex_nz (to_underlying (type_die), 0)); |
| 4304 | } |
| 4305 | } |
| 4306 | break; |
| 4307 | |
| 4308 | case DW_OP_entry_value: |
| 4309 | case DW_OP_GNU_entry_value: |
| 4310 | data = safe_read_uleb128 (data, end, &ul); |
| 4311 | fputc_filtered ('\n', stream); |
| 4312 | disassemble_dwarf_expression (stream, arch, addr_size, offset_size, |
| 4313 | start, data, data + ul, indent + 2, |
| 4314 | all, per_cu); |
| 4315 | data += ul; |
| 4316 | continue; |
| 4317 | |
| 4318 | case DW_OP_GNU_parameter_ref: |
| 4319 | ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch)); |
| 4320 | data += 4; |
| 4321 | fprintf_filtered (stream, " offset %s", phex_nz (ul, 4)); |
| 4322 | break; |
| 4323 | |
| 4324 | case DW_OP_GNU_addr_index: |
| 4325 | data = safe_read_uleb128 (data, end, &ul); |
| 4326 | ul = dwarf2_read_addr_index (per_cu, ul); |
| 4327 | fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size)); |
| 4328 | break; |
| 4329 | case DW_OP_GNU_const_index: |
| 4330 | data = safe_read_uleb128 (data, end, &ul); |
| 4331 | ul = dwarf2_read_addr_index (per_cu, ul); |
| 4332 | fprintf_filtered (stream, " %s", pulongest (ul)); |
| 4333 | break; |
| 4334 | |
| 4335 | case DW_OP_GNU_variable_value: |
| 4336 | ul = extract_unsigned_integer (data, offset_size, |
| 4337 | gdbarch_byte_order (arch)); |
| 4338 | data += offset_size; |
| 4339 | fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size)); |
| 4340 | break; |
| 4341 | } |
| 4342 | |
| 4343 | fprintf_filtered (stream, "\n"); |
| 4344 | } |
| 4345 | |
| 4346 | return data; |
| 4347 | } |
| 4348 | |
| 4349 | /* Describe a single location, which may in turn consist of multiple |
| 4350 | pieces. */ |
| 4351 | |
| 4352 | static void |
| 4353 | locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr, |
| 4354 | struct ui_file *stream, |
| 4355 | const gdb_byte *data, size_t size, |
| 4356 | struct objfile *objfile, unsigned int addr_size, |
| 4357 | int offset_size, struct dwarf2_per_cu_data *per_cu) |
| 4358 | { |
| 4359 | const gdb_byte *end = data + size; |
| 4360 | int first_piece = 1, bad = 0; |
| 4361 | |
| 4362 | while (data < end) |
| 4363 | { |
| 4364 | const gdb_byte *here = data; |
| 4365 | int disassemble = 1; |
| 4366 | |
| 4367 | if (first_piece) |
| 4368 | first_piece = 0; |
| 4369 | else |
| 4370 | fprintf_filtered (stream, _(", and ")); |
| 4371 | |
| 4372 | if (!dwarf_always_disassemble) |
| 4373 | { |
| 4374 | data = locexpr_describe_location_piece (symbol, stream, |
| 4375 | addr, objfile, per_cu, |
| 4376 | data, end, addr_size); |
| 4377 | /* If we printed anything, or if we have an empty piece, |
| 4378 | then don't disassemble. */ |
| 4379 | if (data != here |
| 4380 | || data[0] == DW_OP_piece |
| 4381 | || data[0] == DW_OP_bit_piece) |
| 4382 | disassemble = 0; |
| 4383 | } |
| 4384 | if (disassemble) |
| 4385 | { |
| 4386 | fprintf_filtered (stream, _("a complex DWARF expression:\n")); |
| 4387 | data = disassemble_dwarf_expression (stream, |
| 4388 | get_objfile_arch (objfile), |
| 4389 | addr_size, offset_size, data, |
| 4390 | data, end, 0, |
| 4391 | dwarf_always_disassemble, |
| 4392 | per_cu); |
| 4393 | } |
| 4394 | |
| 4395 | if (data < end) |
| 4396 | { |
| 4397 | int empty = data == here; |
| 4398 | |
| 4399 | if (disassemble) |
| 4400 | fprintf_filtered (stream, " "); |
| 4401 | if (data[0] == DW_OP_piece) |
| 4402 | { |
| 4403 | uint64_t bytes; |
| 4404 | |
| 4405 | data = safe_read_uleb128 (data + 1, end, &bytes); |
| 4406 | |
| 4407 | if (empty) |
| 4408 | fprintf_filtered (stream, _("an empty %s-byte piece"), |
| 4409 | pulongest (bytes)); |
| 4410 | else |
| 4411 | fprintf_filtered (stream, _(" [%s-byte piece]"), |
| 4412 | pulongest (bytes)); |
| 4413 | } |
| 4414 | else if (data[0] == DW_OP_bit_piece) |
| 4415 | { |
| 4416 | uint64_t bits, offset; |
| 4417 | |
| 4418 | data = safe_read_uleb128 (data + 1, end, &bits); |
| 4419 | data = safe_read_uleb128 (data, end, &offset); |
| 4420 | |
| 4421 | if (empty) |
| 4422 | fprintf_filtered (stream, |
| 4423 | _("an empty %s-bit piece"), |
| 4424 | pulongest (bits)); |
| 4425 | else |
| 4426 | fprintf_filtered (stream, |
| 4427 | _(" [%s-bit piece, offset %s bits]"), |
| 4428 | pulongest (bits), pulongest (offset)); |
| 4429 | } |
| 4430 | else |
| 4431 | { |
| 4432 | bad = 1; |
| 4433 | break; |
| 4434 | } |
| 4435 | } |
| 4436 | } |
| 4437 | |
| 4438 | if (bad || data > end) |
| 4439 | error (_("Corrupted DWARF2 expression for \"%s\"."), |
| 4440 | SYMBOL_PRINT_NAME (symbol)); |
| 4441 | } |
| 4442 | |
| 4443 | /* Print a natural-language description of SYMBOL to STREAM. This |
| 4444 | version is for a symbol with a single location. */ |
| 4445 | |
| 4446 | static void |
| 4447 | locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr, |
| 4448 | struct ui_file *stream) |
| 4449 | { |
| 4450 | struct dwarf2_locexpr_baton *dlbaton |
| 4451 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 4452 | struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); |
| 4453 | unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 4454 | int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu); |
| 4455 | |
| 4456 | locexpr_describe_location_1 (symbol, addr, stream, |
| 4457 | dlbaton->data, dlbaton->size, |
| 4458 | objfile, addr_size, offset_size, |
| 4459 | dlbaton->per_cu); |
| 4460 | } |
| 4461 | |
| 4462 | /* Describe the location of SYMBOL as an agent value in VALUE, generating |
| 4463 | any necessary bytecode in AX. */ |
| 4464 | |
| 4465 | static void |
| 4466 | locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, |
| 4467 | struct axs_value *value) |
| 4468 | { |
| 4469 | struct dwarf2_locexpr_baton *dlbaton |
| 4470 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 4471 | unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 4472 | |
| 4473 | if (dlbaton->size == 0) |
| 4474 | value->optimized_out = 1; |
| 4475 | else |
| 4476 | dwarf2_compile_expr_to_ax (ax, value, addr_size, dlbaton->data, |
| 4477 | dlbaton->data + dlbaton->size, dlbaton->per_cu); |
| 4478 | } |
| 4479 | |
| 4480 | /* symbol_computed_ops 'generate_c_location' method. */ |
| 4481 | |
| 4482 | static void |
| 4483 | locexpr_generate_c_location (struct symbol *sym, string_file *stream, |
| 4484 | struct gdbarch *gdbarch, |
| 4485 | unsigned char *registers_used, |
| 4486 | CORE_ADDR pc, const char *result_name) |
| 4487 | { |
| 4488 | struct dwarf2_locexpr_baton *dlbaton |
| 4489 | = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym); |
| 4490 | unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 4491 | |
| 4492 | if (dlbaton->size == 0) |
| 4493 | error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym)); |
| 4494 | |
| 4495 | compile_dwarf_expr_to_c (stream, result_name, |
| 4496 | sym, pc, gdbarch, registers_used, addr_size, |
| 4497 | dlbaton->data, dlbaton->data + dlbaton->size, |
| 4498 | dlbaton->per_cu); |
| 4499 | } |
| 4500 | |
| 4501 | /* The set of location functions used with the DWARF-2 expression |
| 4502 | evaluator. */ |
| 4503 | const struct symbol_computed_ops dwarf2_locexpr_funcs = { |
| 4504 | locexpr_read_variable, |
| 4505 | locexpr_read_variable_at_entry, |
| 4506 | locexpr_get_symbol_read_needs, |
| 4507 | locexpr_describe_location, |
| 4508 | 0, /* location_has_loclist */ |
| 4509 | locexpr_tracepoint_var_ref, |
| 4510 | locexpr_generate_c_location |
| 4511 | }; |
| 4512 | |
| 4513 | |
| 4514 | /* Wrapper functions for location lists. These generally find |
| 4515 | the appropriate location expression and call something above. */ |
| 4516 | |
| 4517 | /* Return the value of SYMBOL in FRAME using the DWARF-2 expression |
| 4518 | evaluator to calculate the location. */ |
| 4519 | static struct value * |
| 4520 | loclist_read_variable (struct symbol *symbol, struct frame_info *frame) |
| 4521 | { |
| 4522 | struct dwarf2_loclist_baton *dlbaton |
| 4523 | = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 4524 | struct value *val; |
| 4525 | const gdb_byte *data; |
| 4526 | size_t size; |
| 4527 | CORE_ADDR pc = frame ? get_frame_address_in_block (frame) : 0; |
| 4528 | |
| 4529 | data = dwarf2_find_location_expression (dlbaton, &size, pc); |
| 4530 | val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size, |
| 4531 | dlbaton->per_cu); |
| 4532 | |
| 4533 | return val; |
| 4534 | } |
| 4535 | |
| 4536 | /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function |
| 4537 | entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR |
| 4538 | will be thrown. |
| 4539 | |
| 4540 | Function always returns non-NULL value, it may be marked optimized out if |
| 4541 | inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR |
| 4542 | if it cannot resolve the parameter for any reason. */ |
| 4543 | |
| 4544 | static struct value * |
| 4545 | loclist_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame) |
| 4546 | { |
| 4547 | struct dwarf2_loclist_baton *dlbaton |
| 4548 | = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 4549 | const gdb_byte *data; |
| 4550 | size_t size; |
| 4551 | CORE_ADDR pc; |
| 4552 | |
| 4553 | if (frame == NULL || !get_frame_func_if_available (frame, &pc)) |
| 4554 | return allocate_optimized_out_value (SYMBOL_TYPE (symbol)); |
| 4555 | |
| 4556 | data = dwarf2_find_location_expression (dlbaton, &size, pc); |
| 4557 | if (data == NULL) |
| 4558 | return allocate_optimized_out_value (SYMBOL_TYPE (symbol)); |
| 4559 | |
| 4560 | return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, data, size); |
| 4561 | } |
| 4562 | |
| 4563 | /* Implementation of get_symbol_read_needs from |
| 4564 | symbol_computed_ops. */ |
| 4565 | |
| 4566 | static enum symbol_needs_kind |
| 4567 | loclist_symbol_needs (struct symbol *symbol) |
| 4568 | { |
| 4569 | /* If there's a location list, then assume we need to have a frame |
| 4570 | to choose the appropriate location expression. With tracking of |
| 4571 | global variables this is not necessarily true, but such tracking |
| 4572 | is disabled in GCC at the moment until we figure out how to |
| 4573 | represent it. */ |
| 4574 | |
| 4575 | return SYMBOL_NEEDS_FRAME; |
| 4576 | } |
| 4577 | |
| 4578 | /* Print a natural-language description of SYMBOL to STREAM. This |
| 4579 | version applies when there is a list of different locations, each |
| 4580 | with a specified address range. */ |
| 4581 | |
| 4582 | static void |
| 4583 | loclist_describe_location (struct symbol *symbol, CORE_ADDR addr, |
| 4584 | struct ui_file *stream) |
| 4585 | { |
| 4586 | struct dwarf2_loclist_baton *dlbaton |
| 4587 | = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 4588 | const gdb_byte *loc_ptr, *buf_end; |
| 4589 | struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); |
| 4590 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 4591 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 4592 | unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 4593 | int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu); |
| 4594 | int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd); |
| 4595 | /* Adjust base_address for relocatable objects. */ |
| 4596 | CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu); |
| 4597 | CORE_ADDR base_address = dlbaton->base_address + base_offset; |
| 4598 | int done = 0; |
| 4599 | |
| 4600 | loc_ptr = dlbaton->data; |
| 4601 | buf_end = dlbaton->data + dlbaton->size; |
| 4602 | |
| 4603 | fprintf_filtered (stream, _("multi-location:\n")); |
| 4604 | |
| 4605 | /* Iterate through locations until we run out. */ |
| 4606 | while (!done) |
| 4607 | { |
| 4608 | CORE_ADDR low = 0, high = 0; /* init for gcc -Wall */ |
| 4609 | int length; |
| 4610 | enum debug_loc_kind kind; |
| 4611 | const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */ |
| 4612 | |
| 4613 | if (dlbaton->from_dwo) |
| 4614 | kind = decode_debug_loc_dwo_addresses (dlbaton->per_cu, |
| 4615 | loc_ptr, buf_end, &new_ptr, |
| 4616 | &low, &high, byte_order); |
| 4617 | else |
| 4618 | kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr, |
| 4619 | &low, &high, |
| 4620 | byte_order, addr_size, |
| 4621 | signed_addr_p); |
| 4622 | loc_ptr = new_ptr; |
| 4623 | switch (kind) |
| 4624 | { |
| 4625 | case DEBUG_LOC_END_OF_LIST: |
| 4626 | done = 1; |
| 4627 | continue; |
| 4628 | case DEBUG_LOC_BASE_ADDRESS: |
| 4629 | base_address = high + base_offset; |
| 4630 | fprintf_filtered (stream, _(" Base address %s"), |
| 4631 | paddress (gdbarch, base_address)); |
| 4632 | continue; |
| 4633 | case DEBUG_LOC_START_END: |
| 4634 | case DEBUG_LOC_START_LENGTH: |
| 4635 | break; |
| 4636 | case DEBUG_LOC_BUFFER_OVERFLOW: |
| 4637 | case DEBUG_LOC_INVALID_ENTRY: |
| 4638 | error (_("Corrupted DWARF expression for symbol \"%s\"."), |
| 4639 | SYMBOL_PRINT_NAME (symbol)); |
| 4640 | default: |
| 4641 | gdb_assert_not_reached ("bad debug_loc_kind"); |
| 4642 | } |
| 4643 | |
| 4644 | /* Otherwise, a location expression entry. */ |
| 4645 | low += base_address; |
| 4646 | high += base_address; |
| 4647 | |
| 4648 | low = gdbarch_adjust_dwarf2_addr (gdbarch, low); |
| 4649 | high = gdbarch_adjust_dwarf2_addr (gdbarch, high); |
| 4650 | |
| 4651 | length = extract_unsigned_integer (loc_ptr, 2, byte_order); |
| 4652 | loc_ptr += 2; |
| 4653 | |
| 4654 | /* (It would improve readability to print only the minimum |
| 4655 | necessary digits of the second number of the range.) */ |
| 4656 | fprintf_filtered (stream, _(" Range %s-%s: "), |
| 4657 | paddress (gdbarch, low), paddress (gdbarch, high)); |
| 4658 | |
| 4659 | /* Now describe this particular location. */ |
| 4660 | locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length, |
| 4661 | objfile, addr_size, offset_size, |
| 4662 | dlbaton->per_cu); |
| 4663 | |
| 4664 | fprintf_filtered (stream, "\n"); |
| 4665 | |
| 4666 | loc_ptr += length; |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | /* Describe the location of SYMBOL as an agent value in VALUE, generating |
| 4671 | any necessary bytecode in AX. */ |
| 4672 | static void |
| 4673 | loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, |
| 4674 | struct axs_value *value) |
| 4675 | { |
| 4676 | struct dwarf2_loclist_baton *dlbaton |
| 4677 | = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); |
| 4678 | const gdb_byte *data; |
| 4679 | size_t size; |
| 4680 | unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 4681 | |
| 4682 | data = dwarf2_find_location_expression (dlbaton, &size, ax->scope); |
| 4683 | if (size == 0) |
| 4684 | value->optimized_out = 1; |
| 4685 | else |
| 4686 | dwarf2_compile_expr_to_ax (ax, value, addr_size, data, data + size, |
| 4687 | dlbaton->per_cu); |
| 4688 | } |
| 4689 | |
| 4690 | /* symbol_computed_ops 'generate_c_location' method. */ |
| 4691 | |
| 4692 | static void |
| 4693 | loclist_generate_c_location (struct symbol *sym, string_file *stream, |
| 4694 | struct gdbarch *gdbarch, |
| 4695 | unsigned char *registers_used, |
| 4696 | CORE_ADDR pc, const char *result_name) |
| 4697 | { |
| 4698 | struct dwarf2_loclist_baton *dlbaton |
| 4699 | = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym); |
| 4700 | unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); |
| 4701 | const gdb_byte *data; |
| 4702 | size_t size; |
| 4703 | |
| 4704 | data = dwarf2_find_location_expression (dlbaton, &size, pc); |
| 4705 | if (size == 0) |
| 4706 | error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym)); |
| 4707 | |
| 4708 | compile_dwarf_expr_to_c (stream, result_name, |
| 4709 | sym, pc, gdbarch, registers_used, addr_size, |
| 4710 | data, data + size, |
| 4711 | dlbaton->per_cu); |
| 4712 | } |
| 4713 | |
| 4714 | /* The set of location functions used with the DWARF-2 expression |
| 4715 | evaluator and location lists. */ |
| 4716 | const struct symbol_computed_ops dwarf2_loclist_funcs = { |
| 4717 | loclist_read_variable, |
| 4718 | loclist_read_variable_at_entry, |
| 4719 | loclist_symbol_needs, |
| 4720 | loclist_describe_location, |
| 4721 | 1, /* location_has_loclist */ |
| 4722 | loclist_tracepoint_var_ref, |
| 4723 | loclist_generate_c_location |
| 4724 | }; |
| 4725 | |
| 4726 | void |
| 4727 | _initialize_dwarf2loc (void) |
| 4728 | { |
| 4729 | add_setshow_zuinteger_cmd ("entry-values", class_maintenance, |
| 4730 | &entry_values_debug, |
| 4731 | _("Set entry values and tail call frames " |
| 4732 | "debugging."), |
| 4733 | _("Show entry values and tail call frames " |
| 4734 | "debugging."), |
| 4735 | _("When non-zero, the process of determining " |
| 4736 | "parameter values from function entry point " |
| 4737 | "and tail call frames will be printed."), |
| 4738 | NULL, |
| 4739 | show_entry_values_debug, |
| 4740 | &setdebuglist, &showdebuglist); |
| 4741 | |
| 4742 | #if GDB_SELF_TEST |
| 4743 | selftests::register_test ("copy_bitwise", selftests::copy_bitwise_tests); |
| 4744 | #endif |
| 4745 | } |