views:

422

answers:

2

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?

+2  A: 

Normally I'm expecting that my service runs over the DebugBreak() call without doing anyting when no debugger is attached. Why is it crashing?

The MSDN Help for the DebugBreak function says, "If the process is not being debugged, the function uses the search logic of a standard exception handler. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception."

Is there a possible setting to change so that it continues to run?

You could try adding a Structured Exception Handler.

Alternatively, check some run-time flag before calling DebugBreak.

ChrisW
Of course both answers are correct. Thanks for the help, I wasn't aware that DebugBreak() causes an exception.
vividos
+5  A: 

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.