最近在调试一个服务器程序时, 发布版会崩溃.
我使用下面代码在程序崩溃时生成dmp
#include <dbghelp.h>
#pragma comment(lib, "Dbghelp.lib")
// dmp输出
inline LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
{
LONG ret = EXCEPTION_EXECUTE_HANDLER;
TCHAR szFileName[64];
SYSTEMTIME st;
::GetLocalTime(&st);
wsprintf(szFileName, TEXT("%04d-%02d-%02d-%02d-%02d-%02d-%02d-%02d.dmp"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, rand()%100);
HANDLE hFile = ::CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if (hFile != INVALID_HANDLE_VALUE)
{
MINIDUMP_EXCEPTION_INFORMATION ExInfo;
ExInfo.ThreadId = ::GetCurrentThreadId();
ExInfo.ExceptionPointers = lpExceptionInfo;
ExInfo.ClientPointers = false;
// write the dump
BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
if (bOK)
{
printf("Create Dump File Success!\n");
}
else
{
printf("MiniDumpWriteDump Failed: %x\n", GetLastError());
}
::CloseHandle(hFile);
}
else
{
printf("Create File %s Failed %d\n", szFileName, GetLastError());
}
return ret;
}
inline void RegisterMiniDump()
{
::SetUnhandledExceptionFilter(UnhandledFilter);
}
在多数情况下可以生成一个dmp文件, 不过最近遇到的情况它返回false GetLastError()好象是个-214xxxxx看起来像是,很长一个.
想问下什么情况下会dmp生成不了? 大家都是怎么来生成dmp的.
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!