如何从googletest中的异常获取backtrace信息? [英] How to get backtrace information from exception in googletest?
问题描述
如果我运行gdb --args --gtest_catch_exceptions = 0,它将在测试时停止,但是没有任何backtrace信息。它简单地说:
[RUN] TESTNAME.test_case
EXCEPTION:exception description [Inferior 1(process 30528)exited代码0377]
(gdb)bt
无堆栈。
解决方案code> gdb命令在抛出异常之前设置特殊断点。当它被命中,你可以看到backtrace像往常一样通过命令
bt
。请参见 https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints。 html 。I'm trying to do some semi test driven design, and occasionally when I implement a new feature, it will have an exception somewhere. All gtest tells me is what the exception is, and does not give me any backtrace information.
If I run gdb --args --gtest_catch_exceptions=0, it will stop at the test with the exception but not have any backtrace information. It simply states:
[ RUN ] TESTNAME.test_case EXCEPTION: exception description[Inferior 1 (process 30528) exited with code 0377] (gdb) bt No stack.
解决方案Use
catch throw
gdb command to set special breakpoint before your exception is thrown. When it is hit you can see backtrace as usual by commandbt
. See https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html.这篇关于如何从googletest中的异常获取backtrace信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!