Bug 28564 - gcov fails to store the absolute path to the source files
Summary: gcov fails to store the absolute path to the source files
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: gcov-profile (show other bugs)
Version: 4.0.1
: P3 enhancement
Target Milestone: 9.0
Assignee: Martin Liška
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-01 17:36 UTC by David Coppit
Modified: 2018-08-01 13:46 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-11-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Coppit 2006-08-01 17:36:18 UTC
Unlike other tools such as gdb that need source files, gcov does not store the absolute path. As a result, gcov must be run in the same directory in which gcc was invoked. This makes it particularly difficult to generate coverage reports for separately compiled libraries that have separate src/ and build/ directories.

Below is a shell script that demonstrates the problem.

#!/bin/sh

rm -rf src build bin coverage
mkdir src build bin coverage
echo 'int main() {return 0;}' > src/test.c
gcc -c -o build/test.o -g -fprofile-arcs -ftest-coverage src/test.c
gcc -o bin/test -g -fprofile-arcs -ftest-coverage build/test.o
./bin/test
cd coverage
gcov -o ../build ../src/test.c

As an addendum to this bug, if the absolute path to the object file was also saved in the .gcda or .gcno file with the absolute path to the source file, then one could generate coverage files using simply:

gcov ../build/test.gcna

(Currently one can specify the .gcna file this way, but one must run gcov in the original build directory due to the relative source file path bug, and also specify "-o build" since the object file path is not saved in the .gcna/.gcno file.)
Comment 1 Martin Liška 2016-11-25 14:40:49 UTC
The request sound eligible for me.
What others think about it?
Comment 2 Dmitry G. Dyachenko 2018-02-25 12:14:03 UTC
(In reply to Martin Liška from comment #1)
> The request sound eligible for me.
> What others think about it?

Nice to have for me
Comment 3 Martin Liška 2018-02-26 09:15:10 UTC
Then let me do that in GCC 9.
Comment 4 Martin Liška 2018-08-01 13:46:02 UTC
Well after reconsidering this, I probably don't want to hardwire absolute paths to .gcda and .gcno files. One can do instrumentation and run on a different machine, thus usage of -o option is right thing to do.