문제

My application has custom crash-handling built-in (see John Robbins' excellent book about "Debugging Windows Applications"). To test this functionality, I always used the Windows function DebugBreak() and this always worked perfectly. But since Windows 7, calling this function just says "A breakpoint has been reached" and stops the application without calling my crash handlers.

I could always put this code in my application to test the crash-functionality:

int *ptr = (int *)0xdeadbeef;
*ptr = 123456789;

Or even add several cases, just in case 0xdeadbeef is a valid address:

int *ptr = (int *)0xdeadbeef;
*ptr = 123456789;
ptr = (int *)0L;
*ptr = 123456789;
ptr = (int *)0xffffffff;
*ptr = 123456789;

But I was wondering: isn't there a cleaner way to crash your application under Windows?

도움이 되었습니까?

해결책

Just create a null pointer to an object with some member functions a try and call one of them? And maybe do it in a function so you know what it daoes

void CrashApp()
{
    MyObject * ptr = 0;
    ptr->Function();
}

Definitely the easiest way and pretty clear whats going on

다른 팁

You can use __debugbreak() intrinsic instead of DebugBreak() function. This does not say anything and crashes with EXCEPTION_BREAKPOINT

RaiseException() is yet another way to crash.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top