Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcov: producing .gcda output from shared library?

Is it possible to produce gcov data files (.gcda files) by running an executable linked to a shared library built with the --coverage option?

Basically, I have the main library consisting of multiple c++ files compiled into one shared library and then a subdirectory called "test" containing a test program that links to and tests the main library. Everything compiles fine and the .gcno files are produced for both the library source files and the test source files. The .gcda files are only produced for the test source files though, but I really need them for the actual source files that are compiled into the shared library.

Any ideas?

Additional info:

  • It's all C++ code
  • Everything is being build with make scripts generated by automake
  • The --coverage option is specified for lib_la_CPPFLAGS and lib_la_LDFLAGS in the shared library Makefile.am
  • The --coverage option is specified for AM_CPPFLAGS and AM_LDFLAGS in test executable Makefile.am
  • The test source files make use of Google Test (a C++ Unit Testing Framework)
like image 763
deuberger Avatar asked Sep 14 '10 21:09

deuberger


People also ask

What can I do with gcov files?

You can use gcov as a profiling tool to help discover where your optimization efforts will best affect your code. You can also use gcov along with the other profiling tool, gprof, to assess which parts of your code use the greatest amount of computing time. Profiling tools help you analyze your code's performance.

Where are GCNO files generated?

The . gcno file is generated when the source file is compiled with the GCC -ftest-coverage option. It contains information to reconstruct the basic block graphs and assign source line numbers to blocks.


1 Answers

I finally solved this problem by getting some help from the gcc guys. See the thread here: http://gcc.gnu.org/ml/gcc-help/2010-09/msg00130.html.

It turns out that the .gcda files were being put in the .libs directory since that's where the shared library (.so) files were. In order to get gcov to produce the output, I had to move the .gcda files up one level to where the source files were.

Also, here's a similar thread where someone else was running into some of the same problems: can gcov deal with shared object?.

like image 128
deuberger Avatar answered Oct 04 '22 18:10

deuberger