Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Do not use mc_{global_variables,local_variables,variables_type}_{libsimgrid...
[simgrid.git] / src / mc / mc_checkpoint.c
index 30dfc17..42e9509 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 2008-2013 Da SimGrid Team. All rights reserved.            */
+/* Copyright (c) 2008-2013. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -29,8 +30,7 @@ void *start_text_binary;
 
 static void MC_snapshot_stack_free(mc_snapshot_stack_t s){
   if(s){
-    xbt_free(s->local_variables->data);
-    xbt_free(s->local_variables);
+    xbt_dynar_free(&(s->local_variables));
     xbt_free(s);
   }
 }
@@ -50,6 +50,23 @@ static void local_variable_free_voidp(void *v){
   local_variable_free((local_variable_t) * (void **) v);
 }
 
+static void MC_region_destroy(mc_mem_region_t reg)
+{
+  xbt_free(reg->data);
+  xbt_free(reg);
+}
+
+void MC_free_snapshot(mc_snapshot_t snapshot){
+  unsigned int i;
+  for(i=0; i < NB_REGIONS; i++)
+    MC_region_destroy(snapshot->regions[i]);
+
+  xbt_free(snapshot->stack_sizes);
+  xbt_dynar_free(&(snapshot->stacks));
+  xbt_dynar_free(&(snapshot->to_ignore));
+  xbt_free(snapshot);
+}
+
 
 /*******************************  Snapshot regions ********************************/
 /*********************************************************************************/
@@ -73,16 +90,9 @@ static void MC_region_restore(mc_mem_region_t reg)
     before copying the data */
  
   memcpy(reg->start_addr, reg->data, reg->size);
   return;
 }
 
