This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] [debug] Added DEBUG_FUNCTION void dump_backtrace.
- From: Adam Butcher <adam at jessamine dot co dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Jason Merrill <jason at redhat dot com>, Adam Butcher <adam at jessamine dot co dot uk>
- Date: Tue, 2 Jul 2013 01:01:34 +0100
- Subject: [PATCH] [debug] Added DEBUG_FUNCTION void dump_backtrace.
- References: <1372721221-6201-1-git-send-email-adam at jessamine dot co dot uk>
* diagnostic-core.h: Declare dump_backtrace (void).
* diagnostic.c: Define it.
---
Just realized that I've submitted an unintended hunk in [PATCH 3/4]
(http://gcc.gnu.org/ml/gcc-patches/2013-07/msg00042.html). 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.
Cheers,
Adam
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. */
+DEBUG_FUNCTION void
+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
--
1.8.3