How to get VS Code debug data like breakpoints, steps, line code

拟墨画扇 提交于 2021-02-09 11:13:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!