From 97552d7c1c5a42f8eb6ce8ea8301df4c0185e768 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Mon, 29 Sep 2014 13:56:39 +0000 Subject: [PATCH] Store TypeUnits in a SmallVector instead of a single DWARFUnitSection. There will be multiple TypeUnits in an unlinked object that will be extracted from different sections. Now that we have DWARFUnitSection that is supposed to represent an input section, we need a DWARFUnitSection per input .debug_types section. Once this is done, the interface is homogenous and we can move the Section parsing code into DWARFUnitSection. This is a respin of r218513 that got reverted because it broke some builders. This new version features an explicit move constructor for the DWARFUnitSection class to workaround compilers unable to generate correct C++11 default constructors. Reviewers: samsonov, dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5482 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218606 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/DebugInfo/DWARFContext.cpp | 26 ++++++++++++++++---------- lib/DebugInfo/DWARFContext.h | 14 ++++++++------ lib/DebugInfo/DWARFUnit.h | 4 ++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 62e3b9ccf64..819fc142e50 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -86,15 +86,17 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) { if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) { OS << "\n.debug_types contents:\n"; - for (const auto &TU : type_units()) - TU->dump(OS); + for (const auto &TUS : type_unit_sections()) + for (const auto &TU : TUS) + TU->dump(OS); } if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) && getNumDWOTypeUnits()) { OS << "\n.debug_types.dwo contents:\n"; - for (const auto &DWOTU : dwo_type_units()) - DWOTU->dump(OS); + for (const auto &DWOTUS : dwo_type_unit_sections()) + for (const auto &DWOTU : DWOTUS) + DWOTU->dump(OS); } if (DumpType == DIDT_All || DumpType == DIDT_Loc) { @@ -337,15 +339,17 @@ void DWARFContext::parseTypeUnits() { uint32_t offset = 0; const DataExtractor &DIData = DataExtractor(I.second.Data, isLittleEndian(), 0); + TUs.push_back(DWARFUnitSection()); + auto &TUS = TUs.back(); while (DIData.isValidOffset(offset)) { std::unique_ptr TU(new DWARFTypeUnit(*this, getDebugAbbrev(), I.second.Data, getRangeSection(), getStringSection(), StringRef(), getAddrSection(), - &I.second.Relocs, isLittleEndian(), TUs)); + &I.second.Relocs, isLittleEndian(), TUS)); if (!TU->extract(DIData, &offset)) break; - TUs.push_back(std::move(TU)); - offset = TUs.back()->getNextUnitOffset(); + TUS.push_back(std::move(TU)); + offset = TUS.back()->getNextUnitOffset(); } } } @@ -376,15 +380,17 @@ void DWARFContext::parseDWOTypeUnits() { uint32_t offset = 0; const DataExtractor &DIData = DataExtractor(I.second.Data, isLittleEndian(), 0); + DWOTUs.push_back(DWARFUnitSection()); + auto &TUS = DWOTUs.back(); while (DIData.isValidOffset(offset)) { std::unique_ptr TU(new DWARFTypeUnit(*this, getDebugAbbrevDWO(), I.second.Data, getRangeDWOSection(), getStringDWOSection(), getStringOffsetDWOSection(), getAddrSection(), - &I.second.Relocs, isLittleEndian(), DWOTUs)); + &I.second.Relocs, isLittleEndian(), TUS)); if (!TU->extract(DIData, &offset)) break; - DWOTUs.push_back(std::move(TU)); - offset = DWOTUs.back()->getNextUnitOffset(); + TUS.push_back(std::move(TU)); + offset = TUS.back()->getNextUnitOffset(); } } } diff --git a/lib/DebugInfo/DWARFContext.h b/lib/DebugInfo/DWARFContext.h index f00191acb93..3c627bd3280 100644 --- a/lib/DebugInfo/DWARFContext.h +++ b/lib/DebugInfo/DWARFContext.h @@ -20,6 +20,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/DebugInfo/DIContext.h" +#include namespace llvm { @@ -30,7 +31,7 @@ namespace llvm { class DWARFContext : public DIContext { DWARFUnitSection CUs; - DWARFUnitSection TUs; + std::vector> TUs; std::unique_ptr Abbrev; std::unique_ptr Loc; std::unique_ptr Aranges; @@ -38,7 +39,7 @@ class DWARFContext : public DIContext { std::unique_ptr DebugFrame; DWARFUnitSection DWOCUs; - DWARFUnitSection DWOTUs; + std::vector> DWOTUs; std::unique_ptr AbbrevDWO; std::unique_ptr LocDWO; @@ -77,6 +78,7 @@ public: typedef DWARFUnitSection::iterator_range cu_iterator_range; typedef DWARFUnitSection::iterator_range tu_iterator_range; + typedef iterator_range>::iterator> tu_section_iterator_range; /// Get compile units in this context. cu_iterator_range compile_units() { @@ -85,9 +87,9 @@ public: } /// Get type units in this context. - tu_iterator_range type_units() { + tu_section_iterator_range type_unit_sections() { parseTypeUnits(); - return tu_iterator_range(TUs.begin(), TUs.end()); + return tu_section_iterator_range(TUs.begin(), TUs.end()); } /// Get compile units in the DWO context. @@ -97,9 +99,9 @@ public: } /// Get type units in the DWO context. - tu_iterator_range dwo_type_units() { + tu_section_iterator_range dwo_type_unit_sections() { parseDWOTypeUnits(); - return tu_iterator_range(DWOTUs.begin(), DWOTUs.end()); + return tu_section_iterator_range(DWOTUs.begin(), DWOTUs.end()); } /// Get the number of compile units in this context. diff --git a/lib/DebugInfo/DWARFUnit.h b/lib/DebugInfo/DWARFUnit.h index 528bfbbf89b..9762f65491b 100644 --- a/lib/DebugInfo/DWARFUnit.h +++ b/lib/DebugInfo/DWARFUnit.h @@ -53,6 +53,10 @@ class DWARFUnitSection final : public SmallVector, 1>, }; public: + DWARFUnitSection() {} + DWARFUnitSection(DWARFUnitSection &&DUS) : + SmallVector, 1>(std::move(DUS)) {} + typedef llvm::SmallVectorImpl> UnitVector; typedef typename UnitVector::iterator iterator; typedef llvm::iterator_range iterator_range; -- 2.34.1