Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] OOPify/C++ify ObjectInformation
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 17 Jul 2015 10:29:07 +0000 (12:29 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jul 2015 12:18:30 +0000 (14:18 +0200)
src/mc/mc_checkpoint.cpp
src/mc/mc_diff.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_dwarf_expression.cpp
src/mc/mc_forward.h
src/mc/mc_object_info.cpp
src/mc/mc_object_info.h
src/mc/mc_process.cpp
teshsuite/mc/dwarf/dwarf.cpp

index 24149db..5b16ad1 100644 (file)
@@ -140,7 +140,7 @@ static void MC_snapshot_add_region(int index, mc_snapshot_t snapshot,
   else if (type == simgrid::mc::RegionType::Heap)
     xbt_assert(!object_info, "Unexpected object info for heap region.");
 
-  const bool privatization_aware = MC_object_info_is_privatized(object_info);
+  const bool privatization_aware = object_info && object_info->privatized();
 
   simgrid::mc::RegionSnapshot region;
   if (privatization_aware && MC_smpi_process_count())
index 06b1141..6ea1d01 100644 (file)
@@ -1573,27 +1573,6 @@ static int get_pointed_area_size(void *area, int heap)
   }
 }
 
-// Not used:
-char *get_type_description(mc_object_info_t info, char *type_name)
-{
-
-  xbt_dict_cursor_t dict_cursor;
-  char *type_origin;
-  dw_type_t type;
-
-  xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
-    if (type->name && (strcmp(type->name, type_name) == 0)
-        && type->byte_size > 0) {
-      xbt_dict_cursor_free(&dict_cursor);
-      return type_origin;
-    }
-  }
-
-  xbt_dict_cursor_free(&dict_cursor);
-  return NULL;
-}
-
-
 #ifndef max
 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
 #endif
index ab65cae..faba98c 100644 (file)
@@ -755,7 +755,7 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die,
       if (len == 1 && expr[0].atom == DW_OP_addr) {
         variable->global = 1;
         uintptr_t offset = (uintptr_t) expr[0].number;
-        uintptr_t base = (uintptr_t) MC_object_base_address(info);
+        uintptr_t base = (uintptr_t) info->base_address();
         variable->address = (void *) (base + offset);
       } else {
         mc_dwarf_location_list_init_from_expression(&variable->locations, len,
@@ -863,7 +863,7 @@ static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die,
   // This is the base address for DWARF addresses.
   // Relocated addresses are offset from this base address.
   // See DWARF4 spec 7.5
-  void *base = MC_object_base_address(info);
+  void *base = info->base_address();
 
   // Variables are filled in the (recursive) call of MC_dwarf_handle_children:
   frame->variables =
@@ -1087,7 +1087,10 @@ void dw_variable_free_voidp(void *t)
 
 // ***** object_info
 
-s_mc_object_info::s_mc_object_info()
+namespace simgrid {
+namespace mc {
+
+ObjectInformation::ObjectInformation()
 {
   this->flags = 0;
   this->file_name = nullptr;
@@ -1107,7 +1110,7 @@ s_mc_object_info::s_mc_object_info()
   this->functions_index = nullptr;
 }
 
-s_mc_object_info::~s_mc_object_info()
+ObjectInformation::~ObjectInformation()
 {
   xbt_free(this->file_name);
   xbt_dict_free(&this->subprograms);
@@ -1117,20 +1120,38 @@ s_mc_object_info::~s_mc_object_info()
   xbt_dynar_free(&this->functions_index);
 }
 
-// ***** Helpers
-
-void *MC_object_base_address(mc_object_info_t info)
+/** Find the DWARF offset for this ELF object
+ *
+ *  An offset is applied to address found in DWARF:
+ *
+ *  <ul>
+ *    <li>for an executable obejct, addresses are virtual address
+ *        (there is no offset) i.e. \f$\text{virtual address} = \{dwarf address}\f$;</li>
+ *    <li>for a shared object, the addreses are offset from the begining
+ *        of the shared object (the base address of the mapped shared
+ *        object must be used as offset
+ *        i.e. \f$\text{virtual address} = \text{shared object base address}
+ *             + \text{dwarf address}\f$.</li>
+ *
+ */
+void *ObjectInformation::base_address() const
 {
-  if (info->flags & MC_OBJECT_INFO_EXECUTABLE)
-    return 0;
-  void *result = info->start_exec;
-  if (info->start_rw != NULL && result > (void *) info->start_rw)
-    result = info->start_rw;
-  if (info->start_ro != NULL && result > (void *) info->start_ro)
-    result = info->start_ro;
+  if (this->executable())
+    return nullptr;
+
+  void *result = this->start_exec;
+  if (this->start_rw != NULL && result > (void *) this->start_rw)
+    result = this->start_rw;
+  if (this->start_ro != NULL && result > (void *) this->start_ro)
+    result = this->start_ro;
   return result;
 }
 
+}
+}
+
+// ***** Helpers
+
 // ***** Functions index
 
 static int MC_compare_frame_index_items(mc_function_index_item_t a,
index 33a01b9..db02993 100644 (file)
@@ -230,7 +230,7 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops,
       if (state->stack_size == MC_EXPRESSION_STACK_SIZE)
         return MC_EXPRESSION_E_STACK_OVERFLOW;
       Dwarf_Off addr = (Dwarf_Off) (uintptr_t)
-        MC_object_base_address(state->object_info) + op->number;
+        state->object_info->base_address() + op->number;
       error = mc_dwarf_push_value(state, addr);
       break;
     }
@@ -601,9 +601,7 @@ void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info,
     expression->ops = NULL;
     mc_dwarf_expression_init(expression, len, ops);
 
-    void *base =
-        info->
-        flags & MC_OBJECT_INFO_EXECUTABLE ? 0 : MC_object_base_address(info);
+    void *base = info->base_address();
     // If start == 0, this is not a location list:
     expression->lowpc = start == 0 ? NULL : (char *) base + start;
     expression->highpc = start == 0 ? NULL : (char *) base + end;
index a247eba..d2ca1cd 100644 (file)
@@ -22,6 +22,7 @@ class ModelChecker;
 class AddressSpace;
 class Process;
 class Snapshot;
+class ObjectInformation;
 
 }
 }
