gcov not showing any coverage data

goldenmean picture goldenmean · Dec 19, 2012 · Viewed 11.5k times · Source

I am trying to use gcov on Linux(Ubuntu) to see frequency of execution for each line of source.

I have added following flags to my gcc compiler and linker flags,

CCFLAGS =  -fprofile-arcs -ftest-coverage
LDFLAGS = -fprofile-arcs -lgcov

but after compiling and running the program, i see no *.gcda file created. As a result of which when i run

gcov  --object-directory <path to the *.gcno/*.gcda files> myfile.cpp 

Shows error:

myfile.gcda:cannot open data file, assuming not executed
File '../../../../../code/myfile.cpp'
Lines executed:0.00% of 2625

Am i missing something. How to fix this?

Answer

Icarus3 picture Icarus3 · Dec 20, 2012

You can use __gcov_flush() method inside your code. You will need to invoke this from registered signal handler.

See:

https://www.osadl.org/fileadmin/dam/interface/docbook/howtos/coverage.pdf

Using this, you can keep your service running and issue "kill" whenever you need to dump coverage data.

Hope that helps....