gdb - 防止在catch / rethrow情况下丢失回溯 [英] gdb - Prevent losing backtrace in a catch/rethrow situation

查看:142
本文介绍了gdb - 防止在catch / rethrow情况下丢失回溯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以重新抛出异常,而不会丢失gdb中的后跟踪?还是在gdb中有一种方法来备份几行,从那里回溯跟踪?我在GDB 7.7.1中是最新的。

Is it possible to re-throw an exception without losing the back-trace in gdb? Or is there a way in gdb to "back up' a few lines and back trace from there? I'm on GDB 7.7.1, the most recent.

我有时候会发现自己遇到这样的情况,需要从原始的异常处理中回溯跟踪,并且需要注释掉gdb中的try / catch部分,重新​​编译和重新运行。

I sometimes find myself running into situations like this, needing a back trace from the original throw of the exception, and needing to comment out the try/catch parts, recompiling, and re-running in gdb.

try {
   someFuncThatCanThrowException();
} catch(exceptionType& exception) {
   if(@CAN_RECOVER@) {
      ...
   } else {
      throw;
   }
}

----或----

----OR----

try {
   someFuncThatCanThrowException();
} catch(exceptionType& exception) {
   exception.printMessageToCout();
   throw;
}


推荐答案


需要从原始的异常的追溯,

needing a back trace from the original throw of the exception,

使用简单的方法可以吗? ch打印所有投掷的所有回溯,然后当有必要找到特定异常的追溯时,只是通过异常的地址找到它。像这样的gdb命令序列:

Is it OK to use a simple approach of printing all backtraces of all throws and then when it is necessary to find a backtrace of a particular exception just find it by the address of the exception. Something like this sequence of gdb commands:

set pagination off
catch throw
commands
info args
bt
c
end

当你需要找到追溯异常,首先打印其地址,如下所示:

When you need to find backtrace of an exception, first print its address, like this:

print &exception

并在gdb输出中找到它的地址。它必须由 info args 打印。一旦你找到地址,就会在 info args 输出之后回溯这个例外。

And find its address in the gdb output. It must be printed by info args. As soon as you find address there will be backtrace of this exception after info args output.

这篇关于gdb - 防止在catch / rethrow情况下丢失回溯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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