public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcov and autotools - filename issues
@ 2010-04-10  4:05 Adam Nielsen
  2010-04-10  4:46 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Nielsen @ 2010-04-10  4:05 UTC (permalink / raw)
  To: gcc-help

Hi all,

I hope this is the right place for this question.

Having just discovered gcov, I would like to use it with my autoconf-based
project.  Unfortunately all the examples seem to use only one source file,
whereas I have many and they're in different subfolders.

If I compile my code with the appropriate GCC options, the .gcno files get
created but I'm not sure how to run gcov.  For example I have some unit tests
in a tests/ subdirectory:

  $ gcov tests/tests.cpp
  tests.gcno:cannot open graph file

Which is correct, because the autotools name it as tests/tests-tests.gcno.
Likewise all the other .gcno files are in subdirectories with the directory
name prepended onto the filename.

If anyone can shed some light on how gcov should be run in this situation
please let me know!

Many thanks,
Adam.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcov and autotools - filename issues
  2010-04-10  4:05 gcov and autotools - filename issues Adam Nielsen
@ 2010-04-10  4:46 ` Ian Lance Taylor
  2010-04-10  5:59   ` Adam Nielsen
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2010-04-10  4:46 UTC (permalink / raw)
  To: Adam Nielsen; +Cc: gcc-help

Adam Nielsen <a.nielsen@shikadi.net> writes:

> Having just discovered gcov, I would like to use it with my autoconf-based
> project.  Unfortunately all the examples seem to use only one source file,
> whereas I have many and they're in different subfolders.
>
> If I compile my code with the appropriate GCC options, the .gcno files get
> created but I'm not sure how to run gcov.  For example I have some unit tests
> in a tests/ subdirectory:
>
>   $ gcov tests/tests.cpp
>   tests.gcno:cannot open graph file
>
> Which is correct, because the autotools name it as tests/tests-tests.gcno.
> Likewise all the other .gcno files are in subdirectories with the directory
> name prepended onto the filename.
>
> If anyone can shed some light on how gcov should be run in this situation
> please let me know!

http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Invoking-Gcov.html

Note the -o option.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcov and autotools - filename issues
  2010-04-10  4:46 ` Ian Lance Taylor
@ 2010-04-10  5:59   ` Adam Nielsen
  2010-04-10  6:10     ` Adam Nielsen
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Nielsen @ 2010-04-10  5:59 UTC (permalink / raw)
  To: gcc-help

>>   $ gcov tests/tests.cpp
>>   tests.gcno:cannot open graph file
>>
>> Which is correct, because the autotools name it as tests/tests-tests.gcno.
>> Likewise all the other .gcno files are in subdirectories with the directory
>> name prepended onto the filename.
> 
> http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Invoking-Gcov.html
> 
> Note the -o option.

I had a look at the -o option, but I'm not sure how to use it.  For example,
this is the only way I can get gcov to run:

  $ gcov tests/tests.cpp -o tests/tests-tests

But then it produces tests.cpp.gcov that contains a bunch of lines like this:

        -:    1:/*EOF*/
        -:    2:/*EOF*/
        -:    3:/*EOF*/
        -:    4:/*EOF*/
        -:    5:/*EOF*/
        -:    6:/*EOF*/
        -:    7:/*EOF*/
        -:    8:/*EOF*/

I'm also a bit confused about why I should supply a .cpp filename instead of a
program name.  How does it know which program to run?  If I run "gcov
string.cpp" how does gcov know that it needs to run some other program with
certain parameters to actually execute the code in that file?

Thanks,
Adam.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcov and autotools - filename issues
  2010-04-10  5:59   ` Adam Nielsen
@ 2010-04-10  6:10     ` Adam Nielsen
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Nielsen @ 2010-04-10  6:10 UTC (permalink / raw)
  To: gcc-help

Oh ok, my bad, now I've figured out how it should work.

> I had a look at the -o option, but I'm not sure how to use it.  For example,
> this is the only way I can get gcov to run:
> 
>   $ gcov tests/tests.cpp -o tests/tests-tests

You have to run gcov in the same directory as the .cpp file, otherwise it
gives an error message about being unable to find it (even with a path.)  This
works:

  $ cd tests; gcov tests.cpp -o tests-tests

Likewise for other files:

  $ cd tests; gcov blah.cpp -o tests-blah

> I'm also a bit confused about why I should supply a .cpp filename instead of a
> program name.  How does it know which program to run?  If I run "gcov
> string.cpp" how does gcov know that it needs to run some other program with
> certain parameters to actually execute the code in that file?

Now I also realise I'm supposed to run the program normally *first* to
generate the .gcda files, *then* gcov is used to convert them into
human-readable text files with the commands above.

Now it seems to work as advertised :-)

Cheers,
Adam.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-10  6:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-10  4:05 gcov and autotools - filename issues Adam Nielsen
2010-04-10  4:46 ` Ian Lance Taylor
2010-04-10  5:59   ` Adam Nielsen
2010-04-10  6:10     ` Adam Nielsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).