40#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
41#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
61 uint8_t addr_byte_size) {
62 if (!const_value_byte_size)
74 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum,
75 bool IsEH) -> llvm::StringRef {
78 if (std::optional<unsigned> LLVMRegNum =
79 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
80 if (
const char *RegName = MCRegInfo->getName(*LLVMRegNum))
81 return llvm::StringRef(RegName);
84 llvm::DIDumpOptions DumpOpts;
85 DumpOpts.GetNameForDWARFReg = GetRegName;
99 uint32_t reg_num,
Status *error_ptr,
101 if (reg_ctx ==
nullptr) {
105 uint32_t native_reg =
110 "kind=%u reg_num=%u to a native "
111 "register number.\n",
130 "register %s can't be converted to a scalar value",
147 const uint8_t op,
const DWARFUnit *dwarf_cu) {
247 case DW_OP_push_object_address:
248 case DW_OP_form_tls_address:
249 case DW_OP_call_frame_cfa:
250 case DW_OP_stack_value:
251 case DW_OP_GNU_push_tls_address:
258 case DW_OP_deref_size:
259 case DW_OP_xderef_size:
285 case DW_OP_plus_uconst:
321 case DW_OP_GNU_addr_index:
322 case DW_OP_GNU_const_index:
324 return offset - data_offset;
328 case DW_OP_bit_piece:
331 return offset - data_offset;
333 case DW_OP_implicit_value:
338 return offset - data_offset;
341 case DW_OP_GNU_entry_value:
342 case DW_OP_entry_value:
344 uint64_t subexpr_len = data.
GetULEB128(&offset);
345 return (offset - data_offset) + subexpr_len;
353 data, data_offset, op);
364 if (op == DW_OP_addr)
366 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
379 offset += op_arg_size;
390 if (op == DW_OP_addr) {
412 if (op == DW_OP_addrx) {
416 llvm::ArrayRef data_before_op =
m_data.
GetData().take_front(offset - 1);
421 if (old_offset == offset)
423 llvm::ArrayRef data_after_op =
m_data.
GetData().drop_front(offset);
437 offset += op_arg_size;
448 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
454 offset += op_arg_size;
461 &link_address_callback) {
475 size_t const_byte_size = 0;
479 bool decoded_data =
false;
484 const_offset = offset;
493 const_offset = offset;
499 case DW_OP_form_tls_address:
500 case DW_OP_GNU_push_tls_address:
511 if (const_byte_size > 0) {
512 lldb::addr_t linked_file_addr = link_address_callback(const_value);
516 if (encoder.
PutUnsigned(const_offset, const_byte_size,
535 offset += op_arg_size;
595 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: no exe/reg context");
601 if (!current_frame || !thread) {
602 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: no current frame/thread");
611 for (uint32_t parent_frame_idx = current_frame_idx + 1;
612 parent_frame_idx < num_frames; ++parent_frame_idx) {
622 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
624 "Evaluate_DW_OP_entry_value: immediate ancestor with pc = {0:x}",
630 if (parent_frame->IsInlined())
636 if (!parent_frame || !parent_frame->GetRegisterContext()) {
637 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: no parent frame with reg ctx");
642 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
644 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: no parent function");
653 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: no current function");
661 if (!parent_frame->IsArtificial()) {
667 "Evaluate_DW_OP_entry_value: no call edge for retn-pc = {0:x} "
668 "in parent frame {1}",
669 return_pc, parent_func->
GetName());
673 if (callee_func != current_func) {
674 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: ambiguous call sequence, "
675 "can't find real parent frame");
683 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
684 call_edge = edge.get();
690 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: no unambiguous edge from parent "
691 "to current function");
698 const uint32_t subexpr_len = opcodes.
GetULEB128(&opcode_offset);
699 const void *subexpr_data = opcodes.
GetData(&opcode_offset, subexpr_len);
701 LLDB_LOG(log,
"Evaluate_DW_OP_entry_value: subexpr could not be read");
708 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
711 const void *param_subexpr_data =
712 param_subexpr_extractor.
GetData(¶m_subexpr_offset, subexpr_len);
713 if (!param_subexpr_data ||
714 param_subexpr_extractor.
BytesLeft(param_subexpr_offset) != 0)
724 if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
725 matched_param = ¶m;
729 if (!matched_param) {
731 "Evaluate_DW_OP_entry_value: no matching call site param found");
739 if (!param_expr.
Evaluate(&parent_exe_ctx,
743 nullptr, result, error_ptr)) {
745 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
749 stack.push_back(result);
757enum LocationDescriptionKind {
765void UpdateValueTypeFromLocationDescription(
Log *log,
const DWARFUnit *dwarf_cu,
766 LocationDescriptionKind kind,
767 Value *value =
nullptr) {
774 if (dwarf_cu && dwarf_cu->
GetVersion() >= 4) {
775 const char *log_msg =
"DWARF location description kind: %s";
815static std::optional<lldb::addr_t>
817 Status *error_ptr,
const char *dw_op_type,
819 bool check_sectionoffset =
false) {
823 "need module to resolve file address for %s", dw_op_type);
827 if (!module_sp->ResolveFileAddress(file_addr, so_addr)) {
829 error_ptr->
SetErrorString(
"failed to resolve file address in module");
854 size_t size_addr_bytes,
856 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
860 return addr_data.
GetMaxU64(&addr_data_offset, size);
862 return addr_data.
GetAddress(&addr_data_offset);
869 const Value *initial_value_ptr,
const Value *object_address_ptr,
875 "no location, value may have been optimized out");
878 std::vector<Value> stack;
889 if (reg_ctx ==
nullptr && frame)
892 if (initial_value_ptr)
893 stack.push_back(*initial_value_ptr);
900 uint64_t op_piece_offset = 0;
908 auto to_generic = [&](
auto v) {
909 bool is_signed = std::is_signed<
decltype(v)>::value;
910 return Scalar(llvm::APSInt(
918 LocationDescriptionKind dwarf4_location_description_kind =
Memory;
922 const uint8_t op = opcodes.
GetU8(&offset);
925 size_t count = stack.size();
926 LLDB_LOGF(log,
"Stack before operation has %" PRIu64
" values:",
928 for (
size_t i = 0; i < count; ++i) {
930 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
931 stack[i].Dump(&new_value);
934 LLDB_LOGF(log,
"0x%8.8" PRIx64
": %s", op_offset,
999 error_ptr->
SetErrorString(
"Expression stack empty for DW_OP_deref.");
1003 switch (value_type) {
1005 void *src = (
void *)stack.back().GetScalar().ULongLong();
1007 ::memcpy(&ptr, src,
sizeof(
void *));
1008 stack.back().GetScalar() = ptr;
1009 stack.back().ClearContext();
1012 auto file_addr = stack.back().GetScalar().ULongLong(
1017 exe_ctx, module_sp, error_ptr,
"DW_OP_deref", file_addr, so_addr);
1019 if (!maybe_load_addr)
1022 stack.back().GetScalar() = *maybe_load_addr;
1040 pointer_value = abi_sp->FixCodeAddress(pointer_value);
1041 stack.back().GetScalar() = pointer_value;
1042 stack.back().ClearContext();
1046 "Failed to dereference pointer from 0x%" PRIx64
1047 " for DW_OP_deref: %s\n",
1048 pointer_addr,
error.AsCString());
1059 "NULL execution context for DW_OP_deref.\n");
1066 error_ptr->
SetErrorString(
"Invalid value type for DW_OP_deref.\n");
1084 case DW_OP_deref_size: {
1085 if (stack.empty()) {
1088 "Expression stack empty for DW_OP_deref_size.");
1091 uint8_t size = opcodes.
GetU8(&offset);
1095 "Invalid address size for DW_OP_deref_size: %d\n",
1100 switch (value_type) {
1102 void *src = (
void *)stack.back().GetScalar().ULongLong();
1104 ::memcpy(&ptr, src,
sizeof(
void *));
1117 ptr = ptr & 0xffffff;
1120 ptr = ptr & 0xffffffff;
1127 ptr = (intptr_t)ptr & 0xffffffffffULL;
1130 ptr = (intptr_t)ptr & 0xffffffffffffULL;
1133 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
1138 stack.back().GetScalar() = ptr;
1139 stack.back().ClearContext();
1145 auto maybe_load_addr =
1147 "DW_OP_deref_size", file_addr, so_addr,
1150 if (!maybe_load_addr)
1153 addr_t load_addr = *maybe_load_addr;
1156 uint8_t addr_bytes[8];
1162 ObjectFile *objfile = module_sp->GetObjectFile();
1166 stack.back().ClearContext();
1171 "Failed to dereference pointer for DW_OP_deref_size: "
1177 stack.back().GetScalar() = load_addr;
1193 stack.back().GetScalar() =
1196 stack.back().ClearContext();
1200 "Failed to dereference pointer from 0x%" PRIx64
1201 " for DW_OP_deref: %s\n",
1202 pointer_addr,
error.AsCString());
1207 error_ptr->
SetErrorString(
"NULL process for DW_OP_deref_size.\n");
1213 "NULL execution context for DW_OP_deref_size.\n");
1220 error_ptr->
SetErrorString(
"Invalid value for DW_OP_deref_size.\n");
1241 case DW_OP_xderef_size:
1243 error_ptr->
SetErrorString(
"Unimplemented opcode: DW_OP_xderef_size.");
1257 error_ptr->
SetErrorString(
"Unimplemented opcode: DW_OP_xderef.");
1274 stack.push_back(to_generic(opcodes.
GetU8(&offset)));
1277 stack.push_back(to_generic((int8_t)opcodes.
GetU8(&offset)));
1280 stack.push_back(to_generic(opcodes.
GetU16(&offset)));
1283 stack.push_back(to_generic((int16_t)opcodes.
GetU16(&offset)));
1286 stack.push_back(to_generic(opcodes.
GetU32(&offset)));
1289 stack.push_back(to_generic((int32_t)opcodes.
GetU32(&offset)));
1292 stack.push_back(to_generic(opcodes.
GetU64(&offset)));
1295 stack.push_back(to_generic((int64_t)opcodes.
GetU64(&offset)));
1310 if (stack.empty()) {
1312 error_ptr->
SetErrorString(
"Expression stack empty for DW_OP_dup.");
1315 stack.push_back(stack.back());
1322 if (stack.empty()) {
1324 error_ptr->
SetErrorString(
"Expression stack empty for DW_OP_drop.");
1335 if (stack.size() < 2) {
1338 "Expression stack needs at least 2 items for DW_OP_over.");
1341 stack.push_back(stack[stack.size() - 2]);
1349 uint8_t pick_idx = opcodes.
GetU8(&offset);
1350 if (pick_idx < stack.size())
1351 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1355 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1366 if (stack.size() < 2) {
1369 "Expression stack needs at least 2 items for DW_OP_swap.");
1373 stack.back() = stack[stack.size() - 2];
1374 stack[stack.size() - 2] = tmp;
1385 if (stack.size() < 3) {
1388 "Expression stack needs at least 3 items for DW_OP_rot.");
1391 size_t last_idx = stack.size() - 1;
1392 Value old_top = stack[last_idx];
1393 stack[last_idx] = stack[last_idx - 1];
1394 stack[last_idx - 1] = stack[last_idx - 2];
1395 stack[last_idx - 2] = old_top;
1405 if (stack.empty()) {
1408 "Expression stack needs at least 1 item for DW_OP_abs.");
1410 }
else if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1413 "Failed to take the absolute value of the first stack item.");
1423 if (stack.size() < 2) {
1426 "Expression stack needs at least 2 items for DW_OP_and.");
1432 stack.back().ResolveValue(exe_ctx) & tmp.
ResolveValue(exe_ctx);
1442 if (stack.size() < 2) {
1445 "Expression stack needs at least 2 items for DW_OP_div.");
1455 Scalar divisor, dividend;
1457 dividend = stack.back().ResolveValue(exe_ctx);
1460 stack.back() = dividend / divisor;
1461 if (!stack.back().ResolveValue(exe_ctx).IsValid()) {
1475 if (stack.size() < 2) {
1478 "Expression stack needs at least 2 items for DW_OP_minus.");
1484 stack.back().ResolveValue(exe_ctx) - tmp.
ResolveValue(exe_ctx);
1494 if (stack.size() < 2) {
1497 "Expression stack needs at least 2 items for DW_OP_mod.");
1503 stack.back().ResolveValue(exe_ctx) % tmp.
ResolveValue(exe_ctx);
1512 if (stack.size() < 2) {
1515 "Expression stack needs at least 2 items for DW_OP_mul.");
1521 stack.back().ResolveValue(exe_ctx) * tmp.
ResolveValue(exe_ctx);
1529 if (stack.empty()) {
1532 "Expression stack needs at least 1 item for DW_OP_neg.");
1535 if (!stack.back().ResolveValue(exe_ctx).UnaryNegate()) {
1548 if (stack.empty()) {
1551 "Expression stack needs at least 1 item for DW_OP_not.");
1554 if (!stack.back().ResolveValue(exe_ctx).OnesComplement()) {
1567 if (stack.size() < 2) {
1570 "Expression stack needs at least 2 items for DW_OP_or.");
1576 stack.back().ResolveValue(exe_ctx) | tmp.
ResolveValue(exe_ctx);
1585 if (stack.size() < 2) {
1588 "Expression stack needs at least 2 items for DW_OP_plus.");
1601 case DW_OP_plus_uconst:
1602 if (stack.empty()) {
1605 "Expression stack needs at least 1 item for DW_OP_plus_uconst.");
1608 const uint64_t uconst_value = opcodes.
GetULEB128(&offset);
1610 stack.back().GetScalar() += uconst_value;
1611 if (!stack.back().GetScalar().IsValid()) {
1625 if (stack.size() < 2) {
1628 "Expression stack needs at least 2 items for DW_OP_shl.");
1643 if (stack.size() < 2) {
1646 "Expression stack needs at least 2 items for DW_OP_shr.");
1651 if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1667 if (stack.size() < 2) {
1670 "Expression stack needs at least 2 items for DW_OP_shra.");
1684 if (stack.size() < 2) {
1687 "Expression stack needs at least 2 items for DW_OP_xor.");
1693 stack.back().ResolveValue(exe_ctx) ^ tmp.
ResolveValue(exe_ctx);
1704 int16_t skip_offset = (int16_t)opcodes.
GetU16(&offset);
1710 offset = new_offset;
1714 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1728 if (stack.empty()) {
1731 "Expression stack needs at least 1 item for DW_OP_bra.");
1736 int16_t bra_offset = (int16_t)opcodes.
GetU16(&offset);
1744 offset = new_offset;
1748 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1764 if (stack.size() < 2) {
1767 "Expression stack needs at least 2 items for DW_OP_eq.");
1773 stack.back().ResolveValue(exe_ctx) == tmp.
ResolveValue(exe_ctx);
1785 if (stack.size() < 2) {
1788 "Expression stack needs at least 2 items for DW_OP_ge.");
1794 stack.back().ResolveValue(exe_ctx) >= tmp.
ResolveValue(exe_ctx);
1806 if (stack.size() < 2) {
1809 "Expression stack needs at least 2 items for DW_OP_gt.");
1815 stack.back().ResolveValue(exe_ctx) > tmp.
ResolveValue(exe_ctx);
1827 if (stack.size() < 2) {
1830 "Expression stack needs at least 2 items for DW_OP_le.");
1836 stack.back().ResolveValue(exe_ctx) <= tmp.
ResolveValue(exe_ctx);
1848 if (stack.size() < 2) {
1851 "Expression stack needs at least 2 items for DW_OP_lt.");
1857 stack.back().ResolveValue(exe_ctx) < tmp.
ResolveValue(exe_ctx);
1869 if (stack.size() < 2) {
1872 "Expression stack needs at least 2 items for DW_OP_ne.");
1878 stack.back().ResolveValue(exe_ctx) != tmp.
ResolveValue(exe_ctx);
1919 stack.push_back(to_generic(op - DW_OP_lit0));
1957 dwarf4_location_description_kind = Register;
1958 reg_num = op - DW_OP_reg0;
1961 stack.push_back(tmp);
1970 dwarf4_location_description_kind = Register;
1973 stack.push_back(tmp);
2014 case DW_OP_breg31: {
2015 reg_num = op - DW_OP_breg0;
2019 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
2022 stack.push_back(tmp);
2038 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
2041 stack.push_back(tmp);
2052 int64_t fbreg_offset = opcodes.
GetSLEB128(&offset);
2053 value += fbreg_offset;
2054 stack.push_back(value);
2061 "Invalid stack frame in context for DW_OP_fbreg opcode.");
2067 "NULL execution context for DW_OP_fbreg.\n");
2094 LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
2096 dwarf4_location_description_kind =
Memory;
2098 const uint64_t piece_byte_size = opcodes.
GetULEB128(&offset);
2100 if (piece_byte_size > 0) {
2103 if (stack.empty()) {
2104 UpdateValueTypeFromLocationDescription(
2105 log, dwarf_cu, LocationDescriptionKind::Empty);
2119 Value curr_piece_source_value(stack.back());
2121 UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
2122 &curr_piece_source_value);
2126 switch (curr_piece_source_value_type) {
2131 if (curr_piece.
ResizeData(piece_byte_size) == piece_byte_size) {
2137 piece_byte_size,
error) != piece_byte_size) {
2140 "failed to read memory DW_OP_piece(%" PRIu64
2141 ") from 0x%" PRIx64,
2142 piece_byte_size, load_addr);
2148 "failed to resize the piece memory buffer for "
2149 "DW_OP_piece(%" PRIu64
")",
2162 "failed to read memory DW_OP_piece(%" PRIu64
2163 ") from %s address 0x%" PRIx64,
2164 piece_byte_size, curr_piece_source_value.
GetValueType() ==
2173 uint32_t bit_size = piece_byte_size * 8;
2174 uint32_t bit_offset = 0;
2177 bit_size, bit_offset)) {
2180 "unable to extract %" PRIu64
" bytes from a %" PRIu64
2181 " byte scalar value.",
2183 (uint64_t)curr_piece_source_value.
GetScalar()
2189 llvm::APInt fail_value(1, 0,
false);
2190 llvm::APInt ap_int = scalar.
UInt128(fail_value);
2191 assert(ap_int.getBitWidth() >= bit_size);
2192 llvm::ArrayRef<uint64_t> buf{ap_int.getRawData(),
2193 ap_int.getNumWords()};
2199 if (op_piece_offset == 0) {
2214 "DW_OP_piece for offset %" PRIu64
2215 " but top of stack is of size %" PRIu64,
2227 op_piece_offset += piece_byte_size;
2231 case DW_OP_bit_piece:
2232 if (stack.size() < 1) {
2233 UpdateValueTypeFromLocationDescription(log, dwarf_cu,
2234 LocationDescriptionKind::Empty);
2236 dwarf4_location_description_kind =
Memory;
2239 "Expression stack needs at least 1 item for DW_OP_bit_piece.");
2242 UpdateValueTypeFromLocationDescription(
2243 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2245 dwarf4_location_description_kind =
Memory;
2246 const uint64_t piece_bit_size = opcodes.
GetULEB128(&offset);
2247 const uint64_t piece_bit_offset = opcodes.
GetULEB128(&offset);
2248 switch (stack.back().GetValueType()) {
2252 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
2253 piece_bit_offset)) {
2256 "unable to extract %" PRIu64
" bit value with %" PRIu64
2257 " bit offset from a %" PRIu64
" bit scalar value.",
2258 piece_bit_size, piece_bit_offset,
2259 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
2269 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
2270 ", bit_offset = %" PRIu64
") from an address value.",
2271 piece_bit_size, piece_bit_offset);
2285 case DW_OP_implicit_value: {
2286 dwarf4_location_description_kind = Implicit;
2288 const uint32_t len = opcodes.
GetULEB128(&offset);
2289 const void *data = opcodes.
GetData(&offset, len);
2292 LLDB_LOG(log,
"Evaluate_DW_OP_implicit_value: could not be read data");
2298 Value result(data, len);
2299 stack.push_back(result);
2303 case DW_OP_implicit_pointer: {
2304 dwarf4_location_description_kind = Implicit;
2317 case DW_OP_push_object_address:
2318 if (object_address_ptr)
2319 stack.push_back(*object_address_ptr);
2322 error_ptr->
SetErrorString(
"DW_OP_push_object_address used without "
2323 "specifying an object address");
2379 case DW_OP_stack_value:
2380 dwarf4_location_description_kind = Implicit;
2381 if (stack.empty()) {
2384 "Expression stack needs at least 1 item for DW_OP_stack_value.");
2397 case DW_OP_convert: {
2398 if (stack.size() < 1) {
2401 "Expression stack needs at least 1 item for DW_OP_convert.");
2404 const uint64_t die_offset = opcodes.
GetULEB128(&offset);
2407 if (die_offset == 0) {
2417 bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2426 const uint64_t abs_die_offset = die_offset + dwarf_cu->
GetOffset();
2431 error_ptr->
SetErrorString(
"Cannot resolve DW_OP_convert type DIE");
2441 error_ptr->
SetErrorString(
"Unsupported type size in DW_OP_convert");
2446 case DW_ATE_signed_char:
2449 case DW_ATE_unsigned:
2450 case DW_ATE_unsigned_char:
2455 error_ptr->
SetErrorString(
"Unsupported encoding in DW_OP_convert");
2459 Scalar &top = stack.back().ResolveValue(exe_ctx);
2469 case DW_OP_call_frame_cfa:
2476 stack.push_back(
Scalar(cfa));
2478 }
else if (error_ptr)
2479 error_ptr->
SetErrorString(
"Stack frame does not include a canonical "
2480 "frame address for DW_OP_call_frame_cfa "
2485 "DW_OP_call_frame_cfa opcode.");
2496 case DW_OP_form_tls_address:
2497 case DW_OP_GNU_push_tls_address: {
2498 if (stack.size() < 1) {
2500 if (op == DW_OP_form_tls_address)
2502 "DW_OP_form_tls_address needs an argument.");
2505 "DW_OP_GNU_push_tls_address needs an argument.");
2510 if (!exe_ctx || !module_sp) {
2524 const addr_t tls_file_addr =
2526 const addr_t tls_load_addr =
2532 "No TLS data currently exists for this thread.");
2536 stack.back().GetScalar() = tls_load_addr;
2547 case DW_OP_GNU_addr_index: {
2550 error_ptr->
SetErrorString(
"DW_OP_GNU_addr_index found without a "
2551 "compile unit being specified");
2554 uint64_t index = opcodes.
GetULEB128(&offset);
2556 stack.push_back(
Scalar(value));
2574 case DW_OP_GNU_const_index: {
2577 error_ptr->
SetErrorString(
"DW_OP_GNU_const_index found without a "
2578 "compile unit being specified");
2581 uint64_t index = opcodes.
GetULEB128(&offset);
2583 stack.push_back(
Scalar(value));
2586 case DW_OP_GNU_entry_value:
2587 case DW_OP_entry_value: {
2600 op, opcodes, offset, stack)) {
2606 "Unhandled opcode {0} in DWARFExpression", LocationAtom(op));
2611 if (stack.empty()) {
2623 UpdateValueTypeFromLocationDescription(
2624 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2627 size_t count = stack.size();
2629 "Stack after operation has %" PRIu64
" values:", (uint64_t)count);
2630 for (
size_t i = 0; i < count; ++i) {
2632 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
2633 stack[i].Dump(&new_value);
2637 result = stack.back();
2644 location_list->
Clear();
2645 std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2649 [&](uint32_t index) -> std::optional<llvm::object::SectionedAddress> {
2652 return std::nullopt;
2653 return llvm::object::SectionedAddress{address};
2655 auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2661 std::make_shared<DataBufferHeap>(loc->Expr.data(), loc->Expr.size());
2664 location_list->
AddExpression(loc->Range->LowPC, loc->Range->HighPC, expr);
2667 llvm::Error
error = loctable_up->visitAbsoluteLocationList(
2669 lookup_addr, process_list);
2670 location_list->
Sort();
2680 using namespace OperandMatchers;
2690 uint8_t opcode = opcodes.
GetU8(&op_offset);
2692 if (opcode == DW_OP_fbreg) {
2693 int64_t offset = opcodes.
GetSLEB128(&op_offset);
2706 recurse)(operand)) {
2710 return MatchUnaryOp(
2713 MatchImmOp(offset), recurse))(operand);
2716 bool dereference =
false;
2720 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2721 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_reg0);
2722 }
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2724 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_breg0);
2725 }
else if (opcode == DW_OP_regx) {
2726 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2727 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2728 }
else if (opcode == DW_OP_bregx) {
2729 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2731 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2743 MatchRegOp(*reg))(operand)) {
2747 return MatchUnaryOp(
2751 MatchImmOp(offset)))(operand);
2753 return MatchRegOp(*reg)(operand);
static llvm::raw_ostream & error(Stream &strm)
static offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op, const DWARFUnit *dwarf_cu)
Return the length in bytes of the set of operands for op.
static bool ReadRegisterValueAsScalar(RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, uint32_t reg_num, Status *error_ptr, Value &value)
static bool Evaluate_DW_OP_entry_value(std::vector< Value > &stack, ExecutionContext *exe_ctx, RegisterContext *reg_ctx, const DataExtractor &opcodes, lldb::offset_t &opcode_offset, Status *error_ptr, Log *log)
static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes, size_t size_addr_bytes, ByteOrder byte_order, size_t size)
Helper function to move common code used to load sized data from a uint8_t buffer.
static std::optional< lldb::addr_t > ResolveLoadAddress(ExecutionContext *exe_ctx, lldb::ModuleSP &module_sp, Status *error_ptr, const char *dw_op_type, lldb::addr_t file_addr, Address &so_addr, bool check_sectionoffset=false)
Helper function to move common code used to resolve a file address and turn into a load address.
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
@ Empty
If the Mangled object has neither a mangled name or demangled name we can encode the object with one ...
#define LLDB_ERRORF(status, fmt,...)
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
SymbolFileDWARF & GetSymbolFileDWARF() const
dw_addr_t ReadAddressFromDebugAddrSection(uint32_t index) const
uint16_t GetVersion() const
std::unique_ptr< llvm::DWARFLocationTable > GetLocationTable(const lldb_private::DataExtractor &data) const
Return the location table for parsing the given location list data.
dw_addr_t GetBaseAddress() const
dw_offset_t GetOffset() const
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const
virtual bool ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes, lldb::offset_t &offset, std::vector< lldb_private::Value > &stack) const
llvm::MCRegisterInfo & GetMCRegisterInfo()
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
bool IsSectionOffset() const
Check if an address is section offset.
Represent a call made within a Function.
virtual Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx)=0
Get the callee's definition.
llvm::ArrayRef< CallSiteParameter > GetCallSiteParameters() const
Get the call site parameters available at this call edge.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool AddExpression(lldb::addr_t base, lldb::addr_t end, DWARFExpression expr)
bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) const
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &operand) const
void Sort()
Sort m_expressions.
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr)
Evaluate a DWARF location expression in a particular context.
lldb::addr_t GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu, bool &error) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
DataExtractor m_data
A data extractor capable of reading opcode bytes.
virtual ~DWARFExpression()
Destructor.
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
bool LinkThreadLocalStorage(const DWARFUnit *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
bool ContainsThreadLocalStorage(const DWARFUnit *dwarf_cu) const
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
bool Update_DW_OP_addr(const DWARFUnit *dwarf_cu, lldb::addr_t file_addr)
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const
lldb::RegisterKind GetRegisterKind() const
Return the call-frame-info style register kind.
static bool ParseDWARFLocationList(const DWARFUnit *dwarf_cu, const DataExtractor &data, DWARFExpressionList *loc_list)
bool IsValid() const
Return true if the location expression contains data.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An binary data encoding class.
std::shared_ptr< lldb_private::DataBufferHeap > GetDataBuffer()
Get a shared copy of the heap based memory buffer owned by this object.
uint32_t PutUnsigned(uint32_t offset, uint32_t byte_size, uint64_t value)
Encode an unsigned integer of size byte_size to offset.
uint32_t PutAddress(uint32_t offset, lldb::addr_t addr)
Encode an address in the existing buffer at offset bytes into the buffer.
void AppendAddress(lldb::addr_t addr)
Append an address sized integer to the end of the owned data.
void AppendU8(uint8_t value)
Append a unsigned integer to the end of the owned data.
void AppendData(llvm::StringRef data)
Append a bytes to the end of the owned data.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Target & GetTargetRef() const
Returns a reference to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
RegisterContext * GetRegisterContext() const
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
A class that describes a function.
ConstString GetName() const
CallEdge * GetCallEdgeForReturnAddress(lldb::addr_t return_pc, Target &target)
Get the outgoing call edge from this function which has the given return address return_pc,...
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
A collection class for Module objects.
A plug-in interface definition class for object file parsers.
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
A plug-in interface definition class for debugging a process.
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
lldb::ByteOrder GetByteOrder() const
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
const lldb::ABISP & GetABI()
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)=0
bool GetScalarValue(Scalar &scalar) const
size_t GetByteSize() const
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
unsigned long long ULongLong(unsigned long long fail_value=0) const
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
llvm::APInt UInt128(const llvm::APInt &fail_value) const
This base class provides an interface to stack frames.
DWARFExpressionList * GetFrameBaseExpression(Status *error_ptr)
Get the DWARFExpressionList corresponding to the Canonical Frame Address.
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
bool GetFrameBaseValue(Scalar &value, Status *error_ptr)
Return the Canonical Frame Address (DWARF term) for this frame.
lldb::addr_t GetCallFrameAddress() const
void SetErrorStringWithFormatv(const char *format, Args &&... args)
void Clear()
Clear the object state.
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
const char * GetData() const
A stream class that can stream formatted output to a file.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Function * function
The Function for a given query.
size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory=false, lldb::addr_t *load_addr_ptr=nullptr)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, lldb::addr_t tls_file_addr)
Retrieves the per-module TLS block for a thread.
virtual uint32_t GetStackFrameCount()
const Scalar & GetScalar() const
ValueType
Type that describes Value::m_value.
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
@ FileAddress
A file address value.
@ LoadAddress
A load address value.
@ Scalar
A raw scalar value.
size_t AppendDataToHostBuffer(const Value &rhs)
ValueType GetValueType() const
void SetContext(ContextType context_type, void *p)
Scalar & ResolveValue(ExecutionContext *exe_ctx, Module *module=nullptr)
DataBufferHeap & GetBuffer()
void SetValueType(ValueType value_type)
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
size_t ResizeData(size_t len)
uint8_t * GetBytes()
Get a pointer to the data.
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_OFFSET
#define LLDB_INVALID_REGNUM
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
const char * DW_OP_value_to_name(uint32_t val)
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
std::shared_ptr< lldb_private::Module > ModuleSP
RegisterKind
Register numbering types.
Represent the locations of a parameter at a call site, both in the caller and in the callee.
DWARFExpressionList LocationInCaller
Every register is described in detail including its name, alternate name (optional),...
const char * name
Name of this register, can't be NULL.