Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
31b34a8a4d522ee9ec8fc70d82083b5d4f003d49
[simgrid.git] / src / mc / mc_compare.c
1 /* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved.            */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "mc_private.h"
7
8 #include "xbt/mmalloc.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc,
11                                 "Logging specific to mc_compare");
12
13 static int data_bss_program_region_compare(void *d1, void *d2, size_t size);
14 static int data_bss_libsimgrid_region_compare(void *d1, void *d2, size_t size);
15 static int heap_region_compare(void *d1, void *d2, size_t size);
16
17 static int compare_stack(stack_region_t s1, stack_region_t s2, void *sp1, void *sp2, void *heap1, void *heap2, xbt_dynar_t equals);
18 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2);
19 static size_t heap_ignore_size(void *address);
20 static size_t data_bss_ignore_size(void *address);
21
22 static void stack_region_free(stack_region_t s);
23 static void heap_equality_free(heap_equality_t e);
24
25 static int is_stack_ignore_variable(char *frame, char *var_name);
26 static int compare_local_variables(char *s1, char *s2, xbt_dynar_t heap_equals);
27
28 static size_t heap_ignore_size(void *address){
29   unsigned int cursor = 0;
30   int start = 0;
31   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
32   mc_heap_ignore_region_t region;
33
34   while(start <= end){
35     cursor = (start + end) / 2;
36     region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
37     if(region->address == address)
38       return region->size;
39     if(region->address < address)
40       start = cursor + 1;
41     if(region->address > address)
42       end = cursor - 1;   
43   }
44
45   return 0;
46 }
47
48 static size_t data_bss_ignore_size(void *address){
49   unsigned int cursor = 0;
50   int start = 0;
51   int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
52   mc_data_bss_ignore_variable_t var;
53
54   while(start <= end){
55     cursor = (start + end) / 2;
56     var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
57     if(var->address == address)
58       return var->size;
59     if(var->address < address)
60       start = cursor + 1;
61     if(var->address > address)
62       end = cursor - 1;   
63   }
64
65   return 0;
66 }
67
68 static int data_bss_program_region_compare(void *d1, void *d2, size_t size){
69
70   size_t i = 0;
71   int pointer_align;
72   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;
73   
74   for(i=0; i<size; i++){
75     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
76       pointer_align = (i / sizeof(void*)) * sizeof(void*);
77       addr_pointed1 = *((void **)((char *)d1 + pointer_align));
78       addr_pointed2 = *((void **)((char *)d2 + pointer_align));
79       if((addr_pointed1 > start_plt_binary && addr_pointed1 < end_plt_binary) || (addr_pointed2 > start_plt_binary && addr_pointed2 < end_plt_binary)){
80         continue;
81       }else{
82         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
83           XBT_VERB("Different byte (offset=%zu) (%p - %p) in data program region", i, (char *)d1 + i, (char *)d2 + i);
84           XBT_VERB("Addresses pointed : %p - %p", addr_pointed1, addr_pointed2);
85         }
86         return 1;
87       }
88     }
89   }
90   
91   return 0;
92 }
93
94 static int data_bss_libsimgrid_region_compare(void *d1, void *d2, size_t size){
95
96   size_t i = 0, ignore_size = 0;
97   int pointer_align;
98   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;
99
100   for(i=0; i<size; i++){
101     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
102       if((ignore_size = data_bss_ignore_size((char *)start_data_libsimgrid+i)) > 0){
103         i = i + ignore_size;
104         continue;
105       }else if((ignore_size = data_bss_ignore_size((char *)start_bss_libsimgrid+i)) > 0){
106         i = i + ignore_size;
107         continue;
108       }
109       pointer_align = (i / sizeof(void*)) * sizeof(void*);
110       addr_pointed1 = *((void **)((char *)d1 + pointer_align));
111       addr_pointed2 = *((void **)((char *)d2 + pointer_align));
112       if((addr_pointed1 > start_plt_libsimgrid && addr_pointed1 < end_plt_libsimgrid) || (addr_pointed2 > start_plt_libsimgrid && addr_pointed2 < end_plt_libsimgrid)){
113         continue;
114       }else if(addr_pointed1 >= raw_heap && addr_pointed1 <= end_raw_heap && addr_pointed2 >= raw_heap && addr_pointed2 <= end_raw_heap){
115         continue;
116       }else{
117         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
118           XBT_VERB("Different byte (offset=%zu) (%p - %p) in libsimgrid region", i, (char *)d1 + i, (char *)d2 + i);
119           XBT_VERB("Addresses pointed : %p - %p", addr_pointed1, addr_pointed2);
120         }
121         return 1;
122       }
123     }
124   }
125   
126   return 0;
127 }
128
129 static int heap_region_compare(void *d1, void *d2, size_t size){
130   
131   size_t i = 0;
132   
133   for(i=0; i<size; i++){
134     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
135       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
136         XBT_VERB("Different byte (offset=%zu) (%p - %p) in heap region", i, (char *)d1 + i, (char *)d2 + i);
137       }
138       return 1;
139     }
140   }
141   
142   return 0;
143 }
144
145 static void stack_region_free(stack_region_t s){
146   if(s){
147     xbt_free(s->process_name);
148     xbt_free(s);
149   }
150 }
151
152 void stack_region_free_voidp(void *s){
153   stack_region_free((stack_region_t) * (void **) s);
154 }
155
156 static void heap_equality_free(heap_equality_t e){
157   if(e){
158     xbt_free(e);
159   }
160 }
161
162 void heap_equality_free_voidp(void *e){
163   heap_equality_free((heap_equality_t) * (void **) e);
164 }
165
166 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, mc_comparison_times_t ct1, mc_comparison_times_t ct2){
167
168   raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
169   
170   MC_SET_RAW_MEM;
171
172   int errors = 0, i = 0;
173
174   if(s1->num_reg != s2->num_reg){
175     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
176       XBT_VERB("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
177     }
178     return 1;
179   }
180
181   int heap_index = 0, data_libsimgrid_index = 0, data_program_index = 0;
182
183   /* Get index of regions */
184   while(i < s1->num_reg){
185     switch(s1->regions[i]->type){
186     case 0:
187       heap_index = i;
188       i++;
189       break;
190     case 1:
191       data_libsimgrid_index = i;
192       i++;
193       while( i < s1->num_reg && s1->regions[i]->type == 1)
194         i++;
195       break;
196     case 2:
197       data_program_index = i;
198       i++;
199       while( i < s1->num_reg && s1->regions[i]->type == 2)
200         i++;
201       break;
202     }
203   }
204
205   ct1->nb_comparisons++;
206   ct2->nb_comparisons++;
207
208   xbt_os_timer_t global_timer = xbt_os_timer_new();
209   xbt_os_timer_t timer = xbt_os_timer_new();
210
211   xbt_os_timer_start(global_timer);
212
213   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
214     xbt_os_timer_start(timer);
215
216   /* Compare number of blocks/fragments used in each heap */
217   size_t chunks_used1 = mmalloc_get_chunks_used((xbt_mheap_t)s1->regions[heap_index]->data);
218   size_t chunks_used2 = mmalloc_get_chunks_used((xbt_mheap_t)s2->regions[heap_index]->data);
219   if(chunks_used1 != chunks_used2){
220     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
221       xbt_os_timer_stop(timer);
222       xbt_dynar_push_as(ct1->chunks_used_comparison_times, double, xbt_os_timer_elapsed(timer));
223       xbt_dynar_push_as(ct2->chunks_used_comparison_times, double, xbt_os_timer_elapsed(timer));
224       XBT_DEBUG("Different number of chunks used in each heap : %zu - %zu", chunks_used1, chunks_used2);
225       errors++;
226     }else{
227       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
228         XBT_VERB("Different number of chunks used in each heap : %zu - %zu", chunks_used1, chunks_used2);
229      
230       xbt_os_timer_free(timer);
231       xbt_os_timer_stop(global_timer);
232       xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
233       xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
234       xbt_os_timer_free(global_timer);
235
236       if(!raw_mem_set)
237         MC_UNSET_RAW_MEM;
238
239       return 1;
240     }
241   }else{
242     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
243       xbt_os_timer_stop(timer);
244   }
245   
246   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
247     xbt_os_timer_start(timer);
248
249   /* Compare size of stacks */
250   unsigned int cursor = 0;
251   void *addr_stack1, *addr_stack2;
252   void *sp1, *sp2;
253   size_t size_used1, size_used2;
254   int is_diff = 0;
255   while(cursor < xbt_dynar_length(stacks_areas)){
256     addr_stack1 = (char *)s1->regions[heap_index]->data + ((char *)((stack_region_t)xbt_dynar_get_as(stacks_areas, cursor, stack_region_t))->address - (char *)std_heap);
257     addr_stack2 = (char *)s2->regions[heap_index]->data + ((char *)((stack_region_t)xbt_dynar_get_as(stacks_areas, cursor, stack_region_t))->address - (char *)std_heap);
258     sp1 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
259     sp2 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
260     size_used1 = ((stack_region_t)xbt_dynar_get_as(stacks_areas, cursor, stack_region_t))->size - ((char*)sp1 - (char*)addr_stack1);
261     size_used2 = ((stack_region_t)xbt_dynar_get_as(stacks_areas, cursor, stack_region_t))->size - ((char*)sp2 - (char*)addr_stack2);
262     if(size_used1 != size_used2){
263       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
264         if(is_diff == 0){
265           xbt_os_timer_stop(timer);
266           xbt_dynar_push_as(ct1->stacks_sizes_comparison_times, double, xbt_os_timer_elapsed(timer));
267           xbt_dynar_push_as(ct2->stacks_sizes_comparison_times, double, xbt_os_timer_elapsed(timer));
268         }
269         XBT_DEBUG("Different size used in stacks : %zu - %zu", size_used1, size_used2);
270         errors++;
271         is_diff = 1;
272       }else{
273         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
274           XBT_VERB("Different size used in stacks : %zu - %zu", size_used1, size_used2);
275  
276         xbt_os_timer_free(timer);
277         xbt_os_timer_stop(global_timer);
278         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
279         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
280         xbt_os_timer_free(global_timer);
281
282         if(!raw_mem_set)
283           MC_UNSET_RAW_MEM;
284         return 1;
285       }
286     }
287     cursor++;
288   }
289
290   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
291     if(is_diff == 0)
292       xbt_os_timer_stop(timer);
293     xbt_os_timer_start(timer);
294   }
295   
296   /* Compare program data segment(s) */
297   is_diff = 0;
298   i = data_program_index;
299   while(i < s1->num_reg && s1->regions[i]->type == 2){
300     if(data_bss_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
301       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
302         if(is_diff == 0){
303           xbt_os_timer_stop(timer);
304           xbt_dynar_push_as(ct1->program_data_segment_comparison_times, double, xbt_os_timer_elapsed(timer));
305           xbt_dynar_push_as(ct2->program_data_segment_comparison_times, double, xbt_os_timer_elapsed(timer));
306         }
307         XBT_DEBUG("Different memcmp for data in program");
308         errors++;
309         is_diff = 1;
310       }else{
311         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
312           XBT_VERB("Different memcmp for data in program"); 
313
314         xbt_os_timer_free(timer);
315         xbt_os_timer_stop(global_timer);
316         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
317         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
318         xbt_os_timer_free(global_timer);
319
320         if(!raw_mem_set)
321           MC_UNSET_RAW_MEM;
322         return 1;
323       }
324     }
325     i++;
326   }
327
328   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
329     if(is_diff == 0)
330       xbt_os_timer_stop(timer);
331     xbt_os_timer_start(timer);
332   }
333
334   /* Compare libsimgrid data segment(s) */
335   is_diff = 0;
336   i = data_libsimgrid_index;
337   while(i < s1->num_reg && s1->regions[i]->type == 1){
338     if(data_bss_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
339       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
340         if(is_diff == 0){
341           xbt_os_timer_stop(timer);
342           xbt_dynar_push_as(ct1->libsimgrid_data_segment_comparison_times, double, xbt_os_timer_elapsed(timer));
343           xbt_dynar_push_as(ct2->libsimgrid_data_segment_comparison_times, double, xbt_os_timer_elapsed(timer));
344         }
345         XBT_DEBUG("Different memcmp for data in libsimgrid");
346         errors++;
347         is_diff = 1;
348       }else{
349         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
350           XBT_VERB("Different memcmp for data in libsimgrid");
351          
352         xbt_os_timer_free(timer);
353         xbt_os_timer_stop(global_timer);
354         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
355         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
356         xbt_os_timer_free(global_timer);
357         
358         if(!raw_mem_set)
359           MC_UNSET_RAW_MEM;
360         return 1;
361       }
362     }
363     i++;
364   }
365
366   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
367     if(is_diff == 0)
368       xbt_os_timer_stop(timer);
369     xbt_os_timer_start(timer);
370   }
371
372   /* Compare heap */
373   xbt_dynar_t stacks1 = xbt_dynar_new(sizeof(stack_region_t), stack_region_free_voidp);
374   xbt_dynar_t stacks2 = xbt_dynar_new(sizeof(stack_region_t), stack_region_free_voidp);
375   xbt_dynar_t equals = xbt_dynar_new(sizeof(heap_equality_t), heap_equality_free_voidp);
376   
377   void *heap1 = s1->regions[heap_index]->data, *heap2 = s2->regions[heap_index]->data;
378  
379   if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[heap_index]->data, (xbt_mheap_t)s2->regions[heap_index]->data, &stacks1, &stacks2, &equals)){
380
381     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
382       xbt_os_timer_stop(timer);
383       xbt_dynar_push_as(ct1->heap_comparison_times, double, xbt_os_timer_elapsed(timer));
384       xbt_dynar_push_as(ct2->heap_comparison_times, double, xbt_os_timer_elapsed(timer));
385       XBT_DEBUG("Different heap (mmalloc_compare)");
386       errors++;
387     }else{
388
389       xbt_os_timer_free(timer);
390       xbt_dynar_free(&stacks1);
391       xbt_dynar_free(&stacks2);
392       xbt_dynar_free(&equals);
393  
394       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
395         XBT_VERB("Different heap (mmalloc_compare)");
396        
397       xbt_os_timer_stop(global_timer);
398       xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
399       xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
400       xbt_os_timer_free(global_timer);
401
402       if(!raw_mem_set)
403         MC_UNSET_RAW_MEM;
404       return 1;
405     } 
406   }else{
407     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
408       xbt_os_timer_stop(timer);
409   }
410
411   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
412     xbt_os_timer_start(timer);
413
414   /* Stacks comparison */
415   cursor = 0;
416   stack_region_t stack_region1, stack_region2;
417   int diff = 0, diff_local = 0;
418   is_diff = 0;
419
420   while(cursor < xbt_dynar_length(stacks1)){
421     stack_region1 = (stack_region_t)(xbt_dynar_get_as(stacks1, cursor, stack_region_t));
422     stack_region2 = (stack_region_t)(xbt_dynar_get_as(stacks2, cursor, stack_region_t));
423     sp1 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
424     sp2 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
425     diff = compare_stack(stack_region1, stack_region2, sp1, sp2, heap1, heap2, equals);
426
427     if(diff > 0){ /* Differences may be due to padding */  
428       diff_local = compare_local_variables(((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->local_variables->data, ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->local_variables->data, equals);
429       if(diff_local > 0){
430         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
431           if(is_diff == 0){
432             xbt_os_timer_stop(timer);
433             xbt_dynar_push_as(ct1->stacks_comparison_times, double, xbt_os_timer_elapsed(timer));
434             xbt_dynar_push_as(ct2->stacks_comparison_times, double, xbt_os_timer_elapsed(timer));
435           }
436           XBT_DEBUG("Different local variables between stacks %d", cursor + 1);
437           errors++;
438           is_diff = 1;
439         }else{
440           xbt_dynar_free(&stacks1);
441           xbt_dynar_free(&stacks2);
442           xbt_dynar_free(&equals);
443
444           if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
445             XBT_VERB("Different local variables between stacks %d", cursor + 1);
446           
447           xbt_os_timer_free(timer);
448           xbt_os_timer_stop(global_timer);
449           xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
450           xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
451           xbt_os_timer_free(global_timer);
452           
453           if(!raw_mem_set)
454             MC_UNSET_RAW_MEM;
455
456           return 1;
457         }
458       }
459     }
460     cursor++;
461   }
462
463   xbt_dynar_free(&stacks1);
464   xbt_dynar_free(&stacks2);
465   xbt_dynar_free(&equals);
466
467   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))    
468     xbt_os_timer_free(timer);
469
470   if(!XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
471     xbt_os_timer_stop(global_timer);
472     xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
473     xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
474   }
475   xbt_os_timer_free(global_timer);
476
477   if(!raw_mem_set)
478     MC_UNSET_RAW_MEM;
479
480   return errors > 0;
481   
482 }
483
484 static int is_stack_ignore_variable(char *frame, char *var_name){
485
486   unsigned int cursor = 0;
487   int start = 0;
488   int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
489   mc_stack_ignore_variable_t current_var;
490
491   while(start <= end){
492     cursor = (start + end) / 2;
493     current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
494     if(strcmp(current_var->frame, frame) == 0){
495       if(strcmp(current_var->var_name, var_name) == 0)
496         return 1;
497       if(strcmp(current_var->var_name, var_name) < 0)
498         start = cursor + 1;
499       if(strcmp(current_var->var_name, var_name) > 0)
500         end = cursor - 1;
501     }
502   if(strcmp(current_var->frame, frame) < 0)
503       start = cursor + 1;
504   if(strcmp(current_var->frame, frame) > 0)
505       end = cursor - 1; 
506   }
507
508   return 0;
509 }
510
511 static int compare_local_variables(char *s1, char *s2, xbt_dynar_t heap_equals){
512   
513   xbt_dynar_t tokens1 = xbt_str_split(s1, NULL);
514   xbt_dynar_t tokens2 = xbt_str_split(s2, NULL);
515
516   xbt_dynar_t s_tokens1, s_tokens2;
517   unsigned int cursor = 0;
518   void *addr1, *addr2;
519   char *ip1 = NULL, *ip2 = NULL;
520   
521   while(cursor < xbt_dynar_length(tokens1)){
522     s_tokens1 = xbt_str_split(xbt_dynar_get_as(tokens1, cursor, char *), "=");
523     s_tokens2 = xbt_str_split(xbt_dynar_get_as(tokens2, cursor, char *), "=");
524     if(xbt_dynar_length(s_tokens1) > 1 && xbt_dynar_length(s_tokens2) > 1){
525       if((strcmp(xbt_dynar_get_as(s_tokens1, 0, char *), "ip") == 0) && (strcmp(xbt_dynar_get_as(s_tokens2, 0, char *), "ip") == 0)){
526         ip1 = strdup(xbt_dynar_get_as(s_tokens1, 1, char *));
527         ip2 = strdup(xbt_dynar_get_as(s_tokens2, 1, char *));
528         /*if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
529           XBT_VERB("Instruction pointer : %s, Instruction pointer : %s", ip1, ip2);*/
530       }
531       if(strcmp(xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *)) != 0){   
532         /* Ignore this variable ?  */
533         if(is_stack_ignore_variable(ip1, xbt_dynar_get_as(s_tokens1, 0, char *)) && is_stack_ignore_variable(ip2, xbt_dynar_get_as(s_tokens2, 0, char *))){
534           xbt_dynar_free(&s_tokens1);
535           xbt_dynar_free(&s_tokens2);
536           cursor++;
537           continue;
538         }
539         addr1 = (void *) strtoul(xbt_dynar_get_as(s_tokens1, 1, char *), NULL, 16);
540         addr2 = (void *) strtoul(xbt_dynar_get_as(s_tokens2, 1, char *), NULL, 16);
541         if(is_heap_equality(heap_equals, addr1, addr2) == 0){
542           if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
543             XBT_VERB("Variable %s is different between stacks : %s - %s", xbt_dynar_get_as(s_tokens1, 0, char *), xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *));
544           xbt_dynar_free(&s_tokens1);
545           xbt_dynar_free(&s_tokens2);
546           return 1;
547         }
548       }
549     }
550     xbt_dynar_free(&s_tokens1);
551     xbt_dynar_free(&s_tokens2);
552     cursor++;
553   }
554
555   xbt_dynar_free(&tokens1);
556   xbt_dynar_free(&tokens2);
557   return 0;
558   
559 }
560
561 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2){
562
563   unsigned int cursor = 0;
564   int start = 0;
565   int end = xbt_dynar_length(equals) - 1;
566   heap_equality_t current_equality;
567
568   while(start <= end){
569     cursor = (start + end) / 2;
570     current_equality = (heap_equality_t)xbt_dynar_get_as(equals, cursor, heap_equality_t);
571     if(current_equality->address1 == a1){
572       if(current_equality->address2 == a2)
573         return 1;
574       if(current_equality->address2 < a2)
575         start = cursor + 1;
576       if(current_equality->address2 > a2)
577         end = cursor - 1;
578     }
579     if(current_equality->address1 < a1)
580       start = cursor + 1;
581     if(current_equality->address1 > a1)
582       end = cursor - 1; 
583   }
584
585   return 0;
586
587 }
588
589
590 static int compare_stack(stack_region_t s1, stack_region_t s2, void *sp1, void *sp2, void *heap1, void *heap2, xbt_dynar_t equals){
591   
592   size_t k = 0;
593   size_t size_used1 = s1->size - ((char*)sp1 - (char*)s1->address);
594   size_t size_used2 = s2->size - ((char*)sp2 - (char*)s2->address);
595
596   int pointer_align;
597   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;  
598   
599   while(k < size_used1){
600     if(memcmp((char *)s1->address + s1->size - k, (char *)s2->address + s2->size - k, 1) != 0){
601       pointer_align = ((size_used1 - k) / sizeof(void*)) * sizeof(void*);
602       addr_pointed1 = *((void **)(((char*)s1->address + (s1->size - size_used1)) + pointer_align));
603       addr_pointed2 = *((void **)(((char*)s2->address + (s2->size - size_used2)) + pointer_align));
604       if(is_heap_equality(equals, addr_pointed1, addr_pointed2) == 0){
605         if((addr_pointed1 > std_heap) && (addr_pointed1 < (void *)((char *)std_heap + STD_HEAP_SIZE)) && (addr_pointed2 > std_heap) && (addr_pointed2 < (void *)((char *)std_heap + STD_HEAP_SIZE))){
606           if(is_free_area(addr_pointed1, (xbt_mheap_t)heap1) == 0 || is_free_area(addr_pointed2, (xbt_mheap_t)heap2) == 0){
607             return 1;
608           }
609         }else{
610           return 1;
611         } 
612       }
613     } 
614     k++;
615   }
616  
617   return 0;
618 }
619
620 int MC_compare_snapshots(void *s1, void *s2){
621
622   return simcall_mc_compare_snapshots(s1, s2);
623
624 }