在GDB中抛出特定异常类型时如何中断? [英] How to break when a specific exception type is thrown in GDB?

查看:980
本文介绍了在GDB中抛出特定异常类型时如何中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  condition bnum< expression> 

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


{type} addr


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

$ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ b

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



任何人都可以帮忙吗?
$ b $ p

更新


我也试过@ Adam的建议,但它会产生一个错误消息:

$ g $ g $ gdb catch throw boost :: bad_function_call
参数结束时的垃圾。

没有 boost :: namespace:

 (gdb)catch throw bad_function_call 
参数结束时的垃圾。

解决方法


打破构造函数 bad_function_call 有效。

解决方案

编辑



文档表明,只要<$ c>类型的异常可以使用 catch throw< exceptname> $ c>< exceptname> 被抛出;然而,这似乎并没有在实践中。

 (gdb)help catch 
设置catchpoints以捕捉事件。
被捕获的信号可能被捕获:
捕获信号 - 所有信号
捕获信号< signame> - 一个特定的信号
被捕获的异常可能被捕获:
捕获抛出 - 抛出时抛出的所有异常
捕获抛出< exceptname> - 一个特定的异常,当抛出时
catch catch - 所有异常,当被捕获时
catch catch< exceptname> - 一个特定的异常,当被捕获时
线程或进程事件可能被捕获:
catch thread_start - 创建后的任何线程
捕获thread_exit - 任何线程,仅在到期前
catch thread_join - 紧接在
之后的任何线程可以捕获进程事件:
catch start - 创建后的任何进程
catch exit - 任何进程,仅在到期之前
catch fork - 调用fork()
catch vfork - 调用vfork()
catch exec - 调用exec()
动态链接库事件可能被捕获:
catch load - 任何库的加载
catch load< libname> - 特定库的加载
捕获卸载 - 卸载任何库
捕获卸载< libname> - 卸载特定的库
程序的执行停止行为也可能被捕获:
catch stop

可能会捕获C ++异常:
catch throw - all抛出异常时抛出
catch catch - 捕获所有异常
可能捕获Ada异常:
捕获异常 - 所有异常,当引发时
捕获异常< name> - 一个特殊的异常,当引发
捕获异常未处理时 - 所有未处理的异常,当引发
catch assert时 - 所有失败的断言,当引发

时帮助​​设置后续分支 - 模式获取有关在fork或vfork被捕获后调试程序
的信息。

为处理断点的其他命令的信息提供帮助断点。


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 *

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

Can anyone help?


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.

Without boost:: namespace:

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


Workaround

Breaking in the constructor of bad_function_call works.

解决方案

EDIT

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中抛出特定异常类型时如何中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