Skip to content

Commit 57ecd7d

Browse files
author
ex0dus-0x
committed
Improve backtrace routine
1 parent 862c725 commit 57ecd7d

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/include/deepstate/DeepState.h

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
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>
@@ -59,6 +60,10 @@
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. */
527532
static 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
714737
DeepState_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();

src/lib/DeepState.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ DEFINE_bool(abort_on_fail, ExecutionGroup, false, "Abort on file replay failure
4343
DEFINE_bool(exit_on_fail, ExecutionGroup, false, "Exit with status 255 on test failure.");
4444
DEFINE_int(min_log_level, ExecutionGroup, 0, "Minimum level of logging to output (default 2, 0=debug, 1=trace, 2=info, ...).");
4545
DEFINE_int(timeout, ExecutionGroup, 120, "Timeout for brute force fuzzing.");
46-
DEFINE_uint(num_workers, ExecutionGroup, 1, "Number of workers to spawn for testing and test generation.");
4746
DEFINE_bool(verbose_reads, ExecutionGroup, false, "Report on bytes being read during execution of test.");
4847
DEFINE_bool(verbose_crash_trace, ExecutionGroup, false, "If test crashes, report an execution backtrace after abrupt exit.");
4948

0 commit comments

Comments
 (0)