问题
I'm working on an academic software visualization project that aims to capture debug sessions and display graphically. For this, I am trying to create a Visual Studio Code Extension where I can get the data exchanged with the current language debugger, such as added breakpoints, stepsinto, stepsover, debug session start, debug file, context variables, line code debugged. That is, the same data that is displayed in the VS Code windows: VARIABLES, WATCH, CALL STACK, LOADED SCRIPTS and BREAKPOINTS.
I tried to create an extension that adds a new Debugger Provider, using Debug Adapter (DAP - Debug Adapter Protocol). However this cancels the current provider and does not allow debugging. https://code.visualstudio.com/api/extension-guides/debugger-extension
I also tried using the VS Code API events. With these events I managed to control the start of the session and some breakpoint data, however incomplete. https://code.visualstudio.com/api/references/vscode-api#debug
Would anyone know how to capture this debugging data in the VS Code scope (VS Code Generic Debugger UI), that is, regardless of the language used? Is there any open issue for this in VS Code's GitHub?
回答1:
The solution for this is called a DebugAdapterTracker
.
vscode.debug.registerDebugAdapterTrackerFactory('*', {
createDebugAdapterTracker(session: DebugSession) {
return {
onWillReceiveMessage: m => console.log(`> ${JSON.stringify(m, undefined, 2)}`),
onDidSendMessage: m => console.log(`< ${JSON.stringify(m, undefined, 2)}`)
};
}
});
https://code.visualstudio.com/updates/v1_30#_extension-authoring
Look for "Finalized Debug Adapter Tracker API". It was originally created for Live Share debugging.
来源:https://stackoverflow.com/questions/56012353/how-to-get-vs-code-debug-data-like-breakpoints-steps-line-code