Logo AND Algorithmique Numérique Distribuée

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