Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Mar 2016 10:23:57 +0000 (11:23 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Mar 2016 10:23:57 +0000 (11:23 +0100)
appveyor.yml
src/mc/ModelChecker.cpp
src/mc/ModelChecker.hpp
src/mc/Process.cpp
src/mc/Process.hpp
src/mc/Variable.hpp
src/mc/mc_checkpoint.cpp
src/mc/mc_smx.cpp
src/mc/mc_unw.h
src/mc/mc_unw_vmread.cpp

index ca36670..4a6b368 100644 (file)
@@ -13,13 +13,13 @@ init:
 
 environment:
   global:
-    BOOST_ROOT: c:\Libraries\boost
-    BOOST_LIBRARYDIR: c:\Libraries\boost\stage\lib
+    BOOST_ROOT: c:\Libraries\boost_1_59_0
+    BOOST_LIBRARYDIR: c:\Libraries\boost_1_59_0\stage\lib
     TESH_ARGS: C:/projects/simgrid/bin/tesh --setenv srcdir=C:/projects/simgrid/examples/java --setenv classpath=C:/projects/simgrid/examples/java;C:/projects/simgrid/teshsuite/java;C:/projects/simgrid/simgrid.jar --cd C:/projects/simgrid/examples/java
 
 install:
 # Strawberry perl is the one to work with gcc
-- choco install strawberryperl -version 5.20.1.1
+- choco install --limit-output strawberryperl -version 5.20.1.1
 - SET PATH=C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;%PATH%
 - cpanm --notest --quiet Win32API::File
 - cpanm --notest --quiet IPC::Run
@@ -27,7 +27,7 @@ install:
 #- choco install lua53
 # Basic dependencies: gcc and Cmake (must be placed before Perl in the path)
 - SET PATH=C:\tools\mingw64\bin;%PATH%
-- choco install mingw cmake --limit-output
+- choco install --limit-output mingw cmake
 - rename "C:\Program Files\Git\usr\bin\sh.exe" "sh-ignored.exe"
 
 build_script:
@@ -76,4 +76,4 @@ artifacts:
 # https://github.com/polysquare/cmake-unit/blob/master/appveyor.yml
 # https://github.com/openvswitch/ovs/blob/master/appveyor.yml
 
-# https://github.com/behdad/harfbuzz/pull/112/files
\ No newline at end of file
+# https://github.com/behdad/harfbuzz/pull/112/files
index bc69fbe..6ff138a 100644 (file)
@@ -176,7 +176,7 @@ void ModelChecker::resume(simgrid::mc::Process& process)
   int res = process.getChannel().send(MC_MESSAGE_CONTINUE);
   if (res)
     throw simgrid::xbt::errno_error(res);
-  process.cache_flags = (mc_process_cache_flags_t) 0;
+  process.clear_cache();
 }
 
 static
