gcc/ChangeLog:

2019-03-27  Martin Liska  <mli...@suse.cz>

        * dbgcnt.c (print_limit_reach): New function.
        (dbg_cnt): Use it.
---
 gcc/dbgcnt.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/gcc/dbgcnt.c b/gcc/dbgcnt.c
index 5a7c9a8bf6e..cfa03d611ee 100644
--- a/gcc/dbgcnt.c
+++ b/gcc/dbgcnt.c
@@ -59,21 +59,27 @@ dbg_cnt_is_enabled (enum debug_counter index)
   return v > limit_low[index] && v <= limit_high[index];
 }
 
+static void
+print_limit_reach (const char *counter, int limit, bool upper_p)
+{
+  char buffer[128];
+  sprintf (buffer, "***dbgcnt: %s limit %d reached for %s.***\n",
+	   upper_p ? "upper" : "lower", limit, counter);
+  fputs (buffer, stderr);
+  if (dump_file)
+    fputs (buffer, dump_file);
+}
+
 bool
 dbg_cnt (enum debug_counter index)
 {
   count[index]++;
 
-  if (dump_file)
-    {
-      /* Do not print the info for default lower limit.  */
-      if (count[index] == limit_low[index] && limit_low[index] > 0)
-	fprintf (dump_file, "***dbgcnt: lower limit %d reached for %s.***\n",
-		 limit_low[index], map[index].name);
-      else if (count[index] == limit_high[index])
-	fprintf (dump_file, "***dbgcnt: upper limit %d reached for %s.***\n",
-		 limit_high[index], map[index].name);
-    }
+  /* Do not print the info for default lower limit.  */
+  if (count[index] == limit_low[index] && limit_low[index] > 0)
+    print_limit_reach (map[index].name, limit_low[index], false);
+  else if (count[index] == limit_high[index])
+    print_limit_reach (map[index].name, limit_high[index], true);
 
   return dbg_cnt_is_enabled (index);
 }

Reply via email to