microsoft / debug-adapter-protocol

Defines a common protocol for debug adapters.
https://microsoft.github.io/debug-adapter-protocol/
Other
1.41k stars 129 forks source link

Support for multi-adapter launch #139

Open eltonwells opened 4 years ago

eltonwells commented 4 years ago

Currently it seems the only way to handle mixed-mode debugging scenarios is to launch with one debugger, hit a breakpoint, and then attach with another debugger. A few examples online:

In Visual Studio we can do a multi-engine launch via IVsDebugger::LaunchDebugTargets where VsDebugTargetInfo::pClsidList can contain CLSIDs for multiple debug engines. In this scenario, the first debug engine is responsible for launching and then the other(s) attach. For an example of this in the Python PTVS tools, see DebugLaunchHelper.cs.

Can something analogous be supported in VS Code? Apart from the launch.json changes, I think main message updates would be requests for launch suspended (or a new field in the Launch request).

connor4312 commented 4 years ago

In VS Code we use compound launch configurations for this, for example this is a configuration we use to launch VS code and attach to three other associated programs: https://github.com/microsoft/vscode/blob/f63ceed2b004502fffcdf40643aa4a9761a38abe/.vscode/launch.json#L434-L447

The key thing that the debugger doing attaching needs to support is the ability to poll in the event that its target is not ready when the debug session is initiated.

Another approach we've taken is to have the debug extension (or a helper extension) trigger a session based on some event, e.g. with the serverReadyAction.

eltonwells commented 4 years ago

@connor4312 Thanks for the information on compound launch configurations. One question I have about this approach:

Also regarding the option to trigger a session based on an event, this would be triggering a session via vscode.debug.startDebugging?

connor4312 commented 4 years ago

What guarantees the program doesn't run past the C++ breakpoint before the C++ debugger attaches?

Something in the debugger would have to do that. In JS debugging, for example, you can launch a program with --inspect-brk which causes it to pause before the first line of code until a debugger attaches.

Also regarding the option to trigger a session based on an event, this would be triggering a session via vscode.debug.startDebugging?

Yep.

eltonwells commented 4 years ago

@connor4312 One other question, in the compound launch scenario how much coordination is there between the debug adapters in the debug session? For example, if one DA stops do the other(s) get a pause request? Is the behavior consistent here between a compound launch and when an extension triggers additional sessions (eg, serverReadyAction, vscode.debug.startDebugging, etc.)?

connor4312 commented 4 years ago

VS Code does not do very much to coordinate them. In compound launches, there's a stopAll option to configure whether the user ending one session should terminate the others, but that's all.

weinand commented 4 years ago

Yes, as already pointed out by @connor4312, the current approach to mixed-mode (and multi process) debugging scenarios is to handle this outside of DAP.

Reasons being:

If there is anything that is too difficult to do outside of DAP, we can easily extend DAP. But for the sake of simplicity, we need good reasons to do so...

int19h commented 4 years ago

Mixed-mode is not as easy as just having one debugger launch, and the rest attach: the debug adapters need to be aware of each other and co-operate, otherwise one of them can block the others. E.g. in the C++/Python case, if the native debugger pauses in native code, the paused thread can no longer evaluate Python code - which the Python debugger needs to produce stack traces etc. There's also no way to get e.g. a mixed stack trace in this model.

VS eventually came up with a whole new API specifically to allow debug engines to co-operate on stack traces and stepping, and that's the one powering mixed Native/Python experience in VS. So for that to happen in VSCode, it'll need something similar first.