@@ -434,7 +434,7 @@ void ModelChecker::simcall_handle(simgrid::mc::Process& process, unsigned long p
   m.pid   = pid;
   m.value = value;
   process.getChannel().send(m);
-  process.cache_flags = (mc_process_cache_flags_t) 0;
+  process.clear_cache();
   while (process.running())
     if (!this->handle_events())
       return;
index 47790fb..1f7665d 100644 (file)
@@ -30,7 +30,7 @@ namespace mc {
 class ModelChecker {
   struct pollfd fds_[2];
   /** String pool for host names */
-  // TODO, use std::unordered_set with heterogeneous comparison lookup (C++14)
+  // TODO, use std::set with heterogeneous comparison lookup (C++14)?
   xbt_dict_t /* <hostname, nullptr> */ hostnames_;
   // This is the parent snapshot of the current state:
   PageStore page_store_;
index 3f06a40..613eec4 100644 (file)
@@ -227,8 +227,9 @@ void Process::init()
   this->smx_process_infos.clear();
   this->smx_old_process_infos.clear();
   this->unw_addr_space = unw_create_addr_space(&mc_unw_accessors  , __BYTE_ORDER);
-  this->unw_underlying_addr_space = unw_create_addr_space(&mc_unw_vmread_accessors, __BYTE_ORDER);
-  this->unw_underlying_context = _UPT_create(this->pid_);
+  this->unw_underlying_addr_space = simgrid::unw::create_addr_space();
+  this->unw_underlying_context = simgrid::unw::create_context(
+    this->unw_underlying_addr_space, this->pid_);
 }
 
 Process::~Process()
@@ -262,7 +263,7 @@ void Process::refresh_heap()
     this->heap = std::unique_ptr<s_xbt_mheap_t>(new s_xbt_mheap_t());
   this->read_bytes(this->heap.get(), sizeof(struct mdesc),
     remote(this->heap_address), simgrid::mc::ProcessIndexDisabled);
-  this->cache_flags |= MC_PROCESS_CACHE_FLAG_HEAP;
+  this->cache_flags_ |= Process::cache_heap;
 }
 
 /** Refresh the information about the process
@@ -273,15 +274,15 @@ void Process::refresh_heap()
 void Process::refresh_malloc_info()
 {
   xbt_assert(mc_mode == MC_MODE_SERVER);
-  if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
-    this->refresh_heap();
   // Refresh process->heapinfo:
+  if (this->cache_flags_ & Process::cache_malloc)
+    return;
   size_t count = this->heap->heaplimit + 1;
   if (this->heap_info.size() < count)
     this->heap_info.resize(count);
   this->read_bytes(this->heap_info.data(), count * sizeof(malloc_info),
     remote(this->heap->heapinfo), simgrid::mc::ProcessIndexDisabled);
-  this->cache_flags |= MC_PROCESS_CACHE_FLAG_MALLOC_INFO;
+  this->cache_flags_ |= Process::cache_malloc;
 }
 
 /** @brief Finds the range of the different memory segments and binary paths */
index 36ef994..2b53837 100644 (file)
 #include "src/mc/mc_protocol.h"
 #include "src/mc/ObjectInformation.hpp"
 
-// Those flags are used to track down which cached information
-// is still up to date and which information needs to be updated.
-typedef int mc_process_cache_flags_t;
-#define MC_PROCESS_CACHE_FLAG_NONE 0
-#define MC_PROCESS_CACHE_FLAG_HEAP 1
-#define MC_PROCESS_CACHE_FLAG_MALLOC_INFO 2
-#define MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES 4
 
 namespace simgrid {
 namespace mc {
@@ -96,6 +89,13 @@ struct IgnoredHeapRegion {
  *  - etc.
  */
 class Process final : public AddressSpace {
+private:
+  // Those flags are used to track down which cached information
+  // is still up to date and which information needs to be updated.
+  static constexpr int cache_none = 0;
+  static constexpr int cache_heap = 1;
+  static constexpr int cache_malloc = 2;
+  static constexpr int cache_simix_processes = 4;
 public:
   Process(pid_t pid, int sockfd);
   ~Process();
@@ -135,16 +135,21 @@ public:
   // Heap access:
   xbt_mheap_t get_heap()
   {
-    if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
+    if (!(this->cache_flags_ & Process::cache_heap))
       this->refresh_heap();
     return this->heap.get();
   }
   malloc_info* get_malloc_info()
   {
-    if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
+    if (!(this->cache_flags_ & Process::cache_malloc))
       this->refresh_malloc_info();
     return this->heap_info.data();
   }
+  
+  void clear_cache()
+  {
+    this->cache_flags_ = Process::cache_none;
+  }
 
   Channel const& getChannel() const { return channel_; }
   Channel& getChannel() { return channel_; }
@@ -251,9 +256,11 @@ public: // Copies of MCed SMX data structures
    */
   std::vector<SimixProcessInformation> smx_old_process_infos;
 
+private:
   /** State of the cache (which variables are up to date) */
-  mc_process_cache_flags_t cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
+  int cache_flags_ = Process::cache_none;
 
+public:
   /** Address of the heap structure in the MCed process. */
   void* heap_address;
 
index a4f048a..f3b8e0a 100644 (file)
@@ -27,15 +27,16 @@ public:
   unsigned type_id = 0;
   simgrid::mc::Type* type = nullptr;
 
-  /** Address of the variable -if it is fixed) */
+  /** Address of the variable (if it is fixed) */
   void* address = nullptr;
 
-  /** Description of the location of the variable if it's not fixed */
+  /** Description of the location of the variable (if it's not fixed) */
   simgrid::dwarf::LocationList location_list;
 
   /** Offset of validity of the variable (DW_AT_start_scope)
    *
-   *  This variable is not valid since the beginning of its scope.
+   *  This is an offset from the variable scope beginning. This variable
+   *  is only valid starting from this offset.
    */
   std::size_t start_scope = 0;
 
index 1c0c1ce..77d6a73 100644 (file)
@@ -638,7 +638,7 @@ void restore_snapshot(mc_snapshot_t snapshot)
   if (use_soft_dirty)
     mc_model_checker->process().reset_soft_dirty();
   snapshot_ignore_restore(snapshot);
-  mc_model_checker->process().cache_flags = 0;
+  mc_model_checker->process().clear_cache();
   if (use_soft_dirty)
     mc_model_checker->parent_snapshot_ = snapshot;
 }
index 0436185..78f86fe 100644 (file)
@@ -77,7 +77,7 @@ namespace mc {
 void Process::refresh_simix()
 {
   xbt_assert(mc_mode == MC_MODE_SERVER);
-  if (this->cache_flags & MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES)
+  if (this->cache_flags_ & Process::cache_simix_processes)
     return;
 
   // TODO, avoid to reload `&simix_global`, `simix_global`, `*simix_global`
@@ -96,7 +96,7 @@ void Process::refresh_simix()
   MC_process_refresh_simix_process_list(
     this, this->smx_old_process_infos, simix_global.process_to_destroy);
 
-  this->cache_flags |= MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES;
+  this->cache_flags_ |= Process::cache_simix_processes;
 }
 
 }
index 3470bd8..d27fbd1 100644 (file)
  *  much here.
  */
 
+#include <sys/types.h>
+
 #include <xbt/base.h>
 
 #include <libunwind.h>
 
-#include "src/mc/Process.hpp"
+#include "src/mc/mc_forward.hpp"
+
+namespace simgrid {
+namespace unw {
+
+XBT_PRIVATE unw_addr_space_t create_addr_space();
+XBT_PRIVATE void* create_context(unw_addr_space_t as, pid_t pid);
+
+}
+}
 
 SG_BEGIN_DECL()
 
 // ***** Libunwind namespace
 
-/** Virtual table for our `libunwind-process_vm_readv` implementation.
- *
- *  This implementation reuse most the code of `libunwind-ptrace` but
- *  does not use ptrace() to read the target process memory by
- *  `process_vm_readv()` or `/dev/${pid}/mem` if possible.
- *
- *  Does not support any MC-specific behaviour (privatisation, snapshots)
- *  and `ucontext_t`.
- *
- *  It works with `void*` contexts allocated with `_UPT_create(pid)`.
- */
-extern XBT_PRIVATE unw_accessors_t mc_unw_vmread_accessors;
-
 /** Virtual table for our `libunwind` implementation
  *
  *  Stack unwinding on a `simgrid::mc::Process*` (for memory, unwinding information)
index 29b015b..7082dd3 100644 (file)
 #include <libunwind.h>
 #include <libunwind-ptrace.h>
 
+#include "src/mc/Process.hpp"
 #include "src/mc/mc_unw.h"
 
-extern "C" {
-
 /** \file
  *  Libunwind namespace implementation using process_vm_readv.
  *.
@@ -23,9 +22,9 @@ extern "C" {
 
 /** Partial structure of libunwind-ptrace context in order to get the PID
  *
- *  The context type for libunwind-race is an opaque type. We need to get the
- *  PID which is the first field. This is a hack which might break if the
- *  libunwind-ptrace structure changes.
+ *  HACK, The context type for libunwind-race is an opaque type.
+ *  We need to get the PID which is the first field. This is a hack
+ *  which might break if the libunwind-ptrace structure changes.
  */
 struct _UPT_info {
   pid_t pid;
@@ -101,16 +100,42 @@ static int access_mem(const unw_addr_space_t as,
   return _UPT_access_mem(as, addr, valp, write, arg);
 }
 
-unw_accessors_t mc_unw_vmread_accessors =
-  {
-    &_UPT_find_proc_info,
-    &_UPT_put_unwind_info,
-    &_UPT_get_dyn_info_list_addr,
-    &access_mem,
-    &_UPT_access_reg,
-    &_UPT_access_fpreg,
-    &_UPT_resume,
-    &_UPT_get_proc_name
-  };
+namespace simgrid {
+namespace unw {
+
+/** Virtual table for our `libunwind-process_vm_readv` implementation.
+ *
+ *  This implementation reuse most the code of `libunwind-ptrace` but
+ *  does not use ptrace() to read the target process memory by
+ *  `process_vm_readv()` or `/dev/${pid}/mem` if possible.
+ *
+ *  Does not support any MC-specific behaviour (privatisation, snapshots)
+ *  and `ucontext_t`.
+ *
+ *  It works with `void*` contexts allocated with `_UPT_create(pid)`.
+ */
+// TODO, we could get rid of this if we properly stop the model-checked
+// process before reading the memory.
+static unw_accessors_t accessors = {
+  &_UPT_find_proc_info,
+  &_UPT_put_unwind_info,
+  &_UPT_get_dyn_info_list_addr,
+  &access_mem,
+  &_UPT_access_reg,
+  &_UPT_access_fpreg,
+  &_UPT_resume,
+  &_UPT_get_proc_name
+};
+
+unw_addr_space_t create_addr_space()
+{
+  return unw_create_addr_space(&accessors, __BYTE_ORDER);
+}
+
+void* create_context(unw_addr_space_t as, pid_t pid)
+{
+  return _UPT_create(pid);
+}
 
 }
+}
\ No newline at end of file