https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89961
--- Comment #13 from Martin Liška <marxin at gcc dot gnu.org> --- (In reply to xaizek from comment #11) > > Closing this as fixed. > > This isn't fixed. I don't think the problem was actually understood. > > Say you have: > > * src/myclass.o > * tests/myclass.o > Looking into the documentation: https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html#Invoking-Gcov ``` gcov should be run with the current directory the same as that when you invoked the compiler. Otherwise it will not be able to locate the source files. gcov produces files called mangledname.gcov in the current directory. ``` > If you run `gcov -p -x --json-format src/myclass.o` you get > myclass.gcov.json.gz for that file, running `gcov -p -x --json-format > tests/myclass.o` gives you myclass.gcov.json.gz for the test. Running `gcov > -p -x --json-format src/myclass.o tests/myclass.o` gives > myclass.gcov.json.gz *FOR THE TEST ONLY*, because gcov created output for > src/myclass.o and then replaced it. This example violates that because you would end up with clasing myclass.o. > > From reading your comment I thought that maybe gcov combines information > from two files before writing the result to address this issue, but it > doesn't. Results you get depends on the order in which files are specified. > > Either -p and -x need to be obeyed or reports need to be merged. If > combining is implemented, might as well combine all reports and write a > single file specified on command line (--json-format=myfile.gz or > --json-format=- (no compression needed)). What you can use is -t argument that will output to stdout where you'll get 2 JSON objects.