Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[pvs-studio] Initialize every members of class.
[simgrid.git] / src / mc / remote / RemoteProcess.hpp
index 3e35f7f..a183c93 100644 (file)
 #include "src/mc/AddressSpace.hpp"
 #include "src/mc/inspect/ObjectInformation.hpp"
 #include "src/mc/remote/RemotePtr.hpp"
+#include "src/xbt/memory_map.hpp"
 #include "src/xbt/mmalloc/mmprivate.h"
 
+#include <libunwind.h>
 #include <vector>
 
 namespace simgrid {
@@ -27,7 +29,7 @@ public:
 
   /** Hostname (owned by `mc_model_checker->hostnames_`) */
   const xbt::string* hostname = nullptr;
-  std::string name;
+  xbt::string name;
 
   void clear()
   {
@@ -75,13 +77,17 @@ private:
 public:
   explicit RemoteProcess(pid_t pid);
   ~RemoteProcess() override;
-  void init();
+  void init(xbt_mheap_t mmalloc_default_mdp, unsigned long* maxpid, xbt_dynar_t actors, xbt_dynar_t dead_actors);
 
   RemoteProcess(RemoteProcess const&) = delete;
   RemoteProcess(RemoteProcess&&)      = delete;
   RemoteProcess& operator=(RemoteProcess const&) = delete;
   RemoteProcess& operator=(RemoteProcess&&) = delete;
 
+  /* ************* */
+  /* Low-level API */
+  /* ************* */
+
   // Read memory:
   void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
                    ReadOptions options = ReadOptions::none()) const override;
@@ -156,6 +162,17 @@ public:
   void unignore_heap(void* address, size_t size);
 
   void ignore_local_variable(const char* var_name, const char* frame_name) const;
+
+  /* ***************** */
+  /* SIMIX-related API */
+  /* ***************** */
+private:
+  // Cache the address of the variables we read directly in the memory of remote
+  RemotePtr<unsigned long> maxpid_addr_;
+  RemotePtr<s_xbt_dynar_t> actors_addr_;
+  RemotePtr<s_xbt_dynar_t> dead_actors_addr_;
+
+public:
   std::vector<ActorInformation>& actors();
   std::vector<ActorInformation>& dead_actors();
 
@@ -185,6 +202,8 @@ public:
       return nullptr;
   }
 
+  unsigned long get_maxpid() const { return this->read(maxpid_addr_); }
+
   void dump_stack() const;
 
 private:
@@ -203,32 +222,30 @@ private:
   std::vector<s_stack_region_t> stack_areas_;
   std::vector<IgnoredHeapRegion> ignored_heap_;
 
-public:
-  // object info
-  // TODO, make private (first, objectify simgrid::mc::ObjectInformation*)
-  std::vector<std::shared_ptr<ObjectInformation>> object_infos;
-  std::shared_ptr<ObjectInformation> binary_info;
-
   // Copies of MCed SMX data structures
-  /** Copy of `simix_global->process_list`
+  /** Copy of `EngineImpl::actor_list_`
    *
-   *  See mc_smx.c.
+   *  See mc_smx.cpp.
    */
   std::vector<ActorInformation> smx_actors_infos;
 
-  /** Copy of `simix_global->actors_to_destroy`
+  /** Copy of `EngineImpl::actors_to_destroy_`
    *
-   *  See mc_smx.c.
+   *  See mc_smx.cpp.
    */
   std::vector<ActorInformation> smx_dead_actors_infos;
 
-private:
   /** State of the cache (which variables are up to date) */
   int cache_flags_ = RemoteProcess::cache_none;
 
 public:
+  // object info
+  // TODO, make private (first, objectify simgrid::mc::ObjectInformation*)
+  std::vector<std::shared_ptr<ObjectInformation>> object_infos;
+  std::shared_ptr<ObjectInformation> binary_info;
+
   /** Address of the heap structure in the MCed process. */
-  void* heap_address;
+  RemotePtr<s_xbt_mheap_t> heap_address;
 
   /** Copy of the heap structure of the process
    *
@@ -253,7 +270,7 @@ public:
    *  (with simgrid::mc::Process* / simgrid::mc::AddressSpace*
    *  and unw_context_t).
    */
-  unw_addr_space_t unw_addr_space;
+  unw_addr_space_t unw_addr_space = nullptr;
 
   /** Underlying libunwind address-space
    *
@@ -261,11 +278,11 @@ public:
    *  operations of the native MC address space is currently delegated
    *  to this address space (either the local or a ptrace unwinder).
    */
-  unw_addr_space_t unw_underlying_addr_space;
+  unw_addr_space_t unw_underlying_addr_space = nullptr;
 
   /** The corresponding context
    */
-  void* unw_underlying_context;
+  void* unw_underlying_context = nullptr;
 };
 
 /** Open a FD to a remote process memory (`/dev/$pid/mem`) */