28 class DWARFLocationInterpreter {
30 std::function<Optional<object::SectionedAddress>(
uint32_t)> LookupAddr;
33 DWARFLocationInterpreter(
36 : Base(Base), LookupAddr(
std::move(LookupAddr)) {}
45 "Unable to resolve indirect address %u for: %s",
52 case dwarf::DW_LLE_end_of_list:
54 case dwarf::DW_LLE_base_addressx: {
60 case dwarf::DW_LLE_startx_endx: {
71 case dwarf::DW_LLE_startx_length: {
80 case dwarf::DW_LLE_offset_pair: {
83 "Unable to resolve location list offset pair: " 84 "Base address not defined");
88 if (Range.SectionIndex == SectionedAddress::UndefSection)
92 case dwarf::DW_LLE_default_location:
94 case dwarf::DW_LLE_base_address:
97 case dwarf::DW_LLE_start_end:
100 case dwarf::DW_LLE_start_length:
115 bool IsLittleEndian,
unsigned AddressSize,
126 unsigned Indent)
const {
127 DWARFLocationInterpreter Interp(
133 OS <<
format(
"0x%8.8" PRIx64
": ", *Offset);
137 dumpRawEntry(E, OS, Indent, DumpOpts, Obj);
146 if (Loc.
get()->Range)
147 Loc.
get()->Range->dump(OS,
Data.getAddressSize(), RangeDumpOpts, &Obj);
154 if (E.
Kind != dwarf::DW_LLE_base_address &&
155 E.
Kind != dwarf::DW_LLE_base_addressx &&
156 E.
Kind != dwarf::DW_LLE_end_of_list) {
166 OS <<
"error: " <<
toString(std::move(E));
176 DWARFLocationInterpreter Interp(BaseAddr, std::move(LookupAddr));
182 return Callback(**Loc);
190 auto BaseAddr =
None;
191 unsigned Indent = 12;
193 dumpLocationList(&*DumpOffset, OS, BaseAddr, MRI, Obj,
nullptr, DumpOpts,
198 bool CanContinue =
true;
199 while (CanContinue &&
Data.isValidOffset(Offset)) {
203 CanContinue = dumpLocationList(&Offset, OS, BaseAddr, MRI, Obj,
nullptr,
215 uint64_t SectionIndex;
216 uint64_t Value0 =
Data.getRelocatedAddress(C);
217 uint64_t Value1 =
Data.getRelocatedAddress(C, &SectionIndex);
225 if (Value0 == 0 && Value1 == 0) {
226 E.
Kind = dwarf::DW_LLE_end_of_list;
227 }
else if (Value0 == (
Data.getAddressSize() == 4 ? -1U : -1ULL)) {
228 E.
Kind = dwarf::DW_LLE_base_address;
232 E.
Kind = dwarf::DW_LLE_offset_pair;
236 unsigned Bytes =
Data.getU16(C);
243 if (!Callback(E) || E.
Kind == dwarf::DW_LLE_end_of_list)
254 uint64_t Value0, Value1;
255 switch (Entry.
Kind) {
256 case dwarf::DW_LLE_base_address:
257 Value0 =
Data.getAddressSize() == 4 ? -1U : -1ULL;
260 case dwarf::DW_LLE_offset_pair:
264 case dwarf::DW_LLE_end_of_list:
272 OS <<
'(' <<
format_hex(Value0, 2 +
Data.getAddressSize() * 2) <<
", " 286 case dwarf::DW_LLE_end_of_list:
288 case dwarf::DW_LLE_base_addressx:
291 case dwarf::DW_LLE_startx_endx:
295 case dwarf::DW_LLE_startx_length:
304 case dwarf::DW_LLE_offset_pair:
309 case dwarf::DW_LLE_default_location:
311 case dwarf::DW_LLE_base_address:
314 case dwarf::DW_LLE_start_end:
318 case dwarf::DW_LLE_start_length:
325 "LLE of kind %x not supported", (
int)E.
Kind);
328 if (E.
Kind != dwarf::DW_LLE_base_address &&
329 E.
Kind != dwarf::DW_LLE_base_addressx &&
330 E.
Kind != dwarf::DW_LLE_end_of_list) {
338 Continue =
F(E) && E.
Kind != dwarf::DW_LLE_end_of_list;
348 size_t MaxEncodingStringLength = 0;
349 #define HANDLE_DW_LLE(ID, NAME) \ 350 MaxEncodingStringLength = std::max(MaxEncodingStringLength, \ 351 dwarf::LocListEncodingString(ID).size()); 352 #include "llvm/BinaryFormat/Dwarf.def" 358 assert(!EncodingString.
empty() &&
"Unknown loclist entry encoding");
359 OS <<
format(
"%-*s(", MaxEncodingStringLength, EncodingString.
data());
360 unsigned FieldSize = 2 + 2 *
Data.getAddressSize();
361 switch (Entry.
Kind) {
362 case dwarf::DW_LLE_end_of_list:
363 case dwarf::DW_LLE_default_location:
365 case dwarf::DW_LLE_startx_endx:
366 case dwarf::DW_LLE_startx_length:
367 case dwarf::DW_LLE_offset_pair:
368 case dwarf::DW_LLE_start_end:
369 case dwarf::DW_LLE_start_length:
373 case dwarf::DW_LLE_base_addressx:
374 case dwarf::DW_LLE_base_address:
379 switch (Entry.
Kind) {
380 case dwarf::DW_LLE_base_address:
381 case dwarf::DW_LLE_start_end:
382 case dwarf::DW_LLE_start_length:
394 if (!
Data.isValidOffsetForDataOfSize(StartOffset, Size)) {
395 OS <<
"Invalid dump range\n";
398 uint64_t Offset = StartOffset;
400 bool CanContinue =
true;
401 while (CanContinue && Offset < StartOffset + Size) {
405 CanContinue = dumpLocationList(&Offset, OS,
None, MRI, Obj,
406 nullptr, DumpOpts, 12);
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Error visitAbsoluteLocationList(uint64_t Offset, Optional< object::SectionedAddress > BaseAddr, std::function< Optional< object::SectionedAddress >(uint32_t)> LookupAddr, function_ref< bool(Expected< DWARFLocationExpression >)> Callback) const
This class represents lattice values for constants.
bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, Optional< object::SectionedAddress > BaseAddr, const MCRegisterInfo *MRI, const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const
Dump the location list at the given Offset.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
An efficient, type-erasing, non-owning reference to a callable.
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, const MCRegisterInfo *MRI, const DWARFObject &Obj, DIDumpOptions DumpOpts)
Dump all location lists within the given range.
A single location within a location list.
Error takeError()
Take ownership of the stored error.
static Error createResolverError(uint32_t Index, unsigned Kind)
Error visitLocationList(uint64_t *Offset, function_ref< bool(const DWARFLocationEntry &)> Callback) const override
Call the user-provided callback for each entry (including the end-of-list entry) in the location list...
uint8_t Kind
The entry kind (DW_LLE_***).
std::string toString(Error E)
Write all error messages (if any) in E to a string.
uint64_t Value1
The second value of the location entry (if applicable).
Tagged union holding either a T or a Error.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
uint64_t Value0
The first value of the location entry (if applicable).
SmallVector< uint8_t, 4 > Loc
The location expression itself (if applicable).
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Container for dump options that control which debug information will be dumped.
unsigned const MachineRegisterInfo * MRI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
void consumeError(Error Err)
Consume a Error without doing anything.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, const DWARFObject &Obj, DIDumpOptions DumpOpts, Optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
static ErrorSuccess success()
Create a success value.
Represents a single DWARF expression, whose value is location-dependent.
static void dumpExpression(raw_ostream &OS, ArrayRef< uint8_t > Data, bool IsLittleEndian, unsigned AddressSize, const MCRegisterInfo *MRI, DWARFUnit *U)
void print(raw_ostream &OS, const MCRegisterInfo *RegInfo, DWARFUnit *U, bool IsEH=false) const
reference get()
Returns a reference to the stored T value.
This file contains constants used for implementing Dwarf debug support.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef LocListEncodingString(unsigned Encoding)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Error visitLocationList(uint64_t *Offset, function_ref< bool(const DWARFLocationEntry &)> Callback) const override
Call the user-provided callback for each entry (including the end-of-list entry) in the location list...
uint64_t SectionIndex
The index of the section this entry is relative to (if applicable).
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
print Print MemDeps of function
Optional< object::SectionedAddress > getAddrOffsetSectionItem(uint32_t Index) const
StringRef - Represent a constant reference to a string, i.e.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...