[Lldb-commits] [lldb] 8359900 - [lldb][Module] Document ModuleList::ForEach and assert nullness
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 2 02:53:08 PST 2022
Author: Michael Buch
Date: 2022-12-02T10:52:39Z
New Revision: 83599000e1f4b30d93b8f4509011b9b68d722835
URL: https://github.com/llvm/llvm-project/commit/83599000e1f4b30d93b8f4509011b9b68d722835
DIFF: https://github.com/llvm/llvm-project/commit/83599000e1f4b30d93b8f4509011b9b68d722835.diff
LOG: [lldb][Module] Document ModuleList::ForEach and assert nullness
Currently all callsites already assume the pointer is non-null.
This patch just asserts this assumption.
This is practically enforced by `ModuleList::Append`
which won't add `nullptr`s to `m_modules`.
Differential Revision: https://reviews.llvm.org/D139082
Added:
Modified:
lldb/include/lldb/Core/ModuleList.h
lldb/source/Core/ModuleList.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h
index 1630a6d58c570..3ae56f17db744 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -464,6 +464,12 @@ class ModuleList {
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<bool(const lldb::ModuleSP &module_sp)> const
&callback) const;
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index f87a2856ab16a..991163c63dc50 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1067,9 +1067,10 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
void ModuleList::ForEach(
std::function<bool(const ModuleSP &module_sp)> const &callback) const {
std::lock_guard<std::recursive_mutex> 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;
}
}
More information about the lldb-commits
mailing list