1 /* mc_diff - Memory snapshooting and comparison */
3 /* Copyright (c) 2008-2014. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/ex_interface.h" /* internals of backtrace setup */
12 #include "xbt/mmalloc.h"
13 #include "mc/datatypes.h"
14 #include "mc/mc_private.h"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
17 "Logging specific to mc_diff in mc");
19 xbt_dynar_t mc_heap_comparison_ignore;
20 xbt_dynar_t stacks_areas;
21 void *maestro_stack_start, *maestro_stack_end;
24 /********************************* Backtrace ***********************************/
25 /******************************************************************************/
27 static void mmalloc_backtrace_block_display(void* heapinfo, int block){
31 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
32 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
36 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
37 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
39 /* xbt_ex_setup_backtrace(&e); */
40 /* if (e.used == 0) { */
41 /* fprintf(stderr, "(backtrace not set)\n"); */
42 /* } else if (e.bt_strings == NULL) { */
43 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
47 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
48 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
49 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
54 static void mmalloc_backtrace_fragment_display(void* heapinfo, int block, int frag){
58 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
59 /* e.used = XBT_BACKTRACE_SIZE; */
61 /* xbt_ex_setup_backtrace(&e); */
62 /* if (e.used == 0) { */
63 /* fprintf(stderr, "(backtrace not set)\n"); */
64 /* } else if (e.bt_strings == NULL) { */
65 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
69 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
70 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
71 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
77 static void mmalloc_backtrace_display(void *addr){
79 /* size_t block, frag_nb; */
82 /* xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); */
84 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
86 /* type = heap->heapinfo[block].type; */
89 /* case -1 : /\* Free block *\/ */
90 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
93 /* case 0: /\* Large block *\/ */
94 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
96 /* default: /\* Fragmented block *\/ */
97 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
98 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
99 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
102 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
108 static int compare_backtrace(int b1, int f1, int b2, int f2){
111 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
112 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
113 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
114 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
119 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
120 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
121 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
122 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
131 /*********************************** Heap comparison ***********************************/
132 /***************************************************************************************/
134 typedef char* type_name;
137 /** \brief Base address of the real heap */
139 /** \brief Base address of the first heap snapshot */
141 /** \brief Base address of the second heap snapshot */
143 malloc_info *heapinfo1, *heapinfo2;
145 // Number of blocks in the heaps:
146 size_t heapsize1, heapsize2;
147 xbt_dynar_t to_ignore1, to_ignore2;
148 s_heap_area_t *equals_to1, *equals_to2;
149 dw_type_t *types1, *types2;
153 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
154 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
155 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
156 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
158 __thread struct s_mc_diff* mc_diff_info = NULL;
160 /*********************************** Free functions ************************************/
162 static void heap_area_pair_free(heap_area_pair_t pair){
167 static void heap_area_pair_free_voidp(void *d){
168 heap_area_pair_free((heap_area_pair_t) * (void **) d);
171 static void heap_area_free(heap_area_t area){
176 /************************************************************************************/
178 static s_heap_area_t make_heap_area(int block, int fragment){
182 area.fragment = fragment;
187 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
189 unsigned int cursor = 0;
190 heap_area_pair_t current_pair;
192 xbt_dynar_foreach(list, cursor, current_pair){
193 if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
200 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
202 if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
203 heap_area_pair_t pair = NULL;
204 pair = xbt_new0(s_heap_area_pair_t, 1);
205 pair->block1 = block1;
206 pair->fragment1 = fragment1;
207 pair->block2 = block2;
208 pair->fragment2 = fragment2;
210 xbt_dynar_push(list, &pair);
218 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list, void *address){
220 unsigned int cursor = 0;
222 int end = xbt_dynar_length(ignore_list) - 1;
223 mc_heap_ignore_region_t region;
226 cursor = (start + end) / 2;
227 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(ignore_list, cursor, mc_heap_ignore_region_t);
228 if(region->address == address)
230 if(region->address < address)
232 if(region->address > address)
239 static int is_stack(void *address){
240 unsigned int cursor = 0;
241 stack_region_t stack;
243 xbt_dynar_foreach(stacks_areas, cursor, stack){
244 if(address == stack->address)
251 static int is_block_stack(int block){
252 unsigned int cursor = 0;
253 stack_region_t stack;
255 xbt_dynar_foreach(stacks_areas, cursor, stack){
256 if(block == stack->block)
263 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list){
265 unsigned int cursor = 0;
266 heap_area_pair_t current_pair;
268 xbt_dynar_foreach(list, cursor, current_pair){
270 if(current_pair->fragment1 != -1){
272 state->equals_to1_(current_pair->block1,current_pair->fragment1) = make_heap_area(current_pair->block2, current_pair->fragment2);
273 state->equals_to2_(current_pair->block2,current_pair->fragment2) = make_heap_area(current_pair->block1, current_pair->fragment1);
277 state->equals_to1_(current_pair->block1,0) = make_heap_area(current_pair->block2, current_pair->fragment2);
278 state->equals_to2_(current_pair->block2,0) = make_heap_area(current_pair->block1, current_pair->fragment1);
285 /** Check whether two blocks are known to be matching
287 * @param state State used
288 * @param b1 Block of state 1
289 * @param b2 Block of state 2
290 * @return if the blocks are known to be matching
292 static int equal_blocks(struct s_mc_diff *state, int b1, int b2){
294 if(state->equals_to1_(b1,0).block == b2 && state->equals_to2_(b2,0).block == b1)
300 /** Check whether two fragments are known to be matching
302 * @param state State used
303 * @param b1 Block of state 1
304 * @param f1 Fragment of state 1
305 * @param b2 Block of state 2
306 * @param f2 Fragment of state 2
307 * @return if the fragments are known to be matching
309 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2, int f2){
311 if(state->equals_to1_(b1,f1).block == b2
312 && state->equals_to1_(b1,f1).fragment == f2
313 && state->equals_to2_(b2,f2).block == b1
314 && state->equals_to2_(b2,f2).fragment == f1)
320 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, xbt_dynar_t i2){
321 if(mc_diff_info==NULL) {
322 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
323 mc_diff_info->equals_to1 = NULL;
324 mc_diff_info->equals_to2 = NULL;
325 mc_diff_info->types1 = NULL;
326 mc_diff_info->types2 = NULL;
328 struct s_mc_diff *state = mc_diff_info;
330 if((((struct mdesc *)heap1)->heaplimit != ((struct mdesc *)heap2)->heaplimit)
331 || ((((struct mdesc *)heap1)->heapsize != ((struct mdesc *)heap2)->heapsize) ))
334 state->heaplimit = ((struct mdesc *)heap1)->heaplimit;
336 // Mamailloute in order to find the base address of the main heap:
337 state->s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
339 state->heapbase1 = (char *)heap1 + BLOCKSIZE;
340 state->heapbase2 = (char *)heap2 + BLOCKSIZE;
342 state->heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)((struct mdesc *)heap1)->heapinfo - (char *)state->s_heap)));
343 state->heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)((struct mdesc *)heap2)->heapinfo - (char *)state->s_heap)));
345 state->heapsize1 = heap1->heapsize;
346 state->heapsize2 = heap2->heapsize;
348 state->to_ignore1 = i1;
349 state-> to_ignore2 = i2;
351 if(state->heaplimit > state->available) {
352 state->equals_to1 = realloc(state->equals_to1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
353 state->types1 = realloc(state->types1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
354 state->equals_to2 = realloc(state->equals_to2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
355 state->types2 = realloc(state->types2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
356 state->available = state->heaplimit;
359 memset(state->equals_to1, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
360 memset(state->equals_to2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
361 memset(state->types1, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
362 memset(state->types2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
365 MC_ignore_global_variable("mc_diff_info");
372 void reset_heap_information(){
376 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_mheap_t heap1, xbt_mheap_t heap2){
378 struct s_mc_diff *state = mc_diff_info;
380 if(heap1 == NULL && heap2 == NULL){
381 XBT_DEBUG("Malloc descriptors null");
385 /* Start comparison */
386 size_t i1, i2, j1, j2, k;
387 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
388 int nb_diff1 = 0, nb_diff2 = 0;
390 xbt_dynar_t previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
392 int equal, res_compare = 0;
394 /* Check busy blocks*/
398 while(i1 <= state->heaplimit){
400 if(state->heapinfo1[i1].type == -1){ /* Free block */
405 addr_block1 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
407 if(state->heapinfo1[i1].type == 0){ /* Large block */
409 if(is_stack(addr_block1)){
410 for(k=0; k < state->heapinfo1[i1].busy_block.size; k++)
411 state->equals_to1_(i1+k,0) = make_heap_area(i1, -1);
412 for(k=0; k < state->heapinfo2[i1].busy_block.size; k++)
413 state->equals_to2_(i1+k,0) = make_heap_area(i1, -1);
414 i1 += state->heapinfo1[i1].busy_block.size;
418 if(state->equals_to1_(i1,0).valid){
427 /* Try first to associate to same block in the other heap */
428 if(state->heapinfo2[i1].type == state->heapinfo1[i1].type){
430 if(state->equals_to2_(i1,0).valid == 0){
432 addr_block2 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
434 res_compare = compare_heap_area(addr_block1, addr_block2, snapshot1, snapshot2, NULL, NULL, 0);
436 if(res_compare != 1){
437 for(k=1; k < state->heapinfo2[i1].busy_block.size; k++)
438 state->equals_to2_(i1+k,0) = make_heap_area(i1, -1);
439 for(k=1; k < state->heapinfo1[i1].busy_block.size; k++)
440 state->equals_to1_(i1+k,0) = make_heap_area(i1, -1);
442 i1 += state->heapinfo1[i1].busy_block.size;
445 xbt_dynar_reset(previous);
451 while(i2 <= state->heaplimit && !equal){
453 addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
460 if(state->heapinfo2[i2].type != 0){
465 if(state->equals_to2_(i2,0).valid){
470 res_compare = compare_heap_area(addr_block1, addr_block2, snapshot1, snapshot2, NULL, NULL, 0);
472 if(res_compare != 1 ){
473 for(k=1; k < state->heapinfo2[i2].busy_block.size; k++)
474 state->equals_to2_(i2+k,0) = make_heap_area(i1, -1);
475 for(k=1; k < state->heapinfo1[i1].busy_block.size; k++)
476 state->equals_to1_(i1+k,0) = make_heap_area(i2, -1);
478 i1 += state->heapinfo1[i1].busy_block.size;
481 xbt_dynar_reset(previous);
488 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1, state->heapinfo1[i1].busy_block.busy_size, addr_block1);
489 i1 = state->heaplimit + 1;
494 }else{ /* Fragmented block */
496 for(j1=0; j1 < (size_t) (BLOCKSIZE >> state->heapinfo1[i1].type); j1++){
498 if(state->heapinfo1[i1].busy_frag.frag_size[j1] == -1) /* Free fragment */
501 if(state->equals_to1_(i1,j1).valid)
504 addr_frag1 = (void*) ((char *)addr_block1 + (j1 << state->heapinfo1[i1].type));
509 /* Try first to associate to same fragment in the other heap */
510 if(state->heapinfo2[i1].type == state->heapinfo1[i1].type){
512 if(state->equals_to2_(i1,j1).valid == 0){
514 addr_block2 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
515 addr_frag2 = (void*) ((char *)addr_block2 + (j1 << ((xbt_mheap_t)state->s_heap)->heapinfo[i1].type));
517 res_compare = compare_heap_area(addr_frag1, addr_frag2, snapshot1, snapshot2, NULL, NULL, 0);
522 xbt_dynar_reset(previous);
528 while(i2 <= state->heaplimit && !equal){
530 if(state->heapinfo2[i2].type <= 0){
535 for(j2=0; j2 < (size_t) (BLOCKSIZE >> state->heapinfo2[i2].type); j2++){
537 if(i2 == i1 && j2 == j1)
540 if(state->equals_to2_(i2,j2).valid)
543 addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
544 addr_frag2 = (void*) ((char *)addr_block2 + (j2 <<((xbt_mheap_t)state->s_heap)->heapinfo[i2].type));
546 res_compare = compare_heap_area(addr_frag1, addr_frag2, snapshot2, snapshot2, NULL, NULL, 0);
548 if(res_compare != 1){
550 xbt_dynar_reset(previous);
554 xbt_dynar_reset(previous);
563 XBT_DEBUG("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n", i1, j1, state->heapinfo1[i1].busy_frag.frag_size[j1], addr_frag1);
564 i2 = state->heaplimit + 1;
565 i1 = state->heaplimit + 1;
578 /* All blocks/fragments are equal to another block/fragment ? */
580 void *real_addr_frag1 = NULL, *real_addr_block1 = NULL, *real_addr_block2 = NULL, *real_addr_frag2 = NULL;
582 while(i<=state->heaplimit){
583 if(state->heapinfo1[i].type == 0){
584 if(i1 == state->heaplimit){
585 if(state->heapinfo1[i].busy_block.busy_size > 0){
586 if(state->equals_to1_(i,0).valid == 0){
587 if(XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)){
588 addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase1));
589 XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, state->heapinfo1[i].busy_block.busy_size);
590 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
597 if(state->heapinfo1[i].type > 0){
598 addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase1));
599 real_addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)((struct mdesc *)state->s_heap)->heapbase));
600 for(j=0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++){
601 if(i1== state->heaplimit){
602 if(state->heapinfo1[i].busy_frag.frag_size[j] > 0){
603 if(state->equals_to1_(i,j).valid == 0){
604 if(XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)){
605 addr_frag1 = (void*) ((char *)addr_block1 + (j << state->heapinfo1[i].type));
606 real_addr_frag1 = (void*) ((char *)real_addr_block1 + (j << ((struct mdesc *)state->s_heap)->heapinfo[i].type));
607 XBT_DEBUG("Block %zu, Fragment %zu (%p - %p) not found (size used = %zd)", i, j, addr_frag1, real_addr_frag1, state->heapinfo1[i].busy_frag.frag_size[j]);
608 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
619 if(i1 == state->heaplimit)
620 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
624 while(i<=state->heaplimit){
625 if(state->heapinfo2[i].type == 0){
626 if(i1 == state->heaplimit){
627 if(state->heapinfo2[i].busy_block.busy_size > 0){
628 if(state->equals_to2_(i,0).valid == 0){
629 if(XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)){
630 addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase2));
631 XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, state->heapinfo2[i].busy_block.busy_size);
632 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
639 if(state->heapinfo2[i].type > 0){
640 addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase2));
641 real_addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)((struct mdesc *)state->s_heap)->heapbase));
642 for(j=0; j < (size_t) (BLOCKSIZE >> state->heapinfo2[i].type); j++){
643 if(i1 == state->heaplimit){
644 if(state->heapinfo2[i].busy_frag.frag_size[j] > 0){
645 if(state->equals_to2_(i,j).valid == 0){
646 if(XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)){
647 addr_frag2 = (void*) ((char *)addr_block2 + (j << state->heapinfo2[i].type));
648 real_addr_frag2 = (void*) ((char *)real_addr_block2 + (j << ((struct mdesc *)state->s_heap)->heapinfo[i].type));
649 XBT_DEBUG( "Block %zu, Fragment %zu (%p - %p) not found (size used = %zd)", i, j, addr_frag2, real_addr_frag2, state->heapinfo2[i].busy_frag.frag_size[j]);
650 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
661 if(i1 == state->heaplimit)
662 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
664 xbt_dynar_free(&previous);
665 real_addr_frag1 = NULL, real_addr_block1 = NULL, real_addr_block2 = NULL, real_addr_frag2 = NULL;
667 return ((nb_diff1 > 0) || (nb_diff2 > 0));
673 * @param real_area1 Process address for state 1
674 * @param real_area2 Process address for state 2
675 * @param area1 Snapshot address for state 1
676 * @param area2 Snapshot address for state 2
677 * @param snapshot1 Snapshot of state 1
678 * @param snapshot2 Snapshot of state 2
681 * @param check_ignore
683 static int compare_heap_area_without_type(struct s_mc_diff *state, void *real_area1, void *real_area2, void *area1, void *area2, mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_dynar_t previous, int size, int check_ignore){
686 void *addr_pointed1, *addr_pointed2;
687 int pointer_align, res_compare;
688 ssize_t ignore1, ignore2;
692 if(check_ignore > 0){
693 if((ignore1 = heap_comparison_ignore_size(state->to_ignore1, (char *)real_area1 + i)) != -1){
694 if((ignore2 = heap_comparison_ignore_size(state->to_ignore2, (char *)real_area2 + i)) == ignore1){
707 if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
709 pointer_align = (i / sizeof(void*)) * sizeof(void*);
710 addr_pointed1 = *((void **)((char *)area1 + pointer_align));
711 addr_pointed2 = *((void **)((char *)area2 + pointer_align));
713 if(addr_pointed1 > maestro_stack_start && addr_pointed1 < maestro_stack_end && addr_pointed2 > maestro_stack_start && addr_pointed2 < maestro_stack_end){
714 i = pointer_align + sizeof(void *);
716 }else if(addr_pointed1 > state->s_heap && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
717 && addr_pointed2 > state->s_heap && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)){
718 // Both addreses are in the heap:
719 res_compare = compare_heap_area(addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, NULL, 0);
720 if(res_compare == 1){
723 i = pointer_align + sizeof(void *);
742 * @param real_area1 Process address for state 1
743 * @param real_area2 Process address for state 2
744 * @param area1 Snapshot address for state 1
745 * @param area2 Snapshot address for state 2
746 * @param snapshot1 Snapshot of state 1
747 * @param snapshot2 Snapshot of state 2
750 * @param area_size either a byte_size or an elements_count (?)
751 * @param check_ignore
752 * @param pointer_level
753 * @return 0 (same), 1 (different), -1 (unknown)
755 static int compare_heap_area_with_type(struct s_mc_diff *state, void *real_area1, void *real_area2, void *area1, void *area2,
756 mc_snapshot_t snapshot1, mc_snapshot_t snapshot2,
757 xbt_dynar_t previous, dw_type_t type,
758 int area_size, int check_ignore, int pointer_level){
760 if(is_stack(real_area1) && is_stack(real_area2))
763 ssize_t ignore1, ignore2;
765 if((check_ignore > 0) && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1)) > 0) && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2)) == ignore1)){
769 dw_type_t subtype, subsubtype;
770 int res, elm_size, i;
771 unsigned int cursor = 0;
773 void *addr_pointed1, *addr_pointed2;;
776 case DW_TAG_unspecified_type:
779 case DW_TAG_base_type:
780 if(type->name!=NULL && strcmp(type->name, "char") == 0){ /* String, hence random (arbitrary ?) size */
781 if(real_area1 == real_area2)
784 return (memcmp(area1, area2, area_size) != 0);
786 if(area_size != -1 && type->byte_size != area_size)
789 return (memcmp(area1, area2, type->byte_size) != 0);
793 case DW_TAG_enumeration_type:
794 if(area_size != -1 && type->byte_size != area_size)
797 return (memcmp(area1, area2, type->byte_size) != 0);
800 case DW_TAG_const_type:
801 case DW_TAG_volatile_type:
802 return compare_heap_area_with_type(state, real_area1, real_area2, area1, area2, snapshot1, snapshot2, previous, type->subtype, area_size, check_ignore, pointer_level);
804 case DW_TAG_array_type:
805 subtype = type->subtype;
806 switch(subtype->type){
807 case DW_TAG_unspecified_type:
810 case DW_TAG_base_type:
811 case DW_TAG_enumeration_type:
812 case DW_TAG_pointer_type:
813 case DW_TAG_reference_type:
814 case DW_TAG_rvalue_reference_type:
815 case DW_TAG_structure_type:
816 case DW_TAG_class_type:
817 case DW_TAG_union_type:
818 if(subtype->full_type)
819 subtype = subtype->full_type;
820 elm_size = subtype->byte_size;
822 // TODO, just remove the type indirection?
823 case DW_TAG_const_type:
825 case DW_TAG_volatile_type:
826 subsubtype = subtype->subtype;
827 if(subsubtype->full_type)
828 subsubtype = subsubtype->full_type;
829 elm_size = subsubtype->byte_size;
835 for(i=0; i<type->element_count; i++){
836 // TODO, add support for variable stride (DW_AT_byte_stride)
837 res = compare_heap_area_with_type(state, (char *)real_area1 + (i*elm_size), (char *)real_area2 + (i*elm_size), (char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), snapshot1, snapshot2, previous, type->subtype, subtype->byte_size, check_ignore, pointer_level);
842 case DW_TAG_reference_type:
843 case DW_TAG_rvalue_reference_type:
844 case DW_TAG_pointer_type:
845 if(type->subtype && type->subtype->type == DW_TAG_subroutine_type){
846 addr_pointed1 = *((void **)(area1));
847 addr_pointed2 = *((void **)(area2));
848 return (addr_pointed1 != addr_pointed2);;
851 if(pointer_level > 1){ /* Array of pointers */
852 for(i=0; i<(area_size/sizeof(void *)); i++){
853 addr_pointed1 = *((void **)((char *)area1 + (i*sizeof(void *))));
854 addr_pointed2 = *((void **)((char *)area2 + (i*sizeof(void *))));
855 if(addr_pointed1 > state->s_heap && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
856 && addr_pointed2 > state->s_heap && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
857 res = compare_heap_area(addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype, pointer_level);
859 res = (addr_pointed1 != addr_pointed2);
864 addr_pointed1 = *((void **)(area1));
865 addr_pointed2 = *((void **)(area2));
866 if(addr_pointed1 > state->s_heap && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
867 && addr_pointed2 > state->s_heap && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
868 return compare_heap_area(addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype, pointer_level);
870 return (addr_pointed1 != addr_pointed2);
874 case DW_TAG_structure_type:
875 case DW_TAG_class_type:
877 type = type->full_type;
878 if(area_size != -1 && type->byte_size != area_size){
879 if(area_size>type->byte_size && area_size%type->byte_size == 0){
880 for(i=0; i<(area_size/type->byte_size); i++){
881 res = compare_heap_area_with_type(state, (char *)real_area1 + (i*type->byte_size), (char *)real_area2 + (i*type->byte_size), (char *)area1 + (i*type->byte_size), (char *)area2 + (i*type->byte_size), snapshot1, snapshot2, previous, type, -1, check_ignore, 0);
890 xbt_dynar_foreach(type->members, cursor, member){
891 // TODO, optimize this? (for the offset case)
892 char* real_member1 = mc_member_resolve(real_area1, type, member, snapshot1);
893 char* real_member2 = mc_member_resolve(real_area2, type, member, snapshot2);
894 char* member1 = mc_translate_address((uintptr_t)real_member1, snapshot1);
895 char* member2 = mc_translate_address((uintptr_t)real_member2, snapshot2);
896 res = compare_heap_area_with_type(state, real_member1, real_member2, member1, member2, snapshot1, snapshot2, previous, member->subtype, -1, check_ignore, 0);
903 case DW_TAG_union_type:
904 return compare_heap_area_without_type(state, real_area1, real_area2, area1, area2, snapshot1, snapshot2, previous, type->byte_size, check_ignore);
914 /** Infer the type of a part of the block from the type of the block
916 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
918 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
920 * @param type_id DWARF type ID of the root address
922 * @return DWARF type ID for given offset
924 static dw_type_t get_offset_type(void* real_base_address, dw_type_t type, int offset, int area_size, mc_snapshot_t snapshot){
926 // Beginning of the block, the infered variable type if the type of the block:
931 case DW_TAG_structure_type :
932 case DW_TAG_class_type:
934 type = type->full_type;
936 if(area_size != -1 && type->byte_size != area_size){
937 if(area_size>type->byte_size && area_size%type->byte_size == 0)
942 unsigned int cursor = 0;
944 xbt_dynar_foreach(type->members, cursor, member){
946 if(!member->location.size) {
947 // We have the offset, use it directly (shortcut):
948 if(member->offset == offset)
949 return member->subtype;
951 char* real_member = mc_member_resolve(real_base_address, type, member, snapshot);
952 if(real_member - (char*)real_base_address == offset)
953 return member->subtype;
961 /* FIXME : other cases ? */
969 * @param area1 Process address for state 1
970 * @param area2 Process address for state 2
971 * @param snapshot1 Snapshot of state 1
972 * @param snapshot2 Snapshot of state 2
973 * @param previous Pairs of blocks already compared on the current path (or NULL)
974 * @param type_id Type of variable
975 * @param pointer_level
976 * @return 0 (same), 1 (different), -1
978 int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_dynar_t previous, dw_type_t type, int pointer_level){
980 struct s_mc_diff* state = mc_diff_info;
983 ssize_t block1, frag1, block2, frag2;
985 int check_ignore = 0;
987 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2, *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
988 void *area1_to_compare, *area2_to_compare;
990 int offset1 =0, offset2 = 0;
991 int new_size1 = -1, new_size2 = -1;
992 dw_type_t new_type1 = NULL, new_type2 = NULL;
996 if(previous == NULL){
997 previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1001 // Get block number:
1002 block1 = ((char*)area1 - (char*)((xbt_mheap_t)state->s_heap)->heapbase) / BLOCKSIZE + 1;
1003 block2 = ((char*)area2 - (char*)((xbt_mheap_t)state->s_heap)->heapbase) / BLOCKSIZE + 1;
1005 // If either block is a stack block:
1006 if(is_block_stack((int)block1) && is_block_stack((int)block2)){
1007 add_heap_area_pair(previous, block1, -1, block2, -1);
1009 match_equals(state, previous);
1010 xbt_dynar_free(&previous);
1015 // If either block is not in the expected area of memory:
1016 if(((char *)area1 < (char*)((xbt_mheap_t)state->s_heap)->heapbase) || (block1 > state->heapsize1) || (block1 < 1)
1017 || ((char *)area2 < (char*)((xbt_mheap_t)state->s_heap)->heapbase) || (block2 > state->heapsize2) || (block2 < 1)){
1019 xbt_dynar_free(&previous);
1024 // Snapshot address of the block:
1025 addr_block1 = ((void*) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE + (char*)state->heapbase1));
1026 addr_block2 = ((void*) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE + (char*)state->heapbase2));
1028 // Process address of the block:
1029 real_addr_block1 = ((void*) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
1030 real_addr_block2 = ((void*) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase));
1035 type = type->full_type;
1037 // This assume that for "boring" types (volatile ...) byte_size is absent:
1038 while(type->byte_size == 0 && type->subtype!=NULL)
1039 type = type->subtype;
1042 if((type->type == DW_TAG_pointer_type) || ((type->type == DW_TAG_base_type) && type->name!=NULL && (!strcmp(type->name, "char"))))
1045 type_size = type->byte_size;
1049 if((state->heapinfo1[block1].type == -1) && (state->heapinfo2[block2].type == -1)){ /* Free block */
1052 match_equals(state, previous);
1053 xbt_dynar_free(&previous);
1057 }else if((state->heapinfo1[block1].type == 0) && (state->heapinfo2[block2].type == 0)){ /* Complete block */
1059 // TODO, lookup variable type from block type as done for fragmented blocks
1061 if(state->equals_to1_(block1,0).valid && state->equals_to2_(block2,0).valid){
1062 if(equal_blocks(state, block1, block2)){
1064 match_equals(state, previous);
1065 xbt_dynar_free(&previous);
1071 if(type_size != -1){
1072 if(type_size != state->heapinfo1[block1].busy_block.busy_size
1073 && type_size != state->heapinfo2[block2].busy_block.busy_size
1074 && type->name!=NULL && !strcmp(type->name, "s_smx_context")){
1076 match_equals(state, previous);
1077 xbt_dynar_free(&previous);
1083 if(state->heapinfo1[block1].busy_block.size != state->heapinfo2[block2].busy_block.size){
1085 xbt_dynar_free(&previous);
1090 if(state->heapinfo1[block1].busy_block.busy_size != state->heapinfo2[block2].busy_block.busy_size){
1092 xbt_dynar_free(&previous);
1097 if(!add_heap_area_pair(previous, block1, -1, block2, -1)){
1099 match_equals(state, previous);
1100 xbt_dynar_free(&previous);
1105 size = state->heapinfo1[block1].busy_block.busy_size;
1107 // Remember (basic) type inference.
1108 // The current data structure only allows us to do this for the whole block.
1109 if (type != NULL && area1==real_addr_block1) {
1110 state->types1_(block1,0) = type;
1112 if (type != NULL && area2==real_addr_block2) {
1113 state->types2_(block2,0) = type;
1118 match_equals(state, previous);
1119 xbt_dynar_free(&previous);
1127 area1_to_compare = addr_block1;
1128 area2_to_compare = addr_block2;
1130 if((state->heapinfo1[block1].busy_block.ignore > 0) && (state->heapinfo2[block2].busy_block.ignore == state->heapinfo1[block1].busy_block.ignore))
1131 check_ignore = state->heapinfo1[block1].busy_block.ignore;
1133 }else if((state->heapinfo1[block1].type > 0) && (state->heapinfo2[block2].type > 0)){ /* Fragmented block */
1136 frag1 = ((uintptr_t) (ADDR2UINT (area1) % (BLOCKSIZE))) >> state->heapinfo1[block1].type;
1137 frag2 = ((uintptr_t) (ADDR2UINT (area2) % (BLOCKSIZE))) >> state->heapinfo2[block2].type;
1139 // Snapshot address of the fragment:
1140 addr_frag1 = (void*) ((char *)addr_block1 + (frag1 << state->heapinfo1[block1].type));
1141 addr_frag2 = (void*) ((char *)addr_block2 + (frag2 << state->heapinfo2[block2].type));
1143 // Process address of the fragment:
1144 real_addr_frag1 = (void*) ((char *)real_addr_block1 + (frag1 << ((xbt_mheap_t)state->s_heap)->heapinfo[block1].type));
1145 real_addr_frag2 = (void*) ((char *)real_addr_block2 + (frag2 << ((xbt_mheap_t)state->s_heap)->heapinfo[block2].type));
1147 // Check the size of the fragments against the size of the type:
1148 if(type_size != -1){
1149 if(state->heapinfo1[block1].busy_frag.frag_size[frag1] == -1 || state->heapinfo2[block2].busy_frag.frag_size[frag2] == -1){
1151 match_equals(state, previous);
1152 xbt_dynar_free(&previous);
1156 if(type_size != state->heapinfo1[block1].busy_frag.frag_size[frag1]|| type_size != state->heapinfo2[block2].busy_frag.frag_size[frag2]){
1158 match_equals(state, previous);
1159 xbt_dynar_free(&previous);
1165 // Check if the blocks are already matched together:
1166 if(state->equals_to1_(block1,frag1).valid && state->equals_to2_(block2,frag2).valid){
1167 if(equal_fragments(state, block1, frag1, block2, frag2)){
1169 match_equals(state, previous);
1170 xbt_dynar_free(&previous);
1176 // Compare the size of both fragments:
1177 if(state->heapinfo1[block1].busy_frag.frag_size[frag1] != state->heapinfo2[block2].busy_frag.frag_size[frag2]){
1178 if(type_size == -1){
1180 match_equals(state, previous);
1181 xbt_dynar_free(&previous);
1186 xbt_dynar_free(&previous);
1192 // Size of the fragment:
1193 size = state->heapinfo1[block1].busy_frag.frag_size[frag1];
1195 // Remember (basic) type inference.
1196 // The current data structure only allows us to do this for the whole block.
1197 if(type != NULL && area1==real_addr_frag1){
1198 state->types1_(block1,frag1) = type;
1200 if(type != NULL && area2==real_addr_frag2) {
1201 state->types2_(block2,frag2) = type;
1204 // The type of the variable is already known:
1210 // Type inference from the block type.
1211 else if(state->types1_(block1,frag1) != NULL || state->types2_(block2,frag2) != NULL) {
1213 offset1 = (char *)area1 - (char *)real_addr_frag1;
1214 offset2 = (char *)area2 - (char *)real_addr_frag2;
1216 if(state->types1_(block1,frag1) != NULL && state->types2_(block2,frag2) != NULL){
1217 new_type1 = get_offset_type(real_addr_frag1, state->types1_(block1,frag1), offset1, size, snapshot1);
1218 new_type2 = get_offset_type(real_addr_frag2, state->types2_(block2,frag2), offset1, size, snapshot2);
1219 }else if(state->types1_(block1,frag1) != NULL){
1220 new_type1 = get_offset_type(real_addr_frag1, state->types1_(block1,frag1), offset1, size, snapshot1);
1221 new_type2 = get_offset_type(real_addr_frag2, state->types1_(block1,frag1), offset2, size, snapshot2);
1222 }else if(state->types2_(block2,frag2) != NULL){
1223 new_type1 = get_offset_type(real_addr_frag1, state->types2_(block2,frag2), offset1, size, snapshot1);
1224 new_type2 = get_offset_type(real_addr_frag2, state->types2_(block2,frag2), offset2, size, snapshot2);
1227 match_equals(state, previous);
1228 xbt_dynar_free(&previous);
1233 if(new_type1 != NULL && new_type2 != NULL && new_type1!=new_type2){
1236 while(type->byte_size == 0 && type->subtype != NULL)
1237 type = type->subtype;
1238 new_size1 = type->byte_size;
1241 while(type->byte_size == 0 && type->subtype != NULL)
1242 type = type->subtype;
1243 new_size2 = type->byte_size;
1247 match_equals(state, previous);
1248 xbt_dynar_free(&previous);
1254 area1_to_compare = (char *)addr_frag1 + offset1;
1255 area2_to_compare = (char *)addr_frag2 + offset2;
1257 if(new_size1 > 0 && new_size1 == new_size2){
1262 if(offset1 == 0 && offset2 == 0){
1263 if(!add_heap_area_pair(previous, block1, frag1, block2, frag2)){
1265 match_equals(state, previous);
1266 xbt_dynar_free(&previous);
1274 match_equals(state, previous);
1275 xbt_dynar_free(&previous);
1280 if((state->heapinfo1[block1].busy_frag.ignore[frag1] > 0) && ( state->heapinfo2[block2].busy_frag.ignore[frag2] == state->heapinfo1[block1].busy_frag.ignore[frag1]))
1281 check_ignore = state->heapinfo1[block1].busy_frag.ignore[frag1];
1286 xbt_dynar_free(&previous);
1293 /* Start comparison*/
1295 res_compare = compare_heap_area_with_type(state, area1, area2, area1_to_compare, area2_to_compare, snapshot1, snapshot2, previous, type, size, check_ignore, pointer_level);
1297 res_compare = compare_heap_area_without_type(state, area1, area2, area1_to_compare, area2_to_compare, snapshot1, snapshot2, previous, size, check_ignore);
1299 if(res_compare == 1){
1301 xbt_dynar_free(&previous);
1306 match_equals(state, previous);
1307 xbt_dynar_free(&previous);
1313 /*********************************************** Miscellaneous ***************************************************/
1314 /****************************************************************************************************************/
1317 static int get_pointed_area_size(void *area, int heap){
1319 struct s_mc_diff *state = mc_diff_info;
1322 malloc_info *heapinfo;
1325 heapinfo = state->heapinfo1;
1327 heapinfo = state->heapinfo2;
1329 block = ((char*)area - (char*)((xbt_mheap_t)state->s_heap)->heapbase) / BLOCKSIZE + 1;
1331 if(((char *)area < (char*)((xbt_mheap_t)state->s_heap)->heapbase) || (block > state->heapsize1) || (block < 1))
1334 if(heapinfo[block].type == -1){ /* Free block */
1336 }else if(heapinfo[block].type == 0){ /* Complete block */
1337 return (int)heapinfo[block].busy_block.busy_size;
1339 frag = ((uintptr_t) (ADDR2UINT (area) % (BLOCKSIZE))) >> heapinfo[block].type;
1340 return (int)heapinfo[block].busy_frag.frag_size[frag];
1346 char *get_type_description(mc_object_info_t info, char *type_name){
1348 xbt_dict_cursor_t dict_cursor;
1352 xbt_dict_foreach(info->types, dict_cursor, type_origin, type){
1353 if(type->name && (strcmp(type->name, type_name) == 0) && type->byte_size > 0){
1354 xbt_dict_cursor_free(&dict_cursor);
1359 xbt_dict_cursor_free(&dict_cursor);
1365 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1369 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
1371 struct s_mc_diff *state = mc_diff_info;
1373 if(heap1 == NULL && heap1 == NULL){
1374 XBT_DEBUG("Malloc descriptors null");
1378 if(heap1->heaplimit != heap2->heaplimit){
1379 XBT_DEBUG("Different limit of valid info table indices");
1383 /* Heap information */
1384 state->heaplimit = ((struct mdesc *)heap1)->heaplimit;
1387 // Mamailloute in order to find the base address of the main heap:
1388 state->s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1390 state->heapbase1 = (char *)heap1 + BLOCKSIZE;
1391 state->heapbase2 = (char *)heap2 + BLOCKSIZE;
1393 state->heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)state->s_heap)));
1394 state->heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)state->s_heap)));
1396 state->heapsize1 = heap1->heapsize;
1397 state->heapsize2 = heap2->heapsize;
1399 /* Start comparison */
1401 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1405 /* Check busy blocks*/
1409 while(i <= state->heaplimit){
1411 addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase1));
1412 addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase2));
1414 if(state->heapinfo1[i].type != state->heapinfo2[i].type){
1416 distance += BLOCKSIZE;
1417 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i, state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1422 if(state->heapinfo1[i].type == -1){ /* Free block */
1427 if(state->heapinfo1[i].type == 0){ /* Large block */
1429 if(state->heapinfo1[i].busy_block.size != state->heapinfo2[i].busy_block.size){
1430 distance += BLOCKSIZE * max(state->heapinfo1[i].busy_block.size, state->heapinfo2[i].busy_block.size);
1431 i += max(state->heapinfo1[i].busy_block.size, state->heapinfo2[i].busy_block.size);
1432 XBT_DEBUG("Different larger of cluster at block %zu : %zu - %zu -> distance = %d", i, state->heapinfo1[i].busy_block.size, state->heapinfo2[i].busy_block.size, distance);
1436 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1437 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1438 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1439 XBT_DEBUG("Different size used oin large cluster at block %zu : %zu - %zu -> distance = %d", i, heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size, distance);
1445 //while(k < (heapinfo1[i].busy_block.busy_size)){
1446 while(k < state->heapinfo1[i].busy_block.size * BLOCKSIZE){
1447 if(memcmp((char *)addr_block1 + k, (char *)addr_block2 + k, 1) != 0){
1455 }else { /* Fragmented block */
1457 for(j=0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++){
1459 addr_frag1 = (void*) ((char *)addr_block1 + (j << state->heapinfo1[i].type));
1460 addr_frag2 = (void*) ((char *)addr_block2 + (j << state->heapinfo2[i].type));
1462 if(state->heapinfo1[i].busy_frag.frag_size[j] == 0 && state->heapinfo2[i].busy_frag.frag_size[j] == 0){
1467 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1468 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1469 XBT_DEBUG("Different size used in fragment %zu in block %zu : %d - %d -> distance = %d", j, i, heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j], distance);
1475 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1476 while(k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))){
1477 if(memcmp((char *)addr_frag1 + k, (char *)addr_frag2 + k, 1) != 0){