summaryrefslogtreecommitdiff
path: root/gcc/gcov.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-05-18 15:06:31 +0200
committerMartin Liska <marxin@gcc.gnu.org>2018-05-18 13:06:31 +0000
commitfeb4589d19187bc4b46160d0571eea2cb9a263af (patch)
tree607bdc6d8962dc7e45630f718039a30d4ca6e05c /gcc/gcov.c
parentc74bd3fba3572d5825fcc7fabfd136b22c7981ad (diff)
downloadgcc-feb4589d19187bc4b46160d0571eea2cb9a263af.tar.gz
gcov: add new option -t that prints output to stdout (PR gcov-profile/84846).
2018-05-18 Martin Liska <mliska@suse.cz> PR gcov-profile/84846 * gcov.c (print_usage): Add new -t option. (process_args): Handle the option. (generate_results): Use stdout as output when requested by the option. 2018-05-18 Martin Liska <mliska@suse.cz> PR gcov-profile/84846 * doc/gcov.texi: Document -t option of gcov tool. From-SVN: r260361
Diffstat (limited to 'gcc/gcov.c')
-rw-r--r--gcc/gcov.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 8ed6e0d4d3f..887972a1fcd 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -462,6 +462,10 @@ static int flag_unconditional = 0;
static int flag_gcov_file = 1;
+/* Output to stdout instead to a gcov file. */
+
+static int flag_use_stdout = 0;
+
/* Output progress indication if this is true. This is off by default
and can be turned on by the -d option. */
@@ -831,6 +835,7 @@ print_usage (int error_p)
fnotice (file, " -p, --preserve-paths Preserve all pathname components\n");
fnotice (file, " -r, --relative-only Only show data for relative sources\n");
fnotice (file, " -s, --source-prefix DIR Source prefix to elide\n");
+ fnotice (file, " -t, --stdout Output to stdout instead of a file\n");
fnotice (file, " -u, --unconditional-branches Show unconditional branch counts too\n");
fnotice (file, " -v, --version Print version number, then exit\n");
fnotice (file, " -w, --verbose Print verbose informations\n");
@@ -874,6 +879,7 @@ static const struct option options[] =
{ "object-directory", required_argument, NULL, 'o' },
{ "object-file", required_argument, NULL, 'o' },
{ "source-prefix", required_argument, NULL, 's' },
+ { "stdout", no_argument, NULL, 't' },
{ "unconditional-branches", no_argument, NULL, 'u' },
{ "display-progress", no_argument, NULL, 'd' },
{ "hash-filenames", no_argument, NULL, 'x' },
@@ -888,7 +894,7 @@ process_args (int argc, char **argv)
{
int opt;
- const char *opts = "abcdfhijklmno:prs:uvwx";
+ const char *opts = "abcdfhijklmno:prs:tuvwx";
while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
{
switch (opt)
@@ -952,6 +958,9 @@ process_args (int argc, char **argv)
case 'w':
flag_verbose = 1;
break;
+ case 't':
+ flag_use_stdout = 1;
+ break;
case 'v':
print_version ();
/* print_version will exit. */
@@ -1293,7 +1302,7 @@ generate_results (const char *file_name)
file_name = canonicalize_name (file_name);
}
- if (flag_gcov_file && flag_intermediate_format)
+ if (flag_gcov_file && flag_intermediate_format && !flag_use_stdout)
{
/* Open the intermediate file. */
gcov_intermediate_filename = get_gcov_intermediate_filename (file_name);
@@ -1325,7 +1334,9 @@ generate_results (const char *file_name)
}
accumulate_line_counts (src);
- function_summary (&src->coverage, "File");
+
+ if (!flag_use_stdout)
+ function_summary (&src->coverage, "File");
total_lines += src->coverage.lines;
total_executed += src->coverage.lines_executed;
if (flag_gcov_file)
@@ -1333,14 +1344,25 @@ generate_results (const char *file_name)
if (flag_intermediate_format)
/* Output the intermediate format without requiring source
files. This outputs a section to a *single* file. */
- output_intermediate_file (gcov_intermediate_file, src);
+ output_intermediate_file ((flag_use_stdout
+ ? stdout : gcov_intermediate_file), src);
else
- output_gcov_file (file_name, src);
- fnotice (stdout, "\n");
+ {
+ if (flag_use_stdout)
+ {
+ if (src->coverage.lines)
+ output_lines (stdout, src);
+ }
+ else
+ {
+ output_gcov_file (file_name, src);
+ fnotice (stdout, "\n");
+ }
+ }
}
}
- if (flag_gcov_file && flag_intermediate_format)
+ if (flag_gcov_file && flag_intermediate_format && !flag_use_stdout)
{
/* Now we've finished writing the intermediate file. */
fclose (gcov_intermediate_file);