-
Notifications
You must be signed in to change notification settings - Fork 137
DAP Client reference
Clients should use "Late case", (see here) when communicating with debugpy
.
We added some extension to DAP to support Multi-process debugging.
The event body is a fully formed attach debug configuration that can be used to start a separate debug session. This is generated when the debugger detects a subprocess. See DAP Specifcation for Event
object.
interface DebugpyAttachEvent extends Event {
event: "debugpyAttach";
body: {
/**
* Fully formed attach configuration that can be used with VS Code 'debug.startDebugging' API.
*/
};
}
Debugpy uses stdin
/stdout
to send and receive DAP messages. All you need to do to start the debug adapter is run this command:
python ~/debugpy/adapter
Follow the instructions here on how to implement a DAP client.
This assumes debugpy
is already started using the CLI debugging or via import debugpy
(see here). In this mode you can send and receive DAP messages over the socket. Everything else is same as the launch scenario.
This is a sample implementation of how the debug adapter can be invoked in a VS Code extension.
public async createDebugAdapterDescriptor(session: DebugSession, executable: DebugAdapterExecutable | undefined): Promise<DebugAdapterDescriptor> {
const configuration = session.
const isAttach = configuration.request === 'attach';
const port = configuration.port ?? 0;
// When processId is provided we may have to inject the debugger into the process.
// This is done by the debug adapter, so we need to start it. The adapter will handle
// injecting the debugger when it receives the attach request.
const processId = configuration.processId ?? 0;
if (isAttach && processId === 0) {
return new DebugAdapterServer(port, configuration.host);
}
const pythonPath = '<Path to python executable>';
// If logToFile is set in the debug config then pass --log-dir <path-to-extension-dir> when launching the debug adapter.
const logArgs = configuration.logToFile ? ['--log-dir', EXTENSION_ROOT_DIR] : [];
return new DebugAdapterExecutable(pythonPath, [ 'C:\\debugpy\\adapter',...logArgs]);
}