39#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
40#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
45using namespace llvm::dwarf;
59 uint8_t addr_byte_size) {
60 if (!const_value_byte_size)
66 m_data.SetAddressByteSize(addr_byte_size);
71 llvm::DIDumpOptions options)
const {
73 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum,
74 bool IsEH) -> llvm::StringRef {
77 if (std::optional<unsigned> LLVMRegNum =
78 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
79 if (
const char *RegName = MCRegInfo->getName(*LLVMRegNum))
80 return llvm::StringRef(RegName);
83 options.GetNameForDWARFReg = GetRegName;
84 llvm::DWARFExpression E(
m_data.GetAsLLVM(),
m_data.GetAddressByteSize());
85 llvm::printDwarfExpression(&E, s->
AsRawOstream(), options,
nullptr);
97 uint32_t reg_num,
Value &value) {
98 if (reg_ctx ==
nullptr)
99 return llvm::createStringError(
"no register context in frame");
101 const uint32_t native_reg =
104 return llvm::createStringError(
105 "unable to convert register kind=%u reg_num=%u to a native "
116 return llvm::Error::success();
121 return llvm::createStringError(
122 "register %s can't be converted to a scalar value", reg_info->
name);
125 return llvm::createStringError(
"register %s is not available",
133 const LocationAtom op,
138 case DW_OP_LLVM_fragment:
139 case DW_OP_LLVM_convert:
140 case DW_OP_LLVM_tag_offset:
141 case DW_OP_LLVM_entry_value:
142 case DW_OP_LLVM_implicit_pointer:
144 case DW_OP_LLVM_extract_bits_sext:
145 case DW_OP_LLVM_extract_bits_zext:
148 case DW_OP_HP_is_value:
149 case DW_OP_HP_fltconst4:
150 case DW_OP_HP_fltconst8:
151 case DW_OP_HP_mod_range:
152 case DW_OP_HP_unmod_range:
154 case DW_OP_INTEL_bit_piece:
155 case DW_OP_WASM_location:
156 case DW_OP_WASM_location_int:
157 case DW_OP_APPLE_uninit:
158 case DW_OP_PGI_omp_thread_num:
160 case DW_OP_GNU_implicit_pointer:
260 case DW_OP_push_object_address:
261 case DW_OP_form_tls_address:
262 case DW_OP_call_frame_cfa:
263 case DW_OP_stack_value:
264 case DW_OP_GNU_push_tls_address:
271 case DW_OP_deref_size:
272 case DW_OP_xderef_size:
273 case DW_OP_deref_type:
298 case DW_OP_plus_uconst:
335 case DW_OP_reinterpret:
338 case DW_OP_xderef_type:
339 case DW_OP_GNU_addr_index:
340 case DW_OP_GNU_const_index:
342 return offset - data_offset;
346 case DW_OP_bit_piece:
347 case DW_OP_regval_type:
350 return offset - data_offset;
352 case DW_OP_implicit_value:
357 return offset - data_offset;
360 case DW_OP_implicit_pointer:
368 case DW_OP_GNU_entry_value:
369 case DW_OP_entry_value:
371 uint64_t subexpr_len = data.
GetULEB128(&offset);
372 return (offset - data_offset) + subexpr_len;
375 case DW_OP_const_type:
378 uint8_t length = data.
GetU8(&offset);
379 return (offset - data_offset) + length;
382 case DW_OP_LLVM_user:
384 uint64_t constants = data.
GetULEB128(&offset);
385 return (offset - data_offset) + constants;
396 static char invalid[100];
397 llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString(val);
398 if (llvmstr.empty()) {
399 snprintf(invalid,
sizeof(invalid),
"Unknown DW_OP constant: 0x%x", val);
402 return llvmstr.data();
408 while (
m_data.ValidOffset(offset)) {
409 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
411 if (op == DW_OP_addr)
412 return m_data.GetAddress(&offset);
414 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
415 const uint64_t index =
m_data.GetULEB128(&offset);
418 return llvm::createStringError(
"cannot evaluate %s without a DWARF unit",
425 return llvm::createStringError(
"cannot get opcode data size for %s",
428 offset += op_arg_size;
437 while (
m_data.ValidOffset(offset)) {
438 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
440 if (op == DW_OP_addr) {
441 const uint32_t addr_byte_size =
m_data.GetAddressByteSize();
451 m_data.GetByteOrder(), addr_byte_size);
462 if (op == DW_OP_addrx) {
466 llvm::ArrayRef data_before_op =
m_data.GetData().take_front(offset - 1);
470 m_data.GetULEB128(&offset);
471 if (old_offset == offset)
473 llvm::ArrayRef data_after_op =
m_data.GetData().drop_front(offset);
487 offset += op_arg_size;
495 while (
m_data.ValidOffset(offset)) {
496 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
498 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
504 offset += op_arg_size;
511 &link_address_callback) {
512 const uint32_t addr_byte_size =
m_data.GetAddressByteSize();
520 m_data.GetByteOrder(), addr_byte_size);
525 size_t const_byte_size = 0;
526 while (
m_data.ValidOffset(offset)) {
527 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
529 bool decoded_data =
false;
534 const_offset = offset;
535 const_value =
m_data.GetU32(&offset);
543 const_offset = offset;
544 const_value =
m_data.GetU64(&offset);
549 case DW_OP_form_tls_address:
550 case DW_OP_GNU_push_tls_address:
561 if (const_byte_size > 0) {
562 lldb::addr_t linked_file_addr = link_address_callback(const_value);
566 if (encoder.
PutUnsigned(const_offset, const_byte_size,
585 offset += op_arg_size;
645 return llvm::createStringError(
"no exe/reg context");
650 if (!current_frame || !thread)
651 return llvm::createStringError(
"no current frame/thread");
658 for (uint32_t parent_frame_idx = current_frame_idx + 1;; parent_frame_idx++) {
659 parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
668 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
669 LLDB_LOG(log,
"immediate ancestor with pc = {0:x}", return_pc);
674 if (parent_frame->IsInlined())
680 if (!parent_frame || !parent_frame->GetRegisterContext()) {
681 return llvm::createStringError(
"no parent frame with reg ctx");
685 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
687 return llvm::createStringError(
"no parent function");
694 return llvm::createStringError(
"no current function");
700 if (!parent_frame->IsArtificial()) {
705 return llvm::createStringError(
706 llvm::formatv(
"no call edge for retn-pc = {0:x} in parent frame {1}",
707 return_pc, parent_func->
GetName()));
710 if (callee_func != current_func) {
711 return llvm::createStringError(
712 "ambiguous call sequence, can't find real parent frame");
719 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
720 call_edge = edge.get();
726 return llvm::createStringError(
"no unambiguous edge from parent "
727 "to current function");
732 const uint32_t subexpr_len = opcodes.
GetULEB128(&opcode_offset);
733 const void *subexpr_data = opcodes.
GetData(&opcode_offset, subexpr_len);
735 return llvm::createStringError(
"subexpr could not be read");
740 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
743 const void *param_subexpr_data =
744 param_subexpr_extractor.
GetData(¶m_subexpr_offset, subexpr_len);
745 if (!param_subexpr_data ||
746 param_subexpr_extractor.
BytesLeft(param_subexpr_offset) != 0)
756 if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
757 matched_param = ¶m;
762 return llvm::createStringError(
"no matching call site param found");
768 llvm::Expected<Value> maybe_result = param_expr.
Evaluate(
769 &parent_exe_ctx, parent_frame->GetRegisterContext().get(),
775 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
776 return maybe_result.takeError();
779 stack.push_back(*maybe_result);
780 return llvm::Error::success();
787enum LocationDescriptionKind {
795void UpdateValueTypeFromLocationDescription(
797 LocationDescriptionKind kind,
Value *value =
nullptr) {
804 if (dwarf_cu && dwarf_cu->
GetVersion() >= 4) {
805 const char *log_msg =
"DWARF location description kind: %s";
844static llvm::Expected<lldb::addr_t>
847 Address &so_addr,
bool check_sectionoffset =
false) {
849 return llvm::createStringError(
"need module to resolve file address for %s",
852 if (!module_sp->ResolveFileAddress(file_addr, so_addr))
853 return llvm::createStringError(
"failed to resolve file address in module");
859 return llvm::createStringError(
"failed to resolve load address");
872 size_t size_addr_bytes,
874 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
878 return addr_data.
GetMaxU64(&addr_data_offset, size);
879 return addr_data.
GetAddress(&addr_data_offset);
885 size_t size_addr_bytes,
886 LocationDescriptionKind &dwarf4_location_description_kind) {
888 return llvm::createStringError(
889 "expression stack empty for DW_OP_deref_size");
892 return llvm::createStringError(
893 "Invalid address size for DW_OP_deref_size: %d\n", size);
898 if (dwarf4_location_description_kind == Register ||
899 dwarf4_location_description_kind == Implicit) {
901 dwarf4_location_description_kind =
Memory;
902 stack.back().ClearContext();
906 Scalar scalar = stack.back().GetScalar();
910 stack.back().GetScalar() = scalar;
911 return llvm::Error::success();
915 switch (value_type) {
917 void *src = (
void *)stack.back().GetScalar().ULongLong();
919 ::memcpy(&ptr, src,
sizeof(
void *));
931 ptr = ptr & 0xffffff;
934 ptr = ptr & 0xffffffff;
940 ptr = (intptr_t)ptr & 0xffffffffffULL;
943 ptr = (intptr_t)ptr & 0xffffffffffffULL;
946 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
951 stack.back().GetScalar() = ptr;
952 stack.back().ClearContext();
958 exe_ctx, module_sp,
"DW_OP_deref_size", file_addr, so_addr,
961 if (!maybe_load_addr)
962 return maybe_load_addr.takeError();
964 addr_t load_addr = *maybe_load_addr;
967 uint8_t addr_bytes[8];
972 return llvm::createStringError(
973 "failed to dereference pointer for DW_OP_deref_size: "
977 ObjectFile *objfile = module_sp->GetObjectFile();
981 stack.back().ClearContext();
984 stack.back().GetScalar() = load_addr;
995 return llvm::createStringError(
996 "no execution context for DW_OP_deref_size");
998 return llvm::createStringError(
"no process for DW_OP_deref_size");
1005 if (process->
ReadMemory(pointer_addr, &addr_bytes, size,
error) != size)
1006 return llvm::createStringError(
1007 "failed to dereference pointer from 0x%" PRIx64
1008 " for DW_OP_deref_size: %s\n",
1009 pointer_addr,
error.AsCString());
1012 addr_bytes,
sizeof(addr_bytes), process->
GetByteOrder(), size);
1013 stack.back().ClearContext();
1017 return llvm::createStringError(
"invalid value for DW_OP_deref_size");
1020 return llvm::Error::success();
1028 const Value *object_address_ptr) {
1031 return llvm::createStringError(
1032 "no location, value may have been optimized out");
1038 Target *target =
nullptr;
1045 if (reg_ctx ==
nullptr && frame)
1048 if (initial_value_ptr)
1049 stack.push_back(*initial_value_ptr);
1056 uint64_t op_piece_offset = 0;
1064 auto to_generic = [&](
auto v) {
1067 bool is_signed = std::is_signed<
decltype(v)>::value;
1076 LocationDescriptionKind dwarf4_location_description_kind =
Memory;
1080 const uint8_t op = opcodes.
GetU8(&offset);
1083 size_t count = stack.size();
1084 LLDB_LOGF(log,
"Stack before operation has %" PRIu64
" values:",
1086 for (
size_t i = 0; i < count; ++i) {
1088 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
1089 stack[i].Dump(&new_value);
1092 LLDB_LOGF(log,
"0x%8.8" PRIx64
": %s", op_offset,
1096 if (std::optional<unsigned> arity =
1097 llvm::dwarf::OperationArity(
static_cast<LocationAtom
>(op))) {
1098 if (stack.size() < *arity)
1099 return llvm::createStringError(
1100 "%s needs at least %d stack entries (stack has %d entries)",
1165 stack, exe_ctx, module_sp, process, target, size, size,
1166 dwarf4_location_description_kind))
1182 case DW_OP_deref_size: {
1183 size_t size = opcodes.
GetU8(&offset);
1185 stack, exe_ctx, module_sp, process, target, size,
1205 case DW_OP_xderef_size:
1206 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef_size");
1218 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef");
1234 stack.push_back(to_generic(opcodes.
GetU8(&offset)));
1237 stack.push_back(to_generic((int8_t)opcodes.
GetU8(&offset)));
1240 stack.push_back(to_generic(opcodes.
GetU16(&offset)));
1243 stack.push_back(to_generic((int16_t)opcodes.
GetU16(&offset)));
1246 stack.push_back(to_generic(opcodes.
GetU32(&offset)));
1249 stack.push_back(to_generic((int32_t)opcodes.
GetU32(&offset)));
1252 stack.push_back(to_generic(opcodes.
GetU64(&offset)));
1255 stack.push_back(to_generic((int64_t)opcodes.
GetU64(&offset)));
1270 if (stack.empty()) {
1271 return llvm::createStringError(
"expression stack empty for DW_OP_dup");
1273 stack.push_back(stack.back());
1280 if (stack.empty()) {
1281 return llvm::createStringError(
"expression stack empty for DW_OP_drop");
1291 stack.push_back(stack[stack.size() - 2]);
1299 uint8_t pick_idx = opcodes.
GetU8(&offset);
1300 if (pick_idx < stack.size())
1301 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1303 return llvm::createStringError(
1304 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1315 stack.back() = stack[stack.size() - 2];
1316 stack[stack.size() - 2] = tmp;
1326 size_t last_idx = stack.size() - 1;
1327 Value old_top = stack[last_idx];
1328 stack[last_idx] = stack[last_idx - 1];
1329 stack[last_idx - 1] = stack[last_idx - 2];
1330 stack[last_idx - 2] = old_top;
1339 if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1340 return llvm::createStringError(
1341 "failed to take the absolute value of the first stack item");
1352 stack.back().ResolveValue(exe_ctx) =
1353 stack.back().ResolveValue(exe_ctx) & tmp.
ResolveValue(exe_ctx);
1364 return llvm::createStringError(
"divide by zero");
1367 Scalar divisor, dividend;
1369 dividend = stack.back().ResolveValue(exe_ctx);
1372 stack.back() = dividend / divisor;
1374 if (!stack.back().ResolveValue(exe_ctx).IsValid())
1375 return llvm::createStringError(
"divide failed");
1385 stack.back().ResolveValue(exe_ctx) =
1386 stack.back().ResolveValue(exe_ctx) - tmp.
ResolveValue(exe_ctx);
1397 stack.back().ResolveValue(exe_ctx) =
1398 stack.back().ResolveValue(exe_ctx) % tmp.
ResolveValue(exe_ctx);
1408 stack.back().ResolveValue(exe_ctx) =
1409 stack.back().ResolveValue(exe_ctx) * tmp.
ResolveValue(exe_ctx);
1416 if (!stack.back().ResolveValue(exe_ctx).UnaryNegate())
1417 return llvm::createStringError(
"unary negate failed");
1425 if (!stack.back().ResolveValue(exe_ctx).OnesComplement())
1426 return llvm::createStringError(
"logical NOT failed");
1436 stack.back().ResolveValue(exe_ctx) =
1437 stack.back().ResolveValue(exe_ctx) | tmp.
ResolveValue(exe_ctx);
1447 stack.back().GetScalar() += tmp.
GetScalar();
1454 case DW_OP_plus_uconst: {
1455 const uint64_t uconst_value = opcodes.
GetULEB128(&offset);
1457 stack.back().GetScalar() += uconst_value;
1458 if (!stack.back().GetScalar().IsValid())
1459 return llvm::createStringError(
"DW_OP_plus_uconst failed");
1470 stack.back().ResolveValue(exe_ctx) <<= tmp.
ResolveValue(exe_ctx);
1481 if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1483 return llvm::createStringError(
"DW_OP_shr failed");
1495 stack.back().ResolveValue(exe_ctx) >>= tmp.
ResolveValue(exe_ctx);
1505 stack.back().ResolveValue(exe_ctx) =
1506 stack.back().ResolveValue(exe_ctx) ^ tmp.
ResolveValue(exe_ctx);
1516 int16_t skip_offset = (int16_t)opcodes.
GetU16(&offset);
1522 offset = new_offset;
1524 return llvm::createStringError(llvm::formatv(
1525 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1540 int16_t bra_offset = (int16_t)opcodes.
GetU16(&offset);
1548 offset = new_offset;
1550 return llvm::createStringError(llvm::formatv(
1551 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1567 stack.back().ResolveValue(exe_ctx) =
1568 stack.back().ResolveValue(exe_ctx) == tmp.
ResolveValue(exe_ctx);
1581 stack.back().ResolveValue(exe_ctx) =
1582 stack.back().ResolveValue(exe_ctx) >= tmp.
ResolveValue(exe_ctx);
1595 stack.back().ResolveValue(exe_ctx) =
1596 stack.back().ResolveValue(exe_ctx) > tmp.
ResolveValue(exe_ctx);
1609 stack.back().ResolveValue(exe_ctx) =
1610 stack.back().ResolveValue(exe_ctx) <= tmp.
ResolveValue(exe_ctx);
1623 stack.back().ResolveValue(exe_ctx) =
1624 stack.back().ResolveValue(exe_ctx) < tmp.
ResolveValue(exe_ctx);
1637 stack.back().ResolveValue(exe_ctx) =
1638 stack.back().ResolveValue(exe_ctx) != tmp.
ResolveValue(exe_ctx);
1678 stack.push_back(to_generic(op - DW_OP_lit0));
1716 dwarf4_location_description_kind = Register;
1717 reg_num = op - DW_OP_reg0;
1719 if (llvm::Error err =
1722 stack.push_back(tmp);
1729 dwarf4_location_description_kind = Register;
1732 if (llvm::Error err =
1735 stack.push_back(tmp);
1774 case DW_OP_breg31: {
1775 reg_num = op - DW_OP_breg0;
1776 if (llvm::Error err =
1780 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1783 stack.push_back(tmp);
1794 if (llvm::Error err =
1798 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1801 stack.push_back(tmp);
1811 int64_t fbreg_offset = opcodes.
GetSLEB128(&offset);
1812 value += fbreg_offset;
1813 stack.push_back(value);
1816 return llvm::createStringError(
1817 "invalid stack frame in context for DW_OP_fbreg opcode");
1820 return llvm::createStringError(
1821 "NULL execution context for DW_OP_fbreg");
1847 LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
1849 dwarf4_location_description_kind =
Memory;
1851 const uint64_t piece_byte_size = opcodes.
GetULEB128(&offset);
1853 if (piece_byte_size > 0) {
1856 if (stack.empty()) {
1857 UpdateValueTypeFromLocationDescription(
1858 log, dwarf_cu, LocationDescriptionKind::Empty);
1872 Value curr_piece_source_value(stack.back());
1874 UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
1875 &curr_piece_source_value);
1881 switch (curr_piece_source_value_type) {
1883 return llvm::createStringError(
"invalid value type");
1890 return llvm::createStringError(
1891 "unable to convert file address 0x%" PRIx64
1893 "for DW_OP_piece(%" PRIu64
"): "
1894 "no target available",
1895 addr, piece_byte_size);
1900 if (curr_piece.
ResizeData(piece_byte_size) == piece_byte_size) {
1902 piece_byte_size,
error,
1905 const char *addr_type = (curr_piece_source_value_type ==
1909 return llvm::createStringError(
1910 "failed to read memory DW_OP_piece(%" PRIu64
1911 ") from %s address 0x%" PRIx64,
1912 piece_byte_size, addr_type, addr);
1915 return llvm::createStringError(
1916 "failed to resize the piece memory buffer for "
1917 "DW_OP_piece(%" PRIu64
")",
1923 return llvm::createStringError(
1924 "failed to read memory DW_OP_piece(%" PRIu64
1925 ") from host address 0x%" PRIx64,
1926 piece_byte_size, addr);
1930 uint32_t bit_size = piece_byte_size * 8;
1931 uint32_t bit_offset = 0;
1933 return llvm::createStringError(
1934 "unable to extract %" PRIu64
" bytes from a %" PRIu64
1935 " byte scalar value.",
1950 if (op_piece_offset == 0) {
1955 return llvm::createStringError(
"failed to append piece data");
1961 return llvm::createStringError(
1962 "DW_OP_piece for offset %" PRIu64
1963 " but top of stack is of size %" PRIu64,
1968 return llvm::createStringError(
"failed to append piece data");
1971 op_piece_offset += piece_byte_size;
1975 case DW_OP_bit_piece:
1976 if (stack.size() < 1) {
1977 UpdateValueTypeFromLocationDescription(log, dwarf_cu,
1978 LocationDescriptionKind::Empty);
1980 dwarf4_location_description_kind =
Memory;
1981 return llvm::createStringError(
1982 "expression stack needs at least 1 item for DW_OP_bit_piece");
1984 UpdateValueTypeFromLocationDescription(
1985 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
1987 dwarf4_location_description_kind =
Memory;
1988 const uint64_t piece_bit_size = opcodes.
GetULEB128(&offset);
1989 const uint64_t piece_bit_offset = opcodes.
GetULEB128(&offset);
1990 switch (stack.back().GetValueType()) {
1992 return llvm::createStringError(
1993 "unable to extract bit value from invalid value");
1995 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
1996 piece_bit_offset)) {
1997 return llvm::createStringError(
1998 "unable to extract %" PRIu64
" bit value with %" PRIu64
1999 " bit offset from a %" PRIu64
" bit scalar value.",
2000 piece_bit_size, piece_bit_offset,
2001 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
2008 return llvm::createStringError(
2009 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
2010 ", bit_offset = %" PRIu64
") from an address value.",
2011 piece_bit_size, piece_bit_offset);
2023 case DW_OP_implicit_value: {
2024 dwarf4_location_description_kind = Implicit;
2026 const uint32_t len = opcodes.
GetULEB128(&offset);
2027 const void *data = opcodes.
GetData(&offset, len);
2030 LLDB_LOG(log,
"Evaluate_DW_OP_implicit_value: could not be read data");
2031 return llvm::createStringError(
"could not evaluate %s",
2035 Value result(data, len);
2036 stack.push_back(result);
2040 case DW_OP_implicit_pointer: {
2041 dwarf4_location_description_kind = Implicit;
2042 return llvm::createStringError(
"could not evaluate %s",
2054 case DW_OP_push_object_address:
2055 if (object_address_ptr)
2056 stack.push_back(*object_address_ptr);
2058 return llvm::createStringError(
"DW_OP_push_object_address used without "
2059 "specifying an object address");
2082 return llvm::createStringError(
"unimplemented opcode DW_OP_call2");
2103 return llvm::createStringError(
"unimplemented opcode DW_OP_call4");
2110 case DW_OP_stack_value:
2111 dwarf4_location_description_kind = Implicit;
2122 case DW_OP_convert: {
2123 const uint64_t relative_die_offset = opcodes.
GetULEB128(&offset);
2126 if (relative_die_offset == 0) {
2131 return llvm::createStringError(
"no module");
2133 bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2135 return llvm::createStringError(
"unspecified architecture");
2137 auto bit_size_sign_or_err =
2139 if (!bit_size_sign_or_err)
2140 return bit_size_sign_or_err.takeError();
2141 bit_size = bit_size_sign_or_err->first;
2142 sign = bit_size_sign_or_err->second;
2144 Scalar &top = stack.back().ResolveValue(exe_ctx);
2154 case DW_OP_call_frame_cfa:
2159 addr_t cfa =
id.GetCallFrameAddressWithMetadata();
2161 stack.push_back(
Scalar(cfa));
2164 return llvm::createStringError(
2165 "stack frame does not include a canonical "
2166 "frame address for DW_OP_call_frame_cfa "
2170 return llvm::createStringError(
"unvalid stack frame in context for "
2171 "DW_OP_call_frame_cfa opcode");
2181 case DW_OP_form_tls_address:
2182 case DW_OP_GNU_push_tls_address: {
2183 if (stack.size() < 1) {
2184 if (op == DW_OP_form_tls_address)
2185 return llvm::createStringError(
2186 "DW_OP_form_tls_address needs an argument");
2188 return llvm::createStringError(
2189 "DW_OP_GNU_push_tls_address needs an argument");
2192 if (!exe_ctx || !module_sp)
2193 return llvm::createStringError(
"no context to evaluate TLS within");
2197 return llvm::createStringError(
"no thread to evaluate TLS within");
2200 const addr_t tls_file_addr =
2202 const addr_t tls_load_addr =
2203 thread->GetThreadLocalData(module_sp, tls_file_addr);
2206 return llvm::createStringError(
2207 "no TLS data currently exists for this thread");
2209 stack.back().GetScalar() = tls_load_addr;
2220 case DW_OP_GNU_addr_index: {
2222 return llvm::createStringError(
"DW_OP_GNU_addr_index found without a "
2223 "compile unit being specified");
2224 uint64_t index = opcodes.
GetULEB128(&offset);
2226 stack.push_back(
Scalar(value));
2244 case DW_OP_GNU_const_index: {
2246 return llvm::createStringError(
"DW_OP_GNU_const_index found without a "
2247 "compile unit being specified");
2249 uint64_t index = opcodes.
GetULEB128(&offset);
2251 stack.push_back(
Scalar(value));
2254 case DW_OP_GNU_entry_value:
2255 case DW_OP_entry_value: {
2257 opcodes, offset, log))
2258 return llvm::createStringError(
2259 "could not evaluate DW_OP_entry_value: %s",
2260 llvm::toString(std::move(err)).c_str());
2271 return llvm::createStringError(llvm::formatv(
2272 "Unhandled opcode {0} in DWARFExpression", LocationAtom(op)));
2276 if (stack.empty()) {
2282 return llvm::createStringError(
"stack empty after evaluation");
2285 UpdateValueTypeFromLocationDescription(
2286 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2289 size_t count = stack.size();
2291 "Stack after operation has %" PRIu64
" values:", (uint64_t)count);
2292 for (
size_t i = 0; i < count; ++i) {
2294 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
2295 stack[i].Dump(&new_value);
2299 return stack.back();
2314 uint8_t opcode = opcodes.
GetU8(&op_offset);
2316 if (opcode == DW_OP_fbreg) {
2317 int64_t offset = opcodes.
GetSLEB128(&op_offset);
2330 recurse)(operand)) {
2334 return MatchUnaryOp(
2337 MatchImmOp(offset), recurse))(operand);
2340 bool dereference =
false;
2344 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2345 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_reg0);
2346 }
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2348 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_breg0);
2349 }
else if (opcode == DW_OP_regx) {
2350 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2351 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2352 }
else if (opcode == DW_OP_bregx) {
2353 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2355 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2367 MatchRegOp(*reg))(operand)) {
2371 return MatchUnaryOp(
2374 MatchRegOp(*reg), MatchImmOp(offset)))(operand);
2376 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 const char * DW_OP_value_to_name(uint32_t val)
static llvm::Error Evaluate_DW_OP_deref_size(DWARFExpression::Stack &stack, ExecutionContext *exe_ctx, lldb::ModuleSP module_sp, Process *process, Target *target, uint8_t size, size_t size_addr_bytes, LocationDescriptionKind &dwarf4_location_description_kind)
static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const LocationAtom op, const DWARFExpression::Delegate *dwarf_cu)
Return the length in bytes of the set of operands for op.
static llvm::Error Evaluate_DW_OP_entry_value(DWARFExpression::Stack &stack, ExecutionContext *exe_ctx, RegisterContext *reg_ctx, const DataExtractor &opcodes, lldb::offset_t &opcode_offset, Log *log)
static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes, size_t size_addr_bytes, ByteOrder byte_order, size_t size)
Helper function 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,...)
@ 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 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
virtual uint16_t GetVersion() const =0
virtual bool ParseVendorDWARFOpcode(uint8_t op, const DataExtractor &opcodes, lldb::offset_t &offset, RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, Stack &stack) const =0
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const =0
virtual dw_addr_t ReadAddressFromDebugAddrSection(uint32_t index) const =0
virtual llvm::Expected< std::pair< uint64_t, bool > > GetDIEBitSizeAndSign(uint64_t relative_die_offset) const =0
virtual uint8_t GetAddressByteSize() const =0
DataExtractor m_data
A data extractor capable of reading opcode bytes.
std::vector< Value > Stack
~DWARFExpression()
Destructor.
llvm::Expected< lldb::addr_t > GetLocation_DW_OP_addr(const Delegate *dwarf_cu) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
static llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const Delegate *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.
bool ContainsThreadLocalStorage(const Delegate *dwarf_cu) const
bool LinkThreadLocalStorage(const Delegate *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
bool Update_DW_OP_addr(const Delegate *dwarf_cu, lldb::addr_t file_addr)
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, uint32_t reg_num, Value &value)
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi, llvm::DIDumpOptions options={}) 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.
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
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)
This base class provides an interface to stack frames.
virtual DWARFExpressionList * GetFrameBaseExpression(Status *error_ptr)
Get the DWARFExpressionList corresponding to the Canonical Frame Address.
virtual llvm::Error GetFrameBaseValue(Scalar &value)
Return the Canonical Frame Address (DWARF term) for this frame.
virtual lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
virtual StackID & GetStackID()
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
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, bool *did_read_live_memory=nullptr)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
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.
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_OFFSET
#define LLDB_INVALID_REGNUM
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
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.