diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index b1ad38d983893..f5c098363fbc5 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -1068,6 +1068,11 @@ llvm::Error DAP::Loop() { out.Stop(); err.Stop(); StopEventHandlers(); + + // Destroy the debugger when the session ends. This will trigger the + // debugger's destroy callbacks for earlier logging and clean-ups, rather + // than waiting for the termination of the lldb-dap process. + lldb::SBDebugger::Destroy(debugger); }); while (true) { diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index bfb05a387d04d..ecd630cb530d6 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -230,15 +230,7 @@ llvm::Error SendThreadStoppedEvent(DAP &dap, bool on_entry) { // Send a "terminated" event to indicate the process is done being // debugged. -void SendTerminatedEvent(DAP &dap) { - // Prevent races if the process exits while we're being asked to disconnect. - llvm::call_once(dap.terminated_event_flag, [&] { - dap.RunTerminateCommands(); - // Send a "terminated" event - llvm::json::Object event(CreateTerminatedEventObject(dap.target)); - dap.SendJSON(llvm::json::Value(std::move(event))); - }); -} +void SendTerminatedEvent(DAP &dap) { dap.SendTerminatedEvent(); } // Grab any STDOUT and STDERR from the process and send it up to VS Code // via an "output" event to the "stdout" and "stderr" categories.