Commit 59995558 by Vicent Marti

Fix segfault handler in Mac OS X

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 691aa968
...@@ -32,48 +32,21 @@ ...@@ -32,48 +32,21 @@
* GCC only * GCC only
*/ */
#ifdef __GNUC__ #ifdef __GNUC__
#include <stdio.h>
#include <execinfo.h> #include <execinfo.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <ucontext.h>
#include <unistd.h>
typedef struct _sig_ucontext { void crash_handler(int sig)
unsigned long uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
struct sigcontext uc_mcontext;
sigset_t uc_sigmask;
} sig_ucontext_t;
void crash_handler(int sig_num, siginfo_t *info, void *ucontext)
{ {
void *array[50]; void *array[10];
void *caller_address; size_t size;
char **messages;
int size, i;
sig_ucontext_t *uc;
uc = (sig_ucontext_t *)ucontext;
caller_address = (void *)uc->uc_mcontext.eip;
fprintf(stderr, "Signal %d (%s), address: %p from %p\n",
sig_num, strsignal(sig_num), info->si_addr,
(void *)caller_address);
size = backtrace(array, 50);
array[1] = caller_address;
messages = backtrace_symbols(array, size);
for (i = 1; i < size && messages != NULL; ++i) size = backtrace(array, 10);
fprintf(stderr, "\t(%d) %s\n", i, messages[i]);
free(messages); fprintf(stderr, "Error (signal %d)\n", sig);
exit(EXIT_FAILURE); backtrace_symbols_fd(array, size, 2);
exit(1);
} }
#endif #endif
...@@ -99,10 +72,7 @@ int main(int argc, char **argv) ...@@ -99,10 +72,7 @@ int main(int argc, char **argv)
struct test_def *t; struct test_def *t;
#ifdef __GNUC__ #ifdef __GNUC__
struct sigaction sigact; signal(SIGSEGV, crash_handler);
sigact.sa_sigaction = crash_handler;
sigact.sa_flags = SA_RESTART | SA_SIGINFO;
sigaction(SIGSEGV, &sigact, (struct sigaction *)NULL);
#endif #endif
if (argc == 1) { if (argc == 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment