Skip to content

Debug API / Ask Debugger to Evaluate a given Expression #42989

Closed

Description

For a very cool extension I have in mind, I would love to be able to ask the active debugger (if there is an active debug session) to evaluate a given expression and get back the result of that evaluation.

My ultimate goal is to provide a watch-window like pane that visualizes given expressions (like svg, graphs, matrices or tables).

Activity

  1. added
    debug
    feature-request
    on Feb 5, 2018
  2. weinand commented on Feb 5, 2018

    @weinand
    Contributor

    At the moment we have no plans to duplicate the Debug Protocol as extension API.
    But you can use the DebugSession.customRequest(...)API to run any DAP request.

    The following code to run the "evaluate" request works for me:

    'use strict';
    
    import * as vscode from 'vscode';
    
    export function activate(context: vscode.ExtensionContext) {
    
        let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
    
            const session = vscode.debug.activeDebugSession;
            if (session) {
                session.customRequest("evaluate", { "expression": "Math.sqrt(10)" }).then(reply => {
                    vscode.window.showInformationMessage(`result: ${reply.result}`);
                }, error => {
                    vscode.window.showInformationMessage(`error: ${error.message}`);
                });
            }
    
        });
    
        context.subscriptions.push(disposable);
    }
    
    export function deactivate() {
    }

    To try this:

    • create simple "Hello World" extension with yeoman.
    • replace the extension.ts with my code from above
    • press F5 to launch (and debug) extension
    • in new window open a simple node.js program
    • press F5 to debug simple program
    • press F1 and type "Hello" and run the "Hello World" extension.

    Observe: the result of the expression "Math.sqrt(10)" will be shown in an info notification.

  3. changed the title [-][Feature Request] Debug API / Ask Debugger to Evaluate a given Expression[/-] [+]Debug API / Ask Debugger to Evaluate a given Expression[/+] on Feb 6, 2018
  4. hediet commented on Feb 6, 2018

    @hediet
    MemberAuthor

    Now I see what I did wrong - in order to access local variables, I have to pass a frameId, otherwise I just get "not available". How do I get the frameId of the current frame?

    Is there an event that fires when the debugger halts so that I can re-evaluate all my expressions?

  5. robe007 commented on Feb 22, 2019

    @robe007

    Andre Weinand (@weinand) I have tried the code that you exposed above and the const session = vscode.debug.activeDebugSession; returns undefined. I have made a question on SO about it. Some ideas?

  6. added
    *out-of-scope
    on Oct 14, 2019
  7. vscodebot commented on Oct 14, 2019

    @vscodebot

    This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

    If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

    Thanks for your understanding and happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*out-of-scopeapidebugfeature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions