Use gdb to find where program stuck

cdebugginggdb

My program is not working correctly.
It looks like it is stuck in an infinite loop or a bad mutex lock/unlock. But, I have no idea where the bug is.
I tried using gdb for debugging.

I can't use gdb backtrace command because I don't designate breakpoint.
And I can't designate it because I don't have any idea where the error is.

Does gdb have instrument for backtrace "on the fly"?

Best Answer

I can't use gdb backtrace command because I don't designate breakpoint.

Yes, you can.

All you need is for the inferior (being debugged) program to be stopped somewhere.

When you first attach to the program, GDB will stop all threads, and you can examine where they are. Later, you can hit Ctrl-C, and again look at all threads. A useful command is thread apply all where.