public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: gcc-patches@gcc.gnu.org
Cc: Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] Dump function on internal errors
Date: Mon, 22 May 2017 14:26:00 -0000	[thread overview]
Message-ID: <20170522141905.9112-1-andi@firstfloor.org> (raw)

From: Andi Kleen <ak@linux.intel.com>

When a verification check fails it is useful to dump the current
function to the dump file, so it's easier to figure out what
actually went wrong.

v2: Updated version now using a hook in internal_error, and
also prints the pass name and the dump file name.

gcc/:

2017-05-21  Andi Kleen  <ak@linux.intel.com>

        * diagnostic.c (internal_error): Call hook.
        (set_internal_error_hook): New function.
        * diagnostic.h: Add set_internal_error_hook.
        * passes.c: (pass_ice_hook): Add class to set
	internal_error_hook to dump functions.
---
 gcc/diagnostic.c | 18 ++++++++++++++++++
 gcc/diagnostic.h |  1 +
 gcc/passes.c     | 21 +++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 158519606f8..8d9caade60b 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -33,6 +33,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-color.h"
 #include "edit-context.h"
 #include "selftest.h"
+#include "tree.h"
+#include "tree-pass.h"
+#include "tree-cfg.h"
 
 #ifdef HAVE_TERMIOS_H
 # include <termios.h>
@@ -1396,6 +1399,10 @@ fatal_error (location_t loc, const char *gmsgid, ...)
   gcc_unreachable ();
 }
 
+/* Hook to call on internal errors.  */
+
+static void (*internal_error_hook)();
+
 /* An internal consistency check has failed.  We make no attempt to
    continue.  Note that unless there is debugging value to be had from
    a more specific message, or some other good reason, you should use
@@ -1403,6 +1410,9 @@ fatal_error (location_t loc, const char *gmsgid, ...)
 void
 internal_error (const char *gmsgid, ...)
 {
+  if (internal_error_hook)
+    internal_error_hook ();
+
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
@@ -1412,6 +1422,14 @@ internal_error (const char *gmsgid, ...)
   gcc_unreachable ();
 }
 
+/* Call HOOK on internal errors.  */
+
+void
+set_internal_error_hook (void (*hook)())
+{
+  internal_error_hook = hook;
+}
+
 /* Like internal_error, but no backtrace will be printed.  Used when
    the internal error does not happen at the current location, but happened
    somewhere else.  */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index dbd1703e0ef..3d26a84ab44 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -369,5 +369,6 @@ extern char *file_name_as_prefix (diagnostic_context *, const char *);
 
 extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
 
+extern void set_internal_error_hook (void (*)());
 
 #endif /* ! GCC_DIAGNOSTIC_H */
diff --git a/gcc/passes.c b/gcc/passes.c
index e7c5d194010..1bd92c8140a 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -3040,4 +3040,25 @@ function_called_by_processed_nodes_p (void)
   return e != NULL;
 }
 
+class pass_ice_hook {
+
+  /* Print function to dump file on internal errors.  */
+
+  static void ice_hook() {
+    if (dump_file)
+      {
+	fprintf (stderr, "Dumping function to dump file %s for pass %s\n",
+		 dump_file_name, current_pass->name);
+	dump_function_to_file (current_function_decl, dump_file, dump_flags);
+      }
+  }
+
+ public:
+  pass_ice_hook() {
+    set_internal_error_hook (ice_hook);
+  }
+};
+
+static pass_ice_hook pass_ice_hook;
+
 #include "gt-passes.h"
-- 
2.12.2

             reply	other threads:[~2017-05-22 14:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-22 14:26 Andi Kleen [this message]
2017-05-24 13:45 ` Richard Biener
2017-05-29 16:22   ` Alexander Monakov
2017-05-29 16:24     ` Jakub Jelinek
2017-05-29 16:42       ` Alexander Monakov
2017-05-29 16:51         ` Alexander Monakov
2017-05-29 16:53           ` Jakub Jelinek
2017-05-29 16:46     ` Andi Kleen
2017-05-29 19:33     ` Alexander Monakov
2017-05-30  7:44       ` Richard Biener
2017-05-30 10:35         ` Alexander Monakov

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=20170522141905.9112-1-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --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).