Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : init MC for liveness in a separate function
[simgrid.git] / src / mc / mc_checkpoint.c
index 112ffd8..984323b 100644 (file)
@@ -20,6 +20,7 @@ void *start_plt_binary, *end_plt_binary;
 char *libsimgrid_path;
 void *start_data_libsimgrid;
 void *start_text_binary;
+void *end_raw_heap;
 
 static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size);
 static void MC_region_restore(mc_mem_region_t reg);
@@ -33,6 +34,8 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
 static void print_local_variables_values(xbt_dynar_t all_variables);
 static void *get_stack_pointer(void *stack_context, void *heap);
 
+static void snapshot_stack_free(mc_snapshot_stack_t s);
+
 static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size)
 {
   mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1);
@@ -109,9 +112,50 @@ void MC_take_snapshot(mc_snapshot_t snapshot)
   free_memory_map(maps);
 }
 
-void MC_take_snapshot_liveness(mc_snapshot_t snapshot)
+void MC_init_memory_map_info(){
+  
+  unsigned int i = 0;
+  s_map_region_t reg;
+  memory_map_t maps = get_memory_map();
+
+   while (i < maps->mapsize) {
+    reg = maps->regions[i];
+    if ((reg.prot & PROT_WRITE)){
+      if (maps->regions[i].pathname == NULL){
+        if(reg.start_addr == raw_heap){
+          end_raw_heap = reg.end_addr;
+        }
+      } else {
+        if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
+          start_data_libsimgrid = reg.start_addr;
+        }
+      }
+    }else if ((reg.prot & PROT_READ)){
+      if (maps->regions[i].pathname != NULL){
+        if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
+          start_text_libsimgrid = reg.start_addr;
+          libsimgrid_path = strdup(maps->regions[i].pathname);
+        }else{
+          if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
+            start_text_binary = reg.start_addr;
+          }
+        }
+      }
+    }
+    i++;
+  }
+
+}
+
+mc_snapshot_t MC_take_snapshot_liveness()
 {
 
+  raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+
+  MC_SET_RAW_MEM;
+
+  mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
+
   unsigned int i = 0;
   s_map_region_t reg;
   memory_map_t maps = get_memory_map();
@@ -127,6 +171,8 @@ void MC_take_snapshot_liveness(mc_snapshot_t snapshot)
           MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
           heap = snapshot->regions[nb_reg]->data;
           nb_reg++;
+        }else if(reg.start_addr == raw_heap){
+          end_raw_heap = reg.end_addr;
         }
         i++;
       } else {
@@ -171,6 +217,13 @@ void MC_take_snapshot_liveness(mc_snapshot_t snapshot)
   
   free_memory_map(maps);
 
+  MC_UNSET_RAW_MEM;
+
+  if(raw_mem_set)
+    MC_SET_RAW_MEM;
+
+  return snapshot;
+
 }
 
 void MC_restore_snapshot(mc_snapshot_t snapshot)
@@ -188,6 +241,7 @@ void MC_free_snapshot(mc_snapshot_t snapshot)
   for(i=0; i < snapshot->num_reg; i++)
     MC_region_destroy(snapshot->regions[i]);
 
+  xbt_dynar_free(&(snapshot->stacks));
   xbt_free(snapshot);
 }
 
@@ -203,7 +257,10 @@ void get_libsimgrid_plt_section(){
   int i, plt_not_found = 1;
   unsigned long int size, offset;
 
-  char *command = bprintf( "objdump --section-headers %s", libsimgrid_path);
+  if(libsimgrid_path == NULL)
+    libsimgrid_path = get_libsimgrid_path();
+
+  char *command = bprintf("objdump --section-headers %s", libsimgrid_path);
 
   fp = popen(command, "r");
 
@@ -223,7 +280,7 @@ void get_libsimgrid_plt_section(){
     if(lfields[0] == NULL)
       continue;
 
-    if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strcmp(lfields[0], "libsimgrid.so:") == 0)
+    if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strncmp(lfields[0], libsimgrid_path, strlen(libsimgrid_path)) == 0)
       continue;
 
     for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
@@ -240,7 +297,6 @@ void get_libsimgrid_plt_section(){
       }
     }
     
-    
   }
 
   free(command);
@@ -280,7 +336,7 @@ void get_binary_plt_section(){
     if(lfields[0] == NULL)
       continue;
 
-    if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strcmp(lfields[0], basename(xbt_binary_name)) == 0)
+    if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strncmp(lfields[0], basename(xbt_binary_name), strlen(xbt_binary_name)) == 0)
       continue;
 
     for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
@@ -327,7 +383,7 @@ static xbt_dynar_t take_snapshot_stacks(void *heap){
   xbt_dynar_foreach(stacks_areas, cursor1, current_stack){
     mc_snapshot_stack_t st = xbt_new(s_mc_snapshot_stack_t, 1);
     st->local_variables = get_local_variables_values(current_stack->context, heap);
-    st->stack_pointer = get_stack_pointer(current_stack, heap);
+    st->stack_pointer = get_stack_pointer(current_stack->context, heap);
     xbt_dynar_push(res, &st);
   }
 
@@ -359,7 +415,7 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
   int ret;
   //char *stack_name;
 
-  char buf[512], frame_name[256];
+  char frame_name[256];
   
   ret = unw_init_local(&c, (unw_context_t *)stack_context);
   if(ret < 0){
@@ -391,16 +447,9 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
     unw_get_reg(&c, UNW_REG_IP, &ip);
     unw_get_reg(&c, UNW_REG_SP, &sp);
 
-    buf[0] = '\0';
-    if (unw_get_proc_name (&c, frame_name, sizeof (frame_name), &off) == 0){
-      if (off)
-        snprintf (buf, sizeof (buf), "<%s+0x%lx>", frame_name, (long) off);
-      else
-        snprintf (buf, sizeof (buf), "<%s>", frame_name);
-
-    }
+    unw_get_proc_name (&c, frame_name, sizeof (frame_name), &off);
 
-    xbt_strbuff_append(variables, bprintf("ip=%-32s\n", buf));
+    xbt_strbuff_append(variables, bprintf("ip=%s\n", frame_name));
 
     frame = xbt_dict_get_or_null(mc_local_variables, frame_name);
 
@@ -542,3 +591,15 @@ static void print_local_variables_values(xbt_dynar_t all_variables){
   }
 }
 
+
+static void snapshot_stack_free(mc_snapshot_stack_t s){
+  if(s){
+    xbt_free(s->local_variables->data);
+    xbt_free(s->local_variables);
+    xbt_free(s);
+  }
+}
+
+void snapshot_stack_free_voidp(void *s){
+  snapshot_stack_free((mc_snapshot_stack_t) * (void **) s);
+}