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 -1 : /\* Free block *\/ */
94 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
97 /* case 0: /\* Large block *\/ */
98 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
100 /* default: /\* Fragmented block *\/ */
101 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
102 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
103 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
106 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
112 static int compare_backtrace(int b1, int f1, int b2, int f2)
116 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
117 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
118 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
119 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
124 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
125 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
126 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
127 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
136 /*********************************** Heap comparison ***********************************/
137 /***************************************************************************************/
139 typedef char *type_name;
142 /** \brief Base address of the real heap */
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)
168 static void heap_area_pair_free_voidp(void *d)
170 heap_area_pair_free((heap_area_pair_t) * (void **) d);
173 static void heap_area_free(heap_area_t area)
179 /************************************************************************************/
181 static s_heap_area_t make_heap_area(int block, int fragment)
186 area.fragment = fragment;
191 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
192 int block2, int fragment2)
195 unsigned int cursor = 0;
196 heap_area_pair_t current_pair;
198 xbt_dynar_foreach(list, cursor, current_pair) {
199 if (current_pair->block1 == block1 && current_pair->block2 == block2
200 && current_pair->fragment1 == fragment1
201 && current_pair->fragment2 == fragment2)
208 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
209 int block2, int fragment2)
212 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
213 heap_area_pair_t pair = NULL;
214 pair = xbt_new0(s_heap_area_pair_t, 1);
215 pair->block1 = block1;
216 pair->fragment1 = fragment1;
217 pair->block2 = block2;
218 pair->fragment2 = fragment2;
220 xbt_dynar_push(list, &pair);
228 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
232 unsigned int cursor = 0;
234 int end = xbt_dynar_length(ignore_list) - 1;
235 mc_heap_ignore_region_t region;
237 while (start <= end) {
238 cursor = (start + end) / 2;
240 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
241 mc_heap_ignore_region_t);
242 if (region->address == address)
244 if (region->address < address)
246 if (region->address > address)
253 static int is_stack(void *address)
255 unsigned int cursor = 0;
256 stack_region_t stack;
258 xbt_dynar_foreach(stacks_areas, cursor, stack) {
259 if (address == stack->address)
266 // TODO, this should depend on the snapshot?
267 static int is_block_stack(int block)
269 unsigned int cursor = 0;
270 stack_region_t stack;
272 xbt_dynar_foreach(stacks_areas, cursor, stack) {
273 if (block == stack->block)
280 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
283 unsigned int cursor = 0;
284 heap_area_pair_t current_pair;
286 xbt_dynar_foreach(list, cursor, current_pair) {
288 if (current_pair->fragment1 != -1) {
290 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
291 make_heap_area(current_pair->block2, current_pair->fragment2);
292 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
293 make_heap_area(current_pair->block1, current_pair->fragment1);
297 state->equals_to1_(current_pair->block1, 0) =
298 make_heap_area(current_pair->block2, current_pair->fragment2);
299 state->equals_to2_(current_pair->block2, 0) =
300 make_heap_area(current_pair->block1, current_pair->fragment1);
307 /** Check whether two blocks are known to be matching
309 * @param state State used
310 * @param b1 Block of state 1
311 * @param b2 Block of state 2
312 * @return if the blocks are known to be matching
314 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
317 if (state->equals_to1_(b1, 0).block == b2
318 && state->equals_to2_(b2, 0).block == b1)
324 /** Check whether two fragments are known to be matching
326 * @param state State used
327 * @param b1 Block of state 1
328 * @param f1 Fragment of state 1
329 * @param b2 Block of state 2
330 * @param f2 Fragment of state 2
331 * @return if the fragments are known to be matching
333 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
337 if (state->equals_to1_(b1, f1).block == b2
338 && state->equals_to1_(b1, f1).fragment == f2
339 && state->equals_to2_(b2, f2).block == b1
340 && state->equals_to2_(b2, f2).fragment == f1)
346 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
349 if (mc_diff_info == NULL) {
350 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
351 mc_diff_info->equals_to1 = NULL;
352 mc_diff_info->equals_to2 = NULL;
353 mc_diff_info->types1 = NULL;
354 mc_diff_info->types2 = NULL;
356 struct s_mc_diff *state = mc_diff_info;
358 if ((((struct mdesc *) heap1)->heaplimit !=
359 ((struct mdesc *) heap2)->heaplimit)
361 ((((struct mdesc *) heap1)->heapsize !=
362 ((struct mdesc *) heap2)->heapsize)))
365 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
367 // Mamailloute in order to find the base address of the main heap:
369 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
371 state->heapsize1 = heap1->heapsize;
372 state->heapsize2 = heap2->heapsize;
374 state->to_ignore1 = i1;
375 state->to_ignore2 = i2;
377 if (state->heaplimit > state->available) {
379 realloc(state->equals_to1,
380 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
381 sizeof(s_heap_area_t));
383 realloc(state->types1,
384 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
385 sizeof(type_name *));
387 realloc(state->equals_to2,
388 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
389 sizeof(s_heap_area_t));
391 realloc(state->types2,
392 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
393 sizeof(type_name *));
394 state->available = state->heaplimit;
397 memset(state->equals_to1, 0,
398 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
399 memset(state->equals_to2, 0,
400 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
401 memset(state->types1, 0,
402 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
403 memset(state->types2, 0,
404 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
410 void reset_heap_information()
415 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
418 struct s_mc_diff *state = mc_diff_info;
420 /* Start comparison */
421 size_t i1, i2, j1, j2, k;
422 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
423 int nb_diff1 = 0, nb_diff2 = 0;
425 xbt_dynar_t previous =
426 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
428 int equal, res_compare = 0;
430 /* Check busy blocks */
434 malloc_info heapinfo_temp1, heapinfo_temp2;
435 malloc_info heapinfo_temp2b;
437 mc_mem_region_t heap_region1 = snapshot1->regions[0];
438 mc_mem_region_t heap_region2 = snapshot2->regions[0];
440 // This is in snapshot do not use them directly:
441 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot1);
442 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot2);
444 while (i1 <= state->heaplimit) {
446 // TODO, lookup in the correct region in order to speed it up:
447 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
448 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i1], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
450 if (heapinfo1->type == -1) { /* Free block */
456 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
457 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
459 if (heapinfo1->type == 0) { /* Large block */
461 if (is_stack(addr_block1)) {
462 for (k = 0; k < heapinfo1->busy_block.size; k++)
463 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
464 for (k = 0; k < heapinfo2->busy_block.size; k++)
465 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
466 i1 += heapinfo1->busy_block.size;
470 if (state->equals_to1_(i1, 0).valid) {
479 /* Try first to associate to same block in the other heap */
480 if (heapinfo2->type == heapinfo1->type) {
482 if (state->equals_to2_(i1, 0).valid == 0) {
485 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
486 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
489 compare_heap_area(addr_block1, addr_block2, snapshot1, snapshot2,
492 if (res_compare != 1) {
493 for (k = 1; k < heapinfo2->busy_block.size; k++)
494 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
495 for (k = 1; k < heapinfo1->busy_block.size; k++)
496 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
498 i1 += heapinfo1->busy_block.size;
501 xbt_dynar_reset(previous);
507 while (i2 <= state->heaplimit && !equal) {
510 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
511 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
518 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
520 if (heapinfo2b->type != 0) {
525 if (state->equals_to2_(i2, 0).valid) {
531 compare_heap_area(addr_block1, addr_block2, snapshot1, snapshot2,
534 if (res_compare != 1) {
535 for (k = 1; k < heapinfo2b->busy_block.size; k++)
536 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
537 for (k = 1; k < heapinfo1->busy_block.size; k++)
538 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
540 i1 += heapinfo1->busy_block.size;
543 xbt_dynar_reset(previous);
550 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
551 heapinfo1->busy_block.busy_size, addr_block1);
552 i1 = state->heaplimit + 1;
557 } else { /* Fragmented block */
559 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
561 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
564 if (state->equals_to1_(i1, j1).valid)
568 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
573 /* Try first to associate to same fragment in the other heap */
574 if (heapinfo2->type == heapinfo1->type) {
576 if (state->equals_to2_(i1, j1).valid == 0) {
579 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
580 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
582 (void *) ((char *) addr_block2 +
583 (j1 << ((xbt_mheap_t) state->s_heap)->heapinfo[i1].
587 compare_heap_area(addr_frag1, addr_frag2, snapshot1, snapshot2,
590 if (res_compare != 1)
593 xbt_dynar_reset(previous);
599 while (i2 <= state->heaplimit && !equal) {
601 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
602 if (heapinfo2b->type <= 0) {
607 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
610 if (i2 == i1 && j2 == j1)
613 if (state->equals_to2_(i2, j2).valid)
617 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
618 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
620 (void *) ((char *) addr_block2 +
621 (j2 << ((xbt_mheap_t) state->s_heap)->heapinfo[i2].
625 compare_heap_area(addr_frag1, addr_frag2, snapshot2, snapshot2,
628 if (res_compare != 1) {
630 xbt_dynar_reset(previous);
634 xbt_dynar_reset(previous);
644 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
645 i1, j1, heapinfo1->busy_frag.frag_size[j1],
647 i2 = state->heaplimit + 1;
648 i1 = state->heaplimit + 1;
661 /* All blocks/fragments are equal to another block/fragment ? */
664 for(i = 1; i <= state->heaplimit; i++) {
665 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
666 if (heapinfo1->type == 0) {
667 if (i1 == state->heaplimit) {
668 if (heapinfo1->busy_block.busy_size > 0) {
669 if (state->equals_to1_(i, 0).valid == 0) {
670 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
672 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
673 heapinfo1->busy_block.busy_size);
674 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
681 if (heapinfo1->type > 0) {
682 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
683 if (i1 == state->heaplimit) {
684 if (heapinfo1->busy_frag.frag_size[j] > 0) {
685 if (state->equals_to1_(i, j).valid == 0) {
686 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
687 // TODO, print fragment address
689 ("Block %zu, Fragment %zu not found (size used = %zd)",
691 heapinfo1->busy_frag.frag_size[j]);
692 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
702 if (i1 == state->heaplimit)
703 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
705 for (i=1; i <= state->heaplimit; i++) {
706 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
707 if (heapinfo2->type == 0) {
708 if (i1 == state->heaplimit) {
709 if (heapinfo2->busy_block.busy_size > 0) {
710 if (state->equals_to2_(i, 0).valid == 0) {
711 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
712 // TODO, print address of the block
713 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
714 heapinfo2->busy_block.busy_size);
715 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
722 if (heapinfo2->type > 0) {
723 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
724 if (i1 == state->heaplimit) {
725 if (heapinfo2->busy_frag.frag_size[j] > 0) {
726 if (state->equals_to2_(i, j).valid == 0) {
727 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
728 // TODO, print address of the block
730 ("Block %zu, Fragment %zu not found (size used = %zd)",
732 heapinfo2->busy_frag.frag_size[j]);
733 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
743 if (i1 == state->heaplimit)
744 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
746 xbt_dynar_free(&previous);
747 return ((nb_diff1 > 0) || (nb_diff2 > 0));
753 * @param real_area1 Process address for state 1
754 * @param real_area2 Process address for state 2
755 * @param snapshot1 Snapshot of state 1
756 * @param snapshot2 Snapshot of state 2
759 * @param check_ignore
761 static int compare_heap_area_without_type(struct s_mc_diff *state,
762 void *real_area1, void *real_area2,
763 mc_snapshot_t snapshot1,
764 mc_snapshot_t snapshot2,
765 xbt_dynar_t previous, int size,
770 void *addr_pointed1, *addr_pointed2;
771 int pointer_align, res_compare;
772 ssize_t ignore1, ignore2;
774 mc_mem_region_t heap_region1 = snapshot1->regions[0];
775 mc_mem_region_t heap_region2 = snapshot2->regions[0];
779 if (check_ignore > 0) {
781 heap_comparison_ignore_size(state->to_ignore1,
782 (char *) real_area1 + i)) != -1) {
784 heap_comparison_ignore_size(state->to_ignore2,
785 (char *) real_area2 + i)) == ignore1) {
798 if (mc_snapshot_region_memcp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
800 pointer_align = (i / sizeof(void *)) * sizeof(void *);
801 addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1);
802 addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2);
804 if (addr_pointed1 > maestro_stack_start
805 && addr_pointed1 < maestro_stack_end
806 && addr_pointed2 > maestro_stack_start
807 && addr_pointed2 < maestro_stack_end) {
808 i = pointer_align + sizeof(void *);
810 } else if (addr_pointed1 > state->s_heap
811 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
812 && addr_pointed2 > state->s_heap
813 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
814 // Both addreses are in the heap:
816 compare_heap_area(addr_pointed1, addr_pointed2, snapshot1,
817 snapshot2, previous, NULL, 0);
818 if (res_compare == 1) {
821 i = pointer_align + sizeof(void *);
840 * @param real_area1 Process address for state 1
841 * @param real_area2 Process address for state 2
842 * @param snapshot1 Snapshot of state 1
843 * @param snapshot2 Snapshot of state 2
846 * @param area_size either a byte_size or an elements_count (?)
847 * @param check_ignore
848 * @param pointer_level
849 * @return 0 (same), 1 (different), -1 (unknown)
851 static int compare_heap_area_with_type(struct s_mc_diff *state,
852 void *real_area1, void *real_area2,
853 mc_snapshot_t snapshot1,
854 mc_snapshot_t snapshot2,
855 xbt_dynar_t previous, dw_type_t type,
856 int area_size, int check_ignore,
860 if (is_stack(real_area1) && is_stack(real_area2))
863 ssize_t ignore1, ignore2;
865 if ((check_ignore > 0)
866 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
868 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
873 dw_type_t subtype, subsubtype;
874 int res, elm_size, i;
875 unsigned int cursor = 0;
877 void *addr_pointed1, *addr_pointed2;;
879 mc_mem_region_t heap_region1 = snapshot1->regions[0];
880 mc_mem_region_t heap_region2 = snapshot2->regions[0];
882 switch (type->type) {
883 case DW_TAG_unspecified_type:
886 case DW_TAG_base_type:
887 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
888 if (real_area1 == real_area2)
891 return (mc_snapshot_region_memcp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
893 if (area_size != -1 && type->byte_size != area_size)
896 return (mc_snapshot_region_memcp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
900 case DW_TAG_enumeration_type:
901 if (area_size != -1 && type->byte_size != area_size)
904 return (mc_snapshot_region_memcp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
907 case DW_TAG_const_type:
908 case DW_TAG_volatile_type:
909 return compare_heap_area_with_type(state, real_area1, real_area2,
910 snapshot1, snapshot2, previous,
911 type->subtype, area_size, check_ignore,
914 case DW_TAG_array_type:
915 subtype = type->subtype;
916 switch (subtype->type) {
917 case DW_TAG_unspecified_type:
920 case DW_TAG_base_type:
921 case DW_TAG_enumeration_type:
922 case DW_TAG_pointer_type:
923 case DW_TAG_reference_type:
924 case DW_TAG_rvalue_reference_type:
925 case DW_TAG_structure_type:
926 case DW_TAG_class_type:
927 case DW_TAG_union_type:
928 if (subtype->full_type)
929 subtype = subtype->full_type;
930 elm_size = subtype->byte_size;
932 // TODO, just remove the type indirection?
933 case DW_TAG_const_type:
935 case DW_TAG_volatile_type:
936 subsubtype = subtype->subtype;
937 if (subsubtype->full_type)
938 subsubtype = subsubtype->full_type;
939 elm_size = subsubtype->byte_size;
945 for (i = 0; i < type->element_count; i++) {
946 // TODO, add support for variable stride (DW_AT_byte_stride)
948 compare_heap_area_with_type(state,
949 (char *) real_area1 + (i * elm_size),
950 (char *) real_area2 + (i * elm_size),
951 snapshot1, snapshot2, previous,
952 type->subtype, subtype->byte_size,
953 check_ignore, pointer_level);
958 case DW_TAG_reference_type:
959 case DW_TAG_rvalue_reference_type:
960 case DW_TAG_pointer_type:
961 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
962 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1);
963 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2);
964 return (addr_pointed1 != addr_pointed2);;
967 if (pointer_level > 1) { /* Array of pointers */
968 for (i = 0; i < (area_size / sizeof(void *)); i++) {
969 addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1);
970 addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2);
971 if (addr_pointed1 > state->s_heap
972 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
973 && addr_pointed2 > state->s_heap
974 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
976 compare_heap_area(addr_pointed1, addr_pointed2, snapshot1,
977 snapshot2, previous, type->subtype,
980 res = (addr_pointed1 != addr_pointed2);
985 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1);
986 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2);
987 if (addr_pointed1 > state->s_heap
988 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
989 && addr_pointed2 > state->s_heap
990 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
991 return compare_heap_area(addr_pointed1, addr_pointed2, snapshot1,
992 snapshot2, previous, type->subtype,
995 return (addr_pointed1 != addr_pointed2);
999 case DW_TAG_structure_type:
1000 case DW_TAG_class_type:
1001 if (type->full_type)
1002 type = type->full_type;
1003 if (area_size != -1 && type->byte_size != area_size) {
1004 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1005 for (i = 0; i < (area_size / type->byte_size); i++) {
1007 compare_heap_area_with_type(state,
1008 (char *) real_area1 + i * type->byte_size,
1009 (char *) real_area2 + i * type->byte_size,
1010 snapshot1, snapshot2, previous, type, -1,
1020 xbt_dynar_foreach(type->members, cursor, member) {
1021 // TODO, optimize this? (for the offset case)
1022 char *real_member1 =
1023 mc_member_resolve(real_area1, type, member, snapshot1);
1024 char *real_member2 =
1025 mc_member_resolve(real_area2, type, member, snapshot2);
1027 compare_heap_area_with_type(state, real_member1, real_member2,
1028 snapshot1, snapshot2,
1029 previous, member->subtype, -1,
1037 case DW_TAG_union_type:
1038 return compare_heap_area_without_type(state, real_area1, real_area2,
1039 snapshot1, snapshot2, previous,
1040 type->byte_size, check_ignore);
1050 /** Infer the type of a part of the block from the type of the block
1052 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1054 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1056 * @param type_id DWARF type ID of the root address
1058 * @return DWARF type ID for given offset
1060 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1061 int offset, int area_size,
1062 mc_snapshot_t snapshot)
1065 // Beginning of the block, the infered variable type if the type of the block:
1069 switch (type->type) {
1070 case DW_TAG_structure_type:
1071 case DW_TAG_class_type:
1072 if (type->full_type)
1073 type = type->full_type;
1075 if (area_size != -1 && type->byte_size != area_size) {
1076 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1081 unsigned int cursor = 0;
1083 xbt_dynar_foreach(type->members, cursor, member) {
1085 if (!member->location.size) {
1086 // We have the offset, use it directly (shortcut):
1087 if (member->offset == offset)
1088 return member->subtype;
1091 mc_member_resolve(real_base_address, type, member, snapshot);
1092 if (real_member - (char *) real_base_address == offset)
1093 return member->subtype;
1101 /* FIXME : other cases ? */
1109 * @param area1 Process address for state 1
1110 * @param area2 Process address for state 2
1111 * @param snapshot1 Snapshot of state 1
1112 * @param snapshot2 Snapshot of state 2
1113 * @param previous Pairs of blocks already compared on the current path (or NULL)
1114 * @param type_id Type of variable
1115 * @param pointer_level
1116 * @return 0 (same), 1 (different), -1
1118 int compare_heap_area(void *area1, void *area2, mc_snapshot_t snapshot1,
1119 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1120 dw_type_t type, int pointer_level)
1123 struct s_mc_diff *state = mc_diff_info;
1126 ssize_t block1, frag1, block2, frag2;
1128 int check_ignore = 0;
1130 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1133 int offset1 = 0, offset2 = 0;
1134 int new_size1 = -1, new_size2 = -1;
1135 dw_type_t new_type1 = NULL, new_type2 = NULL;
1137 int match_pairs = 0;
1139 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot1);
1140 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot2);
1142 malloc_info heapinfo_temp1, heapinfo_temp2;
1144 if (previous == NULL) {
1146 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1149 // Get block number:
1152 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1155 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1157 // If either block is a stack block:
1158 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1159 add_heap_area_pair(previous, block1, -1, block2, -1);
1161 match_equals(state, previous);
1162 xbt_dynar_free(&previous);
1166 // If either block is not in the expected area of memory:
1167 if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1168 || (block1 > state->heapsize1) || (block1 < 1)
1169 || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1170 || (block2 > state->heapsize2) || (block2 < 1)) {
1172 xbt_dynar_free(&previous);
1177 // Process address of the block:
1179 ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
1180 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1182 ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
1183 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1187 if (type->full_type)
1188 type = type->full_type;
1190 // This assume that for "boring" types (volatile ...) byte_size is absent:
1191 while (type->byte_size == 0 && type->subtype != NULL)
1192 type = type->subtype;
1195 if ((type->type == DW_TAG_pointer_type)
1196 || ((type->type == DW_TAG_base_type) && type->name != NULL
1197 && (!strcmp(type->name, "char"))))
1200 type_size = type->byte_size;
1204 mc_mem_region_t heap_region1 = snapshot1->regions[0];
1205 mc_mem_region_t heap_region2 = snapshot2->regions[0];
1207 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
1208 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
1210 if ((heapinfo1->type == -1) && (heapinfo2->type == -1)) { /* Free block */
1213 match_equals(state, previous);
1214 xbt_dynar_free(&previous);
1218 } else if ((heapinfo1->type == 0) && (heapinfo2->type == 0)) { /* Complete block */
1220 // TODO, lookup variable type from block type as done for fragmented blocks
1222 if (state->equals_to1_(block1, 0).valid
1223 && state->equals_to2_(block2, 0).valid) {
1224 if (equal_blocks(state, block1, block2)) {
1226 match_equals(state, previous);
1227 xbt_dynar_free(&previous);
1233 if (type_size != -1) {
1234 if (type_size != heapinfo1->busy_block.busy_size
1235 && type_size != heapinfo2->busy_block.busy_size
1236 && type->name != NULL && !strcmp(type->name, "s_smx_context")) {
1238 match_equals(state, previous);
1239 xbt_dynar_free(&previous);
1245 if (heapinfo1->busy_block.size !=
1246 heapinfo2->busy_block.size) {
1248 xbt_dynar_free(&previous);
1253 if (heapinfo1->busy_block.busy_size !=
1254 heapinfo2->busy_block.busy_size) {
1256 xbt_dynar_free(&previous);
1261 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1263 match_equals(state, previous);
1264 xbt_dynar_free(&previous);
1269 size = heapinfo1->busy_block.busy_size;
1271 // Remember (basic) type inference.
1272 // The current data structure only allows us to do this for the whole block.
1273 if (type != NULL && area1 == real_addr_block1) {
1274 state->types1_(block1, 0) = type;
1276 if (type != NULL && area2 == real_addr_block2) {
1277 state->types2_(block2, 0) = type;
1282 match_equals(state, previous);
1283 xbt_dynar_free(&previous);
1291 if ((heapinfo1->busy_block.ignore > 0)
1292 && (heapinfo2->busy_block.ignore ==
1293 heapinfo1->busy_block.ignore))
1294 check_ignore = heapinfo1->busy_block.ignore;
1296 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1300 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1302 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1304 // Process address of the fragment:
1306 (void *) ((char *) real_addr_block1 +
1307 (frag1 << ((xbt_mheap_t) state->s_heap)->heapinfo[block1].
1310 (void *) ((char *) real_addr_block2 +
1311 (frag2 << ((xbt_mheap_t) state->s_heap)->heapinfo[block2].
1314 // Check the size of the fragments against the size of the type:
1315 if (type_size != -1) {
1316 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1317 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1319 match_equals(state, previous);
1320 xbt_dynar_free(&previous);
1324 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1325 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1327 match_equals(state, previous);
1328 xbt_dynar_free(&previous);
1333 // Check if the blocks are already matched together:
1334 if (state->equals_to1_(block1, frag1).valid
1335 && state->equals_to2_(block2, frag2).valid) {
1336 if (equal_fragments(state, block1, frag1, block2, frag2)) {
1338 match_equals(state, previous);
1339 xbt_dynar_free(&previous);
1344 // Compare the size of both fragments:
1345 if (heapinfo1->busy_frag.frag_size[frag1] !=
1346 heapinfo2->busy_frag.frag_size[frag2]) {
1347 if (type_size == -1) {
1349 match_equals(state, previous);
1350 xbt_dynar_free(&previous);
1355 xbt_dynar_free(&previous);
1360 // Size of the fragment:
1361 size = heapinfo1->busy_frag.frag_size[frag1];
1363 // Remember (basic) type inference.
1364 // The current data structure only allows us to do this for the whole block.
1365 if (type != NULL && area1 == real_addr_frag1) {
1366 state->types1_(block1, frag1) = type;
1368 if (type != NULL && area2 == real_addr_frag2) {
1369 state->types2_(block2, frag2) = type;
1371 // The type of the variable is already known:
1376 // Type inference from the block type.
1377 else if (state->types1_(block1, frag1) != NULL
1378 || state->types2_(block2, frag2) != NULL) {
1380 offset1 = (char *) area1 - (char *) real_addr_frag1;
1381 offset2 = (char *) area2 - (char *) real_addr_frag2;
1383 if (state->types1_(block1, frag1) != NULL
1384 && state->types2_(block2, frag2) != NULL) {
1386 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1387 offset1, size, snapshot1);
1389 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1390 offset1, size, snapshot2);
1391 } else if (state->types1_(block1, frag1) != NULL) {
1393 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1394 offset1, size, snapshot1);
1396 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1397 offset2, size, snapshot2);
1398 } else if (state->types2_(block2, frag2) != NULL) {
1400 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1401 offset1, size, snapshot1);
1403 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1404 offset2, size, snapshot2);
1407 match_equals(state, previous);
1408 xbt_dynar_free(&previous);
1413 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1416 while (type->byte_size == 0 && type->subtype != NULL)
1417 type = type->subtype;
1418 new_size1 = type->byte_size;
1421 while (type->byte_size == 0 && type->subtype != NULL)
1422 type = type->subtype;
1423 new_size2 = type->byte_size;
1427 match_equals(state, previous);
1428 xbt_dynar_free(&previous);
1434 if (new_size1 > 0 && new_size1 == new_size2) {
1439 if (offset1 == 0 && offset2 == 0) {
1440 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1442 match_equals(state, previous);
1443 xbt_dynar_free(&previous);
1451 match_equals(state, previous);
1452 xbt_dynar_free(&previous);
1457 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1458 && (heapinfo2->busy_frag.ignore[frag2] ==
1459 heapinfo1->busy_frag.ignore[frag1]))
1460 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1465 xbt_dynar_free(&previous);
1472 /* Start comparison */
1475 compare_heap_area_with_type(state, area1, area2, snapshot1, snapshot2,
1476 previous, type, size, check_ignore,
1480 compare_heap_area_without_type(state, area1, area2, snapshot1, snapshot2,
1481 previous, size, check_ignore);
1483 if (res_compare == 1) {
1485 xbt_dynar_free(&previous);
1490 match_equals(state, previous);
1491 xbt_dynar_free(&previous);
1497 /*********************************************** Miscellaneous ***************************************************/
1498 /****************************************************************************************************************/
1500 // Not used and broken code:
1504 static int get_pointed_area_size(void *area, int heap)
1507 struct s_mc_diff *state = mc_diff_info;
1510 malloc_info *heapinfo;
1513 heapinfo = state->heapinfo1;
1515 heapinfo = state->heapinfo2;
1519 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1521 if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1522 || (block > state->heapsize1) || (block < 1))
1525 if (heapinfo[block].type == -1) { /* Free block */
1527 } else if (heapinfo[block].type == 0) { /* Complete block */
1528 return (int) heapinfo[block].busy_block.busy_size;
1531 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1532 return (int) heapinfo[block].busy_frag.frag_size[frag];
1537 char *get_type_description(mc_object_info_t info, char *type_name)
1540 xbt_dict_cursor_t dict_cursor;
1544 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1545 if (type->name && (strcmp(type->name, type_name) == 0)
1546 && type->byte_size > 0) {
1547 xbt_dict_cursor_free(&dict_cursor);
1552 xbt_dict_cursor_free(&dict_cursor);
1558 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1562 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1565 struct s_mc_diff *state = mc_diff_info;
1567 if (heap1 == NULL && heap1 == NULL) {
1568 XBT_DEBUG("Malloc descriptors null");
1572 if (heap1->heaplimit != heap2->heaplimit) {
1573 XBT_DEBUG("Different limit of valid info table indices");
1577 /* Heap information */
1578 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1581 // Mamailloute in order to find the base address of the main heap:
1583 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1585 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1586 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1589 (malloc_info *) ((char *) heap1 +
1591 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1593 (malloc_info *) ((char *) heap2 +
1595 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1597 state->heapsize1 = heap1->heapsize;
1598 state->heapsize2 = heap2->heapsize;
1600 /* Start comparison */
1602 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1606 /* Check busy blocks */
1610 while (i <= state->heaplimit) {
1613 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1614 (char *) state->heapbase1));
1616 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1617 (char *) state->heapbase2));
1619 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1621 distance += BLOCKSIZE;
1622 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1623 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1628 if (state->heapinfo1[i].type == -1) { /* Free block */
1633 if (state->heapinfo1[i].type == 0) { /* Large block */
1635 if (state->heapinfo1[i].busy_block.size !=
1636 state->heapinfo2[i].busy_block.size) {
1638 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1639 state->heapinfo2[i].busy_block.size);
1640 i += max(state->heapinfo1[i].busy_block.size,
1641 state->heapinfo2[i].busy_block.size);
1643 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1644 i, state->heapinfo1[i].busy_block.size,
1645 state->heapinfo2[i].busy_block.size, distance);
1649 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1650 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1651 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1652 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);
1658 //while(k < (heapinfo1[i].busy_block.busy_size)){
1659 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1660 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1669 } else { /* Fragmented block */
1671 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1674 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1676 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1678 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1679 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1684 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1685 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1686 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);
1692 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1693 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1694 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=