aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-09-28 10:08:21 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-09-28 10:08:21 -0700
commit2bc37297c8e0f268115b46604ed5f85371e5f679 (patch)
treeaa5f8c7da9026a308ae5ae82b92b8e43037d2193 /test/core
parentd4509a16b38dc6e4a0dacbdad074accfe7894696 (diff)
Enable backtraces on C tests
Diffstat (limited to 'test/core')
-rw-r--r--test/core/util/test_config.c44
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