mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
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.
This commit is contained in:
@@ -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. */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user