Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: better way to check if address is on heap.
[simgrid.git] / src / mc / compare.cpp
index 4b90663..e8457a3 100644 (file)
@@ -151,12 +151,6 @@ static ssize_t heap_comparison_ignore_size(const std::vector<simgrid::mc::Ignore
   return -1;
 }
 
-static bool is_on_heap(const void* address)
-{
-  const xbt_mheap_t heap = mc_model_checker->process().get_heap();
-  return address >= heap->heapbase && address < heap->breakval;
-}
-
 static bool is_stack(const void *address)
 {
   for (auto const& stack : mc_model_checker->process().stack_areas())
@@ -509,7 +503,7 @@ static bool heap_area_differ_without_type(simgrid::mc::StateComparator& state, c
         continue;
       }
 
-      if (is_on_heap(addr_pointed1) && is_on_heap(addr_pointed2)) {
+      if (snapshot1.on_heap(addr_pointed1) && snapshot2.on_heap(addr_pointed2)) {
         // Both addresses are in the heap:
         if (heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, nullptr, 0))
           return true;
@@ -651,7 +645,7 @@ static bool heap_area_differ_with_type(simgrid::mc::StateComparator& state, cons
       if (pointer_level <= 1) {
         addr_pointed1 = snapshot1.read(remote((void* const*)real_area1));
         addr_pointed2 = snapshot2.read(remote((void* const*)real_area2));
-        if (is_on_heap(addr_pointed1) && is_on_heap(addr_pointed2))
+        if (snapshot1.on_heap(addr_pointed1) && snapshot2.on_heap(addr_pointed2))
           return heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype,
                                   pointer_level);
         else
@@ -660,7 +654,7 @@ static bool heap_area_differ_with_type(simgrid::mc::StateComparator& state, cons
       for (size_t i = 0; i < (area_size / sizeof(void*)); i++) {
         addr_pointed1 = snapshot1.read(remote((void* const*)((const char*)real_area1 + i * sizeof(void*))));
         addr_pointed2 = snapshot2.read(remote((void* const*)((const char*)real_area2 + i * sizeof(void*))));
-        bool differ   = is_on_heap(addr_pointed1) && is_on_heap(addr_pointed2)
+        bool differ   = snapshot1.on_heap(addr_pointed1) && snapshot2.on_heap(addr_pointed2)
                           ? heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous,
                                              type->subtype, pointer_level)
                           : addr_pointed1 != addr_pointed2;
@@ -699,8 +693,7 @@ static bool heap_area_differ_with_type(simgrid::mc::StateComparator& state, cons
                                            type->byte_size, check_ignore);
 
     default:
-      XBT_VERB("Unknown case: %d", type->type);
-      break;
+      THROW_IMPOSSIBLE;
   }
   return false;
 }
@@ -1132,8 +1125,8 @@ static bool areas_differ_with_type(simgrid::mc::StateComparator& state, const vo
       // * a pointer leads to the read-only segment of the current object
       // * a pointer lead to a different ELF object
 
-      if (is_on_heap(addr_pointed1)) {
-        if (not is_on_heap(addr_pointed2))
+      if (snapshot1.on_heap(addr_pointed1)) {
+        if (not snapshot2.on_heap(addr_pointed2))
           return true;
         // The pointers are both in the heap:
         return simgrid::mc::heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, nullptr,
@@ -1184,7 +1177,7 @@ static bool global_variables_differ(simgrid::mc::StateComparator& state, simgrid
 {
   xbt_assert(r1 && r2, "Missing region.");
 
-  std::vector<simgrid::mc::Variable>& variables = object_info->global_variables;
+  const std::vector<simgrid::mc::Variable>& variables = object_info->global_variables;
 
   for (simgrid::mc::Variable const& current_var : variables) {
 
@@ -1196,11 +1189,9 @@ static bool global_variables_differ(simgrid::mc::StateComparator& state, simgrid
       continue;
 
     simgrid::mc::Type* bvariable_type = current_var.type;
-    if (areas_differ_with_type(state, (char*)current_var.address, snapshot1, r1, (char*)current_var.address, snapshot2,
-                               r2, bvariable_type, 0)) {
-      XBT_VERB("Global variable %s (%p) is different between snapshots",
-               current_var.name.c_str(),
-               (char *) current_var.address);
+    if (areas_differ_with_type(state, current_var.address, snapshot1, r1, current_var.address, snapshot2, r2,
+                               bvariable_type, 0)) {
+      XBT_VERB("Global variable %s (%p) is different between snapshots", current_var.name.c_str(), current_var.address);
       return true;
     }
   }
@@ -1223,9 +1214,8 @@ static bool local_variables_differ(simgrid::mc::StateComparator& state, const si
     if (current_var1->name != current_var2->name || current_var1->subprogram != current_var2->subprogram ||
         current_var1->ip != current_var2->ip) {
       // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
-      XBT_VERB("Different name of variable (%s - %s) "
-               "or frame (%s - %s) or ip (%lu - %lu)",
-               current_var1->name.c_str(), current_var2->name.c_str(), current_var1->subprogram->name.c_str(),
+      XBT_VERB("Different name of variable (%s - %s) or frame (%s - %s) or ip (%lu - %lu)", current_var1->name.c_str(),
+               current_var2->name.c_str(), current_var1->subprogram->name.c_str(),
                current_var2->subprogram->name.c_str(), current_var1->ip, current_var2->ip);
       return true;
     }
@@ -1233,10 +1223,8 @@ static bool local_variables_differ(simgrid::mc::StateComparator& state, const si
     if (areas_differ_with_type(state, current_var1->address, snapshot1, snapshot1.get_region(current_var1->address),
                                current_var2->address, snapshot2, snapshot2.get_region(current_var2->address),
                                current_var1->type, 0)) {
-      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());
+      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 true;
     }
   }