R – Why does the Service crash at DebugBreak() on Vista

breakpointscrashservicewinapiwindows-vista

I'm writing a Win32 service in C++. I have a custom Assert macro that calls DebugBreak() (among other things). When I'm running my service under Vista, the service crashes when reaching the DebugBreak() call (an int 3 assembler opcode), showing the vista crash dialog. The error code is 80000003 (hardcoded breakpoint).

Normally I'm expecting that my service runs over the DebugBreak() call without doing anyting when no debugger is attached. Why is it crashing? Is there a possible setting to change so that it continues to run?

Best Answer

It is crashing because it is a breakpoint exception. To be on the safe side you need to either check if a debugger is attached:

if(::IsDebuggerPresent()) ::DebugBreak();

or use try/except and return 1 (exceptionexecutehandler with an empty handler) for your breakpoint exception from the filter.

Related Topic