当捕获异常时,可以使用gdb来追溯吗? [英] Can gdb be used to backtrace when exceptions are caught?
问题描述
我的策略是在 catch
阻止,然后通过调用堆栈来精确地确定为什么首先抛出异常(或是什么原因)?不幸的是,我似乎无法做到这一点,因为当gdb到达断点时,它清除了调用堆栈,我只能看到main(这是我抓到的地方)。这是否应该发生,或者我在这里做错了?
编辑:
我只想总结这里的方法其他人:
第一种方法(通过paulsm4)。通过 catch throw
设置一个捕获点,以捕捉或者code> catch catch 来捕捉捕获!然后调用 backtrace
第二个方法(由aschepler)在 __ cxa_throw
然后 backtrace
第3种方法(在Qt创建者中 - 如果您恰好使用)你可以很容易地在throw或catch上设置一个断点!
Edit_2:使用Qt Creator调试器,似乎在 __ cxa_begin_catch
也相当于 catch catch
:)
这是:
http://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html
您可以使用捕获点导致调试器停止某些
种程序事件,例如C ++异常或
共享库的加载。使用catch命令设置一个接收点。
所以答案应该是是,它应该避免两个问题你引用的链接。
如果有帮助,请回帖就我个人而言,我从未尝试过这个GDB功能:)
I have just started using c++ exceptions and want to get it right. What I have in mind is to generate some sort of backtrace information when exceptions are caught. Initially I had ideas similar to Call-stack for exceptions in C++ but eventually figured out that's not quite good.
I have also read How to generate a stacktrace when my gcc C++ app crashes but do not want to add more complexity to my current project. Since, I only need the backtracing when in debug mode, I was hoping I could be using gdb for that purpose.
My strategy has been to insert breakpoint in the catch
block and then go up through the call stack to exactly pinpoint why the exception was thrown in the first place (or what caused it)? Unfortunatly, I cannot seem to be able to do this since when gdb reaches the breakpoint, it clears the call stack and I can only see main (that's where I catch). Is this supposed to happen or am I doing something wrong here?
Edit: I just like to summarize the methods here for other folks:
1st Method (by paulsm4). Set a catchpoint via catch throw
for catching on throw or catch catch
for catching on catch! Then call backtrace
2nd Method (by aschepler) Set a breakpoint on __cxa_throw
and then backtrace
3rd Method (in Qt Creator -- if you happen to use) You can easily set a breakpoint on throw or catch!
Edit_2: Using Qt Creator debugger, it seems that setting a breakpoint on __cxa_begin_catch
is also an equivalent to catch catch
:)
This this:
http://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html
You can use catchpoints to cause the debugger to stop for certain kinds of program events, such as C++ exceptions or the loading of a shared library. Use the catch command to set a catchpoint.
So the answer should be "yes", and it should avoid the problems with the two links you cited.
Please post back if it helped! Personally, I've never tried this GDB feature myself :)
这篇关于当捕获异常时,可以使用gdb来追溯吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!