DWORD WINAPI CrashThread(LPVOID pParam) { CrashThreadInfo* pInfo = (CrashThreadInfo*)pParam; // Install per-thread exception handlers CrThreadAutoInstallHelper cr_install_helper(0); for(;;) { // Wait until wake up event is signaled WaitForSingleObject(pInfo->m_hWakeUpEvent, INFINITE); if(pInfo->m_bStop) break; // Exit the loop if(pInfo->m_ExceptionType==128) { // Test generate report manually test_generate_report(); } else if(crEmulateCrash(pInfo->m_ExceptionType)!=0) { // Test exception handler TCHAR szErrorMsg[256]; CString sError = _T("Error creating exception situation!\nErrorMsg:"); crGetLastErrorMsg(szErrorMsg, 256); sError+=szErrorMsg; MessageBox(NULL, sError, _T("Error"), 0); } } // Exit this thread return 0; }
void CrashRptAPITests::Test_CrAutoInstallHelper() { // Install crash handler CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail. CrAutoInstallHelper cr_install_helper(&info); TEST_ASSERT(cr_install_helper.m_nInstallStatus==0); __TEST_CLEANUP__; }
void CrashRptAPITests::Test_CrThreadAutoInstallHelper() { // Install crash handler for the main thread CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail. CrAutoInstallHelper cr_install_helper(&info); TEST_ASSERT(cr_install_helper.m_nInstallStatus==0); // Run a worker thread int nResult = -1; HANDLE hThread = CreateThread(NULL, 0, ThreadProc1, &nResult, 0, NULL); // Wait until thread exits WaitForSingleObject(hThread, INFINITE); TEST_ASSERT(nResult==0); __TEST_CLEANUP__; }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { HRESULT hRes = ::CoInitialize(NULL); // If you are running on NT 4.0 or higher you can use the following call instead to // make the EXE free threaded. This means that calls come in on a random RPC thread. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); ATLASSERT(SUCCEEDED(hRes)); // Install crash reporting CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppName = _T("WTLDemo"); // Define application name. //info.pszAppVersion = _T("1.3.1"); // Define application version. info.pszEmailSubject = _T("WTLDemo Error Report"); // Define subject for email. info.pszEmailTo = _T("*****@*****.**"); // Define E-mail recipient address. //info.pszSmtpProxy = _T("127.0.0.1"); // Use SMTP proxy. //info.pszSmtpLogin = _T("test"); // SMTP Login //info.pszSmtpPassword = _T("test"); // SMTP Password info.pszUrl = _T("http://localhost:80/crashrpt.php"); // URL for sending reports over HTTP. info.pfnCrashCallback = CrashCallback; // Define crash callback function. // Define delivery methods priorities. info.uPriorities[CR_HTTP] = 3; // Use HTTP the first. info.uPriorities[CR_SMTP] = 2; // Use SMTP the second. info.uPriorities[CR_SMAPI] = 1; // Use Simple MAPI the last. info.dwFlags = 0; info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers. //info.dwFlags |= CR_INST_APP_RESTART; // Restart the application on crash. //info.dwFlags |= CR_INST_NO_MINIDUMP; // Do not include minidump. //info.dwFlags |= CR_INST_NO_GUI; // Don't display GUI. //info.dwFlags |= CR_INST_DONT_SEND_REPORT; // Don't send report immediately, just queue for later delivery. //info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES; // Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT) //info.dwFlags |= CR_INST_SEND_MANDATORY; // Remove "Close" and "Other actions..." buttons from Error Report dialog. //info.dwFlags |= CR_INST_SHOW_ADDITIONAL_INFO_FIELDS; //!< Make "Your E-mail" and "Describe what you were doing when the problem occurred" fields of Error Report dialog always visible. info.dwFlags |= CR_INST_ALLOW_ATTACH_MORE_FILES; //!< Adds an ability for user to attach more files to crash report by clicking "Attach More File(s)" item from context menu of Error Report Details dialog. //info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS; // Send reports that were failed to send recently. //info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; info.pszDebugHelpDLL = NULL; // Search for dbghelp.dll using default search sequence. info.uMiniDumpType = MiniDumpNormal; // Define minidump size. // Define privacy policy URL. info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate"); info.pszErrorReportSaveDir = NULL; // Save error reports to the default location. info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart. //info.pszLangFilePath = _T("D:\\"); // Specify custom dir or filename for language file. //info.pszCustomSenderIcon = _T("C:\\WINDOWS\\System32\\user32.dll, 1"); // Specify custom icon for CrashRpt dialogs. info.nRestartTimeout = 50; // Install crash handlers. CrAutoInstallHelper cr_install_helper(&info); if(cr_install_helper.m_nInstallStatus!=0) { TCHAR buff[256]; crGetLastErrorMsg(buff, 256); MessageBox(NULL, buff, _T("crInstall error"), MB_OK); return FALSE; } ATLASSERT(cr_install_helper.m_nInstallStatus==0); CString sLogFile = GetAppDir() + _T("\\*.log"); CString sIniFile = _T("\\\\?\\") + GetAppDir() + _T("\\dummy.ini"); int nResult = crAddFile2(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY|CR_AF_ALLOW_DELETE); ATLASSERT(nResult==0); nResult = crAddFile2(sIniFile, NULL, _T("Dummy INI File"), 0); ATLASSERT(nResult==0); nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT|CR_AS_ALLOW_DELETE, 10); //nResult = crAddScreenshot(CR_AS_MAIN_WINDOW); ATLASSERT(nResult==0); nResult = crAddProperty(_T("AnExampleProperty"),_T("Property value")); ATLASSERT(nResult==0); nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800")); ATLASSERT(nResult==0); nResult = crAddProperty(_T("HDDSerialNumber"),_T("1234512345098765")); ATLASSERT(nResult==0); nResult = crAddProperty(_T("MACAddress"),_T("11.11.11.11")); ATLASSERT(nResult==0); nResult = crAddProperty(_T("UserName"),_T("TheUserName")); ATLASSERT(nResult==0); nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), CR_AR_ALLOW_DELETE); ATLASSERT(nResult==0); nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), CR_AR_ALLOW_DELETE); ATLASSERT(nResult==0); /* Create another thread */ g_CrashThreadInfo.m_bStop = false; g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent")); ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL); DWORD dwThreadId = 0; g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId); ATLASSERT(g_hWorkingThread!=NULL); // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used ::DefWindowProc(NULL, 0, 0, 0L); AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls hRes = _Module.Init(NULL, hInstance); ATLASSERT(SUCCEEDED(hRes)); int nRet = Run(lpstrCmdLine, nCmdShow); _Module.Term(); // Close another thread g_CrashThreadInfo.m_bStop = true; SetEvent(g_CrashThreadInfo.m_hWakeUpEvent); // Wait until thread terminates WaitForSingleObject(g_hWorkingThread, INFINITE); ::CoUninitialize(); return nRet; }
int _tmain(int argc, _TCHAR* argv[]) { CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppName = _T("WTLDemo"); // Define application name. info.pszAppVersion = _T("1.3.1"); // Define application version. info.pszEmailSubject = _T("WTLDemo Error Report"); // Define subject for email. info.pszEmailTo = _T("*****@*****.**"); // Define E-mail recipient address. //info.pszSmtpProxy = _T("127.0.0.1"); // Use SMTP proxy. //info.pszSmtpLogin = _T("test"); // SMTP Login //info.pszSmtpPassword = _T("test"); // SMTP Password info.pszUrl = _T("http://192.168.0.26:9000/Operation/CrashLog"); // URL for sending reports over HTTP. //info.pfnCrashCallback = CrashCallback; // Define crash callback function. // Define delivery methods priorities. info.uPriorities[CR_HTTP] = 3; // Use HTTP the first. info.uPriorities[CR_SMTP] = 2; // Use SMTP the second. info.uPriorities[CR_SMAPI] = 1; // Use Simple MAPI the last. info.dwFlags = 0; info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers. //info.dwFlags |= CR_INST_APP_RESTART; // Restart the application on crash. //info.dwFlags |= CR_INST_NO_MINIDUMP; // Do not include minidump. //info.dwFlags |= CR_INST_NO_GUI; // Don't display GUI. //info.dwFlags |= CR_INST_DONT_SEND_REPORT; // Don't send report immediately, just queue for later delivery. //info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES; // Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT) //info.dwFlags |= CR_INST_SEND_MANDATORY; // Remove "Close" and "Other actions..." buttons from Error Report dialog. //info.dwFlags |= CR_INST_SHOW_ADDITIONAL_INFO_FIELDS; //!< Make "Your E-mail" and "Describe what you were doing when the problem occurred" fields of Error Report dialog always visible. info.dwFlags |= CR_INST_ALLOW_ATTACH_MORE_FILES; //!< Adds an ability for user to attach more files to crash report by clicking "Attach More File(s)" item from context menu of Error Report Details dialog. //info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS; // Send reports that were failed to send recently. //info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; info.pszDebugHelpDLL = NULL; // Search for dbghelp.dll using default search sequence. info.uMiniDumpType = MiniDumpNormal; // Define minidump size. // Define privacy policy URL. //info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate"); info.pszErrorReportSaveDir = NULL; // Save error reports to the default location. info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart. //info.pszLangFilePath = _T("D:\\"); // Specify custom dir or filename for language file. //info.pszCustomSenderIcon = _T("C:\\WINDOWS\\System32\\user32.dll, 1"); // Specify custom icon for CrashRpt dialogs. // Install crash handlers. CrAutoInstallHelper cr_install_helper(&info); if(cr_install_helper.m_nInstallStatus!=0) { TCHAR buff[256]; crGetLastErrorMsg(buff, 256); MessageBox(NULL, buff, _T("crInstall error"), MB_OK); return FALSE; } assert(cr_install_helper.m_nInstallStatus==0); std::wstring sLogFile =L".\\*.log"; std::wstring sIniFile = L".\\dummy.ini"; int nResult = crAddFile2(sLogFile.c_str(), NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY|CR_AF_ALLOW_DELETE); assert(nResult==0); nResult = crAddFile2(sIniFile.c_str(), NULL, _T("Dummy INI File"), 0); assert(nResult==0); nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT|CR_AS_ALLOW_DELETE, 10); //nResult = crAddScreenshot(CR_AS_MAIN_WINDOW); assert(nResult==0); nResult = crAddProperty(_T("AnExampleProperty"),_T("Property value")); assert(nResult==0); nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800")); assert(nResult==0); nResult = crAddProperty(_T("HDDSerialNumber"),_T("1234512345098765")); assert(nResult==0); nResult = crAddProperty(_T("MACAddress"),_T("11.11.11.11")); assert(nResult==0); nResult = crAddProperty(_T("UserName"),_T("TheUserName")); assert(nResult==0); nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), CR_AR_ALLOW_DELETE); assert(nResult==0); nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), CR_AR_ALLOW_DELETE); assert(nResult==0); printf("Press Enter to simulate a null pointer exception or any other key to exit...\n"); int n = _getch(); if(n==13) { int *p = 0; *p = 0; // Access violation } int nUninstRes = crUninstall(); // Uninstall exception handlers assert(nUninstRes==0); return 0; }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { HRESULT hRes = ::CoInitialize(NULL); // If you are running on NT 4.0 or higher you can use the following call instead to // make the EXE free threaded. This means that calls come in on a random RPC thread. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); ATLASSERT(SUCCEEDED(hRes)); // Install crash reporting #ifdef TEST_DEPRECATED_FUNCS g_pCrashRptState = Install( CrashCallback, _T("*****@*****.**"), _T("Crash")); #else CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppName = _T("CrashRpt Tests"); info.pszAppVersion = _T("1.2.2"); info.pszEmailSubject = _T("Error from CrashRptTests"); info.pszEmailTo = _T("*****@*****.**"); info.pszUrl = _T("http://myappcom.com/crashrpt.php"); info.pfnCrashCallback = CrashCallback; // Define crash callback function // Define sending priorities info.uPriorities[CR_HTTP] = 3; // Use HTTP the first info.uPriorities[CR_SMTP] = 2; // Use SMTP the second info.uPriorities[CR_SMAPI] = 1; // Use Simple MAPI the last info.dwFlags = 0; info.dwFlags |= CR_INST_ALL_EXCEPTION_HANDLERS; // Install all available exception handlers info.dwFlags |= CR_INST_HTTP_BINARY_ENCODING; // Use binary encoding for HTTP uploads (recommended). info.pszDebugHelpDLL = NULL; // Search for dbghelp.dll using default search sequence info.uMiniDumpType = MiniDumpNormal; // Define minidump size info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate"); info.pszErrorReportSaveDir = NULL; // Save error reports to the default location CrAutoInstallHelper cr_install_helper(&info); ATLASSERT(cr_install_helper.m_nInstallStatus==0); if(cr_install_helper.m_nInstallStatus!=0) { TCHAR buff[256]; crGetLastErrorMsg(buff, 256); MessageBox(NULL, buff, _T("crInstall error"), MB_OK); return FALSE; } #endif //TEST_DEPRECATED_FUNCS /* Create another thread */ g_CrashThreadInfo.m_pCrashRptState = g_pCrashRptState; g_CrashThreadInfo.m_bStop = false; g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent")); ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL); DWORD dwThreadId = 0; g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId); ATLASSERT(g_hWorkingThread!=NULL); // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used ::DefWindowProc(NULL, 0, 0, 0L); AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls hRes = _Module.Init(NULL, hInstance); ATLASSERT(SUCCEEDED(hRes)); int nRet = Run(lpstrCmdLine, nCmdShow); _Module.Term(); // Close another thread g_CrashThreadInfo.m_bStop = true; SetEvent(g_CrashThreadInfo.m_hWakeUpEvent); // Wait until thread terminates WaitForSingleObject(g_hWorkingThread, INFINITE); #ifdef TEST_DEPRECATED_FUNCS // Uninstall crash reporting Uninstall(g_pCrashRptState); #endif //TEST_DEPRECATED_FUNCS ::CoUninitialize(); return nRet; }
int main(int argc, char *argv[]) { qRegisterMetaType<CurrentStatusUpdate>("CurrentStatusUpdate"); qRegisterMetaType<Items>("Items"); qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>"); qRegisterMetaType<std::vector<ItemLocation>>("std::vector<ItemLocation>"); qRegisterMetaType<QsLogging::Level>("QsLogging::Level"); qRegisterMetaType<TabSelection::Type>("TabSelection::Type"); QLocale::setDefault(QLocale::C); std::setlocale(LC_ALL, "C"); #if defined(CRASHRPT) && !defined(_DEBUG) CR_INSTALL_INFOW info; memset(&info, 0, sizeof(info)); info.cb = sizeof(info); info.pszAppName = L"Acquisition"; WCHAR wversion[64]; MultiByteToWideChar(CP_UTF8, 0, VERSION_NAME, -1, wversion, sizeof(wversion) / sizeof(wversion[0])); info.pszAppVersion = wversion; // URL for sending reports over HTTP. info.pszUrl = L"https://xyz.is/crashfix/index.php/crashReport/uploadExternal"; // Define delivery transport priorities. info.uPriorities[CR_HTTP] = 1; // Use HTTP. info.uPriorities[CR_SMTP] = CR_NEGATIVE_PRIORITY; // Not use SMTP. info.uPriorities[CR_SMAPI] = CR_NEGATIVE_PRIORITY; // Not use Simple MAPI. // Define flags. info.dwFlags = 0; info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers. info.dwFlags |= CR_INST_HTTP_BINARY_ENCODING; // Use binary encoding for HTTP uploads (recommended). CrAutoInstallHelper cr_install_helper(&info); #endif InitModlist(); QApplication a(argc, argv); Filesystem::Init(); QFontDatabase::addApplicationFont(":/fonts/Fontin-SmallCaps.ttf"); QCommandLineParser parser; QCommandLineOption option_test("test"), option_data_dir("data-dir", "Where to save Acquisition data.", "data-dir"); parser.addOption(option_test); parser.addOption(option_data_dir); parser.process(a); if (parser.isSet(option_test)) return test_main(); if (parser.isSet(option_data_dir)) Filesystem::SetUserDir(parser.value(option_data_dir).toStdString()); QsLogging::Logger& logger = QsLogging::Logger::instance(); logger.setLoggingLevel(QsLogging::InfoLevel); const QString sLogPath(QDir(Filesystem::UserDir().c_str()).filePath("log.txt")); QsLogging::DestinationPtr fileDestination( QsLogging::DestinationFactory::MakeFileDestination(sLogPath, true, 10 * 1024 * 1024, 0) ); QsLogging::DestinationPtr debugDestination( QsLogging::DestinationFactory::MakeDebugOutputDestination() ); logger.addDestination(debugDestination); logger.addDestination(fileDestination); QLOG_DEBUG() << "-------------------------------------------------------------------------------"; QLOG_DEBUG() << "Built with Qt" << QT_VERSION_STR << "running on" << qVersion(); LoginDialog login(std::make_unique<Application>()); login.show(); return a.exec(); }