Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB - how to find out from where program exited

Tags:

gdb

While debugging a program in GDB, I get an unexpected "program exited normally". So I'm wondering if is there a way to find out from where (which line) the program exited.

Program is multi-threaded, if that matters.

like image 592
NoSenseEtAl Avatar asked Jun 16 '11 18:06

NoSenseEtAl


People also ask

How do you set exits in GDB?

To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.

Can you step back in GDB?

If the target environment supports it, gdb can allow you to “rewind” the program by running it backward. A target environment that supports reverse execution should be able to “undo” the changes in machine state that have taken place as the program was executing normally.

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. To specify other places where gdb should stop, see the section on breakpoints below.

How do I know if I have BT in GDB?

To print a backtrace of the entire stack, use the backtrace command, or its alias bt . This command will print one line per frame for frames in the stack. By default, all stack frames are printed. You can stop the backtrace at any time by typing the system interrupt character, normally Ctrl-c .


2 Answers

You could try the GDB command break exit to set a breakpoint on the exit(2) library call. If that doesn't get you what you need, maybe break _exit. You might need to start your program with 'sta' before getting the latter breakpoint to take. In either case, you should then be able to use the where command to get a stack trace showing where you were when the program decided to exit.

like image 199
acm Avatar answered Sep 30 '22 15:09

acm


Set a breakpoint on _exit and then examine the stack.

like image 27
Vinicius Kamakura Avatar answered Sep 30 '22 16:09

Vinicius Kamakura