15
15
16
16
#include " lldb/Core/Module.h"
17
17
#include " lldb/Core/Value.h"
18
- #include " lldb/Core/dwarf.h"
19
18
#include " lldb/Utility/DataEncoder.h"
20
19
#include " lldb/Utility/LLDBLog.h"
21
20
#include " lldb/Utility/Log.h"
37
36
#include " lldb/Target/StackID.h"
38
37
#include " lldb/Target/Target.h"
39
38
#include " lldb/Target/Thread.h"
40
- #include " llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
41
39
#include " llvm/DebugInfo/DWARF/DWARFExpression.h"
42
40
43
- #include " Plugins/SymbolFile/DWARF/DWARFUnit.h"
44
-
45
41
using namespace lldb ;
46
42
using namespace lldb_private ;
47
43
using namespace lldb_private ::dwarf;
@@ -130,10 +126,10 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
130
126
131
127
// / Return the length in bytes of the set of operands for \p op. No guarantees
132
128
// / 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) {
137
133
lldb::offset_t offset = data_offset;
138
134
switch (op) {
139
135
// Only used in LLVM metadata.
@@ -362,7 +358,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
362
358
// + LEB128
363
359
{
364
360
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;
366
363
}
367
364
368
365
case DW_OP_GNU_entry_value:
@@ -387,14 +384,23 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
387
384
}
388
385
389
386
if (dwarf_cu)
390
- return dwarf_cu->GetSymbolFileDWARF ().GetVendorDWARFOpcodeSize (
391
- data, data_offset, op);
387
+ return dwarf_cu->GetVendorDWARFOpcodeSize (data, data_offset, op);
392
388
393
389
return LLDB_INVALID_OFFSET;
394
390
}
395
391
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 {
398
404
lldb::offset_t offset = 0 ;
399
405
while (m_data.ValidOffset (offset)) {
400
406
const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -422,8 +428,8 @@ DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu) const {
422
428
return LLDB_INVALID_ADDRESS;
423
429
}
424
430
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) {
427
433
lldb::offset_t offset = 0 ;
428
434
while (m_data.ValidOffset (offset)) {
429
435
const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -481,7 +487,7 @@ bool DWARFExpression::Update_DW_OP_addr(const DWARFUnit *dwarf_cu,
481
487
}
482
488
483
489
bool DWARFExpression::ContainsThreadLocalStorage (
484
- const DWARFUnit *dwarf_cu) const {
490
+ const DWARFExpression::Delegate *dwarf_cu) const {
485
491
lldb::offset_t offset = 0 ;
486
492
while (m_data.ValidOffset (offset)) {
487
493
const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -497,7 +503,7 @@ bool DWARFExpression::ContainsThreadLocalStorage(
497
503
return false ;
498
504
}
499
505
bool DWARFExpression::LinkThreadLocalStorage (
500
- const DWARFUnit *dwarf_cu,
506
+ const DWARFExpression::Delegate *dwarf_cu,
501
507
std::function<lldb::addr_t (lldb::addr_t file_addr)> const
502
508
&link_address_callback) {
503
509
const uint32_t addr_byte_size = m_data.GetAddressByteSize ();
@@ -783,9 +789,9 @@ enum LocationDescriptionKind {
783
789
/* Composite*/
784
790
};
785
791
// / 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 ) {
789
795
// Note that this function is conflating DWARF expressions with
790
796
// DWARF location descriptions. Perhaps it would be better to define
791
797
// a wrapper for DWARFExpression::Eval() that deals with DWARF
@@ -875,8 +881,9 @@ static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes,
875
881
llvm::Expected<Value> DWARFExpression::Evaluate (
876
882
ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
877
883
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) {
880
887
881
888
if (opcodes.GetByteSize () == 0 )
882
889
return llvm::createStringError (
@@ -2150,10 +2157,10 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2150
2157
// DESCRIPTION: Pop the top stack element, convert it to a
2151
2158
// different type, and push the result.
2152
2159
case DW_OP_convert: {
2153
- const uint64_t die_offset = opcodes.GetULEB128 (&offset);
2160
+ const uint64_t relative_die_offset = opcodes.GetULEB128 (&offset);
2154
2161
uint64_t bit_size;
2155
2162
bool sign;
2156
- if (die_offset == 0 ) {
2163
+ if (relative_die_offset == 0 ) {
2157
2164
// The generic type has the size of an address on the target
2158
2165
// machine and an unspecified signedness. Scalar has no
2159
2166
// "unspecified signedness", so we use unsigned types.
@@ -2164,35 +2171,12 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2164
2171
if (!bit_size)
2165
2172
return llvm::createStringError (" unspecified architecture" );
2166
2173
} 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 ;
2196
2180
}
2197
2181
Scalar &top = stack.back ().ResolveValue (exe_ctx);
2198
2182
top.TruncOrExtendTo (bit_size, sign);
@@ -2316,8 +2300,7 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2316
2300
2317
2301
default :
2318
2302
if (dwarf_cu) {
2319
- if (dwarf_cu->GetSymbolFileDWARF ().ParseVendorDWARFOpcode (
2320
- op, opcodes, offset, stack)) {
2303
+ if (dwarf_cu->ParseVendorDWARFOpcode (op, opcodes, offset, stack)) {
2321
2304
break ;
2322
2305
}
2323
2306
}
@@ -2352,43 +2335,6 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2352
2335
return stack.back ();
2353
2336
}
2354
2337
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
-
2392
2338
bool DWARFExpression::MatchesOperand (
2393
2339
StackFrame &frame, const Instruction::Operand &operand) const {
2394
2340
using namespace OperandMatchers ;
0 commit comments