Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] OOPify/C++ify Type
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 17 Jul 2015 11:15:46 +0000 (13:15 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jul 2015 12:18:30 +0000 (14:18 +0200)
include/xbt/mmalloc.h
src/mc/mc_compare.cpp
src/mc/mc_diff.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_forward.h
src/mc/mc_hash.cpp
src/mc/mc_member.cpp
src/mc/mc_object_info.cpp
src/mc/mc_object_info.h
src/mc/mc_snapshot.h
teshsuite/mc/dwarf/dwarf.cpp

index 33ad322..9378841 100644 (file)
@@ -67,12 +67,10 @@ XBT_PUBLIC( xbt_mheap_t ) mmalloc_get_default_md(void);
 xbt_mheap_t mmalloc_set_current_heap(xbt_mheap_t new_heap);
 xbt_mheap_t mmalloc_get_current_heap(void);
 
-struct s_dw_type;
-
 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2);
 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2);
 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t to_ignore1, xbt_dynar_t to_ignore2);
-int compare_heap_area(int process_index, const void *area1, const void* area2, mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_dynar_t previous, struct s_dw_type *type, int pointer_level);
+int compare_heap_area(int process_index, const void *area1, const void* area2, mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_dynar_t previous, mc_type_t type, int pointer_level);
 void reset_heap_information(void);
 
 size_t mmalloc_get_bytes_used(xbt_mheap_t);
