diff mbox series

[pushed] gcov: add more debugging facility

Message ID 251dadb2-4116-7ae9-c043-cb59163da105@suse.cz
State New
Headers show
Series [pushed] gcov: add more debugging facility | expand

Commit Message

Martin Liška Jan. 12, 2021, 11:55 a.m. UTC
The patch is about an extensive debugging facility that I see
beneficial for GCOV issue.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
I'm going to push it.

Thanks,
Martin

gcc/ChangeLog:

	* gcov.c (source_info::debug): New.
	(print_usage): Add --debug (-D) option.
	(process_args): Likewise.
	(generate_results): Call src->debug after
	accumulate_line_counts.
	(read_graph_file): Properly assign id for EXIT_BLOCK.
	* profile.c (branch_prob): Dump function body before it is
	instrumented.
---
  gcc/gcov.c    | 43 ++++++++++++++++++++++++++++++++++++++++++-
  gcc/profile.c |  5 +++++
  2 files changed, 47 insertions(+), 1 deletion(-)

Comments

H.J. Lu Jan. 12, 2021, 4:27 p.m. UTC | #1
On Tue, Jan 12, 2021 at 3:55 AM Martin Liška <mliska@suse.cz> wrote:
>
> The patch is about an extensive debugging facility that I see
> beneficial for GCOV issue.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> I'm going to push it.
>
> Thanks,
> Martin
>
> gcc/ChangeLog:
>
>         * gcov.c (source_info::debug): New.
>         (print_usage): Add --debug (-D) option.
>         (process_args): Likewise.
>         (generate_results): Call src->debug after
>         accumulate_line_counts.
>         (read_graph_file): Properly assign id for EXIT_BLOCK.
>         * profile.c (branch_prob): Dump function body before it is
>         instrumented.
> ---
>   gcc/gcov.c    | 43 ++++++++++++++++++++++++++++++++++++++++++-
>   gcc/profile.c |  5 +++++
>   2 files changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/gcov.c b/gcc/gcov.c
> index 01ca52b215d..93128721ef6 100644
> --- a/gcc/gcov.c
> +++ b/gcc/gcov.c
> @@ -371,6 +371,9 @@ public:
>     /* Register a new function.  */
>     void add_function (function_info *fn);
>
> +  /* Debug the source file.  */
> +  void debug ();
> +
>     /* Index of the source_info in sources vector.  */
>     unsigned index;
>
> @@ -428,6 +431,31 @@ source_info::get_functions_at_location (unsigned line_num) const
>     return slot;
>   }
>
> +void source_info::debug ()
> +{
> +  fprintf (stderr, "source_info: %s\n", name);
> +  for (vector<function_info *>::iterator it = functions.begin ();
> +       it != functions.end (); it++)
> +    {
> +      function_info *fn = *it;
> +      fprintf (stderr, "  function_info: %s\n", fn->get_name ());
> +      for (vector<block_info>::iterator bit = fn->blocks.begin ();
> +          bit != fn->blocks.end (); bit++)
> +       {
> +         fprintf (stderr, "    block_info id=%d, count=%ld\n",
> +                  bit->id, bit->count);
> +       }
> +    }
> +
> +  for (unsigned lineno = 1; lineno < lines.size (); ++lineno)
> +    {
> +      line_info &line = lines[lineno];
> +      fprintf (stderr, "  line_info=%d, count=%ld\n", lineno, line.count);
> +    }
> +
> +  fprintf (stderr, "\n");
> +}
> +

This breaks build on 32-bit hosts:

https://gcc.gnu.org/pipermail/gcc-regression/2021-January/074130.html
Martin Liška Jan. 12, 2021, 5:17 p.m. UTC | #2
On 1/12/21 5:27 PM, H.J. Lu wrote:
> This breaks build on 32-bit hosts:

Sorry for that.

Should be fixed with:

commit 248feb2fa2c0dfc8950566010b30351879c9d057
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Jan 12 18:16:05 2021 +0100

     gcov: fix printf format for 32-bit hosts
     
     gcc/ChangeLog:
     
             * gcov.c (source_info::debug): Fix printf format for 32-bit hosts.

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 93128721ef6..5c651a9bdce 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -442,7 +442,7 @@ void source_info::debug ()
        for (vector<block_info>::iterator bit = fn->blocks.begin ();
  	   bit != fn->blocks.end (); bit++)
  	{
-	  fprintf (stderr, "    block_info id=%d, count=%ld\n",
+	  fprintf (stderr, "    block_info id=%d, count=%" PRId64 " \n",
  		   bit->id, bit->count);
  	}
      }
