How to force gcov to extract data, even when program is aborted

久未见 提交于 2019-11-30 04:41:43

问题


I'm using a test-generating tool called KLEE, that creates lots of tests for my C99-Code. Afterwards I run the tests and check line coverage with gcov. Gcov seems to update coverage data at the end of the run upon successful completion.

However, some tests fail (assert statements that are not true), which leads to aborting the program and gcov not counting the lines covered in this run.

Is there any way that gcov flushes information on any exit (not only on successful)?


回答1:


Call void __gcov_flush(void) (from libgcov.a which is linked in by -fprofile-arcs option of compiler) in your assert code, just before killing and application (e.g. change abort(); into __gcov_flush();abort();). This one will call an gcov_exit function (it is statically defined in libgcov). gcov_exit is the main functions to save collected coverage into file. It is registered by __gcov_init with atfork(); and your assert ignores atfork when kills an application.

Another way of solving this is to find why your assert ignores atfork()-registered functions.



来源:https://stackoverflow.com/questions/6699712/how-to-force-gcov-to-extract-data-even-when-program-is-aborted

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