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
41
#ifdef LLDB_ENABLE_SWIFT
@@ -134,10 +132,10 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
134
132
135
133
// / Return the length in bytes of the set of operands for \p op. No guarantees
136
134
// / are made on the state of \p data after this call.
137
- static lldb::offset_t GetOpcodeDataSize ( const DataExtractor &data,
138
- const lldb::offset_t data_offset,
139
- const LocationAtom op,
140
- const DWARFUnit *dwarf_cu) {
135
+ static lldb::offset_t
136
+ GetOpcodeDataSize ( const DataExtractor &data, const lldb::offset_t data_offset,
137
+ const LocationAtom op,
138
+ const DWARFExpression::Delegate *dwarf_cu) {
141
139
lldb::offset_t offset = data_offset;
142
140
switch (op) {
143
141
// Only used in LLVM metadata.
@@ -366,7 +364,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
366
364
// + LEB128
367
365
{
368
366
data.Skip_LEB128 (&offset);
369
- return DWARFUnit::GetAddressByteSize (dwarf_cu) + offset - data_offset;
367
+ return (dwarf_cu ? dwarf_cu->GetAddressByteSize () : 4 ) + offset -
368
+ data_offset;
370
369
}
371
370
372
371
case DW_OP_GNU_entry_value:
@@ -391,14 +390,23 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
391
390
}
392
391
393
392
if (dwarf_cu)
394
- return dwarf_cu->GetSymbolFileDWARF ().GetVendorDWARFOpcodeSize (
395
- data, data_offset, op);
393
+ return dwarf_cu->GetVendorDWARFOpcodeSize (data, data_offset, op);
396
394
397
395
return LLDB_INVALID_OFFSET;
398
396
}
399
397
400
- llvm::Expected<lldb::addr_t >
401
- DWARFExpression::GetLocation_DW_OP_addr (const DWARFUnit *dwarf_cu) const {
398
+ static const char *DW_OP_value_to_name (uint32_t val) {
399
+ static char invalid[100 ];
400
+ llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString (val);
401
+ if (llvmstr.empty ()) {
402
+ snprintf (invalid, sizeof (invalid), " Unknown DW_OP constant: 0x%x" , val);
403
+ return invalid;
404
+ }
405
+ return llvmstr.data ();
406
+ }
407
+
408
+ llvm::Expected<lldb::addr_t > DWARFExpression::GetLocation_DW_OP_addr (
409
+ const DWARFExpression::Delegate *dwarf_cu) const {
402
410
lldb::offset_t offset = 0 ;
403
411
while (m_data.ValidOffset (offset)) {
404
412
const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -426,8 +434,8 @@ DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu) const {
426
434
return LLDB_INVALID_ADDRESS;
427
435
}
428
436
429
- bool DWARFExpression::Update_DW_OP_addr (const DWARFUnit *dwarf_cu,
430
- lldb::addr_t file_addr) {
437
+ bool DWARFExpression::Update_DW_OP_addr (
438
+ const DWARFExpression::Delegate *dwarf_cu, lldb::addr_t file_addr) {
431
439
lldb::offset_t offset = 0 ;
432
440
while (m_data.ValidOffset (offset)) {
433
441
const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -485,7 +493,7 @@ bool DWARFExpression::Update_DW_OP_addr(const DWARFUnit *dwarf_cu,
485
493
}
486
494
487
495
bool DWARFExpression::ContainsThreadLocalStorage (
488
- const DWARFUnit *dwarf_cu) const {
496
+ const DWARFExpression::Delegate *dwarf_cu) const {
489
497
lldb::offset_t offset = 0 ;
490
498
while (m_data.ValidOffset (offset)) {
491
499
const LocationAtom op = static_cast <LocationAtom>(m_data.GetU8 (&offset));
@@ -501,7 +509,7 @@ bool DWARFExpression::ContainsThreadLocalStorage(
501
509
return false ;
502
510
}
503
511
bool DWARFExpression::LinkThreadLocalStorage (
504
- const DWARFUnit *dwarf_cu,
512
+ const DWARFExpression::Delegate *dwarf_cu,
505
513
std::function<lldb::addr_t (lldb::addr_t file_addr)> const
506
514
&link_address_callback) {
507
515
const uint32_t addr_byte_size = m_data.GetAddressByteSize ();
@@ -868,9 +876,9 @@ enum LocationDescriptionKind {
868
876
/* Composite*/
869
877
};
870
878
// / Adjust value's ValueType according to the kind of location description.
871
- void UpdateValueTypeFromLocationDescription (Log *log, const DWARFUnit *dwarf_cu,
872
- LocationDescriptionKind kind ,
873
- Value *value = nullptr ) {
879
+ void UpdateValueTypeFromLocationDescription (
880
+ Log *log, const DWARFExpression::Delegate *dwarf_cu ,
881
+ LocationDescriptionKind kind, Value *value = nullptr ) {
874
882
// Note that this function is conflating DWARF expressions with
875
883
// DWARF location descriptions. Perhaps it would be better to define
876
884
// a wrapper for DWARFExpression::Eval() that deals with DWARF
@@ -960,8 +968,9 @@ static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes,
960
968
llvm::Expected<Value> DWARFExpression::Evaluate (
961
969
ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
962
970
lldb::ModuleSP module_sp, const DataExtractor &opcodes,
963
- const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_kind,
964
- const Value *initial_value_ptr, const Value *object_address_ptr) {
971
+ const DWARFExpression::Delegate *dwarf_cu,
972
+ const lldb::RegisterKind reg_kind, const Value *initial_value_ptr,
973
+ const Value *object_address_ptr) {
965
974
966
975
if (opcodes.GetByteSize () == 0 )
967
976
return llvm::createStringError (
@@ -2235,10 +2244,10 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2235
2244
// DESCRIPTION: Pop the top stack element, convert it to a
2236
2245
// different type, and push the result.
2237
2246
case DW_OP_convert: {
2238
- const uint64_t die_offset = opcodes.GetULEB128 (&offset);
2247
+ const uint64_t relative_die_offset = opcodes.GetULEB128 (&offset);
2239
2248
uint64_t bit_size;
2240
2249
bool sign;
2241
- if (die_offset == 0 ) {
2250
+ if (relative_die_offset == 0 ) {
2242
2251
// The generic type has the size of an address on the target
2243
2252
// machine and an unspecified signedness. Scalar has no
2244
2253
// "unspecified signedness", so we use unsigned types.
@@ -2249,35 +2258,12 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2249
2258
if (!bit_size)
2250
2259
return llvm::createStringError (" unspecified architecture" );
2251
2260
} else {
2252
- // Retrieve the type DIE that the value is being converted to. This
2253
- // offset is compile unit relative so we need to fix it up.
2254
- const uint64_t abs_die_offset = die_offset + dwarf_cu->GetOffset ();
2255
- // FIXME: the constness has annoying ripple effects.
2256
- DWARFDIE die = const_cast <DWARFUnit *>(dwarf_cu)->GetDIE (abs_die_offset);
2257
- if (!die)
2258
- return llvm::createStringError (
2259
- " cannot resolve DW_OP_convert type DIE" );
2260
- uint64_t encoding =
2261
- die.GetAttributeValueAsUnsigned (DW_AT_encoding, DW_ATE_hi_user);
2262
- bit_size = die.GetAttributeValueAsUnsigned (DW_AT_byte_size, 0 ) * 8 ;
2263
- if (!bit_size)
2264
- bit_size = die.GetAttributeValueAsUnsigned (DW_AT_bit_size, 0 );
2265
- if (!bit_size)
2266
- return llvm::createStringError (
2267
- " unsupported type size in DW_OP_convert" );
2268
- switch (encoding) {
2269
- case DW_ATE_signed:
2270
- case DW_ATE_signed_char:
2271
- sign = true ;
2272
- break ;
2273
- case DW_ATE_unsigned:
2274
- case DW_ATE_unsigned_char:
2275
- sign = false ;
2276
- break ;
2277
- default :
2278
- return llvm::createStringError (
2279
- " unsupported encoding in DW_OP_convert" );
2280
- }
2261
+ auto bit_size_sign_or_err =
2262
+ dwarf_cu->GetDIEBitSizeAndSign (relative_die_offset);
2263
+ if (!bit_size_sign_or_err)
2264
+ return bit_size_sign_or_err.takeError ();
2265
+ bit_size = bit_size_sign_or_err->first ;
2266
+ sign = bit_size_sign_or_err->second ;
2281
2267
}
2282
2268
Scalar &top = stack.back ().ResolveValue (exe_ctx);
2283
2269
top.TruncOrExtendTo (bit_size, sign);
@@ -2401,8 +2387,7 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2401
2387
2402
2388
default :
2403
2389
if (dwarf_cu) {
2404
- if (dwarf_cu->GetSymbolFileDWARF ().ParseVendorDWARFOpcode (
2405
- op, opcodes, offset, stack)) {
2390
+ if (dwarf_cu->ParseVendorDWARFOpcode (op, opcodes, offset, stack)) {
2406
2391
break ;
2407
2392
}
2408
2393
}
@@ -2437,43 +2422,6 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
2437
2422
return stack.back ();
2438
2423
}
2439
2424
2440
- bool DWARFExpression::ParseDWARFLocationList (
2441
- const DWARFUnit *dwarf_cu, const DataExtractor &data,
2442
- DWARFExpressionList *location_list) {
2443
- location_list->Clear ();
2444
- std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2445
- dwarf_cu->GetLocationTable (data);
2446
- Log *log = GetLog (LLDBLog::Expressions);
2447
- auto lookup_addr =
2448
- [&](uint32_t index) -> std::optional<llvm::object::SectionedAddress> {
2449
- addr_t address = dwarf_cu->ReadAddressFromDebugAddrSection (index);
2450
- if (address == LLDB_INVALID_ADDRESS)
2451
- return std::nullopt;
2452
- return llvm::object::SectionedAddress{address};
2453
- };
2454
- auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2455
- if (!loc) {
2456
- LLDB_LOG_ERROR (log, loc.takeError (), " {0}" );
2457
- return true ;
2458
- }
2459
- auto buffer_sp =
2460
- std::make_shared<DataBufferHeap>(loc->Expr .data (), loc->Expr .size ());
2461
- DWARFExpression expr = DWARFExpression (DataExtractor (
2462
- buffer_sp, data.GetByteOrder (), data.GetAddressByteSize ()));
2463
- location_list->AddExpression (loc->Range ->LowPC , loc->Range ->HighPC , expr);
2464
- return true ;
2465
- };
2466
- llvm::Error error = loctable_up->visitAbsoluteLocationList (
2467
- 0 , llvm::object::SectionedAddress{dwarf_cu->GetBaseAddress ()},
2468
- lookup_addr, process_list);
2469
- location_list->Sort ();
2470
- if (error) {
2471
- LLDB_LOG_ERROR (log, std::move (error), " {0}" );
2472
- return false ;
2473
- }
2474
- return true ;
2475
- }
2476
-
2477
2425
bool DWARFExpression::MatchesOperand (
2478
2426
StackFrame &frame, const Instruction::Operand &operand) const {
2479
2427
using namespace OperandMatchers ;
0 commit comments