<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. 如何编写会崩溃并生成转储文件的示例代码?

      How to write a sample code that will crash and produce dump file?(如何编写会崩溃并生成转储文件的示例代码?)
    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;
                }
                

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

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(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>

                          <tbody id='Y93ND'></tbody>
                      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>