Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : minor changes for debug information in heap comparison algorithm
[simgrid.git] / src / xbt / mmalloc / mm_diff.c
index 8c67d8d..a46ab72 100644 (file)
@@ -30,6 +30,7 @@ static void remove_heap_equality(xbt_dynar_t equals, int address, void *a);
 static int is_stack(void *address);
 static int is_block_stack(int block);
 static int equal_blocks(int b1, int b2);
+static int equal_fragments(int b1, int f1, int b2, int f2);
 
 void mmalloc_backtrace_block_display(void* heapinfo, int block){
 
@@ -124,12 +125,12 @@ void init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
   heaplimit = ((struct mdesc *)heap1)->heaplimit;
 
   s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
-
+  
   heapbase1 = (char *)heap1 + BLOCKSIZE;
   heapbase2 = (char *)heap2 + BLOCKSIZE;
 
-  heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)s_heap)));
-  heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)s_heap)));
+  heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)((struct mdesc *)s_heap)->heapinfo - (char *)s_heap)));
+  heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)((struct mdesc *)s_heap)->heapinfo - (char *)s_heap)));
 
   heapsize1 = heap1->heapsize;
   heapsize2 = heap2->heapsize;
@@ -149,7 +150,6 @@ void init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
     MC_ignore_data_bss(&to_ignore1, sizeof(to_ignore1));
     MC_ignore_data_bss(&to_ignore2, sizeof(to_ignore2));
   }
-  
 }
 
 int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
@@ -369,6 +369,7 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
 
   /* All blocks/fragments are equal to another block/fragment ? */
   size_t i = 1, j = 0;
+  void *real_addr_frag1 = NULL, *real_addr_block1 = NULL, *real_addr_block2 = NULL, *real_addr_frag2 = NULL;
  
   while(i<=heaplimit){
     if(heapinfo1[i].type == 0){
@@ -389,13 +390,15 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
     }
     if(heapinfo1[i].type > 0){
       addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
+      real_addr_block1 =  ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)((struct mdesc *)s_heap)->heapbase));
       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
         if(current_block == heaplimit){
           if(heapinfo1[i].busy_frag.frag_size[j] > 0){
             if(heapinfo1[i].busy_frag.equal_to[j] == NULL){
               if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
                 addr_frag1 = (void*) ((char *)addr_block1 + (j << heapinfo1[i].type));
-                XBT_DEBUG("Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
+                real_addr_frag1 = (void*) ((char *)real_addr_block1 + (j << ((struct mdesc *)s_heap)->heapinfo[i].type));
+                XBT_DEBUG("Block %zu, Fragment %zu (%p - %p) not found (size used = %d)", i, j, addr_frag1, real_addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
                 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
               }
               nb_diff1++;
@@ -431,13 +434,15 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
     }
     if(heapinfo2[i].type > 0){
       addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
+      real_addr_block2 =  ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)((struct mdesc *)s_heap)->heapbase));
       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
         if(current_block == heaplimit){
           if(heapinfo2[i].busy_frag.frag_size[j] > 0){
             if(heapinfo2[i].busy_frag.equal_to[j] == NULL){
               if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
                 addr_frag2 = (void*) ((char *)addr_block2 + (j << heapinfo2[i].type));
-                XBT_DEBUG( "Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
+                real_addr_frag2 = (void*) ((char *)real_addr_block2 + (j << ((struct mdesc *)s_heap)->heapinfo[i].type));
+                XBT_DEBUG( "Block %zu, Fragment %zu (%p - %p) not found (size used = %d)", i, j, addr_frag2, real_addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
                 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
               }
               nb_diff2++;
@@ -453,6 +458,7 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
     XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
 
   xbt_dynar_free(&previous);
+  real_addr_frag1 = NULL, real_addr_block1 = NULL, real_addr_block2 = NULL, real_addr_frag2 = NULL;
 
   return ((nb_diff1 > 0) || (nb_diff2 > 0));
 }
@@ -590,6 +596,12 @@ int compare_area(void *area1, void* area2, xbt_dynar_t previous){
       frag1 = ((uintptr_t) (ADDR2UINT (area1) % (BLOCKSIZE))) >> heapinfo1[block1].type;
       frag2 = ((uintptr_t) (ADDR2UINT (area2) % (BLOCKSIZE))) >> heapinfo2[block2].type;
 
+      if(heapinfo1[block1].busy_frag.equal_to[frag1] != NULL){
+        if(equal_fragments(block1, frag1, block2, frag2)){
+          return 0;
+        }
+      }
+
       if(heapinfo1[block1].busy_frag.frag_size[frag1] != heapinfo2[block2].busy_frag.frag_size[frag2])
         return 1;  
       if(!add_heap_area_pair(previous, block1, frag1, block2, frag2))
@@ -613,6 +625,12 @@ int compare_area(void *area1, void* area2, xbt_dynar_t previous){
     frag1 = ((uintptr_t) (ADDR2UINT (area1) % (BLOCKSIZE))) >> heapinfo1[block1].type;
     frag2 = ((uintptr_t) (ADDR2UINT (area2) % (BLOCKSIZE))) >> heapinfo2[block2].type;
 
+    if(heapinfo1[block1].busy_frag.equal_to[frag1] != NULL){
+      if(equal_fragments(block1, frag1, block2, frag2)){
+        return 0;
+      }
+    }
+
     if(heapinfo1[block1].busy_frag.frag_size[frag1] != heapinfo2[block2].busy_frag.frag_size[frag2])
       return 1;       
     if(!add_heap_area_pair(previous, block1, frag1, block2, frag2))
@@ -683,10 +701,8 @@ int compare_area(void *area1, void* area2, xbt_dynar_t previous){
 }
 
 static void heap_area_pair_free(heap_area_pair_t pair){
-  if (pair){
-    xbt_free(pair);
-    pair = NULL;
-  }
+  xbt_free(pair);
+  pair = NULL;
 }
 
 static void heap_area_pair_free_voidp(void *d)
@@ -1046,7 +1062,7 @@ int is_free_area(void *area, xbt_mheap_t heap){
  
 }
 
-static int equal_blocks(b1, b2){
+static int equal_blocks(int b1, int b2){
   if(heapinfo1[b1].busy_block.equal_to != NULL){
     if(heapinfo2[b2].busy_block.equal_to != NULL){
       if(((heap_area_t)(heapinfo1[b1].busy_block.equal_to))->block == b2 && ((heap_area_t)(heapinfo2[b2].busy_block.equal_to))->block == b1)
@@ -1055,3 +1071,13 @@ static int equal_blocks(b1, b2){
   }
   return 0;
 }
+
+static int equal_fragments(int b1, int f1, int b2, int f2){
+  if(heapinfo1[b1].busy_frag.equal_to[f1] != NULL){
+    if(heapinfo2[b2].busy_frag.equal_to[f2] != NULL){
+      if(((heap_area_t)(heapinfo1[b1].busy_frag.equal_to[f1]))->block == b2 && ((heap_area_t)(heapinfo2[b2].busy_frag.equal_to[f2]))->block == b1 && ((heap_area_t)(heapinfo1[b1].busy_frag.equal_to[f1]))->fragment == f2 && ((heap_area_t)(heapinfo2[b2].busy_frag.equal_to[f2]))->fragment == f1)
+        return 1;
+    }
+  }
+  return 0;
+}