32class DWARFLocationInterpreter {
33 std::optional<object::SectionedAddress>
Base;
34 std::function<std::optional<object::SectionedAddress>(
uint32_t)> LookupAddr;
37 DWARFLocationInterpreter(
38 std::optional<object::SectionedAddress>
Base,
39 std::function<std::optional<object::SectionedAddress>(
uint32_t)>
55 case dwarf::DW_LLE_end_of_list:
57 case dwarf::DW_LLE_base_addressx: {
63 case dwarf::DW_LLE_startx_endx: {
64 std::optional<SectionedAddress> LowPC = LookupAddr(E.
Value0);
67 std::optional<SectionedAddress> HighPC = LookupAddr(E.
Value1);
74 case dwarf::DW_LLE_startx_length: {
75 std::optional<SectionedAddress> LowPC = LookupAddr(E.
Value0);
83 case dwarf::DW_LLE_offset_pair: {
86 "Unable to resolve location list offset pair: "
87 "Base address not defined");
95 case dwarf::DW_LLE_default_location:
97 case dwarf::DW_LLE_base_address:
100 case dwarf::DW_LLE_start_end:
103 case dwarf::DW_LLE_start_length:
116 std::optional<dwarf::DwarfFormat> Format;
118 Format = U->getFormat();
125 unsigned Indent)
const {
126 DWARFLocationInterpreter Interp(
127 BaseAddr, [U](
uint32_t Index) -> std::optional<SectionedAddress> {
129 return U->getAddrOffsetSectionItem(
Index);
145 if (Loc.
get()->Range)
153 if (E.Kind != dwarf::DW_LLE_base_address &&
154 E.Kind != dwarf::DW_LLE_base_addressx &&
155 E.Kind != dwarf::DW_LLE_end_of_list) {
157 dumpExpression(OS, DumpOpts, E.Loc, Data.isLittleEndian(),
158 Data.getAddressSize(), U);
171 std::function<std::optional<SectionedAddress>(
uint32_t)> LookupAddr,
173 DWARFLocationInterpreter Interp(BaseAddr, std::move(LookupAddr));
179 return Callback(**Loc);
186 std::optional<uint64_t> DumpOffset)
const {
187 auto BaseAddr = std::nullopt;
188 unsigned Indent = 12;
195 bool CanContinue =
true;
222 if (Value0 == 0 && Value1 == 0) {
223 E.
Kind = dwarf::DW_LLE_end_of_list;
225 E.
Kind = dwarf::DW_LLE_base_address;
229 E.
Kind = dwarf::DW_LLE_offset_pair;
239 return C.takeError();
240 if (!Callback(E) || E.
Kind == dwarf::DW_LLE_end_of_list)
252 switch (Entry.Kind) {
253 case dwarf::DW_LLE_base_address:
255 Value1 = Entry.Value0;
257 case dwarf::DW_LLE_offset_pair:
258 Value0 = Entry.Value0;
259 Value1 = Entry.Value1;
261 case dwarf::DW_LLE_end_of_list:
282 case dwarf::DW_LLE_end_of_list:
284 case dwarf::DW_LLE_base_addressx:
287 case dwarf::DW_LLE_startx_endx:
291 case dwarf::DW_LLE_startx_length:
300 case dwarf::DW_LLE_offset_pair:
305 case dwarf::DW_LLE_default_location:
307 case dwarf::DW_LLE_base_address:
310 case dwarf::DW_LLE_start_end:
314 case dwarf::DW_LLE_start_length:
321 "LLE of kind %x not supported", (
int)E.
Kind);
324 if (E.
Kind != dwarf::DW_LLE_base_address &&
325 E.
Kind != dwarf::DW_LLE_base_addressx &&
326 E.
Kind != dwarf::DW_LLE_end_of_list) {
333 return C.takeError();
344 size_t MaxEncodingStringLength = 0;
345#define HANDLE_DW_LLE(ID, NAME) \
346 MaxEncodingStringLength = std::max(MaxEncodingStringLength, \
347 dwarf::LocListEncodingString(ID).size());
348#include "llvm/BinaryFormat/Dwarf.def"
354 assert(!EncodingString.
empty() &&
"Unknown loclist entry encoding");
355 OS <<
format(
"%-*s(", MaxEncodingStringLength, EncodingString.
data());
357 switch (Entry.Kind) {
358 case dwarf::DW_LLE_end_of_list:
359 case dwarf::DW_LLE_default_location:
361 case dwarf::DW_LLE_startx_endx:
362 case dwarf::DW_LLE_startx_length:
363 case dwarf::DW_LLE_offset_pair:
364 case dwarf::DW_LLE_start_end:
365 case dwarf::DW_LLE_start_length:
369 case dwarf::DW_LLE_base_addressx:
370 case dwarf::DW_LLE_base_address:
375 switch (Entry.Kind) {
376 case dwarf::DW_LLE_base_address:
377 case dwarf::DW_LLE_start_end:
378 case dwarf::DW_LLE_start_length:
390 OS <<
"Invalid dump range\n";
395 bool CanContinue =
true;
396 while (CanContinue &&
Offset < StartOffset +
Size) {
401 nullptr, DumpOpts, 12);
407 OS <<
format(
"unable to resolve indirect address %u for: %s",
Index,
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static void dumpExpression(raw_ostream &OS, DIDumpOptions DumpOpts, ArrayRef< uint8_t > Data, bool IsLittleEndian, unsigned AddressSize, DWARFUnit *U)
static Error createResolverError(uint32_t Index, unsigned Kind)
This file contains constants used for implementing Dwarf debug support.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts, std::optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
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...
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts)
Dump all location lists within the given range.
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...
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
void print(raw_ostream &OS, DIDumpOptions DumpOpts, DWARFUnit *U, bool IsEH=false) const
virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const =0
virtual Error visitLocationList(uint64_t *Offset, function_ref< bool(const DWARFLocationEntry &)> Callback) const =0
Call the user-provided callback for each entry (including the end-of-list entry) in the location list...
Error visitAbsoluteLocationList(uint64_t Offset, std::optional< object::SectionedAddress > BaseAddr, std::function< std::optional< object::SectionedAddress >(uint32_t)> LookupAddr, function_ref< bool(Expected< DWARFLocationExpression >)> Callback) const
bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, std::optional< object::SectionedAddress > BaseAddr, const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const
Dump the location list at the given Offset.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
StringRef LocListEncodingString(unsigned Encoding)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
LoclistEntries
DWARF v5 loc list entry encoding values.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
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.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
Container for dump options that control which debug information will be dumped.
std::function< void(Error)> RecoverableErrorHandler
A single location within a location list.
SmallVector< uint8_t, 4 > Loc
The location expression itself (if applicable).
uint8_t Kind
The entry kind (DW_LLE_***).
uint64_t Value1
The second value of the location entry (if applicable).
uint64_t SectionIndex
The index of the section this entry is relative to (if applicable).
uint64_t Value0
The first value of the location entry (if applicable).
Represents a single DWARF expression, whose value is location-dependent.
static const uint64_t UndefSection