Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: better way to check if address is on heap.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 11 Jul 2019 21:24:19 +0000 (23:24 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 11 Jul 2019 22:08:34 +0000 (00:08 +0200)
src/mc/compare.cpp
src/mc/inspect/DwarfExpression.hpp
src/mc/remote/RemoteClient.hpp
src/mc/sosp/Snapshot.hpp

index febf10b..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;
@@ -1131,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,
index 064ba32..efb089e 100644 (file)
@@ -16,7 +16,6 @@
 #include <elfutils/libdw.h>
 #include <libunwind.h>
 
-#include "src/mc/AddressSpace.hpp"
 #include "src/mc/inspect/mc_dwarf.hpp"
 #include "src/mc/mc_forward.hpp"
 
index 174517d..b5cfdc9 100644 (file)
@@ -6,8 +6,10 @@
 #ifndef SIMGRID_MC_PROCESS_H
 #define SIMGRID_MC_PROCESS_H
 
+#include "src/mc/AddressSpace.hpp"
 #include "src/mc/inspect/ObjectInformation.hpp"
 #include "src/mc/remote/Channel.hpp"
+#include "src/mc/remote/RemotePtr.hpp"
 #include "src/xbt/mmalloc/mmprivate.h"
 
 #include <vector>
index ad755f7..f227fe7 100644 (file)
@@ -59,12 +59,17 @@ namespace mc {
 
 class XBT_PRIVATE Snapshot final : public AddressSpace {
 public:
+  /* Initialization */
   Snapshot(int num_state, RemoteClient* process = &mc_model_checker->process());
   ~Snapshot() = default;
 
-  /* Initialization */
-
   /* Regular use */
+  bool on_heap(const void* address) const
+  {
+    const xbt_mheap_t heap = process()->get_heap();
+    return address >= heap->heapbase && address < heap->breakval;
+  }
+
   void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
                    ReadOptions options = ReadOptions::none()) const override;
   Region* get_region(const void* addr) const;