Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix type name handling
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 18 Mar 2014 13:40:20 +0000 (14:40 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 18 Mar 2014 13:40:20 +0000 (14:40 +0100)
 * use a suitable prefix for type names (struct/class/union);

 * rename "types_by_name" into "full_types_by_name" to be more
   descriptive.

src/mc/mc_checkpoint.c
src/mc/mc_dwarf.c
src/mc/mc_global.c
src/mc/mc_private.h
src/xbt/mmalloc/mm_diff.c
testsuite/mc/dwarf.c

index e72bef3..8c49abb 100644 (file)
@@ -163,7 +163,7 @@ static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type) {
   // Try to find a more complete description of the type:
   // We need to fix in order to support C++.
 
   // Try to find a more complete description of the type:
   // We need to fix in order to support C++.
 
-  dw_type_t subtype = xbt_dict_get_or_null(info->types_by_name, type->subtype->name);
+  dw_type_t subtype = xbt_dict_get_or_null(info->full_types_by_name, type->subtype->name);
   if(subtype!=NULL) {
     type->subtype = subtype;
   }
   if(subtype!=NULL) {
     type->subtype = subtype;
   }
index 80b9bdd..1ee1468 100644 (file)
@@ -520,9 +520,24 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die* die, Dwa
   // Global Offset
   type->id = (void *) dwarf_dieoffset(die);
 
   // Global Offset
   type->id = (void *) dwarf_dieoffset(die);
 
+  char* prefix = "";
+  switch (type->type) {
+  case DW_TAG_structure_type:
+    prefix = "struct ";
+    break;
+  case DW_TAG_union_type:
+    prefix = "union ";
+    break;
+  case DW_TAG_class_type:
+    prefix = "class ";
+    break;
+  default:
+    prefix = "";
+  }
+
   const char* name = MC_dwarf_attr_string(die, DW_AT_name);
   if (name!=NULL) {
   const char* name = MC_dwarf_attr_string(die, DW_AT_name);
   if (name!=NULL) {
-       type->name = xbt_strdup(name);
+    type->name = namespace ? bprintf("%s%s::%s", prefix, namespace, name) : bprintf("%s%s", prefix, name);
   }
 
   XBT_DEBUG("Processing type <%p>%s", type->id, type->name);
   }
 
   XBT_DEBUG("Processing type <%p>%s", type->id, type->name);
@@ -556,7 +571,7 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die* die, Dwa
   case DW_TAG_class_type:
          MC_dwarf_add_members(info, die, unit, type);
          char* new_namespace = namespace == NULL ? xbt_strdup(type->name)
   case DW_TAG_class_type:
          MC_dwarf_add_members(info, die, unit, type);
          char* new_namespace = namespace == NULL ? xbt_strdup(type->name)
-           : bprintf("%s::%s", namespace, type->name);
+           : bprintf("%s::%s", namespace, name);
          MC_dwarf_handle_children(info, die, unit, frame, new_namespace);
          free(new_namespace);
          break;
          MC_dwarf_handle_children(info, die, unit, frame, new_namespace);
          free(new_namespace);
          break;
@@ -572,7 +587,7 @@ static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die* die, Dwar
   xbt_dict_set(info->types, key, type, NULL);
 
   if(type->name && type->byte_size!=0) {
   xbt_dict_set(info->types, key, type, NULL);
 
   if(type->name && type->byte_size!=0) {
-    xbt_dict_set(info->types_by_name, type->name, type, NULL);
+    xbt_dict_set(info->full_types_by_name, type->name, type, NULL);
   }
 }
 
   }
 }
 
index f5d183b..47ab4ac 100644 (file)
@@ -186,7 +186,7 @@ mc_object_info_t MC_new_object_info(void) {
   res->subprograms = xbt_dynar_new(sizeof(dw_frame_t), NULL);
   res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
   res->types = xbt_dict_new_homogeneous(NULL);
   res->subprograms = xbt_dynar_new(sizeof(dw_frame_t), NULL);
   res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
   res->types = xbt_dict_new_homogeneous(NULL);
-  res->types_by_name = xbt_dict_new_homogeneous(NULL);
+  res->full_types_by_name = xbt_dict_new_homogeneous(NULL);
   return res;
 }
 
   return res;
 }
 
