Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix lua platform script
[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(s1->num_reg != s2->num_reg){
174     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
175       XBT_VERB("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
176     }
177     if(!raw_mem)
178       MC_UNSET_RAW_MEM;
179     return 1;
180   }
181
182   int heap_index = 0, data_libsimgrid_index = 0, data_program_index = 0;
183
184   /* Get index of regions */
185   while(i < s1->num_reg){
186     switch(s1->regions[i]->type){
187     case 0:
188       heap_index = i;
189       i++;
190       break;
191     case 1:
192       data_libsimgrid_index = i;
193       i++;
194       while( i < s1->num_reg && s1->regions[i]->type == 1)
195         i++;
196       break;
197     case 2:
198       data_program_index = i;
199       i++;
200       while( i < s1->num_reg && s1->regions[i]->type == 2)
201         i++;
202       break;
203     }
204   }
205
206   if(ct1 != NULL)
207     ct1->nb_comparisons++;
208   if(ct2 != NULL)
209     ct2->nb_comparisons++;
210
211   xbt_os_timer_t global_timer = xbt_os_timer_new();
212   xbt_os_timer_t timer = xbt_os_timer_new();
213
214   xbt_os_timer_start(global_timer);
215
216   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
217     xbt_os_timer_start(timer);
218
219   /* Compare number of blocks/fragments used in each heap */
220   size_t chunks_used1 = mmalloc_get_chunks_used((xbt_mheap_t)s1->regions[heap_index]->data);
221   size_t chunks_used2 = mmalloc_get_chunks_used((xbt_mheap_t)s2->regions[heap_index]->data);
222   if(chunks_used1 != chunks_used2){
223     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
224       xbt_os_timer_stop(timer);
225       if(ct1 != NULL)
226         xbt_dynar_push_as(ct1->chunks_used_comparison_times, double, xbt_os_timer_elapsed(timer));
227       if(ct2 != NULL)
228         xbt_dynar_push_as(ct2->chunks_used_comparison_times, double, xbt_os_timer_elapsed(timer));
229       XBT_DEBUG("Different number of chunks used in each heap : %zu - %zu", chunks_used1, chunks_used2);
230       errors++;
231     }else{
232       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
233         XBT_VERB("Different number of chunks used in each heap : %zu - %zu", chunks_used1, chunks_used2);
234      
235       xbt_os_timer_free(timer);
236       xbt_os_timer_stop(global_timer);
237       if(ct1 != NULL)
238         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
239       if(ct2 != NULL)
240         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
241       xbt_os_timer_free(global_timer);
242
243       if(!raw_mem)
244         MC_UNSET_RAW_MEM;
245
246       return 1;
247     }
248   }else{
249     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
250       xbt_os_timer_stop(timer);
251   }
252   
253   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
254     xbt_os_timer_start(timer);
255
256   /* Compare size of stacks */
257   unsigned int cursor = 0;
258   void *addr_stack1, *addr_stack2;
259   void *sp1, *sp2;
260   size_t size_used1, size_used2;
261   int is_diff = 0;
262   while(cursor < xbt_dynar_length(stacks_areas)){
263     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);
264     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);
265     sp1 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
266     sp2 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
267     size_used1 = ((stack_region_t)xbt_dynar_get_as(stacks_areas, cursor, stack_region_t))->size - ((char*)sp1 - (char*)addr_stack1);
268     size_used2 = ((stack_region_t)xbt_dynar_get_as(stacks_areas, cursor, stack_region_t))->size - ((char*)sp2 - (char*)addr_stack2);
269     if(size_used1 != size_used2){
270       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
271         if(is_diff == 0){
272           xbt_os_timer_stop(timer);
273           if(ct1 != NULL)
274             xbt_dynar_push_as(ct1->stacks_sizes_comparison_times, double, xbt_os_timer_elapsed(timer));
275           if(ct2 != NULL)
276             xbt_dynar_push_as(ct2->stacks_sizes_comparison_times, double, xbt_os_timer_elapsed(timer));
277         }
278         XBT_DEBUG("Different size used in stacks : %zu - %zu", size_used1, size_used2);
279         errors++;
280         is_diff = 1;
281       }else{
282         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
283           XBT_VERB("Different size used in stacks : %zu - %zu", size_used1, size_used2);
284  
285         xbt_os_timer_free(timer);
286         xbt_os_timer_stop(global_timer);
287         if(ct1 != NULL)
288           xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
289         if(ct2 != NULL)
290           xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
291         xbt_os_timer_free(global_timer);
292
293         if(!raw_mem)
294           MC_UNSET_RAW_MEM;
295
296         return 1;
297       }
298     }
299     cursor++;
300   }
301
302   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
303     if(is_diff == 0)
304       xbt_os_timer_stop(timer);
305     xbt_os_timer_start(timer);
306   }
307
308   /* Compare binary global variables */
309   is_diff = compare_global_variables(s1->regions[data_program_index]->type, s1->regions[data_program_index]->data, s2->regions[data_program_index]->data);
310   if(is_diff != 0){
311     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
312       xbt_os_timer_stop(timer);
313       if(ct1 != NULL)
314         xbt_dynar_push_as(ct1->binary_global_variables_comparison_times, double, xbt_os_timer_elapsed(timer));
315       if(ct2 != NULL)
316         xbt_dynar_push_as(ct2->binary_global_variables_comparison_times, double, xbt_os_timer_elapsed(timer));
317       XBT_DEBUG("Different global variables in binary"); 
318       errors++; 
319     }else{
320       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
321         XBT_VERB("Different global variables in binary"); 
322     
323       xbt_os_timer_free(timer);
324       xbt_os_timer_stop(global_timer);
325       if(ct1 != NULL)
326         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
327       if(ct2 != NULL)
328         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
329       xbt_os_timer_free(global_timer);
330     
331       if(!raw_mem)
332         MC_UNSET_RAW_MEM;
333       return 1;
334     }
335   }
336
337   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
338     if(is_diff == 0)
339       xbt_os_timer_stop(timer);
340     xbt_os_timer_start(timer);
341   }
342
343   /* Compare libsimgrid global variables */
344   is_diff = compare_global_variables(s1->regions[data_libsimgrid_index]->type, s1->regions[data_libsimgrid_index]->data, s2->regions[data_libsimgrid_index]->data);
345   if(is_diff != 0){
346     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
347       xbt_os_timer_stop(timer);
348       if(ct1 != NULL)
349         xbt_dynar_push_as(ct1->libsimgrid_global_variables_comparison_times, double, xbt_os_timer_elapsed(timer));
350       if(ct2 != NULL)
351         xbt_dynar_push_as(ct2->libsimgrid_global_variables_comparison_times, double, xbt_os_timer_elapsed(timer));
352       XBT_DEBUG("Different global variables in libsimgrid"); 
353       errors++; 
354     }else{
355       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
356         XBT_VERB("Different global variables in libsimgrid"); 
357     
358       xbt_os_timer_free(timer);
359       xbt_os_timer_stop(global_timer);
360       if(ct1 != NULL)
361         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
362       if(ct2 != NULL)
363         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
364       xbt_os_timer_free(global_timer);
365     
366       if(!raw_mem)
367         MC_UNSET_RAW_MEM;
368       return 1;
369     }
370   }  
371
372   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
373     if(is_diff == 0)
374       xbt_os_timer_stop(timer);
375     xbt_os_timer_start(timer);
376   }
377
378   /* Compare heap */
379   xbt_dynar_t stacks1 = xbt_dynar_new(sizeof(stack_region_t), stack_region_free_voidp);
380   xbt_dynar_t stacks2 = xbt_dynar_new(sizeof(stack_region_t), stack_region_free_voidp);
381   xbt_dynar_t equals = xbt_dynar_new(sizeof(heap_equality_t), heap_equality_free_voidp);
382   
383   void *heap1 = s1->regions[heap_index]->data, *heap2 = s2->regions[heap_index]->data;
384  
385   if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[heap_index]->data, (xbt_mheap_t)s2->regions[heap_index]->data, &stacks1, &stacks2, &equals)){
386
387     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
388       xbt_os_timer_stop(timer);
389       if(ct1 != NULL)
390         xbt_dynar_push_as(ct1->heap_comparison_times, double, xbt_os_timer_elapsed(timer));
391       if(ct2 != NULL)
392         xbt_dynar_push_as(ct2->heap_comparison_times, double, xbt_os_timer_elapsed(timer));
393       XBT_DEBUG("Different heap (mmalloc_compare)");
394       errors++;
395     }else{
396
397       xbt_os_timer_free(timer);
398       xbt_dynar_free(&stacks1);
399       xbt_dynar_free(&stacks2);
400       xbt_dynar_free(&equals);
401  
402       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
403         XBT_VERB("Different heap (mmalloc_compare)");
404        
405       xbt_os_timer_stop(global_timer);
406       if(ct1 != NULL)
407         xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
408       if(ct2 != NULL)
409         xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
410       xbt_os_timer_free(global_timer);
411
412       if(!raw_mem)
413         MC_UNSET_RAW_MEM;
414       return 1;
415     } 
416   }else{
417     if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
418       xbt_os_timer_stop(timer);
419   }
420
421   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))
422     xbt_os_timer_start(timer);
423
424   /* Stacks comparison */
425   cursor = 0;
426   stack_region_t stack_region1, stack_region2;
427   int diff = 0, diff_local = 0;
428   is_diff = 0;
429
430   while(cursor < xbt_dynar_length(stacks1)){
431     stack_region1 = (stack_region_t)(xbt_dynar_get_as(stacks1, cursor, stack_region_t));
432     stack_region2 = (stack_region_t)(xbt_dynar_get_as(stacks2, cursor, stack_region_t));
433     sp1 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
434     sp2 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
435     diff = compare_stack(stack_region1, stack_region2, sp1, sp2, heap1, heap2, equals);
436
437     if(diff > 0){ /* Differences may be due to padding */  
438       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);
439       if(diff_local > 0){
440         if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
441           if(is_diff == 0){
442             xbt_os_timer_stop(timer);
443             if(ct1 != NULL)
444               xbt_dynar_push_as(ct1->stacks_comparison_times, double, xbt_os_timer_elapsed(timer));
445             if(ct2 != NULL)
446               xbt_dynar_push_as(ct2->stacks_comparison_times, double, xbt_os_timer_elapsed(timer));
447           }
448           XBT_DEBUG("Different local variables between stacks %d", cursor + 1);
449           errors++;
450           is_diff = 1;
451         }else{
452           xbt_dynar_free(&stacks1);
453           xbt_dynar_free(&stacks2);
454           xbt_dynar_free(&equals);
455
456           if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
457             XBT_VERB("Different local variables between stacks %d", cursor + 1);
458           
459           xbt_os_timer_free(timer);
460           xbt_os_timer_stop(global_timer);
461           if(ct1 != NULL)
462             xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
463           if(ct2 != NULL)
464             xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
465           xbt_os_timer_free(global_timer);
466           
467           if(!raw_mem)
468             MC_UNSET_RAW_MEM;
469
470           return 1;
471         }
472       }
473     }
474     cursor++;
475   }
476
477   xbt_dynar_free(&stacks1);
478   xbt_dynar_free(&stacks2);
479   xbt_dynar_free(&equals);
480
481   if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug))    
482     xbt_os_timer_free(timer);
483
484   if(!XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_debug)){
485     xbt_os_timer_stop(global_timer);
486     if(ct1 != NULL)
487       xbt_dynar_push_as(ct1->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
488     if(ct2 != NULL)
489       xbt_dynar_push_as(ct2->snapshot_comparison_times, double, xbt_os_timer_elapsed(global_timer));
490   }
491   xbt_os_timer_free(global_timer);
492
493   if(!raw_mem)
494     MC_UNSET_RAW_MEM;
495
496   return errors > 0;
497   
498 }
499
500 static int is_stack_ignore_variable(char *frame, char *var_name){
501
502   unsigned int cursor = 0;
503   int start = 0;
504   int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
505   mc_stack_ignore_variable_t current_var;
506
507   while(start <= end){
508     cursor = (start + end) / 2;
509     current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
510     if(strcmp(current_var->frame, frame) == 0 || strcmp(current_var->frame, "*") == 0){
511       if(strcmp(current_var->var_name, var_name) == 0)
512         return 1;
513       if(strcmp(current_var->var_name, var_name) < 0)
514         start = cursor + 1;
515       if(strcmp(current_var->var_name, var_name) > 0)
516         end = cursor - 1;
517     }else if(strcmp(current_var->frame, frame) < 0){
518       start = cursor + 1;
519     }else if(strcmp(current_var->frame, frame) > 0){
520       end = cursor - 1; 
521     }
522   }
523
524   return 0;
525 }
526
527 static int compare_local_variables(char *s1, char *s2, xbt_dynar_t heap_equals){
528   
529   xbt_dynar_t tokens1 = xbt_str_split(s1, NULL);
530   xbt_dynar_t tokens2 = xbt_str_split(s2, NULL);
531
532   xbt_dynar_t s_tokens1, s_tokens2;
533   unsigned int cursor = 0;
534   void *addr1, *addr2;
535   char *ip1 = NULL, *ip2 = NULL;
536   
537   while(cursor < xbt_dynar_length(tokens1)){
538     s_tokens1 = xbt_str_split(xbt_dynar_get_as(tokens1, cursor, char *), "=");
539     s_tokens2 = xbt_str_split(xbt_dynar_get_as(tokens2, cursor, char *), "=");
540     if(xbt_dynar_length(s_tokens1) > 1 && xbt_dynar_length(s_tokens2) > 1){
541       if((strcmp(xbt_dynar_get_as(s_tokens1, 0, char *), "ip") == 0) && (strcmp(xbt_dynar_get_as(s_tokens2, 0, char *), "ip") == 0)){
542         ip1 = strdup(xbt_dynar_get_as(s_tokens1, 1, char *));
543         ip2 = strdup(xbt_dynar_get_as(s_tokens2, 1, char *));
544       }
545       if(strcmp(xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *)) != 0){   
546         /* Ignore this variable ?  */
547         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 *))){
548           xbt_dynar_free(&s_tokens1);
549           xbt_dynar_free(&s_tokens2);
550           cursor++;
551           continue;
552         }
553         addr1 = (void *) strtoul(xbt_dynar_get_as(s_tokens1, 1, char *), NULL, 16);
554         addr2 = (void *) strtoul(xbt_dynar_get_as(s_tokens2, 1, char *), NULL, 16);
555         if(is_heap_equality(heap_equals, addr1, addr2) == 0){
556           if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
557             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 *));
558           xbt_dynar_free(&s_tokens1);
559           xbt_dynar_free(&s_tokens2);
560           return 1;
561         }
562       }
563     }
564     xbt_dynar_free(&s_tokens1);
565     xbt_dynar_free(&s_tokens2);
566     cursor++;
567   }
568
569   xbt_dynar_free(&tokens1);
570   xbt_dynar_free(&tokens2);
571   return 0;
572   
573 }
574
575 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2){
576
577   unsigned int cursor = 0;
578   int start = 0;
579   int end = xbt_dynar_length(equals) - 1;
580   heap_equality_t current_equality;
581
582   while(start <= end){
583     cursor = (start + end) / 2;
584     current_equality = (heap_equality_t)xbt_dynar_get_as(equals, cursor, heap_equality_t);
585     if(current_equality->address1 == a1){
586       if(current_equality->address2 == a2)
587         return 1;
588       if(current_equality->address2 < a2)
589         start = cursor + 1;
590       if(current_equality->address2 > a2)
591         end = cursor - 1;
592     }
593     if(current_equality->address1 < a1)
594       start = cursor + 1;
595     if(current_equality->address1 > a1)
596       end = cursor - 1; 
597   }
598
599   return 0;
600
601 }
602
603
604 static int compare_stack(stack_region_t s1, stack_region_t s2, void *sp1, void *sp2, void *heap1, void *heap2, xbt_dynar_t equals){
605   
606   size_t k = 0;
607   size_t size_used1 = s1->size - ((char*)sp1 - (char*)s1->address);
608   size_t size_used2 = s2->size - ((char*)sp2 - (char*)s2->address);
609
610   int pointer_align;
611   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;  
612   
613   while(k < size_used1){
614     if(memcmp((char *)s1->address + s1->size - k, (char *)s2->address + s2->size - k, 1) != 0){
615       pointer_align = ((size_used1 - k) / sizeof(void*)) * sizeof(void*);
616       addr_pointed1 = *((void **)(((char*)s1->address + (s1->size - size_used1)) + pointer_align));
617       addr_pointed2 = *((void **)(((char*)s2->address + (s2->size - size_used2)) + pointer_align));
618       if(is_heap_equality(equals, addr_pointed1, addr_pointed2) == 0){
619         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))){
620           if(is_free_area(addr_pointed1, (xbt_mheap_t)heap1) == 0 || is_free_area(addr_pointed2, (xbt_mheap_t)heap2) == 0){
621             return 1;
622           }
623         }else{
624           return 1;
625         } 
626       }
627     } 
628     k++;
629   }
630  
631   return 0;
632 }
633
634 int MC_compare_snapshots(void *s1, void *s2){
635   
636   MC_ignore_stack("self", "simcall_BODY_mc_snapshot");
637
638   return simcall_mc_compare_snapshots(s1, s2);
639
640 }