如何从googletest中的异常获取backtrace信息? [英] How to get backtrace information from exception in googletest?

查看:885
本文介绍了如何从googletest中的异常获取backtrace信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些半测试驱动的设计,偶尔当我实现一个新的功能,它会有一个异常。所有gtest告诉我是什么例外,并且不给我任何backtrace信息。



如果我运行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 command bt. See https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html.

这篇关于如何从googletest中的异常获取backtrace信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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