Aaron Michaux
Aaron Michaux

Reputation: 1

Lcov+genhtml incorrect function coverage due to templates (C++)

I'm getting incorrect function coverage output from genhtml when using C++ templates from multiple files. In particular, the function name symbols in the lcov .dat files have the source filename prepended to the function symbol, and this makes it impossible to create a testcase that hits those expanded function symbols.

For example, a .dat file may have a line like follows:

FN:264,stub_handler.cc:_ZZN7Koltrek6PolicyERKNS1_18AbstractSyntaxTree16HeaderFieldMatchEENK3$_9clEv

And elsewhere the symbol appears without stub_handler.cc. Because the template is being instantiated in different files, there's a huge number of generated function symbols, almost all of which aren't being exercised by the tests. Explicitly instantiating the testcase using the relevant template parameters has no effect in getting genhtml to recognize that the functions were actually exercised.

I'm confused to what part of the stack is at fault here. We're using bazel to generate coverage using clang. We then run genhtml on the output.

Any hints on where to look and where to debug are much appreciated, thanks in advance.

I tried:

Upvotes: 0

Views: 223

Answers (1)

Henry Cox
Henry Cox

Reputation: 91

If I understand your goal, the easiest way to achieve it is via "genhtml --filter function ...". This option causes lcov/genhtml to aggregate all the functions which have the same location (filename:start_line) - on the belief that they are likely template instances or generated functions. You might also want to use the '--demangle-cpp' flag (to either 'lcov --capture ...' or to 'genhtml ...') - to see more human-readable function names. Similarly, 'genhtml --show-proportion ...' may help to prioritize partially exercised functions for further verification.

Upvotes: 0

Related Questions