================ @@ -755,11 +755,237 @@ size_t ModuleList::GetIndexForModule(const Module *module) const { } namespace { +/// A wrapper around ModuleList for shared modules. Provides fast lookups for +/// file-based ModuleSpec queries. +class SharedModuleList { +public: + /// Finds all the modules matching the module_spec, and adds them to \p + /// matching_module_list. + void FindModules(const ModuleSpec &module_spec, + ModuleList &matching_module_list) const { + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + // Try index first for performance - if found, skip expensive full list + // search + if (FindModulesInIndex(module_spec, matching_module_list)) + return; + m_list.FindModules(module_spec, matching_module_list); + // Assertion validates that if we found modules in the list but not the + // index, it's because the module_spec has no filename or the found module + // has a different filename (e.g., when searching by UUID and finding a + // module with an alias) + assert((matching_module_list.IsEmpty() || + module_spec.GetFileSpec().GetFilename().IsEmpty() || + module_spec.GetFileSpec().GetFilename() != + matching_module_list.GetModuleAtIndex(0) + ->GetFileSpec() + .GetFilename()) && + "Search by name not found in SharedModuleList's index"); + } + + ModuleSP FindModule(const Module *module_ptr) { + if (!module_ptr) + return ModuleSP(); + + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + // Try index first, fallback to full list search + if (ModuleSP result = FindModuleInIndex(module_ptr)) + return result; + return m_list.FindModule(module_ptr); + } + + // UUID searches bypass index since UUIDs aren't indexed by filename + ModuleSP FindModule(const UUID &uuid) const { + return m_list.FindModule(uuid); + } + + void Append(const ModuleSP &module_sp, bool use_notifier) { + if (!module_sp) + return; + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + m_list.Append(module_sp, use_notifier); + AddToIndex(module_sp); + } + + size_t RemoveOrphans(bool mandatory) { + std::unique_lock<std::recursive_mutex> lock(GetMutex(), std::defer_lock); + if (mandatory) { + lock.lock(); + } else { + // Skip orphan removal if mutex unavailable (non-blocking) ---------------- JDevlieghere wrote:
```suggestion // Skip orphan removal if mutex is unavailable. (non-blocking) ``` https://github.com/llvm/llvm-project/pull/152054 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits