调试Go程序时出现奇怪的行为,使用GDB。

huangapple go评论85阅读模式
英文:

Strange behavior when debugging Go with GDB

问题

我有一个使用GDB(也包括Eclipse/Goclipse,但它使用的是GDB,所以都是一样的)调试的Go程序。偶尔,当我告诉GDB next 时,它的行为就像我告诉它 continuefinish 一样。就好像可执行文件中缺少堆栈/帧等信息一样。有什么帮助吗?

gdb -v 的输出是:
>版权所有(C)2013年自由软件基金会
GNU通用公共许可证版本3+:GNU通用公共许可证第3版或更高版本 <http://gnu.org/licenses/gpl.html>
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,没有任何保证。输入“show copying”
和“show warranty”以获取详细信息。
此GDB配置为“x86_64-apple-darwin13.1.0”。
有关错误报告说明,请参见:
<http://www.gnu.org/software/gdb/bugs/>。

go -v 的输出是:
>go version go1.2.1 darwin/amd64

两者都是在OSX.9下使用MacPorts安装的。

英文:

I have a Go program that I'm debugging using GDB (also Eclipse/Goclipse, but that uses GDB so it's all the same). Occasionally, when I tell GDB next, it acts like I told it to continue or finish. It's like there's missing stack/frame/etc information in the executable. Help?

gdb -v gives:
>Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin13.1.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

go -v gives:
>go version go1.2.1 darwin/amd64

Both were installed with MacPorts under OSX.9

答案1

得分: 2

这不仅仅是在OSX上出现的问题。gdb并不真正理解,并且不能始终跟踪goroutines,因为它们可以在操作系统线程之间调度。

你可以尝试使用另一个断点再次捕获执行,但我认为你没有太多其他选择。

对于堆栈跟踪和断点,GDB仍然很有用,但是可靠地逐步执行代码在可预见的未来内可能不起作用。关于持续改进gdb还是放弃它而转向新的工具,golang开发者邮件列表上有过讨论,但没有公告。

英文:

It's not just OSX. gdb doesn't really understand, and can't always follow goroutines, since they can be scheduled across OS threads.

You can always try to catch the execution again later with another breakpoint, but I don't think there's much else you can do.

GDB is still useful for stacktraces and breakpoints, but stepping through code just isn't going to work reliably for the foreseeable future. There has been discussion on the golang dev mailing list about continually improving gdb versus abandoning it in favor of something new; but no announcements have been made.

huangapple
  • 本文由 发表于 2014年6月5日 05:32:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/24047959.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定