Author: Jan Kratochvil Date: 2020-04-15T15:12:59+02:00 New Revision: 9289f34390daa07b60af07fdd0576ad52001e0a5
URL: https://github.com/llvm/llvm-project/commit/9289f34390daa07b60af07fdd0576ad52001e0a5 DIFF: https://github.com/llvm/llvm-project/commit/9289f34390daa07b60af07fdd0576ad52001e0a5.diff LOG: Revert "[nfc] [lldb] Introduce DWARF callbacks" This reverts commit bd47c470d13b1c57ecf37c1faf0324833d3a4542. It broke Green Dragon, reason is unknown to me so far: http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/15323/consoleFull Differential Revision: https://reviews.llvm.org/D77327 Added: Modified: lldb/include/lldb/Core/UniqueCStringMap.h lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h Removed: ################################################################################ diff --git a/lldb/include/lldb/Core/UniqueCStringMap.h b/lldb/include/lldb/Core/UniqueCStringMap.h index e37027a0150a..7562ef4e9585 100644 --- a/lldb/include/lldb/Core/UniqueCStringMap.h +++ b/lldb/include/lldb/Core/UniqueCStringMap.h @@ -32,10 +32,6 @@ template <typename T> class UniqueCStringMap { T value; }; - typedef std::vector<Entry> collection; - typedef typename collection::iterator iterator; - typedef typename collection::const_iterator const_iterator; - // Call this function multiple times to add a bunch of entries to this map, // then later call UniqueCStringMap<T>::Sort() before doing any searches by // name. @@ -179,18 +175,6 @@ template <typename T> class UniqueCStringMap { } } - iterator begin() { return m_map.begin(); } - iterator end() { return m_map.end(); } - const_iterator begin() const { return m_map.begin(); } - const_iterator end() const { return m_map.end(); } - - // Range-based for loop for all entries of the specified ConstString name. - llvm::iterator_range<const_iterator> - equal_range(ConstString unique_cstr) const { - return llvm::make_range( - std::equal_range(m_map.begin(), m_map.end(), unique_cstr, Compare())); - }; - protected: struct Compare { bool operator()(const Entry &lhs, const Entry &rhs) { @@ -212,6 +196,9 @@ template <typename T> class UniqueCStringMap { return uintptr_t(lhs.GetCString()) < uintptr_t(rhs.GetCString()); } }; + typedef std::vector<Entry> collection; + typedef typename collection::iterator iterator; + typedef typename collection::const_iterator const_iterator; collection m_map; }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index 83ad8c555f80..027eb08e5621 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -52,60 +52,57 @@ std::unique_ptr<AppleDWARFIndex> AppleDWARFIndex::Create( return nullptr; } -void AppleDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetGlobalVariables(ConstString basename, DIEArray &offsets) { if (!m_apple_names_up) return; - m_apple_names_up->FindByName(basename.GetStringRef(), callback); + m_apple_names_up->FindByName(basename.GetStringRef(), offsets); } -void AppleDWARFIndex::GetGlobalVariables( - const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) { if (!m_apple_names_up) return; DWARFMappedHash::DIEInfoArray hash_data; - m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data); - DWARFMappedHash::ExtractDIEArray(hash_data, callback); + if (m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data)) + DWARFMappedHash::ExtractDIEArray(hash_data, offsets); } -void AppleDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, + DIEArray &offsets) { if (!m_apple_names_up) return; DWARFMappedHash::DIEInfoArray hash_data; - m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), cu.GetNextUnitOffset(), - hash_data); - DWARFMappedHash::ExtractDIEArray(hash_data, callback); + if (m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), + cu.GetNextUnitOffset(), hash_data)) + DWARFMappedHash::ExtractDIEArray(hash_data, offsets); } -void AppleDWARFIndex::GetObjCMethods( - ConstString class_name, llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetObjCMethods(ConstString class_name, + DIEArray &offsets) { if (!m_apple_objc_up) return; - m_apple_objc_up->FindByName(class_name.GetStringRef(), callback); + m_apple_objc_up->FindByName(class_name.GetStringRef(), offsets); } -void AppleDWARFIndex::GetCompleteObjCClass( - ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetCompleteObjCClass(ConstString class_name, + bool must_be_implementation, + DIEArray &offsets) { if (!m_apple_types_up) return; m_apple_types_up->FindCompleteObjCClassByName( - class_name.GetStringRef(), callback, must_be_implementation); + class_name.GetStringRef(), offsets, must_be_implementation); } -void AppleDWARFIndex::GetTypes(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { if (!m_apple_types_up) return; - m_apple_types_up->FindByName(name.GetStringRef(), callback); + m_apple_types_up->FindByName(name.GetStringRef(), offsets); } void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) { + DIEArray &offsets) { if (!m_apple_types_up) return; @@ -125,7 +122,7 @@ void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context, if (log) m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()"); m_apple_types_up->FindByNameAndTagAndQualifiedNameHash( - type_name.GetStringRef(), tag, qualified_name_hash, callback); + type_name.GetStringRef(), tag, qualified_name_hash, offsets); return; } @@ -139,46 +136,47 @@ void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context, if (!has_qualified_name_hash && (context.GetSize() > 1) && (context[1].tag == DW_TAG_class_type || context[1].tag == DW_TAG_structure_type)) { - if (!m_apple_types_up->FindByName(context[1].name, - [&](DIERef ref) { return false; })) + DIEArray class_matches; + m_apple_types_up->FindByName(context[1].name, class_matches); + if (class_matches.empty()) return; } if (log) m_module.LogMessage(log, "FindByNameAndTag()"); - m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, callback); + m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, offsets); return; } - m_apple_types_up->FindByName(type_name.GetStringRef(), callback); + m_apple_types_up->FindByName(type_name.GetStringRef(), offsets); } -void AppleDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { if (!m_apple_namespaces_up) return; - m_apple_namespaces_up->FindByName(name.GetStringRef(), callback); + m_apple_namespaces_up->FindByName(name.GetStringRef(), offsets); } -void AppleDWARFIndex::GetFunctions( - ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) { - m_apple_names_up->FindByName(name.GetStringRef(), [&](DIERef die_ref) { - return ProcessFunctionDIE(name.GetStringRef(), die_ref, dwarf, - parent_decl_ctx, name_type_mask, callback); - }); +void AppleDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, + uint32_t name_type_mask, + std::vector<DWARFDIE> &dies) { + DIEArray offsets; + m_apple_names_up->FindByName(name.GetStringRef(), offsets); + for (const DIERef &die_ref : offsets) { + ProcessFunctionDIE(name.GetStringRef(), die_ref, dwarf, parent_decl_ctx, + name_type_mask, dies); + } } -void AppleDWARFIndex::GetFunctions( - const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) { +void AppleDWARFIndex::GetFunctions(const RegularExpression ®ex, + DIEArray &offsets) { if (!m_apple_names_up) return; DWARFMappedHash::DIEInfoArray hash_data; - m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data); - DWARFMappedHash::ExtractDIEArray(hash_data, callback); + if (m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data)) + DWARFMappedHash::ExtractDIEArray(hash_data, offsets); } void AppleDWARFIndex::ReportInvalidDIERef(const DIERef &ref, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h index fcb02a35bd9f..645b6538a1c9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -32,32 +32,21 @@ class AppleDWARFIndex : public DWARFIndex { void Preload() override {} - void - GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetGlobalVariables(const DWARFUnit &cu, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetObjCMethods(ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetTypes(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetTypes(const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) override; + void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; + void GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) override; + void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override; + void GetObjCMethods(ConstString class_name, DIEArray &offsets) override; + void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, + DIEArray &offsets) override; + void GetTypes(ConstString name, DIEArray &offsets) override; + void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; + void GetNamespaces(ConstString name, DIEArray &offsets) override; void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) override; - void GetFunctions(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) override; + std::vector<DWARFDIE> &dies) override; + void GetFunctions(const RegularExpression ®ex, DIEArray &offsets) override; void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override; void Dump(Stream &s) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index da7cb3be1054..56f2f07674cc 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -2013,13 +2013,18 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die, if (class_language == eLanguageTypeObjC) { ConstString class_name(clang_type.GetTypeName()); if (class_name) { - dwarf->GetObjCMethods(class_name, [&](DIERef die_ref) { + DIEArray method_die_offsets; + dwarf->GetObjCMethodDIEOffsets(class_name, method_die_offsets); + + const size_t num_matches = method_die_offsets.size(); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = method_die_offsets[i]; DWARFDebugInfo &debug_info = dwarf->DebugInfo(); DWARFDIE method_die = debug_info.GetDIE(die_ref); + if (method_die) method_die.ResolveType(); - return true; - }); + } for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp index ab3fd1f59a28..0445fa551639 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp @@ -16,14 +16,15 @@ using namespace lldb; DWARFIndex::~DWARFIndex() = default; -bool DWARFIndex::ProcessFunctionDIE( - llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) { +void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, DIERef ref, + SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, + uint32_t name_type_mask, + std::vector<DWARFDIE> &dies) { DWARFDIE die = dwarf.GetDIE(ref); if (!die) { ReportInvalidDIERef(ref, name); - return true; + return; } // Exit early if we're searching exclusively for methods or selectors and @@ -31,22 +32,26 @@ bool DWARFIndex::ProcessFunctionDIE( uint32_t looking_for_nonmethods = name_type_mask & ~(eFunctionNameTypeMethod | eFunctionNameTypeSelector); if (!looking_for_nonmethods && parent_decl_ctx.IsValid()) - return true; + return; // Otherwise, we need to also check that the context matches. If it does not // match, we do nothing. if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - return true; + return; // In case of a full match, we just insert everything we find. - if (name_type_mask & eFunctionNameTypeFull) - return callback(die); + if (name_type_mask & eFunctionNameTypeFull) { + dies.push_back(die); + return; + } // If looking for ObjC selectors, we need to also check if the name is a // possible selector. if (name_type_mask & eFunctionNameTypeSelector && - ObjCLanguage::IsPossibleObjCMethodName(die.GetName())) - return callback(die); + ObjCLanguage::IsPossibleObjCMethodName(die.GetName())) { + dies.push_back(die); + return; + } bool looking_for_methods = name_type_mask & lldb::eFunctionNameTypeMethod; bool looking_for_functions = name_type_mask & lldb::eFunctionNameTypeBase; @@ -56,8 +61,6 @@ bool DWARFIndex::ProcessFunctionDIE( // searching for. if ((looking_for_methods && looking_for_functions) || looking_for_methods == die.IsMethod()) - return callback(die); + dies.push_back(die); } - - return true; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h index 2181b6739a85..cd4e85a31f4d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -27,35 +27,24 @@ class DWARFIndex { /// Finds global variables with the given base name. Any additional filtering /// (e.g., to only retrieve variables from a given context) should be done by /// the consumer. - virtual void - GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DIERef ref)> callback) = 0; + virtual void GetGlobalVariables(ConstString basename, DIEArray &offsets) = 0; - virtual void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void - GetGlobalVariables(const DWARFUnit &cu, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void - GetObjCMethods(ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void - GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void GetTypes(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void GetTypes(const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void GetNamespaces(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) = 0; - virtual void - GetFunctions(ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) = 0; + virtual void GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) = 0; + virtual void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) = 0; + virtual void GetObjCMethods(ConstString class_name, DIEArray &offsets) = 0; + virtual void GetCompleteObjCClass(ConstString class_name, + bool must_be_implementation, + DIEArray &offsets) = 0; + virtual void GetTypes(ConstString name, DIEArray &offsets) = 0; + virtual void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) = 0; + virtual void GetNamespaces(ConstString name, DIEArray &offsets) = 0; + virtual void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, + uint32_t name_type_mask, + std::vector<DWARFDIE> &dies) = 0; virtual void GetFunctions(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) = 0; + DIEArray &offsets) = 0; virtual void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) = 0; virtual void Dump(Stream &s) = 0; @@ -67,11 +56,10 @@ class DWARFIndex { /// the function given by "ref" matches search criteria given by /// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies" /// vector. - bool ProcessFunctionDIE(llvm::StringRef name, DIERef ref, + void ProcessFunctionDIE(llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback); + uint32_t name_type_mask, std::vector<DWARFDIE> &dies); }; } // namespace lldb_private diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 23e9b0b36c04..d3a4b92b7e3e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -57,12 +57,10 @@ DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) { return llvm::None; } -bool DebugNamesDWARFIndex::ProcessEntry( - const DebugNames::Entry &entry, - llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::Append(const DebugNames::Entry &entry, + DIEArray &offsets) { if (llvm::Optional<DIERef> ref = ToDIERef(entry)) - return callback(*ref); - return true; + offsets.push_back(*ref); } void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, @@ -76,23 +74,23 @@ void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, ni.getUnitOffset(), name); } -void DebugNamesDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetGlobalVariables(ConstString basename, + DIEArray &offsets) { + m_fallback.GetGlobalVariables(basename, offsets); + for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(basename.GetStringRef())) { if (entry.tag() != DW_TAG_variable) continue; - if (!ProcessEntry(entry, callback)) - return; + Append(entry, offsets); } - - m_fallback.GetGlobalVariables(basename, callback); } -void DebugNamesDWARFIndex::GetGlobalVariables( - const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) { + m_fallback.GetGlobalVariables(regex, offsets); + for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { if (!regex.Execute(nte.getString())) @@ -104,18 +102,17 @@ void DebugNamesDWARFIndex::GetGlobalVariables( if (entry_or->tag() != DW_TAG_variable) continue; - if (!ProcessEntry(*entry_or, callback)) - return; + Append(*entry_or, offsets); } MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); } } - - m_fallback.GetGlobalVariables(regex, callback); } -void DebugNamesDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, + DIEArray &offsets) { + m_fallback.GetGlobalVariables(cu, offsets); + uint64_t cu_offset = cu.GetOffset(); for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { @@ -127,19 +124,18 @@ void DebugNamesDWARFIndex::GetGlobalVariables( if (entry_or->getCUOffset() != cu_offset) continue; - if (!ProcessEntry(*entry_or, callback)) - return; + Append(*entry_or, offsets); } MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); } } - - m_fallback.GetGlobalVariables(cu, callback); } -void DebugNamesDWARFIndex::GetCompleteObjCClass( - ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetCompleteObjCClass(ConstString class_name, + bool must_be_implementation, + DIEArray &offsets) { + m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, offsets); + // Keep a list of incomplete types as fallback for when we don't find the // complete type. DIEArray incomplete_types; @@ -167,89 +163,76 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass( if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) { // If we find the complete version we're done. - callback(*ref); + offsets.push_back(*ref); return; } incomplete_types.push_back(*ref); } - for (DIERef ref : incomplete_types) - if (!callback(ref)) - return; - - m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, callback); + offsets.insert(offsets.end(), incomplete_types.begin(), + incomplete_types.end()); } -void DebugNamesDWARFIndex::GetTypes( - ConstString name, llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { + m_fallback.GetTypes(name, offsets); + for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { - if (isType(entry.tag())) { - if (!ProcessEntry(entry, callback)) - return; - } + if (isType(entry.tag())) + Append(entry, offsets); } - - m_fallback.GetTypes(name, callback); } -void DebugNamesDWARFIndex::GetTypes( - const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetTypes(const DWARFDeclContext &context, + DIEArray &offsets) { + m_fallback.GetTypes(context, offsets); + for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(context[0].name)) { - if (entry.tag() == context[0].tag) { - if (!ProcessEntry(entry, callback)) - return; - } + if (entry.tag() == context[0].tag) + Append(entry, offsets); } - - m_fallback.GetTypes(context, callback); } -void DebugNamesDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { + m_fallback.GetNamespaces(name, offsets); + for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { - if (entry.tag() == DW_TAG_namespace) { - if (!ProcessEntry(entry, callback)) - return; - } + if (entry.tag() == DW_TAG_namespace) + Append(entry, offsets); } - - m_fallback.GetNamespaces(name, callback); } void DebugNamesDWARFIndex::GetFunctions( ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) { + std::vector<DWARFDIE> &dies) { + + std::vector<DWARFDIE> v; + m_fallback.GetFunctions(name, dwarf, parent_decl_ctx, name_type_mask, v); - std::set<DWARFDebugInfoEntry *> seen; for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { Tag tag = entry.tag(); if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine) continue; - if (llvm::Optional<DIERef> ref = ToDIERef(entry)) { - if (!ProcessFunctionDIE(name.GetStringRef(), *ref, dwarf, parent_decl_ctx, - name_type_mask, [&](DWARFDIE die) { - if (!seen.insert(die.GetDIE()).second) - return true; - return callback(die); - })) - return; - } + if (llvm::Optional<DIERef> ref = ToDIERef(entry)) + ProcessFunctionDIE(name.GetStringRef(), *ref, dwarf, parent_decl_ctx, + name_type_mask, v); } - m_fallback.GetFunctions(name, dwarf, parent_decl_ctx, name_type_mask, - callback); + std::set<DWARFDebugInfoEntry *> seen; + for (DWARFDIE die : v) + if (seen.insert(die.GetDIE()).second) + dies.push_back(die); } -void DebugNamesDWARFIndex::GetFunctions( - const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) { +void DebugNamesDWARFIndex::GetFunctions(const RegularExpression ®ex, + DIEArray &offsets) { + m_fallback.GetFunctions(regex, offsets); + for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { if (!regex.Execute(nte.getString())) @@ -262,14 +245,11 @@ void DebugNamesDWARFIndex::GetFunctions( if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine) continue; - if (!ProcessEntry(*entry_or, callback)) - return; + Append(*entry_or, offsets); } MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); } } - - m_fallback.GetFunctions(regex, callback); } void DebugNamesDWARFIndex::Dump(Stream &s) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h index 204007b57b0d..00f51e7e4128 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -25,32 +25,22 @@ class DebugNamesDWARFIndex : public DWARFIndex { void Preload() override { m_fallback.Preload(); } - void - GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetGlobalVariables(const DWARFUnit &cu, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetObjCMethods(ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback) override {} - void - GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetTypes(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetTypes(const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) override; + void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; + void GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) override; + void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override; + void GetObjCMethods(ConstString class_name, DIEArray &offsets) override {} + void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, + DIEArray &offsets) override; + void GetTypes(ConstString name, DIEArray &offsets) override; + void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; + void GetNamespaces(ConstString name, DIEArray &offsets) override; void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + std::vector<DWARFDIE> &dies) override; void GetFunctions(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) override; + DIEArray &offsets) override; void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {} void Dump(Stream &s) override; @@ -78,8 +68,7 @@ class DebugNamesDWARFIndex : public DWARFIndex { ManualDWARFIndex m_fallback; llvm::Optional<DIERef> ToDIERef(const DebugNames::Entry &entry); - bool ProcessEntry(const DebugNames::Entry &entry, - llvm::function_ref<bool(DIERef ref)> callback); + void Append(const DebugNames::Entry &entry, DIEArray &offsets); static void MaybeLogLookupError(llvm::Error error, const DebugNames::NameIndex &ni, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp index d36f2a8bccf7..c82a8682ca49 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp @@ -9,21 +9,18 @@ #include "HashedNameToDIE.h" #include "llvm/ADT/StringRef.h" -bool DWARFMappedHash::ExtractDIEArray( - const DIEInfoArray &die_info_array, - llvm::function_ref<bool(DIERef ref)> callback) { +void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array, + DIEArray &die_offsets) { const size_t count = die_info_array.size(); for (size_t i = 0; i < count; ++i) - if (!callback(DIERef(die_info_array[i]))) - return false; - return true; + die_offsets.emplace_back(die_info_array[i]); } -void DWARFMappedHash::ExtractDIEArray( - const DIEInfoArray &die_info_array, const dw_tag_t tag, - llvm::function_ref<bool(DIERef ref)> callback) { +void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array, + const dw_tag_t tag, + DIEArray &die_offsets) { if (tag == 0) { - ExtractDIEArray(die_info_array, callback); + ExtractDIEArray(die_info_array, die_offsets); return; } @@ -35,19 +32,17 @@ void DWARFMappedHash::ExtractDIEArray( if (die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type) tag_matches = tag == DW_TAG_structure_type || tag == DW_TAG_class_type; } - if (tag_matches) { - if (!callback(DIERef(die_info_array[i]))) - return; - } + if (tag_matches) + die_offsets.emplace_back(die_info_array[i]); } } -void DWARFMappedHash::ExtractDIEArray( - const DIEInfoArray &die_info_array, const dw_tag_t tag, - const uint32_t qualified_name_hash, - llvm::function_ref<bool(DIERef ref)> callback) { +void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array, + const dw_tag_t tag, + const uint32_t qualified_name_hash, + DIEArray &die_offsets) { if (tag == 0) { - ExtractDIEArray(die_info_array, callback); + ExtractDIEArray(die_info_array, die_offsets); return; } @@ -61,47 +56,44 @@ void DWARFMappedHash::ExtractDIEArray( if (die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type) tag_matches = tag == DW_TAG_structure_type || tag == DW_TAG_class_type; } - if (tag_matches) { - if (!callback(DIERef(die_info_array[i]))) - return; - } + if (tag_matches) + die_offsets.emplace_back(die_info_array[i]); } } void DWARFMappedHash::ExtractClassOrStructDIEArray( const DIEInfoArray &die_info_array, - bool return_implementation_only_if_available, - llvm::function_ref<bool(DIERef ref)> callback) { + bool return_implementation_only_if_available, DIEArray &die_offsets) { const size_t count = die_info_array.size(); for (size_t i = 0; i < count; ++i) { const dw_tag_t die_tag = die_info_array[i].tag; if (!(die_tag == 0 || die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type)) continue; - bool is_implementation = - (die_info_array[i].type_flags & eTypeFlagClassIsImplementation) != 0; - if (is_implementation != return_implementation_only_if_available) - continue; - if (return_implementation_only_if_available) { - // We found the one true definition for this class, so only return - // that - callback(DIERef(die_info_array[i])); - return; + if (die_info_array[i].type_flags & eTypeFlagClassIsImplementation) { + if (return_implementation_only_if_available) { + // We found the one true definition for this class, so only return + // that + die_offsets.clear(); + die_offsets.emplace_back(die_info_array[i]); + return; + } else { + // Put the one true definition as the first entry so it matches first + die_offsets.emplace(die_offsets.begin(), die_info_array[i]); + } + } else { + die_offsets.emplace_back(die_info_array[i]); } - if (!callback(DIERef(die_info_array[i]))) - return; } } void DWARFMappedHash::ExtractTypesFromDIEArray( const DIEInfoArray &die_info_array, uint32_t type_flag_mask, - uint32_t type_flag_value, llvm::function_ref<bool(DIERef ref)> callback) { + uint32_t type_flag_value, DIEArray &die_offsets) { const size_t count = die_info_array.size(); for (size_t i = 0; i < count; ++i) { - if ((die_info_array[i].type_flags & type_flag_mask) == type_flag_value) { - if (!callback(DIERef(die_info_array[i]))) - return; - } + if ((die_info_array[i].type_flags & type_flag_mask) == type_flag_value) + die_offsets.emplace_back(die_info_array[i]); } } @@ -461,7 +453,7 @@ DWARFMappedHash::MemoryTable::AppendHashDataForRegularExpression( } } -void DWARFMappedHash::MemoryTable::AppendAllDIEsThatMatchingRegex( +size_t DWARFMappedHash::MemoryTable::AppendAllDIEsThatMatchingRegex( const lldb_private::RegularExpression ®ex, DIEInfoArray &die_info_array) const { const uint32_t hash_count = m_header.hashes_count; @@ -490,9 +482,10 @@ void DWARFMappedHash::MemoryTable::AppendAllDIEsThatMatchingRegex( } } die_info_array.swap(pair.value); + return die_info_array.size(); } -void DWARFMappedHash::MemoryTable::AppendAllDIEsInRange( +size_t DWARFMappedHash::MemoryTable::AppendAllDIEsInRange( const uint32_t die_offset_start, const uint32_t die_offset_end, DIEInfoArray &die_info_array) const { const uint32_t hash_count = m_header.hashes_count; @@ -519,74 +512,73 @@ void DWARFMappedHash::MemoryTable::AppendAllDIEsInRange( } } } + return die_info_array.size(); } -bool DWARFMappedHash::MemoryTable::FindByName( - llvm::StringRef name, llvm::function_ref<bool(DIERef ref)> callback) { +size_t DWARFMappedHash::MemoryTable::FindByName(llvm::StringRef name, + DIEArray &die_offsets) { if (name.empty()) - return true; + return 0; DIEInfoArray die_info_array; - FindByName(name, die_info_array); - return DWARFMappedHash::ExtractDIEArray(die_info_array, callback); + if (FindByName(name, die_info_array)) + DWARFMappedHash::ExtractDIEArray(die_info_array, die_offsets); + return die_info_array.size(); } -void DWARFMappedHash::MemoryTable::FindByNameAndTag( - llvm::StringRef name, const dw_tag_t tag, - llvm::function_ref<bool(DIERef ref)> callback) { +size_t DWARFMappedHash::MemoryTable::FindByNameAndTag(llvm::StringRef name, + const dw_tag_t tag, + DIEArray &die_offsets) { DIEInfoArray die_info_array; - FindByName(name, die_info_array); - DWARFMappedHash::ExtractDIEArray(die_info_array, tag, callback); + if (FindByName(name, die_info_array)) + DWARFMappedHash::ExtractDIEArray(die_info_array, tag, die_offsets); + return die_info_array.size(); } -void DWARFMappedHash::MemoryTable::FindByNameAndTagAndQualifiedNameHash( +size_t DWARFMappedHash::MemoryTable::FindByNameAndTagAndQualifiedNameHash( llvm::StringRef name, const dw_tag_t tag, - const uint32_t qualified_name_hash, - llvm::function_ref<bool(DIERef ref)> callback) { + const uint32_t qualified_name_hash, DIEArray &die_offsets) { DIEInfoArray die_info_array; - FindByName(name, die_info_array); - DWARFMappedHash::ExtractDIEArray(die_info_array, tag, qualified_name_hash, - callback); + if (FindByName(name, die_info_array)) + DWARFMappedHash::ExtractDIEArray(die_info_array, tag, qualified_name_hash, + die_offsets); + return die_info_array.size(); } -void DWARFMappedHash::MemoryTable::FindCompleteObjCClassByName( - llvm::StringRef name, llvm::function_ref<bool(DIERef ref)> callback, - bool must_be_implementation) { +size_t DWARFMappedHash::MemoryTable::FindCompleteObjCClassByName( + llvm::StringRef name, DIEArray &die_offsets, bool must_be_implementation) { DIEInfoArray die_info_array; - FindByName(name, die_info_array); + if (!FindByName(name, die_info_array)) + return 0; if (must_be_implementation && GetHeader().header_data.ContainsAtom(eAtomTypeTypeFlags)) { // If we have two atoms, then we have the DIE offset and the type flags // so we can find the objective C class efficiently. - DWARFMappedHash::ExtractTypesFromDIEArray( - die_info_array, UINT32_MAX, eTypeFlagClassIsImplementation, callback); - return; + DWARFMappedHash::ExtractTypesFromDIEArray(die_info_array, UINT32_MAX, + eTypeFlagClassIsImplementation, + die_offsets); + return die_offsets.size(); } // We don't only want the one true definition, so try and see what we can // find, and only return class or struct DIEs. If we do have the full // implementation, then return it alone, else return all possible // matches. - bool found_implementation = false; + const bool return_implementation_only_if_available = true; DWARFMappedHash::ExtractClassOrStructDIEArray( - die_info_array, true /*return_implementation_only_if_available*/, - [&](DIERef ref) { - found_implementation = true; - // Here the return value does not matter as we are called at most once. - return callback(ref); - }); - if (found_implementation) - return; - DWARFMappedHash::ExtractClassOrStructDIEArray( - die_info_array, false /*return_implementation_only_if_available*/, - callback); + die_info_array, return_implementation_only_if_available, die_offsets); + return die_offsets.size(); } -void DWARFMappedHash::MemoryTable::FindByName(llvm::StringRef name, - DIEInfoArray &die_info_array) { +size_t DWARFMappedHash::MemoryTable::FindByName(llvm::StringRef name, + DIEInfoArray &die_info_array) { if (name.empty()) - return; + return 0; Pair kv_pair; - if (Find(name, kv_pair)) + size_t old_size = die_info_array.size(); + if (Find(name, kv_pair)) { die_info_array.swap(kv_pair.value); + return die_info_array.size() - old_size; + } + return 0; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h index ad178fc6a987..69ceb2996732 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h @@ -132,36 +132,33 @@ class DWARFMappedHash { bool ReadHashData(uint32_t hash_data_offset, HashData &hash_data) const override; - void + size_t AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression ®ex, DIEInfoArray &die_info_array) const; - void AppendAllDIEsInRange(const uint32_t die_offset_start, - const uint32_t die_offset_end, - DIEInfoArray &die_info_array) const; + size_t AppendAllDIEsInRange(const uint32_t die_offset_start, + const uint32_t die_offset_end, + DIEInfoArray &die_info_array) const; - bool FindByName(llvm::StringRef name, - llvm::function_ref<bool(DIERef ref)> callback); + size_t FindByName(llvm::StringRef name, DIEArray &die_offsets); - void FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag, - llvm::function_ref<bool(DIERef ref)> callback); + size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag, + DIEArray &die_offsets); - void FindByNameAndTagAndQualifiedNameHash( + size_t FindByNameAndTagAndQualifiedNameHash( llvm::StringRef name, const dw_tag_t tag, - const uint32_t qualified_name_hash, - llvm::function_ref<bool(DIERef ref)> callback); + const uint32_t qualified_name_hash, DIEArray &die_offsets); - void - FindCompleteObjCClassByName(llvm::StringRef name, - llvm::function_ref<bool(DIERef ref)> callback, - bool must_be_implementation); + size_t FindCompleteObjCClassByName(llvm::StringRef name, + DIEArray &die_offsets, + bool must_be_implementation); protected: Result AppendHashDataForRegularExpression( const lldb_private::RegularExpression ®ex, lldb::offset_t *hash_data_offset_ptr, Pair &pair) const; - void FindByName(llvm::StringRef name, DIEInfoArray &die_info_array); + size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array); Result GetHashDataForName(llvm::StringRef name, lldb::offset_t *hash_data_offset_ptr, @@ -172,28 +169,27 @@ class DWARFMappedHash { std::string m_name; }; - static bool ExtractDIEArray(const DIEInfoArray &die_info_array, - llvm::function_ref<bool(DIERef ref)> callback); + static void ExtractDIEArray(const DIEInfoArray &die_info_array, + DIEArray &die_offsets); protected: static void ExtractDIEArray(const DIEInfoArray &die_info_array, - const dw_tag_t tag, - llvm::function_ref<bool(DIERef ref)> callback); + const dw_tag_t tag, DIEArray &die_offsets); static void ExtractDIEArray(const DIEInfoArray &die_info_array, const dw_tag_t tag, const uint32_t qualified_name_hash, - llvm::function_ref<bool(DIERef ref)> callback); + DIEArray &die_offsets); static void ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array, bool return_implementation_only_if_available, - llvm::function_ref<bool(DIERef ref)> callback); + DIEArray &die_offsets); - static void - ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array, - uint32_t type_flag_mask, uint32_t type_flag_value, - llvm::function_ref<bool(DIERef ref)> callback); + static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array, + uint32_t type_flag_mask, + uint32_t type_flag_value, + DIEArray &die_offsets); static const char *GetAtomTypeName(uint16_t atom); }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index 535e79a7ecc7..36f8aa2bfc13 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -320,116 +320,113 @@ void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, } } -void ManualDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetGlobalVariables(ConstString basename, DIEArray &offsets) { Index(); - m_set.globals.Find(basename, callback); + m_set.globals.Find(basename, offsets); } -void ManualDWARFIndex::GetGlobalVariables( - const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) { Index(); - m_set.globals.Find(regex, callback); + m_set.globals.Find(regex, offsets); } -void ManualDWARFIndex::GetGlobalVariables( - const DWARFUnit &unit, llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetGlobalVariables(const DWARFUnit &unit, + DIEArray &offsets) { Index(); - m_set.globals.FindAllEntriesForUnit(unit, callback); + m_set.globals.FindAllEntriesForUnit(unit, offsets); } -void ManualDWARFIndex::GetObjCMethods( - ConstString class_name, llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetObjCMethods(ConstString class_name, + DIEArray &offsets) { Index(); - m_set.objc_class_selectors.Find(class_name, callback); + m_set.objc_class_selectors.Find(class_name, offsets); } -void ManualDWARFIndex::GetCompleteObjCClass( - ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetCompleteObjCClass(ConstString class_name, + bool must_be_implementation, + DIEArray &offsets) { Index(); - m_set.types.Find(class_name, callback); + m_set.types.Find(class_name, offsets); } -void ManualDWARFIndex::GetTypes(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { Index(); - m_set.types.Find(name, callback); + m_set.types.Find(name, offsets); } void ManualDWARFIndex::GetTypes(const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) { + DIEArray &offsets) { Index(); - m_set.types.Find(ConstString(context[0].name), callback); + m_set.types.Find(ConstString(context[0].name), offsets); } -void ManualDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { Index(); - m_set.namespaces.Find(name, callback); + m_set.namespaces.Find(name, offsets); } -void ManualDWARFIndex::GetFunctions( - ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) { +void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, + uint32_t name_type_mask, + std::vector<DWARFDIE> &dies) { Index(); if (name_type_mask & eFunctionNameTypeFull) { - if (!m_set.function_fullnames.Find(name, [&](DIERef die_ref) { - DWARFDIE die = dwarf.GetDIE(die_ref); - if (!die) - return true; - if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - return true; - return callback(die); - })) - return; + DIEArray offsets; + m_set.function_fullnames.Find(name, offsets); + for (const DIERef &die_ref: offsets) { + DWARFDIE die = dwarf.GetDIE(die_ref); + if (!die) + continue; + if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) + continue; + dies.push_back(die); + } } if (name_type_mask & eFunctionNameTypeBase) { - if (!m_set.function_basenames.Find(name, [&](DIERef die_ref) { - DWARFDIE die = dwarf.GetDIE(die_ref); - if (!die) - return true; - if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - return true; - return callback(die); - })) - return; + DIEArray offsets; + m_set.function_basenames.Find(name, offsets); + for (const DIERef &die_ref: offsets) { + DWARFDIE die = dwarf.GetDIE(die_ref); + if (!die) + continue; + if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) + continue; + dies.push_back(die); + } } if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) { - if (!m_set.function_methods.Find(name, [&](DIERef die_ref) { - DWARFDIE die = dwarf.GetDIE(die_ref); - if (!die) - return true; - return callback(die); - })) - return; + DIEArray offsets; + m_set.function_methods.Find(name, offsets); + for (const DIERef &die_ref: offsets) { + DWARFDIE die = dwarf.GetDIE(die_ref); + if (!die) + continue; + dies.push_back(die); + } } if (name_type_mask & eFunctionNameTypeSelector && !parent_decl_ctx.IsValid()) { - if (!m_set.function_selectors.Find(name, [&](DIERef die_ref) { - DWARFDIE die = dwarf.GetDIE(die_ref); - if (!die) - return true; - return callback(die); - })) - return; + DIEArray offsets; + m_set.function_selectors.Find(name, offsets); + for (const DIERef &die_ref: offsets) { + DWARFDIE die = dwarf.GetDIE(die_ref); + if (!die) + continue; + dies.push_back(die); + } } } -void ManualDWARFIndex::GetFunctions( - const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) { +void ManualDWARFIndex::GetFunctions(const RegularExpression ®ex, + DIEArray &offsets) { Index(); - if (!m_set.function_basenames.Find(regex, callback)) - return; - if (!m_set.function_fullnames.Find(regex, callback)) - return; + m_set.function_basenames.Find(regex, offsets); + m_set.function_fullnames.Find(regex, offsets); } void ManualDWARFIndex::Dump(Stream &s) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h index 72a5c8ff3681..68eda58221d8 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -26,32 +26,21 @@ class ManualDWARFIndex : public DWARFIndex { void Preload() override { Index(); } - void - GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetGlobalVariables(const DWARFUnit &unit, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetObjCMethods(ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback) override; - void - GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetTypes(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetTypes(const DWARFDeclContext &context, - llvm::function_ref<bool(DIERef ref)> callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) override; + void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; + void GetGlobalVariables(const RegularExpression ®ex, + DIEArray &offsets) override; + void GetGlobalVariables(const DWARFUnit &unit, DIEArray &offsets) override; + void GetObjCMethods(ConstString class_name, DIEArray &offsets) override; + void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, + DIEArray &offsets) override; + void GetTypes(ConstString name, DIEArray &offsets) override; + void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; + void GetNamespaces(ConstString name, DIEArray &offsets) override; void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref<bool(DWARFDIE die)> callback) override; - void GetFunctions(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) override; + std::vector<DWARFDIE> &dies) override; + void GetFunctions(const RegularExpression ®ex, DIEArray &offsets) override; void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {} void Dump(Stream &s) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp index 42e96af84a96..5c314162afb5 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp @@ -26,38 +26,28 @@ void NameToDIE::Insert(ConstString name, const DIERef &die_ref) { m_map.Append(name, die_ref); } -bool NameToDIE::Find(ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) const { - for (const auto &entry : m_map.equal_range(name)) - if (!callback(entry.value)) - return false; - return true; +size_t NameToDIE::Find(ConstString name, DIEArray &info_array) const { + return m_map.GetValues(name, info_array); } -bool NameToDIE::Find(const RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) const { - for (const auto &entry : m_map) - if (regex.Execute(entry.cstring.GetCString())) { - if (!callback(entry.value)) - return false; - } - return true; +size_t NameToDIE::Find(const RegularExpression ®ex, + DIEArray &info_array) const { + return m_map.GetValues(regex, info_array); } -void NameToDIE::FindAllEntriesForUnit( - const DWARFUnit &unit, - llvm::function_ref<bool(DIERef ref)> callback) const { +size_t NameToDIE::FindAllEntriesForUnit(const DWARFUnit &unit, + DIEArray &info_array) const { + const size_t initial_size = info_array.size(); const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i); if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() && unit.GetDebugSection() == die_ref.section() && unit.GetOffset() <= die_ref.die_offset() && - die_ref.die_offset() < unit.GetNextUnitOffset()) { - if (!callback(die_ref)) - return; - } + die_ref.die_offset() < unit.GetNextUnitOffset()) + info_array.push_back(die_ref); } + return info_array.size() - initial_size; } void NameToDIE::Dump(Stream *s) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h index 5aa841cf3d10..ed4146d0b3b1 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -32,15 +32,14 @@ class NameToDIE { void Finalize(); - bool Find(lldb_private::ConstString name, - llvm::function_ref<bool(DIERef ref)> callback) const; + size_t Find(lldb_private::ConstString name, + DIEArray &info_array) const; - bool Find(const lldb_private::RegularExpression ®ex, - llvm::function_ref<bool(DIERef ref)> callback) const; + size_t Find(const lldb_private::RegularExpression ®ex, + DIEArray &info_array) const; - void - FindAllEntriesForUnit(const DWARFUnit &unit, - llvm::function_ref<bool(DIERef ref)> callback) const; + size_t FindAllEntriesForUnit(const DWARFUnit &unit, + DIEArray &info_array) const; void ForEach(std::function<bool(lldb_private::ConstString name, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 400ba6e1f443..fb449edb90ca 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1463,9 +1463,11 @@ SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) { return static_cast<CompileUnit *>(non_dwo_cu->GetUserData()); } -void SymbolFileDWARF::GetObjCMethods( - ConstString class_name, llvm::function_ref<bool(DIERef ref)> callback) { - m_index->GetObjCMethods(class_name, callback); +size_t SymbolFileDWARF::GetObjCMethodDIEOffsets(ConstString class_name, + DIEArray &method_die_offsets) { + method_die_offsets.clear(); + m_index->GetObjCMethods(class_name, method_die_offsets); + return method_die_offsets.size(); } bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) { @@ -2046,28 +2048,32 @@ void SymbolFileDWARF::FindGlobalVariables( context, basename)) basename = name.GetStringRef(); + DIEArray die_offsets; + m_index->GetGlobalVariables(ConstString(basename), die_offsets); + const size_t num_die_matches = die_offsets.size(); + + SymbolContext sc; + sc.module_sp = m_objfile_sp->GetModule(); + assert(sc.module_sp); + // Loop invariant: Variables up to this index have been checked for context // matches. uint32_t pruned_idx = original_size; - SymbolContext sc; - m_index->GetGlobalVariables(ConstString(basename), [&](DIERef die_ref) { - if (!sc.module_sp) - sc.module_sp = m_objfile_sp->GetModule(); - assert(sc.module_sp); - + for (size_t i = 0; i < num_die_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); - return true; + continue; } if (die.Tag() != DW_TAG_variable) - return true; + continue; auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); if (!dwarf_cu) - return true; + continue; sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); if (parent_decl_ctx) { @@ -2076,7 +2082,7 @@ void SymbolFileDWARF::FindGlobalVariables( dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); if (!actual_parent_decl_ctx || actual_parent_decl_ctx != parent_decl_ctx) - return true; + continue; } } @@ -2090,8 +2096,9 @@ void SymbolFileDWARF::FindGlobalVariables( variables.RemoveVariableAtIndex(pruned_idx); } - return variables.GetSize() - original_size < max_matches; - }); + if (variables.GetSize() - original_size >= max_matches) + break; + } // Return the number of variable that were appended to the list const uint32_t num_matches = variables.GetSize() - original_size; @@ -2122,27 +2129,32 @@ void SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex, // Remember how many variables are in the list before we search. const uint32_t original_size = variables.GetSize(); + DIEArray die_offsets; + m_index->GetGlobalVariables(regex, die_offsets); + SymbolContext sc; - m_index->GetGlobalVariables(regex, [&](DIERef die_ref) { - if (!sc.module_sp) - sc.module_sp = m_objfile_sp->GetModule(); - assert(sc.module_sp); + sc.module_sp = m_objfile_sp->GetModule(); + assert(sc.module_sp); + const size_t num_matches = die_offsets.size(); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); if (!die) { m_index->ReportInvalidDIERef(die_ref, regex.GetText()); - return true; + continue; } DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); if (!dwarf_cu) - return true; + continue; sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); - return variables.GetSize() - original_size < max_matches; - }); + if (variables.GetSize() - original_size >= max_matches) + break; + } } bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die, @@ -2256,12 +2268,12 @@ void SymbolFileDWARF::FindFunctions(ConstString name, llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies; - m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask, - [&](DWARFDIE die) { - if (resolved_dies.insert(die.GetDIE()).second) - ResolveFunction(die, include_inlines, sc_list); - return true; - }); + std::vector<DWARFDIE> dies; + m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask, dies); + for (const DWARFDIE &die : dies) { + if (resolved_dies.insert(die.GetDIE()).second) + ResolveFunction(die, include_inlines, sc_list); + } // Return the number of variable that were appended to the list const uint32_t num_matches = sc_list.GetSize() - original_size; @@ -2293,17 +2305,19 @@ void SymbolFileDWARF::FindFunctions(const RegularExpression ®ex, } DWARFDebugInfo &info = DebugInfo(); + DIEArray offsets; + m_index->GetFunctions(regex, offsets); + llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies; - m_index->GetFunctions(regex, [&](DIERef ref) { + for (DIERef ref : offsets) { DWARFDIE die = info.GetDIE(ref); if (!die) { m_index->ReportInvalidDIERef(ref, regex.GetText()); - return true; + continue; } if (resolved_dies.insert(die.GetDIE()).second) ResolveFunction(die, include_inlines, sc_list); - return true; - }); + } } void SymbolFileDWARF::GetMangledNamesForFunction( @@ -2359,25 +2373,31 @@ void SymbolFileDWARF::FindTypes( if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) return; - m_index->GetTypes(name, [&](DIERef die_ref) { + DIEArray die_offsets; + m_index->GetTypes(name, die_offsets); + const size_t num_die_matches = die_offsets.size(); + + for (size_t i = 0; i < num_die_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); - return true; + continue; } if (!DIEInDeclContext(parent_decl_ctx, die)) - return true; // The containing decl contexts don't match + continue; // The containing decl contexts don't match Type *matching_type = ResolveType(die, true, true); if (!matching_type) - return true; + continue; // We found a type pointer, now find the shared pointer form our type // list types.InsertUnique(matching_type->shared_from_this()); - return types.GetSize() < max_matches; - }); + if (types.GetSize() >= max_matches) + break; + } // Next search through the reachable Clang modules. This only applies for // DWARF objects compiled with -gmodules that haven't been processed by @@ -2427,28 +2447,32 @@ void SymbolFileDWARF::FindTypes( if (!name) return; - m_index->GetTypes(name, [&](DIERef die_ref) { + DIEArray die_offsets; + m_index->GetTypes(name, die_offsets); + const size_t num_die_matches = die_offsets.size(); + + for (size_t i = 0; i < num_die_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); - return true; + continue; } if (!languages[GetLanguage(*die.GetCU())]) - return true; + continue; llvm::SmallVector<CompilerContext, 4> die_context; die.GetDeclContext(die_context); if (!contextMatches(die_context, pattern)) - return true; + continue; if (Type *matching_type = ResolveType(die, true, true)) { // We found a type pointer, now find the shared pointer form our type // list. types.InsertUnique(matching_type->shared_from_this()); } - return true; - }); + } // Next search through the reachable Clang modules. This only applies for // DWARF objects compiled with -gmodules that haven't been processed by @@ -2478,24 +2502,28 @@ SymbolFileDWARF::FindNamespace(ConstString name, if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) return namespace_decl_ctx; - m_index->GetNamespaces(name, [&](DIERef die_ref) { + DIEArray die_offsets; + m_index->GetNamespaces(name, die_offsets); + const size_t num_matches = die_offsets.size(); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); - return true; + continue; } if (!DIEInDeclContext(parent_decl_ctx, die)) - return true; // The containing decl contexts don't match + continue; // The containing decl contexts don't match DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); if (!dwarf_ast) - return true; + continue; namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); - return !namespace_decl_ctx.IsValid(); - }); - + if (namespace_decl_ctx) + break; + } if (log && namespace_decl_ctx) { GetObjectFile()->GetModule()->LogMessage( log, @@ -2649,54 +2677,59 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE( if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name))) return type_sp; - m_index->GetCompleteObjCClass( - type_name, must_be_implementation, [&](DIERef die_ref) { - DWARFDIE type_die = GetDIE(die_ref); - if (!type_die) { - m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); - return true; - } + DIEArray die_offsets; + m_index->GetCompleteObjCClass(type_name, must_be_implementation, die_offsets); - bool try_resolving_type = false; + const size_t num_matches = die_offsets.size(); - // Don't try and resolve the DIE we are looking for with the DIE - // itself! - if (type_die != die) { - switch (type_die.Tag()) { - case DW_TAG_class_type: - case DW_TAG_structure_type: - try_resolving_type = true; - break; - default: - break; - } - } - if (!try_resolving_type) - return true; + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; + DWARFDIE type_die = GetDIE(die_ref); + if (!type_die) { + m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); + continue; + } - if (must_be_implementation && - type_die.Supports_DW_AT_APPLE_objc_complete_type()) - try_resolving_type = type_die.GetAttributeValueAsUnsigned( - DW_AT_APPLE_objc_complete_type, 0); - if (!try_resolving_type) - return true; + bool try_resolving_type = false; - Type *resolved_type = ResolveType(type_die, false, true); - if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED) - return true; + // Don't try and resolve the DIE we are looking for with the DIE + // itself! + if (type_die != die) { + switch (type_die.Tag()) { + case DW_TAG_class_type: + case DW_TAG_structure_type: + try_resolving_type = true; + break; + default: + break; + } + } + if (!try_resolving_type) + continue; - DEBUG_PRINTF( - "resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 - " (cu 0x%8.8" PRIx64 ")\n", - die.GetID(), - m_objfile_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"), - type_die.GetID(), type_cu->GetID()); + if (must_be_implementation && + type_die.Supports_DW_AT_APPLE_objc_complete_type()) + try_resolving_type = type_die.GetAttributeValueAsUnsigned( + DW_AT_APPLE_objc_complete_type, 0); + if (!try_resolving_type) + continue; - if (die) - GetDIEToType()[die.GetDIE()] = resolved_type; - type_sp = resolved_type->shared_from_this(); - return false; - }); + Type *resolved_type = ResolveType(type_die, false, true); + if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED) + continue; + + DEBUG_PRINTF( + "resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 + " (cu 0x%8.8" PRIx64 ")\n", + die.GetID(), + m_objfile_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"), + type_die.GetID(), type_cu->GetID()); + + if (die) + GetDIEToType()[die.GetDIE()] = resolved_type; + type_sp = resolved_type->shared_from_this(); + break; + } return type_sp; } @@ -2810,6 +2843,10 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( dwarf_decl_ctx.GetQualifiedName()); } + DIEArray die_offsets; + m_index->GetTypes(dwarf_decl_ctx, die_offsets); + const size_t num_matches = die_offsets.size(); + // Get the type system that we are looking to find a type for. We will // use this to ensure any matches we find are in a language that this // type system supports @@ -2826,12 +2863,12 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( type_system = &type_system_or_err.get(); } } - - m_index->GetTypes(dwarf_decl_ctx, [&](DIERef die_ref) { + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; DWARFDIE type_die = GetDIE(die_ref); if (!type_die) { m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); - return true; + continue; } // Make sure type_die's langauge matches the type system we are @@ -2839,7 +2876,7 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( // are looking for a "Foo" type for C, C++, ObjC, or ObjC++. if (type_system && !type_system->SupportsLanguage(GetLanguage(*type_die.GetCU()))) - return true; + continue; bool try_resolving_type = false; // Don't try and resolve the DIE we are looking for with the DIE @@ -2884,7 +2921,7 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(), qualified_name.c_str()); } - return true; + continue; } DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die); @@ -2902,15 +2939,15 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( // Make sure the decl contexts match all the way up if (dwarf_decl_ctx != type_dwarf_decl_ctx) - return true; + continue; Type *resolved_type = ResolveType(type_die, false); if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED) - return true; + continue; type_sp = resolved_type->shared_from_this(); - return false; - }); + break; + } } } return type_sp; @@ -3054,21 +3091,24 @@ size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) { variables = std::make_shared<VariableList>(); sc.comp_unit->SetVariableList(variables); - m_index->GetGlobalVariables( - dwarf_cu->GetNonSkeletonUnit(), [&](DIERef die_ref) { - DWARFDIE die = GetDIE(die_ref); - if (!die) { - m_index->ReportInvalidDIERef(die_ref, ""); - return true; - } - VariableSP var_sp( - ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); - if (var_sp) { - variables->AddVariableIfUnique(var_sp); - ++vars_added; - } - return true; - }); + DIEArray die_offsets; + m_index->GetGlobalVariables(dwarf_cu->GetNonSkeletonUnit(), + die_offsets); + const size_t num_matches = die_offsets.size(); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; + DWARFDIE die = GetDIE(die_ref); + if (!die) { + m_index->ReportInvalidDIERef(die_ref, ""); + continue; + } + + VariableSP var_sp(ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); + if (var_sp) { + variables->AddVariableIfUnique(var_sp); + ++vars_added; + } + } } return vars_added; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 255fc9093ac1..479235c0d86f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -237,8 +237,8 @@ class SymbolFileDWARF : public lldb_private::SymbolFile, lldb_private::CompileUnit * GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu); - virtual void GetObjCMethods(lldb_private::ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback); + virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name, + DIEArray &method_die_offsets); bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp index 5b232021056f..9bf3206f1c61 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -95,10 +95,10 @@ SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() { return GetBaseSymbolFile().GetForwardDeclClangTypeToDie(); } -void SymbolFileDWARFDwo::GetObjCMethods( - lldb_private::ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback) { - GetBaseSymbolFile().GetObjCMethods(class_name, callback); +size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets( + lldb_private::ConstString class_name, DIEArray &method_die_offsets) { + return GetBaseSymbolFile().GetObjCMethodDIEOffsets(class_name, + method_die_offsets); } UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h index d43579e0e280..ba474f3cd224 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -31,8 +31,8 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF { DWARFCompileUnit *GetDWOCompileUnitForHash(uint64_t hash); - void GetObjCMethods(lldb_private::ConstString class_name, - llvm::function_ref<bool(DIERef ref)> callback) override; + size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name, + DIEArray &method_die_offsets) override; llvm::Expected<lldb_private::TypeSystem &> GetTypeSystemForLanguage(lldb::LanguageType language) override; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits