gcov vs. multiple objects derived from the same source

Holger Blasum hbl@sysgo.com
Fri Mar 7 01:15:00 GMT 2008


Hello Bernd,

On Wed, Mar 05, 2008 at 11:08:04AM +0200, Bernd Jendrissek wrote:
> I'm worried that when I do gcov *.o, gcov might not notice that two
> objects are derived from the same file, and thus the coverage notes
> might reflect coverage only of a subset of the use cases - those that
> exercise foo.c through ${bindir}/bar but not those that exercise it
> through ${bindir}/baz.

> Are there any guarantees (or specific lack thereof) about gcov's
> behaviour under these circumstances?

"gcov bar.o baz.o" ->
  gcov bar.o reads bar.gcno and bar.gcda, then writes output into foo.c.gcov
  gcov baz.o reads baz.gcno and baz.gcda, then writes output into foo.c.gcov
    (overwriting the first foo.c) (tested with gcc-3.4.4)

(Although it is built in into the gnu coverage framework to be able to
add up counts this from different runs of the *same* executable, this
is done at the gcda level and not at the foo.c.gcov level, possibly with
the intention to keep things simple.)

Solution: use lcov from the linux test project that has adding
  up functionality at the *.c.gcov level (internally it just uses
  the same gcov framework)

(Let's assume that bar contains bar.o and baz contain baz.o)

  lcov --zerocounters
  ./bar
  lcov --capture --output-file barbaz.info
  ./baz
  lcov --capture --output-file barbaz.info
  genhtml barbaz.info

HTH,

-- 
Holger Blasum AT www.sysgo.com



More information about the Gcc-help mailing list