是否可以在不丢失 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;
}
最佳答案
needing a back trace from the original throw of the exception,
是否可以使用一种简单的方法来打印所有抛出的所有回溯,然后在需要查找特定异常的回溯时只需通过异常的地址找到它。像这样的 gdb 命令序列:
set pagination off
catch throw
commands
info args
bt
c
end
当你需要查找异常的回溯时,首先打印它的地址,像这样:
print &exception
并在 gdb 输出中找到它的地址。它必须由 info args
打印。一旦找到地址,就会在 info args
输出后回溯此异常。
关于c++ - gdb - 防止在捕获/重新抛出情况下丢失回溯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23820633/