From: Sebastian Huber <sebastian.huber@embedded-brains.de>
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 [thread overview]
Message-ID: <20220331113515.35764-7-sebastian.huber@embedded-brains.de> (raw)
In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de>
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
--
2.34.1
next prev parent reply other threads:[~2022-03-31 11:35 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-31 11:35 [RFC/gcov 00/12] Add merge-stream subcommand to gcov-tool Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 01/12] gcov-tool: Allow merging of empty profile lists Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 02/12] gcov: Add mode to all gcov_open() Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 03/12] gcov: Add open mode parameter to gcov_do_dump() Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 04/12] gcov: Make gcov_seek() static Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 05/12] gcov: Add __gcov_filename_to_gcfn() Sebastian Huber
2022-03-31 11:35 ` Sebastian Huber [this message]
2022-04-07 8:32 ` [RFC/gcov 06/12] gcov-tool: Support file input from stdin Martin Liška
2022-03-31 11:35 ` [RFC/gcov 07/12] gcov: Use xstrdup() Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 08/12] gcov: Move prepend to list to read_gcda_file() Sebastian Huber
2022-04-07 8:33 ` Martin Liška
2022-03-31 11:35 ` [RFC/gcov 09/12] gcov: Move gcov_open() to caller of read_gcda_file() Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 10/12] gcov: Fix integer types in ftw_read_file() Sebastian Huber
2022-03-31 11:35 ` [RFC/gcov 11/12] gcov: Record EOF error during read Sebastian Huber
2022-04-07 8:34 ` Martin Liška
2022-03-31 11:35 ` [RFC/gcov 12/12] gcov-tool: Add merge-stream subcommand Sebastian Huber
2022-04-07 8:36 ` Martin Liška
2022-04-07 8:38 ` [RFC/gcov 00/12] Add merge-stream subcommand to gcov-tool Martin Liška
2022-04-07 9:05 ` Sebastian Huber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220331113515.35764-7-sebastian.huber@embedded-brains.de \
--to=sebastian.huber@embedded-brains.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).