调试一个.NET EXE文件,立即崩溃 [英] Debug a .NET EXE file that crashes immediately

查看:110
本文介绍了调试一个.NET EXE文件,立即崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个受管理的EXE文件,运行时立即崩溃。通常我会期待一个对话框允许启动调试器的选项,但在这种情况下没有这样的运气。另外,程序崩溃太快了,我在Visual Studio中使用附加处理。



有什么解决方案?

解决方案

如果您有 WinDBG 安装,使用文件>打开可执行文件直接在调试器下打开应用程序,并自动断开。



然后可以使用Debug下的命令(即Go )正常执行并进行调试。同时加载 SOS扩展程序。不如Visual Studio那么好,但是如果你只有EXE(而且希望PDB虽然是可选的)而且没有源,但是很有用。



示例:这是我的源代码,我们假设不可用:

  static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
int x = 10 - 10;
int i = 2000 / x;

Application.Run(new Form1());
}

这个崩溃了,没有机会及时附加调试器。这是WinDBG输出后点击运行:



删除死亡ImageShack链接 - 我手写的圈子



加载SOS.dll后,您可以使用!DumpStack查看异常被抛出的位置:



删除死亡ImageShack链接 - 否请注意,JIT或编译器优化可能导致方法内联,这可能使StackTrace不能100%可靠,但是要快速概述它的工作原理。



WinDBG有点神秘,但一旦你得到了一些基础知识,它是非常棒的,至少有助于找到问题的根源。 b $ b

I'm working with a managed EXE file that crashes immediately when run. Usually I'd expect a dialog which allows an option to launch the debugger, but no such luck in this case. Also, the program crashes too quickly for me to use attach to process in Visual Studio.

What is the solution?

解决方案

If you have WinDBG installed, use File > Open Executable to open the application directly under the debugger and automatically break immediately.

You can then use the commands under Debug (i.e., Go) to execute it normally and debug it. Also load the SOS Extensions. Not as nice as Visual Studio, but useful if you only have the EXE (and hopefully the PDB, although that's optional) and no source.

Example: This is my source code, which we assume is unavailable:

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        int x = 10 - 10;
        int i = 2000/x;

        Application.Run(new Form1());
    }

This crashes immedately, with no chance for you to attach a debugger in time. This is the WinDBG output after hitting "Run":

removed dead ImageShack link - Freehand circles by me

After loading SOS.dll, you can use !DumpStack to see where the Exception was thrown:

removed dead ImageShack link - No Freehand Circles, sorry!

Note that JIT or compiler optimizations may cause methods to be inlined which may make the StackTrace not 100% reliable, but for a quick overview it works.

WinDBG is a bit arcane, but once you got some basics done it's awesome and at least helps finding the root of the issue.

这篇关于调试一个.NET EXE文件,立即崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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