Logo AND Algorithmique Numérique Distribuée

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