1、調試release版
步驟
1、代碼示例
// Dump.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <dbghelp.h>
#pragma comment(lib,"Dbghelp.lib")
#include <time.h>
void CreateMiniDump(struct _EXCEPTION_POINTERS* ExceptionInfo);
LONG WINAPI MSJUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
{
CreateMiniDump(pExceptionInfo);
return EXCEPTION_CONTINUE_SEARCH;
}
void CreateMiniDump(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
//char szFile[MAX_PATH+1] = {0};
//_snprintf(szFile, MAX_PATH, ".\\cc_%u.dmp", time(NULL));
HANDLE hFile = CreateFile(L"crash.dmp", GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if( INVALID_HANDLE_VALUE == hFile )
{
return;
}
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ClientPointers = TRUE;
mei.ExceptionPointers = ExceptionInfo;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &mei, NULL, NULL);
CloseHandle(hFile);
}
int _tmain(int argc, _TCHAR* argv[])
{
SetUnhandledExceptionFilter(MSJUnhandledExceptionFilter);
_asm int 3
return 0;
}
2、運行exe,會導致崩潰,exe目錄下會多一個crash.dmp
3、雙擊dmp,VS會打開它
4、點擊“Debug with Native Only”,會看到崩潰位置
注意
1、要確保exe、pdb和源碼一致且可用。