@@ -450,7 +450,7 @@ void source_info::debug ()
    for (unsigned lineno = 1; lineno < lines.size (); ++lineno)
      {
        line_info &line = lines[lineno];
-      fprintf (stderr, "  line_info=%d, count=%ld\n", lineno, line.count);
+      fprintf (stderr, "  line_info=%d, count=%" PRId64 "\n", lineno, line.count);
      }
  
    fprintf (stderr, "\n");

I'm going to install the patch.
Martin
diff mbox series

Patch

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 01ca52b215d..93128721ef6 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -371,6 +371,9 @@  public:
    /* Register a new function.  */
    void add_function (function_info *fn);
  
+  /* Debug the source file.  */
+  void debug ();
+
    /* Index of the source_info in sources vector.  */
    unsigned index;
  
@@ -428,6 +431,31 @@  source_info::get_functions_at_location (unsigned line_num) const
    return slot;
  }
  
+void source_info::debug ()
+{
+  fprintf (stderr, "source_info: %s\n", name);
+  for (vector<function_info *>::iterator it = functions.begin ();
+       it != functions.end (); it++)
+    {
+      function_info *fn = *it;
+      fprintf (stderr, "  function_info: %s\n", fn->get_name ());
+      for (vector<block_info>::iterator bit = fn->blocks.begin ();
+	   bit != fn->blocks.end (); bit++)
+	{
+	  fprintf (stderr, "    block_info id=%d, count=%ld\n",
+		   bit->id, bit->count);
+	}
+    }
+
+  for (unsigned lineno = 1; lineno < lines.size (); ++lineno)
+    {
+      line_info &line = lines[lineno];
+      fprintf (stderr, "  line_info=%d, count=%ld\n", lineno, line.count);
+    }
+
+  fprintf (stderr, "\n");
+}
+
  class name_map
  {
  public:
@@ -579,6 +607,10 @@  static int flag_human_readable_numbers = 0;
  
  static int flag_function_summary = 0;
  
+/* Print debugging dumps.  */
+
+static int flag_debug = 0;
+
  /* Object directory file prefix.  This is the directory/file where the
     graph and data files are looked for, if nonzero.  */
  
@@ -896,6 +928,7 @@  print_usage (int error_p)
    fnotice (file, "  -c, --branch-counts             Output counts of branches taken\n\
                                      rather than percentages\n");
    fnotice (file, "  -d, --display-progress          Display progress information\n");
+  fnotice (file, "  -D, --debug			    Display debugging dumps\n");
    fnotice (file, "  -f, --function-summaries        Output summaries for each function\n");
    fnotice (file, "  -h, --help                      Print this help, then exit\n");
    fnotice (file, "  -j, --json-format               Output JSON intermediate format\n\
@@ -963,6 +996,7 @@  static const struct option options[] =
    { "hash-filenames",	    no_argument,       NULL, 'x' },
    { "use-colors",	    no_argument,       NULL, 'k' },
    { "use-hotness-colors",   no_argument,       NULL, 'q' },
+  { "debug",		    no_argument,       NULL, 'D' },
    { 0, 0, 0, 0 }
  };
  
@@ -973,7 +1007,7 @@  process_args (int argc, char **argv)
  {
    int opt;
  
-  const char *opts = "abcdfhHijklmno:pqrs:tuvwx";
+  const char *opts = "abcdDfhHijklmno:pqrs:tuvwx";
    while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
      {
        switch (opt)
@@ -1044,6 +1078,9 @@  process_args (int argc, char **argv)
  	case 't':
  	  flag_use_stdout = 1;
  	  break;
+	case 'D':
+	  flag_debug = 1;
+	  break;
  	case 'v':
  	  print_version ();
  	  /* print_version will exit.  */
@@ -1466,6 +1503,8 @@  generate_results (const char *file_name)
  	}
  
        accumulate_line_counts (src);
+      if (flag_debug)
+	src->debug ();
  
        if (!flag_use_stdout)
  	file_summary (&src->coverage);
@@ -1804,6 +1843,8 @@  read_graph_file (void)
  	      arc = XCNEW (arc_info);
  
  	      arc->dst = &fn->blocks[dest];
+	      /* Set id in order to find EXIT_BLOCK.  */
+	      arc->dst->id = dest;
  	      arc->src = src_blk;
  
  	      arc->count = 0;
diff --git a/gcc/profile.c b/gcc/profile.c
index d629687484b..1f1d60c8180 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -1294,6 +1294,11 @@  branch_prob (bool thunk)
    if (dump_file)
      fprintf (dump_file, "%d instrumentation edges\n", num_instrumented);
  
+  /* Dump function body before it's instrumented.
+     It helps to debug gcov tool.  */
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    dump_function_to_file (cfun->decl, dump_file, dump_flags);
+
    /* Compute two different checksums. Note that we want to compute
       the checksum in only once place, since it depends on the shape
       of the control flow which can change during