void make_minidump(void) { auto hDbgHelp = LoadLibraryA("dbghelp"); if (hDbgHelp == NULL) return; auto pMiniDumpWriteDump = (decltype(&MiniDumpWriteDump))GetProcAddress(hDbgHelp, "MiniDumpWriteDump"); if (pMiniDumpWriteDump == NULL) return; char name[MAX_PATH]; { auto nameEnd = name + GetModuleFileNameA(GetModuleHandleA(0), name, MAX_PATH); SYSTEMTIME t; GetSystemTime(&t); wsprintfA(nameEnd - strlen(".exe"), "_%4d%02d%02d_%02d%02d%02d.dmp", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); } HANDLE hFile = CreateFileA(name, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return; pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory | MiniDumpWithFullMemory | MiniDumpWithPrivateWriteCopyMemory), NULL, NULL, NULL); CloseHandle(hFile); return; }
void make_minidump(EXCEPTION_POINTERS* e) { write_text_to_log_file("Dump requested"); auto hDbgHelp = LoadLibraryA("dbghelp"); if (hDbgHelp == nullptr) return; auto pMiniDumpWriteDump = (decltype(&MiniDumpWriteDump))GetProcAddress(hDbgHelp, "MiniDumpWriteDump"); if (pMiniDumpWriteDump == nullptr) return; auto hFile = CreateFileA(get_storage_dir_path("ENT-minidump.dmp"), GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return; MINIDUMP_EXCEPTION_INFORMATION exceptionInfo; exceptionInfo.ThreadId = GetCurrentThreadId(); exceptionInfo.ExceptionPointers = e; exceptionInfo.ClientPointers = FALSE; auto dumped = pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory), e ? &exceptionInfo : nullptr, nullptr, nullptr); CloseHandle(hFile); write_text_to_log_file("Dump complete"); return; }
void make_minidump(EXCEPTION_POINTERS* e) { DebugViewPrint(L"OccuRec: CREATING ERROR DUMP\r\n"); auto hDbgHelp = LoadLibraryA("dbghelp"); if(hDbgHelp == nullptr) return; auto pMiniDumpWriteDump = (decltype(&MiniDumpWriteDump))GetProcAddress(hDbgHelp, "MiniDumpWriteDump"); if(pMiniDumpWriteDump == nullptr) return; char name[MAX_PATH]; { auto nameEnd = name + GetModuleFileNameA(GetModuleHandleA(0), name, MAX_PATH); SYSTEMTIME t; GetSystemTime(&t); wsprintfA(nameEnd - strlen(".exe"), "_%4d%02d%02d_%02d%02d%02d.dmp", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); } auto hFile = CreateFileA(name, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if(hFile == INVALID_HANDLE_VALUE) return; MINIDUMP_EXCEPTION_INFORMATION exceptionInfo; exceptionInfo.ThreadId = GetCurrentThreadId(); exceptionInfo.ExceptionPointers = e; exceptionInfo.ClientPointers = FALSE; auto dumped = pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory), e ? &exceptionInfo : nullptr, nullptr, nullptr); CloseHandle(hFile); return; }
void MakeDump(EXCEPTION_POINTERS* e) { TCHAR tszFileName[MAX_BUFF_SIZE] = { 0 }; SYSTEMTIME stTime = { 0 }; GetSystemTime(&stTime); StringCbPrintf(tszFileName, _countof(tszFileName), _T("%s_%4d%02d%02d_%02d%02d%02d.dmp"), _T("DungeonServerDump"), stTime.wYear, stTime.wMonth, stTime.wDay, stTime.wHour, stTime.wMinute, stTime.wSecond); HANDLE hFile = CreateFile(tszFileName, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return; MINIDUMP_EXCEPTION_INFORMATION exceptionInfo; exceptionInfo.ThreadId = GetCurrentThreadId(); exceptionInfo.ExceptionPointers = e; exceptionInfo.ClientPointers = FALSE; MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory | MiniDumpWithFullMemory), e ? &exceptionInfo : NULL, NULL, NULL); if (hFile) { CloseHandle(hFile); hFile = NULL; } }
LONG WINAPI UnhandledFilter ( struct _EXCEPTION_POINTERS *pExceptionInfo ) { LONG retval = EXCEPTION_CONTINUE_SEARCH; bException = TRUE; // firstly see if dbghelp.dll is around and has the function we need // look next to the EXE first, as the one in System32 might be old // (e.g. Windows 2000) HMODULE hDll = NULL; string_path szDbgHelpPath; if (GetModuleFileName( NULL, szDbgHelpPath, _MAX_PATH )) { char *pSlash = strchr( szDbgHelpPath, '\\' ); if (pSlash) { xr_strcpy (pSlash+1, "DBGHELP.DLL" ); hDll = ::LoadLibrary( szDbgHelpPath ); } } if (hDll==NULL) { // load any version we can hDll = ::LoadLibrary( "DBGHELP.DLL" ); } LPCTSTR szResult = NULL; if (hDll) { MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" ); if (pDump) { string_path szDumpPath; string_path szScratch; string64 t_stemp; // work out a good place for the dump file timestamp (t_stemp); xr_strcpy ( szDumpPath, "logs\\" ); xr_strcat ( szDumpPath, Core.ApplicationName ); xr_strcat ( szDumpPath, "_" ); xr_strcat ( szDumpPath, Core.UserName ); xr_strcat ( szDumpPath, "_" ); xr_strcat ( szDumpPath, t_stemp ); xr_strcat ( szDumpPath, ".mdmp" ); // create the file HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if (INVALID_HANDLE_VALUE==hFile) { // try to place into current directory MoveMemory (szDumpPath,szDumpPath+5,strlen(szDumpPath)); hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); } if (hFile!=INVALID_HANDLE_VALUE) { _MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = ::GetCurrentThreadId(); ExInfo.ExceptionPointers = pExceptionInfo; ExInfo.ClientPointers = NULL; // write the dump MINIDUMP_TYPE dump_flags = MINIDUMP_TYPE(MiniDumpNormal | MiniDumpFilterMemory | MiniDumpScanMemory ); BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, dump_flags, &ExInfo, NULL, NULL ); if (bOK) { xr_sprintf( szScratch, "Saved dump file to '%s'", szDumpPath ); szResult = szScratch; retval = EXCEPTION_EXECUTE_HANDLER; } else { xr_sprintf( szScratch, "Failed to save dump file to '%s' (error %d)", szDumpPath, GetLastError() ); szResult = szScratch; } ::CloseHandle(hFile); } else { xr_sprintf( szScratch, "Failed to create dump file '%s' (error %d)", szDumpPath, GetLastError() ); szResult = szScratch; } } else { szResult = "DBGHELP.DLL too old"; } } else { szResult = "DBGHELP.DLL not found"; } string1024 reason; xr_sprintf (reason,"*** Internal Error ***\n%s",szResult); bool ref = false; Debug.backend (reason,0,0,0,0,0,0,ref); return retval; }