Index: lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -39,7 +39,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) override; void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref callback) override; Index: lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -75,13 +75,14 @@ } void AppleDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref callback) { + DWARFUnit &cu, llvm::function_ref callback) { if (!m_apple_names_up) return; + const DWARFUnit &full_unit = cu.GetNonSkeletonUnit(); DWARFMappedHash::DIEInfoArray hash_data; - m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), cu.GetNextUnitOffset(), - hash_data); + m_apple_names_up->AppendAllDIEsInRange( + full_unit.GetOffset(), full_unit.GetNextUnitOffset(), hash_data); DWARFMappedHash::ExtractDIEArray(hash_data, DIERefCallback(callback)); } Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -35,7 +35,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) = 0; virtual void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) = 0; virtual void GetObjCMethods(ConstString class_name, Index: lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -32,7 +32,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) override; void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) override; void GetObjCMethods(ConstString class_name, Index: lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -123,8 +123,8 @@ } void DebugNamesDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref callback) { - uint64_t cu_offset = cu.GetOffset(); + DWARFUnit &cu, llvm::function_ref callback) { + uint64_t cu_offset = cu.GetNonSkeletonUnit().GetOffset(); for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { uint64_t entry_offset = nte.getEntryOffset(); Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -22,7 +22,8 @@ ManualDWARFIndex(Module &module, SymbolFileDWARF &dwarf, llvm::DenseSet units_to_avoid = {}) : DWARFIndex(module), m_dwarf(&dwarf), - m_units_to_avoid(std::move(units_to_avoid)) {} + m_units_to_avoid(std::move(units_to_avoid)), + m_has_indexed_type_units(false) {} void Preload() override { Index(); } @@ -33,7 +34,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) override; void - GetGlobalVariables(const DWARFUnit &unit, + GetGlobalVariables(DWARFUnit &unit, llvm::function_ref callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref callback) override; @@ -67,6 +68,7 @@ NameToDIE namespaces; }; void Index(); + void IndexImpl(DWARFUnit *unit_to_index); void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet &set); static void IndexUnitImpl(DWARFUnit &unit, @@ -78,6 +80,7 @@ SymbolFileDWARF *m_dwarf; /// Which dwarf units should we skip while building the index. llvm::DenseSet m_units_to_avoid; + bool m_has_indexed_type_units; IndexSet m_set; }; Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -23,12 +23,16 @@ using namespace lldb_private; using namespace lldb; -void ManualDWARFIndex::Index() { +void ManualDWARFIndex::Index() { IndexImpl(nullptr); } + +void ManualDWARFIndex::IndexImpl(DWARFUnit *unit_to_index) { if (!m_dwarf) return; SymbolFileDWARF &main_dwarf = *m_dwarf; - m_dwarf = nullptr; + + if (!unit_to_index) + m_dwarf = nullptr; LLDB_SCOPED_TIMERF("%p", static_cast(&main_dwarf)); @@ -45,10 +49,17 @@ // IndexUnit. for (size_t U = 0; U < main_info.GetNumUnits(); ++U) { DWARFUnit *unit = main_info.GetUnitAtIndex(U); - if (unit && m_units_to_avoid.count(unit->GetOffset()) == 0) - units_to_index.push_back(unit); + if (unit && m_units_to_avoid.count(unit->GetOffset()) == 0) { + if (!unit_to_index || unit->GetOffset() == unit_to_index->GetOffset()) + units_to_index.push_back(unit); + } } - if (dwp_info && dwp_info->ContainsTypeUnits()) { + + if (unit_to_index && !units_to_index.empty()) + m_units_to_avoid.insert(unit_to_index->GetOffset()); // Don't index this again + + if (!m_has_indexed_type_units && dwp_info && dwp_info->ContainsTypeUnits()) { + m_has_indexed_type_units = true; for (size_t U = 0; U < dwp_info->GetNumUnits(); ++U) { if (auto *tu = llvm::dyn_cast(dwp_info->GetUnitAtIndex(U))) units_to_index.push_back(tu); @@ -358,9 +369,10 @@ } void ManualDWARFIndex::GetGlobalVariables( - const DWARFUnit &unit, llvm::function_ref callback) { - Index(); - m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback)); + DWARFUnit &unit, llvm::function_ref callback) { + IndexImpl(&unit); + m_set.globals.FindAllEntriesForUnit(unit.GetNonSkeletonUnit(), + DIERefCallback(callback)); } void ManualDWARFIndex::GetObjCMethods( Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3020,16 +3020,14 @@ variables = std::make_shared(); sc.comp_unit->SetVariableList(variables); - m_index->GetGlobalVariables( - dwarf_cu->GetNonSkeletonUnit(), [&](DWARFDIE die) { - VariableSP var_sp( - ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); - if (var_sp) { - variables->AddVariableIfUnique(var_sp); - ++vars_added; - } - return true; - }); + m_index->GetGlobalVariables(*dwarf_cu, [&](DWARFDIE die) { + VariableSP var_sp(ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); + if (var_sp) { + variables->AddVariableIfUnique(var_sp); + ++vars_added; + } + return true; + }); } return vars_added; }