1 /* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /** \file compare.cpp Memory snapshooting and comparison */
8 #include "src/mc/mc_config.hpp"
9 #include "src/mc/mc_private.hpp"
10 #include "src/mc/mc_smx.hpp"
11 #include "src/mc/sosp/Snapshot.hpp"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, xbt, "Logging specific to mc_compare in mc");
19 typedef std::array<HeapLocation, 2> HeapLocationPair;
20 typedef std::set<HeapLocationPair> HeapLocationPairs;
22 struct ProcessComparisonState;
23 struct StateComparator;
25 static int compare_heap_area(StateComparator& state, const void* area1, const void* area2, Snapshot* snapshot1,
26 Snapshot* snapshot2, HeapLocationPairs* previous, Type* type, int pointer_level);
30 using simgrid::mc::remote;
32 /*********************************** Heap comparison ***********************************/
33 /***************************************************************************************/
43 HeapLocation() = default;
44 HeapLocation(int block, int fragment = 0) : block_(block), fragment_(fragment) {}
46 bool operator==(HeapLocation const& that) const
48 return block_ == that.block_ && fragment_ == that.fragment_;
50 bool operator<(HeapLocation const& that) const
52 return std::make_pair(block_, fragment_) < std::make_pair(that.block_, that.fragment_);
57 HeapLocationPair makeHeapLocationPair(int block1, int fragment1, int block2, int fragment2)
59 return simgrid::mc::HeapLocationPair{{
60 simgrid::mc::HeapLocation(block1, fragment1),
61 simgrid::mc::HeapLocation(block2, fragment2)
65 class HeapArea : public HeapLocation {
69 explicit HeapArea(int block) : valid_(true) { block_ = block; }
70 HeapArea(int block, int fragment) : valid_(true)
77 class ProcessComparisonState {
79 std::vector<simgrid::mc::IgnoredHeapRegion>* to_ignore = nullptr;
80 std::vector<HeapArea> equals_to;
81 std::vector<simgrid::mc::Type*> types;
82 std::size_t heapsize = 0;
84 void initHeapInformation(xbt_mheap_t heap, std::vector<simgrid::mc::IgnoredHeapRegion>* i);
89 /** A hash which works with more stuff
91 * It can hash pairs: the standard hash currently doesn't include this.
93 template <class X> class hash : public std::hash<X> {
96 template <class X, class Y> class hash<std::pair<X, Y>> {
98 std::size_t operator()(std::pair<X,Y>const& x) const
102 return h1(x.first) ^ h2(x.second);
108 class StateComparator {
110 s_xbt_mheap_t std_heap_copy;
111 std::size_t heaplimit;
112 std::array<ProcessComparisonState, 2> processStates;
114 std::unordered_set<std::pair<void*, void*>, hash<std::pair<void*, void*>>> compared_pointers;
118 compared_pointers.clear();
121 int initHeapInformation(
122 xbt_mheap_t heap1, xbt_mheap_t heap2,
123 std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
124 std::vector<simgrid::mc::IgnoredHeapRegion>* i2);
126 HeapArea& equals_to1_(std::size_t i, std::size_t j)
128 return processStates[0].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
130 HeapArea& equals_to2_(std::size_t i, std::size_t j)
132 return processStates[1].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
134 Type*& types1_(std::size_t i, std::size_t j)
136 return processStates[0].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
138 Type*& types2_(std::size_t i, std::size_t j)
140 return processStates[1].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
143 HeapArea const& equals_to1_(std::size_t i, std::size_t j) const
145 return processStates[0].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
147 HeapArea const& equals_to2_(std::size_t i, std::size_t j) const
149 return processStates[1].equals_to[ MAX_FRAGMENT_PER_BLOCK * i + j];
151 Type* const& types1_(std::size_t i, std::size_t j) const
153 return processStates[0].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
155 Type* const& types2_(std::size_t i, std::size_t j) const
157 return processStates[1].types[ MAX_FRAGMENT_PER_BLOCK * i + j];
160 /** Check whether two blocks are known to be matching
162 * @param b1 Block of state 1
163 * @param b2 Block of state 2
164 * @return if the blocks are known to be matching
166 bool blocksEqual(int b1, int b2) const
168 return this->equals_to1_(b1, 0).block_ == b2 && this->equals_to2_(b2, 0).block_ == b1;
171 /** Check whether two fragments are known to be matching
173 * @param b1 Block of state 1
174 * @param f1 Fragment of state 1
175 * @param b2 Block of state 2
176 * @param f2 Fragment of state 2
177 * @return if the fragments are known to be matching
179 int fragmentsEqual(int b1, int f1, int b2, int f2) const
181 return this->equals_to1_(b1, f1).block_ == b2 && this->equals_to1_(b1, f1).fragment_ == f2 &&
182 this->equals_to2_(b2, f2).block_ == b1 && this->equals_to2_(b2, f2).fragment_ == f1;
185 void match_equals(HeapLocationPairs* list);
191 /************************************************************************************/
193 static ssize_t heap_comparison_ignore_size(
194 std::vector<simgrid::mc::IgnoredHeapRegion>* ignore_list,
198 int end = ignore_list->size() - 1;
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)
205 if (region.address < address)
207 if (region.address > address)
214 static bool is_stack(const void *address)
216 for (auto const& stack : mc_model_checker->process().stack_areas())
217 if (address == stack.address)
222 // TODO, this should depend on the snapshot?
223 static bool is_block_stack(int block)
225 for (auto const& stack : mc_model_checker->process().stack_areas())
226 if (block == stack.block)
234 void StateComparator::match_equals(HeapLocationPairs* list)
236 for (auto const& pair : *list) {
237 if (pair[0].fragment_ != -1) {
238 this->equals_to1_(pair[0].block_, pair[0].fragment_) = simgrid::mc::HeapArea(pair[1].block_, pair[1].fragment_);
239 this->equals_to2_(pair[1].block_, pair[1].fragment_) = simgrid::mc::HeapArea(pair[0].block_, pair[0].fragment_);
241 this->equals_to1_(pair[0].block_, 0) = simgrid::mc::HeapArea(pair[1].block_, pair[1].fragment_);
242 this->equals_to2_(pair[1].block_, 0) = simgrid::mc::HeapArea(pair[0].block_, pair[0].fragment_);
247 void ProcessComparisonState::initHeapInformation(xbt_mheap_t heap,
248 std::vector<simgrid::mc::IgnoredHeapRegion>* i)
250 auto heaplimit = heap->heaplimit;
251 this->heapsize = heap->heapsize;
253 this->equals_to.assign(heaplimit * MAX_FRAGMENT_PER_BLOCK, HeapArea());
254 this->types.assign(heaplimit * MAX_FRAGMENT_PER_BLOCK, nullptr);
257 int StateComparator::initHeapInformation(xbt_mheap_t heap1, xbt_mheap_t heap2,
258 std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
259 std::vector<simgrid::mc::IgnoredHeapRegion>* i2)
261 if ((heap1->heaplimit != heap2->heaplimit) || (heap1->heapsize != heap2->heapsize))
263 this->heaplimit = heap1->heaplimit;
264 this->std_heap_copy = *mc_model_checker->process().get_heap();
265 this->processStates[0].initHeapInformation(heap1, i1);
266 this->processStates[1].initHeapInformation(heap2, i2);
270 // TODO, have a robust way to find it in O(1)
271 static inline Region* MC_get_heap_region(Snapshot* snapshot)
273 for (auto const& region : snapshot->snapshot_regions_)
274 if (region->region_type() == simgrid::mc::RegionType::Heap)
276 xbt_die("No heap region");
279 static bool mmalloc_heap_equal(simgrid::mc::StateComparator& state, simgrid::mc::Snapshot* snapshot1,
280 simgrid::mc::Snapshot* snapshot2)
282 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
284 /* Start comparison */
289 /* Check busy blocks */
292 malloc_info heapinfo_temp1;
293 malloc_info heapinfo_temp2;
294 malloc_info heapinfo_temp2b;
296 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
297 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
299 // This is the address of std_heap->heapinfo in the application process:
300 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
302 // This is in snapshot do not use them directly:
303 const malloc_info* heapinfos1 =
304 snapshot1->read<malloc_info*>(RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address));
305 const malloc_info* heapinfos2 =
306 snapshot2->read<malloc_info*>(RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address));
308 while (i1 < state.heaplimit) {
310 const malloc_info* heapinfo1 =
311 (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
312 const malloc_info* heapinfo2 =
313 (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
315 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
320 if (heapinfo1->type < 0) {
321 fprintf(stderr, "Unkown mmalloc block type.\n");
325 void* addr_block1 = ((void*)(((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase));
327 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
329 if (is_stack(addr_block1)) {
330 for (size_t k = 0; k < heapinfo1->busy_block.size; k++)
331 state.equals_to1_(i1 + k, 0) = HeapArea(i1, -1);
332 for (size_t k = 0; k < heapinfo2->busy_block.size; k++)
333 state.equals_to2_(i1 + k, 0) = HeapArea(i1, -1);
334 i1 += heapinfo1->busy_block.size;
338 if (state.equals_to1_(i1, 0).valid_) {
346 /* Try first to associate to same block in the other heap */
347 if (heapinfo2->type == heapinfo1->type && state.equals_to2_(i1, 0).valid_ == 0) {
348 void* addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
349 int res_compare = compare_heap_area(state, addr_block1, addr_block2, snapshot1, snapshot2, nullptr, nullptr, 0);
350 if (res_compare != 1) {
351 for (size_t k = 1; k < heapinfo2->busy_block.size; k++)
352 state.equals_to2_(i1 + k, 0) = HeapArea(i1, -1);
353 for (size_t k = 1; k < heapinfo1->busy_block.size; k++)
354 state.equals_to1_(i1 + k, 0) = HeapArea(i1, -1);
356 i1 += heapinfo1->busy_block.size;
360 while (i2 < state.heaplimit && not equal) {
362 void* addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
369 const malloc_info* heapinfo2b =
370 (const malloc_info*)heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
372 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
377 if (state.equals_to2_(i2, 0).valid_) {
382 int res_compare = compare_heap_area(state, addr_block1, addr_block2, snapshot1, snapshot2, nullptr, nullptr, 0);
384 if (res_compare != 1) {
385 for (size_t k = 1; k < heapinfo2b->busy_block.size; k++)
386 state.equals_to2_(i2 + k, 0) = HeapArea(i1, -1);
387 for (size_t k = 1; k < heapinfo1->busy_block.size; k++)
388 state.equals_to1_(i1 + k, 0) = HeapArea(i2, -1);
390 i1 += heapinfo1->busy_block.size;
397 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1, heapinfo1->busy_block.busy_size, addr_block1);
398 i1 = state.heaplimit + 1;
402 } else { /* Fragmented block */
404 for (size_t j1 = 0; j1 < (size_t)(BLOCKSIZE >> heapinfo1->type); j1++) {
406 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment_ */
409 if (state.equals_to1_(i1, j1).valid_)
412 void* addr_frag1 = (void*)((char*)addr_block1 + (j1 << heapinfo1->type));
417 /* Try first to associate to same fragment_ in the other heap */
418 if (heapinfo2->type == heapinfo1->type && not state.equals_to2_(i1, j1).valid_) {
419 void* addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
420 void* addr_frag2 = (void*)((char*)addr_block2 + (j1 << heapinfo2->type));
421 int res_compare = compare_heap_area(state, addr_frag1, addr_frag2, snapshot1, snapshot2, nullptr, nullptr, 0);
422 if (res_compare != 1)
426 while (i2 < state.heaplimit && not equal) {
428 const malloc_info* heapinfo2b =
429 (const malloc_info*)heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
431 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
436 // We currently do not match fragments with unfragmented blocks (maybe we should).
437 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
442 if (heapinfo2b->type < 0) {
443 fprintf(stderr, "Unknown mmalloc block type.\n");
447 for (size_t j2 = 0; j2 < (size_t)(BLOCKSIZE >> heapinfo2b->type); j2++) {
449 if (i2 == i1 && j2 == j1)
452 if (state.equals_to2_(i2, j2).valid_)
455 void* addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
456 void* addr_frag2 = (void*)((char*)addr_block2 + (j2 << heapinfo2b->type));
459 compare_heap_area(state, addr_frag1, addr_frag2, snapshot2, snapshot2, nullptr, nullptr, 0);
460 if (res_compare != 1) {
470 XBT_DEBUG("Block %zu, fragment_ %zu not found (size_used = %zd, address = %p)\n", i1, j1,
471 heapinfo1->busy_frag.frag_size[j1], addr_frag1);
472 i1 = state.heaplimit + 1;
482 /* All blocks/fragments are equal to another block/fragment_ ? */
483 for (size_t i = 1; i < state.heaplimit; i++) {
484 const malloc_info* heapinfo1 =
485 (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
487 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo1->busy_block.busy_size > 0 &&
488 not state.equals_to1_(i, 0).valid_) {
489 XBT_DEBUG("Block %zu not found (size used = %zu)", i, heapinfo1->busy_block.busy_size);
493 if (heapinfo1->type <= 0)
495 for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo1->type); j++)
496 if (i1 == state.heaplimit && heapinfo1->busy_frag.frag_size[j] > 0 && not state.equals_to1_(i, j).valid_) {
497 XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)", i, j, heapinfo1->busy_frag.frag_size[j]);
502 if (i1 == state.heaplimit)
503 XBT_DEBUG("Number of blocks/fragments not found in heap1: %d", nb_diff1);
505 for (size_t i = 1; i < state.heaplimit; i++) {
506 const malloc_info* heapinfo2 =
507 (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
508 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo2->busy_block.busy_size > 0 &&
509 not state.equals_to2_(i, 0).valid_) {
510 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
511 heapinfo2->busy_block.busy_size);
515 if (heapinfo2->type <= 0)
518 for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo2->type); j++)
519 if (i1 == state.heaplimit && heapinfo2->busy_frag.frag_size[j] > 0 && not state.equals_to2_(i, j).valid_) {
520 XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)",
521 i, j, heapinfo2->busy_frag.frag_size[j]);
527 if (i1 == state.heaplimit)
528 XBT_DEBUG("Number of blocks/fragments not found in heap2: %d", nb_diff2);
530 return nb_diff1 == 0 && nb_diff2 == 0;
536 * @param real_area1 Process address for state 1
537 * @param real_area2 Process address for state 2
538 * @param snapshot1 Snapshot of state 1
539 * @param snapshot2 Snapshot of state 2
542 * @param check_ignore
544 static int compare_heap_area_without_type(simgrid::mc::StateComparator& state, const void* real_area1,
545 const void* real_area2, simgrid::mc::Snapshot* snapshot1,
546 simgrid::mc::Snapshot* snapshot2, HeapLocationPairs* previous, int size,
549 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
550 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
551 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
553 for (int i = 0; i < size; ) {
555 if (check_ignore > 0) {
556 ssize_t ignore1 = heap_comparison_ignore_size(
557 state.processStates[0].to_ignore, (char *) real_area1 + i);
559 ssize_t ignore2 = heap_comparison_ignore_size(
560 state.processStates[1].to_ignore, (char *) real_area2 + i);
561 if (ignore2 == ignore1) {
574 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
576 int pointer_align = (i / sizeof(void *)) * sizeof(void *);
577 const void* addr_pointed1 = snapshot1->read(remote((void**)((char*)real_area1 + pointer_align)));
578 const void* addr_pointed2 = snapshot2->read(remote((void**)((char*)real_area2 + pointer_align)));
580 if (process->in_maestro_stack(remote(addr_pointed1))
581 && process->in_maestro_stack(remote(addr_pointed2))) {
582 i = pointer_align + sizeof(void *);
586 if (addr_pointed1 > state.std_heap_copy.heapbase
587 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
588 && addr_pointed2 > state.std_heap_copy.heapbase
589 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
590 // Both addreses are in the heap:
592 compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, nullptr, 0);
593 if (res_compare == 1)
595 i = pointer_align + sizeof(void *);
611 * @param real_area1 Process address for state 1
612 * @param real_area2 Process address for state 2
613 * @param snapshot1 Snapshot of state 1
614 * @param snapshot2 Snapshot of state 2
617 * @param area_size either a byte_size or an elements_count (?)
618 * @param check_ignore
619 * @param pointer_level
620 * @return 0 (same), 1 (different), -1 (unknown)
622 static int compare_heap_area_with_type(simgrid::mc::StateComparator& state, const void* real_area1,
623 const void* real_area2, simgrid::mc::Snapshot* snapshot1,
624 simgrid::mc::Snapshot* snapshot2, HeapLocationPairs* previous,
625 simgrid::mc::Type* type, int area_size, int check_ignore, int pointer_level)
629 // HACK: This should not happen but in pratice, there are some
630 // DW_TAG_typedef without an associated DW_AT_type:
631 //<1><538832>: Abbrev Number: 111 (DW_TAG_typedef)
632 // <538833> DW_AT_name : (indirect string, offset: 0x2292f3): gregset_t
633 // <538837> DW_AT_decl_file : 98
634 // <538838> DW_AT_decl_line : 37
638 if (is_stack(real_area1) && is_stack(real_area2))
641 if (check_ignore > 0) {
642 ssize_t ignore1 = heap_comparison_ignore_size(state.processStates[0].to_ignore, real_area1);
643 if (ignore1 > 0 && heap_comparison_ignore_size(state.processStates[1].to_ignore, real_area2) == ignore1)
647 simgrid::mc::Type* subtype;
648 simgrid::mc::Type* subsubtype;
650 const void* addr_pointed1;
651 const void* addr_pointed2;
653 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
654 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
656 switch (type->type) {
657 case DW_TAG_unspecified_type:
660 case DW_TAG_base_type:
661 if (not type->name.empty() && type->name == "char") { /* String, hence random (arbitrary ?) size */
662 if (real_area1 == real_area2)
665 return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0;
667 if (area_size != -1 && type->byte_size != area_size)
670 return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
673 case DW_TAG_enumeration_type:
674 if (area_size != -1 && type->byte_size != area_size)
676 return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
679 case DW_TAG_const_type:
680 case DW_TAG_volatile_type:
682 type = type->subtype;
685 case DW_TAG_array_type:
686 subtype = type->subtype;
687 switch (subtype->type) {
688 case DW_TAG_unspecified_type:
691 case DW_TAG_base_type:
692 case DW_TAG_enumeration_type:
693 case DW_TAG_pointer_type:
694 case DW_TAG_reference_type:
695 case DW_TAG_rvalue_reference_type:
696 case DW_TAG_structure_type:
697 case DW_TAG_class_type:
698 case DW_TAG_union_type:
699 if (subtype->full_type)
700 subtype = subtype->full_type;
701 elm_size = subtype->byte_size;
703 // TODO, just remove the type indirection?
704 case DW_TAG_const_type:
706 case DW_TAG_volatile_type:
707 subsubtype = subtype->subtype;
708 if (subsubtype->full_type)
709 subsubtype = subsubtype->full_type;
710 elm_size = subsubtype->byte_size;
715 for (int i = 0; i < type->element_count; i++) {
716 // TODO, add support for variable stride (DW_AT_byte_stride)
717 int res = compare_heap_area_with_type(state, (char*)real_area1 + (i * elm_size),
718 (char*)real_area2 + (i * elm_size), snapshot1, snapshot2, previous,
719 type->subtype, subtype->byte_size, check_ignore, pointer_level);
725 case DW_TAG_reference_type:
726 case DW_TAG_rvalue_reference_type:
727 case DW_TAG_pointer_type:
728 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
729 addr_pointed1 = snapshot1->read(remote((void**)real_area1));
730 addr_pointed2 = snapshot2->read(remote((void**)real_area2));
731 return (addr_pointed1 != addr_pointed2);
734 if (pointer_level <= 1) {
735 addr_pointed1 = snapshot1->read(remote((void**)real_area1));
736 addr_pointed2 = snapshot2->read(remote((void**)real_area2));
737 if (addr_pointed1 > state.std_heap_copy.heapbase && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1) &&
738 addr_pointed2 > state.std_heap_copy.heapbase && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
739 return compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype,
742 return (addr_pointed1 != addr_pointed2);
744 for (size_t i = 0; i < (area_size / sizeof(void*)); i++) {
745 addr_pointed1 = snapshot1->read(remote((void**)((char*)real_area1 + i * sizeof(void*))));
746 addr_pointed2 = snapshot2->read(remote((void**)((char*)real_area2 + i * sizeof(void*))));
748 if (addr_pointed1 > state.std_heap_copy.heapbase && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1) &&
749 addr_pointed2 > state.std_heap_copy.heapbase && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
750 res = compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype,
753 res = (addr_pointed1 != addr_pointed2);
759 case DW_TAG_structure_type:
760 case DW_TAG_class_type:
762 type = type->full_type;
763 if (area_size != -1 && type->byte_size != area_size) {
764 if (area_size <= type->byte_size || area_size % type->byte_size != 0)
766 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
767 int res = compare_heap_area_with_type(state, (char*)real_area1 + i * type->byte_size,
768 (char*)real_area2 + i * type->byte_size, snapshot1, snapshot2,
769 previous, type, -1, check_ignore, 0);
774 for (simgrid::mc::Member& member : type->members) {
775 // TODO, optimize this? (for the offset case)
777 simgrid::dwarf::resolve_member(real_area1, type, &member, (simgrid::mc::AddressSpace*)snapshot1);
779 simgrid::dwarf::resolve_member(real_area2, type, &member, (simgrid::mc::AddressSpace*)snapshot2);
780 int res = compare_heap_area_with_type(state, real_member1, real_member2, snapshot1, snapshot2, previous,
781 member.type, -1, check_ignore, 0);
788 case DW_TAG_union_type:
789 return compare_heap_area_without_type(state, real_area1, real_area2, snapshot1, snapshot2, previous,
790 type->byte_size, check_ignore);
796 xbt_die("Unreachable");
800 /** Infer the type of a part of the block from the type of the block
802 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
804 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
806 * @param type DWARF type ID of the root address
808 * @return DWARF type ID for given offset
810 static simgrid::mc::Type* get_offset_type(void* real_base_address, simgrid::mc::Type* type, int offset, int area_size,
811 simgrid::mc::Snapshot* snapshot)
814 // Beginning of the block, the infered variable type if the type of the block:
818 switch (type->type) {
820 case DW_TAG_structure_type:
821 case DW_TAG_class_type:
823 type = type->full_type;
824 if (area_size != -1 && type->byte_size != area_size) {
825 if (area_size > type->byte_size && area_size % type->byte_size == 0)
831 for (simgrid::mc::Member& member : type->members) {
832 if (member.has_offset_location()) {
833 // We have the offset, use it directly (shortcut):
834 if (member.offset() == offset)
837 void* real_member = simgrid::dwarf::resolve_member(real_base_address, type, &member, snapshot);
838 if ((char*)real_member - (char*)real_base_address == offset)
845 /* FIXME: other cases ? */
853 * @param area1 Process address for state 1
854 * @param area2 Process address for state 2
855 * @param snapshot1 Snapshot of state 1
856 * @param snapshot2 Snapshot of state 2
857 * @param previous Pairs of blocks already compared on the current path (or nullptr)
858 * @param type_id Type of variable
859 * @param pointer_level
860 * @return 0 (same), 1 (different), -1
862 static int compare_heap_area(simgrid::mc::StateComparator& state, const void* area1, const void* area2,
863 simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2,
864 HeapLocationPairs* previous, simgrid::mc::Type* type, int pointer_level)
866 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
871 int check_ignore = 0;
879 simgrid::mc::Type* new_type1 = nullptr;
880 simgrid::mc::Type* new_type2 = nullptr;
882 bool match_pairs = false;
884 // This is the address of std_heap->heapinfo in the application process:
885 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
887 const malloc_info* heapinfos1 = snapshot1->read(remote((const malloc_info**)heapinfo_address));
888 const malloc_info* heapinfos2 = snapshot2->read(remote((const malloc_info**)heapinfo_address));
890 malloc_info heapinfo_temp1;
891 malloc_info heapinfo_temp2;
893 simgrid::mc::HeapLocationPairs current;
894 if (previous == nullptr) {
900 block1 = ((char*)area1 - (char*)state.std_heap_copy.heapbase) / BLOCKSIZE + 1;
901 block2 = ((char*)area2 - (char*)state.std_heap_copy.heapbase) / BLOCKSIZE + 1;
903 // If either block is a stack block:
904 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
905 previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1));
907 state.match_equals(previous);
911 // If either block is not in the expected area of memory:
912 if (((char*)area1 < (char*)state.std_heap_copy.heapbase) || (block1 > (ssize_t)state.processStates[0].heapsize) ||
913 (block1 < 1) || ((char*)area2 < (char*)state.std_heap_copy.heapbase) ||
914 (block2 > (ssize_t)state.processStates[1].heapsize) || (block2 < 1)) {
918 // Process address of the block:
919 void* real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
920 void* real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
924 type = type->full_type;
926 // This assume that for "boring" types (volatile ...) byte_size is absent:
927 while (type->byte_size == 0 && type->subtype != nullptr)
928 type = type->subtype;
931 if (type->type == DW_TAG_pointer_type ||
932 (type->type == DW_TAG_base_type && not type->name.empty() && type->name == "char"))
935 type_size = type->byte_size;
939 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
940 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
942 const malloc_info* heapinfo1 =
943 (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
944 const malloc_info* heapinfo2 =
945 (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
947 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
948 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
951 state.match_equals(previous);
955 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
958 // TODO, lookup variable type from block type as done for fragmented blocks
960 if (state.equals_to1_(block1, 0).valid_ && state.equals_to2_(block2, 0).valid_ &&
961 state.blocksEqual(block1, block2)) {
963 state.match_equals(previous);
967 if (type_size != -1 && type_size != (ssize_t)heapinfo1->busy_block.busy_size &&
968 type_size != (ssize_t)heapinfo2->busy_block.busy_size &&
969 (type->name.empty() || type->name == "struct s_smx_context")) {
971 state.match_equals(previous);
975 if (heapinfo1->busy_block.size != heapinfo2->busy_block.size)
977 if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size)
980 if (not previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1)).second) {
982 state.match_equals(previous);
986 size = heapinfo1->busy_block.busy_size;
988 // Remember (basic) type inference.
989 // The current data structure only allows us to do this for the whole block.
990 if (type != nullptr && area1 == real_addr_block1)
991 state.types1_(block1, 0) = type;
992 if (type != nullptr && area2 == real_addr_block2)
993 state.types2_(block2, 0) = type;
997 state.match_equals(previous);
1001 if (heapinfo1->busy_block.ignore > 0
1002 && heapinfo2->busy_block.ignore == heapinfo1->busy_block.ignore)
1003 check_ignore = heapinfo1->busy_block.ignore;
1005 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1008 ssize_t frag1 = ((uintptr_t)(ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1009 ssize_t frag2 = ((uintptr_t)(ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1011 // Process address of the fragment_:
1012 void* real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type));
1013 void* real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type));
1015 // Check the size of the fragments against the size of the type:
1016 if (type_size != -1) {
1017 if (heapinfo1->busy_frag.frag_size[frag1] == -1 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1019 state.match_equals(previous);
1023 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1024 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1026 state.match_equals(previous);
1031 // Check if the blocks are already matched together:
1032 if (state.equals_to1_(block1, frag1).valid_ && state.equals_to2_(block2, frag2).valid_ && offset1 == offset2 &&
1033 state.fragmentsEqual(block1, frag1, block2, frag2)) {
1035 state.match_equals(previous);
1038 // Compare the size of both fragments:
1039 if (heapinfo1->busy_frag.frag_size[frag1] != heapinfo2->busy_frag.frag_size[frag2]) {
1040 if (type_size == -1) {
1042 state.match_equals(previous);
1048 // Size of the fragment_:
1049 size = heapinfo1->busy_frag.frag_size[frag1];
1051 // Remember (basic) type inference.
1052 // The current data structure only allows us to do this for the whole fragment_.
1053 if (type != nullptr && area1 == real_addr_frag1)
1054 state.types1_(block1, frag1) = type;
1055 if (type != nullptr && area2 == real_addr_frag2)
1056 state.types2_(block2, frag2) = type;
1058 // The type of the variable is already known:
1060 new_type1 = new_type2 = type;
1062 // Type inference from the block type.
1063 else if (state.types1_(block1, frag1) != nullptr || state.types2_(block2, frag2) != nullptr) {
1065 offset1 = (char*)area1 - (char*)real_addr_frag1;
1066 offset2 = (char*)area2 - (char*)real_addr_frag2;
1068 if (state.types1_(block1, frag1) != nullptr && state.types2_(block2, frag2) != nullptr) {
1069 new_type1 = get_offset_type(real_addr_frag1, state.types1_(block1, frag1), offset1, size, snapshot1);
1070 new_type2 = get_offset_type(real_addr_frag2, state.types2_(block2, frag2), offset1, size, snapshot2);
1071 } else if (state.types1_(block1, frag1) != nullptr) {
1072 new_type1 = get_offset_type(real_addr_frag1, state.types1_(block1, frag1), offset1, size, snapshot1);
1073 new_type2 = get_offset_type(real_addr_frag2, state.types1_(block1, frag1), offset2, size, snapshot2);
1074 } else if (state.types2_(block2, frag2) != nullptr) {
1075 new_type1 = get_offset_type(real_addr_frag1, state.types2_(block2, frag2), offset1, size, snapshot1);
1076 new_type2 = get_offset_type(real_addr_frag2, state.types2_(block2, frag2), offset2, size, snapshot2);
1079 state.match_equals(previous);
1083 if (new_type1 != nullptr && new_type2 != nullptr && new_type1 != new_type2) {
1086 while (type->byte_size == 0 && type->subtype != nullptr)
1087 type = type->subtype;
1088 new_size1 = type->byte_size;
1091 while (type->byte_size == 0 && type->subtype != nullptr)
1092 type = type->subtype;
1093 new_size2 = type->byte_size;
1097 state.match_equals(previous);
1102 if (new_size1 > 0 && new_size1 == new_size2) {
1107 if (offset1 == 0 && offset2 == 0 &&
1108 not previous->insert(simgrid::mc::makeHeapLocationPair(block1, frag1, block2, frag2)).second) {
1110 state.match_equals(previous);
1116 state.match_equals(previous);
1120 if ((heapinfo1->busy_frag.ignore[frag1] > 0) &&
1121 (heapinfo2->busy_frag.ignore[frag2] == heapinfo1->busy_frag.ignore[frag1]))
1122 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1128 /* Start comparison */
1131 res_compare = compare_heap_area_with_type(state, area1, area2, snapshot1, snapshot2, previous, type, size,
1132 check_ignore, pointer_level);
1135 compare_heap_area_without_type(state, area1, area2, snapshot1, snapshot2, previous, size, check_ignore);
1137 if (res_compare == 1)
1141 state.match_equals(previous);
1148 /************************** Snapshot comparison *******************************/
1149 /******************************************************************************/
1151 static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* real_area1,
1152 simgrid::mc::Snapshot* snapshot1, simgrid::mc::Region* region1, void* real_area2,
1153 simgrid::mc::Snapshot* snapshot2, simgrid::mc::Region* region2,
1154 simgrid::mc::Type* type, int pointer_level)
1156 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
1158 simgrid::mc::Type* subtype;
1159 simgrid::mc::Type* subsubtype;
1165 xbt_assert(type != nullptr);
1166 switch (type->type) {
1167 case DW_TAG_unspecified_type:
1170 case DW_TAG_base_type:
1171 case DW_TAG_enumeration_type:
1172 case DW_TAG_union_type:
1173 return MC_snapshot_region_memcmp(real_area1, region1, real_area2, region2, type->byte_size) != 0;
1174 case DW_TAG_typedef:
1175 case DW_TAG_volatile_type:
1176 case DW_TAG_const_type:
1178 type = type->subtype;
1179 continue; // restart
1180 case DW_TAG_array_type:
1181 subtype = type->subtype;
1182 switch (subtype->type) {
1183 case DW_TAG_unspecified_type:
1186 case DW_TAG_base_type:
1187 case DW_TAG_enumeration_type:
1188 case DW_TAG_pointer_type:
1189 case DW_TAG_reference_type:
1190 case DW_TAG_rvalue_reference_type:
1191 case DW_TAG_structure_type:
1192 case DW_TAG_class_type:
1193 case DW_TAG_union_type:
1194 if (subtype->full_type)
1195 subtype = subtype->full_type;
1196 elm_size = subtype->byte_size;
1198 case DW_TAG_const_type:
1199 case DW_TAG_typedef:
1200 case DW_TAG_volatile_type:
1201 subsubtype = subtype->subtype;
1202 if (subsubtype->full_type)
1203 subsubtype = subsubtype->full_type;
1204 elm_size = subsubtype->byte_size;
1209 for (i = 0; i < type->element_count; i++) {
1210 size_t off = i * elm_size;
1211 res = compare_areas_with_type(state, (char*)real_area1 + off, snapshot1, region1, (char*)real_area2 + off,
1212 snapshot2, region2, type->subtype, pointer_level);
1217 case DW_TAG_pointer_type:
1218 case DW_TAG_reference_type:
1219 case DW_TAG_rvalue_reference_type: {
1220 void* addr_pointed1 = MC_region_read_pointer(region1, real_area1);
1221 void* addr_pointed2 = MC_region_read_pointer(region2, real_area2);
1223 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type)
1224 return (addr_pointed1 != addr_pointed2);
1225 if (addr_pointed1 == nullptr && addr_pointed2 == nullptr)
1227 if (addr_pointed1 == nullptr || addr_pointed2 == nullptr)
1229 if (not state.compared_pointers.insert(std::make_pair(addr_pointed1, addr_pointed2)).second)
1234 // Some cases are not handled here:
1235 // * the pointers lead to different areas (one to the heap, the other to the RW segment ...)
1236 // * a pointer leads to the read-only segment of the current object
1237 // * a pointer lead to a different ELF object
1239 if (addr_pointed1 > process->heap_address && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)) {
1240 if (not(addr_pointed2 > process->heap_address && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)))
1242 // The pointers are both in the heap:
1243 return simgrid::mc::compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, nullptr,
1244 type->subtype, pointer_level);
1246 } else if (region1->contain(simgrid::mc::remote(addr_pointed1))) {
1247 // The pointers are both in the current object R/W segment:
1248 if (not region2->contain(simgrid::mc::remote(addr_pointed2)))
1250 if (not type->type_id)
1251 return (addr_pointed1 != addr_pointed2);
1253 return compare_areas_with_type(state, addr_pointed1, snapshot1, region1, addr_pointed2, snapshot2, region2,
1254 type->subtype, pointer_level);
1257 // TODO, We do not handle very well the case where
1258 // it belongs to a different (non-heap) region from the current one.
1260 return (addr_pointed1 != addr_pointed2);
1263 case DW_TAG_structure_type:
1264 case DW_TAG_class_type:
1265 for (simgrid::mc::Member& member : type->members) {
1266 void* member1 = simgrid::dwarf::resolve_member(real_area1, type, &member, snapshot1);
1267 void* member2 = simgrid::dwarf::resolve_member(real_area2, type, &member, snapshot2);
1268 simgrid::mc::Region* subregion1 = snapshot1->get_region(member1, region1); // region1 is hinted
1269 simgrid::mc::Region* subregion2 = snapshot2->get_region(member2, region2); // region2 is hinted
1270 res = compare_areas_with_type(state, member1, snapshot1, subregion1, member2, snapshot2, subregion2,
1271 member.type, pointer_level);
1276 case DW_TAG_subroutine_type:
1279 XBT_VERB("Unknown case: %d", type->type);
1287 static bool global_variables_equal(simgrid::mc::StateComparator& state, simgrid::mc::ObjectInformation* object_info,
1288 simgrid::mc::Region* r1, simgrid::mc::Region* r2, simgrid::mc::Snapshot* snapshot1,
1289 simgrid::mc::Snapshot* snapshot2)
1291 xbt_assert(r1 && r2, "Missing region.");
1293 std::vector<simgrid::mc::Variable>& variables = object_info->global_variables;
1295 for (simgrid::mc::Variable const& current_var : variables) {
1297 // If the variable is not in this object, skip it:
1298 // We do not expect to find a pointer to something which is not reachable
1299 // by the global variables.
1300 if ((char *) current_var.address < (char *) object_info->start_rw
1301 || (char *) current_var.address > (char *) object_info->end_rw)
1304 simgrid::mc::Type* bvariable_type = current_var.type;
1305 int res = compare_areas_with_type(state, (char*)current_var.address, snapshot1, r1, (char*)current_var.address,
1306 snapshot2, r2, bvariable_type, 0);
1308 XBT_VERB("Global variable %s (%p) is different between snapshots",
1309 current_var.name.c_str(),
1310 (char *) current_var.address);
1318 static bool local_variables_equal(simgrid::mc::StateComparator& state, simgrid::mc::Snapshot* snapshot1,
1319 simgrid::mc::Snapshot* snapshot2, mc_snapshot_stack_t stack1,
1320 mc_snapshot_stack_t stack2)
1322 if (stack1->local_variables.size() != stack2->local_variables.size()) {
1323 XBT_VERB("Different number of local variables");
1327 for (unsigned int cursor = 0; cursor < stack1->local_variables.size(); cursor++) {
1328 local_variable_t current_var1 = &stack1->local_variables[cursor];
1329 local_variable_t current_var2 = &stack2->local_variables[cursor];
1330 if (current_var1->name != current_var2->name || current_var1->subprogram != current_var2->subprogram ||
1331 current_var1->ip != current_var2->ip) {
1332 // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
1333 XBT_VERB("Different name of variable (%s - %s) "
1334 "or frame (%s - %s) or ip (%lu - %lu)",
1335 current_var1->name.c_str(), current_var2->name.c_str(), current_var1->subprogram->name.c_str(),
1336 current_var2->subprogram->name.c_str(), current_var1->ip, current_var2->ip);
1339 // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
1341 if (compare_areas_with_type(state, current_var1->address, snapshot1, snapshot1->get_region(current_var1->address),
1342 current_var2->address, snapshot2, snapshot2->get_region(current_var2->address),
1343 current_var1->type, 0) == 1) {
1344 // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
1345 XBT_VERB("Local variable %s (%p - %p) in frame %s "
1346 "is different between snapshots",
1347 current_var1->name.c_str(), current_var1->address, current_var2->address,
1348 current_var1->subprogram->name.c_str());
1358 static std::unique_ptr<simgrid::mc::StateComparator> state_comparator;
1360 bool snapshot_equal(Snapshot* s1, Snapshot* s2)
1362 // TODO, make this a field of ModelChecker or something similar
1363 if (state_comparator == nullptr)
1364 state_comparator.reset(new StateComparator());
1366 state_comparator->clear();
1368 RemoteClient* process = &mc_model_checker->process();
1370 if (s1->hash_ != s2->hash_) {
1371 XBT_VERB("(%d - %d) Different hash: 0x%" PRIx64 "--0x%" PRIx64, s1->num_state_, s2->num_state_, s1->hash_,
1375 XBT_VERB("(%d - %d) Same hash: 0x%" PRIx64, s1->num_state_, s2->num_state_, s1->hash_);
1377 /* Compare enabled processes */
1378 if (s1->enabled_processes_ != s2->enabled_processes_) {
1379 XBT_VERB("(%d - %d) Different amount of enabled processes", s1->num_state_, s2->num_state_);
1383 /* Compare size of stacks */
1384 for (unsigned long i = 0; i < s1->stacks_.size(); i++) {
1385 size_t size_used1 = s1->stack_sizes_[i];
1386 size_t size_used2 = s2->stack_sizes_[i];
1387 if (size_used1 != size_used2) {
1388 XBT_VERB("(%d - %d) Different size used in stacks: %zu - %zu", s1->num_state_, s2->num_state_, size_used1,
1394 /* Init heap information used in heap comparison algorithm */
1395 xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
1396 remote(process->heap_address), simgrid::mc::ReadOptions::lazy());
1397 xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes(alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
1398 remote(process->heap_address), simgrid::mc::ReadOptions::lazy());
1399 int res_init = state_comparator->initHeapInformation(heap1, heap2, &s1->to_ignore_, &s2->to_ignore_);
1401 if (res_init == -1) {
1402 XBT_VERB("(%d - %d) Different heap information", s1->num_state_, s2->num_state_);
1406 /* Stacks comparison */
1407 for (unsigned int cursor = 0; cursor < s1->stacks_.size(); cursor++) {
1408 mc_snapshot_stack_t stack1 = &s1->stacks_[cursor];
1409 mc_snapshot_stack_t stack2 = &s2->stacks_[cursor];
1411 if (not local_variables_equal(*state_comparator, s1, s2, stack1, stack2)) {
1412 XBT_VERB("(%d - %d) Different local variables between stacks %u", s1->num_state_, s2->num_state_, cursor + 1);
1417 size_t regions_count = s1->snapshot_regions_.size();
1418 if (regions_count != s2->snapshot_regions_.size())
1421 for (size_t k = 0; k != regions_count; ++k) {
1422 Region* region1 = s1->snapshot_regions_[k].get();
1423 Region* region2 = s2->snapshot_regions_[k].get();
1426 if (region1->region_type() != RegionType::Data)
1429 xbt_assert(region1->region_type() == region2->region_type());
1430 xbt_assert(region1->object_info() == region2->object_info());
1431 xbt_assert(region1->object_info());
1433 /* Compare global variables */
1434 if (not global_variables_equal(*state_comparator, region1->object_info(), region1, region2, s1, s2)) {
1435 std::string const& name = region1->object_info()->file_name;
1436 XBT_VERB("(%d - %d) Different global variables in %s", s1->num_state_, s2->num_state_, name.c_str());
1442 if (not mmalloc_heap_equal(*state_comparator, s1, s2)) {
1443 XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", s1->num_state_, s2->num_state_);
1447 XBT_VERB("(%d - %d) No difference found", s1->num_state_, s2->num_state_);