From 6a67ff3523fc9af2c5d0316c8fec2e7375230787 Mon Sep 17 00:00:00 2001 From: Matthieu Volat Date: Sun, 27 Nov 2016 20:31:39 +0100 Subject: [PATCH 1/1] More ptrace portability in model checker. No PTRACE_O_TRACEEXIT equivalent in the original ptrace API, futher work will indicate if this will be a problem. Update message a bit when neither linux's or BSD's version are available. --- src/mc/Client.cpp | 2 +- src/mc/ModelChecker.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/mc/Client.cpp b/src/mc/Client.cpp index e2f389d046..e712affd25 100644 --- a/src/mc/Client.cpp +++ b/src/mc/Client.cpp @@ -73,7 +73,7 @@ Client* Client::initialize() #elif defined BSD ptrace(PT_TRACE_ME, 0, nullptr, 0); #else -# error "ptrace not declared on this platform" +# error "no ptrace equivalent coded for this platform" #endif if(errno != 0 || raise(SIGSTOP) != 0) xbt_die("Could not wait for the model-checker"); diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index 6aff9c463f..160074896a 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -108,8 +108,14 @@ void ModelChecker::start() setup_ignore(); +#ifdef __linux__ ptrace(PTRACE_SETOPTIONS, pid, nullptr, PTRACE_O_TRACEEXIT); ptrace(PTRACE_CONT, pid, 0, 0); +#elif defined BSD + ptrace(PT_CONTINUE, pid, (caddr_t)1, 0); +#else +# error "no ptrace equivalent coded for this platform" +#endif } static const std::pair ignored_local_variables[] = { @@ -399,6 +405,7 @@ void ModelChecker::handle_waitpid() if (pid == this->process().pid()) { // From PTRACE_O_TRACEEXIT: +#ifdef __linux__ if (status>>8 == (SIGTRAP | (PTRACE_EVENT_EXIT<<8))) { if (ptrace(PTRACE_GETEVENTMSG, this->process().pid(), 0, &status) == -1) xbt_die("Could not get exit status"); @@ -407,11 +414,18 @@ void ModelChecker::handle_waitpid() mc_model_checker->exit(SIMGRID_MC_EXIT_PROGRAM_CRASH); } } +#endif // We don't care about signals, just reinject them: if (WIFSTOPPED(status)) { XBT_DEBUG("Stopped with signal %i", (int) WSTOPSIG(status)); - if (ptrace(PTRACE_CONT, this->process().pid(), 0, WSTOPSIG(status)) == -1) + errno = 0; +#ifdef __linux__ + ptrace(PTRACE_CONT, this->process().pid(), 0, WSTOPSIG(status)); +#elif defined BSD + ptrace(PT_CONTINUE, this->process().pid(), nullptr, WSTOPSIG(status)); +#endif + if (errno != 0) xbt_die("Could not PTRACE_CONT"); } -- 2.20.1