tags:

views:

91

answers:

2

I'm building an application for Windows XP using the MinGW tool chain and it sometimes crashes unexpectedly. So, I'm trying to use a debugger (Gdb) but the program exits with code 03 before anything happens. In fact, all I see from GDB is:

[New thread 3184.0x7b8]
[New thread 3184.0xef8]

Program exited with code 03.

My suspicion is that there is some failed dynamic linking of a dependency (which are Qt, VTK, and ITK, all built with MinGW). However, this does not happen when I just run the program normally. Or if it happens, it appears to be intermittent and well after the program is launched and running. NOTE: I'm also using Cmake for cross compiling.

What should I do? What can I try?

A: 

Code 3 is usually returned on a segfault. Try switching to Linux and debugging the program with electric fence. It might give you some extra insight.

mingos
Thanks for the advice, but the crashes don't happen anywhere but in Windows.
Tim
+2  A: 

Add a callback via signal(SIGABRT, <callback>) to catch the call to abort before it shuts down the process. If this happens before you hit main() you might have to resort to a static global and compiler trickery to catch it.

MSN
Ah, that is a good idea. Thanks.
Tim
Yeah. I had to figure this out when our assert macro got rerouted to the macro defined in <assert.h>. It's awesome.
MSN
Cool stuff, I thank thee for a great idea, @MSN, I need to try that myself :)
mingos
If already in GDB, you could try setting a few breakpoints, as well: `catch throw`, and `b raise`, then run your program with whatever args. This should break when either an exception is raised or a signal is invoked.
Nathan Ernst