Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More ptrace portability in model checker.
authorMatthieu Volat <mazhe@alkumuna.eu>
Sun, 27 Nov 2016 19:31:39 +0000 (20:31 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Mon, 28 Nov 2016 09:55:07 +0000 (10:55 +0100)
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
src/mc/ModelChecker.cpp

index e2f389d..e712aff 100644 (file)
@@ -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");
index 6aff9c4..1600748 100644 (file)
@@ -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<const char*, const char*> 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");
       }