diff options
author | Jordan Rupprecht <rupprecht@google.com> | 2024-02-27 12:43:05 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 12:43:05 -0600 |
commit | e427e934f677567f8184ff900cb4cbdb8cf21a21 (patch) | |
tree | 63e6957b6766ec7c1b42e7e078b3ac71319410ef /lldb/tools | |
parent | 563f414e049dc06dcb955f565fcff3c663982ee4 (diff) | |
download | llvm-e427e934f677567f8184ff900cb4cbdb8cf21a21.zip llvm-e427e934f677567f8184ff900cb4cbdb8cf21a21.tar.gz llvm-e427e934f677567f8184ff900cb4cbdb8cf21a21.tar.bz2 |
[lldb][dap] Avoid concurrent `HandleCommand` calls (#83162)
The `EventThreadFunction` can end up calling `HandleCommand`
concurrently with the main request processing thread. The underlying API
does not appear to be thread safe, so add a narrowly scoped mutex lock
to prevent calling it in this place from more than one thread.
Fixes #81686. Prior to this, TestDAP_launch.py is 4% flaky. After, it
passes in 1000 runs.
Diffstat (limited to 'lldb/tools')
-rw-r--r-- | lldb/tools/lldb-dap/LLDBUtils.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lldb/tools/lldb-dap/LLDBUtils.cpp b/lldb/tools/lldb-dap/LLDBUtils.cpp index 35b7a98..a91cc67 100644 --- a/lldb/tools/lldb-dap/LLDBUtils.cpp +++ b/lldb/tools/lldb-dap/LLDBUtils.cpp @@ -9,6 +9,8 @@ #include "LLDBUtils.h" #include "DAP.h" +#include <mutex> + namespace lldb_dap { bool RunLLDBCommands(llvm::StringRef prefix, @@ -37,7 +39,15 @@ bool RunLLDBCommands(llvm::StringRef prefix, } } - interp.HandleCommand(command.str().c_str(), result); + { + // Prevent simultaneous calls to HandleCommand, e.g. EventThreadFunction + // may asynchronously call RunExitCommands when we are already calling + // RunTerminateCommands. + static std::mutex handle_command_mutex; + std::lock_guard<std::mutex> locker(handle_command_mutex); + interp.HandleCommand(command.str().c_str(), result); + } + const bool got_error = !result.Succeeded(); // The if statement below is assuming we always print out `!` prefixed // lines. The only time we don't print is when we have `quiet_on_success == |