简体   繁体   English

在Visual Studio中调试转储文件

[英]Debugging dump files in Visual Studio

I am using Visual Studio 2010 Professional Edition, and Windows Vista. 我使用的是Visual Studio 2010专业版和Windows Vista。

Firstly, I have this code. 首先,我有这个代码。 As you can see, it will crash the program! 如你所见,它会使程序崩溃!

using System;

namespace Crash
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = null;

            if (a.Length == 12)
            {
                // ^^ Crash
            }
        }
    }
}

The program will crash on the if statement. 该程序将在if语句中崩溃。 Now, I want to find out that it crashed on that if statement. 现在,我想知道它在if语句中崩溃了。

If I "Start without Debugging" from Visual Studio, Crash.exe crashes. 如果我从Visual Studio“开始没有调试”,Crash.exe崩溃。 It uses 1,356kb of memory. 它使用1,356kb的内存。 I get the Vista option of Close Program/Debug. 我得到了Close Program / Debug的Vista选项。 If I choose Debug, I can open a new instance of Visual Studio, and it points me to a NullReferenceException on the if statement. 如果我选择Debug,我可以打开一个新的Visual Studio实例,它指向if语句的NullReferenceException。 This is good. 这很好。

Now let me assume that it crashes on another computer, and I get them to give me a Dump File via Task Manager. 现在让我假设它在另一台计算机上崩溃了,我让他们通过任务管理器给我一个转储文件。 It is 54,567kb. 它是54,567kb。 Why so big! 为什么这么大! It's vast! 这是巨大的! Anyway, I am less interested in that (slightly) 无论如何,我对此不太感兴趣(略)

If I open that dump with Windbg, I get very little of use to my untrained eye: 如果我用Windbg打开那个转储,我对未经训练的眼睛几乎没有用处:

Microsoft (R) Windows Debugger Version 6.12.0002.633 X86
Copyright (c) Microsoft Corporation. All rights reserved.


Loading Dump File [C:\Users\Richard\Desktop\Crash.DMP]
User Mini Dump File with Full Memory: Only application data is available

Symbol search path is: SRV*C:\SYMBOLS*http://msdl.microsoft.com/download/symbols
Executable search path is: 
Windows Server 2008/Windows Vista Version 6002 (Service Pack 2) MP (4 procs) Free x86 compatible
Product: WinNt, suite: SingleUserTS Personal
Machine Name:
Debug session time: Sat Jan 15 11:07:36.000 2011 (UTC + 0:00)
System Uptime: 0 days 4:24:57.783
Process Uptime: 0 days 0:00:05.000
........................
eax=002afd40 ebx=77afa6b4 ecx=002afd48 edx=00000001 esi=001cdaa4 edi=00000000
eip=77bf5e74 esp=001cda5c ebp=001cdacc iopl=0         nv up ei ng nz ac pe cy
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000297
ntdll!KiFastSystemCallRet:
77bf5e74 c3              ret

However, this is of less interest to me. 但是,这对我不太感兴趣。 As far as I can tell, I need to write commands in to get useful output, and Visual Studio is better. 据我所知,我需要编写命令以获得有用的输出,Visual Studio更好。

So I open it with Visual Studio. 所以我用Visual Studio打开它。 I can choose to "Debug with Native Only", but I get lots of things that mean something to clever people like you, and I am not clever! 我可以选择“仅使用Native进行调试”,但是我得到的很多东西对于像你这样聪明的人来说意味着什么,而且我并不聪明! I get these two screens: 我得到这两个屏幕:

在此输入图像描述

在此输入图像描述

So, my question: 所以,我的问题:

How do I show Visual Studio to my source code? 如何向我的源代码显示Visual Studio?

Also, is there a way to get a smaller dump file? 另外,有没有办法获得较小的转储文件? It seems ridiculously big, even after compressing. 即使在压缩之后,它看起来也非常大。 I don't understand why there couldn't be one which is only just a tiny bit bigger than the program's footprint, and still get a nice debugging, with the source code. 我不明白为什么没有一个只比程序的足迹大一点,并且仍然得到一个很好的调试,源代码。

The much advertised feature that Visual Studio 2010 allows you to debug crash dump files and step through the managed source code comes with a gotcha: it works only for .NET 4.0 assemblies . Visual Studio 2010允许您调试故障转储文件并逐步执行托管源代码的广告功能附带了一个问题:它仅适用于.NET 4.0程序集 Here are the steps: 以下是步骤:

  1. Create a crash dump file on another computer using the Task Manager 使用任务管理器在另一台计算机上创建故障转储文件
  2. Open the solution in VS2010 在VS2010中打开解决方案
  3. Open the .DMP file (File->Open...) 打开.DMP文件(文件 - >打开...)
  4. Click on Debug With Mixed (This will be visible only for .NET 4.0) 单击Debug With Mixed (这将仅适用于.NET 4.0)
  5. Source code will open and you will be able to inspect the exact cause and location of the exception 源代码将打开,您将能够检查异常的确切原因和位置

As far as debugging with native only is concerned Visual Studio is no more useful than WinDbg. 就仅使用native进行调试而言,Visual Studio并不比WinDbg更有用。

The tooling you are using here wasn't ever designed to troubleshoot crashing managed programs. 您在此处使用的工具并非旨在解决崩溃的托管程序问题。 Minidumps and Windbg is what you use to find out what's wrong with code written in C or C++. 使用Minidumps和Windbg来查找用C或C ++编写的代码有什么问题。 Pretty important tools, these are languages whose runtimes have no support for the kind of goodies you can get out of a crashing managed program. 非常重要的工具,这些语言的运行时不支持您可以从崩溃的托管程序中获得的那种好东西。 Like an exception with a stack trace. 就像堆栈跟踪的异常一样。

The reason the minidump sizes are so different is because of the mini in minidump. minidump尺寸如此不同的原因是因为迷你小型车。 By design, it was meant to capture a small snapshot of the process. 按照设计,它旨在捕获过程的一个小快照。 The relevant argument is DumpType in the MiniDumpWriteDump function . 相关参数是MiniDumpWriteDump函数中的 DumpType。 There's really clever code in this function that can figure out what parts of the process state don't need to be recorded because you are not likely to use it in the debugger session. 在这个函数中有一些非常聪明的代码可以找出不需要记录过程状态的哪些部分,因为你不太可能在调试器会话中使用它。 Which you can override by providing additional dump type flags. 您可以通过提供其他转储类型标志来覆盖。 The minidump that Explorer generates has all of those flags turned on, you get the whole kit and caboodle. Explorer生成的minidump打开了所有这些标志,你得到了整个套件和cabo​​odle。

Which is actually pretty important for a managed program. 这对托管程序来说实际上非常重要。 The heuristics used by this minidump creator is one that's only appropriate for unmanaged code. 这个minidump创建者使用的启发式算法只适用于非托管代码。 Debugging a managed program dump only works well when you include the entire garbage collected heap in the dump. 只有在转储中包含整个垃圾回收堆时,才能调试托管程序转储。 Yes, that will be a large dump, mini doesn't apply anymore. 是的,这将是一个大型转储,迷你不再适用。

Your next problem is that you are getting the soul of the machine view from the minidump data. 您的下一个问题是您从minidump数据中获得了机器视图的灵魂。 Your screen shots are showing the machine code. 您的屏幕截图显示机器代码。 You happen to be located inside of Windows in those shots, note how ntdll.dll is on top of the stack. 你碰巧在这些镜头中位于Windows内部,注意ntdll.dll是如何在堆栈顶部的。 The mscorwks.dll entries are the CLR. mscorwks.dll条目是CLR。 Further down, out of view, you ought to see stack frames from your own code. 再往下看,你应该从你自己的代码中看到堆栈帧。 You'll however see the machine code that was generated by the JIT compiler. 但是,您将看到由JIT编译器生成的机器代码。 Not your C# code. 不是你的C#代码。

There's a Windbg add-in called sos.dll that extends the command set of Windbg to be able to inspect managed data. 有一个名为sos.dll的Windbg加载项,它扩展了Windbg的命令集,以便能够检查托管数据。 Just google "sos.dll" to get good hits. 只需谷歌“sos.dll”获得良好的点击率。 This is however still a looong way away from the kind of debug experience you'll get out of the Visual Studio debugger. 然而,这仍然是一个looong方式远离那种调试经验,你会得到了Visual Studio调试器的。 Which is intimately aware of managed code, very unlike Windbg or the VS debugger that can load minidumps. 这是密切关注托管代码的,非常不像Windbg或可以加载minidump的VS调试器。 Sos was really designed to troubleshoot CLR bugs. Sos真的旨在解决CLR错误。

There were no dramatic improvements in VS2010 other than the minidump info page you now see. 除了你现在看到的minidump信息页面之外,VS2010没有任何显着的改进。 Which really doesn't do much at all. 这真的没什么用。 I suspect the Debugger Team to have this on their todo list, there are surely some fundamental problems to overcome. 我怀疑Debugger团队在他们的待办事项清单上有这个,肯定有一些基本问题需要克服。 Particularly in the minidump format and creation code. 特别是在minidump格式和创建代码中。 Use connect.microsoft.com to provide feedback, they pay attention to it and let votes affect their priority list. 使用connect.microsoft.com提供反馈,他们会关注它并让投票影响他们的优先级列表。

You should be supplying the related pdb (program database) file to the debugger so it can load the symbols. 您应该将相关的pdb(程序数据库)文件提供给调试器,以便它可以加载符号。 Also to get a better view, use Microsoft Public Symbol server. 另外,要获得更好的视图,请使用Microsoft Public Symbol服务器。 This article contains information on it. 本文包含有关它的信息。

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

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