[DWARFDebugRnglists] Add a callback-based version of the getAbsoluteRanges function

Summary:
The dump() function already accepts a callback. This makes
getAbsoluteRanges do the same. The existing DWARFUnit overload is
implemented on top of the new function.

This enables usage of the debug_rnglists parser from within lldb (which
has it's own dwarf parser).

Reviewers: dblaikie, JDevlieghere, aprantl

Subscribers: hiraditya, probinson, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70952
This commit is contained in:
Pavel Labath 2019-11-26 10:40:30 +01:00
parent c3d05c1b52
commit d34927e7db
2 changed files with 17 additions and 2 deletions

View File

@ -45,6 +45,12 @@ struct RangeListEntry : public DWARFListEntryBase {
/// A class representing a single rangelist.
class DWARFDebugRnglist : public DWARFListType<RangeListEntry> {
public:
/// Build a DWARFAddressRangesVector from a rangelist.
DWARFAddressRangesVector
getAbsoluteRanges(Optional<object::SectionedAddress> BaseAddr,
function_ref<Optional<object::SectionedAddress>(uint32_t)>
LookupPooledAddress) const;
/// Build a DWARFAddressRangesVector from a rangelist.
DWARFAddressRangesVector
getAbsoluteRanges(llvm::Optional<object::SectionedAddress> BaseAddr,

View File

@ -114,12 +114,21 @@ Error RangeListEntry::extract(DWARFDataExtractor Data, uint64_t End,
DWARFAddressRangesVector DWARFDebugRnglist::getAbsoluteRanges(
llvm::Optional<object::SectionedAddress> BaseAddr, DWARFUnit &U) const {
return getAbsoluteRanges(BaseAddr, [&](uint32_t Index) {
return U.getAddrOffsetSectionItem(Index);
});
}
DWARFAddressRangesVector DWARFDebugRnglist::getAbsoluteRanges(
Optional<object::SectionedAddress> BaseAddr,
function_ref<Optional<object::SectionedAddress>(uint32_t)>
LookupPooledAddress) const {
DWARFAddressRangesVector Res;
for (const RangeListEntry &RLE : Entries) {
if (RLE.EntryKind == dwarf::DW_RLE_end_of_list)
break;
if (RLE.EntryKind == dwarf::DW_RLE_base_addressx) {
BaseAddr = U.getAddrOffsetSectionItem(RLE.Value0);
BaseAddr = LookupPooledAddress(RLE.Value0);
if (!BaseAddr)
BaseAddr = {RLE.Value0, -1ULL};
continue;
@ -152,7 +161,7 @@ DWARFAddressRangesVector DWARFDebugRnglist::getAbsoluteRanges(
E.HighPC = E.LowPC + RLE.Value1;
break;
case dwarf::DW_RLE_startx_length: {
auto Start = U.getAddrOffsetSectionItem(RLE.Value0);
auto Start = LookupPooledAddress(RLE.Value0);
if (!Start)
Start = {0, -1ULL};
E.SectionIndex = Start->SectionIndex;