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

How to break when a specific exception type is thrown in GDB?(在 GDB 中抛出特定异常类型时如何中断?)
本文介绍了在 GDB 中抛出特定异常类型时如何中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

According to the documentation I can break on specific exception type by using conditional breakpoints. However the syntax for the condition isn't very clear to me:

condition bnum <expression>

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

Looking at the expression syntax I think this is the pattern I need:

{type} 地址

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

However, I don't know what I should pass for the addr argument. I tried the following:

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

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

But it doesn't work (gdb breaks on all exception types).

谁能帮忙?


更新

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


Update

I also tried @Adam's suggestion, but it results in an error message:

(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 的构造函数是可行的.


Workaround

Breaking in the constructor of bad_function_call works.

推荐答案

编辑

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

The documentation suggests that catch throw <exceptname> can be used to break whenever an exception of type <exceptname> is thrown; however, that doesn't seem to work in practice.

(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.

这篇关于在 GDB 中抛出特定异常类型时如何中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)