index 39aaf87..284cc51 100644 (file)
@@ -104,12 +104,12 @@ static int compare_areas_with_type(struct mc_compare_state& state,
                                    int process_index,
                                    void* real_area1, mc_snapshot_t snapshot1, mc_mem_region_t region1,
                                    void* real_area2, mc_snapshot_t snapshot2, mc_mem_region_t region2,
-                                   dw_type_t type, int pointer_level)
+                                   mc_type_t type, int pointer_level)
 {
   mc_process_t process = &mc_model_checker->process();
 
   unsigned int cursor = 0;
-  dw_type_t member, subtype, subsubtype;
+  mc_type_t member, subtype, subsubtype;
   int elm_size, i, res;
 
   top:
@@ -211,7 +211,7 @@ static int compare_areas_with_type(struct mc_compare_state& state,
       else if (region1->contain(simgrid::mc::remote(addr_pointed1))) {
         if (!region2->contain(simgrid::mc::remote(addr_pointed2)))
           return 1;
-        if (type->dw_type_id == NULL)
+        if (type->dw_type_id.empty())
           return (addr_pointed1 != addr_pointed2);
         else {
           return compare_areas_with_type(state, process_index,
@@ -311,7 +311,7 @@ static int compare_global_variables(mc_object_info_t object_info,
         || (char *) current_var->address > (char *) object_info->end_rw)
       continue;
 
-    dw_type_t bvariable_type = current_var->type;
+    mc_type_t bvariable_type = current_var->type;
     res =
         compare_areas_with_type(state, process_index,
                                 (char *) current_var->address, snapshot1, r1,
@@ -361,7 +361,7 @@ static int compare_local_variables(int process_index,
       }
       // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
 
-        dw_type_t subtype = current_var1->type;
+        mc_type_t subtype = current_var1->type;
         res =
             compare_areas_with_type(state, process_index,
                                     current_var1->address, snapshot1, mc_get_snapshot_region(current_var1->address, snapshot1, process_index),
index 6ea1d01..b3940c2 100644 (file)
@@ -151,7 +151,7 @@ struct s_mc_diff {
   std::vector<s_mc_heap_ignore_region_t>* to_ignore1;
   std::vector<s_mc_heap_ignore_region_t>* to_ignore2;
   s_heap_area_t *equals_to1, *equals_to2;
-  dw_type_t *types1, *types2;
+  mc_type_t *types1, *types2;
   size_t available;
 };
 
@@ -380,7 +380,7 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
         realloc(state->equals_to1,
                 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
                 sizeof(s_heap_area_t));
-    state->types1 = (s_dw_type**)
+    state->types1 = (simgrid::mc::Type**)
         realloc(state->types1,
                 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
                 sizeof(type_name *));
@@ -388,7 +388,7 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
         realloc(state->equals_to2,
                 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
                 sizeof(s_heap_area_t));
-    state->types2 = (s_dw_type**)
+    state->types2 = (simgrid::mc::Type**)
         realloc(state->types2,
                 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
                 sizeof(type_name *));
@@ -875,7 +875,7 @@ static int compare_heap_area_with_type(struct s_mc_diff *state, int process_inde
                                        const void *real_area1, const void *real_area2,
                                        mc_snapshot_t snapshot1,
                                        mc_snapshot_t snapshot2,
-                                       xbt_dynar_t previous, dw_type_t type,
+                                       xbt_dynar_t previous, mc_type_t type,
                                        int area_size, int check_ignore,
                                        int pointer_level)
 {
@@ -893,10 +893,10 @@ top:
     return 0;
   }
 
-  dw_type_t subtype, subsubtype;
+  mc_type_t subtype, subsubtype;
   int res, elm_size;
   unsigned int cursor = 0;
-  dw_type_t member;
+  mc_type_t member;
   const void *addr_pointed1, *addr_pointed2;;
 
   mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
@@ -907,7 +907,7 @@ top:
     return 1;
 
   case DW_TAG_base_type:
-    if (type->name != NULL && strcmp(type->name, "char") == 0) {        /* String, hence random (arbitrary ?) size */
+    if (!type->name.empty() && type->name == "char") {        /* String, hence random (arbitrary ?) size */
       if (real_area1 == real_area2)
         return -1;
       else
@@ -1083,7 +1083,7 @@ top:
  * @param  area_size
  * @return                    DWARF type ID for given offset
  */
-static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
+static mc_type_t get_offset_type(void *real_base_address, mc_type_t type,
                                  int offset, int area_size,
                                  mc_snapshot_t snapshot, int process_index)
 {
@@ -1105,7 +1105,7 @@ static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
         return NULL;
     } else {
       unsigned int cursor = 0;
-      dw_type_t member;
+      mc_type_t member;
       xbt_dynar_foreach(type->members, cursor, member) {
 
         if (!member->location.size) {
@@ -1144,7 +1144,7 @@ static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
  */
 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
                       mc_snapshot_t snapshot2, xbt_dynar_t previous,
-                      dw_type_t type, int pointer_level)
+                      mc_type_t type, int pointer_level)
 {
   mc_process_t process = &mc_model_checker->process();
 
@@ -1159,7 +1159,7 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m
   int type_size = -1;
   int offset1 = 0, offset2 = 0;
   int new_size1 = -1, new_size2 = -1;
-  dw_type_t new_type1 = NULL, new_type2 = NULL;
+  mc_type_t new_type1 = NULL, new_type2 = NULL;
 
   int match_pairs = 0;
 
@@ -1223,8 +1223,8 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m
 
     // Find type_size:
     if ((type->type == DW_TAG_pointer_type)
-        || ((type->type == DW_TAG_base_type) && type->name != NULL
-            && (!strcmp(type->name, "char"))))
+        || ((type->type == DW_TAG_base_type) && !type->name.empty()
+            && type->name == "char"))
       type_size = -1;
     else
       type_size = type->byte_size;
@@ -1272,7 +1272,7 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m
     if (type_size != -1) {
       if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
           && type_size != (ssize_t)   heapinfo2->busy_block.busy_size
-          && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
+          && (type->name.empty() || type->name == "struct s_smx_context")) {
         if (match_pairs) {
           match_equals(state, previous);
           xbt_dynar_free(&previous);
index faba98c..7bdc76e 100644 (file)
@@ -18,6 +18,9 @@
 #include "mc_object_info.h"
 #include "mc_private.h"
 
+static void dw_variable_free(dw_variable_t v);
+static void dw_variable_free_voidp(void *t);
+
 static void MC_dwarf_register_global_variable(mc_object_info_t info, dw_variable_t variable);
 static void MC_register_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable);
 static void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable);
@@ -449,7 +452,7 @@ static uint64_t MC_dwarf_array_element_count(Dwarf_Die * die, Dwarf_Die * unit)
   return result;
 }
 
-// ***** dw_type_t
+// ***** mc_type_t
 
 /** \brief Initialize the location of a member of a type
  * (DW_AT_data_member_location of a DW_TAG_member).
@@ -458,7 +461,7 @@ static uint64_t MC_dwarf_array_element_count(Dwarf_Die * die, Dwarf_Die * unit)
  *  \param  member the member of the type
  *  \param  child  DIE of the member (DW_TAG_member)
  */
-static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member,
+static void MC_dwarf_fill_member_location(mc_type_t type, mc_type_t member,
                                           Dwarf_Die * child)
 {
   if (dwarf_hasattr(child, DW_AT_data_bit_offset)) {
@@ -469,7 +472,8 @@ static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member,
     if (type->type != DW_TAG_union_type) {
       xbt_die
           ("Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%"
-           PRIx64 ">%s", member->name, (uint64_t) type->id, type->name);
+           PRIx64 ">%s", member->name.c_str(),
+           (uint64_t) type->id, type->name.c_str());
     } else {
       return;
     }
@@ -490,7 +494,7 @@ static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member,
         xbt_die
             ("Could not read location expression DW_AT_data_member_location in DW_TAG_member %s of type <%"
              PRIx64 ">%s", MC_dwarf_attr_integrate_string(child, DW_AT_name),
-             (uint64_t) type->id, type->name);
+             (uint64_t) type->id, type->name.c_str());
       }
       if (len == 1 && expr[0].atom == DW_OP_plus_uconst) {
         member->offset = expr[0].number;
@@ -508,7 +512,7 @@ static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member,
       else
         xbt_die("Cannot get %s location <%" PRIx64 ">%s",
                 MC_dwarf_attr_integrate_string(child, DW_AT_name),
-                (uint64_t) type->id, type->name);
+                (uint64_t) type->id, type->name.c_str());
       break;
     }
   case MC_DW_CLASS_LOCLISTPTR:
@@ -526,7 +530,7 @@ static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member,
 
 static void dw_type_free_voidp(void *t)
 {
-  delete *(dw_type_t*)t;
+  delete *(mc_type_t*)t;
 }
 
 /** \brief Populate the list of members of a type
@@ -537,13 +541,13 @@ static void dw_type_free_voidp(void *t)
  *  \param type the type
  */
 static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die,
-                                 Dwarf_Die * unit, dw_type_t type)
+                                 Dwarf_Die * unit, mc_type_t type)
 {
   int res;
   Dwarf_Die child;
   xbt_assert(!type->members);
   type->members =
-      xbt_dynar_new(sizeof(dw_type_t), (void (*)(void *)) dw_type_free_voidp);
+      xbt_dynar_new(sizeof(mc_type_t), (void (*)(void *)) dw_type_free_voidp);
   for (res = dwarf_child(die, &child); res == 0;
        res = dwarf_siblingof(&child, &child)) {
     int tag = dwarf_tag(&child);
@@ -558,7 +562,7 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die,
         continue;
 
       // TODO, we should use another type (because is is not a type but a member)
-      dw_type_t member = xbt_new0(s_dw_type_t, 1);
+      mc_type_t member = new simgrid::mc::Type();
       member->type = tag;
 
       // Global Offset:
@@ -566,17 +570,16 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die,
 
       const char *name = MC_dwarf_attr_integrate_string(&child, DW_AT_name);
       if (name)
-        member->name = xbt_strdup(name);
-      else
-        member->name = NULL;
-
+        member->name = name;
       member->byte_size =
           MC_dwarf_attr_integrate_uint(&child, DW_AT_byte_size, 0);
       member->element_count = -1;
-      member->dw_type_id = MC_dwarf_at_type(&child);
-      member->members = NULL;
-      member->is_pointer_type = 0;
-      member->offset = 0;
+
+      char* type_id = MC_dwarf_at_type(&child);
+      if (type_id) {
+        member->dw_type_id = type_id;
+        free(type_id);
+      }
 
       if (dwarf_hasattr(&child, DW_AT_data_bit_offset)) {
         xbt_die("Can't groke DW_AT_data_bit_offset.");
@@ -584,9 +587,10 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die,
 
       MC_dwarf_fill_member_location(type, member, &child);
 
-      if (!member->dw_type_id) {
-        xbt_die("Missing type for member %s of <%" PRIx64 ">%s", member->name,
-                (uint64_t) type->id, type->name);
+      if (member->dw_type_id.empty()) {
+        xbt_die("Missing type for member %s of <%" PRIx64 ">%s",
+                member->name.c_str(),
+                (uint64_t) type->id, type->name.c_str());
       }
 
       xbt_dynar_push(type->members, &member);
@@ -601,21 +605,15 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die,
  *  \param unit compilation unit of the current DIE
  *  \return MC representation of the type
  */
-static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die,
+static mc_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die,
                                       Dwarf_Die * unit, dw_frame_t frame,
                                       const char *ns)
 {
 
-  dw_type_t type = new s_dw_type();
+  mc_type_t type = new simgrid::mc::Type();
   type->type = -1;
-  type->id = 0;
-  type->name = NULL;
-  type->byte_size = 0;
+  type->name = std::string();
   type->element_count = -1;
-  type->dw_type_id = NULL;
-  type->members = NULL;
-  type->is_pointer_type = 0;
-  type->offset = 0;
 
   type->type = dwarf_tag(die);
 
@@ -639,12 +637,17 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die,
 
   const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
   if (name != NULL) {
-    type->name =
-        ns ? bprintf("%s%s::%s", prefix, ns,
-                            name) : bprintf("%s%s", prefix, name);
+    char* full_name = ns ? bprintf("%s%s::%s", prefix, ns, name) :
+      bprintf("%s%s", prefix, name);
+    type->name = std::string(full_name);
+    free(full_name);
   }
 
-  type->dw_type_id = MC_dwarf_at_type(die);
+  char* type_id = MC_dwarf_at_type(die);
+  if (type_id) {
+    type->dw_type_id = type_id;
+    free(type_id);
+  }
 
   // Some compilers do not emit DW_AT_byte_size for pointer_type,
   // so we fill this. We currently assume that the model-checked process is in
@@ -680,7 +683,7 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die,
   case DW_TAG_union_type:
   case DW_TAG_class_type:
     MC_dwarf_add_members(info, die, unit, type);
-    char *new_ns = ns == NULL ? xbt_strdup(type->name)
+    char *new_ns = ns == NULL ? xbt_strdup(type->name.c_str())
         : bprintf("%s::%s", ns, name);
     MC_dwarf_handle_children(info, die, unit, frame, new_ns);
     free(new_ns);
@@ -694,14 +697,14 @@ static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die,
                                      Dwarf_Die * unit, dw_frame_t frame,
                                      const char *ns)
 {
-  dw_type_t type = MC_dwarf_die_to_type(info, die, unit, frame, ns);
+  mc_type_t type = MC_dwarf_die_to_type(info, die, unit, frame, ns);
 
   char *key = bprintf("%" PRIx64, (uint64_t) type->id);
   xbt_dict_set(info->types, key, type, NULL);
   xbt_free(key);
 
-  if (type->name && type->byte_size != 0) {
-    xbt_dict_set(info->full_types_by_name, type->name, type, NULL);
+  if (!type->name.empty() && type->byte_size != 0) {
+    xbt_dict_set(info->full_types_by_name, type->name.c_str(), type, NULL);
   }
 }
 
@@ -1039,31 +1042,7 @@ void mc_frame_free(dw_frame_t frame)
   xbt_free(frame);
 }
 
-s_dw_type::s_dw_type()
-{
-  this->type = 0;
-  this->id = 0;
-  this->name = nullptr;
-  this->byte_size = 0;
-  this->element_count = 0;
-  this->dw_type_id = nullptr;
-  this->members = nullptr;
-  this->is_pointer_type = 0;
-  this->location = { 0, 0, 0, 0};
-  this->offset = 0;
-  this->subtype = nullptr;
-  this->full_type = nullptr;
-}
-
-s_dw_type::~s_dw_type()
-{
-  xbt_free(this->name);
-  xbt_free(this->dw_type_id);
-  xbt_dynar_free(&this->members);
-  mc_dwarf_expression_clear(&this->location);
-}
-
-static void dw_type_free(dw_type_t t)
+static void dw_type_free(mc_type_t t)
 {
   delete t;
 }
@@ -1201,7 +1180,7 @@ static void MC_post_process_variables(mc_object_info_t info)
   dw_variable_t variable = NULL;
   xbt_dynar_foreach(info->global_variables, cursor, variable) {
     if (variable->type_origin) {
-      variable->type = (dw_type_t) xbt_dict_get_or_null(info->types, variable->type_origin);
+      variable->type = (mc_type_t) xbt_dict_get_or_null(info->types, variable->type_origin);
     }
   }
 }
@@ -1224,7 +1203,7 @@ static void mc_post_process_scope(mc_object_info_t info, dw_frame_t scope)
   dw_variable_t variable = NULL;
   xbt_dynar_foreach(scope->variables, cursor, variable) {
     if (variable->type_origin) {
-      variable->type = (dw_type_t) xbt_dict_get_or_null(info->types, variable->type_origin);
+      variable->type = (mc_type_t) xbt_dict_get_or_null(info->types, variable->type_origin);
     }
   }
 
@@ -1248,23 +1227,25 @@ static void MC_post_process_functions(mc_object_info_t info)
 
 /** \brief Fill/lookup the "subtype" field.
  */
-static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type)
+static void MC_resolve_subtype(mc_object_info_t info, mc_type_t type)
 {
 
-  if (type->dw_type_id == NULL)
+  if (type->dw_type_id.empty())
     return;
-  type->subtype = (dw_type_t) xbt_dict_get_or_null(info->types, type->dw_type_id);
+  type->subtype = (mc_type_t) xbt_dict_get_or_null(
+    info->types, type->dw_type_id.c_str());
   if (type->subtype == NULL)
     return;
   if (type->subtype->byte_size != 0)
     return;
-  if (type->subtype->name == NULL)
+  if (type->subtype->name.empty())
     return;
   // Try to find a more complete description of the type:
   // We need to fix in order to support C++.
 
-  dw_type_t subtype =
-    (dw_type_t) xbt_dict_get_or_null(info->full_types_by_name, type->subtype->name);
+  mc_type_t subtype =
+    (mc_type_t) xbt_dict_get_or_null(
+      info->full_types_by_name, type->subtype->name.c_str());
   if (subtype != NULL) {
     type->subtype = subtype;
   }
@@ -1275,13 +1256,13 @@ static void MC_post_process_types(mc_object_info_t info)
 {
   xbt_dict_cursor_t cursor = NULL;
   char *origin;
-  dw_type_t type;
+  mc_type_t type;
 
   // Lookup "subtype" field:
   xbt_dict_foreach(info->types, cursor, origin, type) {
     MC_resolve_subtype(info, type);
 
-    dw_type_t member;
+    mc_type_t member;
     unsigned int i = 0;
     if (type->members != NULL)
       xbt_dynar_foreach(type->members, i, member) {
@@ -1394,10 +1375,10 @@ void MC_post_process_object_info(mc_process_t process, mc_object_info_t info)
 {
   xbt_dict_cursor_t cursor = NULL;
   char *key = NULL;
-  dw_type_t type = NULL;
+  mc_type_t type = NULL;
   xbt_dict_foreach(info->types, cursor, key, type) {
 
-    dw_type_t subtype = type;
+    mc_type_t subtype = type;
     while (subtype->type == DW_TAG_typedef || subtype->type == DW_TAG_volatile_type
       || subtype->type == DW_TAG_const_type) {
       if (subtype->subtype)
@@ -1407,12 +1388,12 @@ void MC_post_process_object_info(mc_process_t process, mc_object_info_t info)
     }
 
     // Resolve full_type:
-    if (subtype->name && subtype->byte_size == 0) {
+    if (!subtype->name.empty() && subtype->byte_size == 0) {
       for (auto const& object_info : process->object_infos) {
-        dw_type_t same_type = (dw_type_t)
+        mc_type_t same_type = (mc_type_t)
             xbt_dict_get_or_null(object_info->full_types_by_name,
-                                 subtype->name);
-        if (same_type && same_type->name && same_type->byte_size) {
+                                 subtype->name.c_str());
+        if (same_type && !same_type->name.empty() && same_type->byte_size) {
           type->full_type = same_type;
           break;
         }
index d2ca1cd..f2de346 100644 (file)
@@ -23,6 +23,7 @@ class AddressSpace;
 class Process;
 class Snapshot;
 class ObjectInformation;
+class Type;
 
 }
 }
@@ -33,6 +34,7 @@ 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;
+typedef ::simgrid::mc::Type s_mc_type_t;
 
 #else
 
@@ -42,22 +44,21 @@ 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;
+typedef struct _s_mc_type_t s_mc_type_t;
 
 #endif
 
-
-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;
 typedef struct s_dw_frame s_dw_frame_t, *dw_frame_t;
 
-
 typedef s_mc_pages_store_t *mc_pages_store_t;
 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;
+typedef s_mc_type_t *mc_type_t;
 
 SG_BEGIN_DECL()
 extern mc_model_checker_t mc_model_checker;
index 65ee9d2..9e6b2c1 100644 (file)
@@ -84,7 +84,7 @@ static void mc_hash_binary(hash_type * hash, const void *s, size_t len)
  * */
 static void mc_hash_value(hash_type * hash, mc_hashing_state * state,
                           mc_object_info_t info, const void *address,
-                          dw_type_t type)
+                          mc_type_t type)
 {
   mc_process_t process = &mc_model_checker->process();
 top:
@@ -111,7 +111,7 @@ top:
         return;
 
       long element_count = type->element_count;
-      dw_type_t subtype = type->subtype;
+      mc_type_t subtype = type->subtype;
       if (subtype == NULL) {
         XBT_DEBUG("Hash array without subtype");
         return;
@@ -145,7 +145,7 @@ top:
         return;
 
       unsigned int cursor = 0;
-      dw_type_t member;
+      mc_type_t member;
       xbt_dynar_foreach(type->members, cursor, member) {
         XBT_DEBUG("Hash struct member %s", member->name);
         if (type->subtype == NULL)
@@ -189,7 +189,8 @@ top:
       }
 
       if (type->subtype == NULL) {
-        XBT_DEBUG("Missing type for %p (type=%s)", pointed, type->dw_type_id);
+        XBT_DEBUG("Missing type for %p (type=%s)",
+          pointed, type->dw_type_id.c_str());
         return;
       }
 
@@ -219,7 +220,7 @@ static void mc_hash_object_globals(hash_type * hash, mc_hashing_state * state,
       continue;
     }
 
-    dw_type_t type = variable->type;
+    mc_type_t type = variable->type;
     if (type == NULL) {
       // Nothing
       continue;
@@ -267,7 +268,7 @@ static void mc_hash_stack_frame(mc_hash_t * hash,
                                             variable->object_info, unw_cursor,
                                             frame_pointer, NULL);
 
-    dw_type_t type = variable->type;
+    mc_type_t type = variable->type;
     if (type == NULL) {
       XBT_DEBUG("Hash local variable %s without loctypeation", variable->name);
       continue;
index 21eaf14..1fde63e 100644 (file)
@@ -17,7 +17,7 @@
  * @param snapshot Snapshot (or NULL)
  * @return Process address of the given member of the 'object' struct/class
  */
-void *mc_member_resolve(const void *base, dw_type_t type, dw_type_t member,
+void *mc_member_resolve(const void *base, mc_type_t type, mc_type_t member,
                         mc_address_space_t address_space, int process_index)
 {
   if (!member->location.size) {
index e040769..67e4d35 100644 (file)
 namespace simgrid {
 namespace mc {
 
+// Type
+
+Type::Type()
+{
+  this->type = 0;
+  this->id = 0;
+  this->name = std::string();
+  this->byte_size = 0;
+  this->element_count = 0;
+  this->members = nullptr;
+  this->is_pointer_type = 0;
+  this->location = {0, 0, 0, 0};
+  this->offset = 0;
+  this->subtype = nullptr;
+  this->full_type = nullptr;
+}
+
+Type::~Type()
+{
+  xbt_dynar_free(&this->members);
+  mc_dwarf_expression_clear(&this->location);
+}
+
+// ObjectInformations
+
 dw_frame_t ObjectInformation::find_function(const void *ip) const
 {
   xbt_dynar_t dynar = this->functions_index;
index f7ab5b5..553bee1 100644 (file)
@@ -12,7 +12,8 @@
 #define SIMGRID_MC_OBJECT_INFO_H
 
 #include <stdint.h>
-#include <stdbool.h>
+
+#include <string>
 
 #include <simgrid_config.h>
 #include <xbt/dict.h>
 
 // ***** Type
 
-typedef int e_dw_type_type;
+typedef int e_mc_type_type;
 
-struct s_dw_type {
-  s_dw_type();
-  ~s_dw_type();
+namespace simgrid {
+namespace mc {
 
-  e_dw_type_type type;
+class Type {
+public:
+  Type();
+  ~Type();
+  Type(Type const& type) = delete;
+  Type& operator=(Type const&) = delete;
+
+  e_mc_type_type type;
   Dwarf_Off id; /* Offset in the section (in hexadecimal form) */
-  char *name; /* Name of the type */
+  std::string name; /* Name of the type */
   int byte_size; /* Size in bytes */
   int element_count; /* Number of elements for array type */
-  char *dw_type_id; /* DW_AT_type id */
+  std::string dw_type_id; /* DW_AT_type id */
   xbt_dynar_t members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
   int is_pointer_type;
 
@@ -44,12 +51,12 @@ struct s_dw_type {
   struct s_mc_expression location;
   int offset;
 
-  dw_type_t subtype; // DW_AT_type
-  dw_type_t full_type; // The same (but more complete) type
+  mc_type_t subtype; // DW_AT_type
+  mc_type_t full_type; // The same (but more complete) type
 };
 
-XBT_INTERNAL void dw_variable_free(dw_variable_t v);
-XBT_INTERNAL void dw_variable_free_voidp(void *t);
+}
+}
 
 // ***** Object info
 
@@ -80,8 +87,8 @@ public:
   char *end_ro; // read-only segment
   xbt_dict_t subprograms; // xbt_dict_t<origin as hexadecimal string, dw_frame_t>
   xbt_dynar_t global_variables; // xbt_dynar_t<dw_variable_t>
-  xbt_dict_t types; // xbt_dict_t<origin as hexadecimal string, dw_type_t>
-  xbt_dict_t full_types_by_name; // xbt_dict_t<name, dw_type_t> (full defined type only)
+  xbt_dict_t types; // xbt_dict_t<origin as hexadecimal string, mc_type_t>
+  xbt_dict_t full_types_by_name; // xbt_dict_t<name, mc_type_t> (full defined type only)
 
   // Here we sort the minimal information for an efficient (and cache-efficient)
   // lookup of a function given an instruction pointer.
@@ -117,14 +124,14 @@ 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);
 
-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);
+XBT_INTERNAL void* mc_member_resolve(const void* base, mc_type_t type, mc_type_t member, mc_address_space_t snapshot, int process_index);
 
 struct s_dw_variable{
   Dwarf_Off dwarf_offset; /* Global offset of the field. */
   int global;
   char *name;
   char *type_origin;
-  dw_type_t type;
+  mc_type_t type;
 
   // Use either of:
   s_mc_location_list_t locations;
index fc2ea78..d3c0542 100644 (file)
@@ -113,7 +113,7 @@ typedef struct s_local_variable{
   dw_frame_t subprogram;
   unsigned long ip;
   std::string name;
-  dw_type_t type;
+  mc_type_t type;
   void *address;
   int region;
 } s_local_variable_t, *local_variable_t;
index 104294f..cf95adf 100644 (file)
 int test_some_array[4][5][6];
 struct some_struct { int first; int second[4][5]; } test_some_struct;
 
-static dw_type_t find_type_by_name(mc_object_info_t info, const char* name) {
+static mc_type_t find_type_by_name(mc_object_info_t info, const char* name) {
   xbt_dict_cursor_t cursor = NULL;
   char *key;
-  dw_type_t type;
-  xbt_dict_foreach(info->types, cursor, key, type) {
-    if(!strcmp(name, type->name))
+  mc_type_t type;
+  xbt_dict_foreach(info->types, cursor, key, type)
+    if(type->name == name)
       return type;
-  }
-
   return NULL;
 }
 
@@ -94,19 +92,18 @@ static dw_variable_t test_global_variable(mc_process_t process, mc_object_info_t
   xbt_assert(variable->address == address,
       "Address mismatch for %s : %p expected but %p found", name, address, variable->address);
 
-  dw_type_t type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, variable->type_origin);
+  mc_type_t type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, variable->type_origin);
   xbt_assert(type!=NULL, "Missing type for %s", name);
   xbt_assert(type->byte_size = byte_size, "Byte size mismatch for %s", name);
   return variable;
 }
 
-static dw_type_t find_member(mc_object_info_t info, const char* name, dw_type_t type) {
+static mc_type_t find_member(mc_object_info_t info, const char* name, mc_type_t type) {
   unsigned int cursor = 0;
-  dw_type_t member;
-  xbt_dynar_foreach(type->members, cursor, member){
-    if(!strcmp(name,member->name))
+  mc_type_t member;
+  xbt_dynar_foreach(type->members, cursor, member)
+    if(member->name == name)
       return member;
-  }
   return NULL;
 }
 
@@ -123,7 +120,7 @@ int main(int argc, char** argv)
   SIMIX_global_init(&argc, argv);
 
   dw_variable_t var;
-  dw_type_t type;
+  mc_type_t type;
 
   s_mc_process_t p(getpid(), -1);
   mc_process_t process = &p;
@@ -133,12 +130,12 @@ int main(int argc, char** argv)
 
   var = test_global_variable(process, process->binary_info.get(),
     "test_some_array", &test_some_array, sizeof(test_some_array));
-  type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
+  type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
   xbt_assert(type->element_count == 6*5*4, "element_count mismatch in test_some_array : %i / %i", type->element_count, 6*5*4);
 
   var = test_global_variable(process, process->binary_info.get(),
     "test_some_struct", &test_some_struct, sizeof(test_some_struct));
-  type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
+  type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
   assert(find_member(process->binary_info.get(), "first", type)->offset == 0);
   assert(find_member(process->binary_info.get(), "second", type)->offset
       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);