Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
doc fix [no-ci]
[simgrid.git] / src / mc / ModelChecker.cpp
index 4d7be7f..1e3c2be 100644 (file)
@@ -4,7 +4,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/mc/ModelChecker.hpp"
-#include "src/mc/Session.hpp"
 #include "src/mc/explo/Exploration.hpp"
 #include "src/mc/mc_config.hpp"
 #include "src/mc/mc_exit.hpp"
@@ -23,16 +22,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ModelChecker, mc, "ModelChecker");
 
 ::simgrid::mc::ModelChecker* mc_model_checker = nullptr;
 
-using simgrid::mc::remote;
-
 #ifdef __linux__
 # define WAITPID_CHECKED_FLAGS __WALL
 #else
 # define WAITPID_CHECKED_FLAGS 0
 #endif
 
-namespace simgrid {
-namespace mc {
+namespace simgrid::mc {
 
 ModelChecker::ModelChecker(std::unique_ptr<RemoteProcess> remote_simulation, int sockfd)
     : checker_side_(sockfd), remote_process_(std::move(remote_simulation))
@@ -75,6 +71,7 @@ void ModelChecker::start()
 
   setup_ignore();
 
+  errno = 0;
 #ifdef __linux__
   ptrace(PTRACE_SETOPTIONS, pid, nullptr, PTRACE_O_TRACEEXIT);
   ptrace(PTRACE_CONT, pid, 0, 0);
@@ -83,6 +80,11 @@ void ModelChecker::start()
 #else
 # error "no ptrace equivalent coded for this platform"
 #endif
+  xbt_assert(errno == 0,
+             "Ptrace does not seem to be usable in your setup (errno: %d). "
+             "If you run from within a docker, adding `--cap-add SYS_PTRACE` to the docker line may help. "
+             "If it does not help, please report this bug.",
+             errno);
 }
 
 static constexpr auto ignored_local_variables = {
@@ -96,8 +98,8 @@ static constexpr auto ignored_local_variables = {
 void ModelChecker::setup_ignore()
 {
   const RemoteProcess& process = this->get_remote_process();
-  for (auto const& var : ignored_local_variables)
-    process.ignore_local_variable(var.first, var.second);
+  for (auto const& [var, frame] : ignored_local_variables)
+    process.ignore_local_variable(var, frame);
 
   /* Static variable used for tracing */
   process.ignore_global_variable("counter");
@@ -118,8 +120,7 @@ void ModelChecker::shutdown()
 
 void ModelChecker::resume()
 {
-  int res = checker_side_.get_channel().send(MessageType::CONTINUE);
-  if (res)
+  if (checker_side_.get_channel().send(MessageType::CONTINUE) != 0)
     throw xbt::errno_error();
   remote_process_->clear_cache();
 }
@@ -140,7 +141,7 @@ static void MC_report_crash(int status)
     for (auto const& s : mc_model_checker->get_exploration()->get_textual_trace())
       XBT_INFO("  %s", s.c_str());
     XBT_INFO("Path = %s", mc_model_checker->get_exploration()->get_record_trace().to_string().c_str());
-    session_singleton->log_state();
+    Api::get().get_session().log_state();
     if (xbt_log_no_loc) {
       XBT_INFO("Stack trace not displayed because you passed --log=no_loc");
     } else {
@@ -232,7 +233,7 @@ bool ModelChecker::handle_message(const char* buffer, ssize_t size)
       for (auto const& s : get_exploration()->get_textual_trace())
         XBT_INFO("  %s", s.c_str());
       XBT_INFO("Path = %s", get_exploration()->get_record_trace().to_string().c_str());
-      session_singleton->log_state();
+      Api::get().get_session().log_state();
 
       this->exit(SIMGRID_MC_EXIT_SAFETY);
 
@@ -351,5 +352,4 @@ void ModelChecker::finalize_app(bool terminate_asap)
   xbt_assert(checker_side_.get_channel().receive(answer) != -1, "Could not receive answer to FINALIZE");
 }
 
-} // namespace mc
-} // namespace simgrid
+} // namespace simgrid::mc