[Lldb-commits] [lldb] [lldb] Make SBProcess thread related actions listen to StopLocker (PR #134339)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 11 10:08:54 PDT 2025
================
@@ -870,6 +870,16 @@ llvm::json::Value CreateThread(lldb::SBThread &thread, lldb::SBFormat &format) {
return llvm::json::Value(std::move(object));
}
+llvm::json::Array GetThreads(lldb::SBProcess process, lldb::SBFormat &format) {
+ llvm::json::Array threads;
+ const uint32_t num_threads = process.GetNumThreads();
+ for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
+ lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
+ threads.emplace_back(CreateThread(thread, format));
+ }
+ return threads;
----------------
JDevlieghere wrote:
This should take the TargetAPI lock as it's doing two SB API calls consecutively.
```suggestion
lldb::SBMutex lock = process.GetTarget().GetAPIMutex();
std::lock_guard<lldb::SBMutex> guard(lock);
llvm::json::Array threads;
const uint32_t num_threads = process.GetNumThreads();
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
threads.emplace_back(CreateThread(thread, format));
}
return threads;
```
https://github.com/llvm/llvm-project/pull/134339
More information about the lldb-commits
mailing list