-static void MC_region_destroy(mc_mem_region_t reg)
-{
-  xbt_free(reg->data);
-  xbt_free(reg);
-}
-
 static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size)
 {
   mc_mem_region_t new_reg = MC_region_new(type, start_addr, size);
@@ -167,7 +177,7 @@ static void MC_get_memory_regions(mc_snapshot_t snapshot){
               }
               tok = strtok(lfields[0], "-");
               start_addr1 = (void *)strtoul(tok, NULL, 16);
-              if(lfields[1][1] == 'w' && lfields[5] == NULL){
+              if(lfields[1][1] == 'w'){
                 if(start_addr1 == std_heap){     /* Std_heap ? */
                   tok = strtok(NULL, "-");
                   end_addr = (void *)strtoul(tok, NULL, 16);
@@ -196,6 +206,7 @@ static void MC_get_memory_regions(mc_snapshot_t snapshot){
 
 }
 
+/** @brief Find the range of the different memory segments and binary paths */
 void MC_init_memory_map_info(){
  
   unsigned int i = 0;
@@ -254,7 +265,7 @@ void MC_get_libsimgrid_plt_section(){
   int i, plt_found = 0;
   unsigned long int size, offset;
 
-  char *command = bprintf("objdump --section-headers %s", libsimgrid_path);
+  char *command = bprintf("LANG=C objdump --section-headers %s", libsimgrid_path);
 
   fp = popen(command, "r");
 
@@ -319,7 +330,7 @@ void MC_get_binary_plt_section(){
   int i, plt_found = 0;
   unsigned long int size;
 
-  char *command = bprintf( "objdump --section-headers %s", xbt_binary_name);
+  char *command = bprintf("LANG=C objdump --section-headers %s", xbt_binary_name);
 
   fp = popen(command, "r");
 
@@ -492,20 +503,24 @@ static xbt_dynar_t MC_get_local_variables_values(void *stack_context){
   int frame_found = 0, region_type;
   void *frame_pointer_address = NULL;
   long true_ip, value;
+  int stop = 0;
 
   xbt_dynar_t variables = xbt_dynar_new(sizeof(local_variable_t), local_variable_free_voidp);
 
-  while(ret >= 0){
+  while(ret >= 0 && !stop){
 
     unw_get_reg(&c, UNW_REG_IP, &ip);
     unw_get_reg(&c, UNW_REG_SP, &sp);
 
     unw_get_proc_name(&c, frame_name, sizeof (frame_name), &off);
 
+    if(!strcmp(frame_name, "smx_ctx_sysv_wrapper")) /* Stop before context switch with maestro */
+      stop = 1;
+
     if((long)ip > (long)start_text_libsimgrid)
-      frame = xbt_dict_get_or_null(mc_local_variables_libsimgrid, frame_name);
+      frame = xbt_dict_get_or_null(mc_libsimgrid_info->local_variables, frame_name);
     else
-      frame = xbt_dict_get_or_null(mc_local_variables_binary, frame_name);
+      frame = xbt_dict_get_or_null(mc_binary_info->local_variables, frame_name);
 
     if(frame == NULL){
       ret = unw_step(&c);
@@ -698,21 +713,20 @@ static void MC_dump_checkpoint_ignore(mc_snapshot_t snapshot){
   xbt_dynar_foreach(mc_checkpoint_ignore, cursor, region){
     if(region->addr > snapshot->regions[0]->start_addr && (char *)(region->addr) < (char *)snapshot->regions[0]->start_addr + STD_HEAP_SIZE){
       offset = (char *)region->addr - (char *)snapshot->regions[0]->start_addr;
-      memset((char *)snapshot->regions[0]->start_addr + offset, 0, region->size);
+      memset((char *)snapshot->regions[0]->data + offset, 0, region->size);
     }else if(region->addr > snapshot->regions[2]->start_addr && (char *)(region->addr) < (char*)snapshot->regions[2]->start_addr + snapshot->regions[2]->size){
       offset = (char *)region->addr - (char *)snapshot->regions[2]->start_addr;
-      memset((char *)snapshot->regions[2]->start_addr + offset, 0, region->size);
+      memset((char *)snapshot->regions[2]->data + offset, 0, region->size);
+    }else if(region->addr > snapshot->regions[1]->start_addr && (char *)(region->addr) < (char*)snapshot->regions[1]->start_addr + snapshot->regions[1]->size){
+      offset = (char *)region->addr - (char *)snapshot->regions[1]->start_addr;
+      memset((char *)snapshot->regions[1]->data + offset, 0, region->size);
     }
   }
 
 }
 
 
-mc_snapshot_t MC_take_snapshot(){
-
-  int raw_mem = (mmalloc_get_current_heap() == raw_heap);
-  
-  MC_SET_RAW_MEM;
+mc_snapshot_t MC_take_snapshot(int num_state){
 
   mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
   snapshot->nb_processes = xbt_swag_size(simix_global->process_list);
@@ -728,12 +742,8 @@ mc_snapshot_t MC_take_snapshot(){
     //MC_get_hash_local(snapshot->hash_local, snapshot->stacks);
   }
 
-  MC_dump_checkpoint_ignore(snapshot);
-
-  MC_UNSET_RAW_MEM;
-
-  if(raw_mem)
-    MC_SET_RAW_MEM;
+  if(num_state > 0)
+    MC_dump_checkpoint_ignore(snapshot);
 
   return snapshot;
 
@@ -747,19 +757,8 @@ void MC_restore_snapshot(mc_snapshot_t snapshot){
 
 }
 
-void MC_free_snapshot(mc_snapshot_t snapshot){
-  unsigned int i;
-  for(i=0; i < NB_REGIONS; i++)
-    MC_region_destroy(snapshot->regions[i]);
-
-  xbt_free(snapshot->stack_sizes);
-  xbt_dynar_free(&(snapshot->stacks));
-  xbt_dynar_free(&(snapshot->to_ignore));
-  xbt_free(snapshot);
-}
-
 mc_snapshot_t SIMIX_pre_mc_snapshot(smx_simcall_t simcall){
-  return MC_take_snapshot();
+  return MC_take_snapshot(1);
 }
 
 void *MC_snapshot(void){