简体   繁体   English

尝试使用gdb(和cgdb)调试go(golang)中的程序,但似乎存在问题

[英]Trying to use gdb (and cgdb) for debugging programs in go (golang) but there seems to be problems

I am aware that the go team will not support GDB very well. 我知道,go团队不会很好地支持GDB。 However, it seems it works sometimes so before I give up I want to see if it works on this program. 但是,似乎有时它可以工作,所以在我放弃之前,我想看看它是否适用于该程序。

I was trying to use it to debug my program in mac os x mavericks and I wasn't able to inspect my program at run time unfortunately. 我试图使用它在mac os x mavericks中调试程序,但是不幸的是,我无法在运行时检查程序。 I am using mac os x mavericks 10.9.4 and my go version is go version go1.2.2 darwin/amd64. 我使用的是Mac OS X Mavericks 10.9.4,我的go版本是go版本go1.2.2 darwin / amd64。

Here is what happens if I do gdb my_binary on my binary and then try to run it: 如果我对二进制文件执行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.

The line I want to focus on is the last one: 我要重点关注的那一行是最后一条:

(no debugging symbols found)...done.

Did I compile my go program wrongly? 我是否编译了go程序错误? Are there any flags that could have made this work? 是否有任何标志可以完成这项工作?

I only did go build my_program but it seems that maybe some flags or something could have made it work? 我只是go build my_program但似乎有些标志或某些功能可以使它工作?

I have been able to make gdb work on very simple programs but on this much larger one it fails and throws the above error. 我已经能够使gdb在非常简单的程序上工作,但是在更大的程序上它会失败并引发上述错误。 Does someone know why might it be? 有人知道为什么会这样吗? Has someone been able to make it work for large programs with lots of libraries and packages and stuff like that? 有人能够使它适用于具有许多库和软件包之类的大型程序吗?

I understand it might not work, but I wanted to give it a try by asking the community. 我了解它可能不起作用,但是我想通过询问社区来尝试一下。

(I would be willing to also use a different debugger if there is one). (如果有的话,我也愿意使用其他调试器)。

(I also had the same issue with cgdb). (我对cgdb也有同样的问题)。

(I am also open for using any other debugger that allows me to see values of variables, breakpoints and basic functionality like that, maybe also explore go-routines would be awesome. For mac, of course) (我也愿意使用任何其他调试器,使我能够查看变量,断点和类似的基本值,也许还可以探索go例程,真棒。对于Mac,当然)

GDB is telling you that the files and directories where it thinks it might find the debug symbols are not there. GDB告诉您认为可能会找到调试符号的文件和目录不存在。 From the names, these are Go's temporary work directories. 从名称中,这些是Go的临时工作目录。

There is a command-line option -work to go build that is described as follows: 有一个命令行选项-work可以go build ,其描述如下:

print the name of the temporary work directory and do not delete it when exiting. 打印临时工作目录的名称,退出时不要删除它。

so this might work, at the cost of some periodic manual clean-up. 因此这可能会起作用,但需要进行一些定期的手动清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM