Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix MC+gcc builds
[simgrid.git] / src / mc / remote / RemoteProcess.cpp
index 1bbd05a845f4538d1d1029c1387d1f36cd8619be..ad816fc361201280173bc68b6abf87f22cf4b6a2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2014-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. */
 #include <memory>
 #include <mutex>
 #include <string>
-
-using simgrid::mc::remote;
+#include <string_view>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc, "MC process information");
 
-namespace simgrid {
-namespace mc {
+namespace simgrid::mc {
 
 // ***** Helper stuff
 
-static bool is_filtered_lib(const std::string& libname)
+static bool is_filtered_lib(std::string_view libname)
 {
   return libname != "libsimgrid";
 }
@@ -41,8 +39,7 @@ static std::string get_lib_name(const std::string& pathname)
   std::string map_basename = simgrid::xbt::Path(pathname).get_base_name();
   std::string libname;
 
-  size_t pos = map_basename.rfind(".so");
-  if (pos != std::string::npos) {
+  if (size_t pos = map_basename.rfind(".so"); pos != std::string::npos) {
     // strip the extension (matching regex "\.so.*$")
     libname.assign(map_basename, 0, pos);
 
@@ -108,13 +105,10 @@ int open_vm(pid_t pid, int flags)
 
 RemoteProcess::RemoteProcess(pid_t pid) : AddressSpace(this), pid_(pid), running_(true) {}
 
-void RemoteProcess::init(xbt_mheap_t mmalloc_default_mdp, unsigned long* maxpid, xbt_dynar_t actors,
-                         xbt_dynar_t dead_actors)
+void RemoteProcess::init(xbt_mheap_t mmalloc_default_mdp, unsigned long* maxpid)
 {
   this->heap_address      = remote(mmalloc_default_mdp);
   this->maxpid_addr_      = remote(maxpid);
-  this->actors_addr_      = remote(actors);
-  this->dead_actors_addr_ = remote(dead_actors);
 
   this->memory_map_ = simgrid::xbt::get_memory_map(this->pid_);
   this->init_memory_map_info();
@@ -123,8 +117,6 @@ void RemoteProcess::init(xbt_mheap_t mmalloc_default_mdp, unsigned long* maxpid,
   xbt_assert(fd >= 0, "Could not open file for process virtual address space");
   this->memory_file = fd;
 
-  this->smx_actors_infos.clear();
-  this->smx_dead_actors_infos.clear();
   this->unw_addr_space            = simgrid::mc::UnwindContext::createUnwindAddressSpace();
   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_);
@@ -153,8 +145,6 @@ RemoteProcess::~RemoteProcess()
 void RemoteProcess::refresh_heap()
 {
   // Read/dereference/refresh the std_heap pointer:
-  if (not this->heap)
-    this->heap = std::make_unique<s_xbt_mheap_t>();
   this->read(this->heap.get(), this->heap_address);
   this->cache_flags_ |= RemoteProcess::cache_heap;
 }
@@ -175,6 +165,10 @@ void RemoteProcess::refresh_malloc_info()
   this->read_bytes(this->heap_info.data(), count * sizeof(malloc_info), remote(this->heap->heapinfo));
   this->cache_flags_ |= RemoteProcess::cache_malloc;
 }
+std::size_t RemoteProcess::get_remote_heap_bytes()
+{
+  return mmalloc_get_bytes_used_remote(get_heap()->heaplimit, get_malloc_info());
+}
 
 /** @brief Finds the range of the different memory segments and binary paths */
 void RemoteProcess::init_memory_map_info()
@@ -322,9 +316,8 @@ std::string RemoteProcess::read_string(RemotePtr<char> address) const
       continue;
     xbt_assert(c > 0, "Could not read string from remote process");
 
-    const void* p = memchr(res.data() + off, '\0', c);
-    if (p)
-      return std::string(res.data());
+    if (memchr(res.data() + off, '\0', c))
+      return res.data();
 
     off += c;
     if (off == (off_t)res.size())
@@ -417,18 +410,6 @@ void RemoteProcess::ignore_local_variable(const char* var_name, const char* fram
     info->remove_local_variable(var_name, frame_name);
 }
 
-std::vector<simgrid::mc::ActorInformation>& RemoteProcess::actors()
-{
-  this->refresh_simix();
-  return smx_actors_infos;
-}
-
-std::vector<simgrid::mc::ActorInformation>& RemoteProcess::dead_actors()
-{
-  this->refresh_simix();
-  return smx_dead_actors_infos;
-}
-
 void RemoteProcess::dump_stack() const
 {
   unw_addr_space_t as = unw_create_addr_space(&_UPT_accessors, BYTE_ORDER);
@@ -457,5 +438,4 @@ void RemoteProcess::dump_stack() const
   _UPT_destroy(context);
   unw_destroy_addr_space(as);
 }
-} // namespace mc
-} // namespace simgrid
+} // namespace simgrid::mc