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

标签 c++ exception exception-handling gdb

是否可以在不丢失 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/

相关文章:

Powershell 捕获异常类型

c++ - 设置 Visual Studio for Windows 初学者教程

c++ - 阿格!反差挫败回调阴谋!想要更改虚拟返回类型

android - 无法启动 Activity ComponentInfo Caused by : android. view.InflateException

java - 统一 Java 中的异常格式

.net - .NET 中的错误代码/消息管理方法

python - 解析 C++ 预处理器 #if 语句

c++ - 使用C++从Windows窗体应用程序访问Sqlite数据库

java - Eclipse 中的 jUnit 抛出空指针异常

silverlight - Silverlight MVVM异常处理