Skip to content

Commit a53da27

Browse files
committed
[DebugInfo] Support to get type units for hash from .debug_types.dwo section in Dwarf4
1 parent 98ebb64 commit a53da27

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ class DWARFUnitVector final : public SmallVector<std::unique_ptr<DWARFUnit>, 1>
143143
decltype(make_filter_range(std::declval<iterator_range>(), isCompileUnit));
144144

145145
LLVM_ABI DWARFUnit *getUnitForOffset(uint64_t Offset) const;
146-
LLVM_ABI DWARFUnit *getUnitForIndexEntry(const DWARFUnitIndex::Entry &E);
146+
LLVM_ABI DWARFUnit *
147+
getUnitForIndexEntry(const DWARFUnitIndex::Entry &E, DWARFSectionKind Sec,
148+
const DWARFSection *Section = nullptr);
147149

148150
/// Read units from a .debug_info or .debug_types section. Calls made
149151
/// before finishedInfoUnits() are assumed to be for .debug_info sections,

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,9 +1344,20 @@ void DWARFContext::dump(
13441344
DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint64_t Hash, bool IsDWO) {
13451345
DWARFUnitVector &DWOUnits = State->getDWOUnits();
13461346
if (const auto &TUI = getTUIndex()) {
1347-
if (const auto *R = TUI.getFromHash(Hash))
1348-
return dyn_cast_or_null<DWARFTypeUnit>(
1349-
DWOUnits.getUnitForIndexEntry(*R));
1347+
if (const auto *R = TUI.getFromHash(Hash)) {
1348+
if (TUI.getVersion() >= 5)
1349+
return dyn_cast_or_null<DWARFTypeUnit>(
1350+
DWOUnits.getUnitForIndexEntry(*R, DW_SECT_INFO));
1351+
else {
1352+
DWARFUnit *TypesUnit = nullptr;
1353+
getDWARFObj().forEachTypesDWOSections([&](const DWARFSection &S) {
1354+
if (!TypesUnit)
1355+
TypesUnit =
1356+
DWOUnits.getUnitForIndexEntry(*R, DW_SECT_EXT_TYPES, &S);
1357+
});
1358+
return dyn_cast_or_null<DWARFTypeUnit>(TypesUnit);
1359+
}
1360+
}
13501361
return nullptr;
13511362
}
13521363
return State->getTypeUnitMap(IsDWO).lookup(Hash);
@@ -1358,7 +1369,7 @@ DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
13581369
if (const auto &CUI = getCUIndex()) {
13591370
if (const auto *R = CUI.getFromHash(Hash))
13601371
return dyn_cast_or_null<DWARFCompileUnit>(
1361-
DWOUnits.getUnitForIndexEntry(*R));
1372+
DWOUnits.getUnitForIndexEntry(*R, DW_SECT_INFO));
13621373
return nullptr;
13631374
}
13641375

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,24 @@ DWARFUnit *DWARFUnitVector::getUnitForOffset(uint64_t Offset) const {
161161
return nullptr;
162162
}
163163

164-
DWARFUnit *
165-
DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E) {
166-
const auto *CUOff = E.getContribution(DW_SECT_INFO);
164+
DWARFUnit *DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E,
165+
DWARFSectionKind Sec,
166+
const DWARFSection *Section) {
167+
const auto *CUOff = E.getContribution(Sec);
167168
if (!CUOff)
168169
return nullptr;
169170

170171
uint64_t Offset = CUOff->getOffset();
171-
auto end = begin() + getNumInfoUnits();
172+
auto begin = this->begin();
173+
auto end = begin + getNumInfoUnits();
174+
175+
if (Sec == DW_SECT_EXT_TYPES) {
176+
begin = end;
177+
end = this->end();
178+
}
172179

173180
auto *CU =
174-
std::upper_bound(begin(), end, CUOff->getOffset(),
181+
std::upper_bound(begin, end, CUOff->getOffset(),
175182
[](uint64_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
176183
return LHS < RHS->getNextUnitOffset();
177184
});
@@ -181,13 +188,14 @@ DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E) {
181188
if (!Parser)
182189
return nullptr;
183190

184-
auto U = Parser(Offset, DW_SECT_INFO, nullptr, &E);
191+
auto U = Parser(Offset, Sec, Section, &E);
185192
if (!U)
186193
return nullptr;
187194

188195
auto *NewCU = U.get();
189196
this->insert(CU, std::move(U));
190-
++NumInfoUnits;
197+
if (Sec == DW_SECT_INFO)
198+
++NumInfoUnits;
191199
return NewCU;
192200
}
193201

0 commit comments

Comments
 (0)