X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b83ad9c88af4715987015ddc91ac93ad749df428..b499a9ef09911820ccd2491efb3ec2781b25f42f:/src/mc/compare.cpp diff --git a/src/mc/compare.cpp b/src/mc/compare.cpp index 0905aeec84..5f5ab012c0 100644 --- a/src/mc/compare.cpp +++ b/src/mc/compare.cpp @@ -13,8 +13,8 @@ #include #include -#include -#include +#include "xbt/dynar.h" +#include "xbt/sysdep.h" #include #include @@ -25,11 +25,11 @@ #include "src/xbt/mmalloc/mmprivate.h" #if HAVE_SMPI -#include "src/smpi/private.h" +#include "src/smpi/include/private.h" +#include "src/smpi/include/private.hpp" #endif #include "src/mc/mc_forward.hpp" -#include "src/mc/mc_safety.h" #include "src/mc/mc_private.h" #include "src/mc/mc_smx.h" #include "src/mc/mc_dwarf.hpp" @@ -70,11 +70,12 @@ using simgrid::mc::remote; namespace simgrid { namespace mc { -struct HeapLocation { +class HeapLocation { +public: int block = 0; int fragment = 0; - HeapLocation() {} + HeapLocation() = default; HeapLocation(int block, int fragment = 0) : block(block), fragment(fragment) {} bool operator==(HeapLocation const& that) const @@ -97,18 +98,16 @@ HeapLocationPair makeHeapLocationPair(int block1, int fragment1, int block2, int }}; } -struct HeapArea : public HeapLocation { +class HeapArea : public HeapLocation { +public: bool valid = false; - int block = 0; - int fragment = 0; - HeapArea() {} - HeapArea(int block) - : valid(true), block(block) {} - HeapArea(int block, int fragment = 0) - : valid(true), block(block), fragment(fragment) {} + HeapArea() = default; + explicit HeapArea(int block) : valid(true), block(block) {} + HeapArea(int block, int fragment) : valid(true), block(block), fragment(fragment) {} }; -struct ProcessComparisonState { +class ProcessComparisonState { +public: std::vector* to_ignore = nullptr; std::vector equals_to; std::vector types; @@ -125,8 +124,8 @@ namespace { */ template struct hash : public std::hash {}; -template -struct hash> { +template class hash> { +public: std::size_t operator()(std::pairconst& x) const { struct hash h1; @@ -137,8 +136,8 @@ struct hash> { } - -struct StateComparator { +class StateComparator { +public: s_xbt_mheap_t std_heap_copy; std::size_t heaplimit; std::array processStates; @@ -306,7 +305,7 @@ int StateComparator::initHeapInformation(xbt_mheap_t heap1, xbt_mheap_t heap2, static inline mc_mem_region_t MC_get_heap_region(simgrid::mc::Snapshot* snapshot) { - for (auto& region : snapshot->snapshot_regions) + for (auto const& region : snapshot->snapshot_regions) if (region->region_type() == simgrid::mc::RegionType::Heap) return region.get(); xbt_die("No heap region"); @@ -316,7 +315,7 @@ static int mmalloc_compare_heap( simgrid::mc::StateComparator& state, simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2) { - simgrid::mc::Process* process = &mc_model_checker->process(); + simgrid::mc::RemoteClient* process = &mc_model_checker->process(); /* Start comparison */ size_t i1; @@ -331,7 +330,6 @@ int mmalloc_compare_heap( int nb_diff1 = 0; int nb_diff2 = 0; int equal; - int res_compare = 0; /* Check busy blocks */ i1 = 1; @@ -387,14 +385,13 @@ int mmalloc_compare_heap( i2 = 1; equal = 0; - res_compare = 0; /* Try first to associate to same block in the other heap */ if (heapinfo2->type == heapinfo1->type && state.equals_to2_(i1, 0).valid == 0) { addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, - snapshot2, nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, + snapshot1, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) { for (k = 1; k < heapinfo2->busy_block.size; k++) state.equals_to2_(i1 + k, 0) = HeapArea(i1, -1); @@ -405,7 +402,7 @@ int mmalloc_compare_heap( } } - while (i2 < state.heaplimit && !equal) { + while (i2 < state.heaplimit && not equal) { addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; @@ -426,9 +423,8 @@ int mmalloc_compare_heap( continue; } - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, - addr_block1, addr_block2, snapshot1, snapshot2, - nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, + snapshot1, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) { for (k = 1; k < heapinfo2b->busy_block.size; k++) @@ -442,7 +438,7 @@ int mmalloc_compare_heap( i2++; } - if (!equal) { + if (not equal) { XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1, heapinfo1->busy_block.busy_size, addr_block1); i1 = state.heaplimit + 1; nb_diff1++; @@ -465,20 +461,19 @@ int mmalloc_compare_heap( equal = 0; /* Try first to associate to same fragment in the other heap */ - if (heapinfo2->type == heapinfo1->type - && !state.equals_to2_(i1, j1).valid) { + if (heapinfo2->type == heapinfo1->type && not state.equals_to2_(i1, j1).valid) { addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char *) state.std_heap_copy.heapbase; addr_frag2 = (void *) ((char *) addr_block2 + (j1 << heapinfo2->type)); - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot1, - snapshot2, nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, + snapshot1, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) equal = 1; } - while (i2 < state.heaplimit && !equal) { + while (i2 < state.heaplimit && not equal) { const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read( heap_region2, &heapinfo_temp2b, &heapinfos2[i2], @@ -512,8 +507,8 @@ int mmalloc_compare_heap( addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; addr_frag2 = (void*)((char*)addr_block2 + (j2 << heapinfo2b->type)); - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot2, - snapshot2, nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, + snapshot2, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) { equal = 1; break; @@ -523,10 +518,9 @@ int mmalloc_compare_heap( i2++; } - if (!equal) { + if (not equal) { XBT_DEBUG("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n", i1, j1, heapinfo1->busy_frag.frag_size[j1], addr_frag1); - i2 = state.heaplimit + 1; i1 = state.heaplimit + 1; nb_diff1++; break; @@ -546,7 +540,7 @@ int mmalloc_compare_heap( heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info)); if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo1->busy_block.busy_size > 0 && - !state.equals_to1_(i, 0).valid) { + not state.equals_to1_(i, 0).valid) { XBT_DEBUG("Block %zu not found (size used = %zu)", i, heapinfo1->busy_block.busy_size); nb_diff1++; } @@ -554,7 +548,7 @@ int mmalloc_compare_heap( if (heapinfo1->type <= 0) continue; for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) - if (i1 == state.heaplimit && heapinfo1->busy_frag.frag_size[j] > 0 && !state.equals_to1_(i, j).valid) { + if (i1 == state.heaplimit && heapinfo1->busy_frag.frag_size[j] > 0 && not state.equals_to1_(i, j).valid) { XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)", i, j, heapinfo1->busy_frag.frag_size[j]); nb_diff1++; } @@ -566,10 +560,8 @@ int mmalloc_compare_heap( for (i=1; i < state.heaplimit; i++) { const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read( heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info)); - if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED - && i1 == state.heaplimit - && heapinfo2->busy_block.busy_size > 0 - && !state.equals_to2_(i, 0).valid) { + if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo2->busy_block.busy_size > 0 && + not state.equals_to2_(i, 0).valid) { XBT_DEBUG("Block %zu not found (size used = %zu)", i, heapinfo2->busy_block.busy_size); nb_diff2++; @@ -579,9 +571,7 @@ int mmalloc_compare_heap( continue; for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) - if (i1 == state.heaplimit - && heapinfo2->busy_frag.frag_size[j] > 0 - && !state.equals_to2_(i, j).valid) { + if (i1 == state.heaplimit && heapinfo2->busy_frag.frag_size[j] > 0 && not state.equals_to2_(i, j).valid) { XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)", i, j, heapinfo2->busy_frag.frag_size[j]); nb_diff2++; @@ -614,7 +604,7 @@ static int compare_heap_area_without_type( HeapLocationPairs* previous, int size, int check_ignore) { - simgrid::mc::Process* process = &mc_model_checker->process(); + simgrid::mc::RemoteClient* process = &mc_model_checker->process(); mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1); mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2); @@ -737,7 +727,7 @@ top: return 1; case DW_TAG_base_type: - if (!type->name.empty() && type->name == "char") { /* String, hence random (arbitrary ?) size */ + if (not type->name.empty() && type->name == "char") { /* String, hence random (arbitrary ?) size */ if (real_area1 == real_area2) return -1; else @@ -870,7 +860,7 @@ top: return res; } } else { - for(simgrid::mc::Member& member : type->members) { + for (simgrid::mc::Member& member : type->members) { // TODO, optimize this? (for the offset case) void *real_member1 = simgrid::dwarf::resolve_member( real_area1, type, &member, (simgrid::mc::AddressSpace*) snapshot1, process_index); @@ -931,7 +921,7 @@ static simgrid::mc::Type* get_offset_type(void *real_base_address, simgrid::mc:: return nullptr; } - for(simgrid::mc::Member& member : type->members) { + for (simgrid::mc::Member& member : type->members) { if (member.has_offset_location()) { // We have the offset, use it directly (shortcut): if (member.offset() == offset) @@ -970,20 +960,13 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, HeapLocationPairs* previous, simgrid::mc::Type* type, int pointer_level) { - simgrid::mc::Process* process = &mc_model_checker->process(); + simgrid::mc::RemoteClient* process = &mc_model_checker->process(); - int res_compare; ssize_t block1; - ssize_t frag1; ssize_t block2; - ssize_t frag2; ssize_t size; int check_ignore = 0; - void* real_addr_block1; - void* real_addr_block2; - void* real_addr_frag1; - void* real_addr_frag2; int type_size = -1; int offset1 = 0; int offset2 = 0; @@ -1029,8 +1012,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, } // Process address of the block: - real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; - real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; + void* real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; + void* real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; if (type) { if (type->full_type) @@ -1042,7 +1025,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, // Find type_size: if (type->type == DW_TAG_pointer_type || - (type->type == DW_TAG_base_type && !type->name.empty() && type->name == "char")) + (type->type == DW_TAG_base_type && not type->name.empty() && type->name == "char")) type_size = -1; else type_size = type->byte_size; @@ -1070,9 +1053,6 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, // TODO, lookup variable type from block type as done for fragmented blocks - offset1 = (char*)area1 - (char*)real_addr_block1; - offset2 = (char*)area2 - (char*)real_addr_block2; - if (state.equals_to1_(block1, 0).valid && state.equals_to2_(block2, 0).valid && state.blocksEqual(block1, block2)) { if (match_pairs) state.match_equals(previous); @@ -1094,7 +1074,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size) return 1; - if (!previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1)).second) { + if (not previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1)).second) { if (match_pairs) state.match_equals(previous); return 0; @@ -1115,9 +1095,6 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, return 0; } - frag1 = -1; - frag2 = -1; - if (heapinfo1->busy_block.ignore > 0 && heapinfo2->busy_block.ignore == heapinfo1->busy_block.ignore) check_ignore = heapinfo1->busy_block.ignore; @@ -1125,12 +1102,12 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */ // Fragment number: - frag1 = ((uintptr_t)(ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type; - frag2 = ((uintptr_t)(ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type; + ssize_t frag1 = ((uintptr_t)(ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type; + ssize_t frag2 = ((uintptr_t)(ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type; // Process address of the fragment: - real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type)); - real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type)); + void* real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type)); + void* real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type)); // Check the size of the fragments against the size of the type: if (type_size != -1) { @@ -1178,8 +1155,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, // The type of the variable is already known: if (type) { - new_type1 = type; - new_type2 = type; + new_type1 = new_type2 = type; } // Type inference from the block type. else if (state.types1_(block1, frag1) != nullptr || state.types2_(block2, frag2) != nullptr) { @@ -1233,7 +1209,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, } if (offset1 == 0 && offset2 == 0 && - !previous->insert(simgrid::mc::makeHeapLocationPair(block1, frag1, block2, frag2)).second) { + not previous->insert(simgrid::mc::makeHeapLocationPair(block1, frag1, block2, frag2)).second) { if (match_pairs) state.match_equals(previous); return 0; @@ -1254,6 +1230,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, /* Start comparison */ + int res_compare; if (type) res_compare = compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2, previous, type, size, check_ignore, pointer_level); @@ -1281,7 +1258,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* real_area2, simgrid::mc::Snapshot* snapshot2, mc_mem_region_t region2, simgrid::mc::Type* type, int pointer_level) { - simgrid::mc::Process* process = &mc_model_checker->process(); + simgrid::mc::RemoteClient* process = &mc_model_checker->process(); simgrid::mc::Type* subtype; simgrid::mc::Type* subsubtype; @@ -1357,8 +1334,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, return 0; if (addr_pointed1 == nullptr || addr_pointed2 == nullptr) return 1; - if (!state.compared_pointers.insert( - std::make_pair(addr_pointed1, addr_pointed2)).second) + if (not state.compared_pointers.insert(std::make_pair(addr_pointed1, addr_pointed2)).second) return 0; pointer_level++; @@ -1370,9 +1346,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, if (addr_pointed1 > process->heap_address && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)) { - if (! - (addr_pointed2 > process->heap_address - && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))) + if (not(addr_pointed2 > process->heap_address && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))) return 1; // The pointers are both in the heap: return simgrid::mc::compare_heap_area(state, @@ -1382,9 +1356,9 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, // The pointers are both in the current object R/W segment: else if (region1->contain(simgrid::mc::remote(addr_pointed1))) { - if (!region2->contain(simgrid::mc::remote(addr_pointed2))) + if (not region2->contain(simgrid::mc::remote(addr_pointed2))) return 1; - if (!type->type_id) + if (not type->type_id) return (addr_pointed1 != addr_pointed2); else return compare_areas_with_type(state, process_index, @@ -1403,7 +1377,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, } case DW_TAG_structure_type: case DW_TAG_class_type: - for(simgrid::mc::Member& member : type->members) { + for (simgrid::mc::Member& member : type->members) { void *member1 = simgrid::dwarf::resolve_member( real_area1, type, &member, snapshot1, process_index); void *member2 = simgrid::dwarf::resolve_member( @@ -1467,7 +1441,7 @@ static int compare_global_variables( std::vector& variables = object_info->global_variables; - for (simgrid::mc::Variable& current_var : variables) { + for (simgrid::mc::Variable const& current_var : variables) { // If the variable is not in this object, skip it: // We do not expect to find a pointer to something which is not reachable @@ -1487,11 +1461,9 @@ static int compare_global_variables( (char *) current_var.address); return 1; } - } return 0; - } static int compare_local_variables(simgrid::mc::StateComparator& state, @@ -1508,7 +1480,6 @@ static int compare_local_variables(simgrid::mc::StateComparator& state, unsigned int cursor = 0; local_variable_t current_var1, current_var2; - int res; while (cursor < stack1->local_variables.size()) { current_var1 = &stack1->local_variables[cursor]; current_var2 = &stack1->local_variables[cursor]; @@ -1529,22 +1500,18 @@ static int compare_local_variables(simgrid::mc::StateComparator& state, // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram simgrid::mc::Type* subtype = current_var1->type; - res = - compare_areas_with_type(state, process_index, - current_var1->address, snapshot1, mc_get_snapshot_region(current_var1->address, snapshot1, process_index), - current_var2->address, snapshot2, mc_get_snapshot_region(current_var2->address, snapshot2, process_index), - subtype, 0); - - if (res == 1) { - // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram - XBT_VERB - ("Local variable %s (%p - %p) in frame %s " - "is different between snapshots", - current_var1->name.c_str(), - current_var1->address, - current_var2->address, - current_var1->subprogram->name.c_str()); - return res; + int res = compare_areas_with_type( + state, process_index, current_var1->address, snapshot1, + mc_get_snapshot_region(current_var1->address, snapshot1, process_index), current_var2->address, snapshot2, + mc_get_snapshot_region(current_var2->address, snapshot2, process_index), subtype, 0); + + if (res == 1) { + // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram + XBT_VERB("Local variable %s (%p - %p) in frame %s " + "is different between snapshots", + current_var1->name.c_str(), current_var1->address, current_var2->address, + current_var1->subprogram->name.c_str()); + return res; } cursor++; } @@ -1565,7 +1532,7 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: else state_comparator->clear(); - simgrid::mc::Process* process = &mc_model_checker->process(); + simgrid::mc::RemoteClient* process = &mc_model_checker->process(); int errors = 0; @@ -1650,12 +1617,10 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1, num2, cursor + 1); errors++; - is_diff = 1; #else #ifdef MC_VERBOSE - XBT_VERB("(%d - %d) Different local variables between stacks %d", num1, - num2, cursor + 1); + XBT_VERB("(%d - %d) Different local variables between stacks %u", num1, num2, cursor + 1); #endif return 1; @@ -1728,8 +1693,7 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: // * There MUST not be any false negative. XBT_VERB("(%d - %d) State equality hash test is %s %s", num1, num2, - (hash_result != 0) == (errors != 0) ? "true" : "false", - !hash_result ? "positive" : "negative"); + (hash_result != 0) == (errors != 0) ? "true" : "false", not hash_result ? "positive" : "negative"); } #endif