We want to allow the client to detect when the debugged process forks and to attach the debugger to a newly created process. For this we propose to implement two options in LLDB: to propagate fork/vfork events to the client and to automatically detach the child/parent in a stopped state. The client can then decide to attach another debugger to that process. Here’s a proof-of-concept implementation – ⚙ D134642 Propagate FORK events back to client (WIP).
In our extension for Microsoft Visual Studio we use LLDB as a debugger backend (GitHub - googlestadia/vsi-lldb). We’d like to support automatic debugging of child processes. We are aware of an effort to support the multi-process debugging directly in LLDB (discussion), but we want to propose a complementary approach that is easier to implement and may be more convenient to use from the client perspective.
In order to achieve the described behavior, we propose to implement two changes in LLDB:
- Add an option
stop-on-clone-eventsto propagate the following events to the client: fork, vfork, vfork_done
- Add an option
detach-keeps-stopped(already exists in LLDB) to detach the child/parent process in a stopped state
- On Linux this can be implemented in lldb-server by injected SIGSTOP via PT_DETACH
The combination of these two options will allow the client to detect when the debugged process forks and then immediately start another debugging session for the detached process. The client (IDE in our case) will manage multiple debugging sessions and from the user perspective it would be completely transparent. By default these options will be disabled, so the default behavior won’t change.
Note: the support for detaching the process in a stopped state is already declared in the Process.h, but it’s not implemented.