From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74242 invoked by alias); 22 Feb 2016 17:03:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 74206 invoked by uid 89); 22 Feb 2016 17:03:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=31,11, 3111, 878,6, 8786 X-HELO: mail-qk0-f169.google.com Received: from mail-qk0-f169.google.com (HELO mail-qk0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 22 Feb 2016 17:03:45 +0000 Received: by mail-qk0-f169.google.com with SMTP id x1so57991417qkc.1 for ; Mon, 22 Feb 2016 09:03:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ujzJQI6X0eZHPnvjakJcU0faceJN+XjcajGr4KQIXJk=; b=GhonAkrf9e8kt4SKRTc9ggr6D0m//1juAYW0G+JTTkqx//gtMmRIqNkjZ67gCTlOYn FkhRPSCA1WAp/NZI1zJLAZYE8+6mphUMWsDQ3t1g0+nPBYNyiJCSpbXRadOZTIj3Beb6 vMuiEOJKos7KIWAKAM4o3OCkq1dGydfZVoigzvMwLa8QQZKJeRJpdWh1esux08Nny8Jd R3I/7Ykd2m7Ia4ifx78C5vEuLw1G9hqAg31ZYXlx5gDW6jb/+asgF1rvvHgq8ZpL9Xvz O9hJE2yt4Lt8H3P8+6KOWTi8mSpSfi0HOv61bZY+AUqRymyhziN+EsDm+kvSJCOtqAPA KoKQ== X-Gm-Message-State: AG10YORljFlegvrp4I+iMeBLUJHyO2EGnoDwI+Ei++4Px0gbz+18/zvbrsPE6YOYjTfZLQ== X-Received: by 10.55.75.144 with SMTP id y138mr35947727qka.96.1456160623110; Mon, 22 Feb 2016 09:03:43 -0800 (PST) Received: from trashheap.supergoodfun.com (c-50-157-177-198.hsd1.ma.comcast.net. [50.157.177.198]) by smtp.gmail.com with ESMTPSA id 200sm10533162qhm.47.2016.02.22.09.03.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 09:03:42 -0800 (PST) From: Aaron Conole To: gcc-patches@gcc.gnu.org, Jan Hubicka , Nathan Sidwell Cc: Aaron Conole Subject: [PATCH] gcov: Configurable destination for error output Date: Mon, 22 Feb 2016 17:03:00 -0000 Message-Id: <1456160612-25123-1-git-send-email-aconole@bytheb.org> X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg01487.txt.bz2 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 silent for certain tests. This change allows configuring the gcov output by an environment variable which will be used to open the appropriate file. --- v0: Note, I do not have a signed FSF agreement at present. I do work at Red Hat, but gcc is not my primary role. If this change requires paperwork, I can sign and return asap. libgcc/libgcov-driver-system.c | 28 +++++++++++++++++++++++++++- libgcc/libgcov-driver.c | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 4e3b244..09bb167 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -23,6 +23,8 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +static FILE *gcov_error_file; + /* A utility function for outputing errors. */ static int __attribute__((format(printf, 1, 2))) @@ -31,11 +33,35 @@ gcov_error (const char *fmt, ...) int ret; va_list argp; va_start (argp, fmt); - ret = vfprintf (stderr, fmt, argp); + ret = vfprintf (gcov_error_file, fmt, argp); va_end (argp); return ret; } +static void +gcov_error_exit(void) +{ + if (gcov_error_file != stderr) + { + fclose(gcov_error_file); + } +} + +static void +gcov_error_init(void) +{ + char *gcov_error_filename = getenv("GCOV_ERROR_FILE"); + gcov_error_file = NULL; + if (gcov_error_filename) + { + FILE *openfile = fopen(gcov_error_filename, "w"); + if (openfile) + gcov_error_file = openfile; + } + if (!gcov_error_file) + gcov_error_file = stderr; +} + /* 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..082755a 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -45,6 +45,8 @@ void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {} /* A utility function for outputing errors. */ static int gcov_error (const char *, ...); +static void gcov_error_init(void); +static void gcov_error_exit(void); #include "gcov-io.c" @@ -878,6 +880,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 @@ -900,6 +904,7 @@ __gcov_init (struct gcov_info *info) __gcov_master.root->prev = &__gcov_root; __gcov_master.root = &__gcov_root; } + gcov_error_init(); atexit (gcov_exit); } -- 2.5.0