从特定函数调用时,GDB会在抛出异常时中断 [英] GDB break on exception thrown when called from specific function

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

问题描述



我的使用情况是我有一个线程,我想使用GDB来打破异常时抛出的异常。在其他线程中调用其doRun()函数的类。那个线程捕捉到任何异常,但是我希望能够在异常抛出(不被捕获)时中断。



我知道GDB可以做反向调试(很棒的概念),所以这可能会被使用,但我想要一些更通用的东西 - 其实我想要这个解决方案找到我的.gdbinit文件。

解决方案

gdb的最新版本有一些方便的功能,例如$ _any_caller_matches。这些都是用Python编写的,所以即使你的gdb没有内置的,你也可以抓住代码,把它放到gdb中。



你会使用它(未经测试,但你得到的想法):

  catch throw if $ _any_caller_matches(Thread doRun)


I would like to use GDB to break when an exception is thrown only when the stack goes through a specific function.

My use case is that I have a Thread class whose doRun() function is called in a new thread. That thread catches any exception that bubbles up, but I would like to be able to break when the exception is thrown (not caught).

I know GDB can do "reverse debugging" (awesome concept) so this could potentially be used, but I'd like something more general purpose -- in fact, I'd like this solution to find its way to my .gdbinit file.

解决方案

Recent versions of gdb have some convenience functions that are useful for this, e.g., "$_any_caller_matches". These are written in Python, so even if your gdb doesn't have them built-in, you might be able to grab the code and just drop it into your gdb.

You would use it like (untested, but you get the idea):

catch throw if $_any_caller_matches("Thread::doRun")

这篇关于从特定函数调用时,GDB会在抛出异常时中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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