Does gcov test code coverage during compilation or during execution?

0

I read about gcov for the first time in the Tor documentation , which says :

'-' before a line means
that the compiler generated no code for that line.  '######' means that the
line was never reached.  Lines with numbers were called that number of times.

There is not exactly a Tor test suite, and by the above description, it looks like gcov tests line coverage during compilation.

Other references that I find about gcov suggest that it is used to detect which lines have been hit during execution (whether during normal use or a test suite). But they do not make that very clear. What, after all, is the function of gcov?

    
asked by anonymous 27.03.2014 / 20:49

1 answer

1

Gcov works by using instrumentation of the code. For example: to check what functions are called, it adds code at the beginning of all functions to save the function's own name to a file. The same applies to any other measurement you want to do. At the time of the code execution you will get a list of all the functions called in the file.

This is done because many analyzes are very difficult or even impossible to do statically (without executing the code). Particularly on account of halting problem , any such analysis will be limited in any way. And in the particular case of gcov, it wants to find parts of code that are never executed. This is highly dependent on the input given in the runtime. Static analyzes can split the code into three groups only: will certainly run, will never run and might run . The last group can be deleted at runtime.

    
28.03.2014 / 15:26