From 72df68895059f778ae2f6b1264fc98415133b66e Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 13 Mar 2014 07:52:54 +0000 Subject: [PATCH] [C++11] Convert DWARF parser to range-based for loops git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203766 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../DWARFAbbreviationDeclaration.cpp | 19 +++-- lib/DebugInfo/DWARFAbbreviationDeclaration.h | 16 ++-- lib/DebugInfo/DWARFContext.cpp | 68 +++++++-------- lib/DebugInfo/DWARFContext.h | 84 +++++++++++-------- lib/DebugInfo/DWARFDebugAbbrev.cpp | 19 ++--- lib/DebugInfo/DWARFDebugArangeSet.cpp | 8 +- lib/DebugInfo/DWARFDebugArangeSet.h | 13 +-- lib/DebugInfo/DWARFDebugAranges.cpp | 23 ++--- lib/DebugInfo/DWARFDebugFrame.cpp | 15 ++-- lib/DebugInfo/DWARFDebugFrame.h | 3 +- lib/DebugInfo/DWARFDebugInfoEntry.cpp | 11 +-- lib/DebugInfo/DWARFDebugInfoEntry.h | 3 - lib/DebugInfo/DWARFDebugLine.cpp | 6 +- lib/DebugInfo/DWARFDebugLoc.cpp | 16 ++-- lib/DebugInfo/DWARFDebugRangeList.cpp | 13 ++- lib/DebugInfo/DWARFUnit.cpp | 9 +- 16 files changed, 162 insertions(+), 164 deletions(-) diff --git a/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp b/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp index f46fd58a63b..b9805af54fa 100644 --- a/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp +++ b/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp @@ -18,7 +18,7 @@ void DWARFAbbreviationDeclaration::clear() { Code = 0; Tag = 0; HasChildren = false; - Attributes.clear(); + AttributeSpecs.clear(); } DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() { @@ -51,7 +51,8 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) { } if (Attr == 0 && Form == 0) break; - Attributes.push_back(AttributeSpec(Attr, Form)); + AttributeSpec AS = {Attr, Form}; + AttributeSpecs.push_back(AS); } if (Tag == 0) { @@ -69,19 +70,19 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { else OS << format("DW_TAG_Unknown_%x", getTag()); OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n'; - for (unsigned i = 0, e = Attributes.size(); i != e; ++i) { + for (const AttributeSpec &Spec : AttributeSpecs) { OS << '\t'; - const char *attrString = AttributeString(Attributes[i].Attr); + const char *attrString = AttributeString(Spec.Attr); if (attrString) OS << attrString; else - OS << format("DW_AT_Unknown_%x", Attributes[i].Attr); + OS << format("DW_AT_Unknown_%x", Spec.Attr); OS << '\t'; - const char *formString = FormEncodingString(Attributes[i].Form); + const char *formString = FormEncodingString(Spec.Form); if (formString) OS << formString; else - OS << format("DW_FORM_Unknown_%x", Attributes[i].Form); + OS << format("DW_FORM_Unknown_%x", Spec.Form); OS << '\n'; } OS << '\n'; @@ -89,8 +90,8 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { uint32_t DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const { - for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) { - if (Attributes[i].Attr == attr) + for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) { + if (AttributeSpecs[i].Attr == attr) return i; } return -1U; diff --git a/lib/DebugInfo/DWARFAbbreviationDeclaration.h b/lib/DebugInfo/DWARFAbbreviationDeclaration.h index e9b072eb86d..f575f323afc 100644 --- a/lib/DebugInfo/DWARFAbbreviationDeclaration.h +++ b/lib/DebugInfo/DWARFAbbreviationDeclaration.h @@ -23,23 +23,27 @@ class DWARFAbbreviationDeclaration { bool HasChildren; struct AttributeSpec { - AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {} uint16_t Attr; uint16_t Form; }; - SmallVector Attributes; + typedef SmallVector AttributeSpecVector; + AttributeSpecVector AttributeSpecs; public: DWARFAbbreviationDeclaration(); uint32_t getCode() const { return Code; } uint32_t getTag() const { return Tag; } bool hasChildren() const { return HasChildren; } - uint32_t getNumAttributes() const { return Attributes.size(); } - uint16_t getAttrByIndex(uint32_t idx) const { - return idx < Attributes.size() ? Attributes[idx].Attr : 0; + + typedef iterator_range + attr_iterator_range; + + attr_iterator_range attributes() const { + return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end()); } + uint16_t getFormByIndex(uint32_t idx) const { - return idx < Attributes.size() ? Attributes[idx].Form : 0; + return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0; } uint32_t findAttributeIndex(uint16_t attr) const; diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 37e86bd92d3..119e3602d0e 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -75,29 +75,29 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) { if (DumpType == DIDT_All || DumpType == DIDT_Info) { OS << "\n.debug_info contents:\n"; - for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) - getCompileUnitAtIndex(i)->dump(OS); + for (const auto &CU : compile_units()) + CU->dump(OS); } if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) && getNumDWOCompileUnits()) { OS << "\n.debug_info.dwo contents:\n"; - for (unsigned i = 0, e = getNumDWOCompileUnits(); i != e; ++i) - getDWOCompileUnitAtIndex(i)->dump(OS); + for (const auto &DWOCU : dwo_compile_units()) + DWOCU->dump(OS); } if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) { OS << "\n.debug_types contents:\n"; - for (unsigned i = 0, e = getNumTypeUnits(); i != e; ++i) - getTypeUnitAtIndex(i)->dump(OS); + for (const auto &TU : type_units()) + TU->dump(OS); } - if (DumpType == DIDT_All || DumpType == DIDT_TypesDwo) - if (getNumDWOTypeUnits()) { - OS << "\n.debug_types.dwo contents:\n"; - for (unsigned i = 0, e = getNumDWOTypeUnits(); i != e; ++i) - getDWOTypeUnitAtIndex(i)->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); + } if (DumpType == DIDT_All || DumpType == DIDT_Loc) { OS << "\n.debug_loc contents:\n"; @@ -121,12 +121,11 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) { uint8_t savedAddressByteSize = 0; if (DumpType == DIDT_All || DumpType == DIDT_Line) { OS << "\n.debug_line contents:\n"; - for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) { - DWARFCompileUnit *cu = getCompileUnitAtIndex(i); - savedAddressByteSize = cu->getAddressByteSize(); + for (const auto &CU : compile_units()) { + savedAddressByteSize = CU->getAddressByteSize(); unsigned stmtOffset = - cu->getCompileUnitDIE()->getAttributeValueAsSectionOffset( - cu, DW_AT_stmt_list, -1U); + CU->getCompileUnitDIE()->getAttributeValueAsSectionOffset( + CU, DW_AT_stmt_list, -1U); if (stmtOffset != -1U) { DataExtractor lineData(getLineSection().Data, isLittleEndian(), savedAddressByteSize); @@ -297,6 +296,8 @@ DWARFContext::getLineTableForCompileUnit(DWARFCompileUnit *cu) { } void DWARFContext::parseCompileUnits() { + if (!CUs.empty()) + return; uint32_t offset = 0; const DataExtractor &DIData = DataExtractor(getInfoSection().Data, isLittleEndian(), 0); @@ -314,17 +315,17 @@ void DWARFContext::parseCompileUnits() { } void DWARFContext::parseTypeUnits() { - const TypeSectionMap &Sections = getTypesSections(); - for (TypeSectionMap::const_iterator I = Sections.begin(), E = Sections.end(); - I != E; ++I) { + if (!TUs.empty()) + return; + for (const auto &I : getTypesSections()) { uint32_t offset = 0; const DataExtractor &DIData = - DataExtractor(I->second.Data, isLittleEndian(), 0); + DataExtractor(I.second.Data, isLittleEndian(), 0); while (DIData.isValidOffset(offset)) { std::unique_ptr TU(new DWARFTypeUnit( - getDebugAbbrev(), I->second.Data, getAbbrevSection(), + getDebugAbbrev(), I.second.Data, getAbbrevSection(), getRangeSection(), getStringSection(), StringRef(), getAddrSection(), - &I->second.Relocs, isLittleEndian())); + &I.second.Relocs, isLittleEndian())); if (!TU->extract(DIData, &offset)) break; TUs.push_back(TU.release()); @@ -334,6 +335,8 @@ void DWARFContext::parseTypeUnits() { } void DWARFContext::parseDWOCompileUnits() { + if (!DWOCUs.empty()) + return; uint32_t offset = 0; const DataExtractor &DIData = DataExtractor(getInfoDWOSection().Data, isLittleEndian(), 0); @@ -352,17 +355,17 @@ void DWARFContext::parseDWOCompileUnits() { } void DWARFContext::parseDWOTypeUnits() { - const TypeSectionMap &Sections = getTypesDWOSections(); - for (TypeSectionMap::const_iterator I = Sections.begin(), E = Sections.end(); - I != E; ++I) { + if (!DWOTUs.empty()) + return; + for (const auto &I : getTypesDWOSections()) { uint32_t offset = 0; const DataExtractor &DIData = - DataExtractor(I->second.Data, isLittleEndian(), 0); + DataExtractor(I.second.Data, isLittleEndian(), 0); while (DIData.isValidOffset(offset)) { std::unique_ptr TU(new DWARFTypeUnit( - getDebugAbbrevDWO(), I->second.Data, getAbbrevDWOSection(), + getDebugAbbrevDWO(), I.second.Data, getAbbrevDWOSection(), getRangeDWOSection(), getStringDWOSection(), - getStringOffsetDWOSection(), getAddrSection(), &I->second.Relocs, + getStringOffsetDWOSection(), getAddrSection(), &I.second.Relocs, isLittleEndian())); if (!TU->extract(DIData, &offset)) break; @@ -388,8 +391,7 @@ namespace { } DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) { - if (CUs.empty()) - parseCompileUnits(); + parseCompileUnits(); DWARFCompileUnit **CU = std::lower_bound(CUs.begin(), CUs.end(), Offset, OffsetComparator()); @@ -522,9 +524,7 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address, if (!LineTable->lookupAddressRange(Address, Size, RowVector)) return Lines; - uint32_t NumRows = RowVector.size(); - for (uint32_t i = 0; i < NumRows; ++i) { - uint32_t RowIndex = RowVector[i]; + for (uint32_t RowIndex : RowVector) { // Take file number and line/column from the row. const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex]; std::string FileName = ""; diff --git a/lib/DebugInfo/DWARFContext.h b/lib/DebugInfo/DWARFContext.h index 96eaa70bd56..42d34b18f46 100644 --- a/lib/DebugInfo/DWARFContext.h +++ b/lib/DebugInfo/DWARFContext.h @@ -28,33 +28,38 @@ namespace llvm { /// information parsing. The actual data is supplied through pure virtual /// methods that a concrete implementation provides. class DWARFContext : public DIContext { - SmallVector CUs; - SmallVector TUs; + typedef SmallVector CUVector; + typedef SmallVector TUVector; + + CUVector CUs; + TUVector TUs; std::unique_ptr Abbrev; std::unique_ptr Loc; std::unique_ptr Aranges; std::unique_ptr Line; std::unique_ptr DebugFrame; - SmallVector DWOCUs; - SmallVector DWOTUs; + CUVector DWOCUs; + TUVector DWOTUs; std::unique_ptr AbbrevDWO; DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; - /// Read compile units from the debug_info section and store them in CUs. + /// Read compile units from the debug_info section (if necessary) + /// and store them in CUs. void parseCompileUnits(); - /// Read type units from the debug_types sections and store them in CUs. + /// Read type units from the debug_types sections (if necessary) + /// and store them in TUs. void parseTypeUnits(); - /// Read compile units from the debug_info.dwo section and store them in - /// DWOCUs. + /// Read compile units from the debug_info.dwo section (if necessary) + /// and store them in DWOCUs. void parseDWOCompileUnits(); - /// Read type units from the debug_types.dwo section and store them in - /// DWOTUs. + /// Read type units from the debug_types.dwo section (if necessary) + /// and store them in DWOTUs. void parseDWOTypeUnits(); public: @@ -72,62 +77,69 @@ public: void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override; + typedef iterator_range cu_iterator_range; + typedef iterator_range tu_iterator_range; + + /// Get compile units in this context. + cu_iterator_range compile_units() { + parseCompileUnits(); + return cu_iterator_range(CUs.begin(), CUs.end()); + } + + /// Get type units in this context. + tu_iterator_range type_units() { + parseTypeUnits(); + return tu_iterator_range(TUs.begin(), TUs.end()); + } + + /// Get compile units in the DWO context. + cu_iterator_range dwo_compile_units() { + parseDWOCompileUnits(); + return cu_iterator_range(DWOCUs.begin(), DWOCUs.end()); + } + + /// Get type units in the DWO context. + tu_iterator_range dwo_type_units() { + parseDWOTypeUnits(); + return tu_iterator_range(DWOTUs.begin(), DWOTUs.end()); + } + /// Get the number of compile units in this context. unsigned getNumCompileUnits() { - if (CUs.empty()) - parseCompileUnits(); + parseCompileUnits(); return CUs.size(); } /// Get the number of compile units in this context. unsigned getNumTypeUnits() { - if (TUs.empty()) - parseTypeUnits(); + parseTypeUnits(); return TUs.size(); } /// Get the number of compile units in the DWO context. unsigned getNumDWOCompileUnits() { - if (DWOCUs.empty()) - parseDWOCompileUnits(); + parseDWOCompileUnits(); return DWOCUs.size(); } /// Get the number of compile units in the DWO context. unsigned getNumDWOTypeUnits() { - if (DWOTUs.empty()) - parseDWOTypeUnits(); + parseDWOTypeUnits(); return DWOTUs.size(); } /// Get the compile unit at the specified index for this compile unit. DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { - if (CUs.empty()) - parseCompileUnits(); + parseCompileUnits(); return CUs[index]; } - /// Get the type unit at the specified index for this compile unit. - DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) { - if (TUs.empty()) - parseTypeUnits(); - return TUs[index]; - } - /// Get the compile unit at the specified index for the DWO compile units. DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { - if (DWOCUs.empty()) - parseDWOCompileUnits(); + parseDWOCompileUnits(); return DWOCUs[index]; } - /// Get the type unit at the specified index for the DWO type units. - DWARFTypeUnit *getDWOTypeUnitAtIndex(unsigned index) { - if (DWOTUs.empty()) - parseDWOTypeUnits(); - return DWOTUs[index]; - } - /// Get a pointer to the parsed DebugAbbrev object. const DWARFDebugAbbrev *getDebugAbbrev(); diff --git a/lib/DebugInfo/DWARFDebugAbbrev.cpp b/lib/DebugInfo/DWARFDebugAbbrev.cpp index 6e6c37e3094..fd5f5e95fc1 100644 --- a/lib/DebugInfo/DWARFDebugAbbrev.cpp +++ b/lib/DebugInfo/DWARFDebugAbbrev.cpp @@ -33,19 +33,17 @@ bool DWARFAbbreviationDeclarationSet::extract(DataExtractor data, } void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const { - for (unsigned i = 0, e = Decls.size(); i != e; ++i) - Decls[i].dump(OS); + for (const auto &Decl : Decls) + Decl.dump(OS); } const DWARFAbbreviationDeclaration* DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(uint32_t abbrCode) const { if (IdxOffset == UINT32_MAX) { - DWARFAbbreviationDeclarationCollConstIter pos; - DWARFAbbreviationDeclarationCollConstIter end = Decls.end(); - for (pos = Decls.begin(); pos != end; ++pos) { - if (pos->getCode() == abbrCode) - return &(*pos); + for (const auto &Decl : Decls) { + if (Decl.getCode() == abbrCode) + return &Decl; } } else { uint32_t idx = abbrCode - IdxOffset; @@ -81,10 +79,9 @@ void DWARFDebugAbbrev::dump(raw_ostream &OS) const { return; } - DWARFAbbreviationDeclarationCollMapConstIter pos; - for (pos = AbbrevCollMap.begin(); pos != AbbrevCollMap.end(); ++pos) { - OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", pos->first); - pos->second.dump(OS); + for (const auto &I : AbbrevCollMap) { + OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first); + I.second.dump(OS); } } diff --git a/lib/DebugInfo/DWARFDebugArangeSet.cpp b/lib/DebugInfo/DWARFDebugArangeSet.cpp index 229376e4a1c..8459cb13789 100644 --- a/lib/DebugInfo/DWARFDebugArangeSet.cpp +++ b/lib/DebugInfo/DWARFDebugArangeSet.cpp @@ -94,9 +94,9 @@ void DWARFDebugArangeSet::dump(raw_ostream &OS) const { HeaderData.CuOffset, HeaderData.AddrSize, HeaderData.SegSize); const uint32_t hex_width = HeaderData.AddrSize * 2; - for (DescriptorConstIter pos = ArangeDescriptors.begin(), - end = ArangeDescriptors.end(); pos != end; ++pos) - OS << format("[0x%*.*" PRIx64 " -", hex_width, hex_width, pos->Address) + for (const auto &Desc : ArangeDescriptors) { + OS << format("[0x%*.*" PRIx64 " -", hex_width, hex_width, Desc.Address) << format(" 0x%*.*" PRIx64 ")\n", - hex_width, hex_width, pos->getEndAddress()); + hex_width, hex_width, Desc.getEndAddress()); + } } diff --git a/lib/DebugInfo/DWARFDebugArangeSet.h b/lib/DebugInfo/DWARFDebugArangeSet.h index 49a713201d1..c18b3c5e504 100644 --- a/lib/DebugInfo/DWARFDebugArangeSet.h +++ b/lib/DebugInfo/DWARFDebugArangeSet.h @@ -10,6 +10,7 @@ #ifndef LLVM_DEBUGINFO_DWARFDEBUGARANGESET_H #define LLVM_DEBUGINFO_DWARFDEBUGARANGESET_H +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/DataExtractor.h" #include @@ -44,7 +45,7 @@ public: private: typedef std::vector DescriptorColl; - typedef DescriptorColl::const_iterator DescriptorConstIter; + typedef iterator_range desc_iterator_range; uint32_t Offset; Header HeaderData; @@ -57,12 +58,12 @@ public: void dump(raw_ostream &OS) const; uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; } - uint32_t getNumDescriptors() const { return ArangeDescriptors.size(); } - const Descriptor *getDescriptor(uint32_t i) const { - if (i < ArangeDescriptors.size()) - return &ArangeDescriptors[i]; - return NULL; + + desc_iterator_range descriptors() const { + return desc_iterator_range(ArangeDescriptors.begin(), + ArangeDescriptors.end()); } + uint32_t getNumDescriptors() const { return ArangeDescriptors.size(); } }; } diff --git a/lib/DebugInfo/DWARFDebugAranges.cpp b/lib/DebugInfo/DWARFDebugAranges.cpp index 591d4bde712..dfab7886b57 100644 --- a/lib/DebugInfo/DWARFDebugAranges.cpp +++ b/lib/DebugInfo/DWARFDebugAranges.cpp @@ -33,15 +33,12 @@ void DWARFDebugAranges::extract(DataExtractor DebugArangesData) { return; Aranges.reserve(TotalRanges); - for (RangeSetColl::const_iterator I = Sets.begin(), E = Sets.end(); I != E; - ++I) { - uint32_t CUOffset = I->getCompileUnitDIEOffset(); + for (const auto &I : Sets) { + uint32_t CUOffset = I.getCompileUnitDIEOffset(); - for (uint32_t i = 0, n = I->getNumDescriptors(); i < n; ++i) { - const DWARFDebugArangeSet::Descriptor *ArangeDescPtr = - I->getDescriptor(i); - uint64_t LowPC = ArangeDescPtr->Address; - uint64_t HighPC = LowPC + ArangeDescPtr->Length; + for (const auto &Desc : I.descriptors()) { + uint64_t LowPC = Desc.Address; + uint64_t HighPC = Desc.getEndAddress(); appendRange(CUOffset, LowPC, HighPC); } } @@ -59,12 +56,10 @@ void DWARFDebugAranges::generate(DWARFContext *CTX) { // Generate aranges from DIEs: even if .debug_aranges section is present, // it may describe only a small subset of compilation units, so we need to // manually build aranges for the rest of them. - for (uint32_t i = 0, n = CTX->getNumCompileUnits(); i < n; ++i) { - if (DWARFCompileUnit *CU = CTX->getCompileUnitAtIndex(i)) { - uint32_t CUOffset = CU->getOffset(); - if (ParsedCUOffsets.insert(CUOffset).second) - CU->buildAddressRangeTable(this, true, CUOffset); - } + for (const auto &CU : CTX->compile_units()) { + uint32_t CUOffset = CU->getOffset(); + if (ParsedCUOffsets.insert(CUOffset).second) + CU->buildAddressRangeTable(this, true, CUOffset); } sortAndMinimize(); diff --git a/lib/DebugInfo/DWARFDebugFrame.cpp b/lib/DebugInfo/DWARFDebugFrame.cpp index b268f300155..5bf7b070b8e 100644 --- a/lib/DebugInfo/DWARFDebugFrame.cpp +++ b/lib/DebugInfo/DWARFDebugFrame.cpp @@ -186,10 +186,8 @@ void FrameEntry::parseInstructions(uint32_t *Offset, uint32_t EndOffset) { void FrameEntry::dumpInstructions(raw_ostream &OS) const { // TODO: at the moment only instruction names are dumped. Expand this to // dump operands as well. - for (std::vector::const_iterator I = Instructions.begin(), - E = Instructions.end(); - I != E; ++I) { - uint8_t Opcode = I->Opcode; + for (const auto &Instr : Instructions) { + uint8_t Opcode = Instr.Opcode; if (Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK) Opcode &= DWARF_CFI_PRIMARY_OPCODE_MASK; OS << " " << CallFrameString(Opcode) << ":\n"; @@ -289,9 +287,8 @@ DWARFDebugFrame::DWARFDebugFrame() { DWARFDebugFrame::~DWARFDebugFrame() { - for (EntryVector::iterator I = Entries.begin(), E = Entries.end(); - I != E; ++I) { - delete *I; + for (const auto &Entry : Entries) { + delete Entry; } } @@ -381,9 +378,7 @@ void DWARFDebugFrame::parse(DataExtractor Data) { void DWARFDebugFrame::dump(raw_ostream &OS) const { OS << "\n"; - for (EntryVector::const_iterator I = Entries.begin(), E = Entries.end(); - I != E; ++I) { - FrameEntry *Entry = *I; + for (const auto &Entry : Entries) { Entry->dumpHeader(OS); Entry->dumpInstructions(OS); OS << "\n"; diff --git a/lib/DebugInfo/DWARFDebugFrame.h b/lib/DebugInfo/DWARFDebugFrame.h index 48b8d63a5a6..7683849b4a1 100644 --- a/lib/DebugInfo/DWARFDebugFrame.h +++ b/lib/DebugInfo/DWARFDebugFrame.h @@ -42,5 +42,4 @@ private: } // namespace llvm -#endif - +#endif diff --git a/lib/DebugInfo/DWARFDebugInfoEntry.cpp b/lib/DebugInfo/DWARFDebugInfoEntry.cpp index babfd2ece06..bde25ec82d1 100644 --- a/lib/DebugInfo/DWARFDebugInfoEntry.cpp +++ b/lib/DebugInfo/DWARFDebugInfoEntry.cpp @@ -40,11 +40,8 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, const DWARFUnit *u, AbbrevDecl->hasChildren() ? '*' : ' '); // Dump all data in the DIE for the attributes. - const uint32_t numAttributes = AbbrevDecl->getNumAttributes(); - for (uint32_t i = 0; i != numAttributes; ++i) { - uint16_t attr = AbbrevDecl->getAttrByIndex(i); - uint16_t form = AbbrevDecl->getFormByIndex(i); - dumpAttribute(OS, u, &offset, attr, form, indent); + for (const auto &AttrSpec : AbbrevDecl->attributes()) { + dumpAttribute(OS, u, &offset, AttrSpec.Attr, AttrSpec.Form, indent); } const DWARFDebugInfoEntryMinimal *child = getFirstChild(); @@ -116,8 +113,8 @@ bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U, assert(FixedFormSizes.size() > 0); // Skip all data in the .debug_info for the attributes - for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) { - uint16_t Form = AbbrevDecl->getFormByIndex(i); + for (const auto &AttrSpec : AbbrevDecl->attributes()) { + uint16_t Form = AttrSpec.Form; uint8_t FixedFormSize = (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0; diff --git a/lib/DebugInfo/DWARFDebugInfoEntry.h b/lib/DebugInfo/DWARFDebugInfoEntry.h index aa61056332e..f30e5310451 100644 --- a/lib/DebugInfo/DWARFDebugInfoEntry.h +++ b/lib/DebugInfo/DWARFDebugInfoEntry.h @@ -60,9 +60,6 @@ public: bool isSubroutineDIE() const; uint32_t getOffset() const { return Offset; } - uint32_t getNumAttributes() const { - return !isNULL() ? AbbrevDecl->getNumAttributes() : 0; - } bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); } // We know we are kept in a vector of contiguous entries, so we know diff --git a/lib/DebugInfo/DWARFDebugLine.cpp b/lib/DebugInfo/DWARFDebugLine.cpp index 83490b1d3ff..43d976480c7 100644 --- a/lib/DebugInfo/DWARFDebugLine.cpp +++ b/lib/DebugInfo/DWARFDebugLine.cpp @@ -90,9 +90,9 @@ void DWARFDebugLine::LineTable::dump(raw_ostream &OS) const { OS << "Address Line Column File ISA Discriminator Flags\n" << "------------------ ------ ------ ------ --- ------------- " "-------------\n"; - for (std::vector::const_iterator pos = Rows.begin(), - end = Rows.end(); pos != end; ++pos) - pos->dump(OS); + for (const Row &R : Rows) { + R.dump(OS); + } } } diff --git a/lib/DebugInfo/DWARFDebugLoc.cpp b/lib/DebugInfo/DWARFDebugLoc.cpp index 8fe7481bbfe..5f0ff0240da 100644 --- a/lib/DebugInfo/DWARFDebugLoc.cpp +++ b/lib/DebugInfo/DWARFDebugLoc.cpp @@ -15,19 +15,19 @@ using namespace llvm; void DWARFDebugLoc::dump(raw_ostream &OS) const { - for (LocationLists::const_iterator I = Locations.begin(), E = Locations.end(); I != E; ++I) { - OS << format("0x%8.8x: ", I->Offset); + for (const LocationList &L : Locations) { + OS << format("0x%8.8x: ", L.Offset); const unsigned Indent = 12; - for (SmallVectorImpl::const_iterator I2 = I->Entries.begin(), E2 = I->Entries.end(); I2 != E2; ++I2) { - if (I2 != I->Entries.begin()) + for (const Entry &E : L.Entries) { + if (&E != L.Entries.begin()) OS.indent(Indent); - OS << "Beginning address offset: " << format("0x%016" PRIx64, I2->Begin) + OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin) << '\n'; OS.indent(Indent) << " Ending address offset: " - << format("0x%016" PRIx64, I2->End) << '\n'; + << format("0x%016" PRIx64, E.End) << '\n'; OS.indent(Indent) << " Location description: "; - for (SmallVectorImpl::const_iterator I3 = I2->Loc.begin(), E3 = I2->Loc.end(); I3 != E3; ++I3) { - OS << format("%2.2x ", *I3); + for (unsigned char Loc : E.Loc) { + OS << format("%2.2x ", Loc); } OS << "\n\n"; } diff --git a/lib/DebugInfo/DWARFDebugRangeList.cpp b/lib/DebugInfo/DWARFDebugRangeList.cpp index 1806beee728..aa2a2be5990 100644 --- a/lib/DebugInfo/DWARFDebugRangeList.cpp +++ b/lib/DebugInfo/DWARFDebugRangeList.cpp @@ -45,22 +45,21 @@ bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) { } void DWARFDebugRangeList::dump(raw_ostream &OS) const { - for (int i = 0, n = Entries.size(); i != n; ++i) { + for (const RangeListEntry &RLE : Entries) { const char *format_str = (AddressSize == 4 ? "%08x %08" PRIx64 " %08" PRIx64 "\n" : "%08x %016" PRIx64 " %016" PRIx64 "\n"); - OS << format(format_str, Offset, Entries[i].StartAddress, - Entries[i].EndAddress); + OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress); } OS << format("%08x \n", Offset); } bool DWARFDebugRangeList::containsAddress(uint64_t BaseAddress, uint64_t Address) const { - for (int i = 0, n = Entries.size(); i != n; ++i) { - if (Entries[i].isBaseAddressSelectionEntry(AddressSize)) - BaseAddress = Entries[i].EndAddress; - else if (Entries[i].containsAddress(BaseAddress, Address)) + for (const RangeListEntry &RLE : Entries) { + if (RLE.isBaseAddressSelectionEntry(AddressSize)) + BaseAddress = RLE.EndAddress; + else if (RLE.containsAddress(BaseAddress, Address)) return true; } return false; diff --git a/lib/DebugInfo/DWARFUnit.cpp b/lib/DebugInfo/DWARFUnit.cpp index 732fb82e73e..316c208479a 100644 --- a/lib/DebugInfo/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARFUnit.cpp @@ -331,11 +331,12 @@ DWARFUnit::buildAddressRangeTable(DWARFDebugAranges *debug_aranges, const DWARFDebugInfoEntryMinimal * DWARFUnit::getSubprogramForAddress(uint64_t Address) { extractDIEsIfNeeded(false); - for (size_t i = 0, n = DieArray.size(); i != n; i++) - if (DieArray[i].isSubprogramDIE() && - DieArray[i].addressRangeContainsAddress(this, Address)) { - return &DieArray[i]; + for (const DWARFDebugInfoEntryMinimal &DIE : DieArray) { + if (DIE.isSubprogramDIE() && + DIE.addressRangeContainsAddress(this, Address)) { + return &DIE; } + } return 0; }