Skip to content

Commit ce40cc2

Browse files
committed
[DebugInfo] Report errors when DWARFUnitHeader::applyIndexEntry fails
Motivation: LLDB is able to report errors about these scenarios whereas LLVM's DWARF parser only gives a boolean success/fail. I want to migrate LLDB to using LLVM's DWARFUnitHeader class, but I don't want to lose some of the error reporting, so I'm adding it to the LLVM class first.
1 parent 0ab3f16 commit ce40cc2

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class DWARFUnitHeader {
8585
uint64_t *offset_ptr, DWARFSectionKind SectionKind);
8686
// For units in DWARF Package File, remember the index entry and update
8787
// the abbreviation offset read by extract().
88-
bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry);
88+
Error applyIndexEntry(const DWARFUnitIndex::Entry *Entry);
8989
uint64_t getOffset() const { return Offset; }
9090
const dwarf::FormParams &getFormParams() const { return FormParams; }
9191
uint16_t getVersion() const { return FormParams.Version; }

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ void DWARFUnitVector::addUnitsImpl(
9898
if (!IndexEntry)
9999
IndexEntry = Index.getFromOffset(Header.getOffset());
100100
}
101-
if (IndexEntry && !Header.applyIndexEntry(IndexEntry))
102-
return nullptr;
101+
if (IndexEntry) {
102+
if (Error ApplicationErr = Header.applyIndexEntry(IndexEntry)) {
103+
Context.getWarningHandler()(std::move(ApplicationErr));
104+
return nullptr;
105+
}
106+
}
103107
std::unique_ptr<DWARFUnit> U;
104108
if (Header.isTypeUnit())
105109
U = std::make_unique<DWARFTypeUnit>(Context, InfoSection, Header, DA,
@@ -334,21 +338,33 @@ Error DWARFUnitHeader::extract(DWARFContext &Context,
334338
return Error::success();
335339
}
336340

337-
bool DWARFUnitHeader::applyIndexEntry(const DWARFUnitIndex::Entry *Entry) {
341+
Error DWARFUnitHeader::applyIndexEntry(const DWARFUnitIndex::Entry *Entry) {
338342
assert(Entry);
339343
assert(!IndexEntry);
340344
IndexEntry = Entry;
341345
if (AbbrOffset)
342-
return false;
346+
return createStringError(errc::invalid_argument,
347+
"DWARF package unit from offset 0x%8.8" PRIx64
348+
" has a non-zero abbreviation offset",
349+
Offset);
350+
343351
auto *UnitContrib = IndexEntry->getContribution();
344352
if (!UnitContrib ||
345353
UnitContrib->getLength() != (getLength() + getUnitLengthFieldByteSize()))
346-
return false;
354+
return createStringError(errc::invalid_argument,
355+
"DWARF package unit at offset 0x%8.8" PRIx64
356+
"has an inconsistent index",
357+
Offset);
358+
347359
auto *AbbrEntry = IndexEntry->getContribution(DW_SECT_ABBREV);
348360
if (!AbbrEntry)
349-
return false;
361+
return createStringError(errc::invalid_argument,
362+
"DWARF package unit at offset 0x%8.8 " PRIx64
363+
" mising abbreviation column",
364+
Offset);
365+
350366
AbbrOffset = AbbrEntry->getOffset();
351-
return true;
367+
return Error::success();
352368
}
353369

354370
Error DWARFUnit::extractRangeList(uint64_t RangeListOffset,

0 commit comments

Comments
 (0)