如何获取崩溃转储 [英] How do I obtain a crash dump

查看:516
本文介绍了如何获取崩溃转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从程序中获取崩溃转储。我如何得到它?
程序是用C#编写的。崩溃转储究竟是什么?什么时候创建?哪里救了
我如何读取?

解决方案

既然你在说C#,我假设你正在使用Windows平台。 / p>

崩溃转储或转储是特定时间点的进程的完整内存快照和其他相关系统信息。转储可用于调试程序崩溃,挂起,内存和资源泄漏,可能还有更多的问题,我没有在这里列出。



在崩溃和挂起的情况下,第一件您要从崩溃转储获取的数据将是调用堆栈。这表示崩溃的点或操作被阻止且从未返回的点,因此程序不在任何位置。



资源泄漏进程的多个内存转储可以在一段时间内收集,并检查内存中哪些对象增长最多。这可以帮助缩小代码的哪些部分导致泄漏。要了解有关调试特定问题的更多信息,我强烈建议您此博客



有几种方法来捕获转储文件。


  1. Procdump( http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx

  2. Visual Studio 2010( http://msdn.microsoft.com/en-us/library/ vstudio / fk551230(v = vs.100).aspx

  3. WinDbg - 不坏,但比其他工具更加恐吓

使用procdump,您可以简单地执行以下操作:

  c:\> procdump .exe -ma YourProcessName.exe 

此命令的结果将是YourProcessName的完整内存快照。 dmp写入c:\。 -ma开关指定转储完整的内存映像。如果您正在调试崩溃或挂起,您可能会在没有-ma开关的情况下离开。记住没有完整的内存转储,当你去检查数据结构,你可能不会有有效的数据。没有完整的内存转储,您仍然可以拥有callstack数据,这对于崩溃和挂起通常是足够好的。我通常在硬盘空间的错误是很便宜的,所以收集完整的转储。



Procdump还会自动在时间间隔或特定条件下满足转储。请阅读以上链接的文档以获取更多信息。我会推荐的一个开关是 -e

  c:\> procdump.exe -ma -e YourProcessName.exe 

而不是立即写入转储,只会在程序崩溃时写入。



使用Visual Studio 2010,您可以使用调试器附加到进程并保存转储文件。 (请记住,当您F5调试您的程序Visual Studio自动附加)。当您的程序处于中断状态(断点,未处理的异常,崩溃)时,调试菜单将具有选项保存转储为.. 。。那么你可以把这个转储保存在你想要的地方。



由于你提到C#,你很有可能收集托管转储文件。最简单的方法是使用Visual Studio 2010.只需打开您创建的转储文件,就像其他文件一样,开始调试。



但是,如果不是一个选项,您可以随时使用VS2008或WinDbg与SOS扩展。我强烈推荐Visual Studio 2010,虽然SOS扩展和WinDbg一般有一个相当陡峭的学习曲线。要了解有关SOS的更多信息,请查看这些MSDN文章此处 here



我建议使用Visual Studio或procdump的另一个原因是它们将收集您期望的转储文件。我建议您清除任务管理器的创建转储文件工具。原因是它将收集64位的32位进程,这是非常难以调试的。


I need to get a crash dump from a program. How do i get it? The Program is written in C#. What exactly is a crash dump? When is it created? Where is it saved? How do i read it?

解决方案

Since you are saying C# I assume you are using the Windows platform.

A crashdump, or just dump, is the complete memory snapshot and other related system info of a process at a particular point in time. Dumps can be used to debug program crashes, hangs, memory and resource leaks and probably more problems I have not listed here.

In the case of crashes and hangs the first piece of data you want to obtain from a crash dump will be the callstack. This indicates the point of a crash or the point at which an operation blocked and never returned so the program sits and does nothing.

For resource leaks multiple memory dumps of a process can be collected over a period of time and examined to see which objects in memory are growing the most. This can help narrow down which parts of the code are causing the leak. To learn more about debugging specific issues I highly recommend this blog.

There are a few ways to capture a dump file.

  1. Procdump (http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx)
  2. Visual Studio 2010 (http://msdn.microsoft.com/en-us/library/vstudio/fk551230(v=vs.100).aspx)
  3. WinDbg - Not to bad but more intimidating than other tools

With procdump you can simply do:

c:\>procdump.exe -ma YourProcessName.exe

The result of this command will be a full memory snapshot of YourProcessName.dmp written to c:\ . The -ma switch specifies dumping a complete memory image. If you are debugging a crash or hang you can likely get away without the -ma switch. Keep in mind without the full memory dump when you go to examine data structures you probably won't have valid data. Without the full memory dump you will still have callstack data which is often good enough for crashes and hangs. I typically error on the side of harddrive space is cheap so collect the full dump.

Procdump will also automatically take dumps at time intervals or when a specific condition is met. Read the documentation at the link above for more info. One switch I would recommend is -e.

c:\>procdump.exe -ma -e YourProcessName.exe

Instead of writing the dump immediately it will only write it when your program crashes.

With Visual Studio 2010 you can attach to the process with the debugger and save a dump file. (Keep in mind when you F5 debug your program Visual Studio automatically attaches). When your program is in a "break state" (breakpoint, unhandled exception, crash) the Debug menu will have the option to Save Dump As.... Then you can save that dump any where you would like.

Since you mentioned C# you are very likely collecting managed dump files. The easiest way is to use Visual Studio 2010. Simply, open up the dump file you created as you would any other file and begin debugging.

However, if that is not an option you can always use VS2008 or WinDbg with the SOS extensions. I do highly recommend Visual Studio 2010 though as SOS extensions and WinDbg in general have a pretty steep learning curve. To learn more about SOS check out these MSDN articles here and here.

Another reason I recommend using Visual Studio or procdump is that they will collect the dump file you expect. I recommend steering clear of Task Manager's "Create Dump File Tool". The reason being it will collect 64bit dumps of 32bit processes which are overly difficult to debug.

这篇关于如何获取崩溃转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