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.
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.
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.
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.
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 .
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.
Set a breakpoint on _exit and then examine the stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With