[Lldb-commits] [lldb] [lldb-dap] Send terminated event only once (PR #93172)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu May 23 04:07:48 PDT 2024
https://github.com/labath created https://github.com/llvm/llvm-project/pull/93172
This is a regression from #91591. Turns out std::mutex does not prevent code from running twice. :facepalm:
>From 26611411308c9a916bc3ffdac0f38e95f8aa8c89 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Thu, 23 May 2024 13:02:30 +0200
Subject: [PATCH] [lldb-dap] Send terminated event only once
This is a regression from #91591. Turns out std::mutex does not prevent
code from running twice :facepalm:.
---
lldb/tools/lldb-dap/DAP.h | 2 ++
lldb/tools/lldb-dap/lldb-dap.cpp | 13 ++++++-------
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index bbd9d46ba3a04..a88ee3e1dec6b 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -26,6 +26,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"
#include "lldb/API/SBAttachInfo.h"
@@ -169,6 +170,7 @@ struct DAP {
std::optional<llvm::json::Object> last_launch_or_attach_request;
lldb::tid_t focus_tid;
bool disconnecting = false;
+ llvm::once_flag terminated_event_flag;
bool stop_at_entry;
bool is_attach;
bool enable_auto_variable_summaries;
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 170fa88f1e8b8..7746afb6cbbf3 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -227,13 +227,12 @@ void SendContinuedEvent() {
// debugged.
void SendTerminatedEvent() {
// Prevent races if the process exits while we're being asked to disconnect.
- static std::mutex mutex;
- std::lock_guard<std::mutex> locker(mutex);
-
- g_dap.RunTerminateCommands();
- // Send a "terminated" event
- llvm::json::Object event(CreateTerminatedEventObject());
- g_dap.SendJSON(llvm::json::Value(std::move(event)));
+ llvm::call_once(g_dap.terminated_event_flag, [&] {
+ g_dap.RunTerminateCommands();
+ // Send a "terminated" event
+ llvm::json::Object event(CreateTerminatedEventObject());
+ g_dap.SendJSON(llvm::json::Value(std::move(event)));
+ });
}
// Send a thread stopped event for all threads as long as the process
More information about the lldb-commits
mailing list