为什么 gcc 4.1 + gcov 报告 100% 的分支覆盖率,而更新的(4.4、4.6、4.8)报告“p = new class;"为 50%?线? [英] Why gcc 4.1 + gcov reports 100% branch coverage and newer (4.4, 4.6, 4.8) reports 50% for "p = new class;" line?
问题描述
当 gcc 4.1(使用 gcov)下一行时:
When gcc 4.1 (using gcov) next line:
p = 新类;
报告为 100% 的分支覆盖率 <-- 这对我来说没问题.
is reported as 100% branch coverage <-- THIS IS OK for me.
为什么使用 gcc 4.4 及更高版本的同一行报告为:
Why using gcc 4.4 and higher same line is reportted as:
[+ -] p = 新类;(50% 分支覆盖率)... <-- 这是覆盖 100% 的问题!!!
[+ -] p = new Class; (50% branch coverage)... <-- THIS IS a problem for covering 100% !!!
我可以为较新的 gcc 版本设置任何额外的选项,以便将单行的分支覆盖率与 gcc 4.1 报告为p = new Class;".
Can I set any extra options to newer gcc versions in order to report same branch coverage as gcc 4.1 for single lines as "p = new Class;".
提前致谢.
推荐答案
解决了!
我们有一些带有和不带有异常处理的 C/C++ 文件,因此 lcov/gcov 为每个代码块处理异常处理".
We have some C/C++ files with and without exceptions handling, so lcov/gcov process "exceptions handling" for each code block.
在普通方块内,例如:
int main(void)
{
...
...
[+ -] printf("Hello
");
...
}
gcov 报告 printf 行的分支覆盖率"为 50% ---> 为什么?
gcov reports that printf line has a "branch coverage" of 50% ---> WHY ?
因为启用了异常处理!!!
Because exceptions handling is enabled !!!
为了解决这个问题,指定:
In order to solve this issue, specify:
-fno-exceptions
-fno-exceptions
在 g++ 命令行中.
in g++ command line.
例子:
g++ -O0 --coverage -fno-exceptions -fno-inline ....
g++ -O0 --coverage -fno-exceptions -fno-inline ....
谢谢!
这篇关于为什么 gcc 4.1 + gcov 报告 100% 的分支覆盖率,而更新的(4.4、4.6、4.8)报告“p = new class;"为 50%?线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!