From 2bc37297c8e0f268115b46604ed5f85371e5f679 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 28 Sep 2015 10:08:21 -0700 Subject: Enable backtraces on C tests --- test/core/util/test_config.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'test/core') diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c index 168b98fe63..c3d356c1f2 100644 --- a/test/core/util/test_config.c +++ b/test/core/util/test_config.c @@ -83,6 +83,50 @@ static void install_crash_handler() { _set_abort_behavior(0, _CALL_REPORTFAULT); signal(SIGABRT, abort_handler); } +#elif GPR_POSIX_CRASH_HANDLER +#include +#include +#include +#include + +static char g_alt_stack[8192]; + +#define MAX_FRAMES 32 + +static void crash_handler(int signum, siginfo_t *info, void *data) { + void *addrlist[MAX_FRAMES + 1]; + int addrlen; + int i; + char **symlist; + + fprintf(stderr, "Caught signal %d\n", signum); + addrlen = backtrace(addrlist, GPR_ARRAY_SIZE(addrlist)); + + symlist = backtrace_symbols(addrlist, addrlen); + for (i = 0; i < addrlen; i++) { + fprintf(stderr, " %s\n", symlist[i]); + } + free(symlist); + + raise(signum); +} + +static void install_crash_handler() { + stack_t ss; + struct sigaction sa; + memset(&ss, 0, sizeof(ss)); + memset(&sa, 0, sizeof(sa)); + ss.ss_size = sizeof(g_alt_stack); + ss.ss_sp = g_alt_stack; + GPR_ASSERT(sigaltstack(&ss, NULL) == 0); + sa.sa_flags = (int)(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); + sa.sa_sigaction = crash_handler; + GPR_ASSERT(sigaction(SIGILL, &sa, NULL) == 0); + GPR_ASSERT(sigaction(SIGABRT, &sa, NULL) == 0); + GPR_ASSERT(sigaction(SIGBUS, &sa, NULL) == 0); + GPR_ASSERT(sigaction(SIGSEGV, &sa, NULL) == 0); + GPR_ASSERT(sigaction(SIGSTKFLT, &sa, NULL) == 0); +} #else static void install_crash_handler() {} #endif -- cgit v1.2.3