VS2008 dump
1 #include <DbgHelp.h> 2 #include <stdlib.h> 3 #pragma comment(lib, "dbghelp.lib") 4 5 BOOL IsDataSectionNeeded(const WCHAR* pModuleName) 6 { 7 if(pModuleName == 0) 8 { 9 return FALSE; 10 } 11 12 WCHAR szFileName[_MAX_FNAME] = L""; 13 _wsplitpath(pModuleName, NULL, NULL, szFileName, NULL); 14 if(wcsicmp(szFileName, L"ntdll") == 0) 15 return TRUE; 16 17 return FALSE; 18 } 19 20 BOOL CALLBACK MiniDumpCallback(PVOID 21 pParam,const PMINIDUMP_CALLBACK_INPUT pInput, 22 PMINIDUMP_CALLBACK_OUTPUT pOutput) 23 { 24 if(pInput == 0 || pOutput == 0) 25 return FALSE; 26 27 switch(pInput->CallbackType) 28 { 29 case ModuleCallback: 30 if(pOutput->ModuleWriteFlags & ModuleWriteDataSeg) 31 if(!IsDataSectionNeeded(pInput->Module.FullPath)) 32 pOutput->ModuleWriteFlags &= (~ModuleWriteDataSeg); 33 case IncludeModuleCallback: 34 case IncludeThreadCallback: 35 case ThreadCallback: 36 case ThreadExCallback: 37 return TRUE; 38 default:; 39 } 40 41 return FALSE; 42 } 43 44 LONG __stdcall AppUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo) 45 { 46 // create dump file 50 TCHAR szPath[MAX_PATH] = {0}; 51 ::GetModuleFileName(NULL, szPath, MAX_PATH); 52 CString strPath(szPath); 53 strPath = strPath.Mid(0, strPath.ReverseFind(_T('\\'))+1); 54 strPath += _T("myApp.dmp"); 55 56 HANDLE hFile = CreateFile(strPath, GENERIC_READ | GENERIC_WRITE, 57 FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 58 59 if((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) 60 { 61 MINIDUMP_EXCEPTION_INFORMATION mdei; 62 mdei.ThreadId = GetCurrentThreadId(); 63 mdei.ExceptionPointers = pExceptionInfo; 64 mdei.ClientPointers = NULL; 65 66 MINIDUMP_CALLBACK_INFORMATION mci; 67 mci.CallbackRoutine = (MINIDUMP_CALLBACK_ROUTINE)MiniDumpCallback; 68 mci.CallbackParam = 0; 69 70 ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), hFile, MiniDumpNormal, (pExceptionInfo != 0) ? &mdei : 0, NULL, &mci); 71 CloseHandle(hFile); 72 } 73 74 return EXCEPTION_EXECUTE_HANDLER; 75 } 76 77 void StartUnhandledExceptionFilter() 78 { 79 ::SetUnhandledExceptionFilter(AppUnhandledExceptionFilter); 80 }