@@ -31,6 +32,7 @@ typedef ::simgrid::mc::PageStore s_mc_pages_store_t;
 typedef ::simgrid::mc::AddressSpace s_mc_address_space_t;
 typedef ::simgrid::mc::Process s_mc_process_t;
 typedef ::simgrid::mc::Snapshot s_mc_snapshot_t;
+typedef ::simgrid::mc::ObjectInformation s_mc_object_info_t;
 
 #else
 
@@ -39,10 +41,11 @@ typedef struct _s_mc_pages_store s_mc_pages_store_t;
 typedef struct _s_mc_address_space_t s_mc_address_space_t;
 typedef struct _s_mc_process_t s_mc_process_t;
 typedef struct _s_mc_snapshot_t s_mc_snapshot_t;
+typedef struct _s_mc_object_info_t s_mc_object_info_t;
 
 #endif
 
-typedef struct s_mc_object_info s_mc_object_info_t, *mc_object_info_t;
+
 typedef struct s_dw_type s_dw_type_t, *dw_type_t;
 typedef struct s_memory_map s_memory_map_t, *memory_map_t;
 typedef struct s_dw_variable s_dw_variable_t, *dw_variable_t;
@@ -54,6 +57,7 @@ typedef s_mc_model_checker_t *mc_model_checker_t;
 typedef s_mc_address_space_t *mc_address_space_t;
 typedef s_mc_process_t *mc_process_t;
 typedef s_mc_snapshot_t *mc_snapshot_t;
+typedef s_mc_object_info_t *mc_object_info_t;
 
 SG_BEGIN_DECL()
 extern mc_model_checker_t mc_model_checker;
index 2b00607..e040769 100644 (file)
 #include "mc_object_info.h"
 #include "mc_private.h"
 
-dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip)
+namespace simgrid {
+namespace mc {
+
+dw_frame_t ObjectInformation::find_function(const void *ip) const
 {
-  xbt_dynar_t dynar = info->functions_index;
+  xbt_dynar_t dynar = this->functions_index;
   mc_function_index_item_t base =
       (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0);
   int i = 0;
@@ -28,17 +31,20 @@ dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *
       return base[k].function;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
-dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, const char* name)
+dw_variable_t ObjectInformation::find_variable(const char* name) const
 {
   unsigned int cursor = 0;
   dw_variable_t variable;
-  xbt_dynar_foreach(info->global_variables, cursor, variable){
+  xbt_dynar_foreach(this->global_variables, cursor, variable){
     if(!strcmp(name, variable->name))
       return variable;
   }
 
-  return NULL;
+  return nullptr;
+}
+
 }
+}
\ No newline at end of file
index b356884..f7ab5b5 100644 (file)
@@ -58,11 +58,15 @@ typedef int mc_object_info_flags;
 #define MC_OBJECT_INFO_NONE 0
 #define MC_OBJECT_INFO_EXECUTABLE 1
 
-struct s_mc_object_info {
-  s_mc_object_info();
-  ~s_mc_object_info();
-  s_mc_object_info(s_mc_object_info const&) = delete;
-  s_mc_object_info& operator=(s_mc_object_info const&) = delete;
+namespace simgrid {
+namespace mc {
+
+class ObjectInformation {
+public:
+  ObjectInformation();
+  ~ObjectInformation();
+  ObjectInformation(ObjectInformation const&) = delete;
+  ObjectInformation& operator=(ObjectInformation const&) = delete;
 
   mc_object_info_flags flags;
   char* file_name;
@@ -83,44 +87,29 @@ struct s_mc_object_info {
   // lookup of a function given an instruction pointer.
   // The entries are sorted by low_pc and a binary search can be used to look them up.
   xbt_dynar_t functions_index;
-};
 
-static inline __attribute__ ((always_inline))
-bool MC_object_info_executable(mc_object_info_t info)
-{
-  return info->flags & MC_OBJECT_INFO_EXECUTABLE;
-}
+  bool executable() const
+  {
+    return this->flags & MC_OBJECT_INFO_EXECUTABLE;
+  }
 
-static inline __attribute__ ((always_inline))
-bool MC_object_info_is_privatized(mc_object_info_t info)
-{
-  return info && MC_object_info_executable(info) && smpi_privatize_global_variables;
-}
+  bool privatized() const
+  {
+    return this->executable() && smpi_privatize_global_variables;
+  }
 
-/** Find the DWARF offset for this ELF object
- *
- *  An offset is applied to address found in DWARF:
- *
- *  <ul>
- *    <li>for an executable obejct, addresses are virtual address
- *        (there is no offset) i.e. \f$\text{virtual address} = \{dwarf address}\f$;</li>
- *    <li>for a shared object, the addreses are offset from the begining
- *        of the shared object (the base address of the mapped shared
- *        object must be used as offset
- *        i.e. \f$\text{virtual address} = \text{shared object base address}
- *             + \text{dwarf address}\f$.</li>
- *
- */
-XBT_INTERNAL void* MC_object_base_address(mc_object_info_t info);
+  void* base_address() const;
 
-XBT_INTERNAL std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
-  std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
+  dw_frame_t find_function(const void *ip) const;
+  dw_variable_t find_variable(const char* name) const;
 
-XBT_INTERNAL void MC_free_object_info(mc_object_info_t* p);
+};
 
-XBT_INTERNAL dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip);
-MC_SHOULD_BE_INTERNAL dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, const char* name);
+}
+}
 
+XBT_INTERNAL std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
+  std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
 XBT_INTERNAL void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
 
 XBT_INTERNAL void MC_dwarf_get_variables(mc_object_info_t info);
@@ -128,9 +117,6 @@ XBT_INTERNAL void MC_dwarf_get_variables_libdw(mc_object_info_t info);
 XBT_INTERNAL const char* MC_dwarf_attrname(int attr);
 XBT_INTERNAL const char* MC_dwarf_tagname(int tag);
 
-// Not used:
-XBT_INTERNAL char* get_type_description(mc_object_info_t info, char *type_name);
-
 XBT_INTERNAL void* mc_member_resolve(const void* base, dw_type_t type, dw_type_t member, mc_address_space_t snapshot, int process_index);
 
 struct s_dw_variable{
index 1a799ae..3ebec2a 100644 (file)
@@ -411,9 +411,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;
@@ -422,9 +422,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;
@@ -436,10 +436,7 @@ std::shared_ptr<s_mc_object_info_t> Process::find_object_info_rw(remote_ptr<void
 dw_frame_t 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());
+  return info ? info->find_function((void*) ip.address()) : nullptr;
 }
 
 /** Find (one occurence of) the named variable definition
@@ -452,13 +449,13 @@ dw_variable_t Process::find_variable(const char* name) const
   // 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);
+    dw_variable_t 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);
+    dw_variable_t var = info->find_variable(name);
     if (var)
       return var;
   }
@@ -521,7 +518,7 @@ const void *Process::read_bytes(void* buffer, std::size_t size,
     std::shared_ptr<s_mc_object_info_t> const& info =
       this->find_object_info_rw((void*)address.address());
     // Segment overlap is not handled.
-    if (MC_object_info_is_privatized(info.get())) {
+    if (info.get() && info.get()->privatized()) {
       if (process_index < 0)
         xbt_die("Missing process index");
       if (process_index >= (int) MC_smpi_process_count())
index 5c07416..104294f 100644 (file)
@@ -87,7 +87,7 @@ static void test_local_variable(mc_object_info_t info, const char* function, con
 
 static dw_variable_t test_global_variable(mc_process_t process, mc_object_info_t info, const char* name, void* address, long byte_size) {
 
-  dw_variable_t variable = MC_file_object_info_find_variable_by_name(info, name);
+  dw_variable_t variable = info->find_variable(name);
   xbt_assert(variable, "Global variable %s was not found", name);
   xbt_assert(!strcmp(variable->name, name), "Name mismatch for %s", name);
   xbt_assert(variable->global, "Variable %s is not global", name);