public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Print working directory to gcov files (PR gcov-profile/84846).
@ 2018-05-18 12:29 Martin Liška
  2018-05-18 12:42 ` Martin Liška
  2018-05-21 20:18 ` Eric Botcazou
  0 siblings, 2 replies; 6+ messages in thread
From: Martin Liška @ 2018-05-18 12:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathan Sidwell, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

Hi.

Simple format extension which prints working directory of TU when it was compiled.
It's requested by LCOV folks.

Survives make check -k -j10 RUNTESTFLAGS="gcov.exp"

Ready for trunk?
Thanks,
Martin

gcc/ChangeLog:

2018-05-18  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/84846
	* coverage.c (coverage_init): Write PWD to .gcno file.
	* doc/gcov.texi: Document how working directory is printed.
	* gcov-dump.c (dump_gcov_file): Print PWD.
	* gcov.c (output_intermediate_file): Likewise.
	(read_graph_file): Read PWD string.
	(output_lines): Print PWD.
---
 gcc/coverage.c    | 1 +
 gcc/doc/gcov.texi | 5 +++++
 gcc/gcov-dump.c   | 2 ++
 gcc/gcov.c        | 7 +++++++
 4 files changed, 15 insertions(+)



[-- Attachment #2: 0001-Print-working-directory-to-gcov-files-PR-gcov-profil.patch --]
[-- Type: text/x-patch, Size: 3805 bytes --]

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 32ef298a11f..9e0185acd09 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -1269,6 +1269,7 @@ coverage_init (const char *filename)
 	  gcov_write_unsigned (GCOV_NOTE_MAGIC);
 	  gcov_write_unsigned (GCOV_VERSION);
 	  gcov_write_unsigned (bbg_file_stamp);
+	  gcov_write_string (getpwd ());
 
 	  /* Do not support has_unexecuted_blocks for Ada.  */
 	  gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);
diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 59235876aaa..9d5cdbc8e03 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -189,6 +189,7 @@ one entry per line
 
 @smallexample
 version:@var{gcc_version}
+pwd:@var{working_directory}
 file:@var{source_file_name}
 function:@var{start_line_number},@var{end_line_number},@var{execution_count},@var{function_name}
 lcount:@var{line number},@var{execution_count},@var{has_unexecuted_block}
@@ -210,6 +211,7 @@ Here is a sample when @option{-i} is used in conjunction with @option{-b} option
 
 @smallexample
 version: 8.1.0 20180103
+pwd:/home/gcc/testcase
 file:tmp.cpp
 function:7,7,0,_ZN3FooIcEC2Ev
 function:7,7,1,_ZN3FooIiEC2Ev
@@ -441,6 +443,7 @@ Here is a sample:
 
 @smallexample
         -:    0:Source:tmp.cpp
+        -:    0:Working directory:/home/gcc/testcase
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
@@ -508,6 +511,7 @@ counts, and the output looks like this:
 
 @smallexample
         -:    0:Source:tmp.cpp
+        -:    0:Working directory:/home/gcc/testcase
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
@@ -596,6 +600,7 @@ When you use the @option{-b} option, your output looks like this:
 
 @smallexample
         -:    0:Source:tmp.cpp
+        -:    0:Working directory:/home/gcc/testcase
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
diff --git a/gcc/gcov-dump.c b/gcc/gcov-dump.c
index ba432db51c7..210e9e46c2e 100644
--- a/gcc/gcov-dump.c
+++ b/gcc/gcov-dump.c
@@ -220,6 +220,8 @@ dump_gcov_file (const char *filename)
 
   if (!is_data_type)
     {
+      printf ("%s:pwd: %s\n", filename, gcov_read_string ());
+
       /* Support for unexecuted basic blocks.  */
       unsigned support_unexecuted_blocks = gcov_read_unsigned ();
       if (!support_unexecuted_blocks)
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 6bbfe33ca33..92972e29b4d 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -432,6 +432,9 @@ static unsigned bbg_stamp;
 /* Supports has_unexecuted_blocks functionality.  */
 static unsigned bbg_supports_has_unexecuted_blocks;
 
+/* Working directory in which a TU was compiled.  */
+static const char *bbg_pwd;
+
 /* Name and file pointer of the input file for the count data (gcda).  */
 
 static char *da_file_name;
@@ -1037,6 +1040,7 @@ output_intermediate_file (FILE *gcov_file, source_info *src)
 {
   fprintf (gcov_file, "version:%s\n", version_string);
   fprintf (gcov_file, "file:%s\n", src->name);    /* source file name */
+  fprintf (gcov_file, "pwd:%s\n", bbg_pwd);
 
   std::sort (src->functions.begin (), src->functions.end (),
 	     function_line_start_cmp ());
@@ -1550,6 +1554,7 @@ read_graph_file (void)
 	       bbg_file_name, v, e);
     }
   bbg_stamp = gcov_read_unsigned ();
