diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -464,6 +464,12 @@ static bool RemoveSharedModuleIfOrphaned(const Module *module_ptr); + /// Applies 'callback' to each module in this ModuleList. + /// If 'callback' returns false, iteration terminates. + /// The 'module_sp' passed to 'callback' is guaranteed to + /// be non-null. + /// + /// This function is thread-safe. void ForEach(std::function const &callback) const; diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -1067,9 +1067,10 @@ void ModuleList::ForEach( std::function const &callback) const { std::lock_guard guard(m_modules_mutex); - for (const auto &module : m_modules) { + for (const auto &module_sp : m_modules) { + assert(module_sp != nullptr); // If the callback returns false, then stop iterating and break out - if (!callback(module)) + if (!callback(module_sp)) break; } }