@@ -256,44 +256,34 @@ template <typename Instance> class PluginInstances {
256256 }
257257 }
258258
259+ // Return a copy of all the enabled instances.
260+ // Note that this is a copy of the internal state so modifications
261+ // to the returned instances will not be reflected back to instances
262+ // stored by the PluginInstances object.
263+ std::vector<Instance> GetSnapshot () { return m_instances; }
264+
259265 const Instance *GetInstanceAtIndex (uint32_t idx) {
260266 uint32_t count = 0 ;
261267
262- const Instance *instance = FindEnabledInstance (
268+ return FindEnabledInstance (
263269 [&](const Instance &instance) { return count++ == idx; });
264- return instance;
265270 }
266271
267272 const Instance *GetInstanceForName (llvm::StringRef name) {
268273 if (name.empty ())
269274 return nullptr ;
270275
271- const Instance *instance = FindEnabledInstance (
276+ return FindEnabledInstance (
272277 [&](const Instance &instance) { return instance.name == name; });
273-
274- return instance;
275- }
276-
277- // Iterate over all enabled plugins, calling the callback for each one.
278- void ForEachEnabledPlugin (
279- std::function<IterationAction(const Instance &)> callback) const {
280- for (auto &instance : m_instances) {
281- if (callback (instance) == IterationAction::Stop)
282- return ;
283- }
284278 }
285279
286280 const Instance *
287281 FindEnabledInstance (std::function<bool (const Instance &)> predicate) const {
288- const Instance *found = nullptr ;
289- ForEachEnabledPlugin ([&](const Instance &instance) {
290- if (predicate (instance)) {
291- found = &instance;
292- return IterationAction::Stop;
293- }
294- return IterationAction::Continue;
295- });
296- return found;
282+ for (const auto &instance : m_instances) {
283+ if (predicate (instance))
284+ return &instance;
285+ }
286+ return nullptr ;
297287 }
298288
299289private:
@@ -744,19 +734,13 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
744734
745735 // Fall back to object plugins.
746736 const auto &plugin_name = options.GetPluginName ().value_or (" " );
747- bool saved = false ;
748- GetObjectFileInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
737+ auto instances = GetObjectFileInstances (). GetSnapshot () ;
738+ for ( auto &instance : instances ) {
749739 if (plugin_name.empty () || instance.name == plugin_name) {
750- if (instance.save_core &&
751- instance.save_core (process_sp, options, error)) {
752- saved = true ;
753- return IterationAction::Stop;
754- }
740+ if (instance.save_core && instance.save_core (process_sp, options, error))
741+ return error;
755742 }
756- return IterationAction::Continue;
757- });
758- if (saved)
759- return error;
743+ }
760744
761745 // Check to see if any of the object file plugins tried and failed to save.
762746 // If none ran, set the error message.
@@ -868,11 +852,10 @@ PluginManager::GetPlatformCreateCallbackForPluginName(llvm::StringRef name) {
868852
869853void PluginManager::AutoCompletePlatformName (llvm::StringRef name,
870854 CompletionRequest &request) {
871- GetPlatformInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
855+ for ( const auto &instance : GetPlatformInstances (). GetSnapshot () ) {
872856 if (instance.name .starts_with (name))
873857 request.AddCompletion (instance.name );
874- return IterationAction::Continue;
875- });
858+ }
876859}
877860
878861#pragma mark Process
@@ -917,11 +900,10 @@ PluginManager::GetProcessCreateCallbackForPluginName(llvm::StringRef name) {
917900
918901void PluginManager::AutoCompleteProcessName (llvm::StringRef name,
919902 CompletionRequest &request) {
920- GetProcessInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
903+ for ( const auto &instance : GetProcessInstances (). GetSnapshot () ) {
921904 if (instance.name .starts_with (name))
922905 request.AddCompletion (instance.name , instance.description );
923- return IterationAction::Continue;
924- });
906+ }
925907}
926908
927909#pragma mark RegisterTypeBuilder
@@ -1005,22 +987,19 @@ PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
1005987lldb::ScriptInterpreterSP
1006988PluginManager::GetScriptInterpreterForLanguage (lldb::ScriptLanguage script_lang,
1007989 Debugger &debugger) {
1008- ScriptInterpreterCreateInstance script_instance = nullptr ;
1009- GetScriptInterpreterInstances ().ForEachEnabledPlugin (
1010- [&](const auto &instance) {
1011- if (instance.language == lldb::eScriptLanguageNone)
1012- script_instance = instance.create_callback ;
1013-
1014- if (script_lang == instance.language ) {
1015- script_instance = instance.create_callback ;
1016- return IterationAction::Stop;
1017- }
1018- return IterationAction::Continue;
1019- });
990+ const auto instances = GetScriptInterpreterInstances ().GetSnapshot ();
991+ ScriptInterpreterCreateInstance none_instance = nullptr ;
992+ for (const auto &instance : instances) {
993+ if (instance.language == lldb::eScriptLanguageNone)
994+ none_instance = instance.create_callback ;
995+
996+ if (script_lang == instance.language )
997+ return instance.create_callback (debugger);
998+ }
1020999
10211000 // If we didn't find one, return the ScriptInterpreter for the null language.
1022- assert (script_instance != nullptr );
1023- return script_instance (debugger);
1001+ assert (none_instance != nullptr );
1002+ return none_instance (debugger);
10241003}
10251004
10261005#pragma mark StructuredDataPlugin
@@ -1190,64 +1169,60 @@ PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
11901169
11911170ModuleSpec
11921171PluginManager::LocateExecutableObjectFile (const ModuleSpec &module_spec) {
1193- std::optional<ModuleSpec> result ;
1194- GetSymbolLocatorInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
1172+ auto instances = GetSymbolLocatorInstances (). GetSnapshot () ;
1173+ for ( auto &instance : instances ) {
11951174 if (instance.locate_executable_object_file ) {
1196- result = instance.locate_executable_object_file (module_spec);
1175+ std::optional<ModuleSpec> result =
1176+ instance.locate_executable_object_file (module_spec);
11971177 if (result)
1198- return IterationAction::Stop ;
1178+ return *result ;
11991179 }
1200- return IterationAction::Continue;
1201- });
1202- return result ? *result : ModuleSpec{};
1180+ }
1181+ return {};
12031182}
12041183
12051184FileSpec PluginManager::LocateExecutableSymbolFile (
12061185 const ModuleSpec &module_spec, const FileSpecList &default_search_paths) {
1207- std::optional<FileSpec> result ;
1208- GetSymbolLocatorInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
1186+ auto instances = GetSymbolLocatorInstances (). GetSnapshot () ;
1187+ for ( auto &instance : instances ) {
12091188 if (instance.locate_executable_symbol_file ) {
1210- result = instance.locate_executable_symbol_file (module_spec,
1211- default_search_paths);
1189+ std::optional<FileSpec> result = instance.locate_executable_symbol_file (
1190+ module_spec, default_search_paths);
12121191 if (result)
1213- return IterationAction::Stop ;
1192+ return *result ;
12141193 }
1215- return IterationAction::Continue;
1216- });
1217- return result ? *result : FileSpec{};
1194+ }
1195+ return {};
12181196}
12191197
12201198bool PluginManager::DownloadObjectAndSymbolFile (ModuleSpec &module_spec,
12211199 Status &error,
12221200 bool force_lookup,
12231201 bool copy_executable) {
1224- bool found = false ;
1225- GetSymbolLocatorInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
1202+ auto instances = GetSymbolLocatorInstances (). GetSnapshot () ;
1203+ for ( auto &instance : instances ) {
12261204 if (instance.download_object_symbol_file ) {
12271205 if (instance.download_object_symbol_file (module_spec, error, force_lookup,
1228- copy_executable)) {
1229- found = true ;
1230- return IterationAction::Stop;
1231- }
1206+ copy_executable))
1207+ return true ;
12321208 }
1233- return IterationAction::Continue;
1234- });
1235- return found;
1209+ }
1210+ return false ;
12361211}
12371212
12381213FileSpec PluginManager::FindSymbolFileInBundle (const FileSpec &symfile_bundle,
12391214 const UUID *uuid,
12401215 const ArchSpec *arch) {
1241- std::optional<FileSpec> result ;
1242- GetSymbolLocatorInstances (). ForEachEnabledPlugin ([&]( const auto &instance) {
1216+ auto instances = GetSymbolLocatorInstances (). GetSnapshot () ;
1217+ for ( auto &instance : instances ) {
12431218 if (instance.find_symbol_file_in_bundle ) {
1244- result = instance.find_symbol_file_in_bundle (symfile_bundle, uuid, arch);
1219+ std::optional<FileSpec> result =
1220+ instance.find_symbol_file_in_bundle (symfile_bundle, uuid, arch);
12451221 if (result)
1246- return IterationAction::Stop ;
1222+ return *result ;
12471223 }
1248- return IterationAction::Continue;
1249- });
1250- return result ? *result : FileSpec{};
1224+ }
1225+ return {};
12511226}
12521227
12531228#pragma mark Trace
@@ -1519,20 +1494,18 @@ PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
15191494}
15201495
15211496LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes () {
1497+ const auto instances = GetTypeSystemInstances ().GetSnapshot ();
15221498 LanguageSet all;
1523- GetTypeSystemInstances ().ForEachEnabledPlugin ([&](const auto &instance) {
1524- all.bitvector |= instance.supported_languages_for_types .bitvector ;
1525- return IterationAction::Continue;
1526- });
1499+ for (unsigned i = 0 ; i < instances.size (); ++i)
1500+ all.bitvector |= instances[i].supported_languages_for_types .bitvector ;
15271501 return all;
15281502}
15291503
15301504LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions () {
1505+ const auto instances = GetTypeSystemInstances ().GetSnapshot ();
15311506 LanguageSet all;
1532- GetTypeSystemInstances ().ForEachEnabledPlugin ([&](const auto &instance) {
1533- all.bitvector |= instance.supported_languages_for_expressions .bitvector ;
1534- return IterationAction::Continue;
1535- });
1507+ for (unsigned i = 0 ; i < instances.size (); ++i)
1508+ all.bitvector |= instances[i].supported_languages_for_expressions .bitvector ;
15361509 return all;
15371510}
15381511
@@ -1573,13 +1546,7 @@ bool PluginManager::UnregisterPlugin(
15731546}
15741547
15751548uint32_t PluginManager::GetNumScriptedInterfaces () {
1576- uint32_t num = 0 ;
1577- GetScriptedInterfaceInstances ().ForEachEnabledPlugin (
1578- [&](const auto &instance) {
1579- ++num;
1580- return IterationAction::Continue;
1581- });
1582- return num;
1549+ return GetScriptedInterfaceInstances ().GetSnapshot ().size ();
15831550}
15841551
15851552llvm::StringRef PluginManager::GetScriptedInterfaceNameAtIndex (uint32_t index) {
@@ -1645,11 +1612,10 @@ LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
16451612}
16461613
16471614LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages () {
1615+ const auto instances = GetREPLInstances ().GetSnapshot ();
16481616 LanguageSet all;
1649- GetREPLInstances ().ForEachEnabledPlugin ([&](const auto &instance) {
1650- all.bitvector |= instance.supported_languages .bitvector ;
1651- return IterationAction::Continue;
1652- });
1617+ for (unsigned i = 0 ; i < instances.size (); ++i)
1618+ all.bitvector |= instances[i].supported_languages .bitvector ;
16531619 return all;
16541620}
16551621
0 commit comments