Scintiller
Scintiller

Reputation: 1

For the input of gcov, any difference between .cpp/.gcda/.gcno

Is there any difference between gcov foo.gcda, gcov foo.gcno and gcov foo.cpp?

According to the official guide, we have to put source file foo.cpp together with foo.gcda and foo.gcno, then use gcov foo.cpp to generate the report.

But in a CMake Project, object files, gcda and gcno files are put in a different folder from the source files, as this Question presents. So sometimes it's hard to find the source files and move them (as I'm calculating coverage for Pytorch Project). Then I tried to skip .cpp, just do

gcov -i foo.gcda

in the CMake folder in which there are foo.gcda, foo.gcno and foo.o. And the result also shows up. I wonder if this result is also correct, or do I have to copy the corresponding foo.cpp to this folder and do as official documentation suggests?

Upvotes: 0

Views: 391

Answers (1)

VVish
VVish

Reputation: 311

You will be getting an output with only the coverage when you run this gcov -i foo.gcda.

For eg :- File 'foo.c' Lines executed:92.86% of 14 Creating 'foo.c.gcov'.

And the coverage percentage you are getting is completely correct. The only difference is when you do not put the source file in the same directory commands like :

gcov -a foo.gcda will fail with Cannot open source file foo.c

This is because with the -a flag you get individual execution counts for every basic block and the output contains the source code along with the number of times each line got executed. If you only want to get the coverage as an output this will work fine but what if you want a HTML based output using tool like lcov, then this method will not work as you will not be able to get the source code.

Upvotes: 1

Related Questions