diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -146,6 +146,7 @@ bool verify(raw_ostream &OS, DIDumpOptions DumpOpts = {}) override; using unit_iterator_range = DWARFUnitVector::iterator_range; + using compile_unit_range = DWARFUnitVector::compile_unit_range; /// Get units from .debug_info in this context. unit_iterator_range info_section_units() { @@ -162,8 +163,14 @@ NormalUnits.begin() + NormalUnits.getNumInfoUnits(), NormalUnits.end()); } + static bool CUOnly(const std::unique_ptr &U) { + return !U->isTypeUnit(); + } + /// Get compile units in this context. - unit_iterator_range compile_units() { return info_section_units(); } + compile_unit_range compile_units() { + return make_filter_range(info_section_units(), CUOnly); + } /// Get type units in this context. unit_iterator_range type_units() { return types_section_units(); } @@ -189,7 +196,9 @@ } /// Get compile units in the DWO context. - unit_iterator_range dwo_compile_units() { return dwo_info_section_units(); } + compile_unit_range dwo_compile_units() { + return make_filter_range(dwo_info_section_units(), CUOnly); + } /// Get type units in the DWO context. unit_iterator_range dwo_type_units() { return dwo_types_section_units(); } diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h @@ -110,7 +110,7 @@ /// Print the macro list found within the debug_macinfo/debug_macro section. void dump(raw_ostream &OS) const; - Error parseMacro(DWARFUnitVector::iterator_range Units, + Error parseMacro(DWARFUnitVector::compile_unit_range Units, DataExtractor StringExtractor, DWARFDataExtractor MacroData) { return parseImpl(Units, StringExtractor, MacroData, /*IsMacro=*/true); @@ -126,7 +126,7 @@ private: /// Parse the debug_macinfo/debug_macro section accessible via the 'MacroData' /// parameter. - Error parseImpl(Optional Units, + Error parseImpl(Optional Units, Optional StringExtractor, DWARFDataExtractor Data, bool IsMacro); }; diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -113,6 +113,8 @@ const DWARFUnitIndex &getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind); +bool isCU(const std::unique_ptr &U); + /// Describe a collection of units. Intended to hold all units either from /// .debug_info and .debug_types, or from .debug_info.dwo and .debug_types.dwo. class DWARFUnitVector final : public SmallVector, 1> { @@ -127,6 +129,9 @@ using iterator = typename UnitVector::iterator; using iterator_range = llvm::iterator_range; + using compile_unit_range = + decltype(make_filter_range(std::declval(), isCU)); + DWARFUnit *getUnitForOffset(uint64_t Offset) const; DWARFUnit *getUnitForIndexEntry(const DWARFUnitIndex::Entry &E); @@ -524,6 +529,10 @@ bool parseDWO(); }; +inline bool isCU(const std::unique_ptr &U) { + return !U->isTypeUnit(); +} + } // end namespace llvm #endif // LLVM_DEBUGINFO_DWARF_DWARFUNIT_H diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1998,6 +1998,6 @@ // first compile unit. In practice the address size field is repeated across // various DWARF headers (at least in version 5) to make it easier to dump // them independently, not to enable varying the address size. - unit_iterator_range CUs = compile_units(); + auto CUs = compile_units(); return CUs.empty() ? 0 : (*CUs.begin())->getAddressByteSize(); } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp @@ -102,7 +102,7 @@ } Error DWARFDebugMacro::parseImpl( - Optional Units, + Optional Units, Optional StringExtractor, DWARFDataExtractor Data, bool IsMacro) { uint64_t Offset = 0;