Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : remove unused function
[simgrid.git] / src / xbt / mmalloc / mm_diff.c
1 /* mm_diff - Memory snapshooting and comparison                             */
2
3 /* Copyright (c) 2008-2012. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "xbt/ex_interface.h" /* internals of backtrace setup */
9 #include "xbt/str.h"
10 #include "mc/mc.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mm_diff, xbt,
13                                 "Logging specific to mm_diff in mmalloc");
14
15 extern char *xbt_binary_name;
16
17 void mmalloc_backtrace_block_display(xbt_mheap_t heap, size_t block){
18
19   int type;
20   xbt_ex_t e;
21
22   type = heap->heapinfo[block].type;
23
24   if (type != 0) {
25     fprintf(stderr,"Only full blocks are backtraced for now. Ignoring your request.\n");
26     return;
27   }
28   if (heap->heapinfo[block].busy_block.bt_size == 0) {
29     fprintf(stderr,"No backtrace available for that block, sorry.\n");
30     return;
31   }
32
33   memcpy(&e.bt,&(heap->heapinfo[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE);
34   e.used = heap->heapinfo[block].busy_block.bt_size;
35
36   xbt_ex_setup_backtrace(&e);
37   if (e.used == 0) {
38     fprintf(stderr, "(backtrace not set)\n");
39   } else if (e.bt_strings == NULL) {
40     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
41   } else {
42     int i;
43
44     fprintf(stderr, "Backtrace of where the block %zu was malloced (%d frames):\n", block ,e.used);
45     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
46       fprintf(stderr,"%d",i);fflush(NULL);
47       fprintf(stderr, "---> %s\n", e.bt_strings[i] + 4);
48     }
49   }
50 }
51
52 void mmalloc_backtrace_fragment_display(xbt_mheap_t mdp, size_t block, size_t frag){
53
54   xbt_ex_t e;
55
56   memcpy(&e.bt,&(mdp->heapinfo[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE);
57   e.used = XBT_BACKTRACE_SIZE;
58
59   xbt_ex_setup_backtrace(&e);
60   if (e.used == 0) {
61     fprintf(stderr, "(backtrace not set)\n");
62   } else if (e.bt_strings == NULL) {
63     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
64   } else {
65     int i;
66
67     fprintf(stderr, "Backtrace of where the fragment %zu in block %zu was malloced (%d frames):\n", frag, block ,e.used);
68     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
69       fprintf(stderr,"%d",i);fflush(NULL);
70       fprintf(stderr, "---> %s\n", e.bt_strings[i] + 4);
71     }
72   }
73 }
74
75 int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2){
76
77   if(mdp1 == NULL && mdp2 == NULL){
78     fprintf(stderr, "Malloc descriptors null\n");
79     return 0;
80   }
81
82   int errors = mmalloc_compare_mdesc(mdp1, mdp2);
83
84   return (errors > 0);
85
86 }
87
88 int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
89
90   int errors = 0;
91
92   if(mdp1->heaplimit != mdp2->heaplimit){
93     fprintf(stderr,"Different limit of valid info table indices\n");
94     return 1;
95   }
96
97   void* s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
98
99   void *heapbase1 = (char *)mdp1 + BLOCKSIZE;
100   void *heapbase2 = (char *)mdp2 + BLOCKSIZE;
101
102   size_t i, j;
103   void *addr_block1 = NULL, *addr_block2 = NULL, *addr_frag1 = NULL, *addr_frag2 = NULL;
104   size_t frag_size;
105
106   i = 1;
107
108   int k = 0;
109   int distance = 0;
110   int total_distance = 0;
111
112   int pointer_align;
113   void *address_pointed1 = NULL, *address_pointed2 = NULL;
114
115   int block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
116   void *addr_block_pointed1 = NULL, *addr_block_pointed2 = NULL, *addr_frag_pointed1 = NULL, *addr_frag_pointed2 = NULL;
117
118   /* Check busy blocks*/
119
120   while(i < mdp1->heaplimit){
121
122     if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
123       fprintf(stderr,"Different type of block : %d - %d\n", mdp1->heapinfo[i].type, mdp2->heapinfo[i].type);
124       errors++;
125     }
126
127     /* Get address of block i in each heap */
128     addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
129     addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
130
131     if(mdp1->heapinfo[i].type == 0){ /* busy large block */
132
133       if(mdp1->heapinfo[i].busy_block.size != mdp2->heapinfo[i].busy_block.size){
134         fprintf(stderr,"Different size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.size, mdp2->heapinfo[i].busy_block.size); 
135         fflush(NULL);
136         errors++;
137       }
138
139       if(mdp1->heapinfo[i].busy_block.busy_size != mdp2->heapinfo[i].busy_block.busy_size){
140         fprintf(stderr,"Different busy_size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.busy_size, mdp2->heapinfo[i].busy_block.busy_size); 
141         fflush(NULL);
142         errors++;
143       }
144
145       /* Hamming distance on different blocks */
146       distance = 0;
147
148
149       for(k=0;k<mdp1->heapinfo[i].busy_block.busy_size;k++){
150
151         if(memcmp(((char *)addr_block1) + k, ((char *)addr_block2) + k, 1) != 0){
152
153           fprintf(stderr, "Different byte (offset=%d) (%p - %p) in block %zu\n", k, (char *)addr_block1 + k, (char *)addr_block2 + k, i); fflush(NULL);
154           
155           /* Check if pointer difference */
156           pointer_align = (k >> sizeof(void*)) * sizeof(void*);
157           address_pointed1 = *((void **)((char *)addr_block1 + pointer_align));
158           address_pointed2 = *((void **)((char *)addr_block2 + pointer_align));
159
160           fprintf(stderr, "Addresses pointed : %p - %p\n", address_pointed1, address_pointed2);
161           
162           block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
163           block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
164           
165           fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
166           
167           if((char *) address_pointed1 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed1 > mdp1->heapsize || block_pointed1 < 1 || (char *) address_pointed2 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed2 > mdp2->heapsize || block_pointed2 < 1) {
168             fprintf(stderr, "Unknown pointer(s) ! \n");
169             fflush(NULL);
170             distance++;
171             continue;
172           }
173
174           /*if(((char *) address_pointed1 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed1 < mdp1->heapsize) && (block_pointed1 >= 1)){
175             addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
176             if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
177               addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
178             }else{
179               addr_block_pointed2 = addr_block2;
180               block_pointed2 = i;
181             }
182           }else{
183             addr_block_pointed1 = addr_block1;
184             block_pointed1 = i;
185             if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
186               addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
187             }else{
188               fprintf(stderr, "Unknown pointers ! \n");
189               fflush(NULL);
190               distance++;
191               continue;
192             }
193             }*/
194           
195           addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
196           addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
197           
198           if(mdp1->heapinfo[block_pointed1].type == mdp2->heapinfo[block_pointed2].type){
199             
200             if(mdp1->heapinfo[block_pointed1].type == 0){ // Large block
201               
202               if(mdp1->heapinfo[block_pointed1].busy_block.busy_size == mdp2->heapinfo[block_pointed2].busy_block.busy_size){
203                 
204                 if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_block.busy_size) != 0){
205                   distance++;
206                 }else{
207                   fprintf(stderr, "False difference detected\n");
208                 }
209                 
210               }else{
211                 distance++;
212               }
213               
214             }else{ // Fragmented block
215               
216
217               frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
218               frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;             
219                             
220               fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
221               
222               if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
223                 fprintf(stderr, "Unknown pointer(s) ! \n");
224                 fflush(NULL);
225                 distance++;
226                 continue;
227               } 
228
229               fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]);  
230               
231               if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
232
233                 addr_frag_pointed1 = (char *)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, mdp1->heapinfo[block_pointed1].type));
234                 addr_frag_pointed2 = (char *)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, mdp2->heapinfo[block_pointed2].type));
235                 
236                 if(memcmp(addr_frag_pointed1, addr_frag_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
237                   distance++;
238                 }else{
239                   fprintf(stderr, "False difference detected\n");
240                 }
241                 
242               }else{
243                 distance ++;
244               }
245             }
246             
247           }else{
248
249             if(((mdp1->heapinfo[block_pointed1].type == 0) && (mdp2->heapinfo[block_pointed2].type != 0)) || ((mdp1->heapinfo[block_pointed1].type != 0) && (mdp2->heapinfo[block_pointed2].type == 0))){  
250               fprintf(stderr, "Pointers on blocks with different types \n");
251               distance++;
252             }else{
253              
254               frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
255               frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
256             
257               fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
258               
259               if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
260                 fprintf(stderr, "Unknown pointer(s) ! \n");
261                 fflush(NULL);
262                 distance++;
263                 continue;
264               } 
265               
266               fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]); 
267               
268               if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
269
270                 addr_frag_pointed1 = (char *)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, mdp1->heapinfo[block_pointed1].type));
271                 addr_frag_pointed2 = (char *)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, mdp2->heapinfo[block_pointed2].type));
272                                 
273                 if(memcmp(addr_frag_pointed1, addr_frag_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
274                   distance++;
275                 }else{
276                   fprintf(stderr, "False difference detected\n");
277                 }
278                 
279               }else{
280                 distance ++;
281               }
282             }
283           }
284         }
285      
286       }
287
288
289       if(distance>0){
290         fprintf(stderr,"\nDifferent data in large block %zu (size = %zu (in blocks), busy_size = %zu (in bytes))\n", i, mdp1->heapinfo[i].busy_block.size, mdp1->heapinfo[i].busy_block.busy_size);
291         fflush(NULL);
292         fprintf(stderr, "Hamming distance between blocks : %d\n", distance);
293         mmalloc_backtrace_block_display(mdp1, i);
294         mmalloc_backtrace_block_display(mdp2, i);
295         fprintf(stderr, "\n");
296         errors++;
297         total_distance += distance;
298       }
299
300       i++;
301
302     }else{
303
304       if(mdp1->heapinfo[i].type > 0){ /* busy fragmented block */
305
306         if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
307           fprintf(stderr,"Different size of fragments in fragmented block %zu : %d - %d\n", i, mdp1->heapinfo[i].type, mdp2->heapinfo[i].type); fflush(NULL);
308           errors++;
309         }
310
311         if(mdp1->heapinfo[i].busy_frag.nfree != mdp2->heapinfo[i].busy_frag.nfree){
312           fprintf(stderr,"Different free fragments in fragmented block %zu : %zu - %zu\n", i, mdp1->heapinfo[i].busy_frag.nfree, mdp2->heapinfo[i].busy_frag.nfree); fflush(NULL);
313           errors++;
314         }
315
316         if(mdp1->heapinfo[i].busy_frag.first != mdp2->heapinfo[i].busy_frag.first){
317           fprintf(stderr,"Different busy_size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.busy_size, mdp2->heapinfo[i].busy_block.busy_size); fflush(NULL);
318           errors++;
319         }
320
321         frag_size = pow(2, mdp1->heapinfo[i].type);
322
323         for(j=0; j< (BLOCKSIZE/frag_size); j++){
324
325           if(mdp1->heapinfo[i].busy_frag.frag_size[j] != mdp2->heapinfo[i].busy_frag.frag_size[j]){
326             fprintf(stderr,"Different busy_size for fragment %zu in block %zu : %hu - %hu\n", j, i, mdp1->heapinfo[i].busy_frag.frag_size[j], mdp2->heapinfo[i].busy_frag.frag_size[j]); fflush(NULL);
327             errors++;
328           }
329
330           if(mdp1->heapinfo[i].busy_frag.frag_size[j] > 0){
331
332             addr_frag1 = (char *)addr_block1 + (j * frag_size);
333             addr_frag2 = (char *)addr_block2 + (j * frag_size);
334
335             /* Hamming distance on different blocks */
336             distance = 0;
337
338             for(k=0;k<mdp1->heapinfo[i].busy_frag.frag_size[j];k++){
339
340               if(memcmp(((char *)addr_frag1) + k, ((char *)addr_frag2) + k, 1) != 0){
341
342                 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in fragment %zu in block %zu\n", k, (char *)addr_frag1 + k, (char *)addr_frag2 + k, j, i); fflush(NULL);
343
344                 pointer_align = (k / sizeof(void*)) * sizeof(void*);
345                 address_pointed1 = *((void **)((char *)addr_frag1 + pointer_align));
346                 address_pointed2 = *((void **)((char *)addr_frag2 + pointer_align));
347
348                 fprintf(stderr, "Addresses pointed : %p - %p\n", address_pointed1, address_pointed2);
349
350                 block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
351                 block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
352
353                 fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
354                 
355                 if((char *) address_pointed1 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed1 > mdp1->heapsize || block_pointed1 < 1 || (char *) address_pointed2 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed2 > mdp2->heapsize || block_pointed2 < 1) {
356                   fprintf(stderr, "Unknown pointer ! \n");
357                   fflush(NULL);
358                   distance++;
359                   continue;
360                 }
361
362                 /*if(((char *) address_pointed1 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed1 < mdp1->heapsize) && (block_pointed1 >= 1)){
363                   addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
364                   pointer1 = 1;
365                   if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
366                     addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
367                     pointer2 = 1;
368                   }else{
369                     pointer2 = 0;
370                     addr_block_pointed2 = addr_block2;
371                     block_pointed2 = i;
372                   }
373                 }else{
374                   addr_block_pointed1 = addr_block1;
375                   block_pointed1 = i;
376                   pointer1 = 0;
377                   if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
378                     addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
379                     pointer2 = 1;
380                   }else{
381                     fprintf(stderr, "Unknown pointers ! \n");
382                     fflush(NULL);
383                     distance++;
384                     continue;
385                   }
386                   }*/
387
388                 addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
389                 addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
390                 
391                 if(mdp1->heapinfo[block_pointed1].type == mdp2->heapinfo[block_pointed2].type){
392                   
393                   if(mdp1->heapinfo[block_pointed1].type == 0){ // Large block
394                     
395                     if(mdp1->heapinfo[block_pointed1].busy_block.busy_size == mdp2->heapinfo[block_pointed2].busy_block.busy_size){
396                       
397                       if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_block.busy_size) != 0){
398                         distance++;
399                       }else{
400                         fprintf(stderr, "False difference detected\n");
401                       }
402                       
403                     }else{
404                       distance++;
405                     }
406                     
407                   }else{ // Fragmented block
408
409                    
410                     frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
411                     frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
412                    
413                     fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
414                     
415                     if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
416                        fprintf(stderr, "Unknown pointer ! \n");
417                        fflush(NULL);
418                        distance++;
419                        continue;
420                     } 
421
422                     fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]); 
423                                         
424                     if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
425
426                       addr_frag_pointed1 = (char *)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, mdp1->heapinfo[block_pointed1].type));
427                       addr_frag_pointed2 = (char *)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, mdp2->heapinfo[block_pointed2].type));
428                       
429                       if(memcmp(addr_frag_pointed1, addr_frag_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
430                         distance++;
431                       }else{
432                         fprintf(stderr, "False difference detected\n");
433                       }
434                       
435                     }else{
436                       distance ++;
437                     }
438                   }
439
440                 }else{
441
442                   if(((mdp1->heapinfo[block_pointed1].type == 0) && (mdp2->heapinfo[block_pointed2].type != 0)) || ((mdp1->heapinfo[block_pointed1].type != 0) && (mdp2->heapinfo[block_pointed2].type == 0))){  
443                     fprintf(stderr, "Pointers on blocks with different types \n");
444                     distance++;
445                   }else{
446
447                     frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
448                     frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
449                    
450                     fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
451                     
452                     if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
453                        fprintf(stderr, "Unknown pointers ! \n");
454                        fflush(NULL);
455                        distance++;
456                        continue;
457                     } 
458
459                     fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]); 
460                                         
461                     if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
462
463                       addr_frag_pointed1 = (char *)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, mdp1->heapinfo[block_pointed1].type));
464                       addr_frag_pointed2 = (char *)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, mdp2->heapinfo[block_pointed2].type));
465                       
466                       if(memcmp(addr_frag_pointed1, addr_frag_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
467                         distance++;
468                       }else{
469                         fprintf(stderr, "False difference detected\n");
470                       }
471                       
472                     }else{
473                       distance ++;
474                     }
475                   }
476                   
477                 }
478               }
479
480             }
481
482             if(distance > 0){
483               fprintf(stderr,"\nDifferent data in fragment %zu (size = %zu, size used = %hu) in block %zu \n", j, frag_size, mdp1->heapinfo[i].busy_frag.frag_size[j], i);
484               fprintf(stderr, "Hamming distance between fragments : %d\n", distance);
485               mmalloc_backtrace_fragment_display(mdp1, i, j);
486               mmalloc_backtrace_fragment_display(mdp2, i, j);
487               fprintf(stderr, "\n");
488               errors++;
489               total_distance += distance;
490
491             }
492
493           }
494         }
495
496         i++;
497
498       }else{ /* free block */
499
500         i++;
501
502       }
503
504     }
505
506   }
507
508
509   fprintf(stderr, "Hamming distance between heap regions : %d\n", total_distance);
510
511   return (errors);
512 }
513
514
515 /* void *get_end_addr_heap(void *heap){ */
516
517 /*   FILE *fp;                     /\* File pointer to process's proc maps file *\/ */
518 /*   char *line = NULL;            /\* Temporal storage for each line that is readed *\/ */
519 /*   ssize_t read;                 /\* Number of bytes readed *\/ */
520 /*   size_t n = 0;                 /\* Amount of bytes to read by getline *\/ */
521
522 /*   fp = fopen("/proc/self/maps", "r"); */
523
524 /*   if(fp == NULL) */
525 /*     perror("fopen failed"); */
526
527
528 /*   xbt_dynar_t lfields = NULL; */
529 /*   xbt_dynar_t start_end  = NULL; */
530 /*   void *start_addr; */
531 /*   void *end_addr; */
532
533 /*   while ((read = getline(&line, &n, fp)) != -1) { */
534
535 /*     xbt_str_trim(line, NULL); */
536 /*     xbt_str_strip_spaces(line); */
537 /*     lfields = xbt_str_split(line,NULL); */
538
539 /*     start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-"); */
540 /*     start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16); */
541 /*     end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16); */
542
543 /*     if(start_addr == heap){ */
544 /*       free(line); */
545 /*       fclose(fp); */
546 /*       xbt_dynar_reset(lfields); */
547 /*       xbt_free(lfields); */
548 /*       xbt_dynar_reset(start_end); */
549 /*       xbt_free(start_end); */
550 /*       return end_addr; */
551 /*     } */
552
553 /*   } */
554
555 /*   xbt_dynar_reset(lfields); */
556 /*   xbt_free(lfields); */
557 /*   xbt_dynar_reset(start_end); */
558 /*   xbt_free(start_end); */
559 /*   free(line); */
560 /*   fclose(fp); */
561 /*   return NULL; */
562
563
564 /* } */
565
566
567