How to have gcov correctly report unused functions as not executed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

When analyzing a program with gcov, I noticed that code lines that do not end up in the final executable are reported as "not executable" instead of "not executed" (i.e. they are marked with '-' instead of '#####' or '===='). Is there any way to change that behavior, either by

a) making gcc/g++ include unused code anyways, or
b) making gcov directly report the lines as not executed, or
c) another option that I have not thought of?

Below is an example file, main.cpp, followed by the corresponding gcov report. One can see that bar() is correctly reported while baz() isn't.

The reason for this question is that I have a moderately large codebase (250k LOC) that we monitor with a CI system, and we would like to add meaningful regression test coverage results. Having unused functions reported as non-executable code is not really helpful in this case, and manually adding dummy references to the unused functions is not feasible due to the code size and number of different committers. Any help is therefore greatly appreciated.

Thanks,

Michael

P.S.: I have tried adding -fno-default-inline and -fno-inline since I suspected it has something to do with the fact that as per the C++ standard, in-class defined methods are automatically inline, but these flags did not help.

main.cpp:
////////////////////////////////////////////////////////////
#include <iostream>

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

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

main.cpp.gcov:
////////////////////////////////////////////////////////////
        -:    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:}
////////////////////////////////////////////////////////////


------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux