现在的位置: 首页 > 综合 > 正文

dump文件调试

2017年12月21日 ⁄ 综合 ⁄ 共 1101字 ⁄ 字号 评论关闭

问题
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和源码一致且可用。

抱歉!评论已关闭.