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",
236 case DW_OP_push_object_address:
237 case DW_OP_form_tls_address:
238 case DW_OP_call_frame_cfa:
239 case DW_OP_stack_value:
240 case DW_OP_GNU_push_tls_address:
247 case DW_OP_deref_size:
248 case DW_OP_xderef_size:
274 case DW_OP_plus_uconst:
310 case DW_OP_GNU_addr_index:
311 case DW_OP_GNU_const_index:
313 return offset - data_offset;
317 case DW_OP_bit_piece:
320 return offset - data_offset;
322 case DW_OP_implicit_value:
327 return offset - data_offset;
330 case DW_OP_GNU_entry_value:
331 case DW_OP_entry_value:
333 uint64_t subexpr_len = data.
GetULEB128(&offset);
334 return (offset - data_offset) + subexpr_len;
342 data, data_offset, op);
353 if (op == DW_OP_addr)
355 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
368 offset += op_arg_size;
379 if (op == DW_OP_addr) {
401 if (op == DW_OP_addrx) {
405 llvm::ArrayRef data_before_op =
m_data.
GetData().take_front(offset - 1);
410 if (old_offset == offset)
412 llvm::ArrayRef data_after_op =
m_data.
GetData().drop_front(offset);
426 offset += op_arg_size;
437 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
443 offset += op_arg_size;
450 &link_address_callback) {
464 size_t const_byte_size = 0;
468 bool decoded_data =
false;
473 const_offset = offset;
482 const_offset = offset;
488 case DW_OP_form_tls_address:
489 case DW_OP_GNU_push_tls_address:
500 if (const_byte_size > 0) {
501 lldb::addr_t linked_file_addr = link_address_callback(const_value);
505 if (encoder.
PutUnsigned(const_offset, const_byte_size,
524 offset += op_arg_size;
584 return llvm::createStringError(
"no exe/reg context");
589 if (!current_frame || !thread)
590 return llvm::createStringError(
"no current frame/thread");
597 for (uint32_t parent_frame_idx = current_frame_idx + 1;;parent_frame_idx++) {
607 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
608 LLDB_LOG(log,
"immediate ancestor with pc = {0:x}", return_pc);
613 if (parent_frame->IsInlined())
619 if (!parent_frame || !parent_frame->GetRegisterContext()) {
620 return llvm::createStringError(
"no parent frame with reg ctx");
624 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
626 return llvm::createStringError(
"no parent function");
633 return llvm::createStringError(
"no current function");
639 if (!parent_frame->IsArtificial()) {
644 return llvm::createStringError(
645 llvm::formatv(
"no call edge for retn-pc = {0:x} in parent frame {1}",
646 return_pc, parent_func->
GetName()));
649 if (callee_func != current_func) {
650 return llvm::createStringError(
651 "ambiguous call sequence, can't find real parent frame");
658 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
659 call_edge = edge.get();
665 return llvm::createStringError(
"no unambiguous edge from parent "
666 "to current function");
671 const uint32_t subexpr_len = opcodes.
GetULEB128(&opcode_offset);
672 const void *subexpr_data = opcodes.
GetData(&opcode_offset, subexpr_len);
674 return llvm::createStringError(
"subexpr could not be read");
679 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
682 const void *param_subexpr_data =
683 param_subexpr_extractor.
GetData(¶m_subexpr_offset, subexpr_len);
684 if (!param_subexpr_data ||
685 param_subexpr_extractor.
BytesLeft(param_subexpr_offset) != 0)
695 if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
696 matched_param = ¶m;
701 return llvm::createStringError(
"no matching call site param found");
707 llvm::Expected<Value> maybe_result = param_expr.
Evaluate(
714 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
715 return maybe_result.takeError();
718 stack.push_back(*maybe_result);
719 return llvm::Error::success();
726enum LocationDescriptionKind {
734void UpdateValueTypeFromLocationDescription(
Log *log,
const DWARFUnit *dwarf_cu,
735 LocationDescriptionKind kind,
736 Value *value =
nullptr) {
743 if (dwarf_cu && dwarf_cu->
GetVersion() >= 4) {
744 const char *log_msg =
"DWARF location description kind: %s";
783static llvm::Expected<lldb::addr_t>
786 Address &so_addr,
bool check_sectionoffset =
false) {
788 return llvm::createStringError(
"need module to resolve file address for %s",
791 if (!module_sp->ResolveFileAddress(file_addr, so_addr))
792 return llvm::createStringError(
"failed to resolve file address in module");
798 return llvm::createStringError(
"failed to resolve load address");
812 size_t size_addr_bytes,
814 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
818 return addr_data.
GetMaxU64(&addr_data_offset, size);
820 return addr_data.
GetAddress(&addr_data_offset);
827 const Value *initial_value_ptr,
const Value *object_address_ptr) {
830 return llvm::createStringError(
831 "no location, value may have been optimized out");
832 std::vector<Value> stack;
843 if (reg_ctx ==
nullptr && frame)
846 if (initial_value_ptr)
847 stack.push_back(*initial_value_ptr);
854 uint64_t op_piece_offset = 0;
862 auto to_generic = [&](
auto v) {
863 bool is_signed = std::is_signed<
decltype(v)>::value;
864 return Scalar(llvm::APSInt(
872 LocationDescriptionKind dwarf4_location_description_kind =
Memory;
876 const uint8_t op = opcodes.
GetU8(&offset);
879 size_t count = stack.size();
880 LLDB_LOGF(log,
"Stack before operation has %" PRIu64
" values:",
882 for (
size_t i = 0; i < count; ++i) {
884 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
885 stack[i].Dump(&new_value);
888 LLDB_LOGF(log,
"0x%8.8" PRIx64
": %s", op_offset,
892 if (std::optional<unsigned> arity =
893 llvm::dwarf::OperationArity(
static_cast<LocationAtom
>(op))) {
894 if (stack.size() < *arity)
895 return llvm::createStringError(
896 "%s needs at least %d stack entries (stack has %d entries)",
960 return llvm::createStringError(
961 "expression stack empty for DW_OP_deref");
963 switch (value_type) {
965 void *src = (
void *)stack.back().GetScalar().ULongLong();
967 ::memcpy(&ptr, src,
sizeof(
void *));
968 stack.back().GetScalar() = ptr;
969 stack.back().ClearContext();
972 auto file_addr = stack.back().GetScalar().ULongLong(
977 exe_ctx, module_sp,
"DW_OP_deref", file_addr, so_addr);
979 if (!maybe_load_addr)
980 return maybe_load_addr.takeError();
982 stack.back().GetScalar() = *maybe_load_addr;
1000 pointer_value = abi_sp->FixCodeAddress(pointer_value);
1001 stack.back().GetScalar() = pointer_value;
1002 stack.back().ClearContext();
1004 return llvm::createStringError(
1005 "Failed to dereference pointer from 0x%" PRIx64
1006 " for DW_OP_deref: %s\n",
1007 pointer_addr,
error.AsCString());
1010 return llvm::createStringError(
"NULL process for DW_OP_deref");
1013 return llvm::createStringError(
1014 "NULL execution context for DW_OP_deref");
1019 return llvm::createStringError(
"invalid value type for DW_OP_deref");
1036 case DW_OP_deref_size: {
1037 if (stack.empty()) {
1038 return llvm::createStringError(
1039 "expression stack empty for DW_OP_deref_size");
1041 uint8_t size = opcodes.
GetU8(&offset);
1043 return llvm::createStringError(
1044 "Invalid address size for DW_OP_deref_size: %d\n", size);
1047 switch (value_type) {
1049 void *src = (
void *)stack.back().GetScalar().ULongLong();
1051 ::memcpy(&ptr, src,
sizeof(
void *));
1064 ptr = ptr & 0xffffff;
1067 ptr = ptr & 0xffffffff;
1074 ptr = (intptr_t)ptr & 0xffffffffffULL;
1077 ptr = (intptr_t)ptr & 0xffffffffffffULL;
1080 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
1085 stack.back().GetScalar() = ptr;
1086 stack.back().ClearContext();
1093 exe_ctx, module_sp,
"DW_OP_deref_size", file_addr, so_addr,
1096 if (!maybe_load_addr)
1097 return maybe_load_addr.takeError();
1099 addr_t load_addr = *maybe_load_addr;
1102 uint8_t addr_bytes[8];
1108 ObjectFile *objfile = module_sp->GetObjectFile();
1112 stack.back().ClearContext();
1115 return llvm::createStringError(
1116 "Failed to dereference pointer for DW_OP_deref_size: "
1121 stack.back().GetScalar() = load_addr;
1137 stack.back().GetScalar() =
1140 stack.back().ClearContext();
1142 return llvm::createStringError(
1143 "Failed to dereference pointer from 0x%" PRIx64
1144 " for DW_OP_deref: %s\n",
1145 pointer_addr,
error.AsCString());
1149 return llvm::createStringError(
"NULL process for DW_OP_deref_size");
1152 return llvm::createStringError(
1153 "NULL execution context for DW_OP_deref_size");
1159 return llvm::createStringError(
"invalid value for DW_OP_deref_size");
1179 case DW_OP_xderef_size:
1180 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef_size");
1192 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef");
1208 stack.push_back(to_generic(opcodes.
GetU8(&offset)));
1211 stack.push_back(to_generic((int8_t)opcodes.
GetU8(&offset)));
1214 stack.push_back(to_generic(opcodes.
GetU16(&offset)));
1217 stack.push_back(to_generic((int16_t)opcodes.
GetU16(&offset)));
1220 stack.push_back(to_generic(opcodes.
GetU32(&offset)));
1223 stack.push_back(to_generic((int32_t)opcodes.
GetU32(&offset)));
1226 stack.push_back(to_generic(opcodes.
GetU64(&offset)));
1229 stack.push_back(to_generic((int64_t)opcodes.
GetU64(&offset)));
1244 if (stack.empty()) {
1245 return llvm::createStringError(
"expression stack empty for DW_OP_dup");
1247 stack.push_back(stack.back());
1254 if (stack.empty()) {
1255 return llvm::createStringError(
"expression stack empty for DW_OP_drop");
1265 stack.push_back(stack[stack.size() - 2]);
1273 uint8_t pick_idx = opcodes.
GetU8(&offset);
1274 if (pick_idx < stack.size())
1275 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1277 return llvm::createStringError(
1278 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1289 stack.back() = stack[stack.size() - 2];
1290 stack[stack.size() - 2] = tmp;
1300 size_t last_idx = stack.size() - 1;
1301 Value old_top = stack[last_idx];
1302 stack[last_idx] = stack[last_idx - 1];
1303 stack[last_idx - 1] = stack[last_idx - 2];
1304 stack[last_idx - 2] = old_top;
1313 if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1314 return llvm::createStringError(
1315 "failed to take the absolute value of the first stack item");
1327 stack.back().ResolveValue(exe_ctx) & tmp.
ResolveValue(exe_ctx);
1338 return llvm::createStringError(
"divide by zero");
1341 Scalar divisor, dividend;
1343 dividend = stack.back().ResolveValue(exe_ctx);
1346 stack.back() = dividend / divisor;
1348 if (!stack.back().ResolveValue(exe_ctx).IsValid())
1349 return llvm::createStringError(
"divide failed");
1360 stack.back().ResolveValue(exe_ctx) - tmp.
ResolveValue(exe_ctx);
1372 stack.back().ResolveValue(exe_ctx) % tmp.
ResolveValue(exe_ctx);
1383 stack.back().ResolveValue(exe_ctx) * tmp.
ResolveValue(exe_ctx);
1390 if (!stack.back().ResolveValue(exe_ctx).UnaryNegate())
1391 return llvm::createStringError(
"unary negate failed");
1399 if (!stack.back().ResolveValue(exe_ctx).OnesComplement())
1400 return llvm::createStringError(
"logical NOT failed");
1411 stack.back().ResolveValue(exe_ctx) | tmp.
ResolveValue(exe_ctx);
1428 case DW_OP_plus_uconst: {
1429 const uint64_t uconst_value = opcodes.
GetULEB128(&offset);
1431 stack.back().GetScalar() += uconst_value;
1432 if (!stack.back().GetScalar().IsValid())
1433 return llvm::createStringError(
"DW_OP_plus_uconst failed");
1455 if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1457 return llvm::createStringError(
"DW_OP_shr failed");
1480 stack.back().ResolveValue(exe_ctx) ^ tmp.
ResolveValue(exe_ctx);
1490 int16_t skip_offset = (int16_t)opcodes.
GetU16(&offset);
1496 offset = new_offset;
1498 return llvm::createStringError(llvm::formatv(
1499 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1514 int16_t bra_offset = (int16_t)opcodes.
GetU16(&offset);
1522 offset = new_offset;
1524 return llvm::createStringError(llvm::formatv(
1525 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1542 stack.back().ResolveValue(exe_ctx) == tmp.
ResolveValue(exe_ctx);
1556 stack.back().ResolveValue(exe_ctx) >= tmp.
ResolveValue(exe_ctx);
1570 stack.back().ResolveValue(exe_ctx) > tmp.
ResolveValue(exe_ctx);
1584 stack.back().ResolveValue(exe_ctx) <= tmp.
ResolveValue(exe_ctx);
1598 stack.back().ResolveValue(exe_ctx) < tmp.
ResolveValue(exe_ctx);
1612 stack.back().ResolveValue(exe_ctx) != tmp.
ResolveValue(exe_ctx);
1652 stack.push_back(to_generic(op - DW_OP_lit0));
1690 dwarf4_location_description_kind = Register;
1691 reg_num = op - DW_OP_reg0;
1693 if (llvm::Error err =
1696 stack.push_back(tmp);
1703 dwarf4_location_description_kind = Register;
1706 if (llvm::Error err =
1709 stack.push_back(tmp);
1748 case DW_OP_breg31: {
1749 reg_num = op - DW_OP_breg0;
1750 if (llvm::Error err =
1754 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1757 stack.push_back(tmp);
1768 if (llvm::Error err =
1772 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1775 stack.push_back(tmp);
1785 int64_t fbreg_offset = opcodes.
GetSLEB128(&offset);
1786 value += fbreg_offset;
1787 stack.push_back(value);
1792 return llvm::createStringError(
1793 "invalid stack frame in context for DW_OP_fbreg opcode");
1796 return llvm::createStringError(
1797 "NULL execution context for DW_OP_fbreg");
1823 LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
1825 dwarf4_location_description_kind =
Memory;
1827 const uint64_t piece_byte_size = opcodes.
GetULEB128(&offset);
1829 if (piece_byte_size > 0) {
1832 if (stack.empty()) {
1833 UpdateValueTypeFromLocationDescription(
1834 log, dwarf_cu, LocationDescriptionKind::Empty);
1848 Value curr_piece_source_value(stack.back());
1850 UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
1851 &curr_piece_source_value);
1857 switch (curr_piece_source_value_type) {
1859 return llvm::createStringError(
"invalid value type");
1863 if (curr_piece.
ResizeData(piece_byte_size) == piece_byte_size) {
1865 piece_byte_size,
error,
1868 const char *addr_type = (curr_piece_source_value_type ==
1872 return llvm::createStringError(
1873 "failed to read memory DW_OP_piece(%" PRIu64
1874 ") from %s address 0x%" PRIx64,
1875 piece_byte_size, addr_type, addr);
1878 return llvm::createStringError(
1879 "failed to resize the piece memory buffer for "
1880 "DW_OP_piece(%" PRIu64
")",
1886 return llvm::createStringError(
1887 "failed to read memory DW_OP_piece(%" PRIu64
1888 ") from host address 0x%" PRIx64,
1889 piece_byte_size, addr);
1893 uint32_t bit_size = piece_byte_size * 8;
1894 uint32_t bit_offset = 0;
1896 bit_size, bit_offset)) {
1897 return llvm::createStringError(
1898 "unable to extract %" PRIu64
" bytes from a %" PRIu64
1899 " byte scalar value.",
1905 llvm::APInt fail_value(1, 0,
false);
1906 llvm::APInt ap_int = scalar.
UInt128(fail_value);
1907 assert(ap_int.getBitWidth() >= bit_size);
1908 llvm::ArrayRef<uint64_t> buf{ap_int.getRawData(),
1909 ap_int.getNumWords()};
1915 if (op_piece_offset == 0) {
1920 return llvm::createStringError(
"failed to append piece data");
1926 return llvm::createStringError(
1927 "DW_OP_piece for offset %" PRIu64
1928 " but top of stack is of size %" PRIu64,
1933 return llvm::createStringError(
"failed to append piece data");
1936 op_piece_offset += piece_byte_size;
1940 case DW_OP_bit_piece:
1941 if (stack.size() < 1) {
1942 UpdateValueTypeFromLocationDescription(log, dwarf_cu,
1943 LocationDescriptionKind::Empty);
1945 dwarf4_location_description_kind =
Memory;
1946 return llvm::createStringError(
1947 "expression stack needs at least 1 item for DW_OP_bit_piece");
1949 UpdateValueTypeFromLocationDescription(
1950 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
1952 dwarf4_location_description_kind =
Memory;
1953 const uint64_t piece_bit_size = opcodes.
GetULEB128(&offset);
1954 const uint64_t piece_bit_offset = opcodes.
GetULEB128(&offset);
1955 switch (stack.back().GetValueType()) {
1957 return llvm::createStringError(
1958 "unable to extract bit value from invalid value");
1960 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
1961 piece_bit_offset)) {
1962 return llvm::createStringError(
1963 "unable to extract %" PRIu64
" bit value with %" PRIu64
1964 " bit offset from a %" PRIu64
" bit scalar value.",
1965 piece_bit_size, piece_bit_offset,
1966 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
1973 return llvm::createStringError(
1974 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
1975 ", bit_offset = %" PRIu64
") from an address value.",
1976 piece_bit_size, piece_bit_offset);
1988 case DW_OP_implicit_value: {
1989 dwarf4_location_description_kind = Implicit;
1991 const uint32_t len = opcodes.
GetULEB128(&offset);
1992 const void *data = opcodes.
GetData(&offset, len);
1995 LLDB_LOG(log,
"Evaluate_DW_OP_implicit_value: could not be read data");
1996 return llvm::createStringError(
"could not evaluate %s",
2000 Value result(data, len);
2001 stack.push_back(result);
2005 case DW_OP_implicit_pointer: {
2006 dwarf4_location_description_kind = Implicit;
2007 return llvm::createStringError(
"Could not evaluate %s.",
2019 case DW_OP_push_object_address:
2020 if (object_address_ptr)
2021 stack.push_back(*object_address_ptr);
2023 return llvm::createStringError(
"DW_OP_push_object_address used without "
2024 "specifying an object address");
2047 return llvm::createStringError(
"unimplemented opcode DW_OP_call2");
2068 return llvm::createStringError(
"unimplemented opcode DW_OP_call4");
2075 case DW_OP_stack_value:
2076 dwarf4_location_description_kind = Implicit;
2087 case DW_OP_convert: {
2088 const uint64_t die_offset = opcodes.
GetULEB128(&offset);
2091 if (die_offset == 0) {
2096 return llvm::createStringError(
"no module");
2098 bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2100 return llvm::createStringError(
"unspecified architecture");
2104 const uint64_t abs_die_offset = die_offset + dwarf_cu->
GetOffset();
2108 return llvm::createStringError(
2109 "cannot resolve DW_OP_convert type DIE");
2116 return llvm::createStringError(
2117 "unsupported type size in DW_OP_convert");
2120 case DW_ATE_signed_char:
2123 case DW_ATE_unsigned:
2124 case DW_ATE_unsigned_char:
2128 return llvm::createStringError(
2129 "unsupported encoding in DW_OP_convert");
2132 Scalar &top = stack.back().ResolveValue(exe_ctx);
2142 case DW_OP_call_frame_cfa:
2149 stack.push_back(
Scalar(cfa));
2152 return llvm::createStringError(
2153 "stack frame does not include a canonical "
2154 "frame address for DW_OP_call_frame_cfa "
2158 return llvm::createStringError(
"unvalid stack frame in context for "
2159 "DW_OP_call_frame_cfa opcode");
2169 case DW_OP_form_tls_address:
2170 case DW_OP_GNU_push_tls_address: {
2171 if (stack.size() < 1) {
2172 if (op == DW_OP_form_tls_address)
2173 return llvm::createStringError(
2174 "DW_OP_form_tls_address needs an argument");
2176 return llvm::createStringError(
2177 "DW_OP_GNU_push_tls_address needs an argument");
2180 if (!exe_ctx || !module_sp)
2181 return llvm::createStringError(
"no context to evaluate TLS within");
2185 return llvm::createStringError(
"no thread to evaluate TLS within");
2188 const addr_t tls_file_addr =
2190 const addr_t tls_load_addr =
2194 return llvm::createStringError(
2195 "no TLS data currently exists for this thread");
2197 stack.back().GetScalar() = tls_load_addr;
2208 case DW_OP_GNU_addr_index: {
2210 return llvm::createStringError(
"DW_OP_GNU_addr_index found without a "
2211 "compile unit being specified");
2212 uint64_t index = opcodes.
GetULEB128(&offset);
2214 stack.push_back(
Scalar(value));
2232 case DW_OP_GNU_const_index: {
2234 return llvm::createStringError(
"DW_OP_GNU_const_index found without a "
2235 "compile unit being specified");
2237 uint64_t index = opcodes.
GetULEB128(&offset);
2239 stack.push_back(
Scalar(value));
2242 case DW_OP_GNU_entry_value:
2243 case DW_OP_entry_value: {
2245 opcodes, offset, log))
2246 return llvm::createStringError(
2247 "could not evaluate DW_OP_entry_value: %s",
2248 llvm::toString(std::move(err)).c_str());
2255 op, opcodes, offset, stack)) {
2259 return llvm::createStringError(llvm::formatv(
2260 "Unhandled opcode {0} in DWARFExpression", LocationAtom(op)));
2264 if (stack.empty()) {
2270 return llvm::createStringError(
"stack empty after evaluation");
2273 UpdateValueTypeFromLocationDescription(
2274 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2277 size_t count = stack.size();
2279 "Stack after operation has %" PRIu64
" values:", (uint64_t)count);
2280 for (
size_t i = 0; i < count; ++i) {
2282 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
2283 stack[i].Dump(&new_value);
2287 return stack.back();
2293 location_list->
Clear();
2294 std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2298 [&](uint32_t index) -> std::optional<llvm::object::SectionedAddress> {
2301 return std::nullopt;
2302 return llvm::object::SectionedAddress{address};
2304 auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2310 std::make_shared<DataBufferHeap>(loc->Expr.data(), loc->Expr.size());
2313 location_list->
AddExpression(loc->Range->LowPC, loc->Range->HighPC, expr);
2316 llvm::Error
error = loctable_up->visitAbsoluteLocationList(
2318 lookup_addr, process_list);
2319 location_list->
Sort();
2329 using namespace OperandMatchers;
2339 uint8_t opcode = opcodes.
GetU8(&op_offset);
2341 if (opcode == DW_OP_fbreg) {
2342 int64_t offset = opcodes.
GetSLEB128(&op_offset);
2355 recurse)(operand)) {
2359 return MatchUnaryOp(
2362 MatchImmOp(offset), recurse))(operand);
2365 bool dereference =
false;
2369 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2370 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_reg0);
2371 }
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2373 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_breg0);
2374 }
else if (opcode == DW_OP_regx) {
2375 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2376 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2377 }
else if (opcode == DW_OP_bregx) {
2378 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2380 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2392 MatchRegOp(*reg))(operand)) {
2396 return MatchUnaryOp(
2400 MatchImmOp(offset)))(operand);
2402 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 lldb::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.