c++ - 在 GDB 中抛出特定异常类型时如何中断?

标签 c++ gdb

根据文档,我可以通过使用条件断点来中断特定的异常类型。但是条件的语法对我来说不是很清楚:

condition bnum <expression>

查看表达式语法我认为这是我需要的模式:

{type} addr

但是,我不知道应该为 addr 参数传递什么。我尝试了以下方法:

(gdb) catch throw
(gdb) condition 1 boost::bad_function_call *

但它不起作用(gdb 中断所有异常类型)。

谁能帮忙?


更新

我也尝试了@Adam 的建议,但它导致错误消息:

(gdb) catch throw boost::bad_function_call
Junk at end of arguments.

没有 boost:: 命名空间:

(gdb) catch throw bad_function_call
Junk at end of arguments.


解决方法

打破 bad_function_call 的构造函数是可行的。

最佳答案

编辑

文档建议 catch throw <exceptname>可用于中断 <exceptname> 类型的异常被抛出;但是,这在实践中似乎行不通。

(gdb) help catch
Set catchpoints to catch events.
Raised signals may be caught:
        catch signal              - all signals
        catch signal <signame>    - a particular signal
Raised exceptions may be caught:
        catch throw               - all exceptions, when thrown
        catch throw <exceptname>  - a particular exception, when thrown
        catch catch               - all exceptions, when caught
        catch catch <exceptname>  - a particular exception, when caught
Thread or process events may be caught:
        catch thread_start        - any threads, just after creation
        catch thread_exit         - any threads, just before expiration
        catch thread_join         - any threads, just after joins
Process events may be caught:
        catch start               - any processes, just after creation
        catch exit                - any processes, just before expiration
        catch fork                - calls to fork()
        catch vfork               - calls to vfork()
        catch exec                - calls to exec()
Dynamically-linked library events may be caught:
        catch load                - loads of any library
        catch load <libname>      - loads of a particular library
        catch unload              - unloads of any library
        catch unload <libname>    - unloads of a particular library
The act of your program's execution stopping may also be caught:
        catch stop

C++ exceptions may be caught:
        catch throw               - all exceptions, when thrown
        catch catch               - all exceptions, when caught
Ada exceptions may be caught:
        catch exception           - all exceptions, when raised
        catch exception <name>    - a particular exception, when raised
        catch exception unhandled - all unhandled exceptions, when raised
        catch assert              - all failed assertions, when raised

Do "help set follow-fork-mode" for info on debugging your program
after a fork or vfork is caught.

Do "help breakpoints" for info on other commands dealing with breakpoints.

关于c++ - 在 GDB 中抛出特定异常类型时如何中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6835728/

相关文章:

c++ - Windows API 和 GetClassName()?另一个名字?

linux - 在gdb中调用malloc时出现负数

compiler-construction - 符号表存储在哪里?

c++ - 如果附加了 gdb,我该如何中断,但如果没有附加,我该如何继续?

linux - gdb 奇怪的回溯,没有函数名,只有?

c++ - 我应该在 C++11 中显式声明转换运算符吗?

c++ - 纹理的理解

c++ - 当某个成员变量取值时,在 gdb 中有没有一种快速的方法来中断类的任何方法?

C++消息查找表(iostream)

c++ - 连续 block 从初始 block 读取内存