diff options
author | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-09-28 10:39:52 -0700 |
---|---|---|
committer | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-09-28 10:39:52 -0700 |
commit | f2eb040872a74818b144bf8bb28e8e17055f2923 (patch) | |
tree | d9deaf63dc7a9160710d1edbb2ec7ce42a9e07e5 /test/core | |
parent | 72d4593406c64f25c8efb0e26c48ea5110fa50d7 (diff) | |
parent | 2bc37297c8e0f268115b46604ed5f85371e5f679 (diff) |
Merge pull request #3544 from ctiller/backtrace-on-crash
Enable backtraces on C tests
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/util/test_config.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 <execinfo.h> +#include <stdio.h> +#include <string.h> +#include <grpc/support/useful.h> + +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 |