This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] [debug] Added DEBUG_FUNCTION void dump_backtrace.

	* diagnostic-core.h: Declare dump_backtrace (void).
	* diagnostic.c: Define it.

Just realized that I've submitted an unintended hunk in [PATCH 3/4]
(  I didn't
notice that I'd left a tracing line in 'gcc/cp/decl.c'.  This patch
resolves the missing function.  Or you can just skip that change.

I've found this a useful tool when hacking on GCC before I found out
about '-wrapper gdb,--args'.  I cherry-pick it whenever I want to find
out where something is called without stopping the compiler.  Don't
know if any one else would find use in it.


 gcc/diagnostic-core.h |  1 +
 gcc/diagnostic.c      | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index a210782..e204340 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -78,6 +78,7 @@ extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern bool emit_diagnostic (diagnostic_t, location_t, int,
 			     const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
 extern bool seen_error (void);
+extern void dump_backtrace (void);
 #ifdef BUFSIZ
   /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 2ec9620..0f12a38 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -1111,6 +1111,19 @@ fatal_error (const char *gmsgid, ...)
   gcc_unreachable ();
+/* Intended for compiler developers to trace the compiler's call stack
+   to stderr without affecting compilation state.  The trace generated
+   here is the same as would occur with an ICE.  */
+dump_backtrace (void)
+  struct backtrace_state *state =
+    backtrace_create_state (NULL, 0, bt_err_callback, NULL);
+  int count = 0;
+  if (state != NULL)
+    backtrace_full (state, 2, bt_callback, bt_err_callback, (void *) &count);
 /* 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]