Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix SimGridMC when SMPI is disabled
[simgrid.git] / src / mc / mc_process.cpp
index 5fee155..a39caa5 100644 (file)
@@ -4,6 +4,8 @@
 /* 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. */
 
+#define _FILE_OFFSET_BITS 64
+
 #include <assert.h>
 #include <stddef.h>
 #include <stdbool.h>
 
 #include "mc_process.h"
 #include "mc_object_info.h"
-#include "AddressSpace.hpp"
 #include "mc_unw.h"
 #include "mc_snapshot.h"
 #include "mc_ignore.h"
 #include "mc_smx.h"
 #include "mc_server.h"
 
+#include "mc/AddressSpace.hpp"
+#include "mc/ObjectInformation.hpp"
+#include "mc/Variable.hpp"
+
 using simgrid::mc::remote;
 
 extern "C" {
@@ -47,27 +52,32 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc,
 #define VERSION_RE "-[\\.0-9-]*$"
 
 static const char *const FILTERED_LIBS[] = {
-  "libstdc++",
+  "ld",
+  "libbz2",
+  "libboost_chrono",
   "libboost_context",
+  "libboost_system",
+  "libboost_thread",
+  "libc",
   "libc++",
   "libcdt",
-  "libm",
+  "libcgraph",
+  "libdl",
+  "libdw",
+  "libelf",
   "libgcc_s",
+  "liblua5.1",
+  "liblzma",
+  "libm",
   "libpthread",
+  "librt",
+  "libsigc",
+  "libstdc++",
   "libunwind",
   "libunwind-x86_64",
   "libunwind-x86",
   "libunwind-ptrace",
-  "libdw",
-  "libdl",
-  "librt",
-  "liblzma",
-  "libelf",
-  "libbz2",
-  "libz",
-  "libelf",
-  "libc",
-  "ld"
+  "libz"
 };
 
 static bool MC_is_simgrid_lib(const char* libname)
@@ -108,12 +118,12 @@ static char* MC_get_lib_name(const char* pathname, struct s_mc_memory_map_re* re
   return libname;
 }
 
-static ssize_t pread_whole(int fd, void *buf, size_t count, off_t offset)
+static ssize_t pread_whole(int fd, void *buf, size_t count, std::uint64_t offset)
 {
   char* buffer = (char*) buf;
   ssize_t real_count = count;
   while (count) {
-    ssize_t res = pread(fd, buffer, count, offset);
+    ssize_t res = pread(fd, buffer, count, (std::int64_t) offset);
     if (res > 0) {
       count  -= res;
       buffer += res;
@@ -215,7 +225,7 @@ Process::Process(pid_t pid, int sockfd)
   }
 
   // Read std_heap (is a struct mdesc*):
-  dw_variable_t std_heap_var = process->find_variable("__mmalloc_default_mdp");
+  simgrid::mc::Variable* std_heap_var = process->find_variable("__mmalloc_default_mdp");
   if (!std_heap_var)
     xbt_die("No heap information in the target process");
   if(!std_heap_var->address)
@@ -374,7 +384,7 @@ void Process::init_memory_map_info()
       }
     }
 
-    std::shared_ptr<s_mc_object_info_t> info =
+    std::shared_ptr<simgrid::mc::ObjectInformation> info =
       MC_find_object_info(this->memory_map_, pathname, is_executable);
     this->object_infos.push_back(info);
     if (is_executable)
@@ -397,7 +407,7 @@ void Process::init_memory_map_info()
   XBT_DEBUG("Get debug information done !");
 }
 
