39#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
40#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
41#include "llvm/Support/ErrorExtras.h"
46using namespace llvm::dwarf;
60 uint8_t addr_byte_size) {
61 if (!const_value_byte_size)
67 m_data.SetAddressByteSize(addr_byte_size);
72 llvm::DIDumpOptions options)
const {
74 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum,
75 bool IsEH) -> llvm::StringRef {
78 if (std::optional<unsigned> LLVMRegNum =
79 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
80 if (
const char *RegName = MCRegInfo->getName(*LLVMRegNum))
81 return llvm::StringRef(RegName);
84 options.GetNameForDWARFReg = GetRegName;
85 llvm::DWARFExpression E(
m_data.GetAsLLVM(),
m_data.GetAddressByteSize());
86 llvm::printDwarfExpression(&E, s->
AsRawOstream(), options,
nullptr);
98 uint32_t reg_num,
Value &value) {
99 if (reg_ctx ==
nullptr)
100 return llvm::createStringError(
"no register context in frame");
102 const uint32_t native_reg =
105 return llvm::createStringError(
106 "unable to convert register kind=%u reg_num=%u to a native "
117 return llvm::Error::success();
122 return llvm::createStringError(
123 "register %s can't be converted to a scalar value", reg_info->
name);
126 return llvm::createStringError(
"register %s is not available",
134 const LocationAtom op,
139 case DW_OP_LLVM_fragment:
140 case DW_OP_LLVM_convert:
141 case DW_OP_LLVM_tag_offset:
142 case DW_OP_LLVM_entry_value:
143 case DW_OP_LLVM_implicit_pointer:
145 case DW_OP_LLVM_extract_bits_sext:
146 case DW_OP_LLVM_extract_bits_zext:
149 case DW_OP_HP_is_value:
150 case DW_OP_HP_fltconst4:
151 case DW_OP_HP_fltconst8:
152 case DW_OP_HP_mod_range:
153 case DW_OP_HP_unmod_range:
155 case DW_OP_INTEL_bit_piece:
156 case DW_OP_WASM_location:
157 case DW_OP_WASM_location_int:
158 case DW_OP_APPLE_uninit:
159 case DW_OP_PGI_omp_thread_num:
161 case DW_OP_GNU_implicit_pointer:
261 case DW_OP_push_object_address:
262 case DW_OP_form_tls_address:
263 case DW_OP_call_frame_cfa:
264 case DW_OP_stack_value:
265 case DW_OP_GNU_push_tls_address:
272 case DW_OP_deref_size:
273 case DW_OP_xderef_size:
274 case DW_OP_deref_type:
299 case DW_OP_plus_uconst:
336 case DW_OP_reinterpret:
339 case DW_OP_xderef_type:
340 case DW_OP_GNU_addr_index:
341 case DW_OP_GNU_const_index:
343 return offset - data_offset;
347 case DW_OP_bit_piece:
348 case DW_OP_regval_type:
351 return offset - data_offset;
353 case DW_OP_implicit_value:
358 return offset - data_offset;
361 case DW_OP_implicit_pointer:
369 case DW_OP_GNU_entry_value:
370 case DW_OP_entry_value:
372 uint64_t subexpr_len = data.
GetULEB128(&offset);
373 return (offset - data_offset) + subexpr_len;
376 case DW_OP_const_type:
379 uint8_t length = data.
GetU8(&offset);
380 return (offset - data_offset) + length;
383 case DW_OP_LLVM_user:
385 uint64_t constants = data.
GetULEB128(&offset);
386 return (offset - data_offset) + constants;
397 static char invalid[100];
398 llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString(val);
399 if (llvmstr.empty()) {
400 snprintf(invalid,
sizeof(invalid),
"Unknown DW_OP constant: 0x%x", val);
403 return llvmstr.data();
409 while (
m_data.ValidOffset(offset)) {
410 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
412 if (op == DW_OP_addr)
413 return m_data.GetAddress(&offset);
415 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
416 const uint64_t index =
m_data.GetULEB128(&offset);
419 return llvm::createStringError(
"cannot evaluate %s without a DWARF unit",
426 return llvm::createStringError(
"cannot get opcode data size for %s",
429 offset += op_arg_size;
438 while (
m_data.ValidOffset(offset)) {
439 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
441 if (op == DW_OP_addr) {
442 const uint32_t addr_byte_size =
m_data.GetAddressByteSize();
452 m_data.GetByteOrder(), addr_byte_size);
463 if (op == DW_OP_addrx) {
467 llvm::ArrayRef data_before_op =
m_data.GetData().take_front(offset - 1);
471 m_data.GetULEB128(&offset);
472 if (old_offset == offset)
474 llvm::ArrayRef data_after_op =
m_data.GetData().drop_front(offset);
488 offset += op_arg_size;
496 while (
m_data.ValidOffset(offset)) {
497 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
499 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
505 offset += op_arg_size;
512 &link_address_callback) {
513 const uint32_t addr_byte_size =
m_data.GetAddressByteSize();
521 m_data.GetByteOrder(), addr_byte_size);
526 size_t const_byte_size = 0;
527 while (
m_data.ValidOffset(offset)) {
528 const LocationAtom op =
static_cast<LocationAtom
>(
m_data.GetU8(&offset));
530 bool decoded_data =
false;
535 const_offset = offset;
536 const_value =
m_data.GetU32(&offset);
544 const_offset = offset;
545 const_value =
m_data.GetU64(&offset);
550 case DW_OP_form_tls_address:
551 case DW_OP_GNU_push_tls_address:
562 if (const_byte_size > 0) {
563 lldb::addr_t linked_file_addr = link_address_callback(const_value);
567 if (encoder.
PutUnsigned(const_offset, const_byte_size,
586 offset += op_arg_size;
646 return llvm::createStringError(
"no exe/reg context");
651 if (!current_frame || !thread)
652 return llvm::createStringError(
"no current frame/thread");
659 for (uint32_t parent_frame_idx = current_frame_idx + 1;; parent_frame_idx++) {
660 parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
669 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
670 LLDB_LOG(log,
"immediate ancestor with pc = {0:x}", return_pc);
675 if (parent_frame->IsInlined())
681 if (!parent_frame || !parent_frame->GetRegisterContext()) {
682 return llvm::createStringError(
"no parent frame with reg ctx");
686 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
688 return llvm::createStringError(
"no parent function");
695 return llvm::createStringError(
"no current function");
701 if (!parent_frame->IsArtificial()) {
706 return llvm::createStringErrorV(
707 "no call edge for retn-pc = {0:x} in parent frame {1}", return_pc,
711 if (callee_func != current_func) {
712 return llvm::createStringError(
713 "ambiguous call sequence, can't find real parent frame");
720 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
721 call_edge = edge.get();
727 return llvm::createStringError(
"no unambiguous edge from parent "
728 "to current function");
733 const uint32_t subexpr_len = opcodes.
GetULEB128(&opcode_offset);
734 const void *subexpr_data = opcodes.
GetData(&opcode_offset, subexpr_len);
736 return llvm::createStringError(
"subexpr could not be read");
741 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
744 const void *param_subexpr_data =
745 param_subexpr_extractor.
GetData(¶m_subexpr_offset, subexpr_len);
746 if (!param_subexpr_data ||
747 param_subexpr_extractor.
BytesLeft(param_subexpr_offset) != 0)
757 if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
758 matched_param = ¶m;
763 return llvm::createStringError(
"no matching call site param found");
769 llvm::Expected<Value> maybe_result = param_expr.
Evaluate(
770 &parent_exe_ctx, parent_frame->GetRegisterContext().get(),
776 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
777 return maybe_result.takeError();
780 stack.push_back(*maybe_result);
781 return llvm::Error::success();
788enum LocationDescriptionKind {
796void UpdateValueTypeFromLocationDescription(
798 LocationDescriptionKind kind,
Value *value =
nullptr) {
805 if (dwarf_cu && dwarf_cu->
GetVersion() >= 4) {
806 const char *log_msg =
"DWARF location description kind: %s";
845static llvm::Expected<lldb::addr_t>
848 Address &so_addr,
bool check_sectionoffset =
false) {
850 return llvm::createStringError(
"need module to resolve file address for %s",
853 if (!module_sp->ResolveFileAddress(file_addr, so_addr))
854 return llvm::createStringError(
"failed to resolve file address in module");
860 return llvm::createStringError(
"failed to resolve load address");
873 size_t size_addr_bytes,
875 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
879 return addr_data.
GetMaxU64(&addr_data_offset, size);
880 return addr_data.
GetAddress(&addr_data_offset);
886 size_t size_addr_bytes,
887 LocationDescriptionKind &dwarf4_location_description_kind) {
889 return llvm::createStringError(
890 "expression stack empty for DW_OP_deref_size");
893 return llvm::createStringError(
894 "Invalid address size for DW_OP_deref_size: %d\n", size);
899 if (dwarf4_location_description_kind == Register ||
900 dwarf4_location_description_kind == Implicit) {
902 dwarf4_location_description_kind =
Memory;
903 stack.back().ClearContext();
907 Scalar scalar = stack.back().GetScalar();
911 stack.back().GetScalar() = scalar;
912 return llvm::Error::success();
916 switch (value_type) {
918 void *src = (
void *)stack.back().GetScalar().ULongLong();
920 ::memcpy(&ptr, src,
sizeof(
void *));
932 ptr = ptr & 0xffffff;
935 ptr = ptr & 0xffffffff;
941 ptr = (intptr_t)ptr & 0xffffffffffULL;
944 ptr = (intptr_t)ptr & 0xffffffffffffULL;
947 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
952 stack.back().GetScalar() = ptr;
953 stack.back().ClearContext();
959 exe_ctx, module_sp,
"DW_OP_deref_size", file_addr, so_addr,
962 if (!maybe_load_addr)
963 return maybe_load_addr.takeError();
965 addr_t load_addr = *maybe_load_addr;
968 uint8_t addr_bytes[8];
973 return llvm::createStringError(
974 "failed to dereference pointer for DW_OP_deref_size: "
978 ObjectFile *objfile = module_sp->GetObjectFile();
982 stack.back().ClearContext();
985 stack.back().GetScalar() = load_addr;
996 return llvm::createStringError(
997 "no execution context for DW_OP_deref_size");
999 return llvm::createStringError(
"no process for DW_OP_deref_size");
1006 if (process->
ReadMemory(pointer_addr, &addr_bytes, size,
error) != size)
1007 return llvm::createStringError(
1008 "failed to dereference pointer from 0x%" PRIx64
1009 " for DW_OP_deref_size: %s\n",
1010 pointer_addr,
error.AsCString());
1013 addr_bytes,
sizeof(addr_bytes), process->
GetByteOrder(), size);
1014 stack.back().ClearContext();
1018 return llvm::createStringError(
"invalid value for DW_OP_deref_size");
1021 return llvm::Error::success();
1029 const Value *object_address_ptr) {
1032 return llvm::createStringError(
1033 "no location, value may have been optimized out");
1039 Target *target =
nullptr;
1046 if (reg_ctx ==
nullptr && frame)
1049 if (initial_value_ptr)
1050 stack.push_back(*initial_value_ptr);
1057 uint64_t op_piece_offset = 0;
1065 auto to_generic = [&](
auto v) {
1068 bool is_signed = std::is_signed<
decltype(v)>::value;
1077 LocationDescriptionKind dwarf4_location_description_kind =
Memory;
1081 const uint8_t op = opcodes.
GetU8(&offset);
1084 size_t count = stack.size();
1085 LLDB_LOGF(log,
"Stack before operation has %" PRIu64
" values:",
1087 for (
size_t i = 0; i < count; ++i) {
1089 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
1090 stack[i].Dump(&new_value);
1093 LLDB_LOGF(log,
"0x%8.8" PRIx64
": %s", op_offset,
1097 if (std::optional<unsigned> arity =
1098 llvm::dwarf::OperationArity(
static_cast<LocationAtom
>(op))) {
1099 if (stack.size() < *arity)
1100 return llvm::createStringError(
1101 "%s needs at least %d stack entries (stack has %d entries)",
1166 stack, exe_ctx, module_sp, process, target, size, size,
1167 dwarf4_location_description_kind))
1183 case DW_OP_deref_size: {
1184 size_t size = opcodes.
GetU8(&offset);
1186 stack, exe_ctx, module_sp, process, target, size,
1206 case DW_OP_xderef_size:
1207 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef_size");
1219 return llvm::createStringError(
"unimplemented opcode: DW_OP_xderef");
1235 stack.push_back(to_generic(opcodes.
GetU8(&offset)));
1238 stack.push_back(to_generic((int8_t)opcodes.
GetU8(&offset)));
1241 stack.push_back(to_generic(opcodes.
GetU16(&offset)));
1244 stack.push_back(to_generic((int16_t)opcodes.
GetU16(&offset)));
1247 stack.push_back(to_generic(opcodes.
GetU32(&offset)));
1250 stack.push_back(to_generic((int32_t)opcodes.
GetU32(&offset)));
1253 stack.push_back(to_generic(opcodes.
GetU64(&offset)));
1256 stack.push_back(to_generic((int64_t)opcodes.
GetU64(&offset)));
1271 if (stack.empty()) {
1272 return llvm::createStringError(
"expression stack empty for DW_OP_dup");
1274 stack.push_back(stack.back());
1281 if (stack.empty()) {
1282 return llvm::createStringError(
"expression stack empty for DW_OP_drop");
1292 stack.push_back(stack[stack.size() - 2]);
1300 uint8_t pick_idx = opcodes.
GetU8(&offset);
1301 if (pick_idx < stack.size())
1302 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1304 return llvm::createStringError(
1305 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1316 stack.back() = stack[stack.size() - 2];
1317 stack[stack.size() - 2] = tmp;
1327 size_t last_idx = stack.size() - 1;
1328 Value old_top = stack[last_idx];
1329 stack[last_idx] = stack[last_idx - 1];
1330 stack[last_idx - 1] = stack[last_idx - 2];
1331 stack[last_idx - 2] = old_top;
1340 if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1341 return llvm::createStringError(
1342 "failed to take the absolute value of the first stack item");
1353 stack.back().ResolveValue(exe_ctx) =
1354 stack.back().ResolveValue(exe_ctx) & tmp.
ResolveValue(exe_ctx);
1365 return llvm::createStringError(
"divide by zero");
1368 Scalar divisor, dividend;
1370 dividend = stack.back().ResolveValue(exe_ctx);
1373 stack.back() = dividend / divisor;
1375 if (!stack.back().ResolveValue(exe_ctx).IsValid())
1376 return llvm::createStringError(
"divide failed");
1386 stack.back().ResolveValue(exe_ctx) =
1387 stack.back().ResolveValue(exe_ctx) - tmp.
ResolveValue(exe_ctx);
1398 stack.back().ResolveValue(exe_ctx) =
1399 stack.back().ResolveValue(exe_ctx) % tmp.
ResolveValue(exe_ctx);
1409 stack.back().ResolveValue(exe_ctx) =
1410 stack.back().ResolveValue(exe_ctx) * tmp.
ResolveValue(exe_ctx);
1417 if (!stack.back().ResolveValue(exe_ctx).UnaryNegate())
1418 return llvm::createStringError(
"unary negate failed");
1426 if (!stack.back().ResolveValue(exe_ctx).OnesComplement())
1427 return llvm::createStringError(
"logical NOT failed");
1437 stack.back().ResolveValue(exe_ctx) =
1438 stack.back().ResolveValue(exe_ctx) | tmp.
ResolveValue(exe_ctx);
1448 stack.back().GetScalar() += tmp.
GetScalar();
1455 case DW_OP_plus_uconst: {
1456 const uint64_t uconst_value = opcodes.
GetULEB128(&offset);
1458 stack.back().GetScalar() += uconst_value;
1459 if (!stack.back().GetScalar().IsValid())
1460 return llvm::createStringError(
"DW_OP_plus_uconst failed");
1471 stack.back().ResolveValue(exe_ctx) <<= tmp.
ResolveValue(exe_ctx);
1482 if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1484 return llvm::createStringError(
"DW_OP_shr failed");
1496 stack.back().ResolveValue(exe_ctx) >>= tmp.
ResolveValue(exe_ctx);
1506 stack.back().ResolveValue(exe_ctx) =
1507 stack.back().ResolveValue(exe_ctx) ^ tmp.
ResolveValue(exe_ctx);
1517 int16_t skip_offset = (int16_t)opcodes.
GetU16(&offset);
1523 offset = new_offset;
1525 return llvm::createStringErrorV(
1526 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1541 int16_t bra_offset = (int16_t)opcodes.
GetU16(&offset);
1549 offset = new_offset;
1551 return llvm::createStringErrorV(
1552 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1568 stack.back().ResolveValue(exe_ctx) =
1569 stack.back().ResolveValue(exe_ctx) == tmp.
ResolveValue(exe_ctx);
1582 stack.back().ResolveValue(exe_ctx) =
1583 stack.back().ResolveValue(exe_ctx) >= tmp.
ResolveValue(exe_ctx);
1596 stack.back().ResolveValue(exe_ctx) =
1597 stack.back().ResolveValue(exe_ctx) > tmp.
ResolveValue(exe_ctx);
1610 stack.back().ResolveValue(exe_ctx) =
1611 stack.back().ResolveValue(exe_ctx) <= tmp.
ResolveValue(exe_ctx);
1624 stack.back().ResolveValue(exe_ctx) =
1625 stack.back().ResolveValue(exe_ctx) < tmp.
ResolveValue(exe_ctx);
1638 stack.back().ResolveValue(exe_ctx) =
1639 stack.back().ResolveValue(exe_ctx) != tmp.
ResolveValue(exe_ctx);
1679 stack.push_back(to_generic(op - DW_OP_lit0));
1717 dwarf4_location_description_kind = Register;
1718 reg_num = op - DW_OP_reg0;
1720 if (llvm::Error err =
1723 stack.push_back(tmp);
1730 dwarf4_location_description_kind = Register;
1733 if (llvm::Error err =
1736 stack.push_back(tmp);
1775 case DW_OP_breg31: {
1776 reg_num = op - DW_OP_breg0;
1777 if (llvm::Error err =
1781 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1784 stack.push_back(tmp);
1795 if (llvm::Error err =
1799 int64_t breg_offset = opcodes.
GetSLEB128(&offset);
1802 stack.push_back(tmp);
1812 int64_t fbreg_offset = opcodes.
GetSLEB128(&offset);
1813 value += fbreg_offset;
1814 stack.push_back(value);
1817 return llvm::createStringError(
1818 "invalid stack frame in context for DW_OP_fbreg opcode");
1821 return llvm::createStringError(
1822 "NULL execution context for DW_OP_fbreg");
1848 LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
1850 dwarf4_location_description_kind =
Memory;
1852 const uint64_t piece_byte_size = opcodes.
GetULEB128(&offset);
1854 if (piece_byte_size > 0) {
1857 if (stack.empty()) {
1858 UpdateValueTypeFromLocationDescription(
1859 log, dwarf_cu, LocationDescriptionKind::Empty);
1873 Value curr_piece_source_value(stack.back());
1875 UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
1876 &curr_piece_source_value);
1882 switch (curr_piece_source_value_type) {
1884 return llvm::createStringError(
"invalid value type");
1891 return llvm::createStringError(
1892 "unable to convert file address 0x%" PRIx64
1894 "for DW_OP_piece(%" PRIu64
"): "
1895 "no target available",
1896 addr, piece_byte_size);
1901 if (curr_piece.
ResizeData(piece_byte_size) == piece_byte_size) {
1903 piece_byte_size,
error,
1906 const char *addr_type = (curr_piece_source_value_type ==
1910 return llvm::createStringError(
1911 "failed to read memory DW_OP_piece(%" PRIu64
1912 ") from %s address 0x%" PRIx64,
1913 piece_byte_size, addr_type, addr);
1916 return llvm::createStringError(
1917 "failed to resize the piece memory buffer for "
1918 "DW_OP_piece(%" PRIu64
")",
1924 return llvm::createStringError(
1925 "failed to read memory DW_OP_piece(%" PRIu64
1926 ") from host address 0x%" PRIx64,
1927 piece_byte_size, addr);
1931 uint32_t bit_size = piece_byte_size * 8;
1932 uint32_t bit_offset = 0;
1934 return llvm::createStringError(
1935 "unable to extract %" PRIu64
" bytes from a %" PRIu64
1936 " byte scalar value.",
1951 if (op_piece_offset == 0) {
1956 return llvm::createStringError(
"failed to append piece data");
1962 return llvm::createStringError(
1963 "DW_OP_piece for offset %" PRIu64
1964 " but top of stack is of size %" PRIu64,
1969 return llvm::createStringError(
"failed to append piece data");
1972 op_piece_offset += piece_byte_size;
1976 case DW_OP_bit_piece:
1977 if (stack.size() < 1) {
1978 UpdateValueTypeFromLocationDescription(log, dwarf_cu,
1979 LocationDescriptionKind::Empty);
1981 dwarf4_location_description_kind =
Memory;
1982 return llvm::createStringError(
1983 "expression stack needs at least 1 item for DW_OP_bit_piece");
1985 UpdateValueTypeFromLocationDescription(
1986 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
1988 dwarf4_location_description_kind =
Memory;
1989 const uint64_t piece_bit_size = opcodes.
GetULEB128(&offset);
1990 const uint64_t piece_bit_offset = opcodes.
GetULEB128(&offset);
1991 switch (stack.back().GetValueType()) {
1993 return llvm::createStringError(
1994 "unable to extract bit value from invalid value");
1996 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
1997 piece_bit_offset)) {
1998 return llvm::createStringError(
1999 "unable to extract %" PRIu64
" bit value with %" PRIu64
2000 " bit offset from a %" PRIu64
" bit scalar value.",
2001 piece_bit_size, piece_bit_offset,
2002 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
2009 return llvm::createStringError(
2010 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
2011 ", bit_offset = %" PRIu64
") from an address value.",
2012 piece_bit_size, piece_bit_offset);
2024 case DW_OP_implicit_value: {
2025 dwarf4_location_description_kind = Implicit;
2027 const uint32_t len = opcodes.
GetULEB128(&offset);
2028 const void *data = opcodes.
GetData(&offset, len);
2031 LLDB_LOG(log,
"Evaluate_DW_OP_implicit_value: could not be read data");
2032 return llvm::createStringError(
"could not evaluate %s",
2036 Value result(data, len);
2037 stack.push_back(result);
2041 case DW_OP_implicit_pointer: {
2042 dwarf4_location_description_kind = Implicit;
2043 return llvm::createStringError(
"could not evaluate %s",
2055 case DW_OP_push_object_address:
2056 if (object_address_ptr)
2057 stack.push_back(*object_address_ptr);
2059 return llvm::createStringError(
"DW_OP_push_object_address used without "
2060 "specifying an object address");
2083 return llvm::createStringError(
"unimplemented opcode DW_OP_call2");
2104 return llvm::createStringError(
"unimplemented opcode DW_OP_call4");
2111 case DW_OP_stack_value:
2112 dwarf4_location_description_kind = Implicit;
2123 case DW_OP_convert: {
2124 const uint64_t relative_die_offset = opcodes.
GetULEB128(&offset);
2127 if (relative_die_offset == 0) {
2132 return llvm::createStringError(
"no module");
2134 bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2136 return llvm::createStringError(
"unspecified architecture");
2138 auto bit_size_sign_or_err =
2140 if (!bit_size_sign_or_err)
2141 return bit_size_sign_or_err.takeError();
2142 bit_size = bit_size_sign_or_err->first;
2143 sign = bit_size_sign_or_err->second;
2145 Scalar &top = stack.back().ResolveValue(exe_ctx);
2155 case DW_OP_call_frame_cfa:
2160 addr_t cfa =
id.GetCallFrameAddressWithMetadata();
2162 stack.push_back(
Scalar(cfa));
2165 return llvm::createStringError(
2166 "stack frame does not include a canonical "
2167 "frame address for DW_OP_call_frame_cfa "
2171 return llvm::createStringError(
"unvalid stack frame in context for "
2172 "DW_OP_call_frame_cfa opcode");
2182 case DW_OP_form_tls_address:
2183 case DW_OP_GNU_push_tls_address: {
2184 if (stack.size() < 1) {
2185 if (op == DW_OP_form_tls_address)
2186 return llvm::createStringError(
2187 "DW_OP_form_tls_address needs an argument");
2189 return llvm::createStringError(
2190 "DW_OP_GNU_push_tls_address needs an argument");
2193 if (!exe_ctx || !module_sp)
2194 return llvm::createStringError(
"no context to evaluate TLS within");
2198 return llvm::createStringError(
"no thread to evaluate TLS within");
2201 const addr_t tls_file_addr =
2203 const addr_t tls_load_addr =
2204 thread->GetThreadLocalData(module_sp, tls_file_addr);
2207 return llvm::createStringError(
2208 "no TLS data currently exists for this thread");
2210 stack.back().GetScalar() = tls_load_addr;
2221 case DW_OP_GNU_addr_index: {
2223 return llvm::createStringError(
"DW_OP_GNU_addr_index found without a "
2224 "compile unit being specified");
2225 uint64_t index = opcodes.
GetULEB128(&offset);
2227 stack.push_back(
Scalar(value));
2245 case DW_OP_GNU_const_index: {
2247 return llvm::createStringError(
"DW_OP_GNU_const_index found without a "
2248 "compile unit being specified");
2250 uint64_t index = opcodes.
GetULEB128(&offset);
2252 stack.push_back(
Scalar(value));
2255 case DW_OP_GNU_entry_value:
2256 case DW_OP_entry_value: {
2258 opcodes, offset, log))
2259 return llvm::createStringError(
2260 "could not evaluate DW_OP_entry_value: %s",
2261 llvm::toString(std::move(err)).c_str());
2272 return llvm::createStringErrorV(
"Unhandled opcode {0} in DWARFExpression",
2277 if (stack.empty()) {
2283 return llvm::createStringError(
"stack empty after evaluation");
2286 UpdateValueTypeFromLocationDescription(
2287 log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2290 size_t count = stack.size();
2292 "Stack after operation has %" PRIu64
" values:", (uint64_t)count);
2293 for (
size_t i = 0; i < count; ++i) {
2295 new_value.
Printf(
"[%" PRIu64
"]", (uint64_t)i);
2296 stack[i].Dump(&new_value);
2300 return stack.back();
2315 uint8_t opcode = opcodes.
GetU8(&op_offset);
2317 if (opcode == DW_OP_fbreg) {
2318 int64_t offset = opcodes.
GetSLEB128(&op_offset);
2331 recurse)(operand)) {
2335 return MatchUnaryOp(
2338 MatchImmOp(offset), recurse))(operand);
2341 bool dereference =
false;
2345 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2346 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_reg0);
2347 }
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2349 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, opcode - DW_OP_breg0);
2350 }
else if (opcode == DW_OP_regx) {
2351 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2352 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2353 }
else if (opcode == DW_OP_bregx) {
2354 uint32_t reg_num =
static_cast<uint32_t
>(opcodes.
GetULEB128(&op_offset));
2356 reg = reg_ctx_sp->GetRegisterInfo(
m_reg_kind, reg_num);
2368 MatchRegOp(*reg))(operand)) {
2372 return MatchUnaryOp(
2375 MatchRegOp(*reg), MatchImmOp(offset)))(operand);
2377 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.