[PATCH] D87937: DebugInfo: Remove DWARFv5 TUs from CUs list by sorting the finalized list
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 18 13:19:42 PDT 2020
dblaikie created this revision.
dblaikie added reviewers: echristo, aprantl, probinson, JDevlieghere, jhenderson.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
dblaikie requested review of this revision.
Since DWARFv5 places TUs in debug_info, some of DWARFContext's APIs have
become a bit erroneous, including TUs in the CU list by accident.
One of a couple of alternatives - just looking for a quick "which of these seems best".
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D87937
Files:
llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
Index: llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -170,6 +170,23 @@
return NewCU;
}
+void DWARFUnitVector::finishedInfoUnits() {
+ NumInfoUnits = size();
+ llvm::stable_sort(*this, [](const std::unique_ptr<DWARFUnit> &LHS,
+ const std::unique_ptr<DWARFUnit> &RHS) {
+ bool LTU = LHS->isTypeUnit();
+ bool RTU = RHS->isTypeUnit();
+ if (LTU == RTU)
+ return false;
+ if (!LTU && RTU)
+ return true;
+ return false;
+ });
+ auto I = llvm::find_if(*this, [](const std::unique_ptr<DWARFUnit> &U) {
+ return U->isTypeUnit();
+ });
+ NumCompileUnits = I - begin();
+}
DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA,
const DWARFSection *RS, const DWARFSection *LocSection,
Index: llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -379,8 +379,17 @@
DObj->getAbbrevDWOSection()))
getDebugAbbrevDWO()->dump(OS);
- auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
+ auto dumpDebugInfo = [&](const char *Name,
+ unit_iterator_range UnsortedUnits) {
OS << '\n' << Name << " contents:\n";
+ SmallVector<DWARFUnit *, 1> Units;
+ Units.reserve(llvm::size(UnsortedUnits));
+ for (const auto &U : UnsortedUnits)
+ Units.push_back(U.get());
+ llvm::stable_sort(Units, [](const DWARFUnit *LHS, const DWARFUnit *RHS) {
+ return std::make_tuple(LHS->getInfoSection().Index, LHS->getOffset()) <
+ std::make_tuple(RHS->getInfoSection().Index, RHS->getOffset());
+ });
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
for (const auto &U : Units)
U->getDIEForOffset(DumpOffset.getValue())
@@ -1720,6 +1729,7 @@
// there are multiple, comdat grouped, of these sections.
DWARFSectionMap &S = (*Sections)[Section];
S.Data = Data;
+ S.Index = Section.getIndex();
}
if (RelocatedSection == Obj.section_end())
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -121,6 +121,7 @@
const DWARFUnitIndex::Entry *)>
Parser;
int NumInfoUnits = -1;
+ int NumCompileUnits = -1;
public:
using UnitVector = SmallVectorImpl<std::unique_ptr<DWARFUnit>>;
@@ -154,11 +155,14 @@
unsigned getNumInfoUnits() const {
return NumInfoUnits == -1 ? size() : NumInfoUnits;
}
+ unsigned getNumCompileUnits() const {
+ return NumCompileUnits == -1 ? size() : NumCompileUnits;
+ }
/// Returns number of units from all .debug_types[.dwo] sections.
- unsigned getNumTypesUnits() const { return size() - NumInfoUnits; }
+ unsigned getNumTypesUnits() const { return size() - NumCompileUnits; }
/// Indicate that parsing .debug_info[.dwo] is done, and remaining units
/// will be from .debug_types[.dwo].
- void finishedInfoUnits() { NumInfoUnits = size(); }
+ void finishedInfoUnits();
private:
void addUnitsImpl(DWARFContext &Context, const DWARFObject &Obj,
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
@@ -15,6 +15,7 @@
struct DWARFSection {
StringRef Data;
+ int Index;
};
struct SectionName {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87937.292888.patch
Type: text/x-patch
Size: 3895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200918/f5bcc5d6/attachment.bin>
More information about the llvm-commits
mailing list