Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] DW_OP_deref
[simgrid.git] / src / mc / mc_hash.c
index 86847a9..2916ed2 100644 (file)
@@ -77,6 +77,11 @@ static void mc_hash_value(mc_hash_t* hash, mc_hashing_state* state, mc_object_in
   top:
 
   switch(type->type){
+
+  // Not relevant, do nothing:
+  case DW_TAG_unspecified_type:
+    return;
+
   // Simple case, hash this has binary:
   case DW_TAG_base_type:
   case DW_TAG_enumeration_type:
@@ -93,7 +98,7 @@ static void mc_hash_value(mc_hash_t* hash, mc_hashing_state* state, mc_object_in
       return;
 
     long element_count = type->element_count;
-    dw_type_t subtype = xbt_dict_get_or_null(info->types, type->dw_type_id);
+    dw_type_t subtype = type->subtype;
     if(subtype==NULL) {
       XBT_DEBUG("Hash array without subtype");
       return;
@@ -113,10 +118,7 @@ static void mc_hash_value(mc_hash_t* hash, mc_hashing_state* state, mc_object_in
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   {
-    if(type->dw_type_id==NULL) {
-      return;
-    }
-    type = xbt_dict_get_or_null(info->types, type->dw_type_id);
+    type = type->subtype;
     if(type==NULL)
       return;
     else
@@ -133,10 +135,9 @@ static void mc_hash_value(mc_hash_t* hash, mc_hashing_state* state, mc_object_in
     dw_type_t member;
     xbt_dynar_foreach(type->members, cursor, member){
       XBT_DEBUG("Hash struct member %s", member->name);
-      dw_type_t subtype = xbt_dict_get_or_null(info->types, member->dw_type_id);
-      if(subtype==NULL)
+      if(type->subtype==NULL)
         return;
-       mc_hash_value(hash, state, info, ((char*)address) + member->offset, subtype);
+       mc_hash_value(hash, state, info, ((char*)address) + member->offset, type->subtype);
     }
     return;
   }
@@ -171,14 +172,13 @@ static void mc_hash_value(mc_hash_t* hash, mc_hashing_state* state, mc_object_in
       return;
     }
 
-    dw_type_t subtype = type->dw_type_id == NULL ? NULL : xbt_dict_get_or_null(info->types, type->dw_type_id);
-    if(subtype==NULL) {
+    if(type->subtype==NULL) {
       XBT_DEBUG("Missing type for %p (type=%s)", pointed, type->dw_type_id);
       return;
     }
 
     address = pointed;
-    type = subtype;
+    type = type->subtype;
     goto top;
   }
 
@@ -202,19 +202,19 @@ static void mc_hash_object_globals(mc_hash_t *hash, mc_hashing_state* state, mc_
       continue;
     }
 
-    dw_type_t type = xbt_dict_get_or_null(info->types, variable->type_origin);
+    dw_type_t type = variable->type;
     if(type==NULL) {
       // Nothing
       continue;
     }
 
-    const char* address = variable->address.address;
+    const char* address = variable->address;
     bool valid_pointer = (address >= mc_binary_info->start_rw && address <= mc_binary_info->end_rw)
         || (address >= mc_libsimgrid_info->start_rw && address <= mc_libsimgrid_info->end_rw)
         || (address >= (const char*) std_heap && address < (const char *)std_heap + STD_HEAP_SIZE);
     if(!valid_pointer) continue;
 
-    mc_hash_value(hash, state, info, variable->address.address, type);
+    mc_hash_value(hash, state, info, variable->address, type);
   }
 }
 
@@ -233,16 +233,16 @@ static void mc_hash_stack_frame(
       XBT_DEBUG("Hash local variable %s without type", variable->name);
       continue;
     }
-    if(variable->address.location == NULL) {
+    if(variable->locations.size == 0) {
       XBT_DEBUG("Hash local variable %s without location", variable->name);
       continue;
     }
 
     XBT_DEBUG("Hash local variable %s", variable->name);
 
-    void* variable_address = (void*) MC_dwarf_resolve_location(unw_cursor, variable->address.location, frame_pointer);
+    void* variable_address = (void*) mc_dwarf_resolve_locations(&variable->locations, unw_cursor, frame_pointer, NULL);
 
-    dw_type_t type = xbt_dict_get_or_null(info->types, variable->type_origin);
+    dw_type_t type = variable->type;
     if(type==NULL) {
       XBT_DEBUG("Hash local variable %s without loctypeation", variable->name);
       continue;
@@ -252,111 +252,43 @@ static void mc_hash_stack_frame(
   }
 }
 
-/** \brief Find the frame base of a given frame
- *
- *  \param ip         Instruction pointer
- *  \param frame
- *  \param unw_cursor
- */
-void* mc_find_frame_base(unw_word_t ip, dw_frame_t frame, unw_cursor_t* unw_cursor) {
-  switch(frame->frame_base->type) {
-  case e_dw_loclist:
-  {
-    int loclist_cursor;
-    for(loclist_cursor=0; loclist_cursor < xbt_dynar_length(frame->frame_base->location.loclist); loclist_cursor++){
-      dw_location_entry_t entry = xbt_dynar_get_as(frame->frame_base->location.loclist, loclist_cursor, dw_location_entry_t);
-      if((ip >= entry->lowpc) && (ip < entry->highpc)){
-        return (void*) MC_dwarf_resolve_location(unw_cursor, entry->location, NULL);
-      }
-    }
-    return NULL;
-  }
-  // Not handled:
-  default:
-    return NULL;
-  }
-}
-
-static void mc_hash_stack(mc_hash_t *hash, stack_region_t stack, mc_hashing_state* state) {
-
-  unw_cursor_t cursor;
-  if(unw_init_local(&cursor, (unw_context_t *)stack->context)){
-    xbt_die("unw_init_local failed");
-  }
-
-  MC_HASH(*hash, (long)stack->address);
-
-  long count = 0;
-
-  int ret;
-  for(ret=1; ret >= 0; ret = unw_step(&cursor)) {
-
-    // Find the frame name:
-    unw_word_t off;
-    char frame_name[256];
-    if(unw_get_proc_name(&cursor, frame_name, sizeof (frame_name), &off)!=0) {
-      continue;
-    }
-
-    XBT_DEBUG("Frame #%i %s", (int) count, frame_name);
-
-    // Stop before context switch with maestro
-    if(!strcmp(frame_name, "smx_ctx_sysv_wrapper")) {
-      break;
-    }
+static void mc_hash_stack(mc_hash_t *hash, mc_snapshot_stack_t stack, mc_hashing_state* state) {
 
-    ++count;
+  unsigned cursor = 0;
+  mc_stack_frame_t stack_frame;
 
-    unw_word_t ip, sp;
-    if(unw_get_reg(&cursor, UNW_REG_IP, &ip))
-      continue;
-    if(unw_get_reg(&cursor, UNW_REG_SP, &sp))
-      continue;
+  xbt_dynar_foreach(stack->stack_frames, cursor, stack_frame) {
 
-    MC_HASH(*hash, ip);
+    MC_HASH(*hash, stack_frame->ip);
 
-    // Find the object info:
     mc_object_info_t info;
-    if((long)ip >= (long) mc_libsimgrid_info->start_exec && (long)ip < (long) mc_libsimgrid_info->end_exec)
+    if(stack_frame->ip >= (unw_word_t) mc_libsimgrid_info->start_exec && stack_frame->ip < (unw_word_t) mc_libsimgrid_info->end_exec)
       info = mc_libsimgrid_info;
-    else if((long)ip >= (long) mc_binary_info->start_exec && (long)ip < (long) mc_binary_info->end_exec)
+    else if(stack_frame->ip >= (unw_word_t) mc_binary_info->start_exec && stack_frame->ip < (unw_word_t) mc_binary_info->end_exec)
       info = mc_binary_info;
     else
       continue;
 
-    // Find the frame:
-    dw_frame_t frame = xbt_dict_get_or_null(info->local_variables, frame_name);
-    if(frame==NULL)
-      continue;
-
-    long true_ip = (long)frame->low_pc + (long)off;
-
-    // Find the fame base:
-    void* frame_base = mc_find_frame_base(true_ip, frame, &cursor);
-    if(frame_base==NULL)
-      continue;
+    mc_hash_stack_frame(hash, info, &(stack_frame->unw_cursor), stack_frame->frame, (void*)stack_frame->frame_base, state);
 
-    mc_hash_stack_frame(hash, info, &cursor, frame, frame_base, state);
   }
-
-  MC_HASH(*hash, count);
 }
 
-static void mc_hash_stacks(mc_hash_t *hash, mc_hashing_state* state) {
+static void mc_hash_stacks(mc_hash_t *hash, mc_hashing_state* state, xbt_dynar_t stacks) {
   unsigned int cursor = 0;
-  stack_region_t current_stack;
+  mc_snapshot_stack_t current_stack;
 
   MC_HASH(*hash, xbt_dynar_length(stacks_areas));
 
   int i=0;
-  xbt_dynar_foreach(stacks_areas, cursor, current_stack){
+  xbt_dynar_foreach(stacks, cursor, current_stack){
     XBT_DEBUG("Stack %i", i);
     mc_hash_stack(hash, current_stack, state);
     ++i;
   }
 }
 
-uint64_t mc_hash_processes_state(int num_state) {
+uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks) {
   XBT_DEBUG("START hash %i", num_state);
 
   mc_hashing_state state;
@@ -367,7 +299,7 @@ uint64_t mc_hash_processes_state(int num_state) {
   MC_HASH(hash, xbt_swag_size(simix_global->process_list)); // process count
   mc_hash_object_globals(&hash, &state, mc_binary_info);
   // mc_hash_object_globals(&hash, &state, mc_libsimgrid_info);
-  mc_hash_stacks(&hash, &state);
+  mc_hash_stacks(&hash, &state, stacks);
 
   mc_hash_state_destroy(&state);