Index: lib/DebugInfo/DWARFContext.h =================================================================== --- lib/DebugInfo/DWARFContext.h +++ lib/DebugInfo/DWARFContext.h @@ -81,61 +81,61 @@ /// Get compile units in this context. cu_iterator_range compile_units() { parseCompileUnits(); - return cu_iterator_range(CUs.begin(), CUs.end()); + return CUs.Units(); } /// Get type units in this context. tu_iterator_range type_units() { parseTypeUnits(); - return tu_iterator_range(TUs.begin(), TUs.end()); + return TUs.Units(); } /// Get compile units in the DWO context. cu_iterator_range dwo_compile_units() { parseDWOCompileUnits(); - return cu_iterator_range(DWOCUs.begin(), DWOCUs.end()); + return DWOCUs.Units(); } /// Get type units in the DWO context. tu_iterator_range dwo_type_units() { parseDWOTypeUnits(); - return tu_iterator_range(DWOTUs.begin(), DWOTUs.end()); + return DWOTUs.Units(); } /// Get the number of compile units in this context. unsigned getNumCompileUnits() { parseCompileUnits(); - return CUs.size(); + return CUs.getNumUnits(); } /// Get the number of compile units in this context. unsigned getNumTypeUnits() { parseTypeUnits(); - return TUs.size(); + return TUs.getNumUnits(); } /// Get the number of compile units in the DWO context. unsigned getNumDWOCompileUnits() { parseDWOCompileUnits(); - return DWOCUs.size(); + return DWOCUs.getNumUnits(); } /// Get the number of compile units in the DWO context. unsigned getNumDWOTypeUnits() { parseDWOTypeUnits(); - return DWOTUs.size(); + return DWOTUs.getNumUnits(); } /// Get the compile unit at the specified index for this compile unit. DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { parseCompileUnits(); - return CUs[index].get(); + return CUs.getUnitAtIndex(index); } /// Get the compile unit at the specified index for the DWO compile units. DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { parseDWOCompileUnits(); - return DWOCUs[index].get(); + return DWOCUs.getUnitAtIndex(index); } /// Get a pointer to the parsed DebugAbbrev object. Index: lib/DebugInfo/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARFContext.cpp +++ lib/DebugInfo/DWARFContext.cpp @@ -247,7 +247,7 @@ Loc.reset(new DWARFDebugLoc(getLocSection().Relocs)); // assume all compile units have the same address byte size if (getNumCompileUnits()) - Loc->parse(LocData, getCompileUnitAtIndex(0)->getAddressByteSize()); + Loc->parse(LocData, CUs.getUnitAtIndex(0)->getAddressByteSize()); return Loc.get(); } @@ -312,7 +312,7 @@ } void DWARFContext::parseCompileUnits() { - if (!CUs.empty()) + if (CUs.getNumUnits() != 0) return; uint32_t offset = 0; const DataExtractor &DIData = DataExtractor(getInfoSection().Data, @@ -325,13 +325,13 @@ if (!CU->extract(DIData, &offset)) { break; } - CUs.push_back(std::move(CU)); - offset = CUs.back()->getNextUnitOffset(); + offset = CU->getNextUnitOffset(); + CUs.addUnit(std::move(CU)); } } void DWARFContext::parseTypeUnits() { - if (!TUs.empty()) + if (TUs.getNumUnits() != 0) return; for (const auto &I : getTypesSections()) { uint32_t offset = 0; @@ -344,14 +344,14 @@ &I.second.Relocs, isLittleEndian(), TUs)); if (!TU->extract(DIData, &offset)) break; - TUs.push_back(std::move(TU)); - offset = TUs.back()->getNextUnitOffset(); + offset = TU->getNextUnitOffset(); + TUs.addUnit(std::move(TU)); } } } void DWARFContext::parseDWOCompileUnits() { - if (!DWOCUs.empty()) + if (DWOCUs.getNumUnits() != 0) return; uint32_t offset = 0; const DataExtractor &DIData = @@ -364,13 +364,13 @@ if (!DWOCU->extract(DIData, &offset)) { break; } - DWOCUs.push_back(std::move(DWOCU)); - offset = DWOCUs.back()->getNextUnitOffset(); + offset = DWOCU->getNextUnitOffset(); + DWOCUs.addUnit(std::move(DWOCU)); } } void DWARFContext::parseDWOTypeUnits() { - if (!DWOTUs.empty()) + if (DWOTUs.getNumUnits() != 0) return; for (const auto &I : getTypesDWOSections()) { uint32_t offset = 0; @@ -383,8 +383,8 @@ &I.second.Relocs, isLittleEndian(), DWOTUs)); if (!TU->extract(DIData, &offset)) break; - DWOTUs.push_back(std::move(TU)); - offset = DWOTUs.back()->getNextUnitOffset(); + offset = TU->getNextUnitOffset(); + DWOTUs.addUnit(std::move(TU)); } } } Index: lib/DebugInfo/DWARFUnit.h =================================================================== --- lib/DebugInfo/DWARFUnit.h +++ lib/DebugInfo/DWARFUnit.h @@ -65,6 +65,22 @@ typedef typename UnitVector::iterator iterator; typedef llvm::iterator_range iterator_range; + iterator_range Units() { + return iterator_range(this->begin(), this->end()); + } + + unsigned getNumUnits() const { + return this->size(); + } + + UnitType *getUnitAtIndex(unsigned Index) { + return Index < this->size() ? (*this)[Index].get() : nullptr; + } + + void addUnit(std::unique_ptr &&Unit) { + this->push_back(std::move(Unit)); + } + UnitType *getUnitForOffset(uint32_t Offset) const { auto *CU = std::lower_bound(this->begin(), this->end(), Offset, UnitOffsetComparator());