4

在我无权访问的客户计算机 (WinXP SP2) 上,我有一个 Win32 EXE(非托管 C++)在启动时崩溃。我想解决此问题的最佳方法是获取(小型)转储并稍后使用 windbg 或类似工具对其进行分析。

现在,我通常会告诉客户安装适用于 Windows 的调试工具并运行

cscript adplus.vbs -crash

但是,您似乎无法将 adplus 用于启动时崩溃的应用程序(http://support.microsoft.com/kb/q286350/表示“在以下情况下请勿使用 ADPlus:如果您必须对程序进行故障排除或在启动期间意外退出的进程”)。同一篇文章说“使用用户模式进程转储”,但我没有成功安装它。

知道如何获取在 Win32 上启动时崩溃的进程的转储吗?

4

4 回答 4

13

或者,您可以设置自己的转储生成框架,当遇到任何未处理的异常时自动创建进程转储。这将避免客户端必须安装 Windbg。

使用 SetUnhandledExceptionFilter Win32 API 在应用程序启动时注册应用程序级异常处理程序。只要有任何未处理的异常,就会调用注册的回调函数。然后,您可以使用 DbgHelp.dll 中的 MiniDumpWriteDump api 创建进程转储。

示例代码:-

LONG WINAPI My_UnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
    HANDLE hFile = CreateFile("FileName",
            GENERIC_WRITE,
            0,
            NULL,
            CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

    MINIDUMP_EXCEPTION_INFORMATION aMiniDumpInfo;
    aMiniDumpInfo.ThreadId = GetCurrentThreadId();
    aMiniDumpInfo.ExceptionPointers = ExceptionInfo;
    aMiniDumpInfo.ClientPointers = TRUE;

    MiniDumpWriteDump(GetCurrentProcess(),
            GetCurrentProcessId(),
            hFile,
            (MINIDUMP_TYPE) (MiniDumpWithFullMemory|MiniDumpWithHandleData),
            &aMiniDumpInfo,
            NULL,
            NULL);

    CloseHandle(hFile);

    return EXCEPTION_EXECUTE_HANDLER;
}


int main(int argc, char* argv[])
{
    SetUnhandledExceptionFilter(&My_UnhandledExceptionFilter);

    // User code throwing exception..

    return 0; 
}

注意:- 调试进程时不会调用注册的异常过滤器。因此,在调试过程中,如果您在异常过滤器函数中放置断点,即使在导致未处理的异常之后它也没有命中,请不要感到惊讶。

于 2009-03-31T05:20:04.347 回答
7

您可以在客户端计算机上安装WinDBG,然后使用“图像文件执行选项”并将 WinDBG 设置为在进程启动后打开。然后运行崩溃进程,WinDBG 将立即打开。按g (Go) 并等待进程崩溃,然后键入“ .dump /mfh dumpFileName.dmp ”。现在您有了可以调试的转储文件。

于 2009-03-30T09:46:07.443 回答
2

这是收集 Vista SP1 崩溃的好方法:

http://msdn.microsoft.com/en-us/library/bb787181(VS.85).aspx

无需在机器上安装任何东西!

于 2009-08-13T20:48:17.490 回答
0

在客户端机器上安装开发人员工具将是我最后的手段,我必须承认我讨厌这个想法,尤其是在有替代方案对你有用的地方。

首先注册WinQual。您现在可以自动访问客户的故障转储和其他错误。我记得这是一项免费服务,没有理由不使用它。

Since WinQual will likely take a while for the crash dump to get to you, and it is always nice to be a little more responsive to customers especially when you application crashes, use Dr. Watson. As I recall when the crash occurs, before clicking on the dialog you can run drwatsn32 from Start->Run or the command line and Dr Watson will pop up. At this point dismissing the crash dialog will generate a crash dump file. Should this fail, install Dr Watson by running it with the -i parameter on the command line.

于 2009-08-14T12:32:57.263 回答