gdb - 防止在捕获/重新抛出情况下丢失回溯

jam*_*vey 5 c++ gdb exception-handling exception

是否可以重新抛出异常而不会丢失gdb中的反向跟踪?或者有没有办法在gdb中"备份"几行并从那里返回跟踪?我在GDB 7.7.1上,这是最新的.

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

try {
   someFuncThatCanThrowException();
} catch(exceptionType& exception) {
   if(@CAN_RECOVER@) {
      ...
   } else {
      throw;
   }
}
Run Code Online (Sandbox Code Playgroud)

- - 要么 - -

try {
   someFuncThatCanThrowException();
} catch(exceptionType& exception) {
   exception.printMessageToCout();
   throw;
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*kov 6

需要从异常的原始抛出中追溯,

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

set pagination off
catch throw
commands
info args
bt
c
end
Run Code Online (Sandbox Code Playgroud)

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

print &exception
Run Code Online (Sandbox Code Playgroud)

并在gdb输出中找到它的地址.必须打印出来info args.一旦找到地址,info args输出后就会出现此异常的回溯.