3636#include < unistd.h>
3737#include < fnmatch.h>
3838#include < execinfo.h>
39- #include < dlfcn .h>
39+ #include < ucontext .h>
4040
4141#include < deepstate/Log.h>
4242#include < deepstate/Compiler.h>
@@ -529,23 +529,24 @@ extern void DeepState_SaveFailingTest(void);
529529extern void DeepState_SaveCrashingTest (void );
530530
531531/* Emit test function backtrace after test crashes. */
532- static void DeepState_EmitBacktrace (int signum, siginfo_t *sig, void *context ) {
532+ static void DeepState_EmitBacktrace (int signum, siginfo_t *sig, void *_context ) {
533533
534+ /* output information about the signal caught and the exception that occurred */
534535 const char *result;
535536 if (!sig->si_status )
536537 result = sys_siglist[signum];
537538 else
538539 result = sys_siglist[sig->si_status ];
540+ DeepState_LogFormat (DeepState_LogError, " Signal caught in test: %s (%d)" , result, sig->si_signo );
539541
540- DeepState_LogFormat (DeepState_LogInfo, " Test crashed with: %s" , result);
541-
542- // TODO: add line number of crash (ie. addr2line)
542+ ucontext_t *context = (ucontext_t *) _context;
543+ // printf("%lx", context->uc_mcontext.gregs[REG_EIP]);
543544
545+ /* return a backtrace */
546+ size_t size;
544547 void *back_addrs[DEEPSTATE_CRASH_MAX_FRAMES];
545548 char **symbols;
546549
547- size_t size;
548-
549550 size = backtrace (back_addrs, DEEPSTATE_CRASH_MAX_FRAMES);
550551 if (size == 0 )
551552 DeepState_Abandon (" Cannot retrieve backtrace stack addresses" );
@@ -554,8 +555,6 @@ static void DeepState_EmitBacktrace(int signum, siginfo_t *sig, void *context) {
554555 if (symbols == NULL )
555556 DeepState_Abandon (" Cannot retrieve symbols for stack addresses" );
556557
557- // TODO: demangle and resolve, also do for Darwin/BSD
558-
559558 DeepState_LogFormat (DeepState_LogTrace, " ======= Backtrace: =========" );
560559 for (size_t i = 0 ; i < size; i++)
561560 DeepState_LogFormat (DeepState_LogTrace, " %s" , symbols[i]);
@@ -740,12 +739,11 @@ DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) {
740739
741740 /* If flag is set, install a signal handler for SIGCHLD */
742741 if (FLAGS_verbose_crash_trace) {
743- struct sigaction sigact, oldact;
744-
745- sigact.sa_flags = SA_SIGINFO | SA_NOCLDWAIT;
742+ struct sigaction sigact;
743+ sigact.sa_flags = SA_SIGINFO | SA_NODEFER;
746744 sigact.sa_sigaction = DeepState_EmitBacktrace;
747745
748- sigaction (SIGCHLD, &sigact, &oldact );
746+ sigaction (SIGCHLD, &sigact, 0 );
749747 }
750748
751749 test_pid = fork ();
@@ -759,18 +757,7 @@ DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) {
759757 waitpid (test_pid, &wstatus, 0 );
760758 } else {
761759
762- /* If flag is set, install a signal handler for any arbitrary crash*/
763- if (FLAGS_verbose_crash_trace) {
764-
765- struct sigaction sigact, oldact;
766-
767- sigact.sa_flags = SA_SIGINFO | SA_NODEFER;
768- sigact.sa_sigaction = DeepState_EmitBacktrace;
769-
770- sigaction (SIGBUS, &sigact, &oldact);
771- sigaction (SIGSEGV, &sigact, &oldact);
772- }
773-
760+ /* TODO: install multiplexer signal handler, since we need to handle more than SIGCHLD */
774761 wstatus = DeepState_RunTestNoFork (test);
775762 DeepState_CleanUp ();
776763 }
0 commit comments