aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-20 14:04:03 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-20 16:16:45 -0400
commitbb15dc1ebd520cb902124c982abbba135af183b5 (patch)
tree473c77b4e667c3899cdafe027d3b3866dee479d5
parenta969ce464dc23db39725a891d60537f3d3e51b50 (diff)
downloadtor-bb15dc1ebd520cb902124c982abbba135af183b5.tar.gz
tor-bb15dc1ebd520cb902124c982abbba135af183b5.zip
Allow raw_assert() to dump stack traces.
It doesn't do this as beautifully as tor_assert(), but it doesn't depend on any higher-level code.
-rw-r--r--src/common/backtrace.c20
-rw-r--r--src/common/backtrace.h1
-rw-r--r--src/common/torerr.c3
3 files changed, 24 insertions, 0 deletions
diff --git a/src/common/backtrace.c b/src/common/backtrace.c
index af939b0a8a..d83cbba0e8 100644
--- a/src/common/backtrace.c
+++ b/src/common/backtrace.c
@@ -167,6 +167,21 @@ crash_handler(int sig, siginfo_t *si, void *ctx_)
abort();
}
+/** Write a backtrace to all of the emergency-error fds. */
+void
+dump_stack_symbols_to_error_fds(void)
+{
+ int n_fds, i;
+ const int *fds = NULL;
+ size_t depth;
+
+ depth = backtrace(cb_buf, MAX_DEPTH);
+
+ n_fds = tor_log_get_sigsafe_err_fds(&fds);
+ for (i=0; i < n_fds; ++i)
+ backtrace_symbols_fd(cb_buf, (int)depth, fds[i]);
+}
+
/** Install signal handlers as needed so that when we crash, we produce a
* useful stack trace. Return 0 on success, -errno on failure. */
static int
@@ -234,6 +249,11 @@ static void
remove_bt_handler(void)
{
}
+
+void
+dump_stack_symbols_to_error_fds(void)
+{
+}
#endif /* defined(NO_BACKTRACE_IMPL) */
/** Set up code to handle generating error messages on crashes. */
diff --git a/src/common/backtrace.h b/src/common/backtrace.h
index 7182aeb07c..0a145fc92d 100644
--- a/src/common/backtrace.h
+++ b/src/common/backtrace.h
@@ -14,6 +14,7 @@ void log_backtrace_impl(int severity, int domain, const char *msg,
tor_log_fn logger);
int configure_backtrace_handler(const char *tor_version);
void clean_up_backtrace_handler(void);
+void dump_stack_symbols_to_error_fds(void);
#define log_backtrace(sev, dom, msg) \
log_backtrace_impl((sev), (dom), (msg), tor_log)
diff --git a/src/common/torerr.c b/src/common/torerr.c
index c225262545..5dbdc629ad 100644
--- a/src/common/torerr.c
+++ b/src/common/torerr.c
@@ -29,6 +29,7 @@
#endif
#include "common/torerr.h"
+#include "common/backtrace.h"
/** Array of fds to log crash-style warnings to. */
static int sigsafe_log_fds[TOR_SIGSAFE_LOG_MAX_FDS] = { STDERR_FILENO };
@@ -140,6 +141,8 @@ tor_raw_assertion_failed_msg_(const char *file, int line, const char *expr,
tor_log_err_sigsafe_write(msg);
tor_log_err_sigsafe_write("\n");
}
+
+ dump_stack_symbols_to_error_fds();
}
/* As format_{hex,dex}_number_sigsafe, but takes a <b>radix</b> argument