public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] gcov: Runtime configurable destination output
@ 2016-02-24 21:52 Aaron Conole
  2016-04-15 19:02 ` Aaron Conole
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Aaron Conole @ 2016-02-24 21:52 UTC (permalink / raw)
  To: gcc-patches, Nathan Sidwell, Jan Hubicka, 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.
---
v2:
* Retitled subject
* Cleaned up whitespace in libgcov-driver-system.c diff
* Lazy error file opening
* non-static error file
* No warnings during compilation

 libgcc/libgcov-driver-system.c | 35 ++++++++++++++++++++++++++++++++++-
 libgcc/libgcov-driver.c        |  6 ++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c
index 4e3b244..0eb9755 100644
--- a/libgcc/libgcov-driver-system.c
+++ b/libgcc/libgcov-driver-system.c
@@ -23,6 +23,24 @@ 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/>.  */
 
+FILE *__gcov_error_file = NULL;
+
+static FILE *
+get_gcov_error_file(void)
+{
+  char *gcov_error_filename = getenv("GCOV_ERROR_FILE");
+  FILE *gcov_error_file = NULL;
+  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;
+}
+
 /* A utility function for outputing errors.  */
 
 static int __attribute__((format(printf, 1, 2)))
@@ -30,12 +48,27 @@ 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);
+    }
+}
+#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..83d84c5c 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -46,6 +46,10 @@ void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {}
 /* A utility function for outputing 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.0

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

end of thread, other threads:[~2016-06-06 15:25 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-24 21:52 [PATCH v2] gcov: Runtime configurable destination output Aaron Conole
2016-04-15 19:02 ` Aaron Conole
2016-04-27 20:59 ` Aaron Conole
2016-04-28 13:25   ` Nathan Sidwell
2016-04-29 15:08     ` Aaron Conole
2016-05-04 15:22       ` Nathan Sidwell
2016-05-04 15:25         ` Jan Hubicka
2016-05-06 13:18 ` Nathan Sidwell
2016-05-19 18:40   ` Aaron Conole
2016-05-19 19:25     ` Jeff Law
2016-05-19 23:14       ` Nathan Sidwell
2016-05-20  1:11         ` Jeff Law
2016-05-19 23:17     ` Nathan Sidwell
2016-05-23 18:16       ` Aaron Conole
2016-06-03 15:00         ` H.J. Lu
2016-06-03 15:31           ` Aaron Conole
2016-06-04 12:12           ` Aaron Conole
2016-06-06 15:25             ` 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).