Testlib: Add a crash handler for Windows that prints a message.

Change-Id: I4d6559fd1b21f9f259be6a5a160361e25ea0d217
Reviewed-by: Jason McDonald <macadder1@gmail.com>
This commit is contained in:
Friedemann Kleint 2013-07-10 10:05:09 +02:00 committed by The Qt Project
parent 915f4d8c95
commit 066d32d743

View File

@ -2077,6 +2077,18 @@ FatalSignalHandler::~FatalSignalHandler()
} // namespace
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
static LONG WINAPI windowsFaultHandler(struct _EXCEPTION_POINTERS *exInfo)
{
char appName[MAX_PATH];
if (!GetModuleFileNameA(NULL, appName, MAX_PATH))
appName[0] = 0;
fprintf(stderr, "A crash occurred in %s (exception code 0x%lx).",
appName, exInfo->ExceptionRecord->ExceptionCode);
return EXCEPTION_EXECUTE_HANDLER;
}
#endif // Q_OS_WIN) && !Q_OS_WINCE
/*!
Executes tests declared in \a testObject. In addition, the private slots
\c{initTestCase()}, \c{cleanupTestCase()}, \c{init()} and \c{cleanup()}
@ -2163,6 +2175,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
# endif
SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
SetUnhandledExceptionFilter(windowsFaultHandler);
} // !noCrashHandler
#endif // Q_OS_WIN) && !Q_OS_WINCE