views:

93

answers:

2

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?

+2  A: 

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

Marcelo Cantos
temrniate() calls abort(), not exit().
sharptooth
@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
@Mick: in a command-line debugger, `break exit` would do just that.
Potatoswatter
@Mick: Maybe it's time to refactor code so that you don't have so many direct calls to exit()?
sharptooth
+2  A: 

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.

Potatoswatter