34class DWARFLocationInterpreter {
35 std::optional<object::SectionedAddress>
Base;
36 std::function<std::optional<object::SectionedAddress>(uint32_t)> LookupAddr;
39 DWARFLocationInterpreter(
40 std::optional<object::SectionedAddress>
Base,
41 std::function<std::optional<object::SectionedAddress>(uint32_t)>
45 Expected<std::optional<DWARFLocationExpression>>
46 Interpret(
const DWARFLocationEntry &
E);
57 case dwarf::DW_LLE_end_of_list:
59 case dwarf::DW_LLE_base_addressx: {
60 Base = LookupAddr(
E.Value0);
65 case dwarf::DW_LLE_startx_endx: {
66 std::optional<SectionedAddress> LowPC = LookupAddr(
E.Value0);
69 std::optional<SectionedAddress> HighPC = LookupAddr(
E.Value1);
72 return DWARFLocationExpression{
73 DWARFAddressRange{LowPC->Address, HighPC->Address, LowPC->SectionIndex},
76 case dwarf::DW_LLE_startx_length: {
77 std::optional<SectionedAddress> LowPC = LookupAddr(
E.Value0);
80 return DWARFLocationExpression{DWARFAddressRange{LowPC->Address,
81 LowPC->Address +
E.Value1,
85 case dwarf::DW_LLE_offset_pair: {
88 "Unable to resolve location list offset pair: "
89 "Base address not defined");
91 DWARFAddressRange
Range{
Base->Address +
E.Value0,
Base->Address +
E.Value1,
94 Range.SectionIndex =
E.SectionIndex;
95 return DWARFLocationExpression{
Range,
E.Loc};
97 case dwarf::DW_LLE_default_location:
98 return DWARFLocationExpression{std::nullopt,
E.Loc};
99 case dwarf::DW_LLE_base_address:
100 Base = SectionedAddress{
E.Value0,
E.SectionIndex};
102 case dwarf::DW_LLE_start_end:
103 return DWARFLocationExpression{
104 DWARFAddressRange{
E.Value0,
E.Value1,
E.SectionIndex},
E.Loc};
105 case dwarf::DW_LLE_start_length:
106 return DWARFLocationExpression{
107 DWARFAddressRange{
E.Value0,
E.Value0 +
E.Value1,
E.SectionIndex},
118 std::optional<dwarf::DwarfFormat> Format;
120 Format = U->getFormat();
128 unsigned Indent)
const {
129 DWARFLocationInterpreter Interp(
130 BaseAddr, [U](
uint32_t Index) -> std::optional<SectionedAddress> {
132 return U->getAddrOffsetSectionItem(Index);
148 if (
Loc.get()->Range)
149 Loc.get()->Range->dump(OS,
Data.getAddressSize(), RangeDumpOpts, &Obj);
156 if (E.Kind != dwarf::DW_LLE_base_address &&
157 E.Kind != dwarf::DW_LLE_base_addressx &&
158 E.Kind != dwarf::DW_LLE_end_of_list) {
161 Data.getAddressSize(), U);
173 uint64_t
Offset, std::optional<SectionedAddress> BaseAddr,
174 std::function<std::optional<SectionedAddress>(
uint32_t)> LookupAddr,
176 DWARFLocationInterpreter Interp(BaseAddr, std::move(LookupAddr));
180 return Callback(
Loc.takeError());
182 return Callback(**
Loc);
189 std::optional<uint64_t> DumpOffset)
const {
190 auto BaseAddr = std::nullopt;
191 unsigned Indent = 12;
198 bool CanContinue =
true;
199 while (CanContinue &&
Data.isValidOffset(
Offset)) {
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;
230 E.SectionIndex = SectionIndex;
232 E.Kind = dwarf::DW_LLE_offset_pair;
235 E.SectionIndex = SectionIndex;
236 unsigned Bytes =
Data.getU16(
C);
238 Data.getU8(
C, E.Loc, Bytes);
242 return C.takeError();
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;
258 Value1 = Entry.Value0;
260 case dwarf::DW_LLE_offset_pair:
261 Value0 = Entry.Value0;
262 Value1 = Entry.Value1;
264 case dwarf::DW_LLE_end_of_list:
271 OS <<
'(' <<
format_hex(Value0, 2 +
Data.getAddressSize() * 2) <<
", "
285 case dwarf::DW_LLE_end_of_list:
287 case dwarf::DW_LLE_base_addressx:
288 E.Value0 =
Data.getULEB128(
C);
290 case dwarf::DW_LLE_startx_endx:
291 E.Value0 =
Data.getULEB128(
C);
292 E.Value1 =
Data.getULEB128(
C);
294 case dwarf::DW_LLE_startx_length:
295 E.Value0 =
Data.getULEB128(
C);
299 E.Value1 =
Data.getU32(
C);
301 E.Value1 =
Data.getULEB128(
C);
303 case dwarf::DW_LLE_offset_pair:
304 E.Value0 =
Data.getULEB128(
C);
305 E.Value1 =
Data.getULEB128(
C);
308 case dwarf::DW_LLE_default_location:
310 case dwarf::DW_LLE_base_address:
311 E.Value0 =
Data.getRelocatedAddress(
C, &E.SectionIndex);
313 case dwarf::DW_LLE_start_end:
314 E.Value0 =
Data.getRelocatedAddress(
C, &E.SectionIndex);
315 E.Value1 =
Data.getRelocatedAddress(
C);
317 case dwarf::DW_LLE_start_length:
318 E.Value0 =
Data.getRelocatedAddress(
C, &E.SectionIndex);
319 E.Value1 =
Data.getULEB128(
C);
324 "LLE of kind %x not supported", (
int)E.Kind);
327 if (E.Kind != dwarf::DW_LLE_base_address &&
328 E.Kind != dwarf::DW_LLE_base_addressx &&
329 E.Kind != dwarf::DW_LLE_end_of_list) {
330 unsigned Bytes = Version >= 5 ?
Data.getULEB128(
C) :
Data.getU16(
C);
332 Data.getU8(
C, E.Loc, Bytes);
336 return C.takeError();
337 Continue =
F(E) && E.Kind != dwarf::DW_LLE_end_of_list;
347 size_t MaxEncodingStringLength = 0;
348#define HANDLE_DW_LLE(ID, NAME) \
349 MaxEncodingStringLength = std::max(MaxEncodingStringLength, \
350 dwarf::LocListEncodingString(ID).size());
351#include "llvm/BinaryFormat/Dwarf.def"
357 assert(!EncodingString.
empty() &&
"Unknown loclist entry encoding");
359 MaxEncodingStringLength));
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:
370 OS <<
format_hex(Entry.Value0, FieldSize) <<
", "
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:
393 if (!
Data.isValidOffsetForDataOfSize(StartOffset,
Size)) {
394 OS <<
"Invalid dump range\n";
397 uint64_t
Offset = StartOffset;
399 bool CanContinue =
true;
400 while (CanContinue &&
Offset < StartOffset +
Size) {
405 nullptr, DumpOpts, 12);
411 OS <<
formatv(
"unable to resolve indirect address {0} for: {1}", Index,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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)
static void dumpLocationList(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
This file contains constants used for implementing Dwarf debug support.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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
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...
LLVM_ABI 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
LLVM_ABI 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.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
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.
LLVM_ABI StringRef LocListEncodingString(unsigned Encoding)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LoclistEntries
DWARF v5 loc list entry encoding values.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS, DIDumpOptions DumpOpts, DWARFUnit *U, bool IsEH=false)
Print a Dwarf expression/.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
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.
support::detail::AlignAdapter< T > fmt_align(T &&Item, AlignStyle Where, size_t Amount, char Fill=' ')
void consumeError(Error Err)
Consume a Error without doing anything.
Container for dump options that control which debug information will be dumped.
std::function< void(Error)> RecoverableErrorHandler
A single location within a location list.
uint8_t Kind
The entry kind (DW_LLE_***).
static const uint64_t UndefSection
static const uint64_t UndefSection