// CRT unexpected() call handler void __cdecl CCrashHandler::UnexpectedHandler() { // Unexpected error (unexpected() function was called) // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); }
// CRT SIGTERM signal handler void CCrashHandler::SigtermHandler(int) { // Termination request (SIGTERM) // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); }
// CRT sigill signal handler void CCrashHandler::SigillHandler(int) { // Illegal instruction (SIGILL) // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); }
// CRT SIGABRT signal handler void CCrashHandler::SigabrtHandler(int) { // Caught SIGABRT C++ signal // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); }
// CRT Pure virtual method call handler void __cdecl CCrashHandler::PureCallHandler() { // Pure virtual function call // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); }
// CRT new operator fault handler int __cdecl CCrashHandler::NewHandler(size_t) { // 'new' operator memory allocation exception // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); // Unreacheable code return 0; }
// CRT invalid parameter handler void __cdecl CCrashHandler::InvalidParameterHandler( const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) { pReserved; // Invalid parameter exception // Retrieve exception information EXCEPTION_POINTERS* pExceptionPtrs = NULL; GetExceptionPointers(0, &pExceptionPtrs); // Write minidump file CreateMiniDump(pExceptionPtrs); // Terminate process TerminateProcess(GetCurrentProcess(), 1); }
int CCrashHandler::GenerateErrorReport( PCR_EXCEPTION_INFO pExceptionInfo) { crSetErrorMsg(_T("Unspecified error.")); // Validate input parameters if(pExceptionInfo==NULL) { crSetErrorMsg(_T("Exception info is NULL.")); return 1; } // Get exception pointers if not provided. if(pExceptionInfo->pexcptrs==NULL) { GetExceptionPointers(pExceptionInfo->code, &pExceptionInfo->pexcptrs); } // Collect miscellaneous crash info (current time etc.) CollectMiscCrashInfo(); // If error report is being generated manually, disable app restart. if(pExceptionInfo->bManual) m_bAppRestart = FALSE; // Let client add application-specific files / desktop screenshot // to the report via the crash callback function. if (m_lpfnCallback!=NULL && m_lpfnCallback(NULL)==FALSE) { crSetErrorMsg(_T("The operation was cancelled by client application.")); return 2; } if(m_bAddScreenshot) { m_rcAppWnd.SetRectEmpty(); // Find main app window HWND hWndMain = Utility::FindAppWindow(); if(hWndMain) { GetWindowRect(hWndMain, &m_rcAppWnd); } } // Create directory for the error report. BOOL bCreateDir = Utility::CreateFolder(m_sReportFolderName); if(!bCreateDir) { ATLASSERT(bCreateDir); CString szCaption; szCaption.Format(_T("%s has stopped working"), Utility::getAppName()); CString szMessage; // Try notify user about crash using message box. szMessage.Format(_T("Couldn't save error report.")); MessageBox(NULL, szMessage, szCaption, MB_OK|MB_ICONERROR); return 1; // Failed to create directory } // Create crash description file in XML format. CString sFileName; sFileName.Format(_T("%s\\crashrpt.xml"), m_sReportFolderName); AddFile(sFileName, NULL, _T("Crash Log"), CR_AF_MISSING_FILE_OK); int result = CreateCrashDescriptionXML(sFileName.GetBuffer(0), pExceptionInfo); ATLASSERT(result==0); // Write internal crash info to file. This info is required by // CrashSender.exe only and will not be sent anywhere. sFileName = m_sReportFolderName + _T("\\~CrashRptInternal.xml"); result = CreateInternalCrashInfoFile(sFileName, pExceptionInfo->pexcptrs); ATLASSERT(result==0); SetFileAttributes(sFileName, FILE_ATTRIBUTE_HIDDEN); // Start the CrashSender process which will take the dekstop screenshot, // copy user-specified files to the error report folder, create minidump, // notify user about crash, compress the report into ZIP archive and send // the error report. result = LaunchCrashSender(sFileName, TRUE); if(result!=0) { ATLASSERT(result==0); crSetErrorMsg(_T("Error launching CrashSender.exe")); // Failed to launch crash sender process. // Try notify user about crash using message box. CString szCaption; szCaption.Format(_T("%s has stopped working"), Utility::getAppName()); CString szMessage; szMessage.Format(_T("Error launching CrashSender.exe")); MessageBox(NULL, szMessage, szCaption, MB_OK|MB_ICONERROR); return 3; } // OK crSetErrorMsg(_T("Success.")); return 0; }