Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Multiple .so support for region snapshots
[simgrid.git] / src / mc / mc_diff.c
index 377e3cb..089a9b2 100644 (file)
 #include "xbt/str.h"
 #include "mc/mc.h"
 #include "xbt/mmalloc.h"
+#include "mc_object_info.h"
 #include "mc/datatypes.h"
 #include "mc/mc_private.h"
+#include "mc/mc_snapshot.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
                                 "Logging specific to mc_diff in mc");
 
 xbt_dynar_t mc_heap_comparison_ignore;
 xbt_dynar_t stacks_areas;
-void *maestro_stack_start, *maestro_stack_end;
+
 
 
 /********************************* Backtrace ***********************************/
@@ -413,9 +415,21 @@ void reset_heap_information()
 
 }
 
-int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
+// TODO, have a robust way to find it in O(1)
+static inline
+mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
 {
+  size_t n = snapshot->snapshot_regions_count;
+  for (size_t i=0; i!=n; ++i) {
+    mc_mem_region_t region = snapshot->snapshot_regions[i];
+    if (region->region_type == MC_REGION_TYPE_HEAP)
+      return region;
+  }
+  xbt_die("No heap region");
+}
 
+int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
+{
   struct s_mc_diff *state = mc_diff_info;
 
   /* Start comparison */
@@ -432,12 +446,12 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
   malloc_info heapinfo_temp1, heapinfo_temp2;
   malloc_info heapinfo_temp2b;
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
   // This is in snapshot do not use them directly:
-  malloc_info* heapinfos1 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot1, MC_NO_PROCESS_INDEX);
-  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot2, MC_NO_PROCESS_INDEX);
+  malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, MC_NO_PROCESS_INDEX);
+  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, MC_NO_PROCESS_INDEX);
 
   while (i1 <= state->heaplimit) {
 
@@ -767,14 +781,15 @@ static int compare_heap_area_without_type(struct s_mc_diff *state, int process_i
                                           xbt_dynar_t previous, int size,
                                           int check_ignore)
 {
+  mc_process_t process = &mc_model_checker->process;
 
   int i = 0;
   void *addr_pointed1, *addr_pointed2;
   int pointer_align, res_compare;
   ssize_t ignore1, ignore2;
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
   while (i < size) {
 
@@ -803,10 +818,10 @@ static int compare_heap_area_without_type(struct s_mc_diff *state, int process_i
       addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1, process_index);
       addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2, process_index);
 
-      if (addr_pointed1 > maestro_stack_start
-          && addr_pointed1 < maestro_stack_end
-          && addr_pointed2 > maestro_stack_start
-          && addr_pointed2 < maestro_stack_end) {
+      if (addr_pointed1 > process->maestro_stack_start
+          && addr_pointed1 < process->maestro_stack_end
+          && addr_pointed2 > process->maestro_stack_start
+          && addr_pointed2 < process->maestro_stack_end) {
         i = pointer_align + sizeof(void *);
         continue;
       } else if (addr_pointed1 > state->s_heap
@@ -878,8 +893,8 @@ top:
   dw_type_t member;
   void *addr_pointed1, *addr_pointed2;;
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
   switch (type->type) {
   case DW_TAG_unspecified_type:
@@ -1136,8 +1151,8 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
 
   int match_pairs = 0;
 
-  malloc_info* heapinfos1 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot1, process_index);
-  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&((xbt_mheap_t)std_heap)->heapinfo, snapshot2, process_index);
+  malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, process_index);
+  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, process_index);
 
   malloc_info heapinfo_temp1, heapinfo_temp2;
 
@@ -1201,8 +1216,8 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
 
   }
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
   malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
   malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));