LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2011, 01:56 PM   #1
jasper77
LQ Newbie
 
Registered: Aug 2010
Location: Massachusetts
Posts: 29

Rep: Reputation: 0
Running gcov when executable has command line input options


I have an executable with input options, like so:
Code:
./executable -n 42 -s 42
I've added gcov to the makefiles (compiling with --coverage, -fprofile-arcs, and -ftest-coverage, and linking with -lgcov). It builds fine and creates executable.gcno.

When I try to run gcov, gcov things the options belong to it:
Code:
$ gcov ./executable -n 42 -s 42
gcov: invalid option -- 's'
Usage: gcov [OPTION]... SOURCEFILE...
When I use quotes this happens:
Code:
$ gcov './executable -n 42 -s 42'
executable -n 42 -s 42.gcno:cannot open graph file
The command line options must remain. How can I get gcov to generate the same .gcno file it later looks for?
 
Old 03-03-2011, 02:08 PM   #2
jasper77
LQ Newbie
 
Registered: Aug 2010
Location: Massachusetts
Posts: 29

Original Poster
Rep: Reputation: 0
Answering my own question... almost...

Explicitly tell gcov the name of the object file with a flag as follows. But then this happens:
Code:
$ gcov --object-file executable './executable -n 42 -s 42'
executable.gcda:cannot open data file, assuming not executed
... and then I get a bunch of output telling me 0.00% of lines in each file were executed.
When I list the directory, there are no .gcda files.
 
Old 03-03-2011, 04:55 PM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
It's been years since I have used gcov, but I believe you are almost correct with your approach. The only issue you are missing is producing the results.

So first, compile/link your program as you have been doing. Then second, run your program with the command-line args. Then finally, run gcov against the executable.gcda file.

For example:
Code:
gcc --coverage -fprofile-arcs -ftest-coverage MySource.c -o executable -lgcov   # Step 1

./executable -n 42 -s 42   # Step 2

gcov executable.gcda   # Step 3
You should then have one or more .gcov files that you can examine. The one that will probably interest you the most is the one named MySource.c.gcov.

If you want your executable to run a different path, then re-run it (step 2), and then re-run step 3. Then re-examine the .gcov file(s).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GCOV : Produces empty .c.gcov files techtalk Programming 8 02-16-2011 07:47 PM
[SOLVED] command line options mickymanymoons Linux - Newbie 1 01-06-2011 01:22 PM
[SOLVED] Options for running - Executable text files ljm Linux - Newbie 4 08-05-2010 05:46 PM
Command Line Options AUSanders79 Linux - Software 8 03-10-2005 10:24 AM
Command Line Options in C++ crichards Programming 5 03-08-2003 03:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration