Skip to content

Commit bdd0c63

Browse files
author
ex0dus-0x
committed
Cleanup
1 parent 4e45f4e commit bdd0c63

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

src/include/deepstate/DeepState.h

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
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);
529529
extern 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
}

src/lib/DeepState.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
#define __USE_GNU
18+
1719
#include "deepstate/DeepState.h"
1820
#include "deepstate/Option.h"
1921
#include "deepstate/Log.h"
@@ -44,7 +46,7 @@ DEFINE_bool(exit_on_fail, ExecutionGroup, false, "Exit with status 255 on test f
4446
DEFINE_int(min_log_level, ExecutionGroup, 0, "Minimum level of logging to output (default 2, 0=debug, 1=trace, 2=info, ...).");
4547
DEFINE_int(timeout, ExecutionGroup, 120, "Timeout for brute force fuzzing.");
4648
DEFINE_bool(verbose_reads, ExecutionGroup, false, "Report on bytes being read during execution of test.");
47-
DEFINE_bool(verbose_crash_trace, ExecutionGroup, false, "If test crashes, report an execution backtrace after abrupt exit.");
49+
DEFINE_bool(verbose_crash_trace, ExecutionGroup, false, "If test crashes on a fork, report an execution backtrace after abrupt exit.");
4850

4951
/* Fuzzing and symex related options, baked in to perform analysis-related tasks without auxiliary tools */
5052
DEFINE_bool(fuzz, AnalysisGroup, false, "Perform brute force unguided fuzzing.");

0 commit comments

Comments
 (0)