我知道 go 团队不会很好地支持 GDB。但是,它有时似乎有效,所以在我放弃之前,我想看看它是否适用于该程序。
我试图用它来调试我在 mac os x mavericks 中的程序,不幸的是我无法在运行时检查我的程序。我使用的是 mac os x mavericks 10.9.4,我的 go 版本是 go version go1.2.2 darwin/amd64。
如果我在我的二进制文件上执行 gdb my_binary
然后尝试运行它会发生什么:
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hydra...
warning: `/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/go-build728316890/crypto/x509/_obj/root_darwin.cgo2.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/go-build728316890/net/_obj/cgo_unix.cgo2.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/go-build728316890/runtime/cgo/_obj/gcc_amd64.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/go-build728316890/runtime/cgo/_obj/gcc_darwin_amd64.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/go-build728316890/runtime/cgo/_obj/gcc_setenv.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/go-build728316890/runtime/cgo/_obj/gcc_util.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/m9/3tx5tfkx02z9jkwdz0lkg85cj4gbmq/T/go-build297950324/github.com/alecthomas/gozmq/_obj/zmq.cgo2.o': can't open to read symbols: No such file or directory.
warning: `/var/folders/m9/3tx5tfkx02z9jkwdz0lkg85cj4gbmq/T/go-build297950324/github.com/alecthomas/gozmq/_obj/zmq_3_x.cgo2.o': can't open to read symbols: No such file or directory.
(no debugging symbols found)...done.
我要重点说的是最后一行:
(no debugging symbols found)...done.
我的go程序编译错了吗?是否有任何标志可以使这项工作成功?
我只做了 go build my_program
但似乎有些标志或其他东西可以让它工作?
我已经能够让 gdb 在非常简单的程序上工作,但是在这个大得多的程序上它会失败并抛出上述错误。有人知道为什么会这样吗?有人能让它适用于包含大量库和包之类的大型程序吗?
我知道它可能行不通,但我想通过询问社区来尝试一下。
(如果有的话,我也愿意使用不同的调试器)。
(我对 cgdb 也有同样的问题)。
(我也愿意使用任何其他允许我查看变量值、断点和类似基本功能的调试器,也许探索 go-routines 会很棒。当然对于 mac)
最佳答案
GDB 告诉您它认为可能找到调试符号的文件和目录不存在。从名称上看,这些是 Go 的临时工作目录。
go build
有一个命令行选项-work
,说明如下:
print the name of the temporary work directory and do not delete it when exiting.
所以这可能会奏效,但要付出一些定期手动清理的代价。
关于debugging - 尝试使用 gdb(和 cgdb)在 go(golang)中调试程序,但似乎存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222142/