为什么gcov将类的函数定义报告为不可执行? [英] Why does gcov report in-class function definitions as not executable?

查看:204
本文介绍了为什么gcov将类的函数定义报告为不可执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎gcov没有报告类方法作为可执行行的内联定义。示例:

It seems like gcov does not report inline definitions of class methods as executable lines. Example:

#include <iostream>

struct Foo {
  void bar() {}
  void baz() {}
};

int main() {
  Foo foo;
  foo.bar();
}



如果我使用 g ++ -g -O0 -ftest-coverage -fprofile-arcs -o main main.cpp ,运行它,并调用gcov就可以了,我得到以下报告:

If I compile the above program with g++ -g -O0 -ftest-coverage -fprofile-arcs -o main main.cpp, run it, and call gcov on it, I get the following report:

        -:    0:Source:main.cpp
        -:    0:Graph:main.gcno
        -:    0:Data:main.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <iostream>
        -:    2:
        -:    3:struct Foo {
        1:    4:  void bar() {}
        -:    5:  void baz() {}
        -:    6:};
        -:    7:
        1:    8:int main() {
        -:    9:  Foo foo;
        1:   10:  foo.bar();
        4:   11:}

为什么第5行被报告为不可执行,上面的方法是否正确报告执行一次?

Why is line 5 reported as non-executable, even though the method above was reported correctly as executed once?

更新

根据gcov文档( https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html#Invoking -Gcov ), - 表示不可执行行,而 ##### 和<$

According to the gcov documentation (https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html#Invoking-Gcov), - denotes a non-executable line while ##### and ==== mark lines that can be executed but weren't.

推荐答案

gcov报告链接您的二进制文件后,从未有任何可能执行 Foo :: baz()

gcov is reporting that after linking your binary, there was never any possibility of Foo::baz() being executed.

链接器完全删除了该函数,因此没有可执行文件是与该行关联的代码。

The linker completely removed that function, so no executable was code associated with that line anymore.

这篇关于为什么gcov将类的函数定义报告为不可执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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