【问题标题】:gdb - Prevent losing backtrace in a catch/rethrow situationgdb - 防止在 catch/rethrow 情况下丢失回溯
【发布时间】:2014-05-23 03:44:35
【问题描述】:

是否可以在不丢失 gdb 中的回溯的情况下重新抛出异常?或者 gdb 中有没有办法“备份”几行并从那里回溯?我在 GDB 7.7.1 上,最新的。

我有时会发现自己遇到这样的情况,需要从异常的原始抛出中进行回溯,需要注释掉 try/catch 部分,重新​​编译,然后在 gdb 中重新运行。

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

----或----

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

【问题讨论】:

    标签: c++ exception exception-handling gdb


    【解决方案1】:

    需要从异常的原始抛出进行回溯,

    是否可以使用打印所有抛出的所有回溯的简单方法,然后当需要查找特定异常的回溯时,只需通过异常的地址找到它。类似于这个 gdb 命令序列:

    set pagination off
    catch throw
    commands
    info args
    bt
    c
    end
    

    当你需要查找异常的回溯时,首先打印其地址,如下所示:

    print &exception
    

    并在 gdb 输出中找到它的地址。必须由info args 打印。只要找到地址,就会在info args 输出后回溯这个异常。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多