函数调用后 GDB 断点混淆?

发布于 2024-09-09 03:37:21 字数 657 浏览 1 评论 0原文

我有一个依赖于外部共享库的程序,但是在执行库内的函数后,我失去了使用断点的能力。

在执行此函数之前,我可以像平常一样中断和单步执行,但在完成之后它永远不会中断。如果我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂归处 2024-09-16 03:37:21

vfork(2)exec(2) 的组合使事情变得混乱。引用gdb手册(调试分叉 ):

在某些系统上,当 vfork 生成子进程时,在 exec 调用完成之前,您无法调试子进程或父进程。
...

默认情况下,执行 exec 调用后,gdb 会丢弃前一个可执行映像的符号。您可以使用 set follow-exec-mode 命令更改此行为。

follow-fork-mode 设置为 parent 并将 follow-exec-mode 设置为 same

或者,如果您的安装支持多进程调试(它应该支持,因为您的 gdb 版本是 7.1),请尝试使用 info lowers 查找您的原始进程并使用以下命令切换到它: 劣势

It's the combination of vfork(2) and exec(2) that's messing things up. Quoting from gdb manual (debugging forks):

On some systems, when a child process is spawned by vfork, you cannot debug the child or parent until an exec call completes.
...

By default, after an exec call executes, gdb discards the symbols of the previous executable image. You can change this behaviour with the set follow-exec-mode command.

Keep follow-fork-mode set to parent and set follow-exec-mode to same.

Alternatively, if your installation supports multi-process debugging (it should, since your gdb version is 7.1), try using info inferiors to find your original process and switching to it with inferior <num>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文