SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
710 stars 109 forks source link

Coverage report is empty when running --collect-only/--report--only separately for the compiled language case #396

Open YuanLanier opened 1 year ago

YuanLanier commented 1 year ago

Hi Simon,

We are experimenting kcov v41 with running --collect-only/--report-only separately for a .cc binary. But the coverage report ended being empty. Please advise whether we missed anything. Below are the details.

Here is a small .cc test example.

#include <iostream>
using namespace std;

int main() {

  int first_number, second_number, sum;

  cout << "Enter two integers: ";
  cin >> first_number >> second_number;

  // sum of two numbers in stored in variable sumOfTwoNumbers
  sum = first_number + second_number;

  // prints sum 
  cout << first_number << " + " <<  second_number << " = " << sum;     

  return 0;
}

We built the binary using :

g++ cplusplus_demo.cc -g -o demo

Then we used the below commands to generate the reports.

kcov --collect-only output-collect ./demo kcov --report-only output-collect ./demo

The generated report is empty.

image

But if we create the report in one step, the coverage report is as expected.

kcov output-collect-simply ./demo

image

We notice in the case of running --collect-only/--report-only separately, the coverage.db size is much smaller and the html/js files associated with the source files are also missing. Here is the comparison.

image image

The previously reported issue https://github.com/SimonKagstrom/kcov/issues/330 seems to be similar to this issue we are experiencing although our case is the compiled language case.

Could you please advise how to get the compiled language coverage report case working when using --collect-only/--report-only separately? Thank you!

SimonKagstrom commented 1 year ago

One thin which might perhaps affect this is if you've built a "PIE executable", which is effectively loaded as a shared library. If you're able to recompile your application, you may try to add the -no-pie argument to the CFLAGS/CXXFLAGS and the LDFLAGS.

Sorry for the late reply!

SimonKagstrom commented 11 months ago

I've tried this again, and can't seem to reproduce it here. I put your example in /tmp/a.cc, compiled to /tmp/a and ran

 src/kcov --collect-only /tmp/kcov /tmp/a
 src/kcov --report-only /tmp/kcov/ /tmp/a

and I get the same results with collect+report as without them. Ran the test on master, but I don't think anything has changed for a while which should be related to collect+report.