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:
126 unsigned Indent)
const {
127 DWARFLocationInterpreter Interp(
128 BaseAddr, [U](
uint32_t Index) -> std::optional<SectionedAddress> {
130 return U->getAddrOffsetSectionItem(
Index);
146 if (Loc.
get()->Range)
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) {
158 dumpExpression(OS, DumpOpts, E.Loc, Data.isLittleEndian(),
159 Data.getAddressSize(), U);
172 std::function<std::optional<SectionedAddress>(
uint32_t)> LookupAddr,
174 DWARFLocationInterpreter Interp(BaseAddr, std::move(LookupAddr));
180 return Callback(**Loc);
187 std::optional<uint64_t> DumpOffset)
const {
188 auto BaseAddr = std::nullopt;
189 unsigned Indent = 12;
196 bool CanContinue =
true;
223 if (Value0 == 0 && Value1 == 0) {
224 E.
Kind = dwarf::DW_LLE_end_of_list;
226 E.
Kind = dwarf::DW_LLE_base_address;
230 E.
Kind = dwarf::DW_LLE_offset_pair;
240 return C.takeError();
241 if (!Callback(E) || E.
Kind == dwarf::DW_LLE_end_of_list)
253 switch (Entry.Kind) {
254 case dwarf::DW_LLE_base_address:
256 Value1 = Entry.Value0;
258 case dwarf::DW_LLE_offset_pair:
259 Value0 = Entry.Value0;
260 Value1 = Entry.Value1;
262 case dwarf::DW_LLE_end_of_list:
283 case dwarf::DW_LLE_end_of_list:
285 case dwarf::DW_LLE_base_addressx:
288 case dwarf::DW_LLE_startx_endx:
292 case dwarf::DW_LLE_startx_length:
301 case dwarf::DW_LLE_offset_pair:
306 case dwarf::DW_LLE_default_location:
308 case dwarf::DW_LLE_base_address:
311 case dwarf::DW_LLE_start_end:
315 case dwarf::DW_LLE_start_length:
322 "LLE of kind %x not supported", (
int)E.
Kind);
325 if (E.
Kind != dwarf::DW_LLE_base_address &&
326 E.
Kind != dwarf::DW_LLE_base_addressx &&
327 E.
Kind != dwarf::DW_LLE_end_of_list) {
334 return C.takeError();
345 size_t MaxEncodingStringLength = 0;
346#define HANDLE_DW_LLE(ID, NAME) \
347 MaxEncodingStringLength = std::max(MaxEncodingStringLength, \
348 dwarf::LocListEncodingString(ID).size());
349#include "llvm/BinaryFormat/Dwarf.def"
355 assert(!EncodingString.
empty() &&
"Unknown loclist entry encoding");
356 OS <<
format(
"%-*s(", MaxEncodingStringLength, EncodingString.
data());
358 switch (Entry.Kind) {
359 case dwarf::DW_LLE_end_of_list:
360 case dwarf::DW_LLE_default_location:
362 case dwarf::DW_LLE_startx_endx:
363 case dwarf::DW_LLE_startx_length:
364 case dwarf::DW_LLE_offset_pair:
365 case dwarf::DW_LLE_start_end:
366 case dwarf::DW_LLE_start_length:
370 case dwarf::DW_LLE_base_addressx:
371 case dwarf::DW_LLE_base_address:
376 switch (Entry.Kind) {
377 case dwarf::DW_LLE_base_address:
378 case dwarf::DW_LLE_start_end:
379 case dwarf::DW_LLE_start_length:
391 OS <<
"Invalid dump range\n";
396 bool CanContinue =
true;
397 while (CanContinue &&
Offset < StartOffset +
Size) {
402 nullptr, DumpOpts, 12);
408 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