<small id='S8M1n'></small><noframes id='S8M1n'>

<tfoot id='S8M1n'></tfoot>
  1. <legend id='S8M1n'><style id='S8M1n'><dir id='S8M1n'><q id='S8M1n'></q></dir></style></legend>

      • <bdo id='S8M1n'></bdo><ul id='S8M1n'></ul>

    1. <i id='S8M1n'><tr id='S8M1n'><dt id='S8M1n'><q id='S8M1n'><span id='S8M1n'><b id='S8M1n'><form id='S8M1n'><ins id='S8M1n'></ins><ul id='S8M1n'></ul><sub id='S8M1n'></sub></form><legend id='S8M1n'></legend><bdo id='S8M1n'><pre id='S8M1n'><center id='S8M1n'></center></pre></bdo></b><th id='S8M1n'></th></span></q></dt></tr></i><div id='S8M1n'><tfoot id='S8M1n'></tfoot><dl id='S8M1n'><fieldset id='S8M1n'></fieldset></dl></div>

    2. 如何编写会崩溃并生成转储文件的示例代码?

      时间:2023-07-01
    3. <tfoot id='FwhsF'></tfoot>
      <legend id='FwhsF'><style id='FwhsF'><dir id='FwhsF'><q id='FwhsF'></q></dir></style></legend>
      • <bdo id='FwhsF'></bdo><ul id='FwhsF'></ul>

              <small id='FwhsF'></small><noframes id='FwhsF'>

              <i id='FwhsF'><tr id='FwhsF'><dt id='FwhsF'><q id='FwhsF'><span id='FwhsF'><b id='FwhsF'><form id='FwhsF'><ins id='FwhsF'></ins><ul id='FwhsF'></ul><sub id='FwhsF'></sub></form><legend id='FwhsF'></legend><bdo id='FwhsF'><pre id='FwhsF'><center id='FwhsF'></center></pre></bdo></b><th id='FwhsF'></th></span></q></dt></tr></i><div id='FwhsF'><tfoot id='FwhsF'></tfoot><dl id='FwhsF'><fieldset id='FwhsF'></fieldset></dl></div>

                  <tbody id='FwhsF'></tbody>
                本文介绍了如何编写会崩溃并生成转储文件的示例代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我开始学习windbg,发现这篇好文章如何使用WinDbg分析崩溃转储 VC++ 应用程序?

                I started learned windbg and I found this good post How to use WinDbg to analyze the crash dump for VC++ application?

                现在我要按照说明一步一步来.问题来了:我需要编写一些可以立即崩溃的示例代码,并创建一些可以被windbg使用的转储文件.

                Now I want to follow the instructions and do it step by step. Here is the problem: I need to write some sample code that can immediately crash, and create some dump files that can be used by windbg.

                这样的代码怎么写?

                void Example4()
                {
                    int* i = NULL;
                    *i = 80;
                }
                

                上面的代码会立即崩溃;但是,我不知道在哪里可以找到转储文件?

                The above code will crash immediately; however, I don't know where to find the dump file?

                谢谢

                推荐答案

                #include <Windows.h>
                #include <Dbghelp.h>
                
                void make_minidump(EXCEPTION_POINTERS* e)
                {
                    auto hDbgHelp = LoadLibraryA("dbghelp");
                    if(hDbgHelp == nullptr)
                        return;
                    auto pMiniDumpWriteDump = (decltype(&MiniDumpWriteDump))GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
                    if(pMiniDumpWriteDump == nullptr)
                        return;
                
                    char name[MAX_PATH];
                    {
                        auto nameEnd = name + GetModuleFileNameA(GetModuleHandleA(0), name, MAX_PATH);
                        SYSTEMTIME t;
                        GetSystemTime(&t);
                        wsprintfA(nameEnd - strlen(".exe"),
                            "_%4d%02d%02d_%02d%02d%02d.dmp",
                            t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
                    }
                
                    auto hFile = CreateFileA(name, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
                    if(hFile == INVALID_HANDLE_VALUE)
                        return;
                
                    MINIDUMP_EXCEPTION_INFORMATION exceptionInfo;
                    exceptionInfo.ThreadId = GetCurrentThreadId();
                    exceptionInfo.ExceptionPointers = e;
                    exceptionInfo.ClientPointers = FALSE;
                
                    auto dumped = pMiniDumpWriteDump(
                        GetCurrentProcess(),
                        GetCurrentProcessId(),
                        hFile,
                        MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory),
                        e ? &exceptionInfo : nullptr,
                        nullptr,
                        nullptr);
                
                    CloseHandle(hFile);
                
                    return;
                }
                
                LONG CALLBACK unhandled_handler(EXCEPTION_POINTERS* e)
                {
                    make_minidump(e);
                    return EXCEPTION_CONTINUE_SEARCH;
                }
                
                int main()
                {
                    SetUnhandledExceptionFilter(unhandled_handler);
                
                    return *(int*)0;
                }
                

                这篇关于如何编写会崩溃并生成转储文件的示例代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:std::numeric_limits::max 的语法错误 下一篇:为什么 Visual C++ 缺乏重构功能?

                相关文章

                <small id='Y93ND'></small><noframes id='Y93ND'>

                  <i id='Y93ND'><tr id='Y93ND'><dt id='Y93ND'><q id='Y93ND'><span id='Y93ND'><b id='Y93ND'><form id='Y93ND'><ins id='Y93ND'></ins><ul id='Y93ND'></ul><sub id='Y93ND'></sub></form><legend id='Y93ND'></legend><bdo id='Y93ND'><pre id='Y93ND'><center id='Y93ND'></center></pre></bdo></b><th id='Y93ND'></th></span></q></dt></tr></i><div id='Y93ND'><tfoot id='Y93ND'></tfoot><dl id='Y93ND'><fieldset id='Y93ND'></fieldset></dl></div>

                  1. <tfoot id='Y93ND'></tfoot>
                    • <bdo id='Y93ND'></bdo><ul id='Y93ND'></ul>
                    <legend id='Y93ND'><style id='Y93ND'><dir id='Y93ND'><q id='Y93ND'></q></dir></style></legend>