Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill src/include
[simgrid.git] / src / mc / remote / RemoteProcess.hpp
index 3e35f7f..3a6b24e 100644 (file)
@@ -1,6 +1,6 @@
 /* mc::RemoteClient: representative of the Client memory on the MC side */
 
-/* Copyright (c) 2008-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -8,16 +8,17 @@
 #ifndef SIMGRID_MC_PROCESS_H
 #define SIMGRID_MC_PROCESS_H
 
-#include "mc/datatypes.h"
 #include "src/mc/AddressSpace.hpp"
+#include "src/mc/datatypes.h"
 #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 {
-namespace mc {
+namespace simgrid::mc {
 
 class ActorInformation {
 public:
@@ -26,7 +27,7 @@ public:
   Remote<kernel::actor::ActorImpl> copy;
 
   /** Hostname (owned by `mc_model_checker->hostnames_`) */
-  const xbt::string* hostname = nullptr;
+  const std::string* hostname = nullptr;
   std::string name;
 
   void clear()
@@ -49,16 +50,12 @@ struct IgnoredHeapRegion {
   std::size_t size;
 };
 
-/** The Application's process memory, seen from the MCer perspective
- *
- *  This class is mixing a lot of different responsibilities and is tied
- *  to SIMIX. It should probably be split into different classes.
+/** The Application's process memory, seen from the Checker perspective
  *
  *  Responsibilities:
  *
  *  - reading from the process memory (`AddressSpace`);
  *  - accessing the system state of the process (heap, …);
- *  - storing the SIMIX state of the process;
  *  - privatization;
  *  - stack unwinding;
  *  - etc.
@@ -70,18 +67,21 @@ private:
   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:
   explicit RemoteProcess(pid_t pid);
   ~RemoteProcess() override;
-  void init();
+  void init(xbt_mheap_t mmalloc_default_mdp, unsigned long* maxpid);
 
   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;
@@ -125,6 +125,8 @@ public:
       this->refresh_malloc_info();
     return this->heap_info.data();
   }
+  /* Get the amount of memory mallocated in the remote process (requires mmalloc) */
+  std::size_t get_remote_heap_bytes();
 
   void clear_cache() { this->cache_flags_ = RemoteProcess::cache_none; }
 
@@ -156,34 +158,16 @@ public:
   void unignore_heap(void* address, size_t size);
 
   void ignore_local_variable(const char* var_name, const char* frame_name) const;
-  std::vector<ActorInformation>& actors();
-  std::vector<ActorInformation>& dead_actors();
 
-  /** Get a local description of a remote SIMIX actor */
-  ActorInformation* resolve_actor_info(RemotePtr<kernel::actor::ActorImpl> actor)
-  {
-    xbt_assert(mc_model_checker != nullptr);
-    if (not actor)
-      return nullptr;
-    this->refresh_simix();
-    for (auto& actor_info : this->smx_actors_infos)
-      if (actor_info.address == actor)
-        return &actor_info;
-    for (auto& actor_info : this->smx_dead_actors_infos)
-      if (actor_info.address == actor)
-        return &actor_info;
-    return nullptr;
-  }
+  /* ***************** */
+  /* SIMIX-related API */
+  /* ***************** */
+private:
+  // Cache the address of the variables we read directly in the memory of remote
+  RemotePtr<unsigned long> maxpid_addr_;
 
-  /** Get a local copy of the SIMIX actor structure */
-  kernel::actor::ActorImpl* resolve_actor(RemotePtr<kernel::actor::ActorImpl> process)
-  {
-    ActorInformation* actor_info = this->resolve_actor_info(process);
-    if (actor_info)
-      return actor_info->copy.get_buffer();
-    else
-      return nullptr;
-  }
+public:
+  unsigned long get_maxpid() const { return this->read(maxpid_addr_); }
 
   void dump_stack() const;
 
@@ -191,7 +175,6 @@ private:
   void init_memory_map_info();
   void refresh_heap();
   void refresh_malloc_info();
-  void refresh_simix();
 
   pid_t pid_    = -1;
   bool running_ = false;
@@ -203,32 +186,17 @@ private:
   std::vector<s_stack_region_t> stack_areas_;
   std::vector<IgnoredHeapRegion> ignored_heap_;
 
+  /** 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;
 
-  // Copies of MCed SMX data structures
-  /** Copy of `simix_global->process_list`
-   *
-   *  See mc_smx.c.
-   */
-  std::vector<ActorInformation> smx_actors_infos;
-
-  /** Copy of `simix_global->actors_to_destroy`
-   *
-   *  See mc_smx.c.
-   */
-  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:
   /** 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
    *
@@ -236,7 +204,7 @@ public:
    *  This is not used if the process is the current one:
    *  use `get_heap_info()` in order to use it.
    */
-  std::unique_ptr<s_xbt_mheap_t> heap;
+  std::unique_ptr<s_xbt_mheap_t> heap = std::make_unique<s_xbt_mheap_t>();
 
   /** Copy of the allocation info structure
    *
@@ -253,7 +221,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,16 +229,15 @@ 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`) */
 XBT_PRIVATE int open_vm(pid_t pid, int flags);
-} // namespace mc
-} // namespace simgrid
+} // namespace simgrid::mc
 
 #endif