+  bbg_pwd = xstrdup (gcov_read_string ());
   bbg_supports_has_unexecuted_blocks = gcov_read_unsigned ();
 
   function_info *fn = NULL;
@@ -2918,6 +2923,8 @@ output_lines (FILE *gcov_file, const source_info *src)
   const char *retval;
 
   fprintf (gcov_file, DEFAULT_LINE_START "Source:%s\n", src->coverage.name);
+  fprintf (gcov_file, DEFAULT_LINE_START "Working directory:%s\n",
+	   bbg_pwd);
   if (!multiple_files)
     {
       fprintf (gcov_file, DEFAULT_LINE_START "Graph:%s\n", bbg_file_name);


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

* Re: [PATCH] Print working directory to gcov files (PR gcov-profile/84846).
  2018-05-18 12:29 [PATCH] Print working directory to gcov files (PR gcov-profile/84846) Martin Liška
@ 2018-05-18 12:42 ` Martin Liška
  2018-05-18 12:46   ` Nathan Sidwell
  2018-05-21 20:18 ` Eric Botcazou
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Liška @ 2018-05-18 12:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathan Sidwell, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 59 bytes --]

V2: pwd is renamed to cwd, which is a better name.

Martin

[-- Attachment #2: 0001-Print-working-directory-to-gcov-files-PR-gcov-profil.patch --]
[-- Type: text/x-patch, Size: 4545 bytes --]

From a42365bc6987fc13d3a3cd4b98d7d64d94f7f318 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 18 May 2018 13:58:58 +0200
Subject: [PATCH] Print working directory to gcov files (PR
 gcov-profile/84846).

gcc/ChangeLog:

2018-05-18  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/84846
	* coverage.c (coverage_init): Write PWD to .gcno file.
	* doc/gcov.texi: Document how working directory is printed.
	* gcov-dump.c (dump_gcov_file): Print PWD.
	* gcov.c (output_intermediate_file): Likewise.
	(read_graph_file): Read PWD string.
	(output_lines): Print PWD.
---
 gcc/coverage.c    | 1 +
 gcc/doc/gcov.texi | 5 +++++
 gcc/gcov-dump.c   | 2 ++
 gcc/gcov.c        | 7 +++++++
 4 files changed, 15 insertions(+)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 32ef298a11f..9e0185acd09 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -1269,6 +1269,7 @@ coverage_init (const char *filename)
 	  gcov_write_unsigned (GCOV_NOTE_MAGIC);
 	  gcov_write_unsigned (GCOV_VERSION);
 	  gcov_write_unsigned (bbg_file_stamp);
+	  gcov_write_string (getpwd ());
 
 	  /* Do not support has_unexecuted_blocks for Ada.  */
 	  gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);
diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 59235876aaa..54625ce67cb 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -189,6 +189,7 @@ one entry per line
 
 @smallexample
 version:@var{gcc_version}
+cwd:@var{working_directory}
 file:@var{source_file_name}
 function:@var{start_line_number},@var{end_line_number},@var{execution_count},@var{function_name}
 lcount:@var{line number},@var{execution_count},@var{has_unexecuted_block}
@@ -210,6 +211,7 @@ Here is a sample when @option{-i} is used in conjunction with @option{-b} option
 
 @smallexample
 version: 8.1.0 20180103
+cwd:/home/gcc/testcase
 file:tmp.cpp
 function:7,7,0,_ZN3FooIcEC2Ev
 function:7,7,1,_ZN3FooIiEC2Ev
@@ -441,6 +443,7 @@ Here is a sample:
 
 @smallexample
         -:    0:Source:tmp.cpp
+        -:    0:Working directory:/home/gcc/testcase
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
@@ -508,6 +511,7 @@ counts, and the output looks like this:
 
 @smallexample
         -:    0:Source:tmp.cpp
+        -:    0:Working directory:/home/gcc/testcase
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
@@ -596,6 +600,7 @@ When you use the @option{-b} option, your output looks like this:
 
 @smallexample
         -:    0:Source:tmp.cpp
+        -:    0:Working directory:/home/gcc/testcase
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
diff --git a/gcc/gcov-dump.c b/gcc/gcov-dump.c
index ba432db51c7..0ae7e944483 100644
--- a/gcc/gcov-dump.c
+++ b/gcc/gcov-dump.c
@@ -220,6 +220,8 @@ dump_gcov_file (const char *filename)
 
   if (!is_data_type)
     {
+      printf ("%s:cwd: %s\n", filename, gcov_read_string ());
+
       /* Support for unexecuted basic blocks.  */
       unsigned support_unexecuted_blocks = gcov_read_unsigned ();
       if (!support_unexecuted_blocks)
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 6bbfe33ca33..8ed6e0d4d3f 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -432,6 +432,9 @@ static unsigned bbg_stamp;
 /* Supports has_unexecuted_blocks functionality.  */
 static unsigned bbg_supports_has_unexecuted_blocks;
 
+/* Working directory in which a TU was compiled.  */
+static const char *bbg_cwd;
+
 /* Name and file pointer of the input file for the count data (gcda).  */
 
 static char *da_file_name;
@@ -1037,6 +1040,7 @@ output_intermediate_file (FILE *gcov_file, source_info *src)
 {
   fprintf (gcov_file, "version:%s\n", version_string);
   fprintf (gcov_file, "file:%s\n", src->name);    /* source file name */
+  fprintf (gcov_file, "cwd:%s\n", bbg_cwd);
 
   std::sort (src->functions.begin (), src->functions.end (),
 	     function_line_start_cmp ());
@@ -1550,6 +1554,7 @@ read_graph_file (void)
 	       bbg_file_name, v, e);
     }
   bbg_stamp = gcov_read_unsigned ();
+  bbg_cwd = xstrdup (gcov_read_string ());
   bbg_supports_has_unexecuted_blocks = gcov_read_unsigned ();
 
   function_info *fn = NULL;
@@ -2918,6 +2923,8 @@ output_lines (FILE *gcov_file, const source_info *src)
   const char *retval;
 
   fprintf (gcov_file, DEFAULT_LINE_START "Source:%s\n", src->coverage.name);
+  fprintf (gcov_file, DEFAULT_LINE_START "Working directory:%s\n",
+	   bbg_cwd);
   if (!multiple_files)
     {
       fprintf (gcov_file, DEFAULT_LINE_START "Graph:%s\n", bbg_file_name);
-- 
2.16.3


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

* Re: [PATCH] Print working directory to gcov files (PR gcov-profile/84846).
  2018-05-18 12:42 ` Martin Liška
@ 2018-05-18 12:46   ` Nathan Sidwell
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Sidwell @ 2018-05-18 12:46 UTC (permalink / raw)
  To: Martin Liška, gcc-patches; +Cc: Jan Hubicka

On 05/18/2018 08:42 AM, Martin Liška wrote:
> V2: pwd is renamed to cwd, which is a better name.
> 
> Martin
> 

ok thanks.

nathan

-- 
Nathan Sidwell

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

* Re: [PATCH] Print working directory to gcov files (PR gcov-profile/84846).
  2018-05-18 12:29 [PATCH] Print working directory to gcov files (PR gcov-profile/84846) Martin Liška
  2018-05-18 12:42 ` Martin Liška
@ 2018-05-21 20:18 ` Eric Botcazou
  2018-05-22  8:59   ` Martin Liška
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Botcazou @ 2018-05-21 20:18 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches, Nathan Sidwell, Jan Hubicka

> Simple format extension which prints working directory of TU when it was
> compiled. It's requested by LCOV folks.

Can we make that optional, please?  Having the coverage results depends on the 
current working directory is quite annoying, to say the least.

-- 
Eric Botcazou

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

* Re: [PATCH] Print working directory to gcov files (PR gcov-profile/84846).
  2018-05-21 20:18 ` Eric Botcazou
@ 2018-05-22  8:59   ` Martin Liška
  2018-05-22 21:37     ` Eric Botcazou
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Liška @ 2018-05-22  8:59 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches, Nathan Sidwell, Jan Hubicka

On 05/21/2018 10:17 PM, Eric Botcazou wrote:
>> Simple format extension which prints working directory of TU when it was
>> compiled. It's requested by LCOV folks.
> 
> Can we make that optional, please?  Having the coverage results depends on the 
> current working directory is quite annoying, to say the least.
> 

Hi Eric.

How do you mean that? Why would be that dependent?

Martin

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

* Re: [PATCH] Print working directory to gcov files (PR gcov-profile/84846).
  2018-05-22  8:59   ` Martin Liška
@ 2018-05-22 21:37     ` Eric Botcazou
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Botcazou @ 2018-05-22 21:37 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches, Nathan Sidwell, Jan Hubicka

> How do you mean that? Why would be that dependent?

I don't really understand the question...  The coverage result contains the 
working directory where the program was run so by definition it depends on the 
working directory.  Put it differently, run the same program in 2 different 
directories and compare the .gcov files, they are now different, which is a 
very effective way of breaking automatic coverage testing.

-- 
Eric Botcazou

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

end of thread, other threads:[~2018-05-22 21:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 12:29 [PATCH] Print working directory to gcov files (PR gcov-profile/84846) Martin Liška
2018-05-18 12:42 ` Martin Liška
2018-05-18 12:46   ` Nathan Sidwell
2018-05-21 20:18 ` Eric Botcazou
2018-05-22  8:59   ` Martin Liška
2018-05-22 21:37     ` Eric Botcazou

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).