Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ignore empty replay path + hide a global (to avoid init fiasco)
[simgrid.git] / src / mc / remote / AppSide.cpp
index a5d5ffaa3ec9b3a0125fba6ccad037d1599c0bda..3c5b688f19139c9a4b48c6e464e0e1ee89c65c98 100644 (file)
@@ -11,7 +11,9 @@
 #include "src/kernel/actor/SimcallObserver.hpp"
 #include "src/mc/mc_base.hpp"
 #include "src/mc/mc_config.hpp"
+#if SIMGRID_HAVE_STATEFUL_MC
 #include "src/mc/sosp/RemoteProcessMemory.hpp"
+#endif
 #if HAVE_SMPI
 #include "src/smpi/include/private.hpp"
 #endif
@@ -38,16 +40,18 @@ namespace simgrid::mc {
 
 std::unique_ptr<AppSide> AppSide::instance_;
 
-AppSide* AppSide::initialize()
+AppSide* AppSide::get()
 {
-  if (not std::getenv(MC_ENV_SOCKET_FD)) // We are not in MC mode: don't initialize the MC world
+  // Only initialize the MC world once
+  if (instance_ != nullptr)
+    return instance_.get();
+
+  if (std::getenv(MC_ENV_SOCKET_FD) == nullptr) // We are not in MC mode: don't initialize the MC world
     return nullptr;
 
-  // Do not break if we are called multiple times:
-  if (instance_)
-    return instance_.get();
+  XBT_DEBUG("Initialize the MC world. MC_NEED_PTRACE=%s", std::getenv("MC_NEED_PTRACE"));
 
-  simgrid::mc::model_checking_mode = ModelCheckingMode::APP_SIDE;
+  simgrid::mc::set_model_checking_mode(ModelCheckingMode::APP_SIDE);
 
   setvbuf(stdout, nullptr, _IOLBF, 0);
 
@@ -174,6 +178,8 @@ void AppSide::handle_fork(const s_mc_message_int_t* msg)
     answer.type               = MessageType::FORK_REPLY;
     answer.value              = getpid();
     xbt_assert(channel_.send(answer) == 0, "Could not send response to WAIT_CHILD_REPLY: %s", strerror(errno));
+  } else {
+    XBT_DEBUG("App %d forks subprocess %d.", getpid(), pid);
   }
 }
 void AppSide::handle_wait_child(const s_mc_message_int_t* msg)
@@ -190,11 +196,15 @@ void AppSide::handle_wait_child(const s_mc_message_int_t* msg)
 }
 void AppSide::handle_need_meminfo()
 {
+#if SIMGRID_HAVE_STATEFUL_MC
   this->need_memory_info_                  = true;
   s_mc_message_need_meminfo_reply_t answer = {};
   answer.type                              = MessageType::NEED_MEMINFO_REPLY;
   answer.mmalloc_default_mdp               = mmalloc_get_current_heap();
   xbt_assert(channel_.send(answer) == 0, "Could not send response to the request for meminfo.");
+#else
+  xbt_die("SimGrid was compiled without MC suppport, so liveness and similar features are not available.");
+#endif
 }
 void AppSide::handle_actors_status() const
 {
@@ -365,11 +375,15 @@ void AppSide::ignore_memory(void* addr, std::size_t size) const
   if (not MC_is_active() || not need_memory_info_)
     return;
 
+#if SIMGRID_HAVE_STATEFUL_MC
   s_mc_message_ignore_memory_t message = {};
   message.type = MessageType::IGNORE_MEMORY;
   message.addr = (std::uintptr_t)addr;
   message.size = size;
   xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_MEMORY message to model-checker");
+#else
+  xbt_die("Cannot really call ignore_heap() in non-SIMGRID_MC mode.");
+#endif
 }
 
 void AppSide::ignore_heap(void* address, std::size_t size) const
@@ -377,6 +391,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) const
   if (not MC_is_active() || not need_memory_info_)
     return;
 
+#if SIMGRID_HAVE_STATEFUL_MC
   const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
 
   s_mc_message_ignore_heap_t message = {};
@@ -393,6 +408,9 @@ void AppSide::ignore_heap(void* address, std::size_t size) const
   }
 
   xbt_assert(channel_.send(message) == 0, "Could not send ignored region to MCer");
+#else
+  xbt_die("Cannot really call ignore_heap() in non-SIMGRID_MC mode.");
+#endif
 }
 
 void AppSide::unignore_heap(void* address, std::size_t size) const
@@ -400,11 +418,15 @@ void AppSide::unignore_heap(void* address, std::size_t size) const
   if (not MC_is_active() || not need_memory_info_)
     return;
 
+#if SIMGRID_HAVE_STATEFUL_MC
   s_mc_message_ignore_memory_t message = {};
   message.type = MessageType::UNIGNORE_HEAP;
   message.addr = (std::uintptr_t)address;
   message.size = size;
   xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_HEAP message to model-checker");
+#else
+  xbt_die("Cannot really call unignore_heap() in non-SIMGRID_MC mode.");
+#endif
 }
 
 void AppSide::declare_symbol(const char* name, int* value) const
@@ -414,6 +436,7 @@ void AppSide::declare_symbol(const char* name, int* value) const
     return;
   }
 
+#if SIMGRID_HAVE_STATEFUL_MC
   s_mc_message_register_symbol_t message = {};
   message.type = MessageType::REGISTER_SYMBOL;
   xbt_assert(strlen(name) + 1 <= message.name.size(), "Symbol is too long");
@@ -421,6 +444,9 @@ void AppSide::declare_symbol(const char* name, int* value) const
   message.callback = nullptr;
   message.data     = value;
   xbt_assert(channel_.send(message) == 0, "Could send REGISTER_SYMBOL message to model-checker");
+#else
+  xbt_die("Cannot really call declare_symbol() in non-SIMGRID_MC mode.");
+#endif
 }
 
 /** Register a stack in the model checker
@@ -434,6 +460,7 @@ void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const
   if (not MC_is_active() || not need_memory_info_)
     return;
 
+#if SIMGRID_HAVE_STATEFUL_MC
   const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
 
   s_stack_region_t region = {};
@@ -446,5 +473,8 @@ void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const
   message.type         = MessageType::STACK_REGION;
   message.stack_region = region;
   xbt_assert(channel_.send(message) == 0, "Could not send STACK_REGION to model-checker");
+#else
+  xbt_die("Cannot really call declare_stack() in non-SIMGRID_MC mode.");
+#endif
 }
 } // namespace simgrid::mc