diff mbox

Support multiple files w/ -i option in gcov (PR gcov-profile/80224).

Message ID 23d3e712-5e56-e90e-e92b-2e1b21ee9fa9@suse.cz
State New
Headers show

Commit Message

Martin Liška March 28, 2017, 9:06 a.m. UTC
Hello.

The fix of the PR, where intermediate format is currently dumped in a bit different manner.
I believe it can share majority of file creation (and destruction) with normal format.
Apart from that I refined usage string from:

Usage: gcov [OPTION]... SOURCE|OBJ...

to:
Usage: gcov [OPTION...] SOURCE|OBJ...

Patch survives make check -k -j10 RUNTESTFLAGS="gcov.exp"

Ready for trunk?
Thanks,
Martin

Comments

Martin Liška April 6, 2017, 12:52 p.m. UTC | #1
PING^1

On 03/28/2017 11:06 AM, Martin Liška wrote:
> Hello.
> 
> The fix of the PR, where intermediate format is currently dumped in a bit different manner.
> I believe it can share majority of file creation (and destruction) with normal format.
> Apart from that I refined usage string from:
> 
> Usage: gcov [OPTION]... SOURCE|OBJ...
> 
> to:
> Usage: gcov [OPTION...] SOURCE|OBJ...
> 
> Patch survives make check -k -j10 RUNTESTFLAGS="gcov.exp"
> 
> Ready for trunk?
> Thanks,
> Martin
>
diff mbox

Patch

From 0d0c574ccf8fc832b5e1f2d6f77ca195a0eb7ea4 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 28 Mar 2017 10:57:38 +0200
Subject: [PATCH] Support multiple files w/ -i option in gcov (PR
 gcov-profile/80224).

gcc/ChangeLog:

2017-03-28  Martin Liska  <mliska@suse.cz>

	* gcov.c (print_usage): Fix usage string.
	(get_gcov_intermediate_filename): Remove.
	(output_gcov_file): Use both for normal and intermediate format.
	(generate_results): Do not initialize special file for
	intermediate format.
---
 gcc/gcov.c | 62 +++++++-------------------------------------------------------
 1 file changed, 7 insertions(+), 55 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 4198decdabc..05022a6a1ed 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -653,7 +653,7 @@  print_usage (int error_p)
   FILE *file = error_p ? stderr : stdout;
   int status = error_p ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
 
-  fnotice (file, "Usage: gcov [OPTION]... SOURCE|OBJ...\n\n");
+  fnotice (file, "Usage: gcov [OPTION...] SOURCE|OBJ...\n\n");
   fnotice (file, "Print code coverage information.\n\n");
   fnotice (file, "  -h, --help                      Print this help, then exit\n");
   fnotice (file, "  -a, --all-blocks                Show information for every basic block\n");
@@ -791,31 +791,6 @@  process_args (int argc, char **argv)
   return optind;
 }
 
-/* Get the name of the gcov file.  The return value must be free'd.
-
-   It appends the '.gcov' extension to the *basename* of the file.
-   The resulting file name will be in PWD.
-
-   e.g.,
-   input: foo.da,       output: foo.da.gcov
-   input: a/b/foo.cc,   output: foo.cc.gcov  */
-
-static char *
-get_gcov_intermediate_filename (const char *file_name)
-{
-  const char *gcov = ".gcov";
-  char *result;
-  const char *cptr;
-
-  /* Find the 'basename'.  */
-  cptr = lbasename (file_name);
-
-  result = XNEWVEC (char, strlen (cptr) + strlen (gcov) + 1);
-  sprintf (result, "%s%s", cptr, gcov);
-
-  return result;
-}
-
 /* Output the result in intermediate format used by 'lcov'.
 
 The intermediate format contains a single file named 'foo.cc.gcov',
@@ -980,7 +955,11 @@  output_gcov_file (const char *file_name, source_t *src)
       if (gcov_file)
         {
           fnotice (stdout, "Creating '%s'\n", gcov_file_name);
-          output_lines (gcov_file, src);
+
+	  if (flag_intermediate_format)
+	    output_intermediate_file (gcov_file, src);
+	  else
+	    output_lines (gcov_file, src);
           if (ferror (gcov_file))
             fnotice (stderr, "Error writing output file '%s'\n", gcov_file_name);
           fclose (gcov_file);
@@ -1002,8 +981,6 @@  generate_results (const char *file_name)
   unsigned ix;
   source_t *src;
   function_t *fn;
-  FILE *gcov_intermediate_file = NULL;
-  char *gcov_intermediate_filename = NULL;
 
   for (ix = n_sources, src = sources; ix--; src++)
     if (src->num_lines)
@@ -1033,19 +1010,6 @@  generate_results (const char *file_name)
 	file_name = canonicalize_name (file_name);
     }
 
-  if (flag_gcov_file && flag_intermediate_format)
-    {
-      /* Open the intermediate file.  */
-      gcov_intermediate_filename = get_gcov_intermediate_filename (file_name);
-      gcov_intermediate_file = fopen (gcov_intermediate_filename, "w");
-      if (!gcov_intermediate_file)
-	{
-	  fnotice (stderr, "Cannot open intermediate output file %s\n",
-		   gcov_intermediate_filename);
-	  return;
-	}
-    }
-
   for (ix = n_sources, src = sources; ix--; src++)
     {
       if (flag_relative_only)
@@ -1068,23 +1032,11 @@  generate_results (const char *file_name)
       total_executed += src->coverage.lines_executed;
       if (flag_gcov_file)
 	{
-          if (flag_intermediate_format)
-            /* Output the intermediate format without requiring source
-               files.  This outputs a section to a *single* file.  */
-            output_intermediate_file (gcov_intermediate_file, src);
-          else
-            output_gcov_file (file_name, src);
+	  output_gcov_file (file_name, src);
           fnotice (stdout, "\n");
         }
     }
 
-  if (flag_gcov_file && flag_intermediate_format)
-    {
-      /* Now we've finished writing the intermediate file.  */
-      fclose (gcov_intermediate_file);
-      XDELETEVEC (gcov_intermediate_filename);
-    }
-
   if (!file_name)
     executed_summary (total_lines, total_executed);
 }
-- 
2.12.0