aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2001-11-01 21:48:49 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2001-11-01 21:48:49 +0000
commit5735c3ea7861dcc2ada511c2ce6267a5567b00d7 (patch)
tree0f3412160a85317c31f372424279c4043baafa25
parent199898121e433bcade4a0829584238f1fd232ed7 (diff)
downloadgcc-5735c3ea7861dcc2ada511c2ce6267a5567b00d7.zip
gcc-5735c3ea7861dcc2ada511c2ce6267a5567b00d7.tar.gz
gcc-5735c3ea7861dcc2ada511c2ce6267a5567b00d7.tar.bz2
re PR other/704 (--help and --version)
* Makefile.in (GCOV_OBJS): Add version.o. * gcov.c: Include "version.h" and <getopt.h>. (gcov_version_string): Remove. (print_usage): Take a parameter to determine whether this is a call from --help or an error message. Give fuller output that follows the GNU Coding Standards for --help. (print_version): New function. (options): New. (process_args): Use getopt_long. Support long options. Follow GNU Coding Standards for --help and --version. * doc/gcov.texi: Document long options. Addresses part of PR other/704. From-SVN: r46703
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/doc/gcov.texi37
-rw-r--r--gcc/gcov.c117
4 files changed, 128 insertions, 43 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f6d781d..4078f33 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,18 @@
+2001-11-01 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * Makefile.in (GCOV_OBJS): Add version.o.
+ * gcov.c: Include "version.h" and <getopt.h>.
+ (gcov_version_string): Remove.
+ (print_usage): Take a parameter to determine whether this is a
+ call from --help or an error message. Give fuller output that
+ follows the GNU Coding Standards for --help.
+ (print_version): New function.
+ (options): New.
+ (process_args): Use getopt_long. Support long options. Follow
+ GNU Coding Standards for --help and --version.
+ * doc/gcov.texi: Document long options.
+ Addresses part of PR other/704.
+
2001-11-01 John David Anglin <dave@hiauly1.hia.nrc.ca>
* pa.c (output_move_double): Fix typo in double load.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b758510..e03803e 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2117,7 +2117,7 @@ gcov.o: gcov.c gcov-io.h intl.h $(SYSTEM_H) $(CONFIG_H)
# Only one of 'gcov' or 'gcov.exe' is actually built, depending
# upon whether $(exeext) is empty or not.
-GCOV_OBJS = gcov.o intl.o
+GCOV_OBJS = gcov.o intl.o version.o
gcov$(exeext): $(GCOV_OBJS) $(LIBDEPS)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) $(GCOV_OBJS) $(LIBS) -o $@
#
diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index a04a48f..c4e6e55 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -1,10 +1,10 @@
-@c Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+@c Copyright (C) 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.
@ignore
@c man begin COPYRIGHT
-Copyright @copyright{} 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+Copyright @copyright{} 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
@@ -32,8 +32,6 @@ English.
@command{gcov} is a tool you can use in conjunction with GCC to
test code coverage in your programs.
-This chapter describes version 1.5 of @command{gcov}.
-
@menu
* Gcov Intro:: Introduction to gcov.
* Invoking Gcov:: How to use gcov.
@@ -108,12 +106,18 @@ compatible with any other profiling or test coverage mechanism.
@section Invoking gcov
@smallexample
-gcov [-b] [-c] [-v] [-n] [-l] [-f] [-o directory] @var{sourcefile}
+gcov @r{[}@var{options}@r{]} @var{sourcefile}
@end smallexample
+@command{gcov} accepts the following options:
+
@ignore
@c man begin SYNOPSIS
-gcov [@option{-b}] [@option{-c}] [@option{-v}] [@option{-n}] [@option{-l}] [@option{-f}] [@option{-o} @var{directory}] @var{sourcefile}
+gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
+ [@option{-b}|@option{--branch-probabilities}] [@option{-c}|@option{--branch-counts}]
+ [@option{-n}|@option{--no-output}] [@option{-l}|@option{--long-file-names}]
+ [@option{-f}|@option{--function-summaries}]
+ [@option{-o}|@option{--object-directory} @var{directory}] @var{sourcefile}
@c man end
@c man begin SEEALSO
gcc(1) and the Info entry for @file{gcc}.
@@ -122,22 +126,33 @@ gcc(1) and the Info entry for @file{gcc}.
@c man begin OPTIONS
@table @gcctabopt
+@item -h
+@itemx --help
+Display help about using @command{gcov} (on the standard output), and
+exit without doing any further processing.
+
+@item -v
+@itemx --version
+Display the @command{gcov} version number (on the standard output),
+and exit without doing any further processing.
+
@item -b
+@itemx --branch-probabilities
Write branch frequencies to the output file, and write branch summary
info to the standard output. This option allows you to see how often
each branch in your program was taken.
@item -c
+@itemx --branch-counts
Write branch frequencies as the number of branches taken, rather than
the percentage of branches taken.
-@item -v
-Display the @command{gcov} version number (on the standard error stream).
-
@item -n
+@itemx --no-output
Do not create the @command{gcov} output file.
@item -l
+@itemx --long-file-names
Create long file names for included source files. For example, if the
header file @file{x.h} contains code, and was included in the file
@file{a.c}, then running @command{gcov} on the file @file{a.c} will produce
@@ -145,9 +160,11 @@ an output file called @file{a.c.x.h.gcov} instead of @file{x.h.gcov}.
This can be useful if @file{x.h} is included in multiple source files.
@item -f
+@itemx --function-summaries
Output summaries for each function in addition to the file level summary.
-@item -o
+@item -o @var{directory}
+@itemx --object-directory @var{directory}
The directory where the object files live. Gcov will search for @file{.bb},
@file{.bbg}, and @file{.da} files in this directory.
@end table
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 7386b01..aad22a8 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -46,8 +46,11 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "intl.h"
+#include "version.h"
#undef abort
+#include <getopt.h>
+
typedef HOST_WIDEST_INT gcov_type;
#include "gcov-io.h"
@@ -79,8 +82,6 @@ typedef HOST_WIDEST_INT gcov_type;
/* The functions in this file for creating and solution program flow graphs
are very similar to functions in the gcc source file profile.c. */
-static const char gcov_version_string[] = "GNU gcov version 1.5\n";
-
/* This is the size of the buffer used to read in source file lines. */
#define STRING_SIZE 200
@@ -227,7 +228,8 @@ static void open_files PARAMS ((void));
static void read_files PARAMS ((void));
static void scan_for_source_files PARAMS ((void));
static void output_data PARAMS ((void));
-static void print_usage PARAMS ((void)) ATTRIBUTE_NORETURN;
+static void print_usage PARAMS ((int)) ATTRIBUTE_NORETURN;
+static void print_version PARAMS ((void)) ATTRIBUTE_NORETURN;
static void init_arc PARAMS ((struct adj_list *, int, int, struct bb_info *));
static struct adj_list *reverse_arcs PARAMS ((struct adj_list *));
static void create_program_flow_graph PARAMS ((struct bb_info_list *));
@@ -281,15 +283,57 @@ fancy_abort ()
exit (FATAL_EXIT_CODE);
}
-/* Print a usage message and exit. */
+/* Print a usage message and exit. If ERROR_P is nonzero, this is an error,
+ otherwise the output of --help. */
static void
-print_usage ()
+print_usage (error_p)
+ int error_p;
{
- fnotice (stderr, "gcov [-b] [-v] [-n] [-l] [-f] [-o OBJDIR] file\n");
- exit (FATAL_EXIT_CODE);
+ FILE *file = error_p ? stderr : stdout;
+ int status = error_p ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
+ fnotice (file, "Usage: gcov [OPTION]... SOURCEFILE\n\n");
+ fnotice (file, "Print code coverage information.\n\n");
+ fnotice (file, " -h, --help Print this help, then exit\n");
+ fnotice (file, " -v, --version Print version number, then exit\n");
+ fnotice (file, " -b, --branch-probabilities Include branch probabilities in output\n");
+ fnotice (file, " -c, --branch-counts Given counts of branches taken\n\
+ rather than percentages\n");
+ fnotice (file, " -n, --no-output Do not create an output file\n");
+ fnotice (file, " -l, --long-file-names Use long output file names for included\n\
+ source files\n");
+ fnotice (file, " -f, --function-summaries Output summaries for each function\n");
+ fnotice (file, " -o, --object-directory OBJDIR Search for object files in OBJDIR\n");
+ fnotice (file, "\nFor bug reporting instructions, please see:\n%s.\n",
+ GCCBUGURL);
+ exit (status);
+}
+
+/* Print version information and exit. */
+
+static void
+print_version ()
+{
+ fnotice (stdout, "gcov (GCC) %s\n", version_string);
+ fnotice (stdout, "Copyright (C) 2001 Free Software Foundation, Inc.\n");
+ fnotice (stdout,
+ "This is free software; see the source for copying conditions. There is NO\n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
+ exit (SUCCESS_EXIT_CODE);
}
+static const struct option options[] =
+{
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'v' },
+ { "branch-probabilities", no_argument, NULL, 'b' },
+ { "branch-counts", no_argument, NULL, 'c' },
+ { "no-output", no_argument, NULL, 'n' },
+ { "long-file-names", no_argument, NULL, 'l' },
+ { "function-summaries", no_argument, NULL, 'f' },
+ { "object-directory", required_argument, NULL, 'o' }
+};
+
/* Parse the command line. */
static void
@@ -297,37 +341,46 @@ process_args (argc, argv)
int argc;
char **argv;
{
- int i;
+ int opt;
- for (i = 1; i < argc; i++)
+ while ((opt = getopt_long (argc, argv, "hvbclnfo:", options, NULL)) != -1)
{
- if (argv[i][0] == '-')
+ switch (opt)
{
- if (argv[i][1] == 'b')
- output_branch_probs = 1;
- else if (argv[i][1] == 'c')
- output_branch_counts = 1;
- else if (argv[i][1] == 'v')
- fputs (gcov_version_string, stderr);
- else if (argv[i][1] == 'n')
- output_gcov_file = 0;
- else if (argv[i][1] == 'l')
- output_long_names = 1;
- else if (argv[i][1] == 'f')
- output_function_summary = 1;
- else if (argv[i][1] == 'o' && argv[i][2] == '\0')
- object_directory = argv[++i];
- else
- print_usage ();
+ case 'h':
+ print_usage (false);
+ /* print_usage will exit. */
+ case 'v':
+ print_version ();
+ /* print_version will exit. */
+ case 'b':
+ output_branch_probs = 1;
+ break;
+ case 'c':
+ output_branch_counts = 1;
+ break;
+ case 'n':
+ output_gcov_file = 0;
+ break;
+ case 'l':
+ output_long_names = 1;
+ break;
+ case 'f':
+ output_function_summary = 1;
+ break;
+ case 'o':
+ object_directory = optarg;
+ break;
+ default:
+ print_usage (true);
+ /* print_usage will exit. */
}
- else if (! input_file_name)
- input_file_name = argv[i];
- else
- print_usage ();
}
- if (! input_file_name)
- print_usage ();
+ if (optind != argc - 1)
+ print_usage (true);
+
+ input_file_name = argv[optind];
}