函数调用后 GDB 断点混淆?
我有一个依赖于外部共享库的程序,但是在执行库内的函数后,我失去了使用断点的能力。
在执行此函数之前,我可以像平常一样中断和单步执行,但在完成之后它永远不会中断。如果我尝试使用 start
第二次执行程序,它甚至不会在 main 上中断。这不是内联函数问题,因为我之前已经破坏了这些函数,当我注释掉这个特定函数时,一切都开始重新工作。
以前有人遇到过这样的事情吗?我能做些什么?
将 gdb 7.1 与 gcc 3.2.3 一起使用
编辑: 经过用户的一些提示后,我发现该进程是在库调用内部分叉的。我不确定它在做什么(而且我真的不在乎)。我能以某种方式弥补这一点吗?我小时候一直在尝试跟随分叉模式,但我真的很困惑一旦分叉后会发生什么,而且我似乎不知道如何继续执行或做任何有用的事情。
编辑: 进一步调查。据我所知,gdb 在某处丢失了所有符号信息。第二次运行后,所有符号都会解析为 @plt 地址,而不是它们在第一次运行时解析为的实际地址。就像不知何故,进程的第二次加载会丢失第一次获得的所有信息,并拒绝重新加载它。我很困惑!!
编辑: 所以我将问题追溯到popen调用的vfork。显然 gdb 与 popen 配合不好?一旦我脱离 popen'd vforked 进程,我就会丢失所有符号。我也在网上读到了一些关于这方面的报道。 还有希望吗?
I have a program that depends on an external shared library, but after a function inside the library gets executed I lose the ability to use breakpoints.
I can break and step like normal up until I execute this function, but afterwards it is finished it never breaks. It won't even break on main if I try and use start
for the second time executing the program. It's not an inlined function problem, because I've broken on these functions before and when I comment out this particular function everything starts to work again.
Has anyone ever encountered anything like this before? What can I do?
Using gdb 7.1 with gcc 3.2.3
Edit:
After some hints from users I figured out that the process is forking inside the library call. I'm not sure what it's doing (and I really don't care). Can I somehow compensate for this? I've been experimenting with the follow-fork-mode as child, but I'm really confused what happens once it forks and I can't seem to figure out how to continue execution or do anything of use.
Edit:
Further investigation. The nearest I can tell, gdb is losing all its symbol information somewhere. After the 2nd run, all symbols resolve to the @plt address and not to the actual address that they resolved to on the first run. Like somehow the second loading of the process loses all the info it gained the first time around and refuses to reload it. I'm so confused!!
Edit:
So I traced down the problem to the vfork of a popen call. Apparently gdb doesn't play nice with popen? As soon as I detach from the popen'd vforked process, I lose all my symbols. I've read some reports online about this as well. Is there any hope?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
vfork(2)
和exec(2)
的组合使事情变得混乱。引用gdb
手册(调试分叉 ):将
follow-fork-mode
设置为parent
并将follow-exec-mode
设置为same
。或者,如果您的安装支持多进程调试(它应该支持,因为您的
gdb
版本是 7.1),请尝试使用info lowers
查找您的原始进程并使用以下命令切换到它:劣势
。It's the combination of
vfork(2)
andexec(2)
that's messing things up. Quoting fromgdb
manual (debugging forks):Keep
follow-fork-mode
set toparent
and setfollow-exec-mode
tosame
.Alternatively, if your installation supports multi-process debugging (it should, since your
gdb
version is 7.1), try usinginfo inferiors
to find your original process and switching to it withinferior <num>
.