[Lldb-commits] [lldb] [lldb] Remove raw access to PluginInstances vector (PR #132884)
David Peixotto via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 28 16:04:34 PDT 2025
https://github.com/dmpots updated https://github.com/llvm/llvm-project/pull/132884
>From 6edc108199044d30eed396145aab463db40d6351 Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Thu, 13 Mar 2025 16:13:45 -0700
Subject: [PATCH 1/2] Remove raw access to PluginInstances vector
This commit modifies the PluginInstances class to remove direct access
to the m_instances vector. Instead, we expose a new
`ForEachEnabledPlugin` method that takes a callback to operate on each
plugin. All external iteration over the instances is updated to use the
new method.
The motivation for the change is to allow modifying the way we store
instances without having to change all the clients. This is a
preliminary change to allow enabling/disabling of plugins in which case
we want to iterate over only enabled plugins.
We also considered using a custom iterator that wraps the vector
iterator and can skip over disabled instances. That works, but the
iterator code is a bit messy with all template and typedefs to make a
compliant iterator. Instead we go with the `ForEach` approach which is
easy to debug and understand.
---
lldb/source/Core/PluginManager.cpp | 294 ++++++++++++++++-------------
1 file changed, 164 insertions(+), 130 deletions(-)
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index 80c9465f9af72..f5c1e15f199ed 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -226,30 +226,26 @@ template <typename Instance> class PluginInstances {
}
typename Instance::CallbackType GetCallbackAtIndex(uint32_t idx) {
- if (Instance *instance = GetInstanceAtIndex(idx))
+ if (const Instance *instance = GetInstanceAtIndex(idx))
return instance->create_callback;
return nullptr;
}
llvm::StringRef GetDescriptionAtIndex(uint32_t idx) {
- if (Instance *instance = GetInstanceAtIndex(idx))
+ if (const Instance *instance = GetInstanceAtIndex(idx))
return instance->description;
return "";
}
llvm::StringRef GetNameAtIndex(uint32_t idx) {
- if (Instance *instance = GetInstanceAtIndex(idx))
+ if (const Instance *instance = GetInstanceAtIndex(idx))
return instance->name;
return "";
}
typename Instance::CallbackType GetCallbackForName(llvm::StringRef name) {
- if (name.empty())
- return nullptr;
- for (auto &instance : m_instances) {
- if (name == instance.name)
- return instance.create_callback;
- }
+ if (const Instance *instance = GetInstanceForName(name))
+ return instance->create_callback;
return nullptr;
}
@@ -260,13 +256,44 @@ template <typename Instance> class PluginInstances {
}
}
- const std::vector<Instance> &GetInstances() const { return m_instances; }
- std::vector<Instance> &GetInstances() { return m_instances; }
+ const Instance *GetInstanceAtIndex(uint32_t idx) {
+ uint32_t count = 0;
- Instance *GetInstanceAtIndex(uint32_t idx) {
- if (idx < m_instances.size())
- return &m_instances[idx];
- return nullptr;
+ const Instance *instance = FindEnabledInstance(
+ [&](const Instance &instance) { return count++ == idx; });
+ return instance;
+ }
+
+ const Instance *GetInstanceForName(llvm::StringRef name) {
+ if (name.empty())
+ return nullptr;
+
+ const Instance *instance = FindEnabledInstance(
+ [&](const Instance &instance) { return instance.name == name; });
+
+ return instance;
+ }
+
+ // Iterate over all enabled plugins, calling the callback for each one.
+ void ForEachEnabledPlugin(
+ std::function<IterationAction(const Instance &)> callback) const {
+ for (auto &instance : m_instances) {
+ if (callback(instance) == IterationAction::Stop)
+ return;
+ }
+ }
+
+ const Instance *
+ FindEnabledInstance(std::function<bool(const Instance &)> predicate) const {
+ const Instance *found = nullptr;
+ ForEachEnabledPlugin([&](const Instance &instance) {
+ if (predicate(instance)) {
+ found = &instance;
+ return IterationAction::Stop;
+ }
+ return IterationAction::Continue;
+ });
+ return found;
}
private:
@@ -571,17 +598,15 @@ PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
LanguageRuntimeGetCommandObject
PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) {
- const auto &instances = GetLanguageRuntimeInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].command_callback;
+ if (auto instance = GetLanguageRuntimeInstances().GetInstanceAtIndex(idx))
+ return instance->command_callback;
return nullptr;
}
LanguageRuntimeGetExceptionPrecondition
PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx) {
- const auto &instances = GetLanguageRuntimeInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].precondition_callback;
+ if (auto instance = GetLanguageRuntimeInstances().GetInstanceAtIndex(idx))
+ return instance->precondition_callback;
return nullptr;
}
@@ -643,12 +668,7 @@ bool PluginManager::IsRegisteredObjectFilePluginName(llvm::StringRef name) {
if (name.empty())
return false;
- const auto &instances = GetObjectFileInstances().GetInstances();
- for (auto &instance : instances) {
- if (instance.name == name)
- return true;
- }
- return false;
+ return GetObjectFileInstances().GetInstanceForName(name) != nullptr;
}
bool PluginManager::RegisterPlugin(
@@ -674,29 +694,24 @@ PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) {
ObjectFileCreateMemoryInstance
PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx) {
- const auto &instances = GetObjectFileInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].create_memory_callback;
+ if (auto instance = GetObjectFileInstances().GetInstanceAtIndex(idx))
+ return instance->create_memory_callback;
return nullptr;
}
ObjectFileGetModuleSpecifications
PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
uint32_t idx) {
- const auto &instances = GetObjectFileInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].get_module_specifications;
+ if (auto instance = GetObjectFileInstances().GetInstanceAtIndex(idx))
+ return instance->get_module_specifications;
return nullptr;
}
ObjectFileCreateMemoryInstance
PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
llvm::StringRef name) {
- const auto &instances = GetObjectFileInstances().GetInstances();
- for (auto &instance : instances) {
- if (instance.name == name)
- return instance.create_memory_callback;
- }
+ if (auto instance = GetObjectFileInstances().GetInstanceForName(name))
+ return instance->create_memory_callback;
return nullptr;
}
@@ -729,13 +744,19 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
// Fall back to object plugins.
const auto &plugin_name = options.GetPluginName().value_or("");
- auto &instances = GetObjectFileInstances().GetInstances();
- for (auto &instance : instances) {
+ bool saved = false;
+ GetObjectFileInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (plugin_name.empty() || instance.name == plugin_name) {
- if (instance.save_core && instance.save_core(process_sp, options, error))
- return error;
+ if (instance.save_core &&
+ instance.save_core(process_sp, options, error)) {
+ saved = true;
+ return IterationAction::Stop;
+ }
}
- }
+ return IterationAction::Continue;
+ });
+ if (saved)
+ return error;
// Check to see if any of the object file plugins tried and failed to save.
// If none ran, set the error message.
@@ -791,18 +812,16 @@ PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
ObjectContainerCreateMemoryInstance
PluginManager::GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx) {
- const auto &instances = GetObjectContainerInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].create_memory_callback;
+ if (auto instance = GetObjectContainerInstances().GetInstanceAtIndex(idx))
+ return instance->create_memory_callback;
return nullptr;
}
ObjectFileGetModuleSpecifications
PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
uint32_t idx) {
- const auto &instances = GetObjectContainerInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].get_module_specifications;
+ if (auto instance = GetObjectContainerInstances().GetInstanceAtIndex(idx))
+ return instance->get_module_specifications;
return nullptr;
}
@@ -849,10 +868,11 @@ PluginManager::GetPlatformCreateCallbackForPluginName(llvm::StringRef name) {
void PluginManager::AutoCompletePlatformName(llvm::StringRef name,
CompletionRequest &request) {
- for (const auto &instance : GetPlatformInstances().GetInstances()) {
+ GetPlatformInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (instance.name.starts_with(name))
request.AddCompletion(instance.name);
- }
+ return IterationAction::Continue;
+ });
}
#pragma mark Process
@@ -897,10 +917,11 @@ PluginManager::GetProcessCreateCallbackForPluginName(llvm::StringRef name) {
void PluginManager::AutoCompleteProcessName(llvm::StringRef name,
CompletionRequest &request) {
- for (const auto &instance : GetProcessInstances().GetInstances()) {
+ GetProcessInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (instance.name.starts_with(name))
request.AddCompletion(instance.name, instance.description);
- }
+ return IterationAction::Continue;
+ });
}
#pragma mark RegisterTypeBuilder
@@ -935,11 +956,11 @@ bool PluginManager::UnregisterPlugin(
lldb::RegisterTypeBuilderSP
PluginManager::GetRegisterTypeBuilder(Target &target) {
- const auto &instances = GetRegisterTypeBuilderInstances().GetInstances();
// We assume that RegisterTypeBuilderClang is the only instance of this plugin
// type and is always present.
- assert(instances.size());
- return instances[0].create_callback(target);
+ auto instance = GetRegisterTypeBuilderInstances().GetInstanceAtIndex(0);
+ assert(instance);
+ return instance->create_callback(target);
}
#pragma mark ScriptInterpreter
@@ -984,19 +1005,22 @@ PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
lldb::ScriptInterpreterSP
PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
Debugger &debugger) {
- const auto &instances = GetScriptInterpreterInstances().GetInstances();
- ScriptInterpreterCreateInstance none_instance = nullptr;
- for (const auto &instance : instances) {
- if (instance.language == lldb::eScriptLanguageNone)
- none_instance = instance.create_callback;
-
- if (script_lang == instance.language)
- return instance.create_callback(debugger);
- }
+ ScriptInterpreterCreateInstance script_instance = nullptr;
+ GetScriptInterpreterInstances().ForEachEnabledPlugin(
+ [&](const auto &instance) {
+ if (instance.language == lldb::eScriptLanguageNone)
+ script_instance = instance.create_callback;
+
+ if (script_lang == instance.language) {
+ script_instance = instance.create_callback;
+ return IterationAction::Stop;
+ }
+ return IterationAction::Continue;
+ });
// If we didn't find one, return the ScriptInterpreter for the null language.
- assert(none_instance != nullptr);
- return none_instance(debugger);
+ assert(script_instance != nullptr);
+ return script_instance(debugger);
}
#pragma mark StructuredDataPlugin
@@ -1046,13 +1070,12 @@ PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) {
StructuredDataFilterLaunchInfo
PluginManager::GetStructuredDataFilterCallbackAtIndex(
uint32_t idx, bool &iteration_complete) {
- const auto &instances = GetStructuredDataPluginInstances().GetInstances();
- if (idx < instances.size()) {
+ if (auto instance =
+ GetStructuredDataPluginInstances().GetInstanceAtIndex(idx)) {
iteration_complete = false;
- return instances[idx].filter_callback;
- } else {
- iteration_complete = true;
+ return instance->filter_callback;
}
+ iteration_complete = true;
return nullptr;
}
@@ -1167,60 +1190,64 @@ PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
ModuleSpec
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
- auto &instances = GetSymbolLocatorInstances().GetInstances();
- for (auto &instance : instances) {
+ std::optional<ModuleSpec> result;
+ GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (instance.locate_executable_object_file) {
- std::optional<ModuleSpec> result =
- instance.locate_executable_object_file(module_spec);
+ result = instance.locate_executable_object_file(module_spec);
if (result)
- return *result;
+ return IterationAction::Stop;
}
- }
- return {};
+ return IterationAction::Continue;
+ });
+ return result ? *result : ModuleSpec{};
}
FileSpec PluginManager::LocateExecutableSymbolFile(
const ModuleSpec &module_spec, const FileSpecList &default_search_paths) {
- auto &instances = GetSymbolLocatorInstances().GetInstances();
- for (auto &instance : instances) {
+ std::optional<FileSpec> result;
+ GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (instance.locate_executable_symbol_file) {
- std::optional<FileSpec> result = instance.locate_executable_symbol_file(
- module_spec, default_search_paths);
+ result = instance.locate_executable_symbol_file(module_spec,
+ default_search_paths);
if (result)
- return *result;
+ return IterationAction::Stop;
}
- }
- return {};
+ return IterationAction::Continue;
+ });
+ return result ? *result : FileSpec{};
}
bool PluginManager::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error,
bool force_lookup,
bool copy_executable) {
- auto &instances = GetSymbolLocatorInstances().GetInstances();
- for (auto &instance : instances) {
+ bool found = false;
+ GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (instance.download_object_symbol_file) {
if (instance.download_object_symbol_file(module_spec, error, force_lookup,
- copy_executable))
- return true;
+ copy_executable)) {
+ found = true;
+ return IterationAction::Stop;
+ }
}
- }
- return false;
+ return IterationAction::Continue;
+ });
+ return found;
}
FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
const UUID *uuid,
const ArchSpec *arch) {
- auto &instances = GetSymbolLocatorInstances().GetInstances();
- for (auto &instance : instances) {
+ std::optional<FileSpec> result;
+ GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
if (instance.find_symbol_file_in_bundle) {
- std::optional<FileSpec> result =
- instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
+ result = instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
if (result)
- return *result;
+ return IterationAction::Stop;
}
- }
- return {};
+ return IterationAction::Continue;
+ });
+ return result ? *result : FileSpec{};
}
#pragma mark Trace
@@ -1272,21 +1299,20 @@ PluginManager::GetTraceCreateCallback(llvm::StringRef plugin_name) {
TraceCreateInstanceForLiveProcess
PluginManager::GetTraceCreateCallbackForLiveProcess(llvm::StringRef plugin_name) {
- for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
- if (instance.name == plugin_name)
- return instance.create_callback_for_live_process;
+ if (auto instance = GetTracePluginInstances().GetInstanceForName(plugin_name))
+ return instance->create_callback_for_live_process;
+
return nullptr;
}
llvm::StringRef PluginManager::GetTraceSchema(llvm::StringRef plugin_name) {
- for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
- if (instance.name == plugin_name)
- return instance.schema;
+ if (auto instance = GetTracePluginInstances().GetInstanceForName(plugin_name))
+ return instance->schema;
return llvm::StringRef();
}
llvm::StringRef PluginManager::GetTraceSchema(size_t index) {
- if (TraceInstance *instance =
+ if (const TraceInstance *instance =
GetTracePluginInstances().GetInstanceAtIndex(index))
return instance->schema;
return llvm::StringRef();
@@ -1335,7 +1361,7 @@ bool PluginManager::UnregisterPlugin(
ThreadTraceExportCommandCreator
PluginManager::GetThreadTraceExportCommandCreatorAtIndex(uint32_t index) {
- if (TraceExporterInstance *instance =
+ if (const TraceExporterInstance *instance =
GetTraceExporterInstances().GetInstanceAtIndex(index))
return instance->create_thread_trace_export_command;
return nullptr;
@@ -1438,9 +1464,9 @@ bool PluginManager::UnregisterPlugin(
InstrumentationRuntimeGetType
PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) {
- const auto &instances = GetInstrumentationRuntimeInstances().GetInstances();
- if (idx < instances.size())
- return instances[idx].get_type_callback;
+ if (auto instance =
+ GetInstrumentationRuntimeInstances().GetInstanceAtIndex(idx))
+ return instance->get_type_callback;
return nullptr;
}
@@ -1493,18 +1519,20 @@ PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
}
LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
- const auto &instances = GetTypeSystemInstances().GetInstances();
LanguageSet all;
- for (unsigned i = 0; i < instances.size(); ++i)
- all.bitvector |= instances[i].supported_languages_for_types.bitvector;
+ GetTypeSystemInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ all.bitvector |= instance.supported_languages_for_types.bitvector;
+ return IterationAction::Continue;
+ });
return all;
}
LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
- const auto &instances = GetTypeSystemInstances().GetInstances();
LanguageSet all;
- for (unsigned i = 0; i < instances.size(); ++i)
- all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
+ GetTypeSystemInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ all.bitvector |= instance.supported_languages_for_expressions.bitvector;
+ return IterationAction::Continue;
+ });
return all;
}
@@ -1545,7 +1573,13 @@ bool PluginManager::UnregisterPlugin(
}
uint32_t PluginManager::GetNumScriptedInterfaces() {
- return GetScriptedInterfaceInstances().GetInstances().size();
+ uint32_t num = 0;
+ GetScriptedInterfaceInstances().ForEachEnabledPlugin(
+ [&](const auto &instance) {
+ ++num;
+ return IterationAction::Continue;
+ });
+ return num;
}
llvm::StringRef PluginManager::GetScriptedInterfaceNameAtIndex(uint32_t index) {
@@ -1559,17 +1593,16 @@ PluginManager::GetScriptedInterfaceDescriptionAtIndex(uint32_t index) {
lldb::ScriptLanguage
PluginManager::GetScriptedInterfaceLanguageAtIndex(uint32_t idx) {
- const auto &instances = GetScriptedInterfaceInstances().GetInstances();
- return idx < instances.size() ? instances[idx].language
- : ScriptLanguage::eScriptLanguageNone;
+ if (auto instance = GetScriptedInterfaceInstances().GetInstanceAtIndex(idx))
+ return instance->language;
+ return ScriptLanguage::eScriptLanguageNone;
}
ScriptedInterfaceUsages
PluginManager::GetScriptedInterfaceUsagesAtIndex(uint32_t idx) {
- const auto &instances = GetScriptedInterfaceInstances().GetInstances();
- if (idx >= instances.size())
- return {};
- return instances[idx].usages;
+ if (auto instance = GetScriptedInterfaceInstances().GetInstanceAtIndex(idx))
+ return instance->usages;
+ return {};
}
#pragma mark REPL
@@ -1606,16 +1639,17 @@ REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
}
LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
- const auto &instances = GetREPLInstances().GetInstances();
- return idx < instances.size() ? instances[idx].supported_languages
- : LanguageSet();
+ if (auto instance = GetREPLInstances().GetInstanceAtIndex(idx))
+ return instance->supported_languages;
+ return LanguageSet();
}
LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
- const auto &instances = GetREPLInstances().GetInstances();
LanguageSet all;
- for (unsigned i = 0; i < instances.size(); ++i)
- all.bitvector |= instances[i].supported_languages.bitvector;
+ GetREPLInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ all.bitvector |= instance.supported_languages.bitvector;
+ return IterationAction::Continue;
+ });
return all;
}
>From 460e028a0ab25614d54e336677a6c6c0ad8b0e2e Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Thu, 27 Mar 2025 11:30:22 -0700
Subject: [PATCH 2/2] Change to return a copy of the instances vector
---
lldb/source/Core/PluginManager.cpp | 174 ++++++++++++-----------------
1 file changed, 70 insertions(+), 104 deletions(-)
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index f5c1e15f199ed..95eb940efcef2 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -256,44 +256,34 @@ template <typename Instance> class PluginInstances {
}
}
+ // Return a copy of all the enabled instances.
+ // Note that this is a copy of the internal state so modifications
+ // to the returned instances will not be reflected back to instances
+ // stored by the PluginInstances object.
+ std::vector<Instance> GetSnapshot() { return m_instances; }
+
const Instance *GetInstanceAtIndex(uint32_t idx) {
uint32_t count = 0;
- const Instance *instance = FindEnabledInstance(
+ return FindEnabledInstance(
[&](const Instance &instance) { return count++ == idx; });
- return instance;
}
const Instance *GetInstanceForName(llvm::StringRef name) {
if (name.empty())
return nullptr;
- const Instance *instance = FindEnabledInstance(
+ return FindEnabledInstance(
[&](const Instance &instance) { return instance.name == name; });
-
- return instance;
- }
-
- // Iterate over all enabled plugins, calling the callback for each one.
- void ForEachEnabledPlugin(
- std::function<IterationAction(const Instance &)> callback) const {
- for (auto &instance : m_instances) {
- if (callback(instance) == IterationAction::Stop)
- return;
- }
}
const Instance *
FindEnabledInstance(std::function<bool(const Instance &)> predicate) const {
- const Instance *found = nullptr;
- ForEachEnabledPlugin([&](const Instance &instance) {
- if (predicate(instance)) {
- found = &instance;
- return IterationAction::Stop;
- }
- return IterationAction::Continue;
- });
- return found;
+ for (const auto &instance : m_instances) {
+ if (predicate(instance))
+ return &instance;
+ }
+ return nullptr;
}
private:
@@ -744,19 +734,13 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
// Fall back to object plugins.
const auto &plugin_name = options.GetPluginName().value_or("");
- bool saved = false;
- GetObjectFileInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ auto instances = GetObjectFileInstances().GetSnapshot();
+ for (auto &instance : instances) {
if (plugin_name.empty() || instance.name == plugin_name) {
- if (instance.save_core &&
- instance.save_core(process_sp, options, error)) {
- saved = true;
- return IterationAction::Stop;
- }
+ if (instance.save_core && instance.save_core(process_sp, options, error))
+ return error;
}
- return IterationAction::Continue;
- });
- if (saved)
- return error;
+ }
// Check to see if any of the object file plugins tried and failed to save.
// If none ran, set the error message.
@@ -868,11 +852,10 @@ PluginManager::GetPlatformCreateCallbackForPluginName(llvm::StringRef name) {
void PluginManager::AutoCompletePlatformName(llvm::StringRef name,
CompletionRequest &request) {
- GetPlatformInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ for (const auto &instance : GetPlatformInstances().GetSnapshot()) {
if (instance.name.starts_with(name))
request.AddCompletion(instance.name);
- return IterationAction::Continue;
- });
+ }
}
#pragma mark Process
@@ -917,11 +900,10 @@ PluginManager::GetProcessCreateCallbackForPluginName(llvm::StringRef name) {
void PluginManager::AutoCompleteProcessName(llvm::StringRef name,
CompletionRequest &request) {
- GetProcessInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ for (const auto &instance : GetProcessInstances().GetSnapshot()) {
if (instance.name.starts_with(name))
request.AddCompletion(instance.name, instance.description);
- return IterationAction::Continue;
- });
+ }
}
#pragma mark RegisterTypeBuilder
@@ -1005,22 +987,19 @@ PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
lldb::ScriptInterpreterSP
PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
Debugger &debugger) {
- ScriptInterpreterCreateInstance script_instance = nullptr;
- GetScriptInterpreterInstances().ForEachEnabledPlugin(
- [&](const auto &instance) {
- if (instance.language == lldb::eScriptLanguageNone)
- script_instance = instance.create_callback;
-
- if (script_lang == instance.language) {
- script_instance = instance.create_callback;
- return IterationAction::Stop;
- }
- return IterationAction::Continue;
- });
+ const auto instances = GetScriptInterpreterInstances().GetSnapshot();
+ ScriptInterpreterCreateInstance none_instance = nullptr;
+ for (const auto &instance : instances) {
+ if (instance.language == lldb::eScriptLanguageNone)
+ none_instance = instance.create_callback;
+
+ if (script_lang == instance.language)
+ return instance.create_callback(debugger);
+ }
// If we didn't find one, return the ScriptInterpreter for the null language.
- assert(script_instance != nullptr);
- return script_instance(debugger);
+ assert(none_instance != nullptr);
+ return none_instance(debugger);
}
#pragma mark StructuredDataPlugin
@@ -1190,64 +1169,60 @@ PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
ModuleSpec
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
- std::optional<ModuleSpec> result;
- GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ auto instances = GetSymbolLocatorInstances().GetSnapshot();
+ for (auto &instance : instances) {
if (instance.locate_executable_object_file) {
- result = instance.locate_executable_object_file(module_spec);
+ std::optional<ModuleSpec> result =
+ instance.locate_executable_object_file(module_spec);
if (result)
- return IterationAction::Stop;
+ return *result;
}
- return IterationAction::Continue;
- });
- return result ? *result : ModuleSpec{};
+ }
+ return {};
}
FileSpec PluginManager::LocateExecutableSymbolFile(
const ModuleSpec &module_spec, const FileSpecList &default_search_paths) {
- std::optional<FileSpec> result;
- GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ auto instances = GetSymbolLocatorInstances().GetSnapshot();
+ for (auto &instance : instances) {
if (instance.locate_executable_symbol_file) {
- result = instance.locate_executable_symbol_file(module_spec,
- default_search_paths);
+ std::optional<FileSpec> result = instance.locate_executable_symbol_file(
+ module_spec, default_search_paths);
if (result)
- return IterationAction::Stop;
+ return *result;
}
- return IterationAction::Continue;
- });
- return result ? *result : FileSpec{};
+ }
+ return {};
}
bool PluginManager::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error,
bool force_lookup,
bool copy_executable) {
- bool found = false;
- GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ auto instances = GetSymbolLocatorInstances().GetSnapshot();
+ for (auto &instance : instances) {
if (instance.download_object_symbol_file) {
if (instance.download_object_symbol_file(module_spec, error, force_lookup,
- copy_executable)) {
- found = true;
- return IterationAction::Stop;
- }
+ copy_executable))
+ return true;
}
- return IterationAction::Continue;
- });
- return found;
+ }
+ return false;
}
FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
const UUID *uuid,
const ArchSpec *arch) {
- std::optional<FileSpec> result;
- GetSymbolLocatorInstances().ForEachEnabledPlugin([&](const auto &instance) {
+ auto instances = GetSymbolLocatorInstances().GetSnapshot();
+ for (auto &instance : instances) {
if (instance.find_symbol_file_in_bundle) {
- result = instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
+ std::optional<FileSpec> result =
+ instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
if (result)
- return IterationAction::Stop;
+ return *result;
}
- return IterationAction::Continue;
- });
- return result ? *result : FileSpec{};
+ }
+ return {};
}
#pragma mark Trace
@@ -1519,20 +1494,18 @@ PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
}
LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
+ const auto instances = GetTypeSystemInstances().GetSnapshot();
LanguageSet all;
- GetTypeSystemInstances().ForEachEnabledPlugin([&](const auto &instance) {
- all.bitvector |= instance.supported_languages_for_types.bitvector;
- return IterationAction::Continue;
- });
+ for (unsigned i = 0; i < instances.size(); ++i)
+ all.bitvector |= instances[i].supported_languages_for_types.bitvector;
return all;
}
LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
+ const auto instances = GetTypeSystemInstances().GetSnapshot();
LanguageSet all;
- GetTypeSystemInstances().ForEachEnabledPlugin([&](const auto &instance) {
- all.bitvector |= instance.supported_languages_for_expressions.bitvector;
- return IterationAction::Continue;
- });
+ for (unsigned i = 0; i < instances.size(); ++i)
+ all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
return all;
}
@@ -1573,13 +1546,7 @@ bool PluginManager::UnregisterPlugin(
}
uint32_t PluginManager::GetNumScriptedInterfaces() {
- uint32_t num = 0;
- GetScriptedInterfaceInstances().ForEachEnabledPlugin(
- [&](const auto &instance) {
- ++num;
- return IterationAction::Continue;
- });
- return num;
+ return GetScriptedInterfaceInstances().GetSnapshot().size();
}
llvm::StringRef PluginManager::GetScriptedInterfaceNameAtIndex(uint32_t index) {
@@ -1645,11 +1612,10 @@ LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
}
LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
+ const auto instances = GetREPLInstances().GetSnapshot();
LanguageSet all;
- GetREPLInstances().ForEachEnabledPlugin([&](const auto &instance) {
- all.bitvector |= instance.supported_languages.bitvector;
- return IterationAction::Continue;
- });
+ for (unsigned i = 0; i < instances.size(); ++i)
+ all.bitvector |= instances[i].supported_languages.bitvector;
return all;
}
More information about the lldb-commits
mailing list