51

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'

AskYous
  • 4,332
  • 9
  • 46
  • 82
石荒人
  • 753
  • 1
  • 6
  • 11
  • 3
    Unfortunately I think this is a limitation of the language's debugging tools: https://github.com/Microsoft/vscode-go/issues/2225 It seems like pretty basic debugging functionality to be missing... – JHS Aug 04 '19 at 03:41
  • Thanks...that is amazing – 石荒人 Aug 04 '19 at 14:15

5 Answers5

57

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

AskYous
  • 4,332
  • 9
  • 46
  • 82
Javier Dottori
  • 1,040
  • 9
  • 9
5

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

Deine Freunde
  • 61
  • 1
  • 4
3

Type your expression here or select code in source file, right click and select Evaluate in Debug Console.

enter image description here

Jean-Pierre Schnyder
  • 1,572
  • 1
  • 15
  • 24
1

If you run into an error like "call not at safe point", make sure you've stopped at a breakpoint which is not on a line declaring a function, but inside the body of a function.

Apparently function declaration lines are not a safe point for the debugger

Zoltán
  • 21,321
  • 14
  • 93
  • 134
-2

I'm running VS Code 1.72.2 and it's possible to run expressions directly inside the Debug Console.

Just type an expression and press Enter. In the example below I typed req.header:

VS Code Debug Console

vovahost
  • 34,185
  • 17
  • 113
  • 116