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() { @@ -163,10 +164,12 @@ } /// 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(), isCompileUnit); + } - /// Get type units in this context. - unit_iterator_range type_units() { return types_section_units(); } + // If you want type_units(), it'll need to be a concat iterator of a filter of + // TUs in info_section + all the (all type) units in types_section /// Get all normal compile/type units in this context. unit_iterator_range normal_units() { @@ -189,10 +192,13 @@ } /// 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(), isCompileUnit); + } - /// Get type units in the DWO context. - unit_iterator_range dwo_type_units() { return dwo_types_section_units(); } + // If you want dwo_type_units(), it'll need to be a concat iterator of a + // filter of TUs in dwo_info_section + all the (all type) units in + // dwo_types_section. /// Get all units in the DWO context. unit_iterator_range dwo_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 isCompileUnit(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(), isCompileUnit)); + DWARFUnit *getUnitForOffset(uint64_t Offset) const; DWARFUnit *getUnitForIndexEntry(const DWARFUnitIndex::Entry &E); @@ -524,6 +529,10 @@ bool parseDWO(); }; +inline bool isCompileUnit(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;