visual-studio 如何在程序崩溃时调试程序并没有异常?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3792456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug a program when it crashes w/out exception?
提问by mpen
One of my programs crashes periodically, but I don't know why. I'm running it in debug mode, but nothing pops up. The program just suddenly exits. I've had other bugs that do throw an exception...but not this one. Is there a magical way of catching it or something?
我的一个程序会定期崩溃,但我不知道为什么。我在调试模式下运行它,但没有弹出任何内容。程序只是突然退出。我还有其他错误会引发异常……但不是这个。有没有什么神奇的方法可以抓住它?
采纳答案by Sean Fausett
Presumably you're running it from within Visual Studio and for some reason it's not stopping in the debugger with an uncaught exception, in which case you could try catching the crash from outside of Visual Studio. See my answer at System.AccessViolationException from unmanaged code?, in particular how to capture a crash dump.
据推测,您是从 Visual Studio 中运行它的,并且出于某种原因,它不会因未捕获的异常而停止在调试器中,在这种情况下,您可以尝试从 Visual Studio 外部捕获崩溃。从非托管代码在System.AccessViolationException 中看到我的回答?,特别是如何捕获故障转储。
If it only crashes periodically, but within a reasonably short period of time, start with Sysinternals procdump. Start your executable from outside Visual Studio, then run:
如果它只是定期崩溃,但在相当短的时间内崩溃,请从 Sysinternals procdump开始。从 Visual Studio 外部启动可执行文件,然后运行:
procdump -e <YourExecutableNameOrPid>
and wait for it to harvest a crash dump - assuming it exits due to an unhandled exception - then load the crash dump into VS 2010 or WinDbg.
并等待它收集故障转储 - 假设它由于未处理的异常退出 - 然后将故障转储加载到 VS 2010 或 WinDbg。
回答by stijn
The program just suddenly exits
程序只是突然退出
definitely check that your code, or one of the libs you use, does not call exit() (yeah might sound too simple, but we once lost hours tracing random programs shutdowns back to exit() calls..). If so, put a breakpoint there or change to throw(), then run again. If not, Sean's answer seems legit.
一定要检查你的代码,或者你使用的库之一,没有调用 exit() (是的,这听起来可能太简单了,但我们曾经浪费了几个小时来跟踪随机程序关闭回到 exit() 调用..)。如果是这样,在那里放置一个断点或更改为 throw(),然后再次运行。如果没有,肖恩的回答似乎是合法的。

