Skip to content

Commit 1eea3fa

Browse files
committed
DWARFDebugLoclists: Add an api to get the location lists of a DWARF unit
Summary: This avoid the need to duplicate the location lists searching logic in various users. The "inline location list dumping" code (which is the only user actually updated to handle DWARF v5 location lists) is switched to this method. After adding v4 location list support, I'll switch other users too. Reviewers: dblaikie, probinson, JDevlieghere, aprantl, SouraVX Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70084
1 parent e84b7a5 commit 1eea3fa

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/iterator_range.h"
1717
#include "llvm/BinaryFormat/Dwarf.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
19+
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
1920
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
2021
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
2122
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
@@ -199,12 +200,14 @@ class DWARFUnit {
199200
const DWARFDebugAbbrev *Abbrev;
200201
const DWARFSection *RangeSection;
201202
uint64_t RangeSectionBase;
202-
/// We either keep track of the location list section or its data, depending
203-
/// on whether we are handling a split DWARF section or not.
204-
union {
205-
const DWARFSection *LocSection;
206-
StringRef LocSectionData;
207-
};
203+
204+
/// Section containing the location lists of this unit used for non-split
205+
/// DWARF<=v4 units.
206+
const DWARFSection *LocSection;
207+
208+
/// Location table of this unit. Used for DWARF v5 and DWO units.
209+
std::unique_ptr<DWARFLocationTable> LocTable;
210+
208211
const DWARFSection &LineSection;
209212
StringRef StringSection;
210213
const DWARFSection &StringOffsetSection;
@@ -275,7 +278,6 @@ class DWARFUnit {
275278
DWARFContext& getContext() const { return Context; }
276279
const DWARFSection &getInfoSection() const { return InfoSection; }
277280
const DWARFSection *getLocSection() const { return LocSection; }
278-
StringRef getLocSectionData() const { return LocSectionData; }
279281
uint64_t getOffset() const { return Header.getOffset(); }
280282
const dwarf::FormParams &getFormParams() const {
281283
return Header.getFormParams();
@@ -319,6 +321,8 @@ class DWARFUnit {
319321
return DataExtractor(StringSection, false, 0);
320322
}
321323

324+
const DWARFLocationTable *getLocationTable() { return LocTable.get(); }
325+
322326
/// Extract the range list referenced by this compile unit from the
323327
/// .debug_ranges section. If the extraction is unsuccessful, an error
324328
/// is returned. Successful extraction requires that the compile unit

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,49 +92,35 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
9292
}
9393

9494
if (FormValue.isFormClass(DWARFFormValue::FC_SectionOffset)) {
95+
auto LLDumpOpts = DumpOpts;
96+
LLDumpOpts.Verbose = false;
97+
9598
uint64_t Offset = *FormValue.getAsSectionOffset();
9699
uint64_t BaseAddr = 0;
97100
if (Optional<object::SectionedAddress> BA = U->getBaseAddress())
98101
BaseAddr = BA->Address;
99-
auto LLDumpOpts = DumpOpts;
100-
LLDumpOpts.Verbose = false;
101-
102-
if (!U->isDWOUnit() && !U->getLocSection()->Data.empty()) {
103-
DWARFDebugLoc DebugLoc;
104-
DWARFDataExtractor Data(Obj, *U->getLocSection(), Ctx.isLittleEndian(),
105-
Obj.getAddressSize());
106-
107-
FormValue.dump(OS, DumpOpts);
108-
OS << ": ";
109102

110-
if (Expected<DWARFDebugLoc::LocationList> LL =
111-
DebugLoc.parseOneLocationList(Data, &Offset)) {
112-
LL->dump(OS, BaseAddr, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI,
113-
U, LLDumpOpts, Indent);
114-
} else {
115-
OS << '\n';
116-
OS.indent(Indent);
117-
OS << formatv("error extracting location list: {0}",
118-
fmt_consume(LL.takeError()));
119-
}
103+
if (const DWARFLocationTable *LT = U->getLocationTable()) {
104+
LT->dumpLocationList(&Offset, OS, BaseAddr, MRI, U, LLDumpOpts, Indent);
120105
return;
121106
}
122107

123-
bool UseLocLists = !U->isDWOUnit();
124-
auto Data =
125-
UseLocLists
126-
? DWARFDataExtractor(Obj, Obj.getLoclistsSection(),
127-
Ctx.isLittleEndian(), Obj.getAddressSize())
128-
: DWARFDataExtractor(U->getLocSectionData(), Ctx.isLittleEndian(),
129-
Obj.getAddressSize());
130-
131-
if (!Data.getData().empty()) {
132-
// Old-style location list were used in DWARF v4 (.debug_loc.dwo section).
133-
// Modern locations list (.debug_loclists) are used starting from v5.
134-
// Ideally we should take the version from the .debug_loclists section
135-
// header, but using CU's version for simplicity.
136-
DWARFDebugLoclists(Data, UseLocLists ? U->getVersion() : 4)
137-
.dumpLocationList(&Offset, OS, BaseAddr, MRI, U, LLDumpOpts, Indent);
108+
DWARFDebugLoc DebugLoc;
109+
DWARFDataExtractor Data(Obj, *U->getLocSection(), Ctx.isLittleEndian(),
110+
Obj.getAddressSize());
111+
112+
FormValue.dump(OS, DumpOpts);
113+
OS << ": ";
114+
115+
if (Expected<DWARFDebugLoc::LocationList> LL =
116+
DebugLoc.parseOneLocationList(Data, &Offset)) {
117+
LL->dump(OS, BaseAddr, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, U,
118+
LLDumpOpts, Indent);
119+
} else {
120+
OS << '\n';
121+
OS.indent(Indent);
122+
OS << formatv("error extracting location list: {0}",
123+
fmt_consume(LL.takeError()));
138124
}
139125
return;
140126
}

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,22 @@ DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
179179
StringSection(SS), StringOffsetSection(SOS), AddrOffsetSection(AOS),
180180
isLittleEndian(LE), IsDWO(IsDWO), UnitVector(UnitVector) {
181181
clear();
182-
// For split DWARF we only need to keep track of the location list section's
183-
// data (no relocations), and if we are reading a package file, we need to
184-
// adjust the location list data based on the index entries.
185182
if (IsDWO) {
186-
LocSectionData = LocSection->Data;
183+
// If we are reading a package file, we need to adjust the location list
184+
// data based on the index entries.
185+
StringRef Data = LocSection->Data;
187186
if (auto *IndexEntry = Header.getIndexEntry())
188187
if (const auto *C = IndexEntry->getOffset(DW_SECT_LOC))
189-
LocSectionData = LocSectionData.substr(C->Offset, C->Length);
188+
Data = Data.substr(C->Offset, C->Length);
189+
LocTable = std::make_unique<DWARFDebugLoclists>(
190+
DWARFDataExtractor(Data, isLittleEndian, getAddressByteSize()),
191+
Header.getVersion());
192+
} else if (Header.getVersion() >= 5) {
193+
LocTable = std::make_unique<DWARFDebugLoclists>(
194+
DWARFDataExtractor(Context.getDWARFObj(),
195+
Context.getDWARFObj().getLoclistsSection(),
196+
isLittleEndian, getAddressByteSize()),
197+
Header.getVersion());
190198
}
191199
}
192200

0 commit comments

Comments
 (0)