问题描述
我的使用情况是我有一个线程,我想使用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会在抛出异常时中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!