3636#include < unistd.h>
3737#include < fnmatch.h>
3838#include < execinfo.h>
39+ #include < dlfcn.h>
3940
4041#include < deepstate/Log.h>
4142#include < deepstate/Compiler.h>
5960#define DEEPSTATE_SIZE 8192
6061#endif
6162
63+ #ifndef DEEPSTATE_CRASH_MAX_FRAMES
64+ #define DEEPSTATE_CRASH_MAX_FRAMES 63
65+ #endif
66+
6267#ifndef DEEPSTATE_MAX_SWARM_CONFIGS
6368#define DEEPSTATE_MAX_SWARM_CONFIGS 1024
6469#endif
@@ -526,19 +531,37 @@ extern void DeepState_SaveCrashingTest(void);
526531/* Emit test function backtrace after test crashes. */
527532static void DeepState_EmitBacktrace (int signum, siginfo_t *sig, void *context) {
528533
529- DeepState_LogFormat (DeepState_LogInfo, " Test crashed with: %s" , sys_siglist[sig->si_status ]);
534+ const char *result;
535+ if (!sig->si_status )
536+ result = sys_siglist[signum];
537+ else
538+ result = sys_siglist[sig->si_status ];
539+
540+ DeepState_LogFormat (DeepState_LogInfo, " Test crashed with: %s" , result);
541+
542+ // TODO: add line number of crash (ie. addr2line)
543+
544+ void *back_addrs[DEEPSTATE_CRASH_MAX_FRAMES];
545+ char **symbols;
530546
531- void *array[10 ];
532547 size_t size;
533- char **strings;
534548
535- size = backtrace (array, 10 );
536- strings = backtrace_symbols (array, size);
549+ size = backtrace (back_addrs, DEEPSTATE_CRASH_MAX_FRAMES);
550+ if (size == 0 )
551+ DeepState_Abandon (" Cannot retrieve backtrace stack addresses" );
552+
553+ symbols = backtrace_symbols (back_addrs, size);
554+ if (symbols == NULL )
555+ DeepState_Abandon (" Cannot retrieve symbols for stack addresses" );
537556
557+ // TODO: demangle and resolve, also do for Darwin/BSD
558+
559+ DeepState_LogFormat (DeepState_LogTrace, " ======= Backtrace: =========" );
538560 for (size_t i = 0 ; i < size; i++)
539- DeepState_LogFormat (DeepState_LogTrace, " %s" , strings[i]);
561+ DeepState_LogFormat (DeepState_LogTrace, " %s" , symbols[i]);
562+ DeepState_LogFormat (DeepState_LogTrace, " ===========================" );
540563
541- free (strings );
564+ free (symbols );
542565}
543566
544567
@@ -714,7 +737,7 @@ static enum DeepState_TestRunResult
714737DeepState_ForkAndRunTest (struct DeepState_TestInfo *test) {
715738
716739 /* If flag is set, install a signal handler for SIGCHLD */
717- /* TODO(alan): use handler as "multiplexer" and handle child signal */
740+ /* TODO(alan): use handler as robust "multiplexer" and handle child signal */
718741 if (FLAGS_verbose_crash_trace) {
719742 struct sigaction sigact, oldact;
720743
@@ -724,7 +747,6 @@ DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) {
724747 sigaction (SIGCHLD, &sigact, &oldact);
725748 }
726749
727-
728750 pid_t test_pid;
729751 if (FLAGS_fork) {
730752 test_pid = fork ();
0 commit comments