gdb - Prevent losing backtrace in a catch/rethrow situation

天大地大妈咪最大 提交于 2019-12-07 05:23:58

问题


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.

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;
}

回答1:


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

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

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.



来源:https://stackoverflow.com/questions/23820633/gdb-prevent-losing-backtrace-in-a-catch-rethrow-situation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!