From patchwork Thu Jun 2 12:23:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 629219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rL5xs2rQJz9t6C for ; Thu, 2 Jun 2016 22:24:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=m2NHAsKF; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=q7tt3EM3dr8sZ+EtC HNjWg2a6qPi9pGKtv6ZX1xEhG/qJ0XlN8u/ttsVVBZLqhjZ+YGgn2MFEQA80VhRy fXrdmGvDbjTVRPpbEd5d6UUmq9ItDZ2PcDYAjD5CIvzwo3/1rEpqVK/14b0eQusX 4kB4sCLevqwo+HB+cI8NA3OiFE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=T2EYJIy2g8rVFB8rAsoSC9p uCg4=; b=m2NHAsKFf3nbqPCf6yIIgrGDYNoYdNlJeEqWBLJu0wBaSbtpWM/7U3b EwInkAv9DSuT07MamG5VMvypqP6cffWjGZyZ4Y2CKlbJW7tilKl30CZfc7FCzoox 6taqqcK1MYq+5k3LbVaLXBsm4v+Y7NfKwRZ0uRsfY5DbZivSH6i8= Received: (qmail 85193 invoked by alias); 2 Jun 2016 12:24:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85182 invoked by uid 89); 2 Jun 2016 12:24:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=23, 19, 2319, UD:RUNTIME, copyingruntime X-HELO: mail-qk0-f170.google.com Received: from mail-qk0-f170.google.com (HELO mail-qk0-f170.google.com) (209.85.220.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 02 Jun 2016 12:23:57 +0000 Received: by mail-qk0-f170.google.com with SMTP id i187so30944178qkd.3 for ; Thu, 02 Jun 2016 05:23:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=ouuVF8K/dTWEGVG+wnWorbDhomJEaJ9cmImDgGPGxs8=; b=FnMbyc/neDywbW4Lt0UBqBf8wTFiXGEDg2u54nMpgshrs2y1vVdYGS2ZYvlZQZaHV7 djCohQFM3Q77g0KjKxFIdMM5t+Pc6Y6PUG5aUqLKIJr2IFwTkrsbkMfj4FOi0IRAoZrE dhBZbbt0XInHXGofhRkfvprmes1XJXhcaApYeYX8FxrB1jLU/T94H8aYNEn2QPNxZsbn NuQ2dsPXUHcvaYBS+tPSPHUNoaDgXyxi/3HQPOanvfJoFWG47gYgngCSjQBtvvKYJRDb dh+a5YJWNAYWf+jeUhdwOrFydhjpX3ObV8y9GjiPu5nH42oqwERVTZtq8C5ff6D/awhQ NfMQ== X-Gm-Message-State: ALyK8tKKc4JQhluF02v2Ce5qg9VTcuje8f4K9YWCbonbNwEqJaLm0v6AYdgkTw9jtYXHeA== X-Received: by 10.55.25.155 with SMTP id 27mr18599306qkz.61.1464870235497; Thu, 02 Jun 2016 05:23:55 -0700 (PDT) Received: from ?IPv6:2601:181:c003:1930:a2a8:cdff:fe3e:b48? ([2601:181:c003:1930:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id o128sm13708916qkb.40.2016.06.02.05.23.54 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 02 Jun 2016 05:23:54 -0700 (PDT) Subject: Re: [PATCH v4] gcov: Runtime configurable destination output To: Aaron Conole References: <1464282501-7696-1-git-send-email-aconole@bytheb.org> <2f87d729-6577-a262-5bf9-640c0ba582a7@acm.org> Cc: gcc-patches@gcc.gnu.org From: Nathan Sidwell Message-ID: Date: Thu, 2 Jun 2016 08:23:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: On 05/31/16 11:04, Aaron Conole wrote: > Nathan Sidwell 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 2016-06-02 Aaron Conole * 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 . */ -/* 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