1515
1616#include " lldb/Core/Module.h"
1717#include " lldb/Core/Value.h"
18- #include " lldb/Core/dwarf.h"
1918#include " lldb/Utility/DataEncoder.h"
2019#include " lldb/Utility/LLDBLog.h"
2120#include " lldb/Utility/Log.h"
3736#include " lldb/Target/StackID.h"
3837#include " lldb/Target/Target.h"
3938#include " lldb/Target/Thread.h"
40- #include " llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
4139#include " llvm/DebugInfo/DWARF/DWARFExpression.h"
4240
43- #include " Plugins/SymbolFile/DWARF/DWARFUnit.h"
44-
4541using namespace lldb ;
4642using namespace lldb_private ;
4743using namespace lldb_private ::dwarf;
@@ -130,10 +126,10 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
130126
131127// / Return the length in bytes of the set of operands for \p op. No guarantees
132128// / are made on the state of \p data after this call.
133- static lldb::offset_t GetOpcodeDataSize ( const DataExtractor &data,
134- const lldb::offset_t data_offset,
135- const LocationAtom op,
136- const DWARFUnit *dwarf_cu) {
129+ static lldb::offset_t
130+ GetOpcodeDataSize ( const DataExtractor &data, const lldb::offset_t data_offset,
131+ const LocationAtom op,
132+ const DWARFExpression::Delegate *dwarf_cu) {
137133 lldb::offset_t offset = data_offset;
138134 switch (op) {
139135 // Only used in LLVM metadata.
@@ -362,7 +358,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
362358 // + LEB128
363359 {
364360 data.Skip_LEB128 (&offset);
365- return DWARFUnit::GetAddressByteSize (dwarf_cu) + offset - data_offset;
361+ return (dwarf_cu ? dwarf_cu->GetAddressByteSize () : 4 ) + offset -
362+ data_offset;
366363 }
367364
368365 case DW_OP_GNU_entry_value:
@@ -387,14 +384,23 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
387384 }
388385
389386 if (dwarf_cu)
390- return dwarf_cu->GetSymbolFileDWARF ().GetVendorDWARFOpcodeSize (
391- data, data_offset, op);
387+ return dwarf_cu->GetVendorDWARFOpcodeSize (data, data_offset, op);
392388
393389 return LLDB_INVALID_OFFSET;
394390}
395391
396- llvm::Expected<lldb::addr_t >
397- DWARFExpression::GetLocation_DW_OP_addr (const DWARFUnit *dwarf_cu) const {
392+ static const char *DW_OP_value_to_name (uint32_t val) {
393+ static char invalid[100 ];
394+ llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString (val);
395+ if (llvmstr.empty ()) {
396+ snprintf (invalid, sizeof (invalid), " Unknown DW_OP constant: 0x%x" , val);
397+ return invalid;
398+ }
399+ return llvmstr.data ();
400+ }
401+
402+ llvm::Expected<lldb::addr_t > DWARFExpression::GetLocation_DW_OP_addr (
403+ const DWARFExpression::Delegate *dwarf_cu) const {
398404 lldb::offset_t offset = 0 ;
399405 while (m_data.ValidOffset (offset)) {
400406 const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -422,8 +428,8 @@ DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu) const {
422428 return LLDB_INVALID_ADDRESS;
423429}
424430
425- bool DWARFExpression::Update_DW_OP_addr (const DWARFUnit *dwarf_cu,
426- lldb::addr_t file_addr) {
431+ bool DWARFExpression::Update_DW_OP_addr (
432+ const DWARFExpression::Delegate *dwarf_cu, lldb::addr_t file_addr) {
427433 lldb::offset_t offset = 0 ;
428434 while (m_data.ValidOffset (offset)) {
429435 const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -481,7 +487,7 @@ bool DWARFExpression::Update_DW_OP_addr(const DWARFUnit *dwarf_cu,
481487}
482488
483489bool DWARFExpression::ContainsThreadLocalStorage (
484- const DWARFUnit *dwarf_cu) const {
490+ const DWARFExpression::Delegate *dwarf_cu) const {
485491 lldb::offset_t offset = 0 ;
486492 while (m_data.ValidOffset (offset)) {
487493 const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -497,7 +503,7 @@ bool DWARFExpression::ContainsThreadLocalStorage(
497503 return false ;
498504}
499505bool DWARFExpression::LinkThreadLocalStorage (
500- const DWARFUnit *dwarf_cu,
506+ const DWARFExpression::Delegate *dwarf_cu,
501507 std::function<lldb::addr_t (lldb::addr_t file_addr)> const
502508 &link_address_callback) {
503509 const uint32_t addr_byte_size = m_data.GetAddressByteSize ();
@@ -783,9 +789,9 @@ enum LocationDescriptionKind {
783789 /* Composite*/
784790};
785791// / Adjust value's ValueType according to the kind of location description.
786- void UpdateValueTypeFromLocationDescription (Log *log, const DWARFUnit *dwarf_cu,
787- LocationDescriptionKind kind ,
788- Value *value = nullptr ) {
792+ void UpdateValueTypeFromLocationDescription (
793+ Log *log, const DWARFExpression::Delegate *dwarf_cu ,
794+ LocationDescriptionKind kind, Value *value = nullptr ) {
789795 // Note that this function is conflating DWARF expressions with
790796 // DWARF location descriptions. Perhaps it would be better to define
791797 // a wrapper for DWARFExpression::Eval() that deals with DWARF
@@ -875,8 +881,9 @@ static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes,
875881llvm::Expected<Value> DWARFExpression::Evaluate (
876882 ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
877883 lldb::ModuleSP module_sp, const DataExtractor &opcodes,
878- const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_kind,
879- const Value *initial_value_ptr, const Value *object_address_ptr) {
884+ const DWARFExpression::Delegate *dwarf_cu,
885+ const lldb::RegisterKind reg_kind, const Value *initial_value_ptr,
886+ const Value *object_address_ptr) {
880887
881888 if (opcodes.GetByteSize () == 0 )
882889 return llvm::createStringError (
@@ -2150,10 +2157,10 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
21502157 // DESCRIPTION: Pop the top stack element, convert it to a
21512158 // different type, and push the result.
21522159 case DW_OP_convert: {
2153- const uint64_t die_offset = opcodes.GetULEB128 (&offset);
2160+ const uint64_t relative_die_offset = opcodes.GetULEB128 (&offset);
21542161 uint64_t bit_size;
21552162 bool sign;
2156- if (die_offset == 0 ) {
2163+ if (relative_die_offset == 0 ) {
21572164 // The generic type has the size of an address on the target
21582165 // machine and an unspecified signedness. Scalar has no
21592166 // "unspecified signedness", so we use unsigned types.
@@ -2164,35 +2171,12 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
21642171 if (!bit_size)
21652172 return llvm::createStringError (" unspecified architecture" );
21662173 } else {
2167- // Retrieve the type DIE that the value is being converted to. This
2168- // offset is compile unit relative so we need to fix it up.
2169- const uint64_t abs_die_offset = die_offset + dwarf_cu->GetOffset ();
2170- // FIXME: the constness has annoying ripple effects.
2171- DWARFDIE die = const_cast <DWARFUnit *>(dwarf_cu)->GetDIE (abs_die_offset);
2172- if (!die)
2173- return llvm::createStringError (
2174- " cannot resolve DW_OP_convert type DIE" );
2175- uint64_t encoding =
2176- die.GetAttributeValueAsUnsigned (DW_AT_encoding, DW_ATE_hi_user);
2177- bit_size = die.GetAttributeValueAsUnsigned (DW_AT_byte_size, 0 ) * 8 ;
2178- if (!bit_size)
2179- bit_size = die.GetAttributeValueAsUnsigned (DW_AT_bit_size, 0 );
2180- if (!bit_size)
2181- return llvm::createStringError (
2182- " unsupported type size in DW_OP_convert" );
2183- switch (encoding) {
2184- case DW_ATE_signed:
2185- case DW_ATE_signed_char:
2186- sign = true ;
2187- break ;
2188- case DW_ATE_unsigned:
2189- case DW_ATE_unsigned_char:
2190- sign = false ;
2191- break ;
2192- default :
2193- return llvm::createStringError (
2194- " unsupported encoding in DW_OP_convert" );
2195- }
2174+ auto bit_size_sign_or_err =
2175+ dwarf_cu->GetDIEBitSizeAndSign (relative_die_offset);
2176+ if (!bit_size_sign_or_err)
2177+ return bit_size_sign_or_err.takeError ();
2178+ bit_size = bit_size_sign_or_err->first ;
2179+ sign = bit_size_sign_or_err->second ;
21962180 }
21972181 Scalar &top = stack.back ().ResolveValue (exe_ctx);
21982182 top.TruncOrExtendTo (bit_size, sign);
@@ -2316,8 +2300,7 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
23162300
23172301 default :
23182302 if (dwarf_cu) {
2319- if (dwarf_cu->GetSymbolFileDWARF ().ParseVendorDWARFOpcode (
2320- op, opcodes, offset, stack)) {
2303+ if (dwarf_cu->ParseVendorDWARFOpcode (op, opcodes, offset, stack)) {
23212304 break ;
23222305 }
23232306 }
@@ -2352,43 +2335,6 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
23522335 return stack.back ();
23532336}
23542337
2355- bool DWARFExpression::ParseDWARFLocationList (
2356- const DWARFUnit *dwarf_cu, const DataExtractor &data,
2357- DWARFExpressionList *location_list) {
2358- location_list->Clear ();
2359- std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2360- dwarf_cu->GetLocationTable (data);
2361- Log *log = GetLog (LLDBLog::Expressions);
2362- auto lookup_addr =
2363- [&](uint32_t index) -> std::optional<llvm::object::SectionedAddress> {
2364- addr_t address = dwarf_cu->ReadAddressFromDebugAddrSection (index);
2365- if (address == LLDB_INVALID_ADDRESS)
2366- return std::nullopt ;
2367- return llvm::object::SectionedAddress{address};
2368- };
2369- auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2370- if (!loc) {
2371- LLDB_LOG_ERROR (log, loc.takeError (), " {0}" );
2372- return true ;
2373- }
2374- auto buffer_sp =
2375- std::make_shared<DataBufferHeap>(loc->Expr .data (), loc->Expr .size ());
2376- DWARFExpression expr = DWARFExpression (DataExtractor (
2377- buffer_sp, data.GetByteOrder (), data.GetAddressByteSize ()));
2378- location_list->AddExpression (loc->Range ->LowPC , loc->Range ->HighPC , expr);
2379- return true ;
2380- };
2381- llvm::Error error = loctable_up->visitAbsoluteLocationList (
2382- 0 , llvm::object::SectionedAddress{dwarf_cu->GetBaseAddress ()},
2383- lookup_addr, process_list);
2384- location_list->Sort ();
2385- if (error) {
2386- LLDB_LOG_ERROR (log, std::move (error), " {0}" );
2387- return false ;
2388- }
2389- return true ;
2390- }
2391-
23922338bool DWARFExpression::MatchesOperand (
23932339 StackFrame &frame, const Instruction::Operand &operand) const {
23942340 using namespace OperandMatchers ;
0 commit comments