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);
346llvm::Expected<lldb::addr_t>
352 if (op == DW_OP_addr)
355 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
359 return llvm::createStringError(
"cannot evaluate %s without a DWARF unit",
366 return llvm::createStringError(
"cannot get opcode data size for %s",
369 offset += op_arg_size;
381 if (op == DW_OP_addr) {
403 if (op == DW_OP_addrx) {
407 llvm::ArrayRef data_before_op =
m_data.
GetData().take_front(offset - 1);
412 if (old_offset == offset)
414 llvm::ArrayRef data_after_op =
m_data.
GetData().drop_front(offset);
428 offset += op_arg_size;
439 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
445 offset += op_arg_size;
452 &link_address_callback) {
466 size_t const_byte_size = 0;
470 bool decoded_data =
false;
475 const_offset = offset;
484 const_offset = offset;
490 case DW_OP_form_tls_address:
491 case DW_OP_GNU_push_tls_address:
502 if (const_byte_size > 0) {
503 lldb::addr_t linked_file_addr = link_address_callback(const_value);
507 if (encoder.
PutUnsigned(const_offset, const_byte_size,
526 offset += op_arg_size;
586 return llvm::createStringError(
"no exe/reg context");
591 if (!current_frame || !thread)
592 return llvm::createStringError(
"no current frame/thread");
599 for (uint32_t parent_frame_idx = current_frame_idx + 1;;parent_frame_idx++) {
609 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
610 LLDB_LOG(log,
"immediate ancestor with pc = {0:x}", return_pc);
615 if (parent_frame->IsInlined())
621 if (!parent_frame || !parent_frame->GetRegisterContext()) {
622 return llvm::createStringError(
"no parent frame with reg ctx");
626 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
628 return llvm::createStringError(
"no parent function");
635 return llvm::createStringError(
"no current function");
641 if (!parent_frame->IsArtificial()) {
646 return llvm::createStringError(
647 llvm::formatv(
"no call edge for retn-pc = {0:x} in parent frame {1}",
648 return_pc, parent_func->
GetName()));
651 if (callee_func != current_func) {
652 return llvm::createStringError(
653 "ambiguous call sequence, can't find real parent frame");
660 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
661 call_edge = edge.get();
667 return llvm::createStringError(
"no unambiguous edge from parent "
668 "to current function");
673 const uint32_t subexpr_len = opcodes.
GetULEB128(&opcode_offset);
674 const void *subexpr_data = opcodes.
GetData(&opcode_offset, subexpr_len);
676 return llvm::createStringError(
"subexpr could not be read");
681 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
684 const void *param_subexpr_data =
685 param_subexpr_extractor.
GetData(¶m_subexpr_offset, subexpr_len);
686 if (!param_subexpr_data ||
687 param_subexpr_extractor.
BytesLeft(param_subexpr_offset) != 0)
697 if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
698 matched_param = ¶m;
703 return llvm::createStringError(
"no matching call site param found");
709 llvm::Expected<Value> maybe_result = param_expr.
Evaluate(
716 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
717 return maybe_result.takeError();
720 stack.push_back(*maybe_result);
721 return llvm::Error::success();
728enum LocationDescriptionKind {
736void UpdateValueTypeFromLocationDescription(
Log *log,
const DWARFUnit *dwarf_cu,
737 LocationDescriptionKind kind,
738 Value *value =
nullptr) {
745 if (dwarf_cu && dwarf_cu->
GetVersion() >= 4) {
746 const char *log_msg =
"DWARF location description kind: %s";
785static llvm::Expected<lldb::addr_t>
788 Address &so_addr,
bool check_sectionoffset =
false) {
790 return llvm::createStringError(
"need module to resolve file address for %s",
793 if (!module_sp->ResolveFileAddress(file_addr, so_addr))
794 return llvm::createStringError(
"failed to resolve file address in module");
800 return llvm::createStringError(
"failed to resolve load address");
814 size_t size_addr_bytes,
816 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
820 return addr_data.
GetMaxU64(&addr_data_offset, size);
822 return addr_data.
GetAddress(&addr_data_offset);
829 const Value *initial_value_ptr,
const Value *object_address_ptr) {
832 return llvm::createStringError(
833 "no location, value may have been optimized out");
834 std::vector<Value> stack;
845 if (reg_ctx ==
nullptr && frame)
848 if (initial_value_ptr)
849 stack.push_back(*initial_value_ptr);
856 uint64_t op_piece_offset = 0;
864 auto to_generic = [&](
auto v) {
867 bool is_signed = std::is_signed<
decltype(v)>::value;
876 LocationDescriptionKind dwarf4_location_description_kind =
Memory;
880 const uint8_t op = opcodes.
GetU8(&offset);
883 size_t count = stack.size();
884 LLDB_LOGF(log,
"Stack before operation has %" PRIu64
" values:",
886 for (
size_t i = 0; i < count; ++i) {
888 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
889 stack[i].Dump(&new_value);
892 LLDB_LOGF(log,
"0x%8.8" PRIx64
": %s", op_offset,
896 if (std::optional<unsigned> arity =
897 llvm::dwarf::OperationArity(
static_cast<LocationAtom
>(op))) {
898 if (stack.size() < *arity)
899 return llvm::createStringError(
900 "%s needs at least %d stack entries (stack has %d entries)",
964 return llvm::createStringError(
965 "expression stack empty for DW_OP_deref");
967 switch (value_type) {
969 void *src = (
void *)stack.back().GetScalar().ULongLong();
971 ::memcpy(&ptr, src,
sizeof(
void *));
972 stack.back().GetScalar() = ptr;
973 stack.back().ClearContext();
976 auto file_addr = stack.back().GetScalar().ULongLong(
981 exe_ctx, module_sp,
"DW_OP_deref", file_addr, so_addr);
983 if (!maybe_load_addr)
984 return maybe_load_addr.takeError();
986 stack.back().GetScalar() = *maybe_load_addr;
1004 pointer_value = abi_sp->FixCodeAddress(pointer_value);
1005 stack.back().GetScalar() = pointer_value;
1006 stack.back().ClearContext();
1008 return llvm::createStringError(
1009 "Failed to dereference pointer from 0x%" PRIx64
1010 " for DW_OP_deref: %s\n",
1011 pointer_addr,
error.AsCString());
1014 return llvm::createStringError(
"NULL process for DW_OP_deref");
1017 return llvm::createStringError(
1018 "NULL execution context for DW_OP_deref");
1023 return llvm::createStringError(
"invalid value type for DW_OP_deref");
1040 case DW_OP_deref_size: {
1041 if (stack.empty()) {
1042 return llvm::createStringError(
1043 "expression stack empty for DW_OP_deref_size");
1045 uint8_t size = opcodes.
GetU8(&offset);
1047 return llvm::createStringError(
1048 "Invalid address size for DW_OP_deref_size: %d\n", size);
1051 switch (value_type) {
1053 void *src = (
void *)stack.back().GetScalar().ULongLong();
1055 ::memcpy(&ptr, src,
sizeof(
void *));
1068 ptr = ptr & 0xffffff;
1071 ptr = ptr & 0xffffffff;
1078 ptr = (intptr_t)ptr & 0xffffffffffULL;
1081 ptr = (intptr_t)ptr & 0xffffffffffffULL;
1084 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
1089 stack.back().GetScalar() = ptr;
1090 stack.back().ClearContext();
1097 exe_ctx, module_sp,
"DW_OP_deref_size", file_addr, so_addr,
1100 if (!maybe_load_addr)
1101 return maybe_load_addr.takeError();
1103 addr_t load_addr = *maybe_load_addr;
1106 uint8_t addr_bytes[8];
1112 ObjectFile *objfile = module_sp->GetObjectFile();
1116 stack.back().ClearContext();
1119 return llvm::createStringError(
1120 "Failed to dereference pointer for DW_OP_deref_size: "
1125 stack.back().GetScalar() = load_addr;
1141 stack.back().GetScalar() =
1144 stack.back().ClearContext();
1146 return llvm::createStringError(
1147 "Failed to dereference pointer from 0x%" PRIx64
1148 " for DW_OP_deref: %s\n",
1149 pointer_addr,
error.AsCString());
1153 return llvm::createStringError(
"NULL process for DW_OP_deref_size");
1156 return llvm::createStringError(
1157 "NULL execution context for DW_OP_deref_size");
1163 return llvm::createStringError(
"invalid value for DW_OP_deref_size");
1183 case DW_OP_xderef_size:
1184 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef_size");
1196 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef");
1212 stack.push_back(to_generic(opcodes.
GetU8(&offset)));
1215 stack.push_back(to_generic((int8_t)opcodes.
GetU8(&offset)));
1218 stack.push_back(to_generic(opcodes.
GetU16(&offset)));
1221 stack.push_back(to_generic((int16_t)opcodes.
GetU16(&offset)));
1224 stack.push_back(to_generic(opcodes.
GetU32(&offset)));
1227 stack.push_back(to_generic((int32_t)opcodes.
GetU32(&offset)));
1230 stack.push_back(to_generic(opcodes.
GetU64(&offset)));
1233 stack.push_back(to_generic((int64_t)opcodes.
GetU64(&offset)));
1248 if (stack.empty()) {
1249 return llvm::createStringError(
"expression stack empty for DW_OP_dup");
1251 stack.push_back(stack.back());
1258 if (stack.empty()) {
1259 return llvm::createStringError(
"expression stack empty for DW_OP_drop");
1269 stack.push_back(stack[stack.size() - 2]);
1277 uint8_t pick_idx = opcodes.
GetU8(&offset);
1278 if (pick_idx < stack.size())
1279 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1281 return llvm::createStringError(
1282 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1293 stack.back() = stack[stack.size() - 2];
1294 stack[stack.size() - 2] = tmp;
1304 size_t last_idx = stack.size() - 1;
1305 Value old_top = stack[last_idx];
1306 stack[last_idx] = stack[last_idx - 1];
1307 stack[last_idx - 1] = stack[last_idx - 2];
1308 stack[last_idx - 2] = old_top;
1317 if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1318 return llvm::createStringError(
1319 "failed to take the absolute value of the first stack item");
1331 stack.back().ResolveValue(exe_ctx) & tmp.
ResolveValue(exe_ctx);
1342 return llvm::createStringError(
"divide by zero");
1345 Scalar divisor, dividend;
1347 dividend = stack.back().ResolveValue(exe_ctx);
1350 stack.back() = dividend / divisor;
1352 if (!stack.back().ResolveValue(exe_ctx).IsValid())
1353 return llvm::createStringError(
"divide failed");
1364 stack.back().ResolveValue(exe_ctx) - tmp.
ResolveValue(exe_ctx);
1376 stack.back().ResolveValue(exe_ctx) % tmp.
ResolveValue(exe_ctx);
1387 stack.back().ResolveValue(exe_ctx) * tmp.
ResolveValue(exe_ctx);
1394 if (!stack.back().ResolveValue(exe_ctx).UnaryNegate())
1395 return llvm::createStringError(
"unary negate failed");
1403 if (!stack.back().ResolveValue(exe_ctx).OnesComplement())
1404 return llvm::createStringError(
"logical NOT failed");
1415 stack.back().ResolveValue(exe_ctx) | tmp.
ResolveValue(exe_ctx);
1432 case DW_OP_plus_uconst: {
1433 const uint64_t uconst_value = opcodes.
GetULEB128(&offset);
1435 stack.back().GetScalar() += uconst_value;
1436 if (!stack.back().GetScalar().IsValid())
1437 return llvm::createStringError(
"DW_OP_plus_uconst failed");
1459 if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1461 return llvm::createStringError(
"DW_OP_shr failed");
1484 stack.back().ResolveValue(exe_ctx) ^ tmp.
ResolveValue(exe_ctx);
1494 int16_t skip_offset = (int16_t)opcodes.
GetU16(&offset);
1500 offset = new_offset;
1502 return llvm::createStringError(llvm::formatv(
1503 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1518 int16_t bra_offset = (int16_t)opcodes.
GetU16(&offset);
1526 offset = new_offset;
1528 return llvm::createStringError(llvm::formatv(
1529 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1546 stack.back().ResolveValue(exe_ctx) == tmp.
ResolveValue(exe_ctx);
1560 stack.back().ResolveValue(exe_ctx) >= tmp.
ResolveValue(exe_ctx);
1574 stack.back().ResolveValue(exe_ctx) > tmp.
ResolveValue(exe_ctx);
1588 stack.back().ResolveValue(exe_ctx) <= tmp.
ResolveValue(exe_ctx);
1602 stack.back().ResolveValue(exe_ctx) < tmp.
ResolveValue(exe_ctx);
1616 stack.back().ResolveValue(exe_ctx) != tmp.
ResolveValue(exe_ctx);
1656 stack.push_back(to_generic(op - DW_OP_lit0));
1694 dwarf4_location_description_kind = Register;
1695 reg_num = op - DW_OP_reg0;
1697 if (llvm::Error err =
1700 stack.push_back(tmp);
1707 dwarf4_location_description_kind = Register;
1710 if (llvm::Error err =
1713 stack.push_back(tmp);
1752 case DW_OP_breg31: {
1753 reg_num = op - DW_OP_breg0;
1754 if (llvm::Error err =
1758 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1761 stack.push_back(tmp);
1772 if (llvm::Error err =
1776 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1779 stack.push_back(tmp);
1789 int64_t fbreg_offset = opcodes.
GetSLEB128(&offset);
1790 value += fbreg_offset;
1791 stack.push_back(value);
1794 return llvm::createStringError(
1795 "invalid stack frame in context for DW_OP_fbreg opcode");
1798 return llvm::createStringError(
1799 "NULL execution context for DW_OP_fbreg");
1825 LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
1827 dwarf4_location_description_kind =
Memory;
1829 const uint64_t piece_byte_size = opcodes.
GetULEB128(&offset);
1831 if (piece_byte_size > 0) {
1834 if (stack.empty()) {
1835 UpdateValueTypeFromLocationDescription(
1836 log, dwarf_cu, LocationDescriptionKind::Empty);
1850 Value curr_piece_source_value(stack.back());
1852 UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
1853 &curr_piece_source_value);
1859 switch (curr_piece_source_value_type) {
1861 return llvm::createStringError(
"invalid value type");
1868 return llvm::createStringError(
1869 "unable to convert file address 0x%" PRIx64
1871 "for DW_OP_piece(%" PRIu64
"): "
1872 "no target available",
1873 addr, piece_byte_size);
1878 if (curr_piece.
ResizeData(piece_byte_size) == piece_byte_size) {
1880 piece_byte_size,
error,
1883 const char *addr_type = (curr_piece_source_value_type ==
1887 return llvm::createStringError(
1888 "failed to read memory DW_OP_piece(%" PRIu64
1889 ") from %s address 0x%" PRIx64,
1890 piece_byte_size, addr_type, addr);
1893 return llvm::createStringError(
1894 "failed to resize the piece memory buffer for "
1895 "DW_OP_piece(%" PRIu64
")",
1901 return llvm::createStringError(
1902 "failed to read memory DW_OP_piece(%" PRIu64
1903 ") from host address 0x%" PRIx64,
1904 piece_byte_size, addr);
1908 uint32_t bit_size = piece_byte_size * 8;
1909 uint32_t bit_offset = 0;
1911 bit_size, bit_offset)) {
1912 return llvm::createStringError(
1913 "unable to extract %" PRIu64
" bytes from a %" PRIu64
1914 " byte scalar value.",
1920 llvm::APInt fail_value(1, 0,
false);
1921 llvm::APInt ap_int = scalar.
UInt128(fail_value);
1922 assert(ap_int.getBitWidth() >= bit_size);
1923 llvm::ArrayRef<uint64_t> buf{ap_int.getRawData(),
1924 ap_int.getNumWords()};
1930 if (op_piece_offset == 0) {
1935 return llvm::createStringError(
"failed to append piece data");
1941 return llvm::createStringError(
1942 "DW_OP_piece for offset %" PRIu64
1943 " but top of stack is of size %" PRIu64,
1948 return llvm::createStringError(
"failed to append piece data");
1951 op_piece_offset += piece_byte_size;
1955 case DW_OP_bit_piece:
1956 if (stack.size() < 1) {
1957 UpdateValueTypeFromLocationDescription(log, dwarf_cu,
1958 LocationDescriptionKind::Empty);
1960 dwarf4_location_description_kind =
Memory;
1961 return llvm::createStringError(
1962 "expression stack needs at least 1 item for DW_OP_bit_piece");
1964 UpdateValueTypeFromLocationDescription(
1965 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
1967 dwarf4_location_description_kind =
Memory;
1968 const uint64_t piece_bit_size = opcodes.
GetULEB128(&offset);
1969 const uint64_t piece_bit_offset = opcodes.
GetULEB128(&offset);
1970 switch (stack.back().GetValueType()) {
1972 return llvm::createStringError(
1973 "unable to extract bit value from invalid value");
1975 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
1976 piece_bit_offset)) {
1977 return llvm::createStringError(
1978 "unable to extract %" PRIu64
" bit value with %" PRIu64
1979 " bit offset from a %" PRIu64
" bit scalar value.",
1980 piece_bit_size, piece_bit_offset,
1981 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
1988 return llvm::createStringError(
1989 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
1990 ", bit_offset = %" PRIu64
") from an address value.",
1991 piece_bit_size, piece_bit_offset);
2003 case DW_OP_implicit_value: {
2004 dwarf4_location_description_kind = Implicit;
2006 const uint32_t len = opcodes.
GetULEB128(&offset);
2007 const void *data = opcodes.
GetData(&offset, len);
2010 LLDB_LOG(log,
"Evaluate_DW_OP_implicit_value: could not be read data");
2011 return llvm::createStringError(
"could not evaluate %s",
2015 Value result(data, len);
2016 stack.push_back(result);
2020 case DW_OP_implicit_pointer: {
2021 dwarf4_location_description_kind = Implicit;
2022 return llvm::createStringError(
"Could not evaluate %s.",
2034 case DW_OP_push_object_address:
2035 if (object_address_ptr)
2036 stack.push_back(*object_address_ptr);
2038 return llvm::createStringError(
"DW_OP_push_object_address used without "
2039 "specifying an object address");
2062 return llvm::createStringError(
"unimplemented opcode DW_OP_call2");
2083 return llvm::createStringError(
"unimplemented opcode DW_OP_call4");
2090 case DW_OP_stack_value:
2091 dwarf4_location_description_kind = Implicit;
2102 case DW_OP_convert: {
2103 const uint64_t die_offset = opcodes.
GetULEB128(&offset);
2106 if (die_offset == 0) {
2111 return llvm::createStringError(
"no module");
2113 bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2115 return llvm::createStringError(
"unspecified architecture");
2119 const uint64_t abs_die_offset = die_offset + dwarf_cu->
GetOffset();
2123 return llvm::createStringError(
2124 "cannot resolve DW_OP_convert type DIE");
2131 return llvm::createStringError(
2132 "unsupported type size in DW_OP_convert");
2135 case DW_ATE_signed_char:
2138 case DW_ATE_unsigned:
2139 case DW_ATE_unsigned_char:
2143 return llvm::createStringError(
2144 "unsupported encoding in DW_OP_convert");
2147 Scalar &top = stack.back().ResolveValue(exe_ctx);
2157 case DW_OP_call_frame_cfa:
2164 stack.push_back(
Scalar(cfa));
2167 return llvm::createStringError(
2168 "stack frame does not include a canonical "
2169 "frame address for DW_OP_call_frame_cfa "
2173 return llvm::createStringError(
"unvalid stack frame in context for "
2174 "DW_OP_call_frame_cfa opcode");
2184 case DW_OP_form_tls_address:
2185 case DW_OP_GNU_push_tls_address: {
2186 if (stack.size() < 1) {
2187 if (op == DW_OP_form_tls_address)
2188 return llvm::createStringError(
2189 "DW_OP_form_tls_address needs an argument");
2191 return llvm::createStringError(
2192 "DW_OP_GNU_push_tls_address needs an argument");
2195 if (!exe_ctx || !module_sp)
2196 return llvm::createStringError(
"no context to evaluate TLS within");
2200 return llvm::createStringError(
"no thread to evaluate TLS within");
2203 const addr_t tls_file_addr =
2205 const addr_t tls_load_addr =
2209 return llvm::createStringError(
2210 "no TLS data currently exists for this thread");
2212 stack.back().GetScalar() = tls_load_addr;
2223 case DW_OP_GNU_addr_index: {
2225 return llvm::createStringError(
"DW_OP_GNU_addr_index found without a "
2226 "compile unit being specified");
2227 uint64_t index = opcodes.
GetULEB128(&offset);
2229 stack.push_back(
Scalar(value));
2247 case DW_OP_GNU_const_index: {
2249 return llvm::createStringError(
"DW_OP_GNU_const_index found without a "
2250 "compile unit being specified");
2252 uint64_t index = opcodes.
GetULEB128(&offset);
2254 stack.push_back(
Scalar(value));
2257 case DW_OP_GNU_entry_value:
2258 case DW_OP_entry_value: {
2260 opcodes, offset, log))
2261 return llvm::createStringError(
2262 "could not evaluate DW_OP_entry_value: %s",
2263 llvm::toString(std::move(err)).c_str());
2270 op, opcodes, offset, stack)) {
2274 return llvm::createStringError(llvm::formatv(
2275 "Unhandled opcode {0} in DWARFExpression", LocationAtom(op)));
2279 if (stack.empty()) {
2285 return llvm::createStringError(
"stack empty after evaluation");
2288 UpdateValueTypeFromLocationDescription(
2289 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2292 size_t count = stack.size();
2294 "Stack after operation has %" PRIu64
" values:", (uint64_t)count);
2295 for (
size_t i = 0; i < count; ++i) {
2297 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
2298 stack[i].Dump(&new_value);
2302 return stack.back();
2308 location_list->
Clear();
2309 std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2313 [&](uint32_t index) -> std::optional<llvm::object::SectionedAddress> {
2316 return std::nullopt;
2317 return llvm::object::SectionedAddress{address};
2319 auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2325 std::make_shared<DataBufferHeap>(loc->Expr.data(), loc->Expr.size());
2328 location_list->
AddExpression(loc->Range->LowPC, loc->Range->HighPC, expr);
2331 llvm::Error
error = loctable_up->visitAbsoluteLocationList(
2333 lookup_addr, process_list);
2334 location_list->
Sort();
2344 using namespace OperandMatchers;
2354 uint8_t opcode = opcodes.
GetU8(&op_offset);
2356 if (opcode == DW_OP_fbreg) {
2357 int64_t offset = opcodes.
GetSLEB128(&op_offset);
2370 recurse)(operand)) {
2374 return MatchUnaryOp(
2377 MatchImmOp(offset), recurse))(operand);
2380 bool dereference =
false;
2384 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2385 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_reg0);
2386 }
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2388 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_breg0);
2389 }
else if (opcode == DW_OP_regx) {
2390 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2391 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2392 }
else if (opcode == DW_OP_bregx) {
2393 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2395 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2407 MatchRegOp(*reg))(operand)) {
2411 return MatchUnaryOp(
2415 MatchImmOp(offset)))(operand);
2417 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
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.
llvm::Expected< lldb::addr_t > GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
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.
llvm::Error GetFrameBaseValue(Scalar &value)
Return the Canonical Frame Address (DWARF term) for this frame.
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.
lldb::addr_t GetCallFrameAddress() 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).
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
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.