VS Code: How to access debug variables from within extension?

前端 未结 1 648
小蘑菇
小蘑菇 2020-12-30 18:28

I am writing an extension for visual studio code where I want to evaluate the current variables of a javascript debug session. These variables are normally shown when one ha

相关标签:
1条回答
  • 2020-12-30 18:43

    I have managed to get access to the local variables although this is not a general solution - it may only work in a single threaded debugger. If you know any better way, please answer or comment.

    Say, the debugger breaks in a method that has a local variable car.

    To get the value of car, I am using the customRequest method on the active debug session:

    const session = vscode.debug.activeDebugSession;
    const response = await session.customRequest('evaluate', { expression: 'car', frameId: frameId });
    const car = response.result;
    

    To get the frameId, I use another call of customRequest:

    const session = vscode.debug.activeDebugSession;
    const response = await session.customRequest('stackTrace', { threadId: 1 })
    const frameId = response.stackFrames[0].id;
    

    To get a real car object (not a string representation) in my extension, I pass "JSON.stringify(car)" as expression in the evaluate customRequest. Then, I can use JSON.parse(response.result).

    To get all scopes, stacks and variables, have a look at the Debug Session API and the specification of the DebugProtocol.

    0 讨论(0)
提交回复
热议问题