RFC: lldb-vscode startDebugging reverse requests

Introduction

A new reverse request was added in the Debug Adapter Protocol late last year for a call startDebugging (Specification) that can be used to create a new debug adapter instance inheriting some parts of the current adapter. This new call looks to be useful when creating a debug session involving multiple processes, specifically if a parent process is spawning child processes or if you want to attach to both a client and a server of a pair of processes.

Currently, this request is not implemented in lldb-vscode and it looks like the current handling of reverse requests also might need to be refactored to better support this call (e.g. having multiple in-flight reverse requests).

Proposal

Given the complex nature of spawning multiple processes, I think it would be best to expose this new request as a custom lldb command that lldb-vscode can register.

My proposed command would be to use a new lldb command with the following format:

dap startDebug <launch|attach> "<config-json>"

I have working prototype of the new command in ⚙ D153447 Creating a startDebugging reverse DAP request handler in lldb-vscode.

As a trivial example, you could start a server with a child session for a client using something like:

{
  "program": "./server",
  "postRunCommands": [
    "dap startDebugging launch '{\"program\": \"./client\"}'"
  ]
}

But the key feature is that the new command gives you the ability to add the appropriate trigger when a child debug session can be created.

Can you briefly explain (and give examples) the use cases for this request?

I imagine startDebug attach is supposed to be used for automatiaclly spawning debug sessions for child processes, right? If I understand correctly in order for this to work LLDB should be able to pause (e.g. SIGSTOP) the child process when it’s created and then hand over the control to the user (lldb-vscode in this case). There was a proposal a while ago to implement this – [RFC] Support debugging child processes, but I think it wasn’t merged. Is this already implemented independently?

What is the user case for startDebug launch?

Sure, some additional background on my current use case.

I am working on supporting a debug configuration that is used when debugging a test process that launches an app potentially multiple times during the session. The test host process will live for the entire duration and the apps will be launched usually 1 or more times.

I have some lldb python scripts setup to create a listener for these process launches and currently, previously they would notify a VS Code extension through a side-channel for communicate the process launch state. The VS Code extension would then create debug configurations that are used to attach to the launched processes. However, with the new startDebugging it should be possible to trigger this without having to go all the way through the VS Code extension. The main catch is that there isn’t a specific place to listen for this that would work universally (e.g. do you look for posix_spawn, fork, execve, any other platform specific mechanism for starting a process…).

I am currently using the attach request, but I think the launch might also be useful so my current patch doesn’t prevent that at the moment.

A launch case might be to start a server with a child client using something like:

{
  "program": "./server",
  "postRunCommands": [
    "lldb-vscode startDebugging launch {'program': './client'}"
  ]
}