[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Allow raw_assert() to dump stack traces.



commit bb15dc1ebd520cb902124c982abbba135af183b5
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Jun 20 14:04:03 2018 -0400

    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.
---
 src/common/backtrace.c | 20 ++++++++++++++++++++
 src/common/backtrace.h |  1 +
 src/common/torerr.c    |  3 +++
 3 files changed, 24 insertions(+)

diff --git a/src/common/backtrace.c b/src/common/backtrace.c
index af939b0a8..d83cbba0e 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 7182aeb07..0a145fc92 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 c22526254..5dbdc629a 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



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits