Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I evaluate expressions while debugging in VS Code?

enter image description hereI am using vscode to build my golang gin project.

I go to debugging mod and can not do evaluate expressions.

I want to go some line and evaluate that see what happened in that monent.

Like eclipse ctrl+shift+i or idea ctrl+alt+f8

Quick evaluate expression.

I also see this

Eclipse inspection (Ctrl + Shift + I) equivalent in IntelliJ IDEA (Community Edition)

Watch window or evaluate expressions while debugging in VS Code?

func main() {
    
    router := gin.Default()
    router.GET("/user/:name", func(c *gin.Context) {
    name := c.Param("name")
    c.String(http.StatusOK, name, 1, 2, 3, 4)

})

when the debugger line in name := c.Param("name")

I try to use the bottom of vscode window and when I type this code into the command it will return

but if I type name it will return the right string for me.

Failed to eval expression: { "Expr": "c.Param("name")", "Scope": { "goroutineID": 34, "frame": 1 }, "Cfg": { "followPointers": true, "maxVariableRecurse": 1, "maxStringLen": 64, "maxArrayValues": 64, "maxStructFields": -1 } } Eval error: function calls not allowed without using 'call'

like image 761
石荒人 Avatar asked Aug 03 '19 15:08

石荒人


2 Answers

For the ones coming here at 2020+, it is now possible to call a function. The syntax is:

call functionToBeCalled(arg1, arg2)

In the question ask for running an assignation, you can also set a variable

call variable = newValue

Source: https://github.com/golang/vscode-go/issues/100

like image 137
Javier Dottori Avatar answered Oct 07 '22 21:10

Javier Dottori


This isn't possible right now as more complex evaluations have only been added to the Delve debugger recently. You might want to follow these two Github issues:

Add ability to safely call functions #119

Function calls via delve 'call' are not supported #2655

like image 24
Deine Freunde Avatar answered Oct 07 '22 20:10

Deine Freunde