40#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
41#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
62 uint8_t addr_byte_size) {
63 if (!const_value_byte_size)
75 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum,
76 bool IsEH) -> llvm::StringRef {
79 if (std::optional<unsigned> LLVMRegNum =
80 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
81 if (
const char *RegName = MCRegInfo->getName(*LLVMRegNum))
82 return llvm::StringRef(RegName);
85 llvm::DIDumpOptions DumpOpts;
86 DumpOpts.GetNameForDWARFReg = GetRegName;
99 uint32_t reg_num,
Value &value) {
100 if (reg_ctx ==
nullptr)
101 return llvm::createStringError(
"no register context in frame");
103 const uint32_t native_reg =
106 return llvm::createStringError(
107 "unable to convert register kind=%u reg_num=%u to a native "
118 return llvm::Error::success();
123 return llvm::createStringError(
124 "register %s can't be converted to a scalar value", reg_info->
name);
127 return llvm::createStringError(
"register %s is not available",
135 const uint8_t op,
const DWARFUnit *dwarf_cu) {
235 case DW_OP_push_object_address:
236 case DW_OP_form_tls_address:
237 case DW_OP_call_frame_cfa:
238 case DW_OP_stack_value:
239 case DW_OP_GNU_push_tls_address:
246 case DW_OP_deref_size:
247 case DW_OP_xderef_size:
273 case DW_OP_plus_uconst:
309 case DW_OP_GNU_addr_index:
310 case DW_OP_GNU_const_index:
312 return offset - data_offset;
316 case DW_OP_bit_piece:
319 return offset - data_offset;
321 case DW_OP_implicit_value:
326 return offset - data_offset;
329 case DW_OP_GNU_entry_value:
330 case DW_OP_entry_value:
332 uint64_t subexpr_len = data.
GetULEB128(&offset);
333 return (offset - data_offset) + subexpr_len;
341 data, data_offset, op);
352 if (op == DW_OP_addr)
354 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
367 offset += op_arg_size;
378 if (op == DW_OP_addr) {
400 if (op == DW_OP_addrx) {
404 llvm::ArrayRef data_before_op =
m_data.
GetData().take_front(offset - 1);
409 if (old_offset == offset)
411 llvm::ArrayRef data_after_op =
m_data.
GetData().drop_front(offset);
425 offset += op_arg_size;
436 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
442 offset += op_arg_size;
449 &link_address_callback) {
463 size_t const_byte_size = 0;
467 bool decoded_data =
false;
472 const_offset = offset;
481 const_offset = offset;
487 case DW_OP_form_tls_address:
488 case DW_OP_GNU_push_tls_address:
499 if (const_byte_size > 0) {
500 lldb::addr_t linked_file_addr = link_address_callback(const_value);
504 if (encoder.
PutUnsigned(const_offset, const_byte_size,
523 offset += op_arg_size;
583 return llvm::createStringError(
"no exe/reg context");
588 if (!current_frame || !thread)
589 return llvm::createStringError(
"no current frame/thread");
596 for (uint32_t parent_frame_idx = current_frame_idx + 1;;parent_frame_idx++) {
606 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
607 LLDB_LOG(log,
"immediate ancestor with pc = {0:x}", return_pc);
612 if (parent_frame->IsInlined())
618 if (!parent_frame || !parent_frame->GetRegisterContext()) {
619 return llvm::createStringError(
"no parent frame with reg ctx");
623 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
625 return llvm::createStringError(
"no parent function");
632 return llvm::createStringError(
"no current function");
638 if (!parent_frame->IsArtificial()) {
643 return llvm::createStringError(
644 llvm::formatv(
"no call edge for retn-pc = {0:x} in parent frame {1}",
645 return_pc, parent_func->
GetName()));
648 if (callee_func != current_func) {
649 return llvm::createStringError(
650 "ambiguous call sequence, can't find real parent frame");
657 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
658 call_edge = edge.get();
664 return llvm::createStringError(
"no unambiguous edge from parent "
665 "to current function");
670 const uint32_t subexpr_len = opcodes.
GetULEB128(&opcode_offset);
671 const void *subexpr_data = opcodes.
GetData(&opcode_offset, subexpr_len);
673 return llvm::createStringError(
"subexpr could not be read");
678 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
681 const void *param_subexpr_data =
682 param_subexpr_extractor.
GetData(¶m_subexpr_offset, subexpr_len);
683 if (!param_subexpr_data ||
684 param_subexpr_extractor.
BytesLeft(param_subexpr_offset) != 0)
694 if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
695 matched_param = ¶m;
700 return llvm::createStringError(
"no matching call site param found");
706 llvm::Expected<Value> maybe_result = param_expr.
Evaluate(
713 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
714 return maybe_result.takeError();
717 stack.push_back(*maybe_result);
718 return llvm::Error::success();
725enum LocationDescriptionKind {
733void UpdateValueTypeFromLocationDescription(
Log *log,
const DWARFUnit *dwarf_cu,
734 LocationDescriptionKind kind,
735 Value *value =
nullptr) {
742 if (dwarf_cu && dwarf_cu->
GetVersion() >= 4) {
743 const char *log_msg =
"DWARF location description kind: %s";
782static llvm::Expected<lldb::addr_t>
785 Address &so_addr,
bool check_sectionoffset =
false) {
787 return llvm::createStringError(
"need module to resolve file address for %s",
790 if (!module_sp->ResolveFileAddress(file_addr, so_addr))
791 return llvm::createStringError(
"failed to resolve file address in module");
797 return llvm::createStringError(
"failed to resolve load address");
811 size_t size_addr_bytes,
813 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
817 return addr_data.
GetMaxU64(&addr_data_offset, size);
819 return addr_data.
GetAddress(&addr_data_offset);
826 const Value *initial_value_ptr,
const Value *object_address_ptr) {
829 return llvm::createStringError(
830 "no location, value may have been optimized out");
831 std::vector<Value> stack;
842 if (reg_ctx ==
nullptr && frame)
845 if (initial_value_ptr)
846 stack.push_back(*initial_value_ptr);
853 uint64_t op_piece_offset = 0;
861 auto to_generic = [&](
auto v) {
862 bool is_signed = std::is_signed<
decltype(v)>::value;
863 return Scalar(llvm::APSInt(
871 LocationDescriptionKind dwarf4_location_description_kind =
Memory;
875 const uint8_t op = opcodes.
GetU8(&offset);
878 size_t count = stack.size();
879 LLDB_LOGF(log,
"Stack before operation has %" PRIu64
" values:",
881 for (
size_t i = 0; i < count; ++i) {
883 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
884 stack[i].Dump(&new_value);
887 LLDB_LOGF(log,
"0x%8.8" PRIx64
": %s", op_offset,
891 if (std::optional<unsigned> arity =
892 llvm::dwarf::OperationArity(
static_cast<LocationAtom
>(op))) {
893 if (stack.size() < *arity)
894 return llvm::createStringError(
895 "%s needs at least %d stack entries (stack has %d entries)",
959 return llvm::createStringError(
960 "expression stack empty for DW_OP_deref");
962 switch (value_type) {
964 void *src = (
void *)stack.back().GetScalar().ULongLong();
966 ::memcpy(&ptr, src,
sizeof(
void *));
967 stack.back().GetScalar() = ptr;
968 stack.back().ClearContext();
971 auto file_addr = stack.back().GetScalar().ULongLong(
976 exe_ctx, module_sp,
"DW_OP_deref", file_addr, so_addr);
978 if (!maybe_load_addr)
979 return maybe_load_addr.takeError();
981 stack.back().GetScalar() = *maybe_load_addr;
999 pointer_value = abi_sp->FixCodeAddress(pointer_value);
1000 stack.back().GetScalar() = pointer_value;
1001 stack.back().ClearContext();
1003 return llvm::createStringError(
1004 "Failed to dereference pointer from 0x%" PRIx64
1005 " for DW_OP_deref: %s\n",
1006 pointer_addr,
error.AsCString());
1009 return llvm::createStringError(
"NULL process for DW_OP_deref");
1012 return llvm::createStringError(
1013 "NULL execution context for DW_OP_deref");
1018 return llvm::createStringError(
"invalid value type for DW_OP_deref");
1035 case DW_OP_deref_size: {
1036 if (stack.empty()) {
1037 return llvm::createStringError(
1038 "expression stack empty for DW_OP_deref_size");
1040 uint8_t size = opcodes.
GetU8(&offset);
1042 return llvm::createStringError(
1043 "Invalid address size for DW_OP_deref_size: %d\n", size);
1046 switch (value_type) {
1048 void *src = (
void *)stack.back().GetScalar().ULongLong();
1050 ::memcpy(&ptr, src,
sizeof(
void *));
1063 ptr = ptr & 0xffffff;
1066 ptr = ptr & 0xffffffff;
1073 ptr = (intptr_t)ptr & 0xffffffffffULL;
1076 ptr = (intptr_t)ptr & 0xffffffffffffULL;
1079 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
1084 stack.back().GetScalar() = ptr;
1085 stack.back().ClearContext();
1092 exe_ctx, module_sp,
"DW_OP_deref_size", file_addr, so_addr,
1095 if (!maybe_load_addr)
1096 return maybe_load_addr.takeError();
1098 addr_t load_addr = *maybe_load_addr;
1101 uint8_t addr_bytes[8];
1107 ObjectFile *objfile = module_sp->GetObjectFile();
1111 stack.back().ClearContext();
1114 return llvm::createStringError(
1115 "Failed to dereference pointer for DW_OP_deref_size: "
1120 stack.back().GetScalar() = load_addr;
1136 stack.back().GetScalar() =
1139 stack.back().ClearContext();
1141 return llvm::createStringError(
1142 "Failed to dereference pointer from 0x%" PRIx64
1143 " for DW_OP_deref: %s\n",
1144 pointer_addr,
error.AsCString());
1148 return llvm::createStringError(
"NULL process for DW_OP_deref_size");
1151 return llvm::createStringError(
1152 "NULL execution context for DW_OP_deref_size");
1158 return llvm::createStringError(
"invalid value for DW_OP_deref_size");
1178 case DW_OP_xderef_size:
1179 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef_size");
1191 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef");
1207 stack.push_back(to_generic(opcodes.
GetU8(&offset)));
1210 stack.push_back(to_generic((int8_t)opcodes.
GetU8(&offset)));
1213 stack.push_back(to_generic(opcodes.
GetU16(&offset)));
1216 stack.push_back(to_generic((int16_t)opcodes.
GetU16(&offset)));
1219 stack.push_back(to_generic(opcodes.
GetU32(&offset)));
1222 stack.push_back(to_generic((int32_t)opcodes.
GetU32(&offset)));
1225 stack.push_back(to_generic(opcodes.
GetU64(&offset)));
1228 stack.push_back(to_generic((int64_t)opcodes.
GetU64(&offset)));
1243 if (stack.empty()) {
1244 return llvm::createStringError(
"expression stack empty for DW_OP_dup");
1246 stack.push_back(stack.back());
1253 if (stack.empty()) {
1254 return llvm::createStringError(
"expression stack empty for DW_OP_drop");
1264 stack.push_back(stack[stack.size() - 2]);
1272 uint8_t pick_idx = opcodes.
GetU8(&offset);
1273 if (pick_idx < stack.size())
1274 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1276 return llvm::createStringError(
1277 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1288 stack.back() = stack[stack.size() - 2];
1289 stack[stack.size() - 2] = tmp;
1299 size_t last_idx = stack.size() - 1;
1300 Value old_top = stack[last_idx];
1301 stack[last_idx] = stack[last_idx - 1];
1302 stack[last_idx - 1] = stack[last_idx - 2];
1303 stack[last_idx - 2] = old_top;
1312 if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1313 return llvm::createStringError(
1314 "failed to take the absolute value of the first stack item");
1326 stack.back().ResolveValue(exe_ctx) & tmp.
ResolveValue(exe_ctx);
1337 return llvm::createStringError(
"divide by zero");
1340 Scalar divisor, dividend;
1342 dividend = stack.back().ResolveValue(exe_ctx);
1345 stack.back() = dividend / divisor;
1347 if (!stack.back().ResolveValue(exe_ctx).IsValid())
1348 return llvm::createStringError(
"divide failed");
1359 stack.back().ResolveValue(exe_ctx) - tmp.
ResolveValue(exe_ctx);
1371 stack.back().ResolveValue(exe_ctx) % tmp.
ResolveValue(exe_ctx);
1382 stack.back().ResolveValue(exe_ctx) * tmp.
ResolveValue(exe_ctx);
1389 if (!stack.back().ResolveValue(exe_ctx).UnaryNegate())
1390 return llvm::createStringError(
"unary negate failed");
1398 if (!stack.back().ResolveValue(exe_ctx).OnesComplement())
1399 return llvm::createStringError(
"logical NOT failed");
1410 stack.back().ResolveValue(exe_ctx) | tmp.
ResolveValue(exe_ctx);
1427 case DW_OP_plus_uconst: {
1428 const uint64_t uconst_value = opcodes.
GetULEB128(&offset);
1430 stack.back().GetScalar() += uconst_value;
1431 if (!stack.back().GetScalar().IsValid())
1432 return llvm::createStringError(
"DW_OP_plus_uconst failed");
1454 if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1456 return llvm::createStringError(
"DW_OP_shr failed");
1479 stack.back().ResolveValue(exe_ctx) ^ tmp.
ResolveValue(exe_ctx);
1489 int16_t skip_offset = (int16_t)opcodes.
GetU16(&offset);
1495 offset = new_offset;
1497 return llvm::createStringError(llvm::formatv(
1498 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1513 int16_t bra_offset = (int16_t)opcodes.
GetU16(&offset);
1521 offset = new_offset;
1523 return llvm::createStringError(llvm::formatv(
1524 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1541 stack.back().ResolveValue(exe_ctx) == tmp.
ResolveValue(exe_ctx);
1555 stack.back().ResolveValue(exe_ctx) >= tmp.
ResolveValue(exe_ctx);
1569 stack.back().ResolveValue(exe_ctx) > tmp.
ResolveValue(exe_ctx);
1583 stack.back().ResolveValue(exe_ctx) <= tmp.
ResolveValue(exe_ctx);
1597 stack.back().ResolveValue(exe_ctx) < tmp.
ResolveValue(exe_ctx);
1611 stack.back().ResolveValue(exe_ctx) != tmp.
ResolveValue(exe_ctx);
1651 stack.push_back(to_generic(op - DW_OP_lit0));
1689 dwarf4_location_description_kind = Register;
1690 reg_num = op - DW_OP_reg0;
1692 if (llvm::Error err =
1695 stack.push_back(tmp);
1702 dwarf4_location_description_kind = Register;
1705 if (llvm::Error err =
1708 stack.push_back(tmp);
1747 case DW_OP_breg31: {
1748 reg_num = op - DW_OP_breg0;
1749 if (llvm::Error err =
1753 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1756 stack.push_back(tmp);
1767 if (llvm::Error err =
1771 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1774 stack.push_back(tmp);
1784 int64_t fbreg_offset = opcodes.
GetSLEB128(&offset);
1785 value += fbreg_offset;
1786 stack.push_back(value);
1791 return llvm::createStringError(
1792 "invalid stack frame in context for DW_OP_fbreg opcode");
1795 return llvm::createStringError(
1796 "NULL execution context for DW_OP_fbreg");
1822 LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
1824 dwarf4_location_description_kind =
Memory;
1826 const uint64_t piece_byte_size = opcodes.
GetULEB128(&offset);
1828 if (piece_byte_size > 0) {
1831 if (stack.empty()) {
1832 UpdateValueTypeFromLocationDescription(
1833 log, dwarf_cu, LocationDescriptionKind::Empty);
1847 Value curr_piece_source_value(stack.back());
1849 UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
1850 &curr_piece_source_value);
1856 switch (curr_piece_source_value_type) {
1858 return llvm::createStringError(
"invalid value type");
1862 if (curr_piece.
ResizeData(piece_byte_size) == piece_byte_size) {
1864 piece_byte_size,
error,
1867 const char *addr_type = (curr_piece_source_value_type ==
1871 return llvm::createStringError(
1872 "failed to read memory DW_OP_piece(%" PRIu64
1873 ") from %s address 0x%" PRIx64,
1874 piece_byte_size, addr_type, addr);
1877 return llvm::createStringError(
1878 "failed to resize the piece memory buffer for "
1879 "DW_OP_piece(%" PRIu64
")",
1885 return llvm::createStringError(
1886 "failed to read memory DW_OP_piece(%" PRIu64
1887 ") from host address 0x%" PRIx64,
1888 piece_byte_size, addr);
1892 uint32_t bit_size = piece_byte_size * 8;
1893 uint32_t bit_offset = 0;
1895 bit_size, bit_offset)) {
1896 return llvm::createStringError(
1897 "unable to extract %" PRIu64
" bytes from a %" PRIu64
1898 " byte scalar value.",
1904 llvm::APInt fail_value(1, 0,
false);
1905 llvm::APInt ap_int = scalar.
UInt128(fail_value);
1906 assert(ap_int.getBitWidth() >= bit_size);
1907 llvm::ArrayRef<uint64_t> buf{ap_int.getRawData(),
1908 ap_int.getNumWords()};
1914 if (op_piece_offset == 0) {
1919 return llvm::createStringError(
"failed to append piece data");
1925 return llvm::createStringError(
1926 "DW_OP_piece for offset %" PRIu64
1927 " but top of stack is of size %" PRIu64,
1932 return llvm::createStringError(
"failed to append piece data");
1935 op_piece_offset += piece_byte_size;
1939 case DW_OP_bit_piece:
1940 if (stack.size() < 1) {
1941 UpdateValueTypeFromLocationDescription(log, dwarf_cu,
1942 LocationDescriptionKind::Empty);
1944 dwarf4_location_description_kind =
Memory;
1945 return llvm::createStringError(
1946 "expression stack needs at least 1 item for DW_OP_bit_piece");
1948 UpdateValueTypeFromLocationDescription(
1949 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
1951 dwarf4_location_description_kind =
Memory;
1952 const uint64_t piece_bit_size = opcodes.
GetULEB128(&offset);
1953 const uint64_t piece_bit_offset = opcodes.
GetULEB128(&offset);
1954 switch (stack.back().GetValueType()) {
1956 return llvm::createStringError(
1957 "unable to extract bit value from invalid value");
1959 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
1960 piece_bit_offset)) {
1961 return llvm::createStringError(
1962 "unable to extract %" PRIu64
" bit value with %" PRIu64
1963 " bit offset from a %" PRIu64
" bit scalar value.",
1964 piece_bit_size, piece_bit_offset,
1965 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
1972 return llvm::createStringError(
1973 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
1974 ", bit_offset = %" PRIu64
") from an address value.",
1975 piece_bit_size, piece_bit_offset);
1987 case DW_OP_implicit_value: {
1988 dwarf4_location_description_kind = Implicit;
1990 const uint32_t len = opcodes.
GetULEB128(&offset);
1991 const void *data = opcodes.
GetData(&offset, len);
1994 LLDB_LOG(log,
"Evaluate_DW_OP_implicit_value: could not be read data");
1995 return llvm::createStringError(
"could not evaluate %s",
1999 Value result(data, len);
2000 stack.push_back(result);
2004 case DW_OP_implicit_pointer: {
2005 dwarf4_location_description_kind = Implicit;
2006 return llvm::createStringError(
"Could not evaluate %s.",
2018 case DW_OP_push_object_address:
2019 if (object_address_ptr)
2020 stack.push_back(*object_address_ptr);
2022 return llvm::createStringError(
"DW_OP_push_object_address used without "
2023 "specifying an object address");
2046 return llvm::createStringError(
"unimplemented opcode DW_OP_call2");
2067 return llvm::createStringError(
"unimplemented opcode DW_OP_call4");
2074 case DW_OP_stack_value:
2075 dwarf4_location_description_kind = Implicit;
2086 case DW_OP_convert: {
2087 const uint64_t die_offset = opcodes.
GetULEB128(&offset);
2090 if (die_offset == 0) {
2095 return llvm::createStringError(
"no module");
2097 bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2099 return llvm::createStringError(
"unspecified architecture");
2103 const uint64_t abs_die_offset = die_offset + dwarf_cu->
GetOffset();
2107 return llvm::createStringError(
2108 "cannot resolve DW_OP_convert type DIE");
2115 return llvm::createStringError(
2116 "unsupported type size in DW_OP_convert");
2119 case DW_ATE_signed_char:
2122 case DW_ATE_unsigned:
2123 case DW_ATE_unsigned_char:
2127 return llvm::createStringError(
2128 "unsupported encoding in DW_OP_convert");
2131 Scalar &top = stack.back().ResolveValue(exe_ctx);
2141 case DW_OP_call_frame_cfa:
2148 stack.push_back(
Scalar(cfa));
2151 return llvm::createStringError(
2152 "stack frame does not include a canonical "
2153 "frame address for DW_OP_call_frame_cfa "
2157 return llvm::createStringError(
"unvalid stack frame in context for "
2158 "DW_OP_call_frame_cfa opcode");
2168 case DW_OP_form_tls_address:
2169 case DW_OP_GNU_push_tls_address: {
2170 if (stack.size() < 1) {
2171 if (op == DW_OP_form_tls_address)
2172 return llvm::createStringError(
2173 "DW_OP_form_tls_address needs an argument");
2175 return llvm::createStringError(
2176 "DW_OP_GNU_push_tls_address needs an argument");
2179 if (!exe_ctx || !module_sp)
2180 return llvm::createStringError(
"no context to evaluate TLS within");
2184 return llvm::createStringError(
"no thread to evaluate TLS within");
2187 const addr_t tls_file_addr =
2189 const addr_t tls_load_addr =
2193 return llvm::createStringError(
2194 "no TLS data currently exists for this thread");
2196 stack.back().GetScalar() = tls_load_addr;
2207 case DW_OP_GNU_addr_index: {
2209 return llvm::createStringError(
"DW_OP_GNU_addr_index found without a "
2210 "compile unit being specified");
2211 uint64_t index = opcodes.
GetULEB128(&offset);
2213 stack.push_back(
Scalar(value));
2231 case DW_OP_GNU_const_index: {
2233 return llvm::createStringError(
"DW_OP_GNU_const_index found without a "
2234 "compile unit being specified");
2236 uint64_t index = opcodes.
GetULEB128(&offset);
2238 stack.push_back(
Scalar(value));
2241 case DW_OP_GNU_entry_value:
2242 case DW_OP_entry_value: {
2244 opcodes, offset, log))
2245 return llvm::createStringError(
2246 "could not evaluate DW_OP_entry_value: %s",
2247 llvm::toString(std::move(err)).c_str());
2254 op, opcodes, offset, stack)) {
2258 return llvm::createStringError(llvm::formatv(
2259 "Unhandled opcode {0} in DWARFExpression", LocationAtom(op)));
2263 if (stack.empty()) {
2269 return llvm::createStringError(
"stack empty after evaluation");
2272 UpdateValueTypeFromLocationDescription(
2273 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2276 size_t count = stack.size();
2278 "Stack after operation has %" PRIu64
" values:", (uint64_t)count);
2279 for (
size_t i = 0; i < count; ++i) {
2281 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
2282 stack[i].Dump(&new_value);
2286 return stack.back();
2292 location_list->
Clear();
2293 std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2297 [&](uint32_t index) -> std::optional<llvm::object::SectionedAddress> {
2300 return std::nullopt;
2301 return llvm::object::SectionedAddress{address};
2303 auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2309 std::make_shared<DataBufferHeap>(loc->Expr.data(), loc->Expr.size());
2312 location_list->
AddExpression(loc->Range->LowPC, loc->Range->HighPC, expr);
2315 llvm::Error
error = loctable_up->visitAbsoluteLocationList(
2317 lookup_addr, process_list);
2318 location_list->
Sort();
2328 using namespace OperandMatchers;
2338 uint8_t opcode = opcodes.
GetU8(&op_offset);
2340 if (opcode == DW_OP_fbreg) {
2341 int64_t offset = opcodes.
GetSLEB128(&op_offset);
2354 recurse)(operand)) {
2358 return MatchUnaryOp(
2361 MatchImmOp(offset), recurse))(operand);
2364 bool dereference =
false;
2368 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2369 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_reg0);
2370 }
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2372 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_breg0);
2373 }
else if (opcode == DW_OP_regx) {
2374 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2375 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2376 }
else if (opcode == DW_OP_bregx) {
2377 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2379 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2391 MatchRegOp(*reg))(operand)) {
2395 return MatchUnaryOp(
2399 MatchImmOp(offset)))(operand);
2401 return MatchRegOp(*reg)(operand);
static llvm::raw_ostream & error(Stream &strm)
static llvm::Expected< lldb::addr_t > ResolveLoadAddress(ExecutionContext *exe_ctx, lldb::ModuleSP &module_sp, 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.
static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, uint32_t reg_num, Value &value)
static llvm::Error Evaluate_DW_OP_entry_value(std::vector< Value > &stack, ExecutionContext *exe_ctx, RegisterContext *reg_ctx, const DataExtractor &opcodes, lldb::offset_t &opcode_offset, Log *log)
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 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.
#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 ...
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 MatchesOperand(StackFrame &frame, const Instruction::Operand &operand) const
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
void Sort()
Sort m_expressions.
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
static llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const plugin::dwarf::DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr)
Evaluate a DWARF location expression in a particular context.
DataExtractor m_data
A data extractor capable of reading opcode bytes.
~DWARFExpression()
Destructor.
bool LinkThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
lldb::addr_t GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu, bool &error) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu, lldb::addr_t file_addr)
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu, const DataExtractor &data, DWARFExpressionList *loc_list)
bool ContainsThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu) const
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
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.
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
llvm::Error ToError() const
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.
virtual 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.
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.
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
std::unique_ptr< llvm::DWARFLocationTable > GetLocationTable(const DataExtractor &data) const
Return the location table for parsing the given location list data.
dw_addr_t GetBaseAddress() const
SymbolFileDWARF & GetSymbolFileDWARF() const
dw_addr_t ReadAddressFromDebugAddrSection(uint32_t index) const
dw_offset_t GetOffset() const
uint16_t GetVersion() const
virtual bool ParseVendorDWARFOpcode(uint8_t op, const DataExtractor &opcodes, lldb::offset_t &offset, std::vector< Value > &stack) const
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_OFFSET
#define LLDB_INVALID_REGNUM
lldb::ByteOrder InlHostByteOrder()
const char * DW_OP_value_to_name(uint32_t val)
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.
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.