Skip to content

Commit 10bcf0c

Browse files
authored
[lldb-dap] Destroy debugger when debug session terminates (llvm#156231)
# Patch Currently, in Server Mode (i.e. `--connection`), all debuggers are destroyed when the **lldb-dap process** terminates. This causes logging and release of resources to be delayed. This can also cause congestion if multiple debuggers have the same destroy callbacks, which will fight for the same resources (e.g. web requests) at the same time. Instead, the debuggers can be destroyed as early as when the **debug session** terminates. This way, logging and release of release of resources can happen as soon as possible. Congestion can also be naturally reduced, because it's unlikely that all debug sessions will terminate at the same time. # Tests See PR llvm#156231.
1 parent 7bee9d9 commit 10bcf0c

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,11 @@ llvm::Error DAP::Loop() {
10691069
out.Stop();
10701070
err.Stop();
10711071
StopEventHandlers();
1072+
1073+
// Destroy the debugger when the session ends. This will trigger the
1074+
// debugger's destroy callbacks for earlier logging and clean-ups, rather
1075+
// than waiting for the termination of the lldb-dap process.
1076+
lldb::SBDebugger::Destroy(debugger);
10721077
});
10731078

10741079
while (true) {

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,7 @@ llvm::Error SendThreadStoppedEvent(DAP &dap, bool on_entry) {
230230

231231
// Send a "terminated" event to indicate the process is done being
232232
// debugged.
233-
void SendTerminatedEvent(DAP &dap) {
234-
// Prevent races if the process exits while we're being asked to disconnect.
235-
llvm::call_once(dap.terminated_event_flag, [&] {
236-
dap.RunTerminateCommands();
237-
// Send a "terminated" event
238-
llvm::json::Object event(CreateTerminatedEventObject(dap.target));
239-
dap.SendJSON(llvm::json::Value(std::move(event)));
240-
});
241-
}
233+
void SendTerminatedEvent(DAP &dap) { dap.SendTerminatedEvent(); }
242234

243235
// Grab any STDOUT and STDERR from the process and send it up to VS Code
244236
// via an "output" event to the "stdout" and "stderr" categories.

0 commit comments

Comments
 (0)