13
votes

I have an application that I am debugging and I'm trying to understand how gdb works and why I am not able to step through the application sometimes. The problem that I am experiencing is that gdb will hang and the process it is attached to will enter a defunct state when I am stepping through the program. After gdb hangs and I have to kill it to free the terminal (ctrl-C does not work, I have to do this from a different terminal window by getting the process id for that gdb session and using kill -9).

I'm guessing that gdb is hanging because it's waiting for the application to stop at the next instruction and somehow the application finished execution without gdb identifying this. But that's just speculation on my part from the behavior I've observed thus far. So my question is if anyone has seen this type of behavior before and/or could suggest what the cause might be. I think that might help me improve my debugging strategy.

In case it matters I'm using g++ 4.4.3, gdb 7.1, running on Ubuntu 10.04 x86_64.

2
Is there some minimal testcase you can give? I mean, as written, its very hard to answer why it might be happening—other than "could be because gdb has a bug".derobert
thanks for the suggestion. Right now the application has a lot of library code, but I'll see if I can make a small test case that I could post as an example.Gabriel Southern
I would recommend to use a more recent gdb. Current version is 7.3 and they did a lot of progress. (and BTW, using a more recent g++ ie 4.6.2 would also be helpful; since GCC also progressed on debugging information).Basile Starynkevitch
I'm using what's installed with the Ubuntu 10.04 LTS release, and I'm not likely to upgrade until 12.04 is out and tested with the systems we use. But testing with a newer version of gdb is a good idea for checking the specific problem I'm seeing just in case it is a bug with gdb. So thanks for the suggestion I'll try that with one of the systems I can use.Gabriel Southern
@BasileStarynkevitch thanks for the suggestion. I finally got around to trying gdb 7.4 and it seems like that fixed the problem I had so I guess there was some bug that had already been solved.Gabriel Southern

2 Answers

5
votes

I'd say the debugged process wouldn't sit idle if it was the cause of the hang. Every time GDB has completed a step, it has to update any expressions you required to print. It may include following pointers and so, and in some case, it may fail there (although I don't remind of a real "hang"). It also typically try to update your stack trace. If the stack trace has been corrupted and is no longer coherent, it could be trapped into an endless loop. Attaching gdb to strace to see what kind of activity is going on during the hang could be a good way to go one step further into figuring out the problem.

(e.g. accessing sources through a no-longer-working NFS/SSHFS mount is one of the most frequent reason for gdb to hang, here :P)

4
votes

I had a similar problem and solved it by sending a CONT signal to the process being debugged.