Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is gcov creating Code Coverage data for STL Headers?

When I run gcov foo.cpp it not only generates the code coverage report for foo.cpp, but for all the STL headers used by foo.cpp.

Is there a way to prevent this? It seems to ignore standard library headers like <ctime>.

Edit

Just ran across this post on the gcc mailing list:

Re: gcc, gcov and STL

like image 429
Robert S. Barnes Avatar asked Jun 09 '10 08:06

Robert S. Barnes


1 Answers

Any C++ header files with inline code will get coverage instrumentation when you compile and the results will be visible with gcov. One useful flag is gcov -long-file-names (or just -l) which creates a unique .gcov output file for each header included by a given file. The files have names like foo.cpp##bar.h.gcov. This would make them easy for you to delete afterward with rm \*\\#\\#\*.gcov (careful with those backslashes!)

Another way you can detect these files is to look for the lines numbered 0 in the gcov output. These have tagged information including 'Source:' with the full path to the original source file.

like image 158
Ben Jackson Avatar answered Oct 04 '22 18:10

Ben Jackson