Take the 2-minute tour ×

I am trying to debug a program that unexpectedly shuts down. When I say "shuts down, I mean one moment I am seeing all the windows being displayed, each of which is showing all the right data,then suddenly all the windows disappear. The is no messagebox reporting anything wrong. So I tried running the program in the debugger hoping that it would somehow trap whatever was causing the program to abort, but even within the debugger the program simply ends abruptly. The last line in the debugger is:

The program '[5500] test.exe: Native' has exited with code 0 (0x0).

My program, which is extremely large and extremely old, has a lot of self diagnostics. My suspicion is that perhaps a self test has failed and maybe I just called "exit()", forgetting to pop up a dialog explaining why.

My question now is, how can I find out from which point in the code, my program quit?

share|improve this question
One of the solutions is to search all code for calls to functions like exit() and put breakpoints there. Really if you have calls to exit() unwrapped it is a sign of bad design - you should have a wrapper function that shows a message and then calls exit(). –  sharptooth Apr 12 '10 at 11:16
add comment

2 Answers

up vote 2 down vote accepted

Marcelo's answer is great. If for some reason you can't break on exit, install a function (takes no arguments, returns void) with atexit and break inside that.

share|improve this answer
add comment

Set a breakpoint on exit() and terminate() (maybe one calls the other, but I'm not sure).

share|improve this answer
temrniate() calls abort(), not exit(). –  sharptooth Apr 12 '10 at 11:18
@Marcelo Cantos: You say "Set a breakpoint on exit()" as if I only had one of them... but there are hundreds. Are you suggesting I somehow put a breakopoint within exit()? –  Mick Apr 12 '10 at 11:42
@Mick: in a command-line debugger, break exit would do just that. –  Potatoswatter Apr 12 '10 at 12:21
@Mick: Maybe it's time to refactor code so that you don't have so many direct calls to exit()? –  sharptooth Apr 12 '10 at 12:34
add comment

Your Answer


