Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Visual Studio break just before program stops?

Ok, I got this multi-threaded C++ program that I try to debug in Visual Studio 2008.

Sometimes (usually after a random time between one and two hours of computations), the program stops, exits debug mode after writing in the debug window :

The thread 'Win32 Thread' (0x1560) has exited with code 3 (0x3).
The thread 'Win32 Thread' (0x5fc) has exited with code 3 (0x3).
...

And so on for all the threads involved.

AFAIK exit code 3 indicates a failure of something, I'd expect VS to intercept the exception and to break on it so I could try see what is the error and what caused it.

I tried to activate all the exception-catching in visual studio Debug menu, but it didn't change anything.

Is there a way to tell VS that I want a break when this anormal exit occurs ?

like image 226
Louen Avatar asked Sep 14 '11 12:09

Louen


1 Answers

My guess: you're hitting an assertion failure and the CRT cannot create the message window (for some reason). This leads to an exit(3) call. I'm not sure if that will kill all threads with that exit code. Perhaps all of your threads are failing in the same way once something goes wrong.

Try adding a _CrtSetReportMode call at the beginning of your program to force the assertion failure messages to the output window in the debugger. Then, you should see the details of the assertion failure in the debug output window before the series of thread exit messages.

like image 200
Adrian McCarthy Avatar answered Oct 13 '22 21:10

Adrian McCarthy