C ++程序崩溃时如何获取堆栈跟踪?(使用msvc8/2005) [英] How to get a stack trace when C++ program crashes? (using msvc8/2005)

查看:85
本文介绍了C ++程序崩溃时如何获取堆栈跟踪?(使用msvc8/2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我的c ++程序在调试模式下崩溃,我得到的是一个消息框,指出某些内部内存管理例程中的断言失败(访问未分配的内存等).但是我不知道从哪里调用的,因为我没有得到任何堆栈跟踪.如何获得堆栈跟踪或至少查看代码失败的地方(而不是库/内置例程)?

Sometimes my c++ program crashes in debug mode, and what I got is a message box saying that an assertion failed in some of the internal memory management routines (accessing unallocated memory etc.). But I don't know where that was called from, because I didn't get any stack trace. How do I get a stack trace or at least see where it fails in my code (instead of library/ built-in routines)?

推荐答案

如果发生崩溃,无论是调试版本还是发布版本,都可以获取有关崩溃发生位置的信息.即使您在没有源代码的计算机上,也可以看到调用堆栈.

If you have a crash, you can get information about where the crash happened whether you have a debug or a release build. And you can see the call stack even if you are on a computer that does not have the source code.

为此,您需要使用与EXE一起构建的PDB文件.将PDB文件与崩溃的EXE放在同一目录中.注意:即使您具有相同的源代码,也无法两次构建并使用第一个EXE和第二个PDB.您需要使用与EXE一起构建的确切PDB.

To do this you need to use the PDB file that was built with your EXE. Put the PDB file inside the same directory as the EXE that crashed. Note: Even if you have the same source code, building twice and using the first EXE and the second PDB won't work. You need to use the exact PDB that was built with your EXE.

然后将调试器附加到崩溃的进程.例如:windbg或VS.

Then attach a debugger to the process that crashed. Example: windbg or VS.

然后只需签出您的调用堆栈,同时还可以打开线程窗口.您将必须选择崩溃的线程,并在调用堆栈中检查该线程.每个线程都有一个不同的调用堆栈.

Then simply checkout your call stack, while also having your threads window open. You will have to select the thread that crashed and check on the callstack for that thread. Each thread has a different call stack.

如果已经连接了VS调试器,它将自动转到导致崩溃的源代码.

If you already have your VS debugger attached, it will automatically go to the source code that is causing the crash for you.

如果崩溃发生在您正在使用的库中,而您没有该库的PDB.您无能为力.

If the crash is happening inside a library you are using that you don't have the PDB for. There is nothing you can do.

这篇关于C ++程序崩溃时如何获取堆栈跟踪?(使用msvc8/2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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