GDB breakpoints confused after a function call?
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 afterw开发者_开发百科ards 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?
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 byvfork
, you cannot debug the child or parent until anexec
call completes.
...
By default, after anexec
call executes, gdb discards the symbols of the previous executable image. You can change this behaviour with the setfollow-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>
.
精彩评论