NoSenseEtAl
NoSenseEtAl

Reputation: 30158

GDB - how to find out from where program exited

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.

Upvotes: 14

Views: 15066

Answers (3)

karlphillip
karlphillip

Reputation: 93478

Usually with the command below when the application has finished executing:

(gdb) thread apply all bt

Of course, if you want to know the exact line you must compile your application with debugging symbols, i.e. -g

Upvotes: 9

Vinicius Kamakura
Vinicius Kamakura

Reputation: 7778

Set a breakpoint on _exit and then examine the stack.

Upvotes: 5

acm
acm

Reputation: 12737

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.

Upvotes: 20

Related Questions