-std::shared_ptr<s_mc_object_info_t> Process::find_object_info(remote_ptr<void> addr) const
+std::shared_ptr<simgrid::mc::ObjectInformation> Process::find_object_info(remote_ptr<void> addr) const
 {
   for (auto const& object_info : this->object_infos) {
     if (addr.address() >= (std::uint64_t)object_info->start
@@ -408,9 +418,9 @@ std::shared_ptr<s_mc_object_info_t> Process::find_object_info(remote_ptr<void> a
   return NULL;
 }
 
-std::shared_ptr<s_mc_object_info_t> Process::find_object_info_exec(remote_ptr<void> addr) const
+std::shared_ptr<ObjectInformation> Process::find_object_info_exec(remote_ptr<void> addr) const
 {
-  for (std::shared_ptr<s_mc_object_info> const& info : this->object_infos) {
+  for (std::shared_ptr<ObjectInformation> const& info : this->object_infos) {
     if (addr.address() >= (std::uint64_t) info->start_exec
         && addr.address() <= (std::uint64_t) info->end_exec) {
       return info;
@@ -419,9 +429,9 @@ std::shared_ptr<s_mc_object_info_t> Process::find_object_info_exec(remote_ptr<vo
   return nullptr;
 }
 
-std::shared_ptr<s_mc_object_info_t> Process::find_object_info_rw(remote_ptr<void> addr) const
+std::shared_ptr<ObjectInformation> Process::find_object_info_rw(remote_ptr<void> addr) const
 {
-  for (std::shared_ptr<s_mc_object_info> const& info : this->object_infos) {
+  for (std::shared_ptr<ObjectInformation> const& info : this->object_infos) {
     if (addr.address() >= (std::uint64_t)info->start_rw
         && addr.address() <= (std::uint64_t)info->end_rw) {
       return info;
@@ -430,32 +440,29 @@ std::shared_ptr<s_mc_object_info_t> Process::find_object_info_rw(remote_ptr<void
   return nullptr;
 }
 
-dw_frame_t Process::find_function(remote_ptr<void> ip) const
+simgrid::mc::Frame* Process::find_function(remote_ptr<void> ip) const
 {
-  std::shared_ptr<s_mc_object_info_t> info = this->find_object_info_exec(ip);
-  if (!info)
-    return nullptr;
-  else
-    return MC_file_object_info_find_function(info.get(), (void*) ip.address());
+  std::shared_ptr<simgrid::mc::ObjectInformation> info = this->find_object_info_exec(ip);
+  return info ? info->find_function((void*) ip.address()) : nullptr;
 }
 
 /** Find (one occurence of) the named variable definition
  */
-dw_variable_t Process::find_variable(const char* name) const
+simgrid::mc::Variable* Process::find_variable(const char* name) const
 {
   // First lookup the variable in the executable shared object.
   // A global variable used directly by the executable code from a library
   // is reinstanciated in the executable memory .data/.bss.
   // We need to look up the variable in the execvutable first.
   if (this->binary_info) {
-    std::shared_ptr<s_mc_object_info_t> const& info = this->binary_info;
-    dw_variable_t var = MC_file_object_info_find_variable_by_name(info.get(), name);
+    std::shared_ptr<simgrid::mc::ObjectInformation> const& info = this->binary_info;
+    simgrid::mc::Variable* var = info->find_variable(name);
     if (var)
       return var;
   }
 
-  for (std::shared_ptr<s_mc_object_info_t> const& info : this->object_infos) {
-    dw_variable_t var = MC_file_object_info_find_variable_by_name(info.get(), name);
+  for (std::shared_ptr<simgrid::mc::ObjectInformation> const& info : this->object_infos) {
+    simgrid::mc::Variable* var = info->find_variable(name);
     if (var)
       return var;
   }
@@ -465,7 +472,7 @@ dw_variable_t Process::find_variable(const char* name) const
 
 void Process::read_variable(const char* name, void* target, size_t size) const
 {
-  dw_variable_t var = this->find_variable(name);
+  simgrid::mc::Variable* var = this->find_variable(name);
   if (!var->address)
     xbt_die("No simple location for this variable");
   if (!var->type->full_type)
@@ -515,10 +522,11 @@ const void *Process::read_bytes(void* buffer, std::size_t size,
   AddressSpace::ReadMode mode) const
 {
   if (process_index != simgrid::mc::ProcessIndexDisabled) {
-    std::shared_ptr<s_mc_object_info_t> const& info =
+    std::shared_ptr<simgrid::mc::ObjectInformation> const& info =
       this->find_object_info_rw((void*)address.address());
     // Segment overlap is not handled.
-    if (MC_object_info_is_privatized(info.get())) {
+#ifdef HAVE_SMPI
+    if (info.get() && info.get()->privatized()) {
       if (process_index < 0)
         xbt_die("Missing process index");
       if (process_index >= (int) MC_smpi_process_count())
@@ -537,6 +545,7 @@ const void *Process::read_bytes(void* buffer, std::size_t size,
       size_t offset = address.address() - (std::uint64_t)info->start_rw;
       address = remote((char*)privatisation_region.address + offset);
     }
+#endif
   }
 
   if (this->is_self()) {
@@ -547,7 +556,7 @@ const void *Process::read_bytes(void* buffer, std::size_t size,
       return buffer;
     }
   } else {
-    if (pread_whole(this->memory_file, buffer, size, (off_t) address.address()) < 0)
+    if (pread_whole(this->memory_file, buffer, size, address.address()) < 0)
       xbt_die("Read from process %lli failed", (long long) this->pid_);
     return buffer;
   }