Index: lldb/trunk/include/lldb/Core/Module.h =================================================================== --- lldb/trunk/include/lldb/Core/Module.h +++ lldb/trunk/include/lldb/Core/Module.h @@ -447,9 +447,7 @@ /// \param[out] type_list /// A type list gets populated with any matches. /// - /// \return - /// The number of matches added to \a type_list. - size_t + void FindTypes(ConstString type_name, bool exact_match, size_t max_matches, llvm::DenseSet &searched_symbol_files, TypeList &types); @@ -459,8 +457,8 @@ /// This behaves like the other FindTypes method but allows to /// specify a DeclContext and a language for the type being searched /// for. - size_t FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types); + void FindTypes(llvm::ArrayRef pattern, LanguageSet languages, + TypeMap &types); lldb::TypeSP FindFirstType(const SymbolContext &sc, ConstString type_name, bool exact_match); @@ -479,11 +477,9 @@ /// \param[out] type_list /// A type list gets populated with any matches. /// - /// \return - /// The number of matches added to \a type_list. - size_t FindTypesInNamespace(ConstString type_name, - const CompilerDeclContext *parent_decl_ctx, - size_t max_matches, TypeList &type_list); + void FindTypesInNamespace(ConstString type_name, + const CompilerDeclContext *parent_decl_ctx, + size_t max_matches, TypeList &type_list); /// Get const accessor for the module architecture. /// @@ -1074,7 +1070,7 @@ private: Module(); // Only used internally by CreateJITModule () - size_t FindTypes_Impl( + void FindTypes_Impl( ConstString name, const CompilerDeclContext *parent_decl_ctx, size_t max_matches, llvm::DenseSet &searched_symbol_files, Index: lldb/trunk/include/lldb/Core/ModuleList.h =================================================================== --- lldb/trunk/include/lldb/Core/ModuleList.h +++ lldb/trunk/include/lldb/Core/ModuleList.h @@ -393,12 +393,10 @@ /// \param[out] type_list /// A type list gets populated with any matches. /// - /// \return - /// The number of matches added to \a type_list. - size_t FindTypes(Module *search_first, ConstString name, - bool name_is_fully_qualified, size_t max_matches, - llvm::DenseSet &searched_symbol_files, - TypeList &types) const; + void FindTypes(Module *search_first, ConstString name, + bool name_is_fully_qualified, size_t max_matches, + llvm::DenseSet &searched_symbol_files, + TypeList &types) const; bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const; Index: lldb/trunk/include/lldb/Symbol/SymbolFile.h =================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolFile.h +++ lldb/trunk/include/lldb/Symbol/SymbolFile.h @@ -188,7 +188,7 @@ virtual uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, bool append, SymbolContextList &sc_list); - virtual uint32_t + virtual void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, @@ -196,16 +196,16 @@ /// Find types specified by a CompilerContextPattern. /// \param languages Only return results in these languages. - virtual size_t FindTypes(llvm::ArrayRef pattern, + virtual void FindTypes(llvm::ArrayRef pattern, LanguageSet languages, TypeMap &types); virtual void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector &mangled_names); - virtual size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, - lldb::TypeClass type_mask, - lldb_private::TypeList &type_list) = 0; + virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, + lldb::TypeClass type_mask, + lldb_private::TypeList &type_list) = 0; virtual void PreloadSymbols(); Index: lldb/trunk/include/lldb/Symbol/TypeList.h =================================================================== --- lldb/trunk/include/lldb/Symbol/TypeList.h +++ lldb/trunk/include/lldb/Symbol/TypeList.h @@ -28,15 +28,14 @@ void Dump(Stream *s, bool show_context); - // lldb::TypeSP - // FindType(lldb::user_id_t uid); - TypeList FindTypes(ConstString name); void Insert(const lldb::TypeSP &type); uint32_t GetSize() const; + bool Empty() const { return !GetSize(); } + lldb::TypeSP GetTypeAtIndex(uint32_t idx); typedef std::vector collection; Index: lldb/trunk/source/API/SBModule.cpp =================================================================== --- lldb/trunk/source/API/SBModule.cpp +++ lldb/trunk/source/API/SBModule.cpp @@ -503,16 +503,10 @@ const bool exact_match = false; ConstString name(type); llvm::DenseSet searched_symbol_files; - const uint32_t num_matches = module_sp->FindTypes( - name, exact_match, UINT32_MAX, searched_symbol_files, type_list); + module_sp->FindTypes(name, exact_match, UINT32_MAX, searched_symbol_files, + type_list); - if (num_matches > 0) { - for (size_t idx = 0; idx < num_matches; idx++) { - TypeSP type_sp(type_list.GetTypeAtIndex(idx)); - if (type_sp) - retval.Append(SBType(type_sp)); - } - } else { + if (type_list.Empty()) { auto type_system_or_err = module_sp->GetTypeSystemForLanguage(eLanguageTypeC); if (auto err = type_system_or_err.takeError()) { @@ -523,9 +517,14 @@ if (compiler_type) retval.Append(SBType(compiler_type)); } + } else { + for (size_t idx = 0; idx < type_list.GetSize(); idx++) { + TypeSP type_sp(type_list.GetTypeAtIndex(idx)); + if (type_sp) + retval.Append(SBType(type_sp)); + } } } - return LLDB_RECORD_RESULT(retval); } Index: lldb/trunk/source/API/SBTarget.cpp =================================================================== --- lldb/trunk/source/API/SBTarget.cpp +++ lldb/trunk/source/API/SBTarget.cpp @@ -1891,16 +1891,13 @@ bool exact_match = false; TypeList type_list; llvm::DenseSet searched_symbol_files; - uint32_t num_matches = - images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX, - searched_symbol_files, type_list); - - if (num_matches > 0) { - for (size_t idx = 0; idx < num_matches; idx++) { - TypeSP type_sp(type_list.GetTypeAtIndex(idx)); - if (type_sp) - sb_type_list.Append(SBType(type_sp)); - } + images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX, + searched_symbol_files, type_list); + + for (size_t idx = 0; idx < type_list.GetSize(); idx++) { + TypeSP type_sp(type_list.GetTypeAtIndex(idx)); + if (type_sp) + sb_type_list.Append(SBType(type_sp)); } // Try the loaded language runtimes Index: lldb/trunk/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/trunk/source/Commands/CommandObjectTarget.cpp +++ lldb/trunk/source/Commands/CommandObjectTarget.cpp @@ -1629,75 +1629,30 @@ static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name_cstr, bool name_is_regex) { + TypeList type_list; if (module && name_cstr && name_cstr[0]) { - TypeList type_list; const uint32_t max_num_matches = UINT32_MAX; size_t num_matches = 0; bool name_is_fully_qualified = false; ConstString name(name_cstr); llvm::DenseSet searched_symbol_files; - num_matches = - module->FindTypes(name, name_is_fully_qualified, max_num_matches, - searched_symbol_files, type_list); - - if (num_matches) { - strm.Indent(); - strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, - num_matches > 1 ? "es" : ""); - DumpFullpath(strm, &module->GetFileSpec(), 0); - strm.PutCString(":\n"); - for (TypeSP type_sp : type_list.Types()) { - if (type_sp) { - // Resolve the clang type so that any forward references to types - // that haven't yet been parsed will get parsed. - type_sp->GetFullCompilerType(); - type_sp->GetDescription(&strm, eDescriptionLevelFull, true); - // Print all typedef chains - TypeSP typedef_type_sp(type_sp); - TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType()); - while (typedefed_type_sp) { - strm.EOL(); - strm.Printf(" typedef '%s': ", - typedef_type_sp->GetName().GetCString()); - typedefed_type_sp->GetFullCompilerType(); - typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, - true); - typedef_type_sp = typedefed_type_sp; - typedefed_type_sp = typedef_type_sp->GetTypedefType(); - } - } - strm.EOL(); - } - } - return num_matches; - } - return 0; -} + module->FindTypes(name, name_is_fully_qualified, max_num_matches, + searched_symbol_files, type_list); -static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm, - Module &module, const char *name_cstr, - bool name_is_regex) { - TypeList type_list; - const uint32_t max_num_matches = UINT32_MAX; - size_t num_matches = 1; - bool name_is_fully_qualified = false; + if (type_list.Empty()) + return 0; - ConstString name(name_cstr); - llvm::DenseSet searched_symbol_files; - num_matches = module.FindTypes(name, name_is_fully_qualified, max_num_matches, - searched_symbol_files, type_list); - - if (num_matches) { strm.Indent(); - strm.PutCString("Best match found in "); - DumpFullpath(strm, &module.GetFileSpec(), 0); + strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, + num_matches > 1 ? "es" : ""); + DumpFullpath(strm, &module->GetFileSpec(), 0); strm.PutCString(":\n"); - - TypeSP type_sp(type_list.GetTypeAtIndex(0)); - if (type_sp) { - // Resolve the clang type so that any forward references to types that - // haven't yet been parsed will get parsed. + for (TypeSP type_sp : type_list.Types()) { + if (!type_sp) + continue; + // Resolve the clang type so that any forward references to types + // that haven't yet been parsed will get parsed. type_sp->GetFullCompilerType(); type_sp->GetDescription(&strm, eDescriptionLevelFull, true); // Print all typedef chains @@ -1715,7 +1670,50 @@ } strm.EOL(); } - return num_matches; + return type_list.GetSize(); +} + +static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm, + Module &module, const char *name_cstr, + bool name_is_regex) { + TypeList type_list; + const uint32_t max_num_matches = UINT32_MAX; + bool name_is_fully_qualified = false; + + ConstString name(name_cstr); + llvm::DenseSet searched_symbol_files; + module.FindTypes(name, name_is_fully_qualified, max_num_matches, + searched_symbol_files, type_list); + + if (type_list.Empty()) + return 0; + + strm.Indent(); + strm.PutCString("Best match found in "); + DumpFullpath(strm, &module.GetFileSpec(), 0); + strm.PutCString(":\n"); + + TypeSP type_sp(type_list.GetTypeAtIndex(0)); + if (type_sp) { + // Resolve the clang type so that any forward references to types that + // haven't yet been parsed will get parsed. + type_sp->GetFullCompilerType(); + type_sp->GetDescription(&strm, eDescriptionLevelFull, true); + // Print all typedef chains + TypeSP typedef_type_sp(type_sp); + TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType()); + while (typedefed_type_sp) { + strm.EOL(); + strm.Printf(" typedef '%s': ", + typedef_type_sp->GetName().GetCString()); + typedefed_type_sp->GetFullCompilerType(); + typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true); + typedef_type_sp = typedefed_type_sp; + typedefed_type_sp = typedef_type_sp->GetTypedefType(); + } + } + strm.EOL(); + return type_list.GetSize(); } static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter, Index: lldb/trunk/source/Core/Module.cpp =================================================================== --- lldb/trunk/source/Core/Module.cpp +++ lldb/trunk/source/Core/Module.cpp @@ -939,7 +939,7 @@ } } -size_t Module::FindTypes_Impl( +void Module::FindTypes_Impl( ConstString name, const CompilerDeclContext *parent_decl_ctx, size_t max_matches, llvm::DenseSet &searched_symbol_files, @@ -947,42 +947,38 @@ static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); if (SymbolFile *symbols = GetSymbolFile()) - return symbols->FindTypes(name, parent_decl_ctx, max_matches, - searched_symbol_files, types); - return 0; + symbols->FindTypes(name, parent_decl_ctx, max_matches, + searched_symbol_files, types); } -size_t Module::FindTypesInNamespace(ConstString type_name, - const CompilerDeclContext *parent_decl_ctx, - size_t max_matches, TypeList &type_list) { +void Module::FindTypesInNamespace(ConstString type_name, + const CompilerDeclContext *parent_decl_ctx, + size_t max_matches, TypeList &type_list) { TypeMap types_map; llvm::DenseSet searched_symbol_files; - size_t num_types = FindTypes_Impl(type_name, parent_decl_ctx, max_matches, - searched_symbol_files, types_map); - if (num_types > 0) { + FindTypes_Impl(type_name, parent_decl_ctx, max_matches, searched_symbol_files, + types_map); + if (types_map.GetSize()) { SymbolContext sc; sc.module_sp = shared_from_this(); sc.SortTypeList(types_map, type_list); } - return num_types; } lldb::TypeSP Module::FindFirstType(const SymbolContext &sc, ConstString name, bool exact_match) { TypeList type_list; llvm::DenseSet searched_symbol_files; - const size_t num_matches = - FindTypes(name, exact_match, 1, searched_symbol_files, type_list); - if (num_matches) + FindTypes(name, exact_match, 1, searched_symbol_files, type_list); + if (type_list.GetSize()) return type_list.GetTypeAtIndex(0); return TypeSP(); } -size_t Module::FindTypes( +void Module::FindTypes( ConstString name, bool exact_match, size_t max_matches, llvm::DenseSet &searched_symbol_files, TypeList &types) { - size_t num_matches = 0; const char *type_name_cstr = name.GetCString(); llvm::StringRef type_scope; llvm::StringRef type_basename; @@ -998,12 +994,11 @@ exact_match = type_scope.consume_front("::"); ConstString type_basename_const_str(type_basename); - if (FindTypes_Impl(type_basename_const_str, nullptr, max_matches, - searched_symbol_files, typesmap)) { + FindTypes_Impl(type_basename_const_str, nullptr, max_matches, + searched_symbol_files, typesmap); + if (typesmap.GetSize()) typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class, exact_match); - num_matches = typesmap.GetSize(); - } } else { // The type is not in a namespace/class scope, just search for it by // basename @@ -1014,33 +1009,28 @@ searched_symbol_files, typesmap); typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class, exact_match); - num_matches = typesmap.GetSize(); } else { - num_matches = FindTypes_Impl(name, nullptr, UINT_MAX, - searched_symbol_files, typesmap); + FindTypes_Impl(name, nullptr, UINT_MAX, searched_symbol_files, typesmap); if (exact_match) { std::string name_str(name.AsCString("")); typesmap.RemoveMismatchedTypes(type_scope, name_str, type_class, exact_match); - num_matches = typesmap.GetSize(); } } } - if (num_matches > 0) { + if (typesmap.GetSize()) { SymbolContext sc; sc.module_sp = shared_from_this(); sc.SortTypeList(typesmap, types); } - return num_matches; } -size_t Module::FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types) { +void Module::FindTypes(llvm::ArrayRef pattern, + LanguageSet languages, TypeMap &types) { static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); if (SymbolFile *symbols = GetSymbolFile()) - return symbols->FindTypes(pattern, languages, types); - return 0; + symbols->FindTypes(pattern, languages, types); } SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) { Index: lldb/trunk/source/Core/ModuleList.cpp =================================================================== --- lldb/trunk/source/Core/ModuleList.cpp +++ lldb/trunk/source/Core/ModuleList.cpp @@ -17,6 +17,7 @@ #include "lldb/Symbol/LocateSymbolFile.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/VariableList.h" #include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/ConstString.h" @@ -56,9 +57,6 @@ namespace lldb_private { class Target; } -namespace lldb_private { -class TypeList; -} using namespace lldb; using namespace lldb_private; @@ -525,44 +523,36 @@ return module_sp; } -size_t -ModuleList::FindTypes(Module *search_first, ConstString name, - bool name_is_fully_qualified, size_t max_matches, - llvm::DenseSet &searched_symbol_files, - TypeList &types) const { +void ModuleList::FindTypes(Module *search_first, ConstString name, + bool name_is_fully_qualified, size_t max_matches, + llvm::DenseSet &searched_symbol_files, + TypeList &types) const { std::lock_guard guard(m_modules_mutex); - size_t total_matches = 0; collection::const_iterator pos, end = m_modules.end(); if (search_first) { for (pos = m_modules.begin(); pos != end; ++pos) { if (search_first == pos->get()) { - total_matches += - search_first->FindTypes(name, name_is_fully_qualified, max_matches, - searched_symbol_files, types); + search_first->FindTypes(name, name_is_fully_qualified, max_matches, + searched_symbol_files, types); - if (total_matches >= max_matches) - break; + if (types.GetSize() >= max_matches) + return; } } } - if (total_matches < max_matches) { - for (pos = m_modules.begin(); pos != end; ++pos) { - // Search the module if the module is not equal to the one in the symbol - // context "sc". If "sc" contains a empty module shared pointer, then the - // comparison will always be true (valid_module_ptr != nullptr). - if (search_first != pos->get()) - total_matches += - (*pos)->FindTypes(name, name_is_fully_qualified, max_matches, - searched_symbol_files, types); + for (pos = m_modules.begin(); pos != end; ++pos) { + // Search the module if the module is not equal to the one in the symbol + // context "sc". If "sc" contains a empty module shared pointer, then the + // comparison will always be true (valid_module_ptr != nullptr). + if (search_first != pos->get()) + (*pos)->FindTypes(name, name_is_fully_qualified, max_matches, + searched_symbol_files, types); - if (total_matches >= max_matches) - break; - } + if (types.GetSize() >= max_matches) + return; } - - return total_matches; } bool ModuleList::FindSourceFile(const FileSpec &orig_spec, Index: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp =================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -95,31 +95,27 @@ const bool exact_match = true; TypeList class_types; - uint32_t num_matches = 0; // First look in the module that the vtable symbol came from and // look for a single exact match. llvm::DenseSet searched_symbol_files; - if (sc.module_sp) { - num_matches = sc.module_sp->FindTypes( - ConstString(lookup_name), exact_match, 1, - searched_symbol_files, class_types); - } + if (sc.module_sp) + sc.module_sp->FindTypes(ConstString(lookup_name), exact_match, 1, + searched_symbol_files, class_types); // If we didn't find a symbol, then move on to the entire module // list in the target and get as many unique matches as possible - if (num_matches == 0) { - num_matches = target.GetImages().FindTypes( - nullptr, ConstString(lookup_name), exact_match, UINT32_MAX, - searched_symbol_files, class_types); - } + if (class_types.Empty()) + target.GetImages().FindTypes(nullptr, ConstString(lookup_name), + exact_match, UINT32_MAX, + searched_symbol_files, class_types); lldb::TypeSP type_sp; - if (num_matches == 0) { + if (class_types.Empty()) { LLDB_LOGF(log, "0x%16.16" PRIx64 ": is not dynamic\n", original_ptr); return TypeAndOrName(); } - if (num_matches == 1) { + if (class_types.GetSize() == 1) { type_sp = class_types.GetTypeAtIndex(0); if (type_sp) { if (ClangASTContext::IsCXXClassType( @@ -134,10 +130,10 @@ type_info.SetTypeSP(type_sp); } } - } else if (num_matches > 1) { + } else { size_t i; if (log) { - for (i = 0; i < num_matches; i++) { + for (i = 0; i < class_types.GetSize(); i++) { type_sp = class_types.GetTypeAtIndex(i); if (type_sp) { LLDB_LOGF( @@ -151,7 +147,7 @@ } } - for (i = 0; i < num_matches; i++) { + for (i = 0; i < class_types.GetSize(); i++) { type_sp = class_types.GetTypeAtIndex(i); if (type_sp) { if (ClangASTContext::IsCXXClassType( @@ -168,7 +164,7 @@ } } - if (log && i == num_matches) { + if (log) { LLDB_LOGF(log, "0x%16.16" PRIx64 ": static-type = '%s' has multiple matching dynamic " Index: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp =================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp @@ -121,20 +121,17 @@ TypeList types; llvm::DenseSet searched_symbol_files; - const uint32_t num_types = module_sp->FindTypes( - name, exact_match, max_matches, searched_symbol_files, types); + module_sp->FindTypes(name, exact_match, max_matches, searched_symbol_files, + types); - if (num_types) { - uint32_t i; - for (i = 0; i < num_types; ++i) { - TypeSP type_sp(types.GetTypeAtIndex(i)); - - if (ClangASTContext::IsObjCObjectOrInterfaceType( - type_sp->GetForwardCompilerType())) { - if (type_sp->IsCompleteObjCClass()) { - m_complete_class_cache[name] = type_sp; - return type_sp; - } + for (uint32_t i = 0; i < types.GetSize(); ++i) { + TypeSP type_sp(types.GetTypeAtIndex(i)); + + if (ClangASTContext::IsObjCObjectOrInterfaceType( + type_sp->GetForwardCompilerType())) { + if (type_sp->IsCompleteObjCClass()) { + m_complete_class_cache[name] = type_sp; + return type_sp; } } } Index: lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h +++ lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h @@ -97,10 +97,8 @@ lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) override; - size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, - TypeList &type_list) override { - return 0; - } + void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, + TypeList &type_list) override {} uint32_t FindFunctions(ConstString name, const CompilerDeclContext *parent_decl_ctx, @@ -111,14 +109,13 @@ uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, bool append, SymbolContextList &sc_list) override; - uint32_t FindTypes(ConstString name, - const CompilerDeclContext *parent_decl_ctx, - uint32_t max_matches, - llvm::DenseSet &searched_symbol_files, - TypeMap &types) override; + void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, + uint32_t max_matches, + llvm::DenseSet &searched_symbol_files, + TypeMap &types) override; - size_t FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types) override; + void FindTypes(llvm::ArrayRef pattern, LanguageSet languages, + TypeMap &types) override; llvm::Expected GetTypeSystemForLanguage(lldb::LanguageType language) override { Index: lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp +++ lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp @@ -308,17 +308,13 @@ return sc_list.GetSize(); } -uint32_t SymbolFileBreakpad::FindTypes( +void SymbolFileBreakpad::FindTypes( ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, - TypeMap &types) { - return 0; -} + TypeMap &types) {} -size_t SymbolFileBreakpad::FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types) { - return 0; -} +void SymbolFileBreakpad::FindTypes(llvm::ArrayRef pattern, + LanguageSet languages, TypeMap &types) {} void SymbolFileBreakpad::AddSymbols(Symtab &symtab) { Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -151,8 +151,8 @@ // The type in the Clang module must have the same langage as the current CU. LanguageSet languages; languages.Insert(die.GetCU()->GetLanguageType()); - if (!dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, - dwo_types)) { + dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, dwo_types); + if (dwo_types.GetSize()) { if (!IsClangModuleFwdDecl(die)) return TypeSP(); @@ -162,8 +162,9 @@ for (const auto &name_module : sym_file.getExternalTypeModules()) { if (!name_module.second) continue; - if (name_module.second->GetSymbolFile()->FindTypes(decl_context, - languages, dwo_types)) + name_module.second->GetSymbolFile()->FindTypes(decl_context, + languages, dwo_types); + if (dwo_types.GetSize()) break; } } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -181,20 +181,20 @@ const std::string &scope_qualified_name, std::vector &mangled_names) override; - uint32_t + void FindTypes(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, lldb_private::TypeMap &types) override; - size_t FindTypes(llvm::ArrayRef pattern, - lldb_private::LanguageSet languages, - lldb_private::TypeMap &types) override; - - size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, - lldb::TypeClass type_mask, - lldb_private::TypeList &type_list) override; + void FindTypes(llvm::ArrayRef pattern, + lldb_private::LanguageSet languages, + lldb_private::TypeMap &types) override; + + void GetTypes(lldb_private::SymbolContextScope *sc_scope, + lldb::TypeClass type_mask, + lldb_private::TypeList &type_list) override; llvm::Expected GetTypeSystemForLanguage(lldb::LanguageType language) override; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -335,8 +335,8 @@ } } -size_t SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope, - TypeClass type_mask, TypeList &type_list) +void SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope, + TypeClass type_mask, TypeList &type_list) { std::lock_guard guard(GetModuleMutex()); @@ -349,8 +349,8 @@ if (comp_unit) { dwarf_cu = GetDWARFCompileUnit(comp_unit); - if (dwarf_cu == nullptr) - return 0; + if (!dwarf_cu) + return; GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(), dwarf_cu->GetNextUnitOffset(), type_mask, type_set); } else { @@ -367,16 +367,13 @@ } std::set compiler_type_set; - size_t num_types_added = 0; for (Type *type : type_set) { CompilerType compiler_type = type->GetForwardCompilerType(); if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) { compiler_type_set.insert(compiler_type); type_list.Insert(type->shared_from_this()); - ++num_types_added; } } - return num_types_added; } // Gets the first parent that is a lexical block, function or inlined @@ -2383,7 +2380,7 @@ } } -uint32_t SymbolFileDWARF::FindTypes( +void SymbolFileDWARF::FindTypes( ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, @@ -2391,13 +2388,13 @@ std::lock_guard guard(GetModuleMutex()); // Make sure we haven't already searched this SymbolFile before... if (searched_symbol_files.count(this)) - return 0; - else - searched_symbol_files.insert(this); + return; + + searched_symbol_files.insert(this); DWARFDebugInfo *info = DebugInfo(); - if (info == nullptr) - return 0; + if (!info) + return; Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); @@ -2418,12 +2415,11 @@ } if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) - return 0; + return; DIEArray die_offsets; m_index->GetTypes(name, die_offsets); const size_t num_die_matches = die_offsets.size(); - const uint32_t initial_types_size = types.GetSize(); for (size_t i = 0; i < num_die_matches; ++i) { const DIERef &die_ref = die_offsets[i]; @@ -2458,8 +2454,7 @@ searched_symbol_files, types); } - uint32_t num_matches = types.GetSize() - initial_types_size; - if (log && num_matches) { + if (log && types.GetSize()) { if (parent_decl_ctx) { GetObjectFile()->GetModule()->LogMessage( log, @@ -2467,60 +2462,53 @@ "= %p (\"%s\"), max_matches=%u, type_list) => %u", name.GetCString(), static_cast(parent_decl_ctx), parent_decl_ctx->GetName().AsCString(""), max_matches, - num_matches); + types.GetSize()); } else { GetObjectFile()->GetModule()->LogMessage( log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " "= NULL, max_matches=%u, type_list) => %u", - name.GetCString(), max_matches, num_matches); + name.GetCString(), max_matches, types.GetSize()); } } - - return num_matches; } -size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef pattern, +void SymbolFileDWARF::FindTypes(llvm::ArrayRef pattern, LanguageSet languages, TypeMap &types) { std::lock_guard guard(GetModuleMutex()); if (pattern.empty()) - return 0; + return; ConstString name = pattern.back().name; if (!name) - return 0; + return; DIEArray die_offsets; m_index->GetTypes(name, die_offsets); const size_t num_die_matches = die_offsets.size(); - size_t num_matches = 0; for (size_t i = 0; i < num_die_matches; ++i) { const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); - if (die) { - if (!languages[die.GetCU()->GetLanguageType()]) - continue; - - llvm::SmallVector die_context; - die.GetDeclContext(die_context); - if (!contextMatches(die_context, pattern)) - continue; - - Type *matching_type = ResolveType(die, true, true); - if (matching_type) { - // We found a type pointer, now find the shared pointer form our type - // list - types.InsertUnique(matching_type->shared_from_this()); - ++num_matches; - } - } else { + if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + continue; } + if (!languages[die.GetCU()->GetLanguageType()]) + continue; + + llvm::SmallVector die_context; + die.GetDeclContext(die_context); + if (!contextMatches(die_context, pattern)) + 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 num_matches; } CompilerDeclContext Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -108,7 +108,7 @@ uint32_t FindFunctions(const lldb_private::RegularExpression ®ex, bool include_inlines, bool append, lldb_private::SymbolContextList &sc_list) override; - uint32_t + void FindTypes(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, @@ -117,9 +117,9 @@ lldb_private::CompilerDeclContext FindNamespace( lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx) override; - size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, - lldb::TypeClass type_mask, - lldb_private::TypeList &type_list) override; + void GetTypes(lldb_private::SymbolContextScope *sc_scope, + lldb::TypeClass type_mask, + lldb_private::TypeList &type_list) override; std::vector ParseCallEdgesInFunction(lldb_private::UserID func_id) override; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -1070,16 +1070,15 @@ return sc_list.GetSize() - initial_size; } -size_t SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope, - lldb::TypeClass type_mask, - TypeList &type_list) { +void SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope, + lldb::TypeClass type_mask, + TypeList &type_list) { std::lock_guard guard(GetModuleMutex()); static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)", type_mask); - uint32_t initial_size = type_list.GetSize(); SymbolFileDWARF *oso_dwarf = nullptr; if (sc_scope) { SymbolContext sc; @@ -1097,7 +1096,6 @@ return false; }); } - return type_list.GetSize() - initial_size; } std::vector @@ -1199,21 +1197,17 @@ return TypeSP(); } -uint32_t SymbolFileDWARFDebugMap::FindTypes( +void SymbolFileDWARFDebugMap::FindTypes( ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, TypeMap &types) { std::lock_guard guard(GetModuleMutex()); - const uint32_t initial_types_size = types.GetSize(); - ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { oso_dwarf->FindTypes(name, parent_decl_ctx, max_matches, searched_symbol_files, types); return types.GetSize() >= max_matches; }); - - return types.GetSize() - initial_types_size; } // Index: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h +++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h @@ -116,8 +116,8 @@ lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) override; - size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, - TypeList &type_list) override; + void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, + TypeList &type_list) override; uint32_t FindFunctions(ConstString name, const CompilerDeclContext *parent_decl_ctx, @@ -128,14 +128,13 @@ uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, bool append, SymbolContextList &sc_list) override; - uint32_t FindTypes(ConstString name, - const CompilerDeclContext *parent_decl_ctx, - uint32_t max_matches, - llvm::DenseSet &searched_symbol_files, - TypeMap &types) override; + void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, + uint32_t max_matches, + llvm::DenseSet &searched_symbol_files, + TypeMap &types) override; - size_t FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types) override; + void FindTypes(llvm::ArrayRef pattern, LanguageSet languages, + TypeMap &types) override; llvm::Expected GetTypeSystemForLanguage(lldb::LanguageType language) override; @@ -158,8 +157,8 @@ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; - size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches, - TypeMap &types); + void FindTypesByName(llvm::StringRef name, uint32_t max_matches, + TypeMap &types); lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, const llvm::codeview::ModifierRecord &mr, Index: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -1250,33 +1250,28 @@ return 0; } -uint32_t SymbolFileNativePDB::FindTypes( +void SymbolFileNativePDB::FindTypes( ConstString name, const CompilerDeclContext *parent_decl_ctx, - uint32_t max_matches, - llvm::DenseSet &searched_symbol_files, TypeMap &types) { + uint32_t max_matches, llvm::DenseSet &searched_symbol_files, + TypeMap &types) { std::lock_guard guard(GetModuleMutex()); if (!name) - return 0; + return; searched_symbol_files.clear(); searched_symbol_files.insert(this); // There is an assumption 'name' is not a regex - size_t match_count = FindTypesByName(name.GetStringRef(), max_matches, types); - - return match_count; + FindTypesByName(name.GetStringRef(), max_matches, types); } -size_t SymbolFileNativePDB::FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types) { - return 0; -} +void SymbolFileNativePDB::FindTypes(llvm::ArrayRef pattern, + LanguageSet languages, TypeMap &types) {} -size_t SymbolFileNativePDB::FindTypesByName(llvm::StringRef name, - uint32_t max_matches, - TypeMap &types) { +void SymbolFileNativePDB::FindTypesByName(llvm::StringRef name, + uint32_t max_matches, + TypeMap &types) { - size_t match_count = 0; std::vector matches = m_index->tpi().findRecordsByName(name); if (max_matches > 0 && max_matches < matches.size()) matches.resize(max_matches); @@ -1287,9 +1282,7 @@ continue; types.Insert(type); - ++match_count; } - return match_count; } size_t SymbolFileNativePDB::ParseTypes(CompileUnit &comp_unit) { @@ -1578,11 +1571,9 @@ return m_ast->CompleteType(qt); } -size_t SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, - TypeClass type_mask, - lldb_private::TypeList &type_list) { - return 0; -} +void SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, + TypeClass type_mask, + lldb_private::TypeList &type_list) {} CompilerDeclContext SymbolFileNativePDB::FindNamespace(ConstString name, Index: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h +++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h @@ -71,9 +71,9 @@ lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override; - size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, - lldb::TypeClass type_mask, - lldb_private::TypeList &type_list) override; + void GetTypes(lldb_private::SymbolContextScope *sc_scope, + lldb::TypeClass type_mask, + lldb_private::TypeList &type_list) override; // PluginInterface protocol lldb_private::ConstString GetPluginName() override; Index: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp +++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp @@ -47,11 +47,9 @@ return new SymbolFileSymtab(std::move(objfile_sp)); } -size_t SymbolFileSymtab::GetTypes(SymbolContextScope *sc_scope, - TypeClass type_mask, - lldb_private::TypeList &type_list) { - return 0; -} +void SymbolFileSymtab::GetTypes(SymbolContextScope *sc_scope, + TypeClass type_mask, + lldb_private::TypeList &type_list) {} SymbolFileSymtab::SymbolFileSymtab(ObjectFileSP objfile_sp) : SymbolFile(std::move(objfile_sp)), m_source_indexes(), m_func_indexes(), Index: lldb/trunk/source/Symbol/SymbolFile.cpp =================================================================== --- lldb/trunk/source/Symbol/SymbolFile.cpp +++ lldb/trunk/source/Symbol/SymbolFile.cpp @@ -139,18 +139,14 @@ return; } -uint32_t SymbolFile::FindTypes( +void SymbolFile::FindTypes( ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, - TypeMap &types) { - return 0; -} + TypeMap &types) {} -size_t SymbolFile::FindTypes(llvm::ArrayRef pattern, - LanguageSet languages, TypeMap &types) { - return 0; -} +void SymbolFile::FindTypes(llvm::ArrayRef pattern, + LanguageSet languages, TypeMap &types) {} void SymbolFile::AssertModuleLock() { // The code below is too expensive to leave enabled in release builds. It's Index: lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp =================================================================== --- lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp +++ lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp @@ -355,8 +355,7 @@ llvm::pdb::IPDBSession &session = symfile->GetPDBSession(); llvm::DenseSet searched_files; TypeMap results; - symfile->FindTypes(ConstString("Class"), nullptr, false, 0, searched_files, - results); + symfile->FindTypes(ConstString("Class"), nullptr, 0, searched_files, results); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP udt_type = results.GetTypeAtIndex(0); EXPECT_EQ(ConstString("Class"), udt_type->GetName()); @@ -385,8 +384,7 @@ llvm::dyn_cast_or_null(&clang_ast_ctx_or_err.get()); EXPECT_NE(nullptr, clang_ast_ctx); - symfile->FindTypes(ConstString("Class"), nullptr, false, 0, searched_files, - results); + symfile->FindTypes(ConstString("Class"), nullptr, 0, searched_files, results); EXPECT_EQ(1u, results.GetSize()); auto Class = results.GetTypeAtIndex(0); @@ -404,8 +402,8 @@ // compiler type for both, but `FindTypes` may return more than one type // (with the same compiler type) because the symbols have different IDs. auto ClassCompilerDeclCtx = CompilerDeclContext(clang_ast_ctx, ClassDeclCtx); - symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, false, - 0, searched_files, results); + symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, 0, + searched_files, results); EXPECT_LE(1u, results.GetSize()); lldb::TypeSP udt_type = results.GetTypeAtIndex(0); @@ -449,8 +447,8 @@ auto ns_namespace = symfile->FindNamespace(ConstString("NS"), nullptr); EXPECT_TRUE(ns_namespace.IsValid()); - symfile->FindTypes(ConstString("NSClass"), &ns_namespace, false, - 0, searched_files, results); + symfile->FindTypes(ConstString("NSClass"), &ns_namespace, 0, searched_files, + results); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP udt_type = results.GetTypeAtIndex(0); @@ -475,8 +473,7 @@ const char *EnumsToCheck[] = {"Enum", "ShortEnum"}; for (auto Enum : EnumsToCheck) { TypeMap results; - symfile->FindTypes(ConstString(Enum), nullptr, false, 0, - searched_files, results); + symfile->FindTypes(ConstString(Enum), nullptr, 0, searched_files, results); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP enum_type = results.GetTypeAtIndex(0); EXPECT_EQ(ConstString(Enum), enum_type->GetName()); @@ -524,8 +521,8 @@ "VariadicFuncPointerTypedef"}; for (auto Typedef : TypedefsToCheck) { TypeMap results; - symfile->FindTypes(ConstString(Typedef), nullptr, false, 0, - searched_files, results); + symfile->FindTypes(ConstString(Typedef), nullptr, 0, searched_files, + results); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP typedef_type = results.GetTypeAtIndex(0); EXPECT_EQ(ConstString(Typedef), typedef_type->GetName()); @@ -570,7 +567,7 @@ llvm::DenseSet searched_files; TypeMap results; const ConstString name("ClassTypedef"); - symfile->FindTypes(name, nullptr, false, 0, searched_files, results); + symfile->FindTypes(name, nullptr, 0, searched_files, results); // Try to limit ourselves from 1 to 10 results, otherwise we could be doing // this thousands of times. // The idea is just to make sure that for a variety of values, the number of @@ -579,7 +576,7 @@ uint32_t iterations = std::min(results.GetSize(), 10u); uint32_t num_results = results.GetSize(); for (uint32_t i = 1; i <= iterations; ++i) { - symfile->FindTypes(name, nullptr, false, i, searched_files, results); + symfile->FindTypes(name, nullptr, i, searched_files, results); uint32_t num_limited_results = results.GetSize() - num_results); EXPECT_EQ(i, num_limited_results); EXPECT_EQ(num_limited_results, results.GetSize()); @@ -595,7 +592,7 @@ static_cast(module->GetSymbolFile()); llvm::DenseSet searched_files; TypeMap results; - symfile->FindTypes(ConstString(), nullptr, false, 0, searched_files, results); + symfile->FindTypes(ConstString(), nullptr, 0, searched_files, results); EXPECT_EQ(0u, results.GetSize()); }