How to get backtrace information from exception in googletest?

吃可爱长大的小学妹 提交于 2020-01-29 21:48:53

问题


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.

回答1:


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.




回答2:


In a more automatic way, you can add your own listener and then combine the output of failing test-cases by printing additionally the backtrace using How to make backtrace()/backtrace_symbols() print the function names?



来源:https://stackoverflow.com/questions/26581066/how-to-get-backtrace-information-from-exception-in-googletest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!