static DWORD WINAPI CrashDumpThread(LPVOID data) { WaitForSingleObject(gDumpEvent, INFINITE); if (!gCrashed) return 0; printflush("Captain, we've got a crash!\n"); if (!dbghelp::Load()) { printflush("CrashDumpThread(): dbghelp::Load() failed"); return 0; } if (!dbghelp::Initialize(L"")) { printflush("CrashDumpThread(): dbghelp::Initialize() failed"); return 0; } if (!dbghelp::HasSymbols()) { printflush("CrashDumpThread(): dbghelp::HasSymbols() is false"); return 0; } str::Str<char> s(16 * 1024); dbghelp::GetExceptionInfo(s, gMei.ExceptionPointers); dbghelp::GetAllThreadsCallstacks(s); s.Append("\r\n"); printflush(s.LendData()); return 0; }
static void InstallCrashHandler() { gDumpEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); if (!gDumpEvent) { printflush("InstallCrashHandler(): CreateEvent() failed\n"); return; } gDumpThread = CreateThread(nullptr, 0, CrashDumpThread, nullptr, 0, 0); if (!gDumpThread) { printflush("InstallCrashHandler(): CreateThread() failed\n"); return; } gPrevExceptionFilter = SetUnhandledExceptionFilter(DumpExceptionHandler); }
int RegressMain() { RedirectIOToConsole(); if (!FindTestFilesDir()) { return Usage(); } InstallCrashHandler(); InitAllCommonControls(); ScopedGdiPlus gdi; mui::Initialize(); RunTests(); printflush("All tests completed successfully!\n"); mui::Destroy(); UninstallCrashHandler(); system("pause"); return 0; }