@@ -195,7 +195,7 @@ void MC_free_object_info(mc_object_info_t* info) {
   xbt_dynar_free(&(*info)->subprograms);
   xbt_dynar_free(&(*info)->global_variables);
   xbt_dict_free(&(*info)->types);
   xbt_dynar_free(&(*info)->subprograms);
   xbt_dynar_free(&(*info)->global_variables);
   xbt_dict_free(&(*info)->types);
-  xbt_dict_free(&(*info)->types_by_name);
+  xbt_dict_free(&(*info)->full_types_by_name);
   xbt_free(info);
   xbt_dynar_free(&(*info)->functions_index);
   *info = NULL;
   xbt_free(info);
   xbt_dynar_free(&(*info)->functions_index);
   *info = NULL;
@@ -741,7 +741,7 @@ static void MC_post_process_object_info(mc_object_info_t info) {
   dw_type_t type = NULL;
   xbt_dict_foreach(info->types, cursor, key, type){
     if(type->name && type->byte_size == 0) {
   dw_type_t type = NULL;
   xbt_dict_foreach(info->types, cursor, key, type){
     if(type->name && type->byte_size == 0) {
-      type->other_object_same_type = xbt_dict_get_or_null(other_info->types_by_name, type->name);
+      type->other_object_same_type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name);
     }
   }
 }
     }
   }
 }
