Search code examples
c++gcovrg++12

Why does gcovr fail to create a report with g++ version 12?


I have recently upgraded my toolchain, which has caused gcovr to fail to produce any coverage output. Can anyone tell me if this is an issue with gcovr, or my toolchain, or missing dependencies?

Here is the example/comparison I used to verify:

example.cpp

// Taken from gcovr user guide.
// example.cpp

int foo(int param)
{
    if (param)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main(int argc, char* argv[])
{
    foo(0);
    return 0;
}

gcovr version:

gcovr 6.0

Copyright (c) 2013-2023 the gcovr authors
Copyright (c) 2013 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.

When using g++ version:

g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I get the proper result:

$ g++ -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
$ ./program
$ gcovr
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
example.cpp                                    7       6    85%   7
------------------------------------------------------------------------------
TOTAL                                          7       6    85%
------------------------------------------------------------------------------

However when using the updated version 12 toolchain:

g++-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I get the following result:

$ g++-12 -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
$ ./program
$ gcovr
(ERROR) Trouble processing '/home/janjaap/workspace/testgcovr/program-example.gcda' with working directory '/home/janjaap/workspace/testgcovr'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended informations.
Traceback (most recent call last):
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 515, in run_with_args
    raise RuntimeError(
RuntimeError: GCOV returncode was -11 (exited by signal).
Traceback (most recent call last):
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 515, in run_with_args
    raise RuntimeError(
RuntimeError: GCOV returncode was -11 (exited by signal).
(ERROR) Uncaught EXCEPTION
Traceback (most recent call last):
  File "/home/janjaap/.local/bin/gcovr", line 8, in <module>
    sys.exit(main())
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/__main__.py", line 328, in main
    covdata = collect_coverage_from_gcov(options)
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/__main__.py", line 380, in collect_coverage_from_gcov
    with Workers(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 173, in __exit__
    self.wait()
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/__main__.py", line 387, in collect_coverage_from_gcov
    contexts = pool.wait()
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
  File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 515, in run_with_args
    raise RuntimeError(
RuntimeError: GCOV returncode was -11 (exited by signal).

Solution

  • When you run gcovr with a compiler other than your system's default gcc/g++, you must tell it which gcov tool to use. Since the binary coverage data format changes between compiler versions, the matching gcov must be used.

    Here, you're using g++-12. The corresponding gcov is probably called gcov-12. You can tell gcovr to use this via the --gcov-executable option.

    gcovr --gcov-executable gcov-12
    

    Further reading: Choosing the Right Gcov Executable in the gcovr documentation.