How do I evaluate expressions while debugging in VS Code?
Solution 1
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
Solution 2
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
石荒人
Updated on June 21, 2022Comments
-
石荒人 almost 2 years
I 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'
-
JHS almost 5 yearsUnfortunately I think this is a limitation of the language's debugging tools: github.com/Microsoft/vscode-go/issues/2225 It seems like pretty basic debugging functionality to be missing...
-
石荒人 almost 5 yearsThanks...that is amazing
-
-
Dennis Barzanoff over 3 yearsI added this to the Debug Console and it worked:
functioToBeCalled(arg1, arg2)
-
石荒人 over 3 yearsThanks , I already using jetbrain goland for one year.
-
Ed J about 3 yearsYou can also set a property of an object in the debug console:
call myObject.myProperty="some new property value"
-
Jairo Lozano almost 3 years@石荒人 are you able to call a function in jetbrain goland while execution is stopped in a debug break point?