Logo AND Algorithmique Numérique Distribuée

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