[Lldb-commits] [lldb] [lldb-dap] While handling events, grab the APIMutex for consistency. (PR #139596)

via lldb-commits lldb-commits at lists.llvm.org
Mon May 12 10:56:34 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

<details>
<summary>Changes</summary>

A number of unit tests are unstable at the moment and I believe this is due to event handling between the event thread and the DAP::Loop.

One way this manifests is the 'disconnect' request terminating the SBTarget while the event handler is still handling module events. This is causing a SIGPIPE between the debugserver and the lldb-dap process.

I have some additional follow up patches to address test event synchronization, since many tests seem to be under specified in terms of their expected state that I think is contributing to these kinds of races.

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


1 Files Affected:

- (modified) lldb/tools/lldb-dap/DAP.cpp (+5) 


``````````diff
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 4feca1253be20..e84d3d9e7eed8 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1504,6 +1504,11 @@ void DAP::EventThread() {
   bool done = false;
   while (!done) {
     if (listener.WaitForEvent(1, event)) {
+      // Once we get an event, make sure we finish handling it before the main
+      // thread handles the next DAP request.
+      lldb::SBMutex lock = GetAPIMutex();
+      std::lock_guard<lldb::SBMutex> guard(lock);
+
       const auto event_mask = event.GetType();
       if (lldb::SBProcess::EventIsProcessEvent(event)) {
         lldb::SBProcess process = lldb::SBProcess::GetProcessFromEvent(event);

``````````

</details>


https://github.com/llvm/llvm-project/pull/139596


More information about the lldb-commits mailing list