From patchwork Thu Mar 31 11:35:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52502 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDF88383940B for ; Thu, 31 Mar 2022 11:36:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 7986A385E007 for ; Thu, 31 Mar 2022 11:35:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7986A385E007 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5F-000OPo-NL; Thu, 31 Mar 2022 13:35:21 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000FkA-Kf; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 471C3480128; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id xNzarIKDm0fY; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id AEB334800B1; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id eaxwJGkpDQLu; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 88A634800C9; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 01/12] gcov-tool: Allow merging of empty profile lists Date: Thu, 31 Mar 2022 13:35:04 +0200 Message-Id: <20220331113515.35764-2-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The gcov_profile_merge() already had code to deal with profile information which had no counterpart to merge with. For profile information from files with no associated counterpart, the profile information is simply used as is with the weighting transformation applied. Make sure that gcov_profile_merge() works with an empty target profile list. Return the merged profile list. gcc/ * gcov-tool.cc (gcov_profile_merge): Adjust return type. (profile_merge): Allow merging of directories which contain no profile files. libgcc/ * libgcov-util.c (gcov_profile_merge): Return the list of merged profiles. Accept empty target and source profile lists. --- gcc/gcov-tool.cc | 27 ++++++++++----------------- libgcc/libgcov-util.c | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/gcc/gcov-tool.cc b/gcc/gcov-tool.cc index f4e42ae763c..2e4083a664d 100644 --- a/gcc/gcov-tool.cc +++ b/gcc/gcov-tool.cc @@ -40,7 +40,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif #include -extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, int); +extern struct gcov_info *gcov_profile_merge (struct gcov_info*, + struct gcov_info*, int, int); extern int gcov_profile_overlap (struct gcov_info*, struct gcov_info*); extern int gcov_profile_normalize (struct gcov_info*, gcov_type); extern int gcov_profile_scale (struct gcov_info*, float, int, int); @@ -141,26 +142,18 @@ profile_merge (const char *d1, const char *d2, const char *out, int w1, int w2) { struct gcov_info *d1_profile; struct gcov_info *d2_profile; - int ret; + struct gcov_info *merged_profile; d1_profile = gcov_read_profile_dir (d1, 0); - if (!d1_profile) - return 1; - - if (d2) - { - d2_profile = gcov_read_profile_dir (d2, 0); - if (!d2_profile) - return 1; + d2_profile = gcov_read_profile_dir (d2, 0); - /* The actual merge: we overwrite to d1_profile. */ - ret = gcov_profile_merge (d1_profile, d2_profile, w1, w2); + /* The actual merge: we overwrite to d1_profile. */ + merged_profile = gcov_profile_merge (d1_profile, d2_profile, w1, w2); - if (ret) - return ret; - } - - gcov_output_files (out, d1_profile); + if (merged_profile) + gcov_output_files (out, merged_profile); + else if (verbose) + fnotice (stdout, "no profile files were merged\n"); return 0; } diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index ba7fb924b53..100f1b19f1a 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -674,16 +674,16 @@ find_match_gcov_info (struct gcov_info **array, int size, } /* Merge the list of gcov_info objects from SRC_PROFILE to TGT_PROFILE. - Return 0 on success: without mismatch. - Reutrn 1 on error. */ + Return the list of merged gcov_info objects. Return NULL if the list is + empty. */ -int +struct gcov_info * gcov_profile_merge (struct gcov_info *tgt_profile, struct gcov_info *src_profile, int w1, int w2) { struct gcov_info *gi_ptr; struct gcov_info **tgt_infos; - struct gcov_info *tgt_tail; + struct gcov_info **tgt_tail; struct gcov_info **in_src_not_tgt; unsigned tgt_cnt = 0, src_cnt = 0; unsigned unmatch_info_cnt = 0; @@ -703,7 +703,10 @@ gcov_profile_merge (struct gcov_info *tgt_profile, struct gcov_info *src_profile for (gi_ptr = tgt_profile, i = 0; gi_ptr; gi_ptr = gi_ptr->next, i++) tgt_infos[i] = gi_ptr; - tgt_tail = tgt_infos[tgt_cnt - 1]; + if (tgt_cnt) + tgt_tail = &tgt_infos[tgt_cnt - 1]->next; + else + tgt_tail = &tgt_profile; /* First pass on tgt_profile, we multiply w1 to all counters. */ if (w1 > 1) @@ -732,14 +735,14 @@ gcov_profile_merge (struct gcov_info *tgt_profile, struct gcov_info *src_profile gi_ptr = in_src_not_tgt[i]; gcov_merge (gi_ptr, gi_ptr, w2 - 1); gi_ptr->next = NULL; - tgt_tail->next = gi_ptr; - tgt_tail = gi_ptr; + *tgt_tail = gi_ptr; + tgt_tail = &gi_ptr->next; } free (in_src_not_tgt); free (tgt_infos); - return 0; + return tgt_profile; } typedef gcov_type (*counter_op_fn) (gcov_type, void*, void*); From patchwork Thu Mar 31 11:35:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52503 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EEBAB383942B for ; Thu, 31 Mar 2022 11:36:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 7CEA03864842 for ; Thu, 31 Mar 2022 11:35:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7CEA03864842 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5F-000OPj-Id; Thu, 31 Mar 2022 13:35:21 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000Fiv-Fh; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 16FE6480125; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id TfwlnqCglNNY; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id B9B63480114; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id o1uMcKiZPQE2; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 9552F48010D; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 02/12] gcov: Add mode to all gcov_open() Date: Thu, 31 Mar 2022 13:35:05 +0200 Message-Id: <20220331113515.35764-3-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ * gcov-io.cc (gcov_open): Always use the mode parameter. * gcov-io.h (gcov_open): Declare it unconditionally. libgcc/ * libgcov-driver-system.c (gcov_exit_open_gcda_file): Open file for reading and writing. * libgcov-util.c (read_gcda_file): Open file for reading. * libgcov.h (gcov_open): Delete declaration. --- gcc/gcov-io.cc | 7 ------- gcc/gcov-io.h | 5 +---- libgcc/libgcov-driver-system.c | 4 ++-- libgcc/libgcov-util.c | 2 +- libgcc/libgcov.h | 1 - 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc index 72c40f8eaa0..017a6e32a5d 100644 --- a/gcc/gcov-io.cc +++ b/gcc/gcov-io.cc @@ -89,15 +89,8 @@ from_file (gcov_unsigned_t value) Return zero on failure, non-zero on success. */ GCOV_LINKAGE int -#if IN_LIBGCOV -gcov_open (const char *name) -#else gcov_open (const char *name, int mode) -#endif { -#if IN_LIBGCOV - int mode = 0; -#endif #if GCOV_LOCKED struct flock s_flock; int fd; diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index 99ce7dbccc8..afe74b002f1 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -347,15 +347,12 @@ struct gcov_summary functions for writing. Your file may become corrupted if you break these invariants. */ -#if !IN_LIBGCOV -GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/); -#endif - #if !IN_LIBGCOV || defined (IN_GCOV_TOOL) GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t); #endif /* Available everywhere. */ +GCOV_LINKAGE int gcov_open (const char *, int) ATTRIBUTE_HIDDEN; GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN; GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN; GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN; diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index eef6e3cbda1..9abb2fe7f74 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -309,7 +309,7 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, gf->filename = replace_filename_variables (gf->filename); - if (!gcov_open (gf->filename)) + if (!gcov_open (gf->filename, 0)) { /* Open failed likely due to missed directory. Create directory and retry to open file. */ @@ -318,7 +318,7 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, fprintf (stderr, "profiling:%s:Skip\n", gf->filename); return -1; } - if (!gcov_open (gf->filename)) + if (!gcov_open (gf->filename, 0)) { fprintf (stderr, "profiling:%s:Cannot open\n", gf->filename); return -1; diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index 100f1b19f1a..db157220c9d 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -268,7 +268,7 @@ read_gcda_file (const char *filename) k_ctrs_mask[i] = 0; k_ctrs_types = 0; - if (!gcov_open (filename)) + if (!gcov_open (filename, 1)) { fnotice (stderr, "%s:cannot open\n", filename); return NULL; diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h index 40e845ce3ea..f190547e819 100644 --- a/libgcc/libgcov.h +++ b/libgcc/libgcov.h @@ -343,7 +343,6 @@ extern int __gcov_execve (const char *, char *const [], char *const []) ATTRIBUTE_HIDDEN; /* Functions that only available in libgcov. */ -GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN; GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/, const struct gcov_summary *) ATTRIBUTE_HIDDEN; From patchwork Thu Mar 31 11:35:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52504 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 359983888825 for ; Thu, 31 Mar 2022 11:37:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 7919A3857404 for ; Thu, 31 Mar 2022 11:35:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7919A3857404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5F-000OPp-Ne; Thu, 31 Mar 2022 13:35:21 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000FkM-L4; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 4C894480118; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Fg1eDZzxPnpJ; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id C584E4800C9; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id iXJfF1xwzX9k; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id A333B480112; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 03/12] gcov: Add open mode parameter to gcov_do_dump() Date: Thu, 31 Mar 2022 13:35:06 +0200 Message-Id: <20220331113515.35764-4-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ * gcov-tool.cc (gcov_do_dump): Add mode parameter. (gcov_output_files): Open files for reading and writing. libgcc/ * libgcov-driver-system.c (gcov_exit_open_gcda_file): Add mode parameter. Pass mode to gcov_open() calls. * libgcov-driver.c (dump_one_gcov): Add mode parameter. Pass mode to gcov_exit_open_gcda_file() call. (gcov_do_dump): Add mode parameter. Pass mode to dump_one_gcov() calls. (__gcov_dump_one): Open file for reading and writing. --- gcc/gcov-tool.cc | 4 ++-- libgcc/libgcov-driver-system.c | 7 ++++--- libgcc/libgcov-driver.c | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gcc/gcov-tool.cc b/gcc/gcov-tool.cc index 2e4083a664d..d712715cf7e 100644 --- a/gcc/gcov-tool.cc +++ b/gcc/gcov-tool.cc @@ -46,7 +46,7 @@ extern int gcov_profile_overlap (struct gcov_info*, struct gcov_info*); extern int gcov_profile_normalize (struct gcov_info*, gcov_type); extern int gcov_profile_scale (struct gcov_info*, float, int, int); extern struct gcov_info* gcov_read_profile_dir (const char*, int); -extern void gcov_do_dump (struct gcov_info *, int); +extern void gcov_do_dump (struct gcov_info *, int, int); extern const char *gcov_get_filename (struct gcov_info *list); extern void gcov_set_verbose (void); @@ -124,7 +124,7 @@ gcov_output_files (const char *out, struct gcov_info *profile) fatal_error (input_location, "output file %s already exists in folder %s", filename, out); - gcov_do_dump (profile, 0); + gcov_do_dump (profile, 0, 0); ret = chdir (pwd); if (ret) diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 9abb2fe7f74..ac405c38e3a 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -261,7 +261,8 @@ allocate_filename_struct (struct gcov_filename *gf) static int gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, - struct gcov_filename *gf) + struct gcov_filename *gf, + int mode) { int append_slash = 0; const char *fname = gi_ptr->filename; @@ -309,7 +310,7 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, gf->filename = replace_filename_variables (gf->filename); - if (!gcov_open (gf->filename, 0)) + if (!gcov_open (gf->filename, mode)) { /* Open failed likely due to missed directory. Create directory and retry to open file. */ @@ -318,7 +319,7 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, fprintf (stderr, "profiling:%s:Skip\n", gf->filename); return -1; } - if (!gcov_open (gf->filename, 0)) + if (!gcov_open (gf->filename, mode)) { fprintf (stderr, "profiling:%s:Cannot open\n", gf->filename); return -1; diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index 7e52c5676e5..10831e84b61 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -595,14 +595,14 @@ write_one_data (const struct gcov_info *gi_ptr, static void dump_one_gcov (struct gcov_info *gi_ptr, struct gcov_filename *gf, unsigned run_counted ATTRIBUTE_UNUSED, - gcov_type run_max ATTRIBUTE_UNUSED) + gcov_type run_max ATTRIBUTE_UNUSED, int mode) { struct gcov_summary summary = {}; int error; gcov_unsigned_t tag; fn_buffer = 0; - error = gcov_exit_open_gcda_file (gi_ptr, gf); + error = gcov_exit_open_gcda_file (gi_ptr, gf, mode); if (error == -1) return; @@ -649,13 +649,13 @@ read_fatal:; /* Dump all the coverage counts for the program. It first computes program summary and then traverses gcov_list list and dumps the gcov_info - objects one by one. */ + objects one by one. Use MODE to open files. */ #if !IN_GCOV_TOOL static #endif void -gcov_do_dump (struct gcov_info *list, int run_counted) +gcov_do_dump (struct gcov_info *list, int run_counted, int mode) { struct gcov_info *gi_ptr; struct gcov_filename gf; @@ -678,7 +678,7 @@ gcov_do_dump (struct gcov_info *list, int run_counted) /* Now merge each file. */ for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next) { - dump_one_gcov (gi_ptr, &gf, run_counted, run_max); + dump_one_gcov (gi_ptr, &gf, run_counted, run_max, mode); free (gf.filename); } @@ -701,7 +701,7 @@ __gcov_dump_one (struct gcov_root *root) if (root->dumped) return; - gcov_do_dump (root->list, root->run_counted); + gcov_do_dump (root->list, root->run_counted, 0); root->dumped = 1; root->run_counted = 1; From patchwork Thu Mar 31 11:35:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52506 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C2A53876053 for ; Thu, 31 Mar 2022 11:38:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id F15BA3839830 for ; Thu, 31 Mar 2022 11:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F15BA3839830 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5K-000OPy-SW; Thu, 31 Mar 2022 13:35:26 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000FlZ-Q0; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 6A2494800C9; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id U5oaxihq73Hx; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id DEB55480112; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qXB2TL9siAza; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id B0AB448010F; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 04/12] gcov: Make gcov_seek() static Date: Thu, 31 Mar 2022 13:35:07 +0200 Message-Id: <20220331113515.35764-5-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This function is only used by gcov_write_length() in the gcov-io.cc file. gcc/ * gcov-io.cc (gcov_seek): Make it static. * gcov-io.h (struct gcov_summary): Do not mention gcov_seek(). libgcc/ * libgcov.h (gcov_seek): Remove define and declaration. --- gcc/gcov-io.cc | 4 +--- gcc/gcov-io.h | 6 +++--- libgcc/libgcov.h | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc index 017a6e32a5d..fee3130f94a 100644 --- a/gcc/gcov-io.cc +++ b/gcc/gcov-io.cc @@ -294,17 +294,15 @@ gcov_write_filename (const char *filename) gcov_write_string (filename); } -#endif /* Move to a given position in a gcov file. */ -GCOV_LINKAGE void +static void gcov_seek (gcov_position_t base) { fseek (gcov_var.file, base, SEEK_SET); } -#if !IN_LIBGCOV /* Write a tag TAG and reserve space for the record length. Return a value to be used for gcov_write_length. */ diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index afe74b002f1..204ae0ccf7f 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -340,9 +340,9 @@ struct gcov_summary /* Functions for reading and writing gcov files. In libgcov you can open the file for reading then writing. Elsewhere you can open the file either for reading or for writing. When reading a file you may - use the gcov_read_* functions, gcov_sync, gcov_position, & - gcov_error. When writing a file you may use the gcov_write - functions, gcov_seek & gcov_error. When a file is to be rewritten + use the gcov_read_* functions, gcov_sync, gcov_position, and + gcov_error. When writing a file you may use the gcov_write* + functions and gcov_error. When a file is to be rewritten you use the functions for reading, then gcov_rewrite then the functions for writing. Your file may become corrupted if you break these invariants. */ diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h index f190547e819..487bd1464cd 100644 --- a/libgcc/libgcov.h +++ b/libgcc/libgcov.h @@ -115,7 +115,6 @@ typedef unsigned gcov_type_unsigned __attribute__ ((mode (QI))); #define gcov_open __gcov_open #define gcov_close __gcov_close #define gcov_position __gcov_position -#define gcov_seek __gcov_seek #define gcov_rewrite __gcov_rewrite #define gcov_is_error __gcov_is_error #define gcov_write_unsigned __gcov_write_unsigned @@ -346,7 +345,6 @@ extern int __gcov_execve (const char *, char *const [], char *const []) GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/, const struct gcov_summary *) ATTRIBUTE_HIDDEN; -GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN; GCOV_LINKAGE void gcov_rewrite (void) ATTRIBUTE_HIDDEN; /* "Counts" stored in gcda files can be a real counter value, or From patchwork Thu Mar 31 11:35:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52510 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C073B3945C24 for ; Thu, 31 Mar 2022 11:40:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 22544385800E for ; Thu, 31 Mar 2022 11:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22544385800E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5K-000OQY-VS; Thu, 31 Mar 2022 13:35:26 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5K-000Fm5-Sa; Thu, 31 Mar 2022 13:35:26 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 8B84F48010D; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id XisrXTOWtFvb; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 002F6480122; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id E03QNE-m2jlR; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id C34F4480117; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 05/12] gcov: Add __gcov_filename_to_gcfn() Date: Thu, 31 Mar 2022 13:35:08 +0200 Message-Id: <20220331113515.35764-6-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ * gcov-io.h (GCOV_FILENAME_MAGIC): Define and document. libgcc/ * gcov.h (__gcov_info_to_gcda): Mention __gcov_filename_to_gcfn(). (__gcov_filename_to_gcfn): Declare and document. * libgcov-driver.c (dump_string): New. (__gcov_filename_to_gcfn): Likewise. --- gcc/gcov-io.h | 24 ++++++++++++++++-------- libgcc/gcov.h | 17 ++++++++++++++++- libgcc/libgcov-driver.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index 204ae0ccf7f..30947634d73 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -60,14 +60,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see file : int32:magic int32:version int32:stamp record* - The magic ident is different for the notes and the data files. The - magic ident is used to determine the endianness of the file, when - reading. The version is the same for both files and is derived - from gcc's version number. The stamp value is used to synchronize - note and data files and to synchronize merging within a data - file. It need not be an absolute time stamp, merely a ticker that - increments fast enough and cycles slow enough to distinguish - different compile/run/compile cycles. + A filename header may be used to provide a filename for the data in + a stream of data to support gcov in freestanding environments. This + header is used by the merge-stream subcommand of the gcov-tool. The + format of the filename header is + + filename-header : int32:magic int32:version string + + The magic ident is different for the notes and the data files as + well as the filename header. The magic ident is used to determine + the endianness of the file, when reading. The version is the same + for both files and is derived from gcc's version number. The stamp + value is used to synchronize note and data files and to synchronize + merging within a data file. It need not be an absolute time stamp, + merely a ticker that increments fast enough and cycles slow enough + to distinguish different compile/run/compile cycles. Although the ident and version are formally 32 bit numbers, they are derived from 4 character ASCII strings. The version number @@ -228,6 +235,7 @@ typedef uint64_t gcov_type_unsigned; /* File magic. Must not be palindromes. */ #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */ #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */ +#define GCOV_FILENAME_MAGIC ((gcov_unsigned_t)0x6763666e) /* "gcfn" */ #include "version.h" diff --git a/libgcc/gcov.h b/libgcc/gcov.h index cea93023920..cdd4206f625 100644 --- a/libgcc/gcov.h +++ b/libgcc/gcov.h @@ -43,7 +43,8 @@ extern void __gcov_dump (void); stream. The ALLOCATE_FN callback shall allocate memory with a size in characters specified by the first callback parameter. The ARG parameter is a user-provided argument passed as the last argument to the callback - functions. */ + functions. It is recommended to use the __gcov_filename_to_gcfn() + in the filename callback function. */ extern void __gcov_info_to_gcda (const struct gcov_info *__info, @@ -52,4 +53,18 @@ __gcov_info_to_gcda (const struct gcov_info *__info, void *(*__allocate_fn) (unsigned, void *), void *__arg); +/* Convert the FILENAME to a gcfn data stream. The DUMP_FN callback is + subsequently called with chunks (the begin and length of the chunk are + passed as the first two callback parameters) of the gcfn data stream. + The ARG parameter is a user-provided argument passed as the last + argument to the DUMP_FN callback function. This function is intended + to be used by the filename callback of __gcov_info_to_gcda(). The gcfn + data stream is used by the merge-stream subcommand of the gcov-tool to + get the filename associated with a gcda data stream. */ + +extern void +__gcov_filename_to_gcfn (const char *__filename, + void (*__dump_fn) (const void *, unsigned, void *), + void *__arg); + #endif /* GCC_GCOV_H */ diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index 10831e84b61..a44054a3cb3 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -410,6 +410,23 @@ dump_counter (gcov_type counter, dump_unsigned (0, dump_fn, arg); } +/* Dump the STRING using the DUMP handler called with ARG. */ + +static inline void +dump_string (const char *string, + void (*dump_fn) (const void *, unsigned, void *), + void *arg) +{ + unsigned length = 0; + + if (string) + length = strlen (string) + 1; + + dump_unsigned (length, dump_fn, arg); + if (string) + (*dump_fn) (string, length, arg); +} + #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) /* Store all TOP N counters where each has a dynamic length. */ @@ -780,4 +797,17 @@ __gcov_info_to_gcda (const struct gcov_info *gi_ptr, (*filename_fn) (gi_ptr->filename, arg); write_one_data (gi_ptr, NULL, dump_fn, allocate_fn, arg); } + +/* Convert the filename to a gcfn data stream. It is intended for + free-standing environments which do not support the C library file I/O. */ + +void +__gcov_filename_to_gcfn (const char *filename, + void (*dump_fn) (const void *, unsigned, void *), + void *arg) +{ + dump_unsigned (GCOV_FILENAME_MAGIC, dump_fn, arg); + dump_unsigned (GCOV_VERSION, dump_fn, arg); + dump_string (filename, dump_fn, arg); +} #endif /* NEED_L_GCOV_INFO_TO_GCDA */ From patchwork Thu Mar 31 11:35:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52505 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DC05389A103 for ; Thu, 31 Mar 2022 11:37:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id EC61E3839808 for ; Thu, 31 Mar 2022 11:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EC61E3839808 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5K-000OPw-S2; Thu, 31 Mar 2022 13:35:26 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000FlL-Ow; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 6C0B3480120; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 6JQOzt7SGSNm; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 02BE748010F; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JGj9vnNejsFh; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id CFE1048010D; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 06/12] gcov-tool: Support file input from stdin Date: Thu, 31 Mar 2022 13:35:09 +0200 Message-Id: <20220331113515.35764-7-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ * gcov-io.cc (GCOV_MODE_STDIN): Define. (gcov_position): For gcov-tool, return calculated position if file is stdin. (gcov_open): For gcov-tool, use stdin if filename is NULL. (gcov_close): For gcov-tool, do not close stdin. (gcov_read_bytes): For gcov-tool, update position if file is stdin. (gcov_sync): For gcov-tool, discard input if file is stdin. --- gcc/gcov-io.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc index fee3130f94a..177f81166a6 100644 --- a/gcc/gcov-io.cc +++ b/gcc/gcov-io.cc @@ -35,8 +35,13 @@ struct gcov_var int error; /* < 0 overflow, > 0 disk error. */ int mode; /* < 0 writing, > 0 reading. */ int endian; /* Swap endianness. */ +#ifdef IN_GCOV_TOOL + gcov_position_t pos; /* File position for stdin support. */ +#endif } gcov_var; +#define GCOV_MODE_STDIN 2 + /* Save the current position in the gcov file. */ /* We need to expose this function when compiling for gcov-tool. */ #ifndef IN_GCOV_TOOL @@ -45,6 +50,10 @@ static inline gcov_position_t gcov_position (void) { +#ifdef IN_GCOV_TOOL + if (gcov_var.mode == GCOV_MODE_STDIN) + return gcov_var.pos; +#endif return ftell (gcov_var.file); } @@ -108,6 +117,16 @@ gcov_open (const char *name, int mode) #if !IN_LIBGCOV || defined (IN_GCOV_TOOL) gcov_var.endian = 0; #endif +#ifdef IN_GCOV_TOOL + gcov_var.pos = 0; + if (!name) + { + gcov_nonruntime_assert (gcov_var.mode > 0); + gcov_var.file = stdin; + gcov_var.mode = GCOV_MODE_STDIN; + return 1; + } +#endif #if GCOV_LOCKED if (mode > 0) { @@ -190,6 +209,11 @@ gcov_open (const char *name, int mode) GCOV_LINKAGE int gcov_close (void) { +#ifdef IN_GCOV_TOOL + if (gcov_var.file == stdin) + gcov_var.file = 0; + else +#endif if (gcov_var.file) { if (fclose (gcov_var.file)) @@ -363,6 +387,9 @@ gcov_read_bytes (void *buffer, unsigned count) if (read != 1) return NULL; +#ifdef IN_GCOV_TOOL + gcov_var.pos += count; +#endif return buffer; } @@ -499,6 +526,17 @@ gcov_sync (gcov_position_t base, gcov_unsigned_t length) { gcov_nonruntime_assert (gcov_var.mode > 0); base += length; +#ifdef IN_GCOV_TOOL + if (gcov_var.mode == GCOV_MODE_STDIN) + { + while (gcov_var.pos < base) + { + ++gcov_var.pos; + (void)fgetc(gcov_var.file); + } + return; + } +#endif fseek (gcov_var.file, base, SEEK_SET); } #endif From patchwork Thu Mar 31 11:35:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52507 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06E793888C6B for ; Thu, 31 Mar 2022 11:38:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 0109A3839838 for ; Thu, 31 Mar 2022 11:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0109A3839838 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5K-000OPz-T0; Thu, 31 Mar 2022 13:35:26 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000Flh-QU; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 800B1480112; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id mRQM8txScY4o; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 18EC4480123; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id D1v2tx-Z8zI7; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id E59A848011C; Thu, 31 Mar 2022 13:35:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 07/12] gcov: Use xstrdup() Date: Thu, 31 Mar 2022 13:35:10 +0200 Message-Id: <20220331113515.35764-8-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Move duplication of filename to caller and use xstrdup() instead of custom code. This helps to reuse read_gcda_file() for other purposes. libgcc/ * libgcov-util.c (read_gcda_file): Do not duplicate filename. (ftw_read_file): Duplicate filename for read_gcda_file(). --- libgcc/libgcov-util.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index db157220c9d..ae5712c0138 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -296,16 +296,11 @@ read_gcda_file (const char *filename) sizeof (struct gcov_ctr_info) * GCOV_COUNTERS, 1); obj_info->version = version; + obj_info->filename = filename; obstack_init (&fn_info); num_fn_info = 0; curr_fn_info = 0; - { - size_t len = strlen (filename) + 1; - char *str_dup = (char*) xmalloc (len); - memcpy (str_dup, filename, len); - obj_info->filename = str_dup; - } /* Read stamp. */ obj_info->stamp = gcov_read_unsigned (); @@ -415,7 +410,7 @@ ftw_read_file (const char *filename, if (verbose) fnotice (stderr, "reading file: %s\n", filename); - obj_info = read_gcda_file (filename); + obj_info = read_gcda_file (xstrdup (filename)); if (!obj_info) return 0; From patchwork Thu Mar 31 11:35:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52508 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A95D3899434 for ; Thu, 31 Mar 2022 11:39:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 0D27B383982D for ; Thu, 31 Mar 2022 11:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D27B383982D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5K-000OQ0-TX; Thu, 31 Mar 2022 13:35:26 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5F-000Flw-Qu; Thu, 31 Mar 2022 13:35:21 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 834A5480115; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ho0e9IWDvk3i; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 318E148010D; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id rrkwgQes8Izs; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 00B2F480124; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 08/12] gcov: Move prepend to list to read_gcda_file() Date: Thu, 31 Mar 2022 13:35:11 +0200 Message-Id: <20220331113515.35764-9-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This helps to reuse read_gcda_file(). libgcc/ * libgcov-util.c (read_gcda_file): Prepend new info object to global list. (ftw_read_file): Remove list append here. --- libgcc/libgcov-util.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index ae5712c0138..d628c71479e 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -301,6 +301,9 @@ read_gcda_file (const char *filename) num_fn_info = 0; curr_fn_info = 0; + /* Prepend to gcov info list */ + obj_info->next = gcov_info_head; + gcov_info_head = obj_info; /* Read stamp. */ obj_info->stamp = gcov_read_unsigned (); @@ -392,7 +395,6 @@ ftw_read_file (const char *filename, { int filename_len; int suffix_len; - struct gcov_info *obj_info; /* Only read regular files. */ if (type != FTW_F) @@ -410,12 +412,7 @@ ftw_read_file (const char *filename, if (verbose) fnotice (stderr, "reading file: %s\n", filename); - obj_info = read_gcda_file (xstrdup (filename)); - if (!obj_info) - return 0; - - obj_info->next = gcov_info_head; - gcov_info_head = obj_info; + (void)read_gcda_file (xstrdup (filename)); return 0; } From patchwork Thu Mar 31 11:35:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52509 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63709388E82B for ; Thu, 31 Mar 2022 11:39:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 24BDB3838007 for ; Thu, 31 Mar 2022 11:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24BDB3838007 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5L-000OQZ-0W; Thu, 31 Mar 2022 13:35:27 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5K-000Fmn-UV; Thu, 31 Mar 2022 13:35:26 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 95B15480114; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id q5Ux4cGD5waN; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 45B15480110; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3oLmhWzPZvse; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 166CC480116; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 09/12] gcov: Move gcov_open() to caller of read_gcda_file() Date: Thu, 31 Mar 2022 13:35:12 +0200 Message-Id: <20220331113515.35764-10-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This allows to reuse read_gcda_file() to read multiple objects from a single file. libgcc/ * libgcov-util.c (read_gcda_file): Do not open file. (ftw_read_file): Open file here. --- libgcc/libgcov-util.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index d628c71479e..03902ed10b1 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -268,17 +268,10 @@ read_gcda_file (const char *filename) k_ctrs_mask[i] = 0; k_ctrs_types = 0; - if (!gcov_open (filename, 1)) - { - fnotice (stderr, "%s:cannot open\n", filename); - return NULL; - } - /* Read magic. */ if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC)) { fnotice (stderr, "%s:not a gcov data file\n", filename); - gcov_close (); return NULL; } @@ -287,7 +280,6 @@ read_gcda_file (const char *filename) if (version != GCOV_VERSION) { fnotice (stderr, "%s:incorrect gcov version %d vs %d \n", filename, version, GCOV_VERSION); - gcov_close (); return NULL; } @@ -379,7 +371,6 @@ read_gcda_file (const char *filename) } read_gcda_finalize (obj_info); - gcov_close (); return obj_info; } @@ -412,7 +403,14 @@ ftw_read_file (const char *filename, if (verbose) fnotice (stderr, "reading file: %s\n", filename); + if (!gcov_open (filename, 1)) + { + fnotice (stderr, "%s:cannot open\n", filename); + return 0; + } + (void)read_gcda_file (xstrdup (filename)); + gcov_close (); return 0; } From patchwork Thu Mar 31 11:35:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52513 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71A0038A7C11 for ; Thu, 31 Mar 2022 11:41:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 2F57F383943F for ; Thu, 31 Mar 2022 11:35:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F57F383943F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5Q-000OQd-2L; Thu, 31 Mar 2022 13:35:32 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5K-000FnJ-VF; Thu, 31 Mar 2022 13:35:26 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id A74C5480110; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id t_3jZ1TgNHYi; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 56E794800B1; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id GC3667NnK06e; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 33CEC480117; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 10/12] gcov: Fix integer types in ftw_read_file() Date: Thu, 31 Mar 2022 13:35:13 +0200 Message-Id: <20220331113515.35764-11-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" libgcc/ * libgcov-util.c (ftw_read_file): Use size_t for strlen() variables. --- libgcc/libgcov-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index 03902ed10b1..622d5a9dc71 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -384,8 +384,8 @@ ftw_read_file (const char *filename, const struct stat *status ATTRIBUTE_UNUSED, int type) { - int filename_len; - int suffix_len; + size_t filename_len; + size_t suffix_len; /* Only read regular files. */ if (type != FTW_F) From patchwork Thu Mar 31 11:35:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52511 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3AF373864842 for ; Thu, 31 Mar 2022 11:40:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 50BA8383800C for ; Thu, 31 Mar 2022 11:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 50BA8383800C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5O-000OQD-79; Thu, 31 Mar 2022 13:35:30 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5G-000Fo8-3Y; Thu, 31 Mar 2022 13:35:22 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id C5A104800B1; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id McKAjmNtCkbM; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 797D5480113; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Wvz3xDlvZoTE; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 45B60480124; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 11/12] gcov: Record EOF error during read Date: Thu, 31 Mar 2022 13:35:14 +0200 Message-Id: <20220331113515.35764-12-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Use an enum for file error codes. gcc/ * gcov-io.cc (gcov_file_error): New enum. (gcov_var): Use gcov_file_error enum for the error member. (gcov_open): Use GCOV_FILE_NO_ERROR. (gcov_close): Use GCOV_FILE_WRITE_ERROR. (gcov_write): Likewise. (gcov_write_unsigned): Likewise. (gcov_write_string): Likewise. (gcov_read_bytes): Set error code if EOF is reached. (gcov_read_counter): Use GCOV_FILE_COUNTER_OVERFLOW. --- gcc/gcov-io.cc | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc index 177f81166a6..60c762bf3a3 100644 --- a/gcc/gcov-io.cc +++ b/gcc/gcov-io.cc @@ -29,10 +29,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see static gcov_unsigned_t *gcov_read_words (void *buffer, unsigned); +enum gcov_file_error { + GCOV_FILE_COUNTER_OVERFLOW = -1, + GCOV_FILE_NO_ERROR = 0, + GCOV_FILE_WRITE_ERROR = 1, + GCOV_FILE_EOF = 2 +}; + struct gcov_var { FILE *file; - int error; /* < 0 overflow, > 0 disk error. */ + enum gcov_file_error error; int mode; /* < 0 writing, > 0 reading. */ int endian; /* Swap endianness. */ #ifdef IN_GCOV_TOOL @@ -113,7 +120,7 @@ gcov_open (const char *name, int mode) #endif gcov_nonruntime_assert (!gcov_var.file); - gcov_var.error = 0; + gcov_var.error = GCOV_FILE_NO_ERROR; #if !IN_LIBGCOV || defined (IN_GCOV_TOOL) gcov_var.endian = 0; #endif @@ -217,7 +224,7 @@ gcov_close (void) if (gcov_var.file) { if (fclose (gcov_var.file)) - gcov_var.error = 1; + gcov_var.error = GCOV_FILE_WRITE_ERROR; gcov_var.file = 0; } @@ -253,7 +260,7 @@ gcov_write (const void *data, unsigned length) { gcov_unsigned_t r = fwrite (data, length, 1, gcov_var.file); if (r != 1) - gcov_var.error = 1; + gcov_var.error = GCOV_FILE_WRITE_ERROR; } /* Write unsigned VALUE to coverage file. */ @@ -263,7 +270,7 @@ gcov_write_unsigned (gcov_unsigned_t value) { gcov_unsigned_t r = fwrite (&value, sizeof (value), 1, gcov_var.file); if (r != 1) - gcov_var.error = 1; + gcov_var.error = GCOV_FILE_WRITE_ERROR; } #if !IN_LIBGCOV @@ -283,7 +290,7 @@ gcov_write_string (const char *string) { gcov_unsigned_t r = fwrite (string, length, 1, gcov_var.file); if (r != 1) - gcov_var.error = 1; + gcov_var.error = GCOV_FILE_WRITE_ERROR; } } #endif @@ -385,7 +392,11 @@ gcov_read_bytes (void *buffer, unsigned count) unsigned read = fread (buffer, count, 1, gcov_var.file); if (read != 1) - return NULL; + { + if (feof (gcov_var.file)) + gcov_var.error = GCOV_FILE_EOF; + return NULL; + } #ifdef IN_GCOV_TOOL gcov_var.pos += count; @@ -434,7 +445,7 @@ gcov_read_counter (void) if (sizeof (value) > sizeof (gcov_unsigned_t)) value |= ((gcov_type) from_file (buffer[1])) << 32; else if (buffer[1]) - gcov_var.error = -1; + gcov_var.error = GCOV_FILE_COUNTER_OVERFLOW; return value; } From patchwork Thu Mar 31 11:35:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52512 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7665F383801A for ; Thu, 31 Mar 2022 11:41:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 5EF573838019 for ; Thu, 31 Mar 2022 11:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5EF573838019 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5O-000OQj-8j; Thu, 31 Mar 2022 13:35:30 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5O-000Fp1-66; Thu, 31 Mar 2022 13:35:30 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id DD5854800C9; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 2eFrUAAx8XSu; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 7E64B48010F; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3prgjPukmlNb; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 57444480121; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 12/12] gcov-tool: Add merge-stream subcommand Date: Thu, 31 Mar 2022 13:35:15 +0200 Message-Id: <20220331113515.35764-13-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ * gcov-tool.cc (gcov_profile_merge_stream): Declare. (print_merge_stream_usage_message): New. (merge_stream_usage): Likewise. (do_merge_stream): Likewise. (print_usage): Call print_merge_stream_usage_message(). (main): Call do_merge_stream() to execute merge-stream subcommand. libgcc/ * libgcov-util.c (consume_stream): New. (get_target_profiles_for_merge): Likewise. (gcov_profile_merge_stream): Likewise. --- gcc/gcov-tool.cc | 76 ++++++++++++++++++++++++++++++++++++++++ libgcc/libgcov-util.c | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/gcc/gcov-tool.cc b/gcc/gcov-tool.cc index d712715cf7e..d8572b184e9 100644 --- a/gcc/gcov-tool.cc +++ b/gcc/gcov-tool.cc @@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see extern struct gcov_info *gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, int); +extern struct gcov_info *gcov_profile_merge_stream (const char *, int, int); extern int gcov_profile_overlap (struct gcov_info*, struct gcov_info*); extern int gcov_profile_normalize (struct gcov_info*, gcov_type); extern int gcov_profile_scale (struct gcov_info*, float, int, int); @@ -229,6 +230,78 @@ do_merge (int argc, char **argv) return profile_merge (argv[optind], argv[optind+1], output_dir, w1, w2); } +/* Usage message for profile merge-stream. */ + +static void +print_merge_stream_usage_message (int error_p) +{ + FILE *file = error_p ? stderr : stdout; + + fnotice (file, " merge-stream [options] [stream-file] Merge coverage stream file (or stdin)\n" + " and coverage file contents\n"); + fnotice (file, " -v, --verbose Verbose mode\n"); + fnotice (file, " -w, --weight Set weights (float point values)\n"); +} + +static const struct option merge_stream_options[] = +{ + { "verbose", no_argument, NULL, 'v' }, + { "weight", required_argument, NULL, 'w' }, + { 0, 0, 0, 0 } +}; + +/* Print merge-stream usage and exit. */ + +static void ATTRIBUTE_NORETURN +merge_stream_usage (void) +{ + fnotice (stderr, "Merge-stream subcomand usage:"); + print_merge_stream_usage_message (true); + exit (FATAL_EXIT_CODE); +} + +/* Driver for profile merge-stream sub-command. */ + +static int +do_merge_stream (int argc, char **argv) +{ + int opt; + int w1 = 1, w2 = 1; + struct gcov_info *merged_profile; + + optind = 0; + while ((opt = getopt_long (argc, argv, "vw:", + merge_stream_options, NULL)) != -1) + { + switch (opt) + { + case 'v': + verbose = true; + gcov_set_verbose (); + break; + case 'w': + sscanf (optarg, "%d,%d", &w1, &w2); + if (w1 < 0 || w2 < 0) + fatal_error (input_location, "weights need to be non-negative"); + break; + default: + merge_stream_usage (); + } + } + + if (argc - optind > 1) + merge_stream_usage (); + + merged_profile = gcov_profile_merge_stream (argv[optind], w1, w2); + + if (merged_profile) + gcov_do_dump (merged_profile, 0, -1); + else if (verbose) + fnotice (stdout, "no profile files were merged\n"); + + return 0; +} + /* If N_VAL is no-zero, normalize the profile by setting the largest counter counter value to N_VAL and scale others counters proportionally. Otherwise, multiply the all counters by SCALE. */ @@ -505,6 +578,7 @@ print_usage (int error_p) fnotice (file, " -h, --help Print this help, then exit\n"); fnotice (file, " -v, --version Print version number, then exit\n"); print_merge_usage_message (error_p); + print_merge_stream_usage_message (error_p); print_rewrite_usage_message (error_p); print_overlap_usage_message (error_p); fnotice (file, "\nFor bug reporting instructions, please see:\n%s.\n", @@ -594,6 +668,8 @@ main (int argc, char **argv) if (!strcmp (sub_command, "merge")) return do_merge (argc - optind, argv + optind); + else if (!strcmp (sub_command, "merge-stream")) + return do_merge_stream (argc - optind, argv + optind); else if (!strcmp (sub_command, "rewrite")) return do_rewrite (argc - optind, argv + optind); else if (!strcmp (sub_command, "overlap")) diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index 622d5a9dc71..0fe60528b48 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -735,6 +735,86 @@ gcov_profile_merge (struct gcov_info *tgt_profile, struct gcov_info *src_profile return tgt_profile; } +struct gcov_info * +consume_stream (const char *filename) +{ + read_profile_dir_init (); + + while (true) + { + unsigned version; + const char *filename_of_info; + struct gcov_info *obj_info; + + if (!gcov_magic (gcov_read_unsigned (), GCOV_FILENAME_MAGIC)) + { + if (gcov_is_error() != 2) + fnotice (stderr, "%s:not a gcfn stream\n", filename); + break; + } + + version = gcov_read_unsigned (); + if (version != GCOV_VERSION) + { + fnotice (stderr, "%s:incorrect gcov version %d vs %d \n", + filename, version, GCOV_VERSION); + break; + } + + filename_of_info = gcov_read_string (); + if (!filename_of_info) + { + fnotice (stderr, "%s:no filename in gcfn stream\n", + filename); + break; + } + + obj_info = read_gcda_file (filename); + if (!obj_info) + break; + + obj_info->filename = filename_of_info; + } + + return gcov_info_head; +} + +struct gcov_info * +get_target_profiles_for_merge (struct gcov_info *src_profile) +{ + struct gcov_info *gi_ptr; + + read_profile_dir_init (); + + for (gi_ptr = src_profile; gi_ptr; gi_ptr = gi_ptr->next) + if (gcov_open (gi_ptr->filename, 1)) + { + (void)read_gcda_file (gi_ptr->filename); + gcov_close (); + } + + return gcov_info_head; +} + +struct gcov_info * +gcov_profile_merge_stream (const char *filename, int w1, int w2) +{ + struct gcov_info *tgt_profile; + struct gcov_info *src_profile; + + if (!gcov_open (filename, 1)) + { + fnotice (stderr, "%s:cannot open\n", filename); + return NULL; + } + + src_profile = consume_stream (filename ? filename : ""); + gcov_close (); + tgt_profile = get_target_profiles_for_merge (src_profile); + + return gcov_profile_merge (tgt_profile, src_profile, w1, w2); +} + typedef gcov_type (*counter_op_fn) (gcov_type, void*, void*); /* Performing FN upon arc counters. */