index fa2945f..47fb84c 100644 (file)
@@ -349,7 +349,7 @@ struct s_mc_object_info {
   xbt_dynar_t subprograms; // xbt_dynar_t<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_dynar_t subprograms; // xbt_dynar_t<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 types_by_name; // xbt_dict_t<name, dw_type_t> (full defined type only)
+  xbt_dict_t full_types_by_name; // xbt_dict_t<name, dw_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.
 
   // Here we sort the minimal information for an efficient (and cache-efficient)
   // lookup of a function given an instruction pointer.
index a634e67..07419b6 100644 (file)
@@ -875,7 +875,7 @@ static int compare_heap_area_with_type(struct s_mm_diff *state, void *real_area1
     case DW_TAG_class_type:
     case DW_TAG_union_type:
       if(subtype->byte_size == 0){ /*declaration of the type, need the complete description */
     case DW_TAG_class_type:
     case DW_TAG_union_type:
       if(subtype->byte_size == 0){ /*declaration of the type, need the complete description */
-          subtype = xbt_dict_get_or_null(other_info->types_by_name, subtype->name);
+          subtype = xbt_dict_get_or_null(other_info->full_types_by_name, subtype->name);
           switch_types = 1;
       }
       elm_size = subtype->byte_size;
           switch_types = 1;
       }
       elm_size = subtype->byte_size;
@@ -886,7 +886,7 @@ static int compare_heap_area_with_type(struct s_mm_diff *state, void *real_area1
     case DW_TAG_volatile_type:
       subsubtype = subtype->subtype;
       if(subsubtype->byte_size == 0){ /*declaration of the type, need the complete description */
     case DW_TAG_volatile_type:
       subsubtype = subtype->subtype;
       if(subsubtype->byte_size == 0){ /*declaration of the type, need the complete description */
-          subsubtype = xbt_dict_get_or_null(other_info->types_by_name, subtype->name);
+          subsubtype = xbt_dict_get_or_null(other_info->full_types_by_name, subtype->name);
           switch_types = 1;
       }
       elm_size = subsubtype->byte_size;
           switch_types = 1;
       }
       elm_size = subsubtype->byte_size;
@@ -938,11 +938,11 @@ static int compare_heap_area_with_type(struct s_mm_diff *state, void *real_area1
   case DW_TAG_structure_type:
   case DW_TAG_class_type:
     if(type->byte_size == 0){ /*declaration of the structure, need the complete description */
   case DW_TAG_structure_type:
   case DW_TAG_class_type:
     if(type->byte_size == 0){ /*declaration of the structure, need the complete description */
-      dw_type_t full_type = xbt_dict_get_or_null(info->types_by_name, type->name);
+      dw_type_t full_type = xbt_dict_get_or_null(info->full_types_by_name, type->name);
       if(full_type){
         type = full_type;
       }else{
       if(full_type){
         type = full_type;
       }else{
-        type = xbt_dict_get_or_null(other_info->types_by_name, type->name);
+        type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name);
         switch_types = 1;
       }
     }
         switch_types = 1;
       }
     }
@@ -1018,19 +1018,19 @@ static char* get_offset_type(void* real_base_address, char* type_id, int offset,
   case DW_TAG_class_type:
     if(type->byte_size == 0){ /*declaration of the structure, need the complete description */
       if(*switch_type == 0){
   case DW_TAG_class_type:
     if(type->byte_size == 0){ /*declaration of the structure, need the complete description */
       if(*switch_type == 0){
-        dw_type_t full_type = xbt_dict_get_or_null(info->types_by_name, type->name);
+        dw_type_t full_type = xbt_dict_get_or_null(info->full_types_by_name, type->name);
         if(full_type){
           type = full_type;
         }else{
         if(full_type){
           type = full_type;
         }else{
-          type = xbt_dict_get_or_null(other_info->types_by_name, type->name);
+          type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name);
           *switch_type = 1;
         }
       }else{
           *switch_type = 1;
         }
       }else{
-        dw_type_t full_type = xbt_dict_get_or_null(other_info->types_by_name, type->name);
+        dw_type_t full_type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name);
         if(full_type){
           type = full_type;
         }else{
         if(full_type){
           type = full_type;
         }else{
-          type = xbt_dict_get_or_null(info->types_by_name, type->name);
+          type = xbt_dict_get_or_null(info->full_types_by_name, type->name);
           *switch_type = 0;
         }
       }
           *switch_type = 0;
         }
       }
@@ -1142,11 +1142,11 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap
     type = xbt_dict_get_or_null(info->types, type_id);
     if(type->byte_size == 0){
       if(type->subtype == NULL){
     type = xbt_dict_get_or_null(info->types, type_id);
     if(type->byte_size == 0){
       if(type->subtype == NULL){
-        dw_type_t full_type = xbt_dict_get_or_null(info->types_by_name, type->name);
+        dw_type_t full_type = xbt_dict_get_or_null(info->full_types_by_name, type->name);
         if(full_type)
           type = full_type;
         else
         if(full_type)
           type = full_type;
         else
-          type = xbt_dict_get_or_null(other_info->types_by_name, type->name);
+          type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name);
       }else{
         type = type->subtype;
       }
       }else{
         type = type->subtype;
       }
index 08b93a3..c6b1fe5 100644 (file)
@@ -87,7 +87,7 @@ static dw_variable_t test_global_variable(mc_object_info_t info, const char* nam
   return variable;
 }
 
   return variable;
 }
 
-static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t type) {
+static dw_type_t find_member(mc_object_info_t info, const char* name, dw_type_t type) {
   unsigned int cursor = 0;
   dw_type_t member;
   xbt_dynar_foreach(type->members, cursor, member){
   unsigned int cursor = 0;
   dw_type_t member;
   xbt_dynar_foreach(type->members, cursor, member){
@@ -99,6 +99,8 @@ static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t ty
 
 int some_local_variable = 0;
 
 
 int some_local_variable = 0;
 
+typedef struct foo {int i;} s_foo;
+
 int main(int argc, char** argv) {
 
   // xbt_init(&argc, argv);
 int main(int argc, char** argv) {
 
   // xbt_init(&argc, argv);
@@ -117,8 +119,8 @@ int main(int argc, char** argv) {
 
   var = test_global_variable(mc_binary_info, "test_some_struct", &test_some_struct, sizeof(test_some_struct));
   type = xbt_dict_get_or_null(mc_binary_info->types, var->type_origin);
 
   var = test_global_variable(mc_binary_info, "test_some_struct", &test_some_struct, sizeof(test_some_struct));
   type = xbt_dict_get_or_null(mc_binary_info->types, var->type_origin);
-  assert(find_type(mc_binary_info, "first", type)->offset == 0);
-  assert(find_type(mc_binary_info, "second", type)->offset
+  assert(find_member(mc_binary_info, "first", type)->offset == 0);
+  assert(find_member(mc_binary_info, "second", type)->offset
       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
 
   unw_context_t context;
       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
 
   unw_context_t context;
@@ -128,5 +130,9 @@ int main(int argc, char** argv) {
 
   test_local_variable(mc_binary_info, "main", "argc", &argc, &cursor);
 
 
   test_local_variable(mc_binary_info, "main", "argc", &argc, &cursor);
 
+  s_foo my_foo;
+
+  assert(xbt_dict_get_or_null(mc_binary_info->full_types_by_name, "struct foo"));
+
   _exit(0);
 }
   _exit(0);
 }