我如何从gcov获得更准确的结果? [英] How can I get more accurate results from gcov?

查看:119
本文介绍了我如何从gcov获得更准确的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用gingw gcc 4.4.0试验gcov。我得到了一些有趣但奇怪的结果。一个常见的模式是这样的...

  5162:66:std :: string :: iterator i = l_Temp.begin (); 
5162:67:std :: string :: iterator j = l_Temp.end() - 1;
- :68:char ch;
- :69:
20564:70:while(i - :71:{
10240:72:ch = * i; * i = * j; * j = ch;我++; j--;
- :73:}
- :74:
#####:75:return l_Temp;
- :76:}

code>根本没有被执行,因为前面的循环清楚地执行和退出?假设这个临时变量的类型是 std :: string ,那么我认为我是返回值优化的受害者。



问题是,我已经在编译器选项中指定了 -O0 。这些是我正在使用的确切编译器标志...

  -Wno-invalid-offsetof -g -O0 -fprofile- arcs -ftest-coverage 

我最好的猜测是并非所有的优化都被 -O0 毕竟。我可以开始寻找特定的优化标志,因为我发现问题,但这似乎是一个奇怪的事情需要做。

所以 - 什么标志应该我指定为了从gcov获得理智的覆盖结果?



编辑



到目前为止,我认为我需要以下附加标志...




  • -fno-default-inline
  • >
  • -fno-inline



我不确定这些都是必需的,但我认为它们都是禁用不同的特定类型的内联。



尽管如此,我还没有找到任何禁用返回值优化的方法。这不是一个大问题,但是这有点麻烦。当瞄准100%的覆盖率时,一些真正达到100%的文件会因为这个问题而少报。 grep可以找到 ##### 标记并显示它们是否为 return 语句,但是您仍然需要做一些视觉检查,以检查问题是纯粹的RVO。

正如Mat在评论中所建议的那样,选项 -fno-elide-constructors 修复了这个问题。



这个答案是为了让这个古老的问题关闭。如果Mat发布了答案,我会删除它,并将接受转换为该答案。


I'm experimenting with gcov using mingw gcc 4.4.0. I've been getting some interesting but strange results. A common pattern is something like this...

     5162:   66:  std::string::iterator i = l_Temp.begin ();
     5162:   67:  std::string::iterator j = l_Temp.end () - 1;
        -:   68:  char ch;
        -:   69:
    20564:   70:  while (i < j)
        -:   71:  {
    10240:   72:    ch = *i; *i = *j; *j = ch; i++; j--;
        -:   73:  }
        -:   74:
    #####:   75:  return l_Temp;
        -:   76:}

How can that return not be exected at all, given that the loop just before clearly is both executing and exiting? I think I'm a victim of the return value optimisation here, given that this temporary variable is of type std::string.

The trouble is, I'm already specifying -O0 in the compiler options. These are the exact compiler flags I'm using...

-Wno-invalid-offsetof -g -O0 -fprofile-arcs -ftest-coverage

My best guess is that not all optimisations are disabled by -O0 after all. I can start hunting down specific optimisation flags one by one as I notice problems, but this seems a strange thing to need to do.

So - what flags should I be specifying in order to get sane coverage results from gcov?

EDIT

So far, I think I need the following additional flags...

  • -fno-default-inline
  • -fno-inline

I'm not sure these are both needed, though I think they each disable a different specific type of inline.

I haven't found any way to disable return value optimisations, though. This isn't a big problem, but it's a bit of an annoyance. When aiming for 100% coverage, some files that really do achieve 100% will be reported as less because of this issue. A grep can find the ##### markers and show if they're for return statements, but you still need to do some visual inspection to check that the problem is purely an RVO.

解决方案

As suggested in the comment by Mat, the option -fno-elide-constructors fixes this problem.

This answer was posted to get this already ancient question closed. If Mat posts an answer, I'll delete this and switch the accept to that.

这篇关于我如何从gcov获得更准确的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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