Author: Ayush Sahay Date: 2021-06-11T21:37:19+05:30 New Revision: 5ef5177145b48e6379fe3a6434d3ff593fe7202a
URL: https://github.com/llvm/llvm-project/commit/5ef5177145b48e6379fe3a6434d3ff593fe7202a DIFF: https://github.com/llvm/llvm-project/commit/5ef5177145b48e6379fe3a6434d3ff593fe7202a.diff LOG: [lldb-vscode] Synchronize calls to 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, in turn, testing and/or setting g_vsc.sent_terminated_event without any synchronization. In case the thread executing EventThreadFunction sets it before the thread executing request_discontinue has had a chance to test it, the latter would move ahead to issue a response to the disconnect request. Said response may be 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. Reviewed By: clayborg, wallace Differential Revision: https://reviews.llvm.org/D103609 Added: Modified: lldb/tools/lldb-vscode/lldb-vscode.cpp Removed: ################################################################################ diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp index 29b4019379d83..9619572ef4889 100644 --- a/lldb/tools/lldb-vscode/lldb-vscode.cpp +++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp @@ -179,6 +179,19 @@ void SendThreadExitedEvent(lldb::tid_t tid) { // 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<std::mutex> 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