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")
}
答案 0 :(得分:2)
我认为没有办法自动显示所有全局变量。只需手动添加它们(通过单击加号或按插入)。
答案 1 :(得分:2)
答案 2 :(得分:1)
您还可以右键单击编辑器中的变量,然后单击“添加到手表”。
答案 3 :(得分:0)
可视代码将同时显示局部变量和全局变量。
答案 4 :(得分:0)
我认为没有直接的方法。只是为了详细说明,您可以单击 Evaluate from Debug 窗口: Evaluate Expression Button in Debug Window
开始输入变量的名称,GoLand 将尝试自动完成: Expression Window
然后点击评估按钮:Autocompletion in Expression window