[Lldb-commits] [lldb] [lldb-dap] Send terminated event only once (PR #93172)
https://github.com/labath closed https://github.com/llvm/llvm-project/pull/93172 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Send terminated event only once (PR #93172)
https://github.com/kusmour edited https://github.com/llvm/llvm-project/pull/93172 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Send terminated event only once (PR #93172)
https://github.com/kusmour approved this pull request. Thanks for fixing it :) Just tested this patch from my side, worked well! https://github.com/llvm/llvm-project/pull/93172 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Send terminated event only once (PR #93172)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Pavel Labath (labath) Changes This is a regression from #91591. Turns out std::mutex does not prevent code from running twice. :facepalm: --- Full diff: https://github.com/llvm/llvm-project/pull/93172.diff 2 Files Affected: - (modified) lldb/tools/lldb-dap/DAP.h (+2) - (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+6-7) ``diff 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 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 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 `` https://github.com/llvm/llvm-project/pull/93172 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Send terminated event only once (PR #93172)
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 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 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 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 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits