[Lldb-commits] [lldb] [lldb-dap] Run the terminate commands only on disconnect (PR #200829)

via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 1 07:10:51 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

<details>
<summary>Changes</summary>

The terminate commands should only run when a debug session ends.

Fixes https://github.com/llvm/llvm-project/issues/194670

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


3 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py (+2) 
- (modified) lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_commands.py (+2) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (+1-2) 


``````````diff
diff --git a/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py b/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py
index 056e213a6fc81..80ebfc451dfe3 100644
--- a/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py
+++ b/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py
@@ -58,6 +58,7 @@ def test_commands(self):
             exitCommands=exitCommands,
             terminateCommands=terminateCommands,
             postRunCommands=postRunCommands,
+            disconnectAutomatically=False,
         )
         self.dap_server.wait_for_initialized()
         # Get output from the console. This should contain both the
@@ -89,6 +90,7 @@ def test_commands(self):
 
         # Continue until the program exits
         self.continue_to_exit()
+        self.dap_server.request_disconnect(terminateDebuggee=True)
         # Get output from the console. This should contain both the
         # "exitCommands" that were run after the second breakpoint was hit
         # and the "terminateCommands" due to the debugging session ending
diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_commands.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_commands.py
index 48398e5915069..a47212b548a06 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_commands.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_commands.py
@@ -42,6 +42,7 @@ def test(self):
             stopCommands=stopCommands,
             exitCommands=exitCommands,
             terminateCommands=terminateCommands,
+            disconnectAutomatically=False,
         )
         self.dap_server.wait_for_initialized()
 
@@ -83,6 +84,7 @@ def test(self):
 
         # Continue until the program exits
         self.continue_to_exit()
+        self.dap_server.request_disconnect(terminateDebuggee=True)
         # Get output from the console. This should contain both the
         # "exitCommands" that were run after the second breakpoint was hit
         # and the "terminateCommands" due to the debugging session ending
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index cb34c7b2fd1e8..c4647c01494b1 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -891,8 +891,6 @@ bool DAP::HandleObject(const Message &M) {
 void DAP::SendTerminatedEvent() {
   // Prevent races if the process exits while we're being asked to disconnect.
   llvm::call_once(terminated_event_flag, [&] {
-    RunTerminateCommands();
-    // Send a "terminated" event
     llvm::json::Object event(CreateTerminatedEventObject(target));
     SendJSON(llvm::json::Value(std::move(event)));
   });
@@ -924,6 +922,7 @@ llvm::Error DAP::Disconnect(bool terminateDebuggee) {
   }
   }
 
+  RunTerminateCommands();
   SendTerminatedEvent();
   TerminateLoop();
   return ToError(error);

``````````

</details>


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


More information about the lldb-commits mailing list