views:

47

answers:

1

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?

+1  A: 

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>.

Nikolai N Fetissov
@Nikolai N FetissovThank you very much for taking the time to answer my question! I checked my gdb configuration and follow-fork-mode and follow-exec-mode are already set the way you suggested be default :/. If I switch the config to follow the child, it breaks after the fork or exec or something, but if I try to switch back to debugging the parent (with inferior <parent-num>) it has no execution context. It doesn't even think it's being run!
jdizzle
"On some systems, gdb provides support for debugging programs that create additional processes using the fork or vfork functions. Currently, the only platforms with this feature are HP-UX (11.x and later only?) and gnu/Linux (kernel version 2.5.60 and later)." I'm using gdb 7.1, but a 2.4 kernel version :/ Maybe that's also contributing to my problems?
jdizzle
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.
jdizzle
Hmm, 2.4 kernels are pretty much obsolete by now. Any chance of upgrading to 2.6 series? Also try `file` command to load the symbols again.
Nikolai N Fetissov