public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v4] gcov: Runtime configurable destination output
@ 2016-05-26 19:25 Aaron Conole
  2016-05-28 13:12 ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: Aaron Conole @ 2016-05-26 19:25 UTC (permalink / raw)
  To: gcc-patches, Nathan Sidwell

The previous gcov behavior was to always output errors on the stderr channel.
This is fine for most uses, but some programs will require stderr to be
untouched by libgcov for certain tests. This change allows configuring
the gcov output via an environment variable which will be used to open
the appropriate file.
---
 libgcc/libgcov-driver-system.c | 49 ++++++++++++++++++++++++++++++++++++++++--
 libgcc/libgcov-driver.c        |  8 ++++++-
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c
index 4e3b244..ff8a521 100644
--- a/libgcc/libgcov-driver-system.c
+++ b/libgcc/libgcov-driver-system.c
@@ -23,19 +23,64 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
-/* A utility function for outputing errors.  */
+/* Configured via the GCOV_ERROR_FILE environment variable;
+   it will either be stderr, or a file of the user's choosing.
+   Non-static to prevent multiple gcov-aware shared objects from
+   instantiating their own copies. */
+FILE *__gcov_error_file = NULL;
+
+/* A utility function to populate the __gcov_error_file pointer.
+   This should NOT be called outside of the gcov system driver code. */
+
+static FILE *
+get_gcov_error_file(void)
+{
+#if !IN_GCOV_TOOL
+  return stderr;
+#else
+  char *gcov_error_filename = getenv ("GCOV_ERROR_FILE");
+
+  if (gcov_error_filename)
+    {
+      FILE *openfile = fopen (gcov_error_filename, "a");
+      if (openfile)
+        __gcov_error_file = openfile;
+    }
+  if (!__gcov_error_file)
+    __gcov_error_file = stderr;
+  return __gcov_error_file;
+#endif
+}
+
+/* A utility function for outputting errors.  */
 
 static int __attribute__((format(printf, 1, 2)))
 gcov_error (const char *fmt, ...)
 {
   int ret;
   va_list argp;
+
+  if (!__gcov_error_file)
+    __gcov_error_file = get_gcov_error_file ();
+
   va_start (argp, fmt);
-  ret = vfprintf (stderr, fmt, argp);
+  ret = vfprintf (__gcov_error_file, fmt, argp);
   va_end (argp);
   return ret;
 }
 
+#if !IN_GCOV_TOOL
+static void
+gcov_error_exit (void)
+{
+  if (__gcov_error_file && __gcov_error_file != stderr)
+    {
+      fclose (__gcov_error_file);
+      __gcov_error_file = NULL;
+    }
+}
+#endif
+
 /* Make sure path component of the given FILENAME exists, create
    missing directories. FILENAME must be writable.
    Returns zero on success, or -1 if an error occurred.  */
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 9c4eeca..d51397e 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -43,9 +43,13 @@ void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {}
 
 #ifdef L_gcov
 
-/* A utility function for outputing errors.  */
+/* A utility function for outputting errors.  */
 static int gcov_error (const char *, ...);
 
+#if !IN_GCOV_TOOL
+static void gcov_error_exit (void);
+#endif
+
 #include "gcov-io.c"
 
 struct gcov_fn_buffer
@@ -878,6 +882,8 @@ gcov_exit (void)
     __gcov_root.prev->next = __gcov_root.next;
   else
     __gcov_master.root = __gcov_root.next;
+
+  gcov_error_exit ();
 }
 
 /* Add a new object file onto the bb chain.  Invoked automatically
-- 
2.5.5

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

* Re: [PATCH v4] gcov: Runtime configurable destination output
  2016-05-26 19:25 [PATCH v4] gcov: Runtime configurable destination output Aaron Conole
@ 2016-05-28 13:12 ` Nathan Sidwell
  2016-05-31 16:00   ` Aaron Conole
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2016-05-28 13:12 UTC (permalink / raw)
  To: Aaron Conole, gcc-patches

On 05/26/16 13:08, Aaron Conole wrote:
> The previous gcov behavior was to always output errors on the stderr channel.
> This is fine for most uses, but some programs will require stderr to be
> untouched by libgcov for certain tests. This change allows configuring
> the gcov output via an environment variable which will be used to open
> the appropriate file.

this is ok, thanks.

1) Do you know how to write and format a ChangeLog entry?
2) Are you able to commit the patch yourself (or have someone at RH walk you 
through the process)

nathan

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

* Re: [PATCH v4] gcov: Runtime configurable destination output
  2016-05-28 13:12 ` Nathan Sidwell
@ 2016-05-31 16:00   ` Aaron Conole
  2016-06-02 12:24     ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: Aaron Conole @ 2016-05-31 16:00 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: gcc-patches

Nathan Sidwell <nathan@acm.org> writes:

> On 05/26/16 13:08, Aaron Conole wrote:
>> The previous gcov behavior was to always output errors on the stderr channel.
>> This is fine for most uses, but some programs will require stderr to be
>> untouched by libgcov for certain tests. This change allows configuring
>> the gcov output via an environment variable which will be used to open
>> the appropriate file.
>
> this is ok, thanks.
>
> 1) Do you know how to write and format a ChangeLog entry?

I can copy the style used, I hope.

> 2) Are you able to commit the patch yourself (or have someone at RH
> walk you through the process)

I don't know how to do this for gcc, but I will ask.

Thanks for your all your time!

-Aaron

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

* Re: [PATCH v4] gcov: Runtime configurable destination output
  2016-05-31 16:00   ` Aaron Conole
@ 2016-06-02 12:24     ` Nathan Sidwell
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2016-06-02 12:24 UTC (permalink / raw)
  To: Aaron Conole; +Cc: gcc-patches

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

On 05/31/16 11:04, Aaron Conole wrote:
> Nathan Sidwell <nathan@acm.org> writes:
>
>> On 05/26/16 13:08, Aaron Conole wrote:
>>> The previous gcov behavior was to always output errors on the stderr channel.
>>> This is fine for most uses, but some programs will require stderr to be
>>> untouched by libgcov for certain tests. This change allows configuring
>>> the gcov output via an environment variable which will be used to open
>>> the appropriate file.
>>
>> this is ok, thanks.


After offlist discussion, I committed this patch.  Thanks Aaron!


nathan


[-- Attachment #2: gcov.patch --]
[-- Type: text/x-patch, Size: 3013 bytes --]

2016-06-02  Aaron Conole  <aconole@redhat.com>

	* libgcov-driver-system.c (__gcov_error_file): New.
	(get_gcov_error_file): New.
	(gcov_error): Use and set __gcov_error_file.
	(gcov_error_exit): New.
	* libgcov-driver.c (gcov_exit): Call gcov_error_exit.

Index: libgcov-driver-system.c
===================================================================
--- libgcov-driver-system.c	(revision 237032)
+++ libgcov-driver-system.c	(working copy)
@@ -23,19 +23,64 @@ a copy of the GCC Runtime Library Except
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
-/* A utility function for outputing errors.  */
+/* Configured via the GCOV_ERROR_FILE environment variable;
+   it will either be stderr, or a file of the user's choosing.
+   Non-static to prevent multiple gcov-aware shared objects from
+   instantiating their own copies. */
+FILE *__gcov_error_file = NULL;
+
+/* A utility function to populate the __gcov_error_file pointer.
+   This should NOT be called outside of the gcov system driver code. */
+
+static FILE *
+get_gcov_error_file(void)
+{
+#if !IN_GCOV_TOOL
+  return stderr;
+#else
+  char *gcov_error_filename = getenv ("GCOV_ERROR_FILE");
+
+  if (gcov_error_filename)
+    {
+      FILE *openfile = fopen (gcov_error_filename, "a");
+      if (openfile)
+        __gcov_error_file = openfile;
+    }
+  if (!__gcov_error_file)
+    __gcov_error_file = stderr;
+  return __gcov_error_file;
+#endif
+}
+
+/* A utility function for outputting errors.  */
 
 static int __attribute__((format(printf, 1, 2)))
 gcov_error (const char *fmt, ...)
 {
   int ret;
   va_list argp;
+
+  if (!__gcov_error_file)
+    __gcov_error_file = get_gcov_error_file ();
+
   va_start (argp, fmt);
-  ret = vfprintf (stderr, fmt, argp);
+  ret = vfprintf (__gcov_error_file, fmt, argp);
   va_end (argp);
   return ret;
 }
 
+#if !IN_GCOV_TOOL
+static void
+gcov_error_exit (void)
+{
+  if (__gcov_error_file && __gcov_error_file != stderr)
+    {
+      fclose (__gcov_error_file);
+      __gcov_error_file = NULL;
+    }
+}
+#endif
+
 /* Make sure path component of the given FILENAME exists, create
    missing directories. FILENAME must be writable.
    Returns zero on success, or -1 if an error occurred.  */
Index: libgcov-driver.c
===================================================================
--- libgcov-driver.c	(revision 237032)
+++ libgcov-driver.c	(working copy)
@@ -43,9 +43,13 @@ void __gcov_init (struct gcov_info *p __
 
 #ifdef L_gcov
 
-/* A utility function for outputing errors.  */
+/* A utility function for outputting errors.  */
 static int gcov_error (const char *, ...);
 
+#if !IN_GCOV_TOOL
+static void gcov_error_exit (void);
+#endif
+
 #include "gcov-io.c"
 
 struct gcov_fn_buffer
@@ -878,6 +882,8 @@ gcov_exit (void)
     __gcov_root.prev->next = __gcov_root.next;
   else
     __gcov_master.root = __gcov_root.next;
+
+  gcov_error_exit ();
 }
 
 /* Add a new object file onto the bb chain.  Invoked automatically

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

end of thread, other threads:[~2016-06-02 12:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-26 19:25 [PATCH v4] gcov: Runtime configurable destination output Aaron Conole
2016-05-28 13:12 ` Nathan Sidwell
2016-05-31 16:00   ` Aaron Conole
2016-06-02 12:24     ` Nathan Sidwell

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