Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use gdb to find where program stuck

Tags:

c

debugging

gdb

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"?

like image 510
Stepan Loginov Avatar asked Jul 17 '14 18:07

Stepan Loginov


People also ask

At which point does GDB stop a running program?

gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program.

How do you stop an infinite loop in GDB?

Start calc from within gdb using the run command. It will go into an infinite loop. Press Ctrl-C (like before) to stop your program.

What does GDB where do?

GDB allows you to do things like run the program up to a certain point then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line. GDB uses a simple command line interface.


1 Answers

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.

like image 119
Employed Russian Avatar answered Sep 30 '22 10:09

Employed Russian