Reputation: 137
When I debug a go program in GoLand, I can't see the value of global variable. Can anyone tell me why and how to fix it?
Here is an example:
I set a breakpoint in the last line of main function. But as shown in the picture, we can only get the value of 'a', but not 'a' and 'xx'.
package main
import "fmt"
var xx int = 1
func main() {
var a int = 1
fmt.Println(a)
xx = 3
fmt.Println("end")
}
Upvotes: 4
Views: 4882
Reputation: 560
I think there is no direct way. Just to elaborate more, you can click on Evaluate from Debug window: Evaluate Expression Button in Debug Window
Start typing the name of the variable, GoLand will try to autocomplete: Expression Window
Then click on Evaluate button: Autocompletion in Expression window
Upvotes: 0
Reputation: 1063
You can also right click the variable in the editor and "Add to Watches".
Upvotes: 2
Reputation: 137
We can use Evaluate function to get the value of global variables, but can only get one value each time
Upvotes: 3
Reputation: 6556
I think there is no way to show all global variables automatically. Just add them manually (by clicking plus sign or pressing Insert).
Upvotes: 2