Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Simplified control flow
[simgrid.git] / src / mc / mc_diff.cpp
1 /* Copyright (c) 2008-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* mc_diff - Memory snapshooting and comparison                             */
8
9 #include <array>
10 #include <memory>
11 #include <utility>
12
13 #include "src/xbt/ex_interface.h"   /* internals of backtrace setup */
14 #include "mc/mc.h"
15 #include "xbt/mmalloc.h"
16 #include "mc/datatypes.h"
17 #include "src/mc/malloc.hpp"
18 #include "src/mc/mc_private.h"
19 #include "src/mc/mc_snapshot.h"
20 #include "src/mc/mc_dwarf.hpp"
21 #include "src/mc/Type.hpp"
22
23 #include <xbt/dynar.h>
24
25 using simgrid::mc::remote;
26
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
28                                 "Logging specific to mc_diff in mc");
29
30 /*********************************** Heap comparison ***********************************/
31 /***************************************************************************************/
32
33 namespace simgrid {
34 namespace mc {
35
36 struct ProcessComparisonState {
37   std::vector<simgrid::mc::IgnoredHeapRegion>* to_ignore = nullptr;
38   std::vector<s_heap_area_t> equals_to;
39   std::vector<simgrid::mc::Type*> types;
40   std::size_t heapsize = 0;
41
42   void initHeapInformation(xbt_mheap_t heap,
43                           std::vector<simgrid::mc::IgnoredHeapRegion>* i);
44 };
45
46 struct StateComparator {
47   s_xbt_mheap_t std_heap_copy;
48   std::size_t heaplimit;
49   std::array<ProcessComparisonState, 2> processStates;
50
51   int initHeapInformation(
52     xbt_mheap_t heap1, xbt_mheap_t heap2,
53     std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
54     std::vector<simgrid::mc::IgnoredHeapRegion>* i2);
55
56   s_heap_area_t& equals_to1_(std::size_t i, std::size_t j)
57   {
58     return processStates[0].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
59   }
60   s_heap_area_t& equals_to2_(std::size_t i, std::size_t j)
61   {
62     return processStates[1].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
63   }
64   Type*& types1_(std::size_t i, std::size_t j)
65   {
66     return processStates[0].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
67   }
68   Type*& types2_(std::size_t i, std::size_t j)
69   {
70     return processStates[1].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
71   }
72
73   s_heap_area_t const& equals_to1_(std::size_t i, std::size_t j) const
74   {
75     return processStates[0].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
76   }
77   s_heap_area_t const& equals_to2_(std::size_t i, std::size_t j) const
78   {
79     return processStates[1].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
80   }
81   Type* const& types1_(std::size_t i, std::size_t j) const
82   {
83     return processStates[0].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
84   }
85   Type* const& types2_(std::size_t i, std::size_t j) const
86   {
87     return processStates[1].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
88   }
89
90   /** Check whether two blocks are known to be matching
91    *
92    *  @param state  State used
93    *  @param b1     Block of state 1
94    *  @param b2     Block of state 2
95    *  @return       if the blocks are known to be matching
96    */
97   bool blocksEqual(int b1, int b2) const
98   {
99     return this->equals_to1_(b1, 0).block == b2
100         && this->equals_to2_(b2, 0).block == b1;
101   }
102
103   /** Check whether two fragments are known to be matching
104    *
105    *  @param state  State used
106    *  @param b1     Block of state 1
107    *  @param f1     Fragment of state 1
108    *  @param b2     Block of state 2
109    *  @param f2     Fragment of state 2
110    *  @return       if the fragments are known to be matching
111    */
112   int fragmentsEqual(int b1, int f1, int b2, int f2) const
113   {
114     return this->equals_to1_(b1, f1).block == b2
115         && this->equals_to1_(b1, f1).fragment == f2
116         && this->equals_to2_(b2, f2).block == b1
117         && this->equals_to2_(b2, f2).fragment == f1;
118   }
119
120   void match_equals(xbt_dynar_t list);
121 };
122
123 }
124 }
125
126 // TODO, make this a field of ModelChecker or something similar
127 static std::unique_ptr<simgrid::mc::StateComparator> mc_diff_info;
128
129 /*********************************** Free functions ************************************/
130
131 static void heap_area_pair_free(heap_area_pair_t pair)
132 {
133   xbt_free(pair);
134   pair = nullptr;
135 }
136
137 static void heap_area_pair_free_voidp(void *d)
138 {
139   heap_area_pair_free((heap_area_pair_t) * (void **) d);
140 }
141
142 static void heap_area_free(heap_area_t area)
143 {
144   xbt_free(area);
145   area = nullptr;
146 }
147
148 /************************************************************************************/
149
150 static s_heap_area_t make_heap_area(int block, int fragment)
151 {
152   s_heap_area_t area;
153   area.valid = 1;
154   area.block = block;
155   area.fragment = fragment;
156   return area;
157 }
158
159
160 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
161                                  int block2, int fragment2)
162 {
163
164   unsigned int cursor = 0;
165   heap_area_pair_t current_pair;
166
167   xbt_dynar_foreach(list, cursor, current_pair)
168     if (current_pair->block1 == block1 && current_pair->block2 == block2
169         && current_pair->fragment1 == fragment1
170         && current_pair->fragment2 == fragment2)
171       return 0;
172
173   return 1;
174 }
175
176 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
177                               int block2, int fragment2)
178 {
179
180   if (!is_new_heap_area_pair(list, block1, fragment1, block2, fragment2))
181     return 0;
182
183   heap_area_pair_t pair = nullptr;
184   pair = xbt_new0(s_heap_area_pair_t, 1);
185   pair->block1 = block1;
186   pair->fragment1 = fragment1;
187   pair->block2 = block2;
188   pair->fragment2 = fragment2;
189   xbt_dynar_push(list, &pair);
190   return 1;
191 }
192
193 static ssize_t heap_comparison_ignore_size(
194   std::vector<simgrid::mc::IgnoredHeapRegion>* ignore_list,
195   const void *address)
196 {
197   int start = 0;
198   int end = ignore_list->size() - 1;
199
200   while (start <= end) {
201     unsigned int cursor = (start + end) / 2;
202     simgrid::mc::IgnoredHeapRegion const& region = (*ignore_list)[cursor];
203     if (region.address == address)
204       return region.size;
205     if (region.address < address)
206       start = cursor + 1;
207     if (region.address > address)
208       end = cursor - 1;
209   }
210
211   return -1;
212 }
213
214 static bool is_stack(const void *address)
215 {
216   for (auto const& stack : mc_model_checker->process().stack_areas())
217     if (address == stack.address)
218       return true;
219   return false;
220 }
221
222 // TODO, this should depend on the snapshot?
223 static bool is_block_stack(int block)
224 {
225   for (auto const& stack : mc_model_checker->process().stack_areas())
226     if (block == stack.block)
227       return true;
228   return false;
229 }
230
231 namespace simgrid {
232 namespace mc {
233
234 void StateComparator::match_equals(xbt_dynar_t list)
235 {
236   unsigned int cursor = 0;
237   heap_area_pair_t current_pair;
238
239   xbt_dynar_foreach(list, cursor, current_pair) {
240     if (current_pair->fragment1 != -1) {
241       this->equals_to1_(current_pair->block1, current_pair->fragment1) =
242           make_heap_area(current_pair->block2, current_pair->fragment2);
243       this->equals_to2_(current_pair->block2, current_pair->fragment2) =
244           make_heap_area(current_pair->block1, current_pair->fragment1);
245     } else {
246       this->equals_to1_(current_pair->block1, 0) =
247           make_heap_area(current_pair->block2, current_pair->fragment2);
248       this->equals_to2_(current_pair->block2, 0) =
249           make_heap_area(current_pair->block1, current_pair->fragment1);
250     }
251   }
252 }
253
254 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
255                           std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
256                           std::vector<simgrid::mc::IgnoredHeapRegion>* i2)
257 {
258   if (mc_diff_info == nullptr)
259     mc_diff_info = std::unique_ptr<StateComparator>(new StateComparator());
260   return mc_diff_info->initHeapInformation(heap1, heap2, i1, i2);
261 }
262
263 void ProcessComparisonState::initHeapInformation(xbt_mheap_t heap,
264                         std::vector<simgrid::mc::IgnoredHeapRegion>* i)
265 {
266   auto heaplimit = ((struct mdesc *) heap)->heaplimit;
267   this->heapsize = ((struct mdesc *) heap)->heapsize;
268   this->to_ignore = i;
269   this->equals_to.assign(heaplimit * MAX_FRAGMENT_PER_BLOCK, s_heap_area {0, 0, 0});
270   this->types.assign(heaplimit * MAX_FRAGMENT_PER_BLOCK, nullptr);
271 }
272
273 int StateComparator::initHeapInformation(xbt_mheap_t heap1, xbt_mheap_t heap2,
274                           std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
275                           std::vector<simgrid::mc::IgnoredHeapRegion>* i2)
276 {
277   if ((((struct mdesc *) heap1)->heaplimit !=
278        ((struct mdesc *) heap2)->heaplimit)
279       ||
280       ((((struct mdesc *) heap1)->heapsize !=
281         ((struct mdesc *) heap2)->heapsize)))
282     return -1;
283   this->heaplimit = ((struct mdesc *) heap1)->heaplimit;
284   this->std_heap_copy = *mc_model_checker->process().get_heap();
285   this->processStates[0].initHeapInformation(heap1, i1);
286   this->processStates[1].initHeapInformation(heap2, i2);
287   return 0;
288 }
289
290 void reset_heap_information()
291 {
292
293 }
294
295 // TODO, have a robust way to find it in O(1)
296 static inline
297 mc_mem_region_t MC_get_heap_region(simgrid::mc::Snapshot* snapshot)
298 {
299   for (auto& region : snapshot->snapshot_regions)
300     if (region->region_type() == simgrid::mc::RegionType::Heap)
301       return region.get();
302   xbt_die("No heap region");
303 }
304
305 int mmalloc_compare_heap(simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2)
306 {
307   simgrid::mc::Process* process = &mc_model_checker->process();
308   simgrid::mc::StateComparator *state = mc_diff_info.get();
309
310   /* Start comparison */
311   size_t i1, i2, j1, j2, k;
312   void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
313   int nb_diff1 = 0, nb_diff2 = 0;
314
315   int equal, res_compare = 0;
316
317   /* Check busy blocks */
318
319   i1 = 1;
320
321   malloc_info heapinfo_temp1, heapinfo_temp2;
322   malloc_info heapinfo_temp2b;
323
324   mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
325   mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
326
327   // This is the address of std_heap->heapinfo in the application process:
328   void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
329
330   // This is in snapshot do not use them directly:
331   const malloc_info* heapinfos1 = snapshot1->read<malloc_info*>(
332     (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
333   const malloc_info* heapinfos2 = snapshot2->read<malloc_info*>(
334     (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
335
336   while (i1 < state->heaplimit) {
337
338     const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
339     const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
340
341     if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) {      /* Free block */
342       i1 ++;
343       continue;
344     }
345
346     if (heapinfo1->type < 0) {
347       fprintf(stderr, "Unkown mmalloc block type.\n");
348       abort();
349     }
350
351     addr_block1 =
352         ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
353                    (char *) state->std_heap_copy.heapbase));
354
355     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {       /* Large block */
356
357       if (is_stack(addr_block1)) {
358         for (k = 0; k < heapinfo1->busy_block.size; k++)
359           state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
360         for (k = 0; k < heapinfo2->busy_block.size; k++)
361           state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
362         i1 += heapinfo1->busy_block.size;
363         continue;
364       }
365
366       if (state->equals_to1_(i1, 0).valid) {
367         i1++;
368         continue;
369       }
370
371       i2 = 1;
372       equal = 0;
373       res_compare = 0;
374
375       /* Try first to associate to same block in the other heap */
376       if (heapinfo2->type == heapinfo1->type
377         && state->equals_to2_(i1, 0).valid == 0) {
378         addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
379                        (char *) state->std_heap_copy.heapbase;
380         res_compare =
381             compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
382                               nullptr, nullptr, 0);
383         if (res_compare != 1) {
384           for (k = 1; k < heapinfo2->busy_block.size; k++)
385             state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
386           for (k = 1; k < heapinfo1->busy_block.size; k++)
387             state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
388           equal = 1;
389           i1 += heapinfo1->busy_block.size;
390         }
391       }
392
393       while (i2 < state->heaplimit && !equal) {
394
395         addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
396                        (char *) state->std_heap_copy.heapbase;
397
398         if (i2 == i1) {
399           i2++;
400           continue;
401         }
402
403         const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
404
405         if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
406           i2++;
407           continue;
408         }
409
410         if (state->equals_to2_(i2, 0).valid) {
411           i2++;
412           continue;
413         }
414
415         res_compare =
416             compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
417                               nullptr, nullptr, 0);
418
419         if (res_compare != 1) {
420           for (k = 1; k < heapinfo2b->busy_block.size; k++)
421             state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
422           for (k = 1; k < heapinfo1->busy_block.size; k++)
423             state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
424           equal = 1;
425           i1 += heapinfo1->busy_block.size;
426         }
427
428         i2++;
429
430       }
431
432       if (!equal) {
433         XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
434                   heapinfo1->busy_block.busy_size, addr_block1);
435         i1 = state->heaplimit + 1;
436         nb_diff1++;
437         //i1++;
438       }
439
440     } else {                    /* Fragmented block */
441
442       for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
443
444         if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
445           continue;
446
447         if (state->equals_to1_(i1, j1).valid)
448           continue;
449
450         addr_frag1 =
451             (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
452
453         i2 = 1;
454         equal = 0;
455
456         /* Try first to associate to same fragment in the other heap */
457         if (heapinfo2->type == heapinfo1->type
458             && state->equals_to2_(i1, j1).valid == 0) {
459           addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
460                          (char *) state->std_heap_copy.heapbase;
461           addr_frag2 =
462               (void *) ((char *) addr_block2 +
463                         (j1 << heapinfo2->type));
464           res_compare =
465               compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot1, snapshot2,
466                                 nullptr, nullptr, 0);
467           if (res_compare != 1)
468             equal = 1;
469         }
470
471
472
473         while (i2 < state->heaplimit && !equal) {
474
475           const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
476             heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
477             sizeof(malloc_info));
478
479           if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
480             i2 ++;
481             continue;
482           }
483
484           // We currently do not match fragments with unfragmented blocks (maybe we should).
485           if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
486             i2++;
487             continue;
488           }
489
490           if (heapinfo2b->type < 0) {
491             fprintf(stderr, "Unkown mmalloc block type.\n");
492             abort();
493           }
494
495           for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
496                j2++) {
497
498             if (i2 == i1 && j2 == j1)
499               continue;
500
501             if (state->equals_to2_(i2, j2).valid)
502               continue;
503
504             addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
505                            (char *) state->std_heap_copy.heapbase;
506             addr_frag2 =
507                 (void *) ((char *) addr_block2 +
508                           (j2 << heapinfo2b->type));
509
510             res_compare =
511                 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot2, snapshot2,
512                                   nullptr, nullptr, 0);
513
514             if (res_compare != 1) {
515               equal = 1;
516               break;
517             }
518
519           }
520
521           i2++;
522
523         }
524
525         if (!equal) {
526           XBT_DEBUG
527               ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
528                i1, j1, heapinfo1->busy_frag.frag_size[j1],
529                addr_frag1);
530           i2 = state->heaplimit + 1;
531           i1 = state->heaplimit + 1;
532           nb_diff1++;
533           break;
534         }
535
536       }
537
538       i1++;
539
540     }
541
542   }
543
544   /* All blocks/fragments are equal to another block/fragment ? */
545   size_t i = 1, j = 0;
546
547   for(i = 1; i < state->heaplimit; i++) {
548     const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
549       heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
550
551     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
552         && i1 == state->heaplimit
553         && heapinfo1->busy_block.busy_size > 0
554         && state->equals_to1_(i, 0).valid == 0) {
555       XBT_DEBUG("Block %zu not found (size used = %zu)", i,
556                 heapinfo1->busy_block.busy_size);
557       nb_diff1++;
558     }
559
560     if (heapinfo1->type <= 0)
561       continue;
562     for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++)
563       if (i1 == state->heaplimit
564           && heapinfo1->busy_frag.frag_size[j] > 0
565           && state->equals_to1_(i, j).valid == 0) {
566         XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)",
567           i, j, heapinfo1->busy_frag.frag_size[j]);
568         nb_diff1++;
569       }
570   }
571
572   if (i1 == state->heaplimit)
573     XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
574
575   for (i=1; i < state->heaplimit; i++) {
576     const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
577       heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
578     if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED
579         && i1 == state->heaplimit
580         && heapinfo2->busy_block.busy_size > 0
581         && state->equals_to2_(i, 0).valid == 0) {
582       XBT_DEBUG("Block %zu not found (size used = %zu)", i,
583                 heapinfo2->busy_block.busy_size);
584       nb_diff2++;
585     }
586
587     if (heapinfo2->type <= 0)
588       continue;
589
590     for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++)
591       if (i1 == state->heaplimit
592           && heapinfo2->busy_frag.frag_size[j] > 0
593           && state->equals_to2_(i, j).valid == 0) {
594         XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)",
595           i, j, heapinfo2->busy_frag.frag_size[j]);
596         nb_diff2++;
597       }
598
599   }
600
601   if (i1 == state->heaplimit)
602     XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
603
604   return nb_diff1 > 0 || nb_diff2 > 0;
605 }
606
607 /**
608  *
609  * @param state
610  * @param real_area1     Process address for state 1
611  * @param real_area2     Process address for state 2
612  * @param snapshot1      Snapshot of state 1
613  * @param snapshot2      Snapshot of state 2
614  * @param previous
615  * @param size
616  * @param check_ignore
617  */
618 static int compare_heap_area_without_type(
619   simgrid::mc::StateComparator *state, int process_index,
620   const void *real_area1, const void *real_area2,
621   simgrid::mc::Snapshot* snapshot1,
622   simgrid::mc::Snapshot* snapshot2,
623   xbt_dynar_t previous, int size,
624   int check_ignore)
625 {
626   simgrid::mc::Process* process = &mc_model_checker->process();
627   mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
628   mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
629
630   for (int i = 0; i < size; ) {
631
632     if (check_ignore > 0) {
633       ssize_t ignore1 = heap_comparison_ignore_size(
634         state->processStates[0].to_ignore, (char *) real_area1 + i);
635       if (ignore1 != -1) {
636         ssize_t ignore2 = heap_comparison_ignore_size(
637           state->processStates[1].to_ignore, (char *) real_area2 + i);
638         if (ignore2 == ignore1) {
639           if (ignore1 == 0) {
640             check_ignore--;
641             return 0;
642           } else {
643             i = i + ignore2;
644             check_ignore--;
645             continue;
646           }
647         }
648       }
649     }
650
651     if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
652
653       int pointer_align = (i / sizeof(void *)) * sizeof(void *);
654       const void* addr_pointed1 = snapshot1->read(
655         remote((void**)((char *) real_area1 + pointer_align)), process_index);
656       const void* addr_pointed2 = snapshot2->read(
657         remote((void**)((char *) real_area2 + pointer_align)), process_index);
658
659       if (process->in_maestro_stack(remote(addr_pointed1))
660         && process->in_maestro_stack(remote(addr_pointed2))) {
661         i = pointer_align + sizeof(void *);
662         continue;
663       }
664
665       if (addr_pointed1 > state->std_heap_copy.heapbase
666            && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
667            && addr_pointed2 > state->std_heap_copy.heapbase
668            && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
669         // Both addreses are in the heap:
670         int res_compare =
671             compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
672                               snapshot2, previous, nullptr, 0);
673         if (res_compare == 1)
674           return res_compare;
675         i = pointer_align + sizeof(void *);
676         continue;
677       }
678
679       return 1;
680     }
681
682     i++;
683   }
684
685   return 0;
686 }
687
688 /**
689  *
690  * @param state
691  * @param real_area1     Process address for state 1
692  * @param real_area2     Process address for state 2
693  * @param snapshot1      Snapshot of state 1
694  * @param snapshot2      Snapshot of state 2
695  * @param previous
696  * @param type_id
697  * @param area_size      either a byte_size or an elements_count (?)
698  * @param check_ignore
699  * @param pointer_level
700  * @return               0 (same), 1 (different), -1 (unknown)
701  */
702 static int compare_heap_area_with_type(
703   simgrid::mc::StateComparator *state, int process_index,
704   const void *real_area1, const void *real_area2,
705   simgrid::mc::Snapshot* snapshot1,
706   simgrid::mc::Snapshot* snapshot2,
707   xbt_dynar_t previous, simgrid::mc::Type* type,
708   int area_size, int check_ignore,
709   int pointer_level)
710 {
711 top:
712
713   // HACK: This should not happen but in pratice, there are some
714   // DW_TAG_typedef without an associated DW_AT_type:
715   //<1><538832>: Abbrev Number: 111 (DW_TAG_typedef)
716   //    <538833>   DW_AT_name        : (indirect string, offset: 0x2292f3): gregset_t
717   //    <538837>   DW_AT_decl_file   : 98
718   //    <538838>   DW_AT_decl_line   : 37
719   if (type == nullptr)
720     return 0;
721
722   if (is_stack(real_area1) && is_stack(real_area2))
723     return 0;
724
725   if (check_ignore > 0) {
726     ssize_t ignore1 = heap_comparison_ignore_size(
727       state->processStates[0].to_ignore, real_area1);
728     if (ignore1 > 0
729         && heap_comparison_ignore_size(
730           state->processStates[1].to_ignore, real_area2) == ignore1)
731       return 0;
732   }
733
734   simgrid::mc::Type *subtype, *subsubtype;
735   int res, elm_size;
736   const void *addr_pointed1, *addr_pointed2;
737
738   mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
739   mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
740
741   switch (type->type) {
742   case DW_TAG_unspecified_type:
743     return 1;
744
745   case DW_TAG_base_type:
746     if (!type->name.empty() && type->name == "char") {        /* String, hence random (arbitrary ?) size */
747       if (real_area1 == real_area2)
748         return -1;
749       else
750         return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0;
751     } else {
752       if (area_size != -1 && type->byte_size != area_size)
753         return -1;
754       else
755         return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
756     }
757     break;
758
759   case DW_TAG_enumeration_type:
760     if (area_size != -1 && type->byte_size != area_size)
761       return -1;
762     return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
763
764   case DW_TAG_typedef:
765   case DW_TAG_const_type:
766   case DW_TAG_volatile_type:
767     // Poor man's TCO:
768     type = type->subtype;
769     goto top;
770
771   case DW_TAG_array_type:
772     subtype = type->subtype;
773     switch (subtype->type) {
774     case DW_TAG_unspecified_type:
775       return 1;
776
777     case DW_TAG_base_type:
778     case DW_TAG_enumeration_type:
779     case DW_TAG_pointer_type:
780     case DW_TAG_reference_type:
781     case DW_TAG_rvalue_reference_type:
782     case DW_TAG_structure_type:
783     case DW_TAG_class_type:
784     case DW_TAG_union_type:
785       if (subtype->full_type)
786         subtype = subtype->full_type;
787       elm_size = subtype->byte_size;
788       break;
789       // TODO, just remove the type indirection?
790     case DW_TAG_const_type:
791     case DW_TAG_typedef:
792     case DW_TAG_volatile_type:
793       subsubtype = subtype->subtype;
794       if (subsubtype->full_type)
795         subsubtype = subsubtype->full_type;
796       elm_size = subsubtype->byte_size;
797       break;
798     default:
799       return 0;
800       break;
801     }
802     for (int i = 0; i < type->element_count; i++) {
803       // TODO, add support for variable stride (DW_AT_byte_stride)
804       res =
805           compare_heap_area_with_type(state, process_index,
806                                       (char *) real_area1 + (i * elm_size),
807                                       (char *) real_area2 + (i * elm_size),
808                                       snapshot1, snapshot2, previous,
809                                       type->subtype, subtype->byte_size,
810                                       check_ignore, pointer_level);
811       if (res == 1)
812         return res;
813     }
814     return 0;
815
816   case DW_TAG_reference_type:
817   case DW_TAG_rvalue_reference_type:
818   case DW_TAG_pointer_type:
819     if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
820       addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
821       addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
822       return (addr_pointed1 != addr_pointed2);
823     }
824     pointer_level++;
825     if (pointer_level <= 1) {
826       addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
827       addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
828       if (addr_pointed1 > state->std_heap_copy.heapbase
829           && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
830           && addr_pointed2 > state->std_heap_copy.heapbase
831           && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
832         return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
833                                  snapshot2, previous, type->subtype,
834                                  pointer_level);
835       else
836         return (addr_pointed1 != addr_pointed2);
837     }
838     for (size_t i = 0; i < (area_size / sizeof(void *)); i++) {
839       addr_pointed1 = snapshot1->read(
840         remote((void**)((char*) real_area1 + i * sizeof(void *))),
841         process_index);
842       addr_pointed2 = snapshot2->read(
843         remote((void**)((char*) real_area2 + i * sizeof(void *))),
844         process_index);
845       if (addr_pointed1 > state->std_heap_copy.heapbase
846           && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
847           && addr_pointed2 > state->std_heap_copy.heapbase
848           && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
849         res =
850             compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
851                               snapshot2, previous, type->subtype,
852                               pointer_level);
853       else
854         res = (addr_pointed1 != addr_pointed2);
855       if (res == 1)
856         return res;
857     }
858     return 0;
859
860   case DW_TAG_structure_type:
861   case DW_TAG_class_type:
862     if (type->full_type)
863       type = type->full_type;
864     if (area_size != -1 && type->byte_size != area_size) {
865       if (area_size <= type->byte_size || area_size % type->byte_size != 0)
866         return -1;
867       for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
868         int res = compare_heap_area_with_type(state, process_index,
869                     (char *) real_area1 + i * type->byte_size,
870                     (char *) real_area2 + i * type->byte_size,
871                     snapshot1, snapshot2, previous, type, -1,
872                     check_ignore, 0);
873         if (res == 1)
874           return res;
875       }
876     } else {
877       for(simgrid::mc::Member& member : type->members) {
878         // TODO, optimize this? (for the offset case)
879         void *real_member1 = simgrid::dwarf::resolve_member(
880           real_area1, type, &member, (simgrid::mc::AddressSpace*) snapshot1, process_index);
881         void *real_member2 = simgrid::dwarf::resolve_member(
882             real_area2, type, &member, (simgrid::mc::AddressSpace*) snapshot2, process_index);
883         int res = compare_heap_area_with_type(
884                     state, process_index, real_member1, real_member2,
885                     snapshot1, snapshot2,
886                     previous, member.type, -1,
887                     check_ignore, 0);
888         if (res == 1)
889           return res;
890       }
891     }
892     return 0;
893
894   case DW_TAG_union_type:
895     return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
896                                           snapshot1, snapshot2, previous,
897                                           type->byte_size, check_ignore);
898     return 0;
899
900   default:
901     return 0;
902   }
903
904   xbt_die("Unreachable");
905 }
906
907 /** Infer the type of a part of the block from the type of the block
908  *
909  * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
910  *
911  * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
912  *
913  * @param  type_id            DWARF type ID of the root address
914  * @param  area_size
915  * @return                    DWARF type ID for given offset
916  */
917 static simgrid::mc::Type* get_offset_type(void *real_base_address, simgrid::mc::Type* type,
918                                  int offset, int area_size,
919                                  simgrid::mc::Snapshot* snapshot, int process_index)
920 {
921
922   // Beginning of the block, the infered variable type if the type of the block:
923   if (offset == 0)
924     return type;
925
926   switch (type->type) {
927
928   case DW_TAG_structure_type:
929   case DW_TAG_class_type:
930     if (type->full_type)
931       type = type->full_type;
932     if (area_size != -1 && type->byte_size != area_size) {
933       if (area_size > type->byte_size && area_size % type->byte_size == 0)
934         return type;
935       else
936         return nullptr;
937     }
938
939     for(simgrid::mc::Member& member : type->members) {
940       if (member.has_offset_location()) {
941         // We have the offset, use it directly (shortcut):
942         if (member.offset() == offset)
943           return member.type;
944       } else {
945         void *real_member = simgrid::dwarf::resolve_member(
946           real_base_address, type, &member, snapshot, process_index);
947         if ((char*) real_member - (char *) real_base_address == offset)
948           return member.type;
949       }
950     }
951     return nullptr;
952
953   default:
954     /* FIXME : other cases ? */
955     return nullptr;
956
957   }
958 }
959
960 /**
961  *
962  * @param area1          Process address for state 1
963  * @param area2          Process address for state 2
964  * @param snapshot1      Snapshot of state 1
965  * @param snapshot2      Snapshot of state 2
966  * @param previous       Pairs of blocks already compared on the current path (or nullptr)
967  * @param type_id        Type of variable
968  * @param pointer_level
969  * @return 0 (same), 1 (different), -1
970  */
971 int compare_heap_area(int process_index, const void *area1, const void *area2, simgrid::mc::Snapshot* snapshot1,
972                       simgrid::mc::Snapshot* snapshot2, xbt_dynar_t previous,
973                       simgrid::mc::Type* type, int pointer_level)
974 {
975   simgrid::mc::Process* process = &mc_model_checker->process();
976
977   simgrid::mc::StateComparator *state = mc_diff_info.get();
978
979   int res_compare;
980   ssize_t block1, frag1, block2, frag2;
981   ssize_t size;
982   int check_ignore = 0;
983
984   void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
985   int type_size = -1;
986   int offset1 = 0, offset2 = 0;
987   int new_size1 = -1, new_size2 = -1;
988   simgrid::mc::Type *new_type1 = nullptr, *new_type2 = nullptr;
989
990   int match_pairs = 0;
991
992   // This is the address of std_heap->heapinfo in the application process:
993   void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
994
995   const malloc_info* heapinfos1 = snapshot1->read(
996     remote((const malloc_info**)heapinfo_address), process_index);
997   const malloc_info* heapinfos2 = snapshot2->read(
998     remote((const malloc_info**)heapinfo_address), process_index);
999
1000   malloc_info heapinfo_temp1, heapinfo_temp2;
1001
1002   if (previous == nullptr) {
1003     previous =
1004         xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1005     match_pairs = 1;
1006   }
1007   // Get block number:
1008   block1 =
1009       ((char *) area1 -
1010        (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1011   block2 =
1012       ((char *) area2 -
1013        (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1014
1015   // If either block is a stack block:
1016   if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1017     add_heap_area_pair(previous, block1, -1, block2, -1);
1018     if (match_pairs) {
1019       state->match_equals(previous);
1020       xbt_dynar_free(&previous);
1021     }
1022     return 0;
1023   }
1024
1025   // If either block is not in the expected area of memory:
1026   if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1027       || (block1 > (ssize_t) state->processStates[0].heapsize) || (block1 < 1)
1028       || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1029       || (block2 > (ssize_t) state->processStates[1].heapsize) || (block2 < 1)) {
1030     if (match_pairs)
1031       xbt_dynar_free(&previous);
1032     return 1;
1033   }
1034
1035   // Process address of the block:
1036   real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1037                  (char *) state->std_heap_copy.heapbase;
1038   real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1039                  (char *) state->std_heap_copy.heapbase;
1040
1041   if (type) {
1042
1043     if (type->full_type)
1044       type = type->full_type;
1045
1046     // This assume that for "boring" types (volatile ...) byte_size is absent:
1047     while (type->byte_size == 0 && type->subtype != nullptr)
1048       type = type->subtype;
1049
1050     // Find type_size:
1051     if (type->type == DW_TAG_pointer_type
1052         || (type->type == DW_TAG_base_type && !type->name.empty()
1053             && type->name == "char"))
1054       type_size = -1;
1055     else
1056       type_size = type->byte_size;
1057
1058   }
1059
1060   mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1061   mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1062
1063   const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1064     heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1065   const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1066     heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1067
1068   if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1069     && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1070     /* Free block */
1071     if (match_pairs) {
1072       state->match_equals(previous);
1073       xbt_dynar_free(&previous);
1074     }
1075     return 0;
1076   }
1077
1078   if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1079     && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1080     /* Complete block */
1081
1082     // TODO, lookup variable type from block type as done for fragmented blocks
1083
1084     offset1 = (char *) area1 - (char *) real_addr_block1;
1085     offset2 = (char *) area2 - (char *) real_addr_block2;
1086
1087     if (state->equals_to1_(block1, 0).valid
1088         && state->equals_to2_(block2, 0).valid
1089         && state->blocksEqual(block1, block2)) {
1090       if (match_pairs) {
1091         state->match_equals(previous);
1092         xbt_dynar_free(&previous);
1093       }
1094       return 0;
1095     }
1096
1097     if (type_size != -1) {
1098       if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
1099           && type_size != (ssize_t)   heapinfo2->busy_block.busy_size
1100           && (type->name.empty() || type->name == "struct s_smx_context")) {
1101         if (match_pairs) {
1102           state->match_equals(previous);
1103           xbt_dynar_free(&previous);
1104         }
1105         return -1;
1106       }
1107     }
1108
1109     if (heapinfo1->busy_block.size != heapinfo2->busy_block.size) {
1110       if (match_pairs)
1111         xbt_dynar_free(&previous);
1112       return 1;
1113     }
1114
1115     if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size) {
1116       if (match_pairs)
1117         xbt_dynar_free(&previous);
1118       return 1;
1119     }
1120
1121     if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1122       if (match_pairs) {
1123         state->match_equals(previous);
1124         xbt_dynar_free(&previous);
1125       }
1126       return 0;
1127     }
1128
1129     size = heapinfo1->busy_block.busy_size;
1130
1131     // Remember (basic) type inference.
1132     // The current data structure only allows us to do this for the whole block.
1133     if (type != nullptr && area1 == real_addr_block1)
1134       state->types1_(block1, 0) = type;
1135     if (type != nullptr && area2 == real_addr_block2)
1136       state->types2_(block2, 0) = type;
1137
1138     if (size <= 0) {
1139       if (match_pairs) {
1140         state->match_equals(previous);
1141         xbt_dynar_free(&previous);
1142       }
1143       return 0;
1144     }
1145
1146     frag1 = -1;
1147     frag2 = -1;
1148
1149     if (heapinfo1->busy_block.ignore > 0
1150         && heapinfo2->busy_block.ignore == heapinfo1->busy_block.ignore)
1151       check_ignore = heapinfo1->busy_block.ignore;
1152
1153   } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) {      /* Fragmented block */
1154
1155     // Fragment number:
1156     frag1 =
1157         ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1158     frag2 =
1159         ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1160
1161     // Process address of the fragment:
1162     real_addr_frag1 =
1163         (void *) ((char *) real_addr_block1 +
1164                   (frag1 << heapinfo1->type));
1165     real_addr_frag2 =
1166         (void *) ((char *) real_addr_block2 +
1167                   (frag2 << heapinfo2->type));
1168
1169     // Check the size of the fragments against the size of the type:
1170     if (type_size != -1) {
1171       if (heapinfo1->busy_frag.frag_size[frag1] == -1
1172           || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1173         if (match_pairs) {
1174           state->match_equals(previous);
1175           xbt_dynar_free(&previous);
1176         }
1177         return -1;
1178       }
1179       // ?
1180       if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1181           || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1182         if (match_pairs) {
1183           state->match_equals(previous);
1184           xbt_dynar_free(&previous);
1185         }
1186         return -1;
1187       }
1188     }
1189
1190     // Check if the blocks are already matched together:
1191     if (state->equals_to1_(block1, frag1).valid
1192         && state->equals_to2_(block2, frag2).valid) {
1193       if (offset1==offset2 && state->fragmentsEqual(block1, frag1, block2, frag2)) {
1194         if (match_pairs) {
1195           state->match_equals(previous);
1196           xbt_dynar_free(&previous);
1197         }
1198         return 0;
1199       }
1200     }
1201     // Compare the size of both fragments:
1202     if (heapinfo1->busy_frag.frag_size[frag1] !=
1203         heapinfo2->busy_frag.frag_size[frag2]) {
1204       if (type_size == -1) {
1205         if (match_pairs) {
1206           state->match_equals(previous);
1207           xbt_dynar_free(&previous);
1208         }
1209         return -1;
1210       } else {
1211         if (match_pairs)
1212           xbt_dynar_free(&previous);
1213         return 1;
1214       }
1215     }
1216
1217     // Size of the fragment:
1218     size = heapinfo1->busy_frag.frag_size[frag1];
1219
1220     // Remember (basic) type inference.
1221     // The current data structure only allows us to do this for the whole fragment.
1222     if (type != nullptr && area1 == real_addr_frag1)
1223       state->types1_(block1, frag1) = type;
1224     if (type != nullptr && area2 == real_addr_frag2)
1225       state->types2_(block2, frag2) = type;
1226
1227     // The type of the variable is already known:
1228     if (type) {
1229       new_type1 = type;
1230       new_type2 = type;
1231     }
1232     // Type inference from the block type.
1233     else if (state->types1_(block1, frag1) != nullptr
1234              || state->types2_(block2, frag2) != nullptr) {
1235
1236       offset1 = (char *) area1 - (char *) real_addr_frag1;
1237       offset2 = (char *) area2 - (char *) real_addr_frag2;
1238
1239       if (state->types1_(block1, frag1) != nullptr
1240           && state->types2_(block2, frag2) != nullptr) {
1241         new_type1 =
1242             get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1243                             offset1, size, snapshot1, process_index);
1244         new_type2 =
1245             get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1246                             offset1, size, snapshot2, process_index);
1247       } else if (state->types1_(block1, frag1) != nullptr) {
1248         new_type1 =
1249             get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1250                             offset1, size, snapshot1, process_index);
1251         new_type2 =
1252             get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1253                             offset2, size, snapshot2, process_index);
1254       } else if (state->types2_(block2, frag2) != nullptr) {
1255         new_type1 =
1256             get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1257                             offset1, size, snapshot1, process_index);
1258         new_type2 =
1259             get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1260                             offset2, size, snapshot2, process_index);
1261       } else {
1262         if (match_pairs) {
1263           state->match_equals(previous);
1264           xbt_dynar_free(&previous);
1265         }
1266         return -1;
1267       }
1268
1269       if (new_type1 != nullptr && new_type2 != nullptr && new_type1 != new_type2) {
1270
1271         type = new_type1;
1272         while (type->byte_size == 0 && type->subtype != nullptr)
1273           type = type->subtype;
1274         new_size1 = type->byte_size;
1275
1276         type = new_type2;
1277         while (type->byte_size == 0 && type->subtype != nullptr)
1278           type = type->subtype;
1279         new_size2 = type->byte_size;
1280
1281       } else {
1282         if (match_pairs) {
1283           state->match_equals(previous);
1284           xbt_dynar_free(&previous);
1285         }
1286         return -1;
1287       }
1288     }
1289
1290     if (new_size1 > 0 && new_size1 == new_size2) {
1291       type = new_type1;
1292       size = new_size1;
1293     }
1294
1295     if (offset1 == 0 && offset2 == 0
1296       && !add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1297         if (match_pairs) {
1298           state->match_equals(previous);
1299           xbt_dynar_free(&previous);
1300         }
1301         return 0;
1302       }
1303
1304     if (size <= 0) {
1305       if (match_pairs) {
1306         state->match_equals(previous);
1307         xbt_dynar_free(&previous);
1308       }
1309       return 0;
1310     }
1311
1312     if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1313         && (heapinfo2->busy_frag.ignore[frag2] ==
1314             heapinfo1->busy_frag.ignore[frag1]))
1315       check_ignore = heapinfo1->busy_frag.ignore[frag1];
1316
1317   } else {
1318     if (match_pairs)
1319       xbt_dynar_free(&previous);
1320     return 1;
1321   }
1322
1323
1324   /* Start comparison */
1325   if (type)
1326     res_compare =
1327         compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1328                                     previous, type, size, check_ignore,
1329                                     pointer_level);
1330   else
1331     res_compare =
1332         compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1333                                        previous, size, check_ignore);
1334
1335   if (res_compare == 1) {
1336     if (match_pairs)
1337       xbt_dynar_free(&previous);
1338     return res_compare;
1339   }
1340
1341   if (match_pairs) {
1342     state->match_equals(previous);
1343     xbt_dynar_free(&previous);
1344   }
1345
1346   return 0;
1347 }
1348
1349 }
1350 }