Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : cleanups in mc_snapshot structure
[simgrid.git] / src / mc / mc_checkpoint.c
index 0cde216..46b7096 100644 (file)
@@ -42,7 +42,6 @@ static xbt_dynar_t take_snapshot_ignore(void);
 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);
-  new_reg->type = type;
   new_reg->start_addr = start_addr;
   new_reg->size = size;
   new_reg->data = xbt_malloc0(size);
@@ -72,10 +71,7 @@ static void MC_region_destroy(mc_mem_region_t 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);
-  snapshot->regions = xbt_realloc(snapshot->regions, (snapshot->num_reg + 1) * sizeof(mc_mem_region_t));
-  snapshot->regions[snapshot->num_reg] = new_reg;
-  snapshot->region_type[snapshot->num_reg] = type;
-  snapshot->num_reg++;
+  snapshot->regions[type] = new_reg;
   return;
 } 
 
@@ -163,7 +159,7 @@ mc_snapshot_t MC_take_snapshot()
         if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one)
           MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
           snapshot->heap_bytes_used = mmalloc_get_bytes_used(std_heap);
-          heap = snapshot->regions[snapshot->num_reg - 1]->data;
+          heap = snapshot->regions[0]->data;
         }
         i++;
       } else{ 
@@ -221,7 +217,7 @@ mc_snapshot_t MC_take_snapshot()
 void MC_restore_snapshot(mc_snapshot_t snapshot)
 {
   unsigned int i;
-  for(i=0; i < snapshot->num_reg; i++){
+  for(i=0; i < NB_REGIONS; i++){
     MC_region_restore(snapshot->regions[i]);
   }
 
@@ -230,10 +226,9 @@ void MC_restore_snapshot(mc_snapshot_t snapshot)
 void MC_free_snapshot(mc_snapshot_t snapshot)
 {
   unsigned int i;
-  for(i=0; i < snapshot->num_reg; i++)
+  for(i=0; i < NB_REGIONS; i++)
     MC_region_destroy(snapshot->regions[i]);
 
-  xbt_free(snapshot->regions);
   xbt_dynar_free(&(snapshot->stacks));
   xbt_dynar_free(&(snapshot->to_ignore));
   xbt_free(snapshot);
@@ -245,7 +240,7 @@ void get_libsimgrid_plt_section(){
   FILE *fp;
   char *line = NULL;            /* Temporal storage for each line that is readed */
   ssize_t read;                 /* Number of bytes readed */
-  size_t n = 0;                 /* Amount of bytes to read by getline */
+  size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
 
   char *lfields[7];
   int i, plt_found = 0;
@@ -260,7 +255,7 @@ void get_libsimgrid_plt_section(){
     xbt_abort();
   }
 
-  while ((read = getline(&line, &n, fp)) != -1 && plt_found != 2) {
+  while ((read = xbt_getline(&line, &n, fp)) != -1 && plt_found != 2) {
 
     if(n == 0)
       continue;
@@ -310,7 +305,7 @@ void get_binary_plt_section(){
   FILE *fp;
   char *line = NULL;            /* Temporal storage for each line that is readed */
   ssize_t read;                 /* Number of bytes readed */
-  size_t n = 0;                 /* Amount of bytes to read by getline */
+  size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
 
   char *lfields[7];
   int i, plt_found = 0;
@@ -325,7 +320,7 @@ void get_binary_plt_section(){
     xbt_abort();
   }
 
-  while ((read = getline(&line, &n, fp)) != -1 && plt_found != 2) {
+  while ((read = xbt_getline(&line, &n, fp)) != -1 && plt_found != 2) {
 
     if(n == 0)
       continue;
@@ -463,7 +458,10 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
       return variables;
     }
 
-    to_append = bprintf("ip=%s\n", frame_name);
+    to_append = bprintf("ip=%lx\n", ip);
+    xbt_strbuff_append(variables, to_append);
+    xbt_free(to_append);
+    to_append = bprintf("frame_name=%s\n", frame_name);
     xbt_strbuff_append(variables, to_append);
     xbt_free(to_append);
 
@@ -498,7 +496,7 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
               cursor2++;
             }
 
-            if(xbt_dynar_length(compose) > 0){
+            if(!xbt_dynar_is_empty(compose)){
               frame_pointer_address = xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address ; 
             }
             break;
@@ -546,7 +544,7 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
             cursor++;
           }
           
-          if(xbt_dynar_length(compose) > 0){
+          if(!xbt_dynar_is_empty(compose)){
             if(strcmp(xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->type, "value") == 0){
               to_append = bprintf("%s=%lx\n", current_variable->name, xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.res);
               xbt_strbuff_append(variables, to_append);