PATCH: implement --coverage option

Ben Elliston bje@au1.ibm.com
Wed Mar 2 05:03:00 GMT 2005


Several times, users have complained to me that the coverage options are obtuse and
hard to remember (therefore they don't use them).  This patch adds a --coverage
option to the compiler driver to make it easier to use.

I've made a start at implementing a driver options testsuite, too, that ensures that
options are passed to the compiler, assembler and linker as we expect.  Okay for
mainline?


2005-03-01  Ben Elliston  <bje@au.ibm.com>

         * gcc.c (option_map): Add --coverage.
         (LINK_COMMAND_SPEC): Pass -lgcov for `coverage'.
         (cc1_options): Pass -fprofile-arcs -ftest-coverage for `coverage'.
         * doc/invoke.texi (Debugging Options): Document --coverage.

Index: gcc.c
===================================================================
RCS file: /home/bje/gcc-cvs/gcc/gcc/gcc.c,v
retrieving revision 1.448
diff -u -r1.448 gcc.c
--- gcc.c       23 Feb 2005 23:11:06 -0000      1.448
+++ gcc.c       2 Mar 2005 04:55:10 -0000
@@ -700,7 +700,7 @@
      %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
      %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
      %{static:} %{L*} %(mfwrap) %(link_libgcc) %o %(mflib)\
-    %{fprofile-arcs|fprofile-generate:-lgcov}\
+    %{fprofile-arcs|fprofile-generate|coverage:-lgcov}\
      %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
      %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
  #endif
@@ -796,7 +796,8 @@
   %{--target-help:--target-help}\
   %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
   %{fsyntax-only:-o %j} %{-param*}\
- %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}";
+ %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\
+ %{coverage:-fprofile-arcs -ftest-coverage}";

  static const char *asm_options =
  "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
@@ -1065,6 +1066,7 @@
     {"--for-assembler", "-Wa", "a"},
     {"--for-linker", "-Xlinker", "a"},
     {"--force-link", "-u", "a"},
+   {"--coverage", "-coverage", 0},
     {"--imacros", "-imacros", "a"},
     {"--include", "-include", "a"},
     {"--include-barrier", "-I-", 0},
Index: doc/invoke.texi
===================================================================
RCS file: /home/bje/gcc-cvs/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.584
diff -u -r1.584 invoke.texi
--- doc/invoke.texi     1 Mar 2005 17:59:06 -0000       1.584
+++ doc/invoke.texi     2 Mar 2005 04:55:11 -0000
@@ -3345,6 +3345,15 @@
  (e.g.@: @file{foo.gcda} for input file @file{dir/foo.c}, or
  @file{dir/foo.gcda} for output file specified as @option{-o dir/foo.o}).

+@cindex @command{gcov}
+@item --coverage
+@opindex coverage
+
+This option is used to compile and link code instrumented for coverage
+analysis.  The option is a synonym for @option{-fprofile-arcs}
+@option{-ftest-coverage} (when compiling) and @option{-lgcov} (when
+linking).  See the documentation for those options for more details.
+
  @itemize

  @item
Index: testsuite/gcc.misc-tests/options.exp
===================================================================
RCS file: testsuite/gcc.misc-tests/options.exp
diff -N testsuite/gcc.misc-tests/options.exp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.misc-tests/options.exp        2 Mar 2005 04:55:11 -0000
@@ -0,0 +1,39 @@
+# Copyright (C) 2005 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Run the compiler with GCC_OPTIONS and inspect the cc1 and ld option
+# output (from gcc -v) to make sure that they match the patterns
+# CC1_PATERN and LD_PATTERN, respectively.
+#
+# This really ought to be generalised to other languages.
+
+proc check_for_options {gcc_options cc1_pattern ld_pattern} {
+    set test "compiler driver $gcc_options option(s)"
+    set gcc_options "\{additional_flags=$gcc_options -v\}"
+
+    # FIXME: avoid using -x c here to make gcc happy about compiling /dev/null
+    set gcc_output [gcc_target_compile {-x c /dev/null} options.x executable
$gcc_options]
+    remote_file build delete options.x
+
+    if {[regexp -- "/cc1 -quiet.*$cc1_pattern" $gcc_output] \
+           && [regexp -- "/collect2 .*$ld_pattern" $gcc_output]} {
+       pass $test
+    } else {
+       fail $test
+    }
+}
+
+check_for_options {--coverage} {-fprofile-arcs -ftest-coverage} {-lgcov}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050302/cde2f2a5/attachment.sig>


More information about the Gcc-patches mailing list