Skip to content

[lldb-dap] Ensure we acquire the SB API lock while handling requests. #137026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented Apr 23, 2025

Acquiring the lock for the target should help ensure consistency with other background operations, like the thread monitoring events that can trigger run commands from a different thread.

Aquiring the lock for the target should help ensure consistency with other background operations, like the thread monitoring events that can trigger run commands from a different thread.
@llvmbot
Copy link
Member

llvmbot commented Apr 23, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

Acquiring the lock for the target should help ensure consistency with other background operations, like the thread monitoring events that can trigger run commands from a different thread.


Full diff: https://github.com/llvm/llvm-project/pull/137026.diff

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+4)
diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
index 3520dc2c71a55..be9273963654a 100644
--- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
@@ -14,6 +14,7 @@
 #include "Protocol/ProtocolBase.h"
 #include "RunInTerminal.h"
 #include "llvm/Support/Error.h"
+#include <mutex>
 
 #if !defined(_WIN32)
 #include <unistd.h>
@@ -180,6 +181,9 @@ void BaseRequestHandler::Run(const Request &request) {
     return;
   }
 
+  lldb::SBMutex lock = dap.GetAPIMutex();
+  std::lock_guard<lldb::SBMutex> guard(lock);
+
   // FIXME: After all the requests have migrated from LegacyRequestHandler >
   // RequestHandler<> we should be able to move this into
   // RequestHandler<>::operator().

@ashgti ashgti merged commit 3b48e2a into llvm:main Apr 23, 2025
11 of 12 checks passed
@ashgti ashgti deleted the lldb-dap-locking branch April 23, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants