Skip to content

Commit 77ae18b

Browse files
authored
[lldb-dap] Send terminated event only once (#93172)
This is a regression from #91591. Turns out std::mutex does not prevent code from running twice. 🤦
1 parent a1f9259 commit 77ae18b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lldb/tools/lldb-dap/DAP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/ADT/StringMap.h"
2727
#include "llvm/ADT/StringRef.h"
2828
#include "llvm/Support/JSON.h"
29+
#include "llvm/Support/Threading.h"
2930
#include "llvm/Support/raw_ostream.h"
3031

3132
#include "lldb/API/SBAttachInfo.h"
@@ -169,6 +170,7 @@ struct DAP {
169170
std::optional<llvm::json::Object> last_launch_or_attach_request;
170171
lldb::tid_t focus_tid;
171172
bool disconnecting = false;
173+
llvm::once_flag terminated_event_flag;
172174
bool stop_at_entry;
173175
bool is_attach;
174176
bool enable_auto_variable_summaries;

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,12 @@ void SendContinuedEvent() {
227227
// debugged.
228228
void SendTerminatedEvent() {
229229
// Prevent races if the process exits while we're being asked to disconnect.
230-
static std::mutex mutex;
231-
std::lock_guard<std::mutex> locker(mutex);
232-
233-
g_dap.RunTerminateCommands();
234-
// Send a "terminated" event
235-
llvm::json::Object event(CreateTerminatedEventObject());
236-
g_dap.SendJSON(llvm::json::Value(std::move(event)));
230+
llvm::call_once(g_dap.terminated_event_flag, [&] {
231+
g_dap.RunTerminateCommands();
232+
// Send a "terminated" event
233+
llvm::json::Object event(CreateTerminatedEventObject());
234+
g_dap.SendJSON(llvm::json::Value(std::move(event)));
235+
});
237236
}
238237

239238
// Send a thread stopped event for all threads as long as the process

0 commit comments

Comments
 (0)