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");
280 int mmalloc_compare_heap(
281 simgrid::mc::StateComparator& state, simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2)
283 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
285 /* Start comparison */
290 /* Check busy blocks */
293 malloc_info heapinfo_temp1;
294 malloc_info heapinfo_temp2;
295 malloc_info heapinfo_temp2b;
297 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
298 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
300 // This is the address of std_heap->heapinfo in the application process:
301 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
303 // This is in snapshot do not use them directly:
304 const malloc_info* heapinfos1 =
305 snapshot1->read<malloc_info*>(RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address));
306 const malloc_info* heapinfos2 =
307 snapshot2->read<malloc_info*>(RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address));
309 while (i1 < state.heaplimit) {
311 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
312 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
314 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
319 if (heapinfo1->type < 0) {
320 fprintf(stderr, "Unkown mmalloc block type.\n");
324 void* addr_block1 = ((void*)(((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase));
326 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
328 if (is_stack(addr_block1)) {
329 for (size_t k = 0; k < heapinfo1->busy_block.size; k++)
330 state.equals_to1_(i1 + k, 0) = HeapArea(i1, -1);
331 for (size_t k = 0; k < heapinfo2->busy_block.size; k++)
332 state.equals_to2_(i1 + k, 0) = HeapArea(i1, -1);
333 i1 += heapinfo1->busy_block.size;
337 if (state.equals_to1_(i1, 0).valid_) {
345 /* Try first to associate to same block in the other heap */
346 if (heapinfo2->type == heapinfo1->type && state.equals_to2_(i1, 0).valid_ == 0) {
347 void* addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
348 int res_compare = compare_heap_area(state, addr_block1, addr_block2, snapshot1, snapshot2, nullptr, nullptr, 0);
349 if (res_compare != 1) {
350 for (size_t k = 1; k < heapinfo2->busy_block.size; k++)
351 state.equals_to2_(i1 + k, 0) = HeapArea(i1, -1);
352 for (size_t k = 1; k < heapinfo1->busy_block.size; k++)
353 state.equals_to1_(i1 + k, 0) = HeapArea(i1, -1);
355 i1 += heapinfo1->busy_block.size;
359 while (i2 < state.heaplimit && not equal) {
361 void* addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
368 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
370 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
375 if (state.equals_to2_(i2, 0).valid_) {
380 int res_compare = compare_heap_area(state, addr_block1, addr_block2, snapshot1, snapshot2, nullptr, nullptr, 0);
382 if (res_compare != 1) {
383 for (size_t k = 1; k < heapinfo2b->busy_block.size; k++)
384 state.equals_to2_(i2 + k, 0) = HeapArea(i1, -1);
385 for (size_t k = 1; k < heapinfo1->busy_block.size; k++)
386 state.equals_to1_(i1 + k, 0) = HeapArea(i2, -1);
388 i1 += heapinfo1->busy_block.size;
395 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1, heapinfo1->busy_block.busy_size, addr_block1);
396 i1 = state.heaplimit + 1;
400 } else { /* Fragmented block */
402 for (size_t j1 = 0; j1 < (size_t)(BLOCKSIZE >> heapinfo1->type); j1++) {
404 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment_ */
407 if (state.equals_to1_(i1, j1).valid_)
410 void* addr_frag1 = (void*)((char*)addr_block1 + (j1 << heapinfo1->type));
415 /* Try first to associate to same fragment_ in the other heap */
416 if (heapinfo2->type == heapinfo1->type && not state.equals_to2_(i1, j1).valid_) {
417 void* addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
418 void* addr_frag2 = (void*)((char*)addr_block2 + (j1 << heapinfo2->type));
419 int res_compare = compare_heap_area(state, addr_frag1, addr_frag2, snapshot1, snapshot2, nullptr, nullptr, 0);
420 if (res_compare != 1)
424 while (i2 < state.heaplimit && not equal) {
426 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
427 heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
428 sizeof(malloc_info));
430 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
435 // We currently do not match fragments with unfragmented blocks (maybe we should).
436 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
441 if (heapinfo2b->type < 0) {
442 fprintf(stderr, "Unknown mmalloc block type.\n");
446 for (size_t j2 = 0; j2 < (size_t)(BLOCKSIZE >> heapinfo2b->type); j2++) {
448 if (i2 == i1 && j2 == j1)
451 if (state.equals_to2_(i2, j2).valid_)
454 void* addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
455 void* addr_frag2 = (void*)((char*)addr_block2 + (j2 << heapinfo2b->type));
458 compare_heap_area(state, addr_frag1, addr_frag2, snapshot2, snapshot2, nullptr, nullptr, 0);
459 if (res_compare != 1) {
469 XBT_DEBUG("Block %zu, fragment_ %zu not found (size_used = %zd, address = %p)\n", i1, j1,
470 heapinfo1->busy_frag.frag_size[j1], addr_frag1);
471 i1 = state.heaplimit + 1;
481 /* All blocks/fragments are equal to another block/fragment_ ? */
482 for (size_t i = 1; i < state.heaplimit; i++) {
483 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
484 heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
486 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo1->busy_block.busy_size > 0 &&
487 not state.equals_to1_(i, 0).valid_) {
488 XBT_DEBUG("Block %zu not found (size used = %zu)", i, heapinfo1->busy_block.busy_size);
492 if (heapinfo1->type <= 0)
494 for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo1->type); j++)
495 if (i1 == state.heaplimit && heapinfo1->busy_frag.frag_size[j] > 0 && not state.equals_to1_(i, j).valid_) {
496 XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)", i, j, heapinfo1->busy_frag.frag_size[j]);
501 if (i1 == state.heaplimit)
502 XBT_DEBUG("Number of blocks/fragments not found in heap1: %d", nb_diff1);
504 for (size_t i = 1; i < state.heaplimit; i++) {
505 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
506 heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
507 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo2->busy_block.busy_size > 0 &&
508 not state.equals_to2_(i, 0).valid_) {
509 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
510 heapinfo2->busy_block.busy_size);
514 if (heapinfo2->type <= 0)
517 for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo2->type); j++)
518 if (i1 == state.heaplimit && heapinfo2->busy_frag.frag_size[j] > 0 && not state.equals_to2_(i, j).valid_) {
519 XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)",
520 i, j, heapinfo2->busy_frag.frag_size[j]);
526 if (i1 == state.heaplimit)
527 XBT_DEBUG("Number of blocks/fragments not found in heap2: %d", nb_diff2);
529 return nb_diff1 > 0 || nb_diff2 > 0;
535 * @param real_area1 Process address for state 1
536 * @param real_area2 Process address for state 2
537 * @param snapshot1 Snapshot of state 1
538 * @param snapshot2 Snapshot of state 2
541 * @param check_ignore
543 static int compare_heap_area_without_type(simgrid::mc::StateComparator& state, const void* real_area1,
544 const void* real_area2, simgrid::mc::Snapshot* snapshot1,
545 simgrid::mc::Snapshot* snapshot2, HeapLocationPairs* previous, int size,
548 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
549 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
550 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
552 for (int i = 0; i < size; ) {
554 if (check_ignore > 0) {
555 ssize_t ignore1 = heap_comparison_ignore_size(
556 state.processStates[0].to_ignore, (char *) real_area1 + i);
558 ssize_t ignore2 = heap_comparison_ignore_size(
559 state.processStates[1].to_ignore, (char *) real_area2 + i);
560 if (ignore2 == ignore1) {
573 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
575 int pointer_align = (i / sizeof(void *)) * sizeof(void *);
576 const void* addr_pointed1 = snapshot1->read(remote((void**)((char*)real_area1 + pointer_align)));
577 const void* addr_pointed2 = snapshot2->read(remote((void**)((char*)real_area2 + pointer_align)));
579 if (process->in_maestro_stack(remote(addr_pointed1))
580 && process->in_maestro_stack(remote(addr_pointed2))) {
581 i = pointer_align + sizeof(void *);
585 if (addr_pointed1 > state.std_heap_copy.heapbase
586 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
587 && addr_pointed2 > state.std_heap_copy.heapbase
588 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
589 // Both addreses are in the heap:
591 compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, nullptr, 0);
592 if (res_compare == 1)
594 i = pointer_align + sizeof(void *);
610 * @param real_area1 Process address for state 1
611 * @param real_area2 Process address for state 2
612 * @param snapshot1 Snapshot of state 1
613 * @param snapshot2 Snapshot of state 2
616 * @param area_size either a byte_size or an elements_count (?)
617 * @param check_ignore
618 * @param pointer_level
619 * @return 0 (same), 1 (different), -1 (unknown)
621 static int compare_heap_area_with_type(simgrid::mc::StateComparator& state, const void* real_area1,
622 const void* real_area2, simgrid::mc::Snapshot* snapshot1,
623 simgrid::mc::Snapshot* snapshot2, HeapLocationPairs* previous,
624 simgrid::mc::Type* type, int area_size, int check_ignore, int pointer_level)
628 // HACK: This should not happen but in pratice, there are some
629 // DW_TAG_typedef without an associated DW_AT_type:
630 //<1><538832>: Abbrev Number: 111 (DW_TAG_typedef)
631 // <538833> DW_AT_name : (indirect string, offset: 0x2292f3): gregset_t
632 // <538837> DW_AT_decl_file : 98
633 // <538838> DW_AT_decl_line : 37
637 if (is_stack(real_area1) && is_stack(real_area2))
640 if (check_ignore > 0) {
641 ssize_t ignore1 = heap_comparison_ignore_size(state.processStates[0].to_ignore, real_area1);
642 if (ignore1 > 0 && heap_comparison_ignore_size(state.processStates[1].to_ignore, real_area2) == ignore1)
646 simgrid::mc::Type* subtype;
647 simgrid::mc::Type* subsubtype;
649 const void* addr_pointed1;
650 const void* addr_pointed2;
652 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
653 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
655 switch (type->type) {
656 case DW_TAG_unspecified_type:
659 case DW_TAG_base_type:
660 if (not type->name.empty() && type->name == "char") { /* String, hence random (arbitrary ?) size */
661 if (real_area1 == real_area2)
664 return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0;
666 if (area_size != -1 && type->byte_size != area_size)
669 return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
672 case DW_TAG_enumeration_type:
673 if (area_size != -1 && type->byte_size != area_size)
675 return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
678 case DW_TAG_const_type:
679 case DW_TAG_volatile_type:
681 type = type->subtype;
684 case DW_TAG_array_type:
685 subtype = type->subtype;
686 switch (subtype->type) {
687 case DW_TAG_unspecified_type:
690 case DW_TAG_base_type:
691 case DW_TAG_enumeration_type:
692 case DW_TAG_pointer_type:
693 case DW_TAG_reference_type:
694 case DW_TAG_rvalue_reference_type:
695 case DW_TAG_structure_type:
696 case DW_TAG_class_type:
697 case DW_TAG_union_type:
698 if (subtype->full_type)
699 subtype = subtype->full_type;
700 elm_size = subtype->byte_size;
702 // TODO, just remove the type indirection?
703 case DW_TAG_const_type:
705 case DW_TAG_volatile_type:
706 subsubtype = subtype->subtype;
707 if (subsubtype->full_type)
708 subsubtype = subsubtype->full_type;
709 elm_size = subsubtype->byte_size;
714 for (int i = 0; i < type->element_count; i++) {
715 // TODO, add support for variable stride (DW_AT_byte_stride)
716 int res = compare_heap_area_with_type(state, (char*)real_area1 + (i * elm_size),
717 (char*)real_area2 + (i * elm_size), snapshot1, snapshot2, previous,
718 type->subtype, subtype->byte_size, check_ignore, pointer_level);
724 case DW_TAG_reference_type:
725 case DW_TAG_rvalue_reference_type:
726 case DW_TAG_pointer_type:
727 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
728 addr_pointed1 = snapshot1->read(remote((void**)real_area1));
729 addr_pointed2 = snapshot2->read(remote((void**)real_area2));
730 return (addr_pointed1 != addr_pointed2);
733 if (pointer_level <= 1) {
734 addr_pointed1 = snapshot1->read(remote((void**)real_area1));
735 addr_pointed2 = snapshot2->read(remote((void**)real_area2));
736 if (addr_pointed1 > state.std_heap_copy.heapbase && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1) &&
737 addr_pointed2 > state.std_heap_copy.heapbase && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
738 return compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype,
741 return (addr_pointed1 != addr_pointed2);
743 for (size_t i = 0; i < (area_size / sizeof(void*)); i++) {
744 addr_pointed1 = snapshot1->read(remote((void**)((char*)real_area1 + i * sizeof(void*))));
745 addr_pointed2 = snapshot2->read(remote((void**)((char*)real_area2 + i * sizeof(void*))));
747 if (addr_pointed1 > state.std_heap_copy.heapbase && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1) &&
748 addr_pointed2 > state.std_heap_copy.heapbase && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
749 res = compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype,
752 res = (addr_pointed1 != addr_pointed2);
758 case DW_TAG_structure_type:
759 case DW_TAG_class_type:
761 type = type->full_type;
762 if (area_size != -1 && type->byte_size != area_size) {
763 if (area_size <= type->byte_size || area_size % type->byte_size != 0)
765 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
766 int res = compare_heap_area_with_type(state, (char*)real_area1 + i * type->byte_size,
767 (char*)real_area2 + i * type->byte_size, snapshot1, snapshot2,
768 previous, type, -1, check_ignore, 0);
773 for (simgrid::mc::Member& member : type->members) {
774 // TODO, optimize this? (for the offset case)
776 simgrid::dwarf::resolve_member(real_area1, type, &member, (simgrid::mc::AddressSpace*)snapshot1);
778 simgrid::dwarf::resolve_member(real_area2, type, &member, (simgrid::mc::AddressSpace*)snapshot2);
779 int res = compare_heap_area_with_type(state, real_member1, real_member2, snapshot1, snapshot2, previous,
780 member.type, -1, check_ignore, 0);
787 case DW_TAG_union_type:
788 return compare_heap_area_without_type(state, real_area1, real_area2, snapshot1, snapshot2, previous,
789 type->byte_size, check_ignore);
795 xbt_die("Unreachable");
799 /** Infer the type of a part of the block from the type of the block
801 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
803 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
805 * @param type DWARF type ID of the root address
807 * @return DWARF type ID for given offset
809 static simgrid::mc::Type* get_offset_type(void* real_base_address, simgrid::mc::Type* type, int offset, int area_size,
810 simgrid::mc::Snapshot* snapshot)
813 // Beginning of the block, the infered variable type if the type of the block:
817 switch (type->type) {
819 case DW_TAG_structure_type:
820 case DW_TAG_class_type:
822 type = type->full_type;
823 if (area_size != -1 && type->byte_size != area_size) {
824 if (area_size > type->byte_size && area_size % type->byte_size == 0)
830 for (simgrid::mc::Member& member : type->members) {
831 if (member.has_offset_location()) {
832 // We have the offset, use it directly (shortcut):
833 if (member.offset() == offset)
836 void* real_member = simgrid::dwarf::resolve_member(real_base_address, type, &member, snapshot);
837 if ((char*)real_member - (char*)real_base_address == offset)
844 /* FIXME: other cases ? */
852 * @param area1 Process address for state 1
853 * @param area2 Process address for state 2
854 * @param snapshot1 Snapshot of state 1
855 * @param snapshot2 Snapshot of state 2
856 * @param previous Pairs of blocks already compared on the current path (or nullptr)
857 * @param type_id Type of variable
858 * @param pointer_level
859 * @return 0 (same), 1 (different), -1
861 static int compare_heap_area(simgrid::mc::StateComparator& state, const void* area1, const void* area2,
862 simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2,
863 HeapLocationPairs* previous, simgrid::mc::Type* type, int pointer_level)
865 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
870 int check_ignore = 0;
878 simgrid::mc::Type* new_type1 = nullptr;
879 simgrid::mc::Type* new_type2 = nullptr;
881 bool match_pairs = false;
883 // This is the address of std_heap->heapinfo in the application process:
884 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
886 const malloc_info* heapinfos1 = snapshot1->read(remote((const malloc_info**)heapinfo_address));
887 const malloc_info* heapinfos2 = snapshot2->read(remote((const malloc_info**)heapinfo_address));
889 malloc_info heapinfo_temp1;
890 malloc_info heapinfo_temp2;
892 simgrid::mc::HeapLocationPairs current;
893 if (previous == nullptr) {
899 block1 = ((char*)area1 - (char*)state.std_heap_copy.heapbase) / BLOCKSIZE + 1;
900 block2 = ((char*)area2 - (char*)state.std_heap_copy.heapbase) / BLOCKSIZE + 1;
902 // If either block is a stack block:
903 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
904 previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1));
906 state.match_equals(previous);
910 // If either block is not in the expected area of memory:
911 if (((char*)area1 < (char*)state.std_heap_copy.heapbase) || (block1 > (ssize_t)state.processStates[0].heapsize) ||
912 (block1 < 1) || ((char*)area2 < (char*)state.std_heap_copy.heapbase) ||
913 (block2 > (ssize_t)state.processStates[1].heapsize) || (block2 < 1)) {
917 // Process address of the block:
918 void* real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
919 void* real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
923 type = type->full_type;
925 // This assume that for "boring" types (volatile ...) byte_size is absent:
926 while (type->byte_size == 0 && type->subtype != nullptr)
927 type = type->subtype;
930 if (type->type == DW_TAG_pointer_type ||
931 (type->type == DW_TAG_base_type && not type->name.empty() && type->name == "char"))
934 type_size = type->byte_size;
938 simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
939 simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
941 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
942 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
943 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
944 heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
946 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
947 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
950 state.match_equals(previous);
954 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
957 // TODO, lookup variable type from block type as done for fragmented blocks
959 if (state.equals_to1_(block1, 0).valid_ && state.equals_to2_(block2, 0).valid_ &&
960 state.blocksEqual(block1, block2)) {
962 state.match_equals(previous);
966 if (type_size != -1 && type_size != (ssize_t)heapinfo1->busy_block.busy_size &&
967 type_size != (ssize_t)heapinfo2->busy_block.busy_size &&
968 (type->name.empty() || type->name == "struct s_smx_context")) {
970 state.match_equals(previous);
974 if (heapinfo1->busy_block.size != heapinfo2->busy_block.size)
976 if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size)
979 if (not previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1)).second) {
981 state.match_equals(previous);
985 size = heapinfo1->busy_block.busy_size;
987 // Remember (basic) type inference.
988 // The current data structure only allows us to do this for the whole block.
989 if (type != nullptr && area1 == real_addr_block1)
990 state.types1_(block1, 0) = type;
991 if (type != nullptr && area2 == real_addr_block2)
992 state.types2_(block2, 0) = type;
996 state.match_equals(previous);
1000 if (heapinfo1->busy_block.ignore > 0
1001 && heapinfo2->busy_block.ignore == heapinfo1->busy_block.ignore)
1002 check_ignore = heapinfo1->busy_block.ignore;
1004 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1007 ssize_t frag1 = ((uintptr_t)(ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1008 ssize_t frag2 = ((uintptr_t)(ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1010 // Process address of the fragment_:
1011 void* real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type));
1012 void* real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type));
1014 // Check the size of the fragments against the size of the type:
1015 if (type_size != -1) {
1016 if (heapinfo1->busy_frag.frag_size[frag1] == -1 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1018 state.match_equals(previous);
1022 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1023 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1025 state.match_equals(previous);
1030 // Check if the blocks are already matched together:
1031 if (state.equals_to1_(block1, frag1).valid_ && state.equals_to2_(block2, frag2).valid_ && offset1 == offset2 &&
1032 state.fragmentsEqual(block1, frag1, block2, frag2)) {
1034 state.match_equals(previous);
1037 // Compare the size of both fragments:
1038 if (heapinfo1->busy_frag.frag_size[frag1] != heapinfo2->busy_frag.frag_size[frag2]) {
1039 if (type_size == -1) {
1041 state.match_equals(previous);
1047 // Size of the fragment_:
1048 size = heapinfo1->busy_frag.frag_size[frag1];
1050 // Remember (basic) type inference.
1051 // The current data structure only allows us to do this for the whole fragment_.
1052 if (type != nullptr && area1 == real_addr_frag1)
1053 state.types1_(block1, frag1) = type;
1054 if (type != nullptr && area2 == real_addr_frag2)
1055 state.types2_(block2, frag2) = type;
1057 // The type of the variable is already known:
1059 new_type1 = new_type2 = type;
1061 // Type inference from the block type.
1062 else if (state.types1_(block1, frag1) != nullptr || state.types2_(block2, frag2) != nullptr) {
1064 offset1 = (char*)area1 - (char*)real_addr_frag1;
1065 offset2 = (char*)area2 - (char*)real_addr_frag2;
1067 if (state.types1_(block1, frag1) != nullptr && state.types2_(block2, frag2) != nullptr) {
1068 new_type1 = get_offset_type(real_addr_frag1, state.types1_(block1, frag1), offset1, size, snapshot1);
1069 new_type2 = get_offset_type(real_addr_frag2, state.types2_(block2, frag2), offset1, size, snapshot2);
1070 } else if (state.types1_(block1, frag1) != nullptr) {
1071 new_type1 = get_offset_type(real_addr_frag1, state.types1_(block1, frag1), offset1, size, snapshot1);
1072 new_type2 = get_offset_type(real_addr_frag2, state.types1_(block1, frag1), offset2, size, snapshot2);
1073 } else if (state.types2_(block2, frag2) != nullptr) {
1074 new_type1 = get_offset_type(real_addr_frag1, state.types2_(block2, frag2), offset1, size, snapshot1);
1075 new_type2 = get_offset_type(real_addr_frag2, state.types2_(block2, frag2), offset2, size, snapshot2);
1078 state.match_equals(previous);
1082 if (new_type1 != nullptr && new_type2 != nullptr && new_type1 != new_type2) {
1085 while (type->byte_size == 0 && type->subtype != nullptr)
1086 type = type->subtype;
1087 new_size1 = type->byte_size;
1090 while (type->byte_size == 0 && type->subtype != nullptr)
1091 type = type->subtype;
1092 new_size2 = type->byte_size;
1096 state.match_equals(previous);
1101 if (new_size1 > 0 && new_size1 == new_size2) {
1106 if (offset1 == 0 && offset2 == 0 &&
1107 not previous->insert(simgrid::mc::makeHeapLocationPair(block1, frag1, block2, frag2)).second) {
1109 state.match_equals(previous);
1115 state.match_equals(previous);
1119 if ((heapinfo1->busy_frag.ignore[frag1] > 0) &&
1120 (heapinfo2->busy_frag.ignore[frag2] == heapinfo1->busy_frag.ignore[frag1]))
1121 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1127 /* Start comparison */
1130 res_compare = compare_heap_area_with_type(state, area1, area2, snapshot1, snapshot2, previous, type, size,
1131 check_ignore, pointer_level);
1134 compare_heap_area_without_type(state, area1, area2, snapshot1, snapshot2, previous, size, check_ignore);
1136 if (res_compare == 1)
1140 state.match_equals(previous);
1147 /************************** Snapshot comparison *******************************/
1148 /******************************************************************************/
1150 static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* real_area1,
1151 simgrid::mc::Snapshot* snapshot1, simgrid::mc::Region* region1, void* real_area2,
1152 simgrid::mc::Snapshot* snapshot2, simgrid::mc::Region* region2,
1153 simgrid::mc::Type* type, int pointer_level)
1155 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
1157 simgrid::mc::Type* subtype;
1158 simgrid::mc::Type* subsubtype;
1164 xbt_assert(type != nullptr);
1165 switch (type->type) {
1166 case DW_TAG_unspecified_type:
1169 case DW_TAG_base_type:
1170 case DW_TAG_enumeration_type:
1171 case DW_TAG_union_type:
1172 return MC_snapshot_region_memcmp(real_area1, region1, real_area2, region2, type->byte_size) != 0;
1173 case DW_TAG_typedef:
1174 case DW_TAG_volatile_type:
1175 case DW_TAG_const_type:
1177 type = type->subtype;
1178 continue; // restart
1179 case DW_TAG_array_type:
1180 subtype = type->subtype;
1181 switch (subtype->type) {
1182 case DW_TAG_unspecified_type:
1185 case DW_TAG_base_type:
1186 case DW_TAG_enumeration_type:
1187 case DW_TAG_pointer_type:
1188 case DW_TAG_reference_type:
1189 case DW_TAG_rvalue_reference_type:
1190 case DW_TAG_structure_type:
1191 case DW_TAG_class_type:
1192 case DW_TAG_union_type:
1193 if (subtype->full_type)
1194 subtype = subtype->full_type;
1195 elm_size = subtype->byte_size;
1197 case DW_TAG_const_type:
1198 case DW_TAG_typedef:
1199 case DW_TAG_volatile_type:
1200 subsubtype = subtype->subtype;
1201 if (subsubtype->full_type)
1202 subsubtype = subsubtype->full_type;
1203 elm_size = subsubtype->byte_size;
1208 for (i = 0; i < type->element_count; i++) {
1209 size_t off = i * elm_size;
1210 res = compare_areas_with_type(state, (char*)real_area1 + off, snapshot1, region1, (char*)real_area2 + off,
1211 snapshot2, region2, type->subtype, pointer_level);
1216 case DW_TAG_pointer_type:
1217 case DW_TAG_reference_type:
1218 case DW_TAG_rvalue_reference_type: {
1219 void* addr_pointed1 = MC_region_read_pointer(region1, real_area1);
1220 void* addr_pointed2 = MC_region_read_pointer(region2, real_area2);
1222 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type)
1223 return (addr_pointed1 != addr_pointed2);
1224 if (addr_pointed1 == nullptr && addr_pointed2 == nullptr)
1226 if (addr_pointed1 == nullptr || addr_pointed2 == nullptr)
1228 if (not state.compared_pointers.insert(std::make_pair(addr_pointed1, addr_pointed2)).second)
1233 // Some cases are not handled here:
1234 // * the pointers lead to different areas (one to the heap, the other to the RW segment ...)
1235 // * a pointer leads to the read-only segment of the current object
1236 // * a pointer lead to a different ELF object
1238 if (addr_pointed1 > process->heap_address && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)) {
1239 if (not(addr_pointed2 > process->heap_address && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)))
1241 // The pointers are both in the heap:
1242 return simgrid::mc::compare_heap_area(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, nullptr,
1243 type->subtype, pointer_level);
1245 } else if (region1->contain(simgrid::mc::remote(addr_pointed1))) {
1246 // The pointers are both in the current object R/W segment:
1247 if (not region2->contain(simgrid::mc::remote(addr_pointed2)))
1249 if (not type->type_id)
1250 return (addr_pointed1 != addr_pointed2);
1252 return compare_areas_with_type(state, addr_pointed1, snapshot1, region1, addr_pointed2, snapshot2, region2,
1253 type->subtype, pointer_level);
1256 // TODO, We do not handle very well the case where
1257 // it belongs to a different (non-heap) region from the current one.
1259 return (addr_pointed1 != addr_pointed2);
1262 case DW_TAG_structure_type:
1263 case DW_TAG_class_type:
1264 for (simgrid::mc::Member& member : type->members) {
1265 void* member1 = simgrid::dwarf::resolve_member(real_area1, type, &member, snapshot1);
1266 void* member2 = simgrid::dwarf::resolve_member(real_area2, type, &member, snapshot2);
1267 simgrid::mc::Region* subregion1 = snapshot1->get_region(member1, region1); // region1 is hinted
1268 simgrid::mc::Region* subregion2 = snapshot2->get_region(member2, region2); // region2 is hinted
1269 res = compare_areas_with_type(state, member1, snapshot1, subregion1, member2, snapshot2, subregion2,
1270 member.type, pointer_level);
1275 case DW_TAG_subroutine_type:
1278 XBT_VERB("Unknown case: %d", type->type);
1286 static int compare_global_variables(simgrid::mc::StateComparator& state, simgrid::mc::ObjectInformation* object_info,
1287 simgrid::mc::Region* r1, simgrid::mc::Region* r2, simgrid::mc::Snapshot* snapshot1,
1288 simgrid::mc::Snapshot* snapshot2)
1290 xbt_assert(r1 && r2, "Missing region.");
1292 std::vector<simgrid::mc::Variable>& variables = object_info->global_variables;
1294 for (simgrid::mc::Variable const& current_var : variables) {
1296 // If the variable is not in this object, skip it:
1297 // We do not expect to find a pointer to something which is not reachable
1298 // by the global variables.
1299 if ((char *) current_var.address < (char *) object_info->start_rw
1300 || (char *) current_var.address > (char *) object_info->end_rw)
1303 simgrid::mc::Type* bvariable_type = current_var.type;
1304 int res = compare_areas_with_type(state, (char*)current_var.address, snapshot1, r1, (char*)current_var.address,
1305 snapshot2, r2, bvariable_type, 0);
1307 XBT_VERB("Global variable %s (%p) is different between snapshots",
1308 current_var.name.c_str(),
1309 (char *) current_var.address);
1317 static int compare_local_variables(simgrid::mc::StateComparator& state,
1318 simgrid::mc::Snapshot* snapshot1,
1319 simgrid::mc::Snapshot* snapshot2,
1320 mc_snapshot_stack_t stack1,
1321 mc_snapshot_stack_t stack2)
1323 if (stack1->local_variables.size() != stack2->local_variables.size()) {
1324 XBT_VERB("Different number of local variables");
1328 unsigned int cursor = 0;
1329 local_variable_t current_var1;
1330 local_variable_t current_var2;
1331 while (cursor < stack1->local_variables.size()) {
1332 current_var1 = &stack1->local_variables[cursor];
1333 current_var2 = &stack1->local_variables[cursor];
1334 if (current_var1->name != current_var2->name
1335 || current_var1->subprogram != current_var2->subprogram
1336 || current_var1->ip != current_var2->ip) {
1337 // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
1339 ("Different name of variable (%s - %s) "
1340 "or frame (%s - %s) or ip (%lu - %lu)",
1341 current_var1->name.c_str(),
1342 current_var2->name.c_str(),
1343 current_var1->subprogram->name.c_str(),
1344 current_var2->subprogram->name.c_str(),
1345 current_var1->ip, current_var2->ip);
1348 // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
1350 simgrid::mc::Type* subtype = current_var1->type;
1351 int res = compare_areas_with_type(state, current_var1->address, snapshot1,
1352 snapshot1->get_region(current_var1->address), current_var2->address,
1353 snapshot2, snapshot2->get_region(current_var2->address), subtype, 0);
1356 // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
1357 XBT_VERB("Local variable %s (%p - %p) in frame %s "
1358 "is different between snapshots",
1359 current_var1->name.c_str(), current_var1->address, current_var2->address,
1360 current_var1->subprogram->name.c_str());
1371 static std::unique_ptr<simgrid::mc::StateComparator> state_comparator;
1373 int snapshot_compare(Snapshot* s1, Snapshot* s2)
1375 // TODO, make this a field of ModelChecker or something similar
1376 if (state_comparator == nullptr)
1377 state_comparator.reset(new StateComparator());
1379 state_comparator->clear();
1381 RemoteClient* process = &mc_model_checker->process();
1385 int hash_result = 0;
1387 hash_result = (s1->hash_ != s2->hash_);
1389 XBT_VERB("(%d - %d) Different hash: 0x%" PRIx64 "--0x%" PRIx64, s1->num_state_, s2->num_state_, s1->hash_,
1395 XBT_VERB("(%d - %d) Same hash: 0x%" PRIx64, s1->num_state_, s2->num_state_, s1->hash_);
1398 /* Compare enabled processes */
1399 if (s1->enabled_processes_ != s2->enabled_processes_) {
1400 XBT_VERB("(%d - %d) Different amount of enabled processes", s1->num_state_, s2->num_state_);
1404 /* Compare size of stacks */
1406 for (unsigned long i = 0; i < s1->stacks_.size(); i++) {
1407 size_t size_used1 = s1->stack_sizes_[i];
1408 size_t size_used2 = s2->stack_sizes_[i];
1409 if (size_used1 != size_used2) {
1411 XBT_DEBUG("(%d - %d) Different size used in stacks: %zu - %zu", s1->num_state, s2->num_state, size_used1,
1417 XBT_VERB("(%d - %d) Different size used in stacks: %zu - %zu", s1->num_state_, s2->num_state_, size_used1,
1424 if (is_diff) // do not proceed if there is any stacks that don't match
1427 /* Init heap information used in heap comparison algorithm */
1428 xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
1429 remote(process->heap_address), simgrid::mc::ReadOptions::lazy());
1430 xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes(alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
1431 remote(process->heap_address), simgrid::mc::ReadOptions::lazy());
1432 int res_init = state_comparator->initHeapInformation(heap1, heap2, &s1->to_ignore_, &s2->to_ignore_);
1434 if (res_init == -1) {
1436 XBT_DEBUG("(%d - %d) Different heap information", num1, nus1->num_state, s2->num_statem2);
1440 XBT_VERB("(%d - %d) Different heap information", s1->num_state_, s2->num_state_);
1447 /* Stacks comparison */
1448 // int diff_local = 0;
1449 for (unsigned int cursor = 0; cursor < s1->stacks_.size(); cursor++) {
1450 mc_snapshot_stack_t stack1 = &s1->stacks_[cursor];
1451 mc_snapshot_stack_t stack2 = &s2->stacks_[cursor];
1453 if (compare_local_variables(*state_comparator, s1, s2, stack1, stack2) > 0) {
1455 XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1,
1461 XBT_VERB("(%d - %d) Different local variables between stacks %u", s1->num_state_, s2->num_state_, cursor + 1);
1469 size_t regions_count = s1->snapshot_regions_.size();
1470 // TODO, raise a difference instead?
1471 xbt_assert(regions_count == s2->snapshot_regions_.size());
1473 for (size_t k = 0; k != regions_count; ++k) {
1474 Region* region1 = s1->snapshot_regions_[k].get();
1475 Region* region2 = s2->snapshot_regions_[k].get();
1478 if (region1->region_type() != RegionType::Data)
1481 xbt_assert(region1->region_type() == region2->region_type());
1482 xbt_assert(region1->object_info() == region2->object_info());
1483 xbt_assert(region1->object_info());
1485 /* Compare global variables */
1486 if (compare_global_variables(*state_comparator, region1->object_info(), region1, region2, s1, s2)) {
1489 std::string const& name = region1->object_info()->file_name;
1490 XBT_DEBUG("(%d - %d) Different global variables in %s", s1->num_state, s2->num_state, name.c_str());
1494 std::string const& name = region1->object_info()->file_name;
1495 XBT_VERB("(%d - %d) Different global variables in %s", s1->num_state_, s2->num_state_, name.c_str());
1504 if (mmalloc_compare_heap(*state_comparator, s1, s2) > 0) {
1507 XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", s1->num_state, s2->num_state);
1512 XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", s1->num_state_, s2->num_state_);
1519 if (errors || hash_result)
1520 XBT_VERB("(%d - %d) Difference found", s1->num_state_, s2->num_state_);
1522 XBT_VERB("(%d - %d) No difference found", s1->num_state_, s2->num_state_);
1525 #if defined(MC_DEBUG) && defined(MC_VERBOSE)
1527 // * false positive SHOULD be avoided.
1528 // * There MUST not be any false negative.
1530 XBT_VERB("(%d - %d) State equality hash test is %s %s", s1->num_state, s2->num_state,
1531 (hash_result != 0) == (errors != 0) ? "true" : "false", not hash_result ? "positive" : "negative");
1535 return errors > 0 || hash_result;