Hello.
Motivation of the patch is to display debug counter values after a compilation.
It's handy for bisection of a debug counter. The new output is printed to stderr
(instead of stdout) and it works fine with LTO as well.
Sample output:
counter name counter value closed intervals
-----------------------------------------------------------------
asan_use_after_scope 0 unset
auto_inc_dec 0 unset
ccp 29473 unset
cfg_cleanup 292 unset
cprop 45 unset
cse2_move2add 451 unset
dce 740 unset
dce_fast 15 unset
dce_ud 15 unset
delete_trivial_dead 5747 unset
devirt 0 unset
df_byte_scan 0 unset
dom_unreachable_edges 10 unset
tail_call 393 [1, 4], [100, 200]
...
Ready for master?
Thanks,
Martin
gcc/ChangeLog:
* common.opt: Remove -fdbg-cnt-list from deferred options.
* dbgcnt.c (dbg_cnt_set_limit_by_index): Make a copy
to original_limits.
(dbg_cnt_list_all_counters): Print also current counter value
and print to stderr.
* opts-global.c (handle_common_deferred_options): Do not handle
-fdbg-cnt-list.
* opts.c (common_handle_option): Likewise.
* toplev.c (finalize): Handle it after compilation here.
---
gcc/common.opt | 2 +-
gcc/dbgcnt.c | 25 +++++++++++++++----------
gcc/opts-global.c | 4 ----
gcc/opts.c | 5 -----
gcc/toplev.c | 4 ++++
5 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 292c2de694e..7e789d1c47f 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1202,7 +1202,7 @@ Common Report Var(flag_data_sections)
Place data items into their own section.
fdbg-cnt-list
-Common Report Var(common_deferred_options) Defer
+Common Report Var(flag_dbg_cnt_list)
List all available debugging counters with their limits and counts.
fdbg-cnt=
diff --git a/gcc/dbgcnt.c b/gcc/dbgcnt.c
index 01893ce7238..2a2dd57507d 100644
--- a/gcc/dbgcnt.c
+++ b/gcc/dbgcnt.c
@@ -45,6 +45,7 @@ static struct string2counter_map
map[debug_counter_number_of_counters] =
typedef std::pair<unsigned int, unsigned int> limit_tuple;
static vec<limit_tuple> limits[debug_counter_number_of_counters];
+static vec<limit_tuple> original_limits[debug_counter_number_of_counters];
static unsigned int count[debug_counter_number_of_counters];
@@ -134,6 +135,8 @@ dbg_cnt_set_limit_by_index (enum debug_counter index, const char *name,
}
}
+ original_limits[index] = limits[index].copy ();
+
return true;
}
@@ -226,25 +229,27 @@ void
dbg_cnt_list_all_counters (void)
{
int i;
- printf (" %-30s %s\n", G_("counter name"), G_("closed intervals"));
- printf
("-----------------------------------------------------------------\n");
+ fprintf (stderr, " %-30s%-15s %s\n", G_("counter name"),
+ G_("counter value"), G_("closed intervals"));
+ fprintf (stderr,
"-----------------------------------------------------------------\n");
for (i = 0; i < debug_counter_number_of_counters; i++)
{
- printf (" %-30s ", map[i].name);
- if (limits[i].exists ())
+ fprintf (stderr, " %-30s%-15d ", map[i].name, count[i]);
+ if (original_limits[i].exists ())
{
- for (int j = limits[i].length () - 1; j >= 0; j--)
+ for (int j = original_limits[i].length () - 1; j >= 0; j--)
{
- printf ("[%u, %u]", limits[i][j].first, limits[i][j].second);
+ fprintf (stderr, "[%u, %u]", original_limits[i][j].first,
+ original_limits[i][j].second);
if (j > 0)
- printf (", ");
+ fprintf (stderr, ", ");
}
- putchar ('\n');
+ fprintf (stderr, "\n");
}
else
- printf ("unset\n");
+ fprintf (stderr, "unset\n");
}
- printf ("\n");
+ fprintf (stderr, "\n");
}
#if CHECKING_P
diff --git a/gcc/opts-global.c b/gcc/opts-global.c
index b024ab8e18f..1816acf805b 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -378,10 +378,6 @@ handle_common_deferred_options (void)
dbg_cnt_process_opt (opt->arg);
break;
- case OPT_fdbg_cnt_list:
- dbg_cnt_list_all_counters ();
- break;
-
case OPT_fdebug_prefix_map_:
add_debug_prefix_map (opt->arg);
break;
diff --git a/gcc/opts.c b/gcc/opts.c
index 3bda59afced..da503c32dd0 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2361,11 +2361,6 @@ common_handle_option (struct gcc_options *opts,
/* Deferred. */
break;
- case OPT_fdbg_cnt_list:
- /* Deferred. */
- opts->x_exit_after_options = true;
- break;
-
case OPT_fdebug_prefix_map_:
case OPT_ffile_prefix_map_:
/* Deferred. */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index a4cb8bb262e..8c1e1e1f44f 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -86,6 +86,7 @@ along with GCC; see the file COPYING3. If not see
#include "optinfo-emit-json.h"
#include "ipa-modref-tree.h"
#include "ipa-modref.h"
+#include "dbgcnt.h"
#if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
#include "dbxout.h"
@@ -2213,6 +2214,9 @@ finalize (bool no_backend)
if (profile_report)
dump_profile_report ();
+ if (flag_dbg_cnt_list)
+ dbg_cnt_list_all_counters ();
+
/* Language-specific end of compilation actions. */
lang_hooks.finish ();
}
--
2.28.0