简体   繁体   English

如何获取即将终止的进程的调用堆栈,即找出进程如何退出

[英]How to get call stack of a dying process, i.e. to find out how the process is exiting

I'm in a unique predicament where my process is exiting without throwing any exception or such, just silently exiting. 我处在一个独特的困境中,我的过程正在退出而没有引发任何异常等,而只是默默地退出了。

I want to find out what the call stack is when the process is exiting, like, who is calling exit(0) on my process. 我想找出进程退出时调用堆栈是什么,例如谁在我的进程上调用exit(0)。

This is a native C++ application, that is millions of line, I couldn't possibly figure out where things were going wrong. 这是一个本机C ++应用程序,有数百万行,我无法弄清楚哪里出了问题。

Is there such a faciliity, for example if I run under Windbg? 是否有这样的便利性,例如,如果我在Windbg下运行?

You can configure Process Dumper to dump a full image of the process on exit, for postmortem debugging. 您可以配置Process Dumper以在退出时转储该进程的完整映像,以进行事后调试。 From the Overview: 从概述:

Dump automatically when process being monitored exited 退出监视进程时自动转储

WinDbg is by default configured to break when a process exits, so all you have to do is attach to your process and wait. WinDbg默认情况下配置为在进程退出时中断,因此您要做的就是附加到进程上并等待。 And of course type 'k' to have your callstack once your process has broken. 当然,一旦您的进程中断,请键入“ k”以拥有您的调用堆栈。

The Microsoft Debugging Toolkit from Microsoft comes with such a utility, called ADPlus. Microsoft提供的Microsoft Debugging Toolkit带有一个称为ADPlus的实用程序。

ADPlus is a command line tool (It used to be a glorified vb script apparently) that does a bunch of things. ADPlus是一个命令行工具(显然它曾经是美化的vb脚本),可以执行很多操作。 But You and I care about is getting the callstack of a process that died. 但是您和我关心的是获取死掉的进程的调用堆栈。 AdPlus can be configured to capture the callstack of an external process when it encounters an unhandled exception. 可以将AdPlus配置为在遇到未处理的异常时捕获外部进程的调用堆栈。

The syntax is like this: 语法如下:

ADPlus -p <process id> -crash -o <output path>

where 哪里

-p is the argument where you pass in the process ID. -p是您在其中传递进程ID的参数。 You can get this from process explorer to TList (I think). 您可以将其从流程浏览器获取到TList(我认为)。 There are other arguments that allow you specify the process name, but you will have to look up that yourself. 还有其他参数可以让您指定进程名称,但是您必须自己查找。

-crash is to tell it to generate a minidump when it crashes, or encounters an unhandled exception. -crash告诉它在崩溃或遇到未处理的异常时生成一个小型转储。

-o is the path to a directory where you want the minidump to be saved. -o是要在其中保存小型转储的目录的路径。 What ADPlus will do is then create a subdirectory there that incorporates the name of the process and a timestamp. 然后,ADPlus要做的是在其中创建一个子目录,其中合并了进程的名称和时间戳。

Then you can run your application, and when it crashes, ADPlus will create the minidump, and then your process will exit. 然后,您可以运行您的应用程序,当它崩溃时,ADPlus将创建小型转储,然后您的进程将退出。

The microsoft Debugging toolkit is now a part of the Windows SDK install. Microsoft调试工具包现在是Windows SDK安装的一部分。 You go here to find it: 您可以在这里找到它:

http://www.microsoft.com/whdc/devtools/debugging/default.mspx http://www.microsoft.com/whdc/devtools/debugging/default.mspx

Click on the download link to download a small app that will install the whole thing from the web. 单击下载链接以下载一个小型应用程序,该应用程序将从网络上安装整个程序。 The installer will give you lots of options for different components to install. 安装程序将为您提供许多用于安装不同组件的选项。 You can ignore most of them and install just the debugging toolkit. 您可以忽略其中的大多数,而仅安装调试工具包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM