[all-commits] [llvm/llvm-project] a2c267: [lldb] Fix race condition between lldb-vscode and ...
Ilya Nozhkin via All-commits
all-commits at lists.llvm.org
Tue Feb 22 03:54:44 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: a2c267e0c9d9b9963f4022caf455327a7d96dfbf
https://github.com/llvm/llvm-project/commit/a2c267e0c9d9b9963f4022caf455327a7d96dfbf
Author: Ilya Nozhkin <nozhkin.ii at gmail.com>
Date: 2022-02-22 (Tue, 22 Feb 2022)
Changed paths:
M lldb/include/lldb/Target/Process.h
M lldb/packages/Python/lldbsuite/test/lldbtest.py
M lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
M lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
M lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
M lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
M lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
M lldb/source/Target/Process.cpp
M lldb/source/Target/Target.cpp
A lldb/test/API/tools/lldb-vscode/stop-hooks/Makefile
A lldb/test/API/tools/lldb-vscode/stop-hooks/TestVSCode_stop_hooks.py
A lldb/test/API/tools/lldb-vscode/stop-hooks/main.c
Log Message:
-----------
[lldb] Fix race condition between lldb-vscode and stop hooks executor
The race is between these two pieces of code that are executed in two separate
lldb-vscode threads (the first is in the main thread and another is in the
event-handling thread):
```
// lldb-vscode.cpp
g_vsc.debugger.SetAsync(false);
g_vsc.target.Launch(launch_info, error);
g_vsc.debugger.SetAsync(true);
```
```
// Target.cpp
bool old_async = debugger.GetAsyncExecution();
debugger.SetAsyncExecution(true);
debugger.GetCommandInterpreter().HandleCommands(GetCommands(), exc_ctx,
options, result);
debugger.SetAsyncExecution(old_async);
```
The sequence that leads to the bug is this one:
1. Main thread enables synchronous mode and launches the process.
2. When the process is launched, it generates the first stop event.
3. This stop event is catched by the event-handling thread and DoOnRemoval
is invoked.
4. Inside DoOnRemoval, this thread runs stop hooks. And before running stop
hooks, the current synchronization mode is stored into old_async (and
right now it is equal to "false").
5. The main thread finishes the launch and returns to lldb-vscode, the
synchronization mode is restored to asynchronous by lldb-vscode.
6. Event-handling thread finishes stop hooks processing and restores the
synchronization mode according to old_async (i.e. makes the mode synchronous)
7. And now the mode is synchronous while lldb-vscode expects it to be
asynchronous. Synchronous mode forbids the process to broadcast public stop
events, so, VS Code just hangs because lldb-vscode doesn't notify it about
stops.
So, this diff makes the target intercept the first stop event if the process is
launched in the synchronous mode, thus preventing stop hooks execution.
The bug is only present on Windows because other platforms already
intercept this event using their own hijacking listeners.
So, this diff also fixes some problems with lldb-vscode tests on Windows to make
it possible to run the related test. Other tests still can't be enabled because
the debugged program prints something into stdout and LLDB can't intercept this
output and redirect it to lldb-vscode properly.
Reviewed By: jingham
Differential Revision: https://reviews.llvm.org/D119548
More information about the All-commits
mailing list