如何从.NET应用程序与procdump(或类似)捕获未处理的异常?应用程序、异常、类似、未处理

2023-09-04 22:41:05 作者:持枪走四方

目前我有一个导致异常的只有一台PC的应用程序。经过一番周围挖我可以封装用小示例应用程序的问题,但真正的原因还是躲了起来。

Currently i have an application that leads to an exception on only one pc. After some digging around i could encapsulate the problem with a small sample application, but the true reason is still hiding.

由于,在这个电脑未安装Visual Studio的我们也不能够这样做,所以我搜索到了另一种解决方案,找到真正的原因这一事实。

Due to the fact that on this pc is no Visual Studio installed nor we are able to do so i searched for another solution to find the true reason.

在第一种方法我剥夺了我的小应用越来越多,只需仔细阅读异常消息,比较到code和尝试和放大器;错误前来问题的具体线路。但是,这无助于让所有关于什么是所有使用的变量等的当前值的信息。

In a first approach i stripped down my small application more and more by just carefully reading the exception message, compare to the code and try & error to come to the concrete line of problem. But that wouldn't help to get all the informations about what are the current values of all the used variables etc.

所以,我搜索其它的好的方式来获得我需要的信息。我已经读到的转储和小型转储的约很长一段时间,但从来没有需要他们,原因到现在我总是可以重现用户描述的场景在我的开发或测试机器。

So i searched for another better way to get the informations i need. I already read about Dumps and Minidumps about a long time but never need them, cause till now i could always reproduce the user described scenario on my developer or test machine.

但这一次似乎只有一个电脑问题,遗憾的是不断变化的整机或安装新事物有不是一个选项。

But this time there seems to be only one pc having the problem and unfortunately changing the complete machine or installing everything new there isn't an option.

要熟悉有关如何​​使用转储工作,我只是写了一个简单的C#测试程序,包含一个按钮,什么也不做超过抛出新的ArgumentException(测试);

To get familiar on how to work with dumps i just wrote a simple c# test application, containing a single button which does nothing more than throw new ArgumentException("Test");

现在我需要按下恶意按钮后创造如此神奇的转储文件,读到Visual Studio 2008专业版,可以看它像在VS正常运行的应用程序不同的是步骤下一的,等将无法正常工作。

Now i need to create such a magical dump file after pushing the malicious button, read it into Visual Studio 2008 Professional and can look at it like a normal running application within VS except that Step next, etc. won't work.

据我所知最好的工具在特定时间点来创建转储的 procdump 时,由于有可能可以定义当一个或多个转储采取

As far as i know the best tool to create a dump at a specific point in time is procdump, due to the possibility you can define when one or multiple dumps are taken.

所以,我只是下载了它,并通过调用启动它procdump -o -e MyApp.exe将D:\ MyApp.dmp 。它声称的 MyApp.exe的的不存在。好了,我的错。只需先升后procdump启动MyApp的。

So i simply downloaded it and started it by calling procdump -o -e MyApp.exe d:\MyApp.dmp. It claims that MyApp.exe doesn't exists. Okay, my fault. Just start MyApp first and afterwards procdump.

Procdump现在正在运行显示我所有的选项,它使用,似乎等待未处理的异常。没有什么比这更容易,我只是把我的恶意的按钮...并没有任何反应的procdump。

Procdump is running now showing me all its options it uses and seems to await an unhandled exception. Nothing easier than this, i simply push my malicious button ... and nothing happens in procdump.

而不是从我的应用程序中的对话窗口会弹出解释说,未处理的异常发生(惊奇,惊奇),什么我想要做的(详细信息,请继续,退出)。但无论怎样我选择,procdump无法自动创建转储文件。

Instead a dialog window from my application pops up that explains that an unhandled exception occured (surprise, surprise) and what i'd like to do (Details, Continue, Quit). But no matter what i select, procdump isn't able to create a dump file automatically.

如果我去,就叫 procdump -o MyApp.exe将D:\ MyApp.dmp 的对话框显示转储文件的时候几乎没什么用,开盘后事业它VS调用堆栈只是挂在某处 ntdll.dll中但无处在我的code(我猜想,这是对话等待的MessageQueue一些鼠标点击)。

If i go and just call procdump -o MyApp.exe d:\MyApp.dmp when the dialog is showing the dump file seems to be useless, cause after opening it in VS the call stack is just hanging around somewhere in ntdll.dll but nowhere within my code (i would guess that this is the MessageQueue of the dialog waiting for some mouse clicks).

如果我细看到细节,你会发现有关如何委派未处理的异常到JIT调试器的一些信息。但我不希望JIT调试器,我想崩溃的应用程序来获得转储文件。

If i take a closer look into the details you'll find some informations about how to delegate the unhandled exception to a JIT-debugger. But i don't want a JIT-debugger, i'd like to crash the application to get the dump file.

这些尝试后,我发现 ClrDump ,但是这并没有产生任何更好的转储(如果我把它加载到VS和看看调用堆栈)。

After these tries i found ClrDump, but that didn't produce any better dumps (if i load it into VS and take a look at the call stack).

使用这些信息考虑到你现在(希望)能够为我提供了我的.Net应用程序(工作)解决方案:

With these informations taken into account you are now (hopefully) able to provide me with a (working) solution for my .Net application:

我是如何能够当未处理的异常的.NET应用程序中发生创建转储文件,我是能够加载的MyApp .pdb文件,看看在何种情况下的异常被抛出?

How i'm able to create a dump file when an unhandled exception occurs within an .net application, that i'm able to load MyApp .pdb files and see under which circumstances the exception was thrown?

通过纳文和Lex李的帮助,我能得到关于如何使用调试崩溃转储的作品多了几分见解。现在我只是想回顾一下所有的东西,是需要得到它的工作:

With the help of Naveen and Lex Li i could get a little more insight on how debugging with crash dumps works. And now i just like to recap all the stuff, that is needed to get it to work:

每当你想获得一个进程的转储,你可以几​​个工具之间进行选择,以完成这项工作:

Whenever you like to get a dump of a process, you can select between several tools to get the job done:

Procdump 在轻松的命令行工具,可以创建复杂的场景场,但它的不可以工作,以赶上.NET未处理的异常。 Procdump easy command line tool that can create dumps in complicated scenarios, but it does not work to catch .net unhandled exceptions. 在简单的图形工具,可以创建转储在崩溃(甚至是.NET例外),但它不能创建转储在高级场景,如Procdump。

正如你所看到的,你会得到两个工具能够创建在不同情况下的转储,所以无论是更多的合作伙伴,然后对手在一次创建转储在需要的点。

As you can see you'll get two tools that are capable to create dumps under different circumstances, so both are more partners then rivals in creating a dump at the needed point in time.

创建转储上述工具之一后,它的时间来分析转储以找出问题的原因。为了分析,你可以抓住的WinDbg。这是 Windows调试工具的一部分,可以从微软获得。不幸的是入门壁垒的WinDbg相当高,但它真的很强大。也许看看成这个博客,以获取有关如何使用这个工具更好的理解。

After creating a dump with one of the above tool it's time to analyze the dump to find out the reason for the problem. For analyzing you can grab WinDbg. It is part of the Debugging Tools for Windows and can be get from Microsoft. Unfortunately is the entry-barrier of WinDbg quite high but it is really powerful. Maybe take a look into this blog to get a better understanding on how to use this tool.

如果你有一个.NET 4中的应用程序和使用Visual Studio 2010,您还可以使用它进行分析。它更容易使用,由于更好的图形用户界面,但它不具备的WinDbg的力量。为了获得更好的比较,你应该看看到这篇文章。

If you have a .Net 4 application and using Visual Studio 2010 you can also use this for analyzing. It's much easier to use, due to the better graphical user interface, but it doesn't have the power of WinDbg. To get a better comparison, you should take a look into this article.

最后但并非最不重要,你也可以使用sos.dll在Visual Studio 2008 以下是描述,你可以用它做什么文章。

Last but not least you can also use the sos.dll in Visual Studio 2008. Here is the article describing what you can do with it.

推荐答案

DebugDiag资料是最简单的方式来获得基于异常内存转储之一。

DebugDiag is one of the easiest way to get memory dump based on an exception.

在DebugDiag资料查找配置异常对话框帮助部分基于例外生成转储。

Look for "Configure Exception Dialog" help section within debugdiag to generate a dump based on exception.

下面是一个例子,生成基于ArgumentException的完全内存转储

Below is an example to generate full memory dump based on ArgumentException