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)
32 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
33 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
37 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
38 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
40 /* xbt_ex_setup_backtrace(&e); */
41 /* if (e.used == 0) { */
42 /* fprintf(stderr, "(backtrace not set)\n"); */
43 /* } else if (e.bt_strings == NULL) { */
44 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
48 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
49 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
50 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
55 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
61 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
62 /* e.used = XBT_BACKTRACE_SIZE; */
64 /* xbt_ex_setup_backtrace(&e); */
65 /* if (e.used == 0) { */
66 /* fprintf(stderr, "(backtrace not set)\n"); */
67 /* } else if (e.bt_strings == NULL) { */
68 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
72 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
73 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
74 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
80 static void mmalloc_backtrace_display(void *addr)
83 /* size_t block, frag_nb; */
86 /* xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); */
88 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
90 /* type = heap->heapinfo[block].type; */
93 /* case MMALLOC_TYPE_HEAPINFO : */
94 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
95 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
98 /* case 0: /\* Large block *\/ */
99 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
101 /* default: /\* Fragmented block *\/ */
102 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
103 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
104 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
107 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
113 static int compare_backtrace(int b1, int f1, int b2, int f2)
117 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
118 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
119 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
120 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
125 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
126 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
127 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
128 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
137 /*********************************** Heap comparison ***********************************/
138 /***************************************************************************************/
140 typedef char *type_name;
143 /** \brief Base address of the real heap */
146 // Number of blocks in the heaps:
147 size_t heapsize1, heapsize2;
148 xbt_dynar_t to_ignore1, to_ignore2;
149 s_heap_area_t *equals_to1, *equals_to2;
150 dw_type_t *types1, *types2;
154 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
155 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
156 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
157 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
159 __thread struct s_mc_diff *mc_diff_info = NULL;
161 /*********************************** Free functions ************************************/
163 static void heap_area_pair_free(heap_area_pair_t pair)
169 static void heap_area_pair_free_voidp(void *d)
171 heap_area_pair_free((heap_area_pair_t) * (void **) d);
174 static void heap_area_free(heap_area_t area)
180 /************************************************************************************/
182 static s_heap_area_t make_heap_area(int block, int fragment)
187 area.fragment = fragment;
192 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
193 int block2, int fragment2)
196 unsigned int cursor = 0;
197 heap_area_pair_t current_pair;
199 xbt_dynar_foreach(list, cursor, current_pair) {
200 if (current_pair->block1 == block1 && current_pair->block2 == block2
201 && current_pair->fragment1 == fragment1
202 && current_pair->fragment2 == fragment2)
209 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
210 int block2, int fragment2)
213 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
214 heap_area_pair_t pair = NULL;
215 pair = xbt_new0(s_heap_area_pair_t, 1);
216 pair->block1 = block1;
217 pair->fragment1 = fragment1;
218 pair->block2 = block2;
219 pair->fragment2 = fragment2;
221 xbt_dynar_push(list, &pair);
229 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
233 unsigned int cursor = 0;
235 int end = xbt_dynar_length(ignore_list) - 1;
236 mc_heap_ignore_region_t region;
238 while (start <= end) {
239 cursor = (start + end) / 2;
241 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
242 mc_heap_ignore_region_t);
243 if (region->address == address)
245 if (region->address < address)
247 if (region->address > address)
254 static int is_stack(void *address)
256 unsigned int cursor = 0;
257 stack_region_t stack;
259 xbt_dynar_foreach(stacks_areas, cursor, stack) {
260 if (address == stack->address)
267 // TODO, this should depend on the snapshot?
268 static int is_block_stack(int block)
270 unsigned int cursor = 0;
271 stack_region_t stack;
273 xbt_dynar_foreach(stacks_areas, cursor, stack) {
274 if (block == stack->block)
281 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
284 unsigned int cursor = 0;
285 heap_area_pair_t current_pair;
287 xbt_dynar_foreach(list, cursor, current_pair) {
289 if (current_pair->fragment1 != -1) {
291 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
292 make_heap_area(current_pair->block2, current_pair->fragment2);
293 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
294 make_heap_area(current_pair->block1, current_pair->fragment1);
298 state->equals_to1_(current_pair->block1, 0) =
299 make_heap_area(current_pair->block2, current_pair->fragment2);
300 state->equals_to2_(current_pair->block2, 0) =
301 make_heap_area(current_pair->block1, current_pair->fragment1);
308 /** Check whether two blocks are known to be matching
310 * @param state State used
311 * @param b1 Block of state 1
312 * @param b2 Block of state 2
313 * @return if the blocks are known to be matching
315 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
318 if (state->equals_to1_(b1, 0).block == b2
319 && state->equals_to2_(b2, 0).block == b1)
325 /** Check whether two fragments are known to be matching
327 * @param state State used
328 * @param b1 Block of state 1
329 * @param f1 Fragment of state 1
330 * @param b2 Block of state 2
331 * @param f2 Fragment of state 2
332 * @return if the fragments are known to be matching
334 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
338 if (state->equals_to1_(b1, f1).block == b2
339 && state->equals_to1_(b1, f1).fragment == f2
340 && state->equals_to2_(b2, f2).block == b1
341 && state->equals_to2_(b2, f2).fragment == f1)
347 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
350 if (mc_diff_info == NULL) {
351 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
352 mc_diff_info->equals_to1 = NULL;
353 mc_diff_info->equals_to2 = NULL;
354 mc_diff_info->types1 = NULL;
355 mc_diff_info->types2 = NULL;
357 struct s_mc_diff *state = mc_diff_info;
359 if ((((struct mdesc *) heap1)->heaplimit !=
360 ((struct mdesc *) heap2)->heaplimit)
362 ((((struct mdesc *) heap1)->heapsize !=
363 ((struct mdesc *) heap2)->heapsize)))
366 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
368 // Mamailloute in order to find the base address of the main heap:
370 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
372 state->heapsize1 = heap1->heapsize;
373 state->heapsize2 = heap2->heapsize;
375 state->to_ignore1 = i1;
376 state->to_ignore2 = i2;
378 if (state->heaplimit > state->available) {
380 realloc(state->equals_to1,
381 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
382 sizeof(s_heap_area_t));
384 realloc(state->types1,
385 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
386 sizeof(type_name *));
388 realloc(state->equals_to2,
389 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
390 sizeof(s_heap_area_t));
392 realloc(state->types2,
393 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
394 sizeof(type_name *));
395 state->available = state->heaplimit;
398 memset(state->equals_to1, 0,
399 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
400 memset(state->equals_to2, 0,
401 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
402 memset(state->types1, 0,
403 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
404 memset(state->types2, 0,
405 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
411 void reset_heap_information()
416 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
419 struct s_mc_diff *state = mc_diff_info;
421 /* Start comparison */
422 size_t i1, i2, j1, j2, k;
423 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
424 int nb_diff1 = 0, nb_diff2 = 0;
426 int equal, res_compare = 0;
428 /* Check busy blocks */
432 malloc_info heapinfo_temp1, heapinfo_temp2;
433 malloc_info heapinfo_temp2b;
435 mc_mem_region_t heap_region1 = snapshot1->regions[0];
436 mc_mem_region_t heap_region2 = snapshot2->regions[0];
438 // This is in snapshot do not use them directly:
439 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot1);
440 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot2);
442 while (i1 <= state->heaplimit) {
444 // TODO, lookup in the correct region in order to speed it up:
445 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
446 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i1], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
448 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
449 i1 += heapinfo1->free_block.size;
453 if (heapinfo1->type < 0) {
454 fprintf(stderr, "Unkown mmalloc block type.\n");
459 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
460 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
462 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
464 if (is_stack(addr_block1)) {
465 for (k = 0; k < heapinfo1->busy_block.size; k++)
466 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
467 for (k = 0; k < heapinfo2->busy_block.size; k++)
468 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
469 i1 += heapinfo1->busy_block.size;
473 if (state->equals_to1_(i1, 0).valid) {
482 /* Try first to associate to same block in the other heap */
483 if (heapinfo2->type == heapinfo1->type) {
485 if (state->equals_to2_(i1, 0).valid == 0) {
488 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
489 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
492 compare_heap_area(addr_block1, addr_block2, snapshot1, snapshot2,
495 if (res_compare != 1) {
496 for (k = 1; k < heapinfo2->busy_block.size; k++)
497 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
498 for (k = 1; k < heapinfo1->busy_block.size; k++)
499 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
501 i1 += heapinfo1->busy_block.size;
508 while (i2 <= state->heaplimit && !equal) {
511 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
512 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
519 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
521 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
526 if (state->equals_to2_(i2, 0).valid) {
532 compare_heap_area(addr_block1, addr_block2, snapshot1, snapshot2,
535 if (res_compare != 1) {
536 for (k = 1; k < heapinfo2b->busy_block.size; k++)
537 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
538 for (k = 1; k < heapinfo1->busy_block.size; k++)
539 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
541 i1 += heapinfo1->busy_block.size;
549 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
550 heapinfo1->busy_block.busy_size, addr_block1);
551 i1 = state->heaplimit + 1;
556 } else { /* Fragmented block */
558 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
560 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
563 if (state->equals_to1_(i1, j1).valid)
567 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
572 /* Try first to associate to same fragment in the other heap */
573 if (heapinfo2->type == heapinfo1->type) {
575 if (state->equals_to2_(i1, j1).valid == 0) {
578 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
579 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
581 (void *) ((char *) addr_block2 +
582 (j1 << heapinfo2->type));
585 compare_heap_area(addr_frag1, addr_frag2, snapshot1, snapshot2,
588 if (res_compare != 1)
595 while (i2 <= state->heaplimit && !equal) {
597 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
599 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
600 i2 += heapinfo2b->free_block.size;
604 if (heapinfo2b->type < 0) {
605 fprintf(stderr, "Unkown mmalloc block type.\n");
609 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
612 if (i2 == i1 && j2 == j1)
615 if (state->equals_to2_(i2, j2).valid)
619 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
620 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
622 (void *) ((char *) addr_block2 +
623 (j2 << heapinfo2b->type));
626 compare_heap_area(addr_frag1, addr_frag2, snapshot2, snapshot2,
629 if (res_compare != 1) {
642 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
643 i1, j1, heapinfo1->busy_frag.frag_size[j1],
645 i2 = state->heaplimit + 1;
646 i1 = state->heaplimit + 1;
659 /* All blocks/fragments are equal to another block/fragment ? */
662 for(i = 1; i <= state->heaplimit; i++) {
663 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
664 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
665 if (i1 == state->heaplimit) {
666 if (heapinfo1->busy_block.busy_size > 0) {
667 if (state->equals_to1_(i, 0).valid == 0) {
668 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
670 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
671 heapinfo1->busy_block.busy_size);
672 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
679 if (heapinfo1->type > 0) {
680 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
681 if (i1 == state->heaplimit) {
682 if (heapinfo1->busy_frag.frag_size[j] > 0) {
683 if (state->equals_to1_(i, j).valid == 0) {
684 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
685 // TODO, print fragment address
687 ("Block %zu, Fragment %zu not found (size used = %zd)",
689 heapinfo1->busy_frag.frag_size[j]);
690 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
700 if (i1 == state->heaplimit)
701 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
703 for (i=1; i <= state->heaplimit; i++) {
704 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
705 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
706 if (i1 == state->heaplimit) {
707 if (heapinfo2->busy_block.busy_size > 0) {
708 if (state->equals_to2_(i, 0).valid == 0) {
709 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
710 // TODO, print address of the block
711 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
712 heapinfo2->busy_block.busy_size);
713 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
720 if (heapinfo2->type > 0) {
721 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
722 if (i1 == state->heaplimit) {
723 if (heapinfo2->busy_frag.frag_size[j] > 0) {
724 if (state->equals_to2_(i, j).valid == 0) {
725 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
726 // TODO, print address of the block
728 ("Block %zu, Fragment %zu not found (size used = %zd)",
730 heapinfo2->busy_frag.frag_size[j]);
731 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
741 if (i1 == state->heaplimit)
742 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
744 return ((nb_diff1 > 0) || (nb_diff2 > 0));
750 * @param real_area1 Process address for state 1
751 * @param real_area2 Process address for state 2
752 * @param snapshot1 Snapshot of state 1
753 * @param snapshot2 Snapshot of state 2
756 * @param check_ignore
758 static int compare_heap_area_without_type(struct s_mc_diff *state,
759 void *real_area1, void *real_area2,
760 mc_snapshot_t snapshot1,
761 mc_snapshot_t snapshot2,
762 xbt_dynar_t previous, int size,
767 void *addr_pointed1, *addr_pointed2;
768 int pointer_align, res_compare;
769 ssize_t ignore1, ignore2;
771 mc_mem_region_t heap_region1 = snapshot1->regions[0];
772 mc_mem_region_t heap_region2 = snapshot2->regions[0];
776 if (check_ignore > 0) {
778 heap_comparison_ignore_size(state->to_ignore1,
779 (char *) real_area1 + i)) != -1) {
781 heap_comparison_ignore_size(state->to_ignore2,
782 (char *) real_area2 + i)) == ignore1) {
795 if (mc_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
797 pointer_align = (i / sizeof(void *)) * sizeof(void *);
798 addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1);
799 addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2);
801 if (addr_pointed1 > maestro_stack_start
802 && addr_pointed1 < maestro_stack_end
803 && addr_pointed2 > maestro_stack_start
804 && addr_pointed2 < maestro_stack_end) {
805 i = pointer_align + sizeof(void *);
807 } else if (addr_pointed1 > state->s_heap
808 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
809 && addr_pointed2 > state->s_heap
810 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
811 // Both addreses are in the heap:
813 compare_heap_area(addr_pointed1, addr_pointed2, snapshot1,
814 snapshot2, previous, NULL, 0);
815 if (res_compare == 1) {
818 i = pointer_align + sizeof(void *);
837 * @param real_area1 Process address for state 1
838 * @param real_area2 Process address for state 2
839 * @param snapshot1 Snapshot of state 1
840 * @param snapshot2 Snapshot of state 2
843 * @param area_size either a byte_size or an elements_count (?)
844 * @param check_ignore
845 * @param pointer_level
846 * @return 0 (same), 1 (different), -1 (unknown)
848 static int compare_heap_area_with_type(struct s_mc_diff *state,
849 void *real_area1, void *real_area2,
850 mc_snapshot_t snapshot1,
851 mc_snapshot_t snapshot2,
852 xbt_dynar_t previous, dw_type_t type,
853 int area_size, int check_ignore,
857 if (is_stack(real_area1) && is_stack(real_area2))
860 ssize_t ignore1, ignore2;
862 if ((check_ignore > 0)
863 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
865 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
870 dw_type_t subtype, subsubtype;
871 int res, elm_size, i;
872 unsigned int cursor = 0;
874 void *addr_pointed1, *addr_pointed2;;
876 mc_mem_region_t heap_region1 = snapshot1->regions[0];
877 mc_mem_region_t heap_region2 = snapshot2->regions[0];
879 switch (type->type) {
880 case DW_TAG_unspecified_type:
883 case DW_TAG_base_type:
884 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
885 if (real_area1 == real_area2)
888 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
890 if (area_size != -1 && type->byte_size != area_size)
893 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
897 case DW_TAG_enumeration_type:
898 if (area_size != -1 && type->byte_size != area_size)
901 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
904 case DW_TAG_const_type:
905 case DW_TAG_volatile_type:
907 type = type->subtype;
910 case DW_TAG_array_type:
911 subtype = type->subtype;
912 switch (subtype->type) {
913 case DW_TAG_unspecified_type:
916 case DW_TAG_base_type:
917 case DW_TAG_enumeration_type:
918 case DW_TAG_pointer_type:
919 case DW_TAG_reference_type:
920 case DW_TAG_rvalue_reference_type:
921 case DW_TAG_structure_type:
922 case DW_TAG_class_type:
923 case DW_TAG_union_type:
924 if (subtype->full_type)
925 subtype = subtype->full_type;
926 elm_size = subtype->byte_size;
928 // TODO, just remove the type indirection?
929 case DW_TAG_const_type:
931 case DW_TAG_volatile_type:
932 subsubtype = subtype->subtype;
933 if (subsubtype->full_type)
934 subsubtype = subsubtype->full_type;
935 elm_size = subsubtype->byte_size;
941 for (i = 0; i < type->element_count; i++) {
942 // TODO, add support for variable stride (DW_AT_byte_stride)
944 compare_heap_area_with_type(state,
945 (char *) real_area1 + (i * elm_size),
946 (char *) real_area2 + (i * elm_size),
947 snapshot1, snapshot2, previous,
948 type->subtype, subtype->byte_size,
949 check_ignore, pointer_level);
954 case DW_TAG_reference_type:
955 case DW_TAG_rvalue_reference_type:
956 case DW_TAG_pointer_type:
957 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
958 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1);
959 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2);
960 return (addr_pointed1 != addr_pointed2);;
963 if (pointer_level > 1) { /* Array of pointers */
964 for (i = 0; i < (area_size / sizeof(void *)); i++) {
965 addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1);
966 addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2);
967 if (addr_pointed1 > state->s_heap
968 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
969 && addr_pointed2 > state->s_heap
970 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
972 compare_heap_area(addr_pointed1, addr_pointed2, snapshot1,
973 snapshot2, previous, type->subtype,
976 res = (addr_pointed1 != addr_pointed2);
981 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1);
982 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2);
983 if (addr_pointed1 > state->s_heap
984 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
985 && addr_pointed2 > state->s_heap
986 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
987 return compare_heap_area(addr_pointed1, addr_pointed2, snapshot1,
988 snapshot2, previous, type->subtype,
991 return (addr_pointed1 != addr_pointed2);
995 case DW_TAG_structure_type:
996 case DW_TAG_class_type:
998 type = type->full_type;
999 if (area_size != -1 && type->byte_size != area_size) {
1000 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1001 for (i = 0; i < (area_size / type->byte_size); i++) {
1003 compare_heap_area_with_type(state,
1004 (char *) real_area1 + i * type->byte_size,
1005 (char *) real_area2 + i * type->byte_size,
1006 snapshot1, snapshot2, previous, type, -1,
1016 xbt_dynar_foreach(type->members, cursor, member) {
1017 // TODO, optimize this? (for the offset case)
1018 char *real_member1 =
1019 mc_member_resolve(real_area1, type, member, snapshot1);
1020 char *real_member2 =
1021 mc_member_resolve(real_area2, type, member, snapshot2);
1023 compare_heap_area_with_type(state, real_member1, real_member2,
1024 snapshot1, snapshot2,
1025 previous, member->subtype, -1,
1033 case DW_TAG_union_type:
1034 return compare_heap_area_without_type(state, real_area1, real_area2,
1035 snapshot1, snapshot2, previous,
1036 type->byte_size, check_ignore);
1046 /** Infer the type of a part of the block from the type of the block
1048 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1050 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1052 * @param type_id DWARF type ID of the root address
1054 * @return DWARF type ID for given offset
1056 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1057 int offset, int area_size,
1058 mc_snapshot_t snapshot)
1061 // Beginning of the block, the infered variable type if the type of the block:
1065 switch (type->type) {
1066 case DW_TAG_structure_type:
1067 case DW_TAG_class_type:
1068 if (type->full_type)
1069 type = type->full_type;
1071 if (area_size != -1 && type->byte_size != area_size) {
1072 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1077 unsigned int cursor = 0;
1079 xbt_dynar_foreach(type->members, cursor, member) {
1081 if (!member->location.size) {
1082 // We have the offset, use it directly (shortcut):
1083 if (member->offset == offset)
1084 return member->subtype;
1087 mc_member_resolve(real_base_address, type, member, snapshot);
1088 if (real_member - (char *) real_base_address == offset)
1089 return member->subtype;
1097 /* FIXME : other cases ? */
1105 * @param area1 Process address for state 1
1106 * @param area2 Process address for state 2
1107 * @param snapshot1 Snapshot of state 1
1108 * @param snapshot2 Snapshot of state 2
1109 * @param previous Pairs of blocks already compared on the current path (or NULL)
1110 * @param type_id Type of variable
1111 * @param pointer_level
1112 * @return 0 (same), 1 (different), -1
1114 int compare_heap_area(void *area1, void *area2, mc_snapshot_t snapshot1,
1115 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1116 dw_type_t type, int pointer_level)
1119 struct s_mc_diff *state = mc_diff_info;
1122 ssize_t block1, frag1, block2, frag2;
1124 int check_ignore = 0;
1126 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1128 int offset1 = 0, offset2 = 0;
1129 int new_size1 = -1, new_size2 = -1;
1130 dw_type_t new_type1 = NULL, new_type2 = NULL;
1132 int match_pairs = 0;
1134 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot1);
1135 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot2);
1137 malloc_info heapinfo_temp1, heapinfo_temp2;
1139 void* real_area1_to_compare = area1;
1140 void* real_area2_to_compare = area2;
1142 if (previous == NULL) {
1144 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1147 // Get block number:
1150 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1153 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1155 // If either block is a stack block:
1156 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1157 add_heap_area_pair(previous, block1, -1, block2, -1);
1159 match_equals(state, previous);
1160 xbt_dynar_free(&previous);
1164 // If either block is not in the expected area of memory:
1165 if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1166 || (block1 > state->heapsize1) || (block1 < 1)
1167 || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1168 || (block2 > state->heapsize2) || (block2 < 1)) {
1170 xbt_dynar_free(&previous);
1175 // Process address of the block:
1177 ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
1178 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1180 ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
1181 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1185 if (type->full_type)
1186 type = type->full_type;
1188 // This assume that for "boring" types (volatile ...) byte_size is absent:
1189 while (type->byte_size == 0 && type->subtype != NULL)
1190 type = type->subtype;
1193 if ((type->type == DW_TAG_pointer_type)
1194 || ((type->type == DW_TAG_base_type) && type->name != NULL
1195 && (!strcmp(type->name, "char"))))
1198 type_size = type->byte_size;
1202 mc_mem_region_t heap_region1 = snapshot1->regions[0];
1203 mc_mem_region_t heap_region2 = snapshot2->regions[0];
1205 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
1206 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
1208 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1209 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1213 match_equals(state, previous);
1214 xbt_dynar_free(&previous);
1218 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1219 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1220 /* Complete block */
1222 // TODO, lookup variable type from block type as done for fragmented blocks
1224 offset1 = (char *) area1 - (char *) real_addr_block1;
1225 offset2 = (char *) area2 - (char *) real_addr_block2;
1227 if (state->equals_to1_(block1, 0).valid
1228 && state->equals_to2_(block2, 0).valid) {
1229 if (equal_blocks(state, block1, block2)) {
1231 match_equals(state, previous);
1232 xbt_dynar_free(&previous);
1238 if (type_size != -1) {
1239 if (type_size != heapinfo1->busy_block.busy_size
1240 && type_size != heapinfo2->busy_block.busy_size
1241 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1243 match_equals(state, previous);
1244 xbt_dynar_free(&previous);
1250 if (heapinfo1->busy_block.size !=
1251 heapinfo2->busy_block.size) {
1253 xbt_dynar_free(&previous);
1258 if (heapinfo1->busy_block.busy_size !=
1259 heapinfo2->busy_block.busy_size) {
1261 xbt_dynar_free(&previous);
1266 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1268 match_equals(state, previous);
1269 xbt_dynar_free(&previous);
1274 size = heapinfo1->busy_block.busy_size;
1276 // Remember (basic) type inference.
1277 // The current data structure only allows us to do this for the whole block.
1278 if (type != NULL && area1 == real_addr_block1) {
1279 state->types1_(block1, 0) = type;
1281 if (type != NULL && area2 == real_addr_block2) {
1282 state->types2_(block2, 0) = type;
1287 match_equals(state, previous);
1288 xbt_dynar_free(&previous);
1296 if ((heapinfo1->busy_block.ignore > 0)
1297 && (heapinfo2->busy_block.ignore ==
1298 heapinfo1->busy_block.ignore))
1299 check_ignore = heapinfo1->busy_block.ignore;
1301 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1305 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1307 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1309 // Process address of the fragment:
1311 (void *) ((char *) real_addr_block1 +
1312 (frag1 << heapinfo1->type));
1314 (void *) ((char *) real_addr_block2 +
1315 (frag2 << heapinfo2->type));
1317 // Check the size of the fragments against the size of the type:
1318 if (type_size != -1) {
1319 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1320 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1322 match_equals(state, previous);
1323 xbt_dynar_free(&previous);
1328 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1329 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1331 match_equals(state, previous);
1332 xbt_dynar_free(&previous);
1338 // Check if the blocks are already matched together:
1339 if (state->equals_to1_(block1, frag1).valid
1340 && state->equals_to2_(block2, frag2).valid) {
1341 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1343 match_equals(state, previous);
1344 xbt_dynar_free(&previous);
1349 // Compare the size of both fragments:
1350 if (heapinfo1->busy_frag.frag_size[frag1] !=
1351 heapinfo2->busy_frag.frag_size[frag2]) {
1352 if (type_size == -1) {
1354 match_equals(state, previous);
1355 xbt_dynar_free(&previous);
1360 xbt_dynar_free(&previous);
1366 // Size of the fragment:
1367 size = heapinfo1->busy_frag.frag_size[frag1];
1369 // Remember (basic) type inference.
1370 // The current data structure only allows us to do this for the whole fragment.
1371 if (type != NULL && area1 == real_addr_frag1) {
1372 state->types1_(block1, frag1) = type;
1374 if (type != NULL && area2 == real_addr_frag2) {
1375 state->types2_(block2, frag2) = type;
1377 // The type of the variable is already known:
1382 // Type inference from the block type.
1383 else if (state->types1_(block1, frag1) != NULL
1384 || state->types2_(block2, frag2) != NULL) {
1386 offset1 = (char *) area1 - (char *) real_addr_frag1;
1387 offset2 = (char *) area2 - (char *) real_addr_frag2;
1389 if (state->types1_(block1, frag1) != NULL
1390 && state->types2_(block2, frag2) != NULL) {
1392 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1393 offset1, size, snapshot1);
1395 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1396 offset1, size, snapshot2);
1397 } else if (state->types1_(block1, frag1) != NULL) {
1399 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1400 offset1, size, snapshot1);
1402 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1403 offset2, size, snapshot2);
1404 } else if (state->types2_(block2, frag2) != NULL) {
1406 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1407 offset1, size, snapshot1);
1409 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1410 offset2, size, snapshot2);
1413 match_equals(state, previous);
1414 xbt_dynar_free(&previous);
1419 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1422 while (type->byte_size == 0 && type->subtype != NULL)
1423 type = type->subtype;
1424 new_size1 = type->byte_size;
1427 while (type->byte_size == 0 && type->subtype != NULL)
1428 type = type->subtype;
1429 new_size2 = type->byte_size;
1433 match_equals(state, previous);
1434 xbt_dynar_free(&previous);
1440 if (new_size1 > 0 && new_size1 == new_size2) {
1445 if (offset1 == 0 && offset2 == 0) {
1446 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1448 match_equals(state, previous);
1449 xbt_dynar_free(&previous);
1457 match_equals(state, previous);
1458 xbt_dynar_free(&previous);
1463 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1464 && (heapinfo2->busy_frag.ignore[frag2] ==
1465 heapinfo1->busy_frag.ignore[frag1]))
1466 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1471 xbt_dynar_free(&previous);
1478 /* Start comparison */
1481 compare_heap_area_with_type(state, real_area1_to_compare, real_area2_to_compare, snapshot1, snapshot2,
1482 previous, type, size, check_ignore,
1486 compare_heap_area_without_type(state, real_area1_to_compare, real_area2_to_compare, snapshot1, snapshot2,
1487 previous, size, check_ignore);
1489 if (res_compare == 1) {
1491 xbt_dynar_free(&previous);
1496 match_equals(state, previous);
1497 xbt_dynar_free(&previous);
1503 /*********************************************** Miscellaneous ***************************************************/
1504 /****************************************************************************************************************/
1506 // Not used and broken code:
1510 static int get_pointed_area_size(void *area, int heap)
1513 struct s_mc_diff *state = mc_diff_info;
1516 malloc_info *heapinfo;
1519 heapinfo = state->heapinfo1;
1521 heapinfo = state->heapinfo2;
1525 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1527 if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1528 || (block > state->heapsize1) || (block < 1))
1531 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1533 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1534 return (int) heapinfo[block].busy_block.busy_size;
1537 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1538 return (int) heapinfo[block].busy_frag.frag_size[frag];
1543 char *get_type_description(mc_object_info_t info, char *type_name)
1546 xbt_dict_cursor_t dict_cursor;
1550 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1551 if (type->name && (strcmp(type->name, type_name) == 0)
1552 && type->byte_size > 0) {
1553 xbt_dict_cursor_free(&dict_cursor);
1558 xbt_dict_cursor_free(&dict_cursor);
1564 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1568 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1571 struct s_mc_diff *state = mc_diff_info;
1573 if (heap1 == NULL && heap1 == NULL) {
1574 XBT_DEBUG("Malloc descriptors null");
1578 if (heap1->heaplimit != heap2->heaplimit) {
1579 XBT_DEBUG("Different limit of valid info table indices");
1583 /* Heap information */
1584 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1587 // Mamailloute in order to find the base address of the main heap:
1589 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1591 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1592 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1595 (malloc_info *) ((char *) heap1 +
1597 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1599 (malloc_info *) ((char *) heap2 +
1601 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1603 state->heapsize1 = heap1->heapsize;
1604 state->heapsize2 = heap2->heapsize;
1606 /* Start comparison */
1608 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1612 /* Check busy blocks */
1616 while (i <= state->heaplimit) {
1619 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1620 (char *) state->heapbase1));
1622 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1623 (char *) state->heapbase2));
1625 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1627 distance += BLOCKSIZE;
1628 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1629 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1634 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1635 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1640 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1642 if (state->heapinfo1[i].busy_block.size !=
1643 state->heapinfo2[i].busy_block.size) {
1645 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1646 state->heapinfo2[i].busy_block.size);
1647 i += max(state->heapinfo1[i].busy_block.size,
1648 state->heapinfo2[i].busy_block.size);
1650 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1651 i, state->heapinfo1[i].busy_block.size,
1652 state->heapinfo2[i].busy_block.size, distance);
1656 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1657 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1658 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1659 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);
1665 //while(k < (heapinfo1[i].busy_block.busy_size)){
1666 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1667 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1676 } else { /* Fragmented block */
1678 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1681 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1683 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1685 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1686 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1691 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1692 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1693 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);
1699 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1700 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1701 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=