Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Add more information about mc_dwarf_register_to_libunwind()
[simgrid.git] / src / mc / mc_diff.c
index 2566334..4adf44b 100644 (file)
@@ -415,9 +415,22 @@ 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)
+{
+  mc_process_t process = &mc_model_checker->process;
   struct s_mc_diff *state = mc_diff_info;
 
   /* Start comparison */
@@ -434,12 +447,15 @@ 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 the address of std_heap->heapinfo in the application process:
+  void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
 
   // This is in snapshot do not use them directly:
-  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);
+  malloc_info* heapinfos1 = mc_snapshot_read_pointer(heapinfo_address, snapshot1, MC_NO_PROCESS_INDEX);
+  malloc_info* heapinfos2 = mc_snapshot_read_pointer(heapinfo_address, snapshot2, MC_NO_PROCESS_INDEX);
 
   while (i1 <= state->heaplimit) {
 
@@ -776,8 +792,8 @@ static int compare_heap_area_without_type(struct s_mc_diff *state, int process_i
   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) {
 
@@ -881,8 +897,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:
@@ -1123,6 +1139,7 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
                       mc_snapshot_t snapshot2, xbt_dynar_t previous,
                       dw_type_t type, int pointer_level)
 {
+  mc_process_t process = &mc_model_checker->process;
 
   struct s_mc_diff *state = mc_diff_info;
 
@@ -1139,8 +1156,11 @@ 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(&std_heap->heapinfo, snapshot1, process_index);
-  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, process_index);
+  // This is the address of std_heap->heapinfo in the application process:
+  void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
+
+  malloc_info* heapinfos1 = mc_snapshot_read_pointer(heapinfo_address, snapshot1, process_index);
+  malloc_info* heapinfos2 = mc_snapshot_read_pointer(heapinfo_address, snapshot2, process_index);
 
   malloc_info heapinfo_temp1, heapinfo_temp2;
 
@@ -1204,8 +1224,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));