1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #ifdef Q_OS_WIN
#pragma once #include <tchar.h> #include <Windows.h> #include <DbgHelp.h> #include <QDebug> #pragma comment(lib, "user32.lib")
int GenerateMiniDump(PEXCEPTION_POINTERS pExceptionPointers) { typedef BOOL(WINAPI* MiniDumpWriteDumpT)( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION ); MiniDumpWriteDumpT pfnMiniDumpWriteDump = NULL; HMODULE hDbgHelp = LoadLibrary(_T("DbgHelp.dll")); if (NULL == hDbgHelp) { return EXCEPTION_CONTINUE_EXECUTION; } pfnMiniDumpWriteDump = (MiniDumpWriteDumpT)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
if (NULL == pfnMiniDumpWriteDump) { FreeLibrary(hDbgHelp); return EXCEPTION_CONTINUE_EXECUTION; } TCHAR szFileName[MAX_PATH] = { 0 }; TCHAR szVersion[] = TEXT("DumpFile"); SYSTEMTIME stLocalTime; GetLocalTime(&stLocalTime); wsprintf(szFileName, TEXT("%s-%04d%02d%02d-%02d%02d%02d.dmp"), szVersion, stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond); HANDLE hDumpFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); if (INVALID_HANDLE_VALUE == hDumpFile) { FreeLibrary(hDbgHelp); return EXCEPTION_CONTINUE_EXECUTION; } MINIDUMP_EXCEPTION_INFORMATION expParam; expParam.ThreadId = GetCurrentThreadId(); expParam.ExceptionPointers = pExceptionPointers; expParam.ClientPointers = FALSE; pfnMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpWithDataSegs, (pExceptionPointers ? &expParam : NULL), NULL, NULL); CloseHandle(hDumpFile); FreeLibrary(hDbgHelp); qDebug() << "生成 pump"; return EXCEPTION_EXECUTE_HANDLER; }
LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS lpExceptionInfo) { if (IsDebuggerPresent()) { return EXCEPTION_CONTINUE_SEARCH; } return GenerateMiniDump(lpExceptionInfo); }
#endif
|