Go:用gdb打印变量 [英] Go: print variables with gdb
本文介绍了Go:用gdb打印变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个程序中,如何使用调试器打断执行并打印出i的值?
In this program, how can break execution with the debugger and print the value of i?
package main
import "fmt"
func main() {
x := "abc"
i := 3
fmt.Println(i)
fmt.Println(x)
}
我无法打印i。但是我可以打印x:
I can't print i. However I can print x:
go build test.go
gdb test
[...]Reading symbols from /home/ned/test...done.
(gdb) br 9
(gdb) run
(gdb) p i
No symbol "i" in current context.
(gdb) p x
$1 = "abc"
推荐答案
听起来像我可能被编译器优化过的变量。您是否尝试过构建调试版本?
It sounds like the variable i probably got optimized out of existence by the compiler. Did you try a debug build?
您可以使用 go build -gcflags'-N'
。
这篇关于Go:用gdb打印变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文