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

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

问题描述

我需要从程序中获取故障转储.我怎么得到它?该程序是用 C# 编写的.什么是崩溃转储?它是什么时候创建的?它保存在哪里?我怎么读?

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?

推荐答案

既然你说的是 C#,我假设你使用的是 Windows 平台.

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 - 不错,但比其他工具更吓人

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

With procdump you can simply do:

c:>procdump.exe -ma YourProcessName.exe

此命令的结果将是写入 c: 的 YourProcessName.dmp 的完整内存快照.-ma 开关指定转储完整的内存映像.如果您正在调试崩溃或挂起,您可能无需使用 -ma 开关就可以逃脱.请记住,当您检查数据结构时,如果没有完整的内存转储,您可能不会拥有有效数据.如果没有完整的内存转储,您仍然会有调用堆栈数据,这些数据通常足以应对崩溃和挂起.我通常在硬盘空间方面的错误很便宜所以收集完整的转储.

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 还会在时间间隔或满足特定条件时自动进行转储.阅读上面链接中的文档以获取更多信息.我推荐的一种开关是 -e.

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.

使用 Visual Studio 2010,您可以使用调试器附加到进程并保存转储文件.(请记住,当您按 F5 调试 Visual Studio 自动附加的程序时).当您的程序处于中断状态"(断点、未处理的异常、崩溃)时,Debug 菜单将提供 Save Dump As... 选项.然后您可以将该转储保存在任何您想要的位置.

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.

既然您提到了 C#,您很可能会收集托管转储文件.最简单的方法是使用 Visual Studio 2010.只需像打开任何其他文件一样打开您创建的转储文件并开始调试.

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.

但是,如果这不是一个选项,您可以始终使用带有 SOS 扩展的 VS2008 或 WinDbg.我强烈推荐 Visual Studio 2010,因为 SOS 扩展和 WinDbg 通常有一个非常陡峭的学习曲线.要了解有关 SOS 的更多信息,请查看这些 MSDN 文章此处此处.

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.

我推荐使用 Visual Studio 或 procdump 的另一个原因是它们会收集您期望的转储文件.我建议避开任务管理器的创建转储文件工具".原因是它将收集 32 位进程的 64 位转储,这些转储过于难以调试.

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天全站免登陆