[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-05-09 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D122975#3500176 , @labath wrote:

> or rethink the do-tasks-while-you-wait idea.

I suppose one way to fix this would be to ensure that the waiting thread only 
picks up its own subtasks while its waiting. That would avoid these deadlocks, 
and also ensure that the wait is not unnecessarily delayed by a completely 
unrelated long-running task.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-05-09 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I'm afraid I had to revert this, as it was causing hangs in 
TestMultipleDebuggers.py.

I haven't fully debugged this, but what I think is happening is this:

- the test debug multiple (identical) inferiors in parallel
- as a result the thread pool gets hit with many preload-symbols tasks for the 
same set of modules. As these tasks are taking the respective module mutexes, 
they cannot all make progress and a large part of them gets stuck.
- those that to manage to make progress (take the module mutex) get to the 
dwarf indexing stage. while waiting for the indexing tasks to complete, they 
start to perform some other tasks
- if one of those tasks is another preload-symbols task the can get stuck 
acquiring the module mutex. However, they will still be holding the mutex for 
the module that they are indexing, preventing the other threads from making 
progress
- if this happens to multiple threads, they can form a loop in the module mutex 
waits, thereby hanging forever

I'm not entirely sure what would be the right way to fix this, but it seems 
that we either need to make sure the threads don't hold the mutexes while 
performing other tasks (not sure if that's possible), or rethink the 
do-tasks-while-you-wait idea.

It should be fairly easy to reproduce this by running TestMultipleDebuggers a 
couple of times, but if you run into problems doing that, I can provide you 
with some backtraces, logs, or something.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-05-04 Thread Luboš Luňák via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7d807dbcff0: [lldb] parallelize calling of 
Module::PreloadSymbols() (authored by llunak).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+task_group.async(preload_symbols_fn, idx);
+  task_group.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+task_group.async(preload_symbols_fn, idx);
+  task_group.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-05-04 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

Awesome. Thanks for your patience.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-05-03 Thread Luboš Luňák via Phabricator via lldb-commits
llunak added a comment.

The prerequisities fo this change have been pushed, so this one is ready.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-16 Thread Luboš Luňák via Phabricator via lldb-commits
llunak updated this revision to Diff 423247.
llunak added a comment.

Adapted to API changes from D123225 .


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+task_group.async(preload_symbols_fn, idx);
+  task_group.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+task_group.async(preload_symbols_fn, idx);
+  task_group.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-06 Thread Luboš Luňák via Phabricator via lldb-commits
llunak updated this revision to Diff 420885.
llunak added a comment.

Rebased on ThreadPool groups (D123225 ) and 
adding such thread pool to LLDB (D123226 ).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,18 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPool &pool = Debugger::GetThreadPool();
+  llvm::ThreadPool::TaskGroup group;
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+pool.async(group, preload_symbols_fn, idx);
+  pool.wait(group);
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2183,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,18 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPool &pool = Debugger::GetThreadPool();
+  llvm::ThreadPool::TaskGroup group;
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+pool.async(group, preload_symbols_fn, idx);
+  pool.wait(group);
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2183,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-05 Thread Luboš Luňák via Phabricator via lldb-commits
llunak added a comment.

In D122975#3430613 , @JDevlieghere 
wrote:

> After applying this patch I started seeing data races reported by TSan when 
> running the shell tests (`check-lldb-shell`). It seems to happen to different 
> tests on different runs but the backtraces are the same.

That's some debug code using a static bool. I take it D123158 
 takes care of it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

After applying this patch I started seeing data races reported by TSan when 
running the shell tests (`check-lldb-shell`). It seems to happen to different 
tests on different runs but the backtraces are the same.

  WARNING: ThreadSanitizer: data race (pid=40880)
Read of size 1 at 0x0001139ae0a8 by thread T3 (mutexes: write M4094, write 
M119908344493401136):
  #0 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorEncoding() ItaniumDemangle.h:3033 
(liblldb.15.0.0git.dylib:arm64+0x555e668)
  #1 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:3060 
(liblldb.15.0.0git.dylib:arm64+0x55628dc)
  #2 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseUnqualifiedName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*, llvm::itanium_demangle::Node*, 
llvm::itanium_demangle::ModuleName*) ItaniumDemangle.h:2803 
(liblldb.15.0.0git.dylib:arm64+0x5559ff0)
  #3 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:2666 
(liblldb.15.0.0git.dylib:arm64+0x5556c08)
  #4 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseEncoding() ItaniumDemangle.h:5038 
(liblldb.15.0.0git.dylib:arm64+0x555108c)
  #5 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parse() ItaniumDemangle.h:5449 
(liblldb.15.0.0git.dylib:arm64+0x554b9b0)
  #6 llvm::ItaniumPartialDemangler::partialDemangle(char const*) 
ItaniumDemangle.cpp:385 (liblldb.15.0.0git.dylib:arm64+0x554c2a0)
  #7 
lldb_private::RichManglingContext::FromItaniumName(lldb_private::ConstString) 
RichManglingContext.cpp:42 (liblldb.15.0.0git.dylib:arm64+0x2df084)
  #8 
lldb_private::Mangled::GetRichManglingInfo(lldb_private::RichManglingContext&, 
bool (*)(llvm::StringRef, lldb_private::Mangled::ManglingScheme)) 
Mangled.cpp:217 (liblldb.15.0.0git.dylib:arm64+0x2bfec4)
  #9 lldb_private::Symtab::InitNameIndexes() Symtab.cpp:331 
(liblldb.15.0.0git.dylib:arm64+0x41aaa0)
  #10 lldb_private::Symtab::PreloadSymbols() Symtab.cpp:456 
(liblldb.15.0.0git.dylib:arm64+0x41ba4c)
  #11 lldb_private::Module::PreloadSymbols() Module.cpp:1378 
(liblldb.15.0.0git.dylib:arm64+0x2c74d4)
  #12 
std::__1::__function::__func, 
std::__1::allocator >, void ()>::operator()() function.h:352 
(liblldb.15.0.0git.dylib:arm64+0x4d73e0)
  #13 
std::__1::__function::__func)::'lambda'(), 
std::__1::allocator)::'lambda'()>, void ()>::operator()() function.h:352 
(liblldb.15.0.0git.dylib:arm64+0x4d6920)
  #14 void* 
llvm::thread::ThreadProxy 
>(void*) thread.h:60 (liblldb.15.0.0git.dylib:arm64+0x9daa0c)
  
Previous write of size 1 at 0x0001139ae0a8 by thread T6 (mutexes: write 
M26458652249517616, write M208572962157285296):
  #0 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorEncoding() ItaniumDemangle.h:3034 
(liblldb.15.0.0git.dylib:arm64+0x555e720)
  #1 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:3060 
(liblldb.15.0.0git.dylib:arm64+0x55628dc)
  #2 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseUnqualifiedName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*, llvm::itanium_demangle::Node*, 
llvm::itanium_demangle::ModuleName*) ItaniumDemangle.h:2803 
(liblldb.15.0.0git.dylib:arm64+0x5559ff0)
  #3 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:2666 
(liblldb.15.0.0git.dylib:arm64+0x5556c08)
  #4 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseEncoding() ItaniumDemangle.h:5038 
(liblldb.15.0.0git.dylib:arm64+0x555108c)
  #5 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parse() ItaniumDemangle.h:5449 
(liblldb.15.0.0git.dylib:arm64+0x554b9b0)
  #6 llvm::ItaniumPartialDemangler::partialDemangle(char const*) 
ItaniumDemangle.cpp:385 (liblldb.15.0.0git.dylib:arm64+0x554c2a0)
  #7 
lldb_private::RichManglingContext::FromItaniumName(lldb_private::ConstString) 
RichManglingContext.cpp:42 (liblldb.15.0.0git.dy

[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-05 Thread Luboš Luňák via Phabricator via lldb-commits
llunak updated this revision to Diff 420492.
llunak retitled this revision from "parallelize module loading in  
DynamicLoaderPOSIXDYLD()" to "parallelize calling of Module::PreloadSymbols()".
llunak edited the summary of this revision.
llunak added a reviewer: jingham.
llunak added a comment.

Ok, parallelizing of only Module::PreloadSymbols() was simpler than I expected 
and it also works, so I've reworked the patch to do that.

This change now requires D123128  and also 
adding the grouping ability to ThreadPool, which I haven't done yet.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122975/new/

https://reviews.llvm.org/D122975

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPool pool(llvm::optimal_concurrency(num_images));
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+pool.async(preload_symbols_fn, idx);
+  pool.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPool pool(llvm::optimal_concurrency(num_images));
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+pool.async(preload_symbols_fn, idx);
+  pool.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits