[Lldb-commits] [lldb] [lldb-dap] Run the terminate commands only on disconnect (PR #200829)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 1 07:10:04 PDT 2026
https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/200829
The terminate commands should only run when a debug session ends.
Fixes https://github.com/llvm/llvm-project/issues/194670
>From 5ae1d1523e4759d4c8036caa0c6b2d45b6faf977 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Mon, 1 Jun 2026 15:00:27 +0100
Subject: [PATCH] [lldb-dap] Run the terminate commands only on disconnect
The terminate commands should only run when a debug
session ends.
Fixes https://github.com/llvm/llvm-project/issues/194670
---
.../tools/lldb-dap/attach-commands/TestDAP_attachCommands.py | 2 ++
lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_commands.py | 2 ++
lldb/tools/lldb-dap/DAP.cpp | 3 +--
3 files changed, 5 insertions(+), 2 deletions(-)
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);
More information about the lldb-commits
mailing list