[Lldb-commits] [PATCH] D103609: [lldb-vscode] Synchronize calls to SendTerminatedEvent

2021-06-11 Thread Ayush Sahay via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ef5177145b4: [lldb-vscode] Synchronize calls to 
SendTerminatedEvent (authored by asahay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103609/new/

https://reviews.llvm.org/D103609

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -179,6 +179,19 @@
 // Send a "terminated" event to indicate the process is done being
 // debugged.
 void SendTerminatedEvent() {
+  // If an inferior exits prior to the processing of a disconnect request, then
+  // the threads executing EventThreadFunction and request_discontinue
+  // respectively may call SendTerminatedEvent simultaneously. Without any
+  // synchronization, the thread executing EventThreadFunction may set
+  // g_vsc.sent_terminated_event before the thread executing
+  // request_discontinue has had a chance to test it, in which case the latter
+  // would move ahead to issue a response to the disconnect request. Said
+  // response may get dispatched ahead of the terminated event compelling the
+  // client to terminate the debug session without consuming any console output
+  // that might've been generated by the execution of terminateCommands. So,
+  // synchronize simultaneous calls to SendTerminatedEvent.
+  static std::mutex mutex;
+  std::lock_guard locker(mutex);
   if (!g_vsc.sent_terminated_event) {
 g_vsc.sent_terminated_event = true;
 g_vsc.RunTerminateCommands();


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -179,6 +179,19 @@
 // Send a "terminated" event to indicate the process is done being
 // debugged.
 void SendTerminatedEvent() {
+  // If an inferior exits prior to the processing of a disconnect request, then
+  // the threads executing EventThreadFunction and request_discontinue
+  // respectively may call SendTerminatedEvent simultaneously. Without any
+  // synchronization, the thread executing EventThreadFunction may set
+  // g_vsc.sent_terminated_event before the thread executing
+  // request_discontinue has had a chance to test it, in which case the latter
+  // would move ahead to issue a response to the disconnect request. Said
+  // response may get dispatched ahead of the terminated event compelling the
+  // client to terminate the debug session without consuming any console output
+  // that might've been generated by the execution of terminateCommands. So,
+  // synchronize simultaneous calls to SendTerminatedEvent.
+  static std::mutex mutex;
+  std::lock_guard locker(mutex);
   if (!g_vsc.sent_terminated_event) {
 g_vsc.sent_terminated_event = true;
 g_vsc.RunTerminateCommands();
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D103609: [lldb-vscode] Synchronize calls to SendTerminatedEvent

2021-06-03 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103609/new/

https://reviews.llvm.org/D103609

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits