如何在 .NET 中调试 stackoverflowexception [英] How to debug a stackoverflowexception in .NET

查看:27
本文介绍了如何在 .NET 中调试 stackoverflowexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

我刚刚开始并实现了一堆代码,但是当我执行它时,我抛出了一个 StackOverflowException?StackOverflowException 没有堆栈跟踪,所以我被卡住了.我知道为什么会发生堆栈溢出,但要修复它,我需要知道它的根在哪里.

I've just been on a roll and implemented a bunch of code, but when I execute it I get thrown a StackOverflowException? The StackOverflowException doesn't have a stacktrace so I'm stuck. I know why a stack overflow might occur, but to fix it I need to know where it's root is.

我得到的只是:在 tag-you're-it.dll 中发生了类型为System.StackOverflowException"的未处理异常

All I'm getting is: An unhandled exception of type 'System.StackOverflowException' occurred in tag-you're-it.dll

选项:

  1. 浏览所有更改并尝试找出问题所在.(可能会很慢)
  2. 使用调试器并逐步执行,直到找到问题为止.(可能比 1 好.)
  3. 使用配置文件并查找调用次数最多的方法.
  4. ?

附注:

这是一种假设情况(虽然并不少见),因此没有可用的代码.

This is a hypothetical situation (although not too uncommon) and therefore no code is available.

推荐答案

WinDbg 可以完成工作,甚至包括获得合理的 (clr) 堆栈跟踪.您需要获取WinDbg除非您已经使用 Visual Studio 或 Windows SDK 安装了它.注意:带有新 GUI 的WinDbg 预览"对我来说效果很好.

WinDbg can get the job done, including even getting a sensible (clr) stack trace. You'll need to get WinDbg unless you've already installed it with Visual Studio or Windows SDK. Note: "WinDbg Preview" with the new GUI has worked fine for me.

我建议从 WinDbg 开始你的进程,当然你也可以将它附加到一个正在运行的进程,如果这更适合你.

I suggest to start your process from WinDbg, but of course you can also attach it to a running process if this suits you better.

注意:在启动进程后,CLR 没有加载,.loadby SOS.dll clr 将失败(unable to find module 'clr').你必须等待要加载的 CLR.​​一旦发生就停止执行,请执行:

Note: Right after starting the process, the CLR is not loaded, and .loadby SOS.dll clr will fail ("unable to find module 'clr'). You have to wait for the CLR to be loaded. To stop execution once that happens perform:

  • sxe ld clr

加载 CLR 后,您必须执行以下步骤以中断 StackOverflowException(在命令窗口/行中输入):

Once the CLR is loaded you'll have to perform the following steps to break on StackOverflowException (enter in the command window / line):

  • .loadby SOS.dll clr(不是 .loadby sos clr——这会导致扩展被加载两次)
  • !stoponeexception -create System.StackOverflowException
  • g(继续调试)
  • .loadby SOS.dll clr (not .loadby sos clr—this can lead to the extension being loaded twice)
  • !stoponexception -create System.StackOverflowException
  • g (continues debugging)

触发 StackOverflowException/等待它发生

  • !clrstack(将打印堆栈跟踪)
  • !clrstack (will print the stacktrace)

值得注意的来源:

这篇关于如何在 .NET 中调试 stackoverflowexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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