Logo AND Algorithmique Numérique Distribuée

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