dump 文件生成和使用

1.VS 生成pdb

 

2.WinDbg

打开WinDbg,依次进行下面操作:
File -> Symbol File Path -> 选择pdb文件存放路径。
File -> Image File Path -> 选择exe文件存放路径。
File -> Open Crash Dump -> 选择DMP文件存放路径。
最后会弹出WinDbg对崩溃文件的初步分析的结果,在下面的输入框中输入“!analyze -v”,
————————————————
版权声明:本文为CSDN博主「Ruo_Xiao」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/itworld123/article/details/79041500

 3.添加的源码

 1 #include <QtWidgets/QApplication>
 2 #include "Windows.h"
 3 #include "DbgHelp.h"
 4 #include <tchar.h>
 5 
 6 int GenerateMiniDump(PEXCEPTION_POINTERS pExceptionPointers)
 7 {
 8     // 定义函数指针
 9     typedef BOOL(WINAPI* MiniDumpWriteDumpT)(
10         HANDLE,
11         DWORD,
12         HANDLE,
13         MINIDUMP_TYPE,
14         PMINIDUMP_EXCEPTION_INFORMATION,
15         PMINIDUMP_USER_STREAM_INFORMATION,
16         PMINIDUMP_CALLBACK_INFORMATION
17         );
18     // 从 "DbgHelp.dll" 库中获取 "MiniDumpWriteDump" 函数
19     MiniDumpWriteDumpT pfnMiniDumpWriteDump = NULL;
20     HMODULE hDbgHelp = LoadLibrary(_T("DbgHelp.dll"));
21     if (NULL == hDbgHelp)
22     {
23         return EXCEPTION_CONTINUE_EXECUTION;
24     }
25     pfnMiniDumpWriteDump = (MiniDumpWriteDumpT)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
26 
27     if (NULL == pfnMiniDumpWriteDump)
28     {
29         FreeLibrary(hDbgHelp);
30         return EXCEPTION_CONTINUE_EXECUTION;
31     }
32     // 创建 dmp 文件件
33     TCHAR szFileName[MAX_PATH] = { 0 };
34     const TCHAR* szVersion = _T("DumpDemo_v1.0");
35     SYSTEMTIME stLocalTime;
36     GetLocalTime(&stLocalTime);
37     wsprintf(szFileName, L"%s-%04d%02d%02d-%02d%02d%02d.dmp",
38         szVersion, stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay,
39         stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond);
40     HANDLE hDumpFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE,
41         FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
42     if (INVALID_HANDLE_VALUE == hDumpFile)
43     {
44         FreeLibrary(hDbgHelp);
45         return EXCEPTION_CONTINUE_EXECUTION;
46     }
47     // 写入 dmp 文件
48     MINIDUMP_EXCEPTION_INFORMATION expParam;
49     expParam.ThreadId = GetCurrentThreadId();
50     expParam.ExceptionPointers = pExceptionPointers;
51     expParam.ClientPointers = FALSE;
52     pfnMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
53         hDumpFile, MiniDumpWithDataSegs, (pExceptionPointers ? &expParam : NULL), NULL, NULL);
54     // 释放文件
55     CloseHandle(hDumpFile);
56     FreeLibrary(hDbgHelp);
57     return EXCEPTION_EXECUTE_HANDLER;
58 }
59 
60 LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS lpExceptionInfo)
61 {
62     // 这里做一些异常的过滤或提示
63     if (IsDebuggerPresent())
64     {
65         return EXCEPTION_CONTINUE_SEARCH;
66     }
67     return GenerateMiniDump(lpExceptionInfo);
68 }
View Code
1 int main(int argc, char *argv[])
2 {
3     // 加入崩溃dump文件功能
4     SetUnhandledExceptionFilter(ExceptionFilter);
View Code

4.使用

用VS 打开,pdb文件同一个目录

 

posted @ 2023-04-02 20:56  三岁玩童  阅读(152)  评论(0编辑  收藏  举报