Logo AND Algorithmique Numérique Distribuée

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