Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Add useless parends to remove WTF warning-which-is-an-error
[simgrid.git] / src / mc / mc_global.c
1 /* Copyright (c) 2008-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <sys/time.h>
11 #include <sys/mman.h>
12 #include <libgen.h>
13
14 #define UNW_LOCAL_ONLY
15 #include <libunwind.h>
16
17 #include "simgrid/sg_config.h"
18 #include "../surf/surf_private.h"
19 #include "../simix/smx_private.h"
20 #include "../xbt/mmalloc/mmprivate.h"
21 #include "xbt/fifo.h"
22 #include "mc_private.h"
23 #include "xbt/automaton.h"
24 #include "xbt/dict.h"
25
26 XBT_LOG_NEW_CATEGORY(mc, "All MC categories");
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
28                                 "Logging specific to MC (global)");
29
30 int user_max_depth_reached = 0;
31
32 /* MC global data structures */
33 mc_state_t mc_current_state = NULL;
34 char mc_replay_mode = FALSE;
35 double *mc_time = NULL;
36 __thread mc_comparison_times_t mc_comp_times = NULL;
37 __thread double mc_snapshot_comparison_time;
38 mc_stats_t mc_stats = NULL;
39 mc_global_t initial_global_state = NULL;
40 xbt_fifo_t mc_stack = NULL;
41
42 /* Liveness */
43 xbt_automaton_t _mc_property_automaton = NULL;
44
45 /* Variables */
46 mc_object_info_t mc_libsimgrid_info = NULL;
47 mc_object_info_t mc_binary_info = NULL;
48
49 mc_object_info_t mc_object_infos[2] = { NULL, NULL };
50
51 size_t mc_object_infos_size = 2;
52
53 /* Dot output */
54 FILE *dot_output = NULL;
55 const char *colors[13];
56
57
58 /*******************************  Initialisation of MC *******************************/
59 /*********************************************************************************/
60
61 static void MC_init_dot_output()
62 {                               /* FIXME : more colors */
63
64   colors[0] = "blue";
65   colors[1] = "red";
66   colors[2] = "green3";
67   colors[3] = "goldenrod";
68   colors[4] = "brown";
69   colors[5] = "purple";
70   colors[6] = "magenta";
71   colors[7] = "turquoise4";
72   colors[8] = "gray25";
73   colors[9] = "forestgreen";
74   colors[10] = "hotpink";
75   colors[11] = "lightblue";
76   colors[12] = "tan";
77
78   dot_output = fopen(_sg_mc_dot_output_file, "w");
79
80   if (dot_output == NULL) {
81     perror("Error open dot output file");
82     xbt_abort();
83   }
84
85   fprintf(dot_output,
86           "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node [fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
87
88 }
89
90 static void MC_init_debug_info(void)
91 {
92   XBT_INFO("Get debug information ...");
93
94   memory_map_t maps = MC_get_memory_map();
95
96   /* Get local variables for state equality detection */
97   mc_binary_info = MC_find_object_info(maps, xbt_binary_name, 1);
98   mc_object_infos[0] = mc_binary_info;
99
100   mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path, 0);
101   mc_object_infos[1] = mc_libsimgrid_info;
102
103   // Use information of the other objects:
104   MC_post_process_object_info(mc_binary_info);
105   MC_post_process_object_info(mc_libsimgrid_info);
106
107   MC_free_memory_map(maps);
108   XBT_INFO("Get debug information done !");
109 }
110
111
112 mc_model_checker_t mc_model_checker = NULL;
113
114 void MC_init()
115 {
116   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
117
118   mc_time = xbt_new0(double, simix_process_maxpid);
119
120   /* Initialize the data structures that must be persistent across every
121      iteration of the model-checker (in RAW memory) */
122
123   MC_SET_MC_HEAP;
124
125   mc_model_checker = xbt_new0(s_mc_model_checker_t, 1);
126   mc_model_checker->pages = mc_pages_store_new();
127   mc_model_checker->fd_clear_refs = -1;
128   mc_model_checker->fd_pagemap = -1;
129
130   mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
131
132   /* Initialize statistics */
133   mc_stats = xbt_new0(s_mc_stats_t, 1);
134   mc_stats->state_size = 1;
135
136   MC_init_memory_map_info();
137   MC_init_debug_info();         /* FIXME : get debug information only if liveness verification or visited state reduction */
138
139   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0'))
140     MC_init_dot_output();
141
142   /* Init parmap */
143   //parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
144
145   MC_SET_STD_HEAP;
146
147   if (_sg_mc_visited > 0 || _sg_mc_liveness) {
148     /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
149     MC_ignore_local_variable("e", "*");
150     MC_ignore_local_variable("__ex_cleanup", "*");
151     MC_ignore_local_variable("__ex_mctx_en", "*");
152     MC_ignore_local_variable("__ex_mctx_me", "*");
153     MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
154     MC_ignore_local_variable("_log_ev", "*");
155     MC_ignore_local_variable("_throw_ctx", "*");
156     MC_ignore_local_variable("ctx", "*");
157
158     MC_ignore_local_variable("self", "simcall_BODY_mc_snapshot");
159     MC_ignore_local_variable("next_cont"
160       "ext", "smx_ctx_sysv_suspend_serial");
161     MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
162
163     /* Ignore local variable about time used for tracing */
164     MC_ignore_local_variable("start_time", "*");
165
166     MC_ignore_global_variable("mc_model_checker");
167
168     // Mot of those things could be moved into mc_model_checker:
169     MC_ignore_global_variable("compared_pointers");
170     MC_ignore_global_variable("mc_comp_times");
171     MC_ignore_global_variable("mc_snapshot_comparison_time");
172     MC_ignore_global_variable("mc_time");
173     MC_ignore_global_variable("smpi_current_rank");
174     MC_ignore_global_variable("counter");       /* Static variable used for tracing */
175     MC_ignore_global_variable("maestro_stack_start");
176     MC_ignore_global_variable("maestro_stack_end");
177     MC_ignore_global_variable("smx_total_comms");
178     MC_ignore_global_variable("communications_pattern");
179     MC_ignore_global_variable("initial_communications_pattern");
180     MC_ignore_global_variable("incomplete_communications_pattern");
181
182     if (MC_is_active()) {
183       MC_ignore_global_variable("mc_diff_info");
184     }
185
186     MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
187
188     smx_process_t process;
189     xbt_swag_foreach(process, simix_global->process_list) {
190       MC_ignore_heap(&(process->process_hookup),
191                      sizeof(process->process_hookup));
192                      }
193   }
194
195   if (raw_mem_set)
196     MC_SET_MC_HEAP;
197
198 }
199
200 /*******************************  Core of MC *******************************/
201 /**************************************************************************/
202
203 static void MC_modelcheck_comm_determinism_init(void)
204 {
205
206   int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
207
208   MC_init();
209
210   if (!mc_mem_set)
211     MC_SET_MC_HEAP;
212
213   /* Create exploration stack */
214   mc_stack = xbt_fifo_new();
215
216   MC_SET_STD_HEAP;
217
218   MC_pre_modelcheck_comm_determinism();
219
220   MC_SET_MC_HEAP;
221   initial_global_state = xbt_new0(s_mc_global_t, 1);
222   initial_global_state->snapshot = MC_take_snapshot(0);
223   initial_global_state->initial_communications_pattern_done = 0;
224   initial_global_state->comm_deterministic = 1;
225   initial_global_state->send_deterministic = 1;
226   MC_SET_STD_HEAP;
227
228   MC_modelcheck_comm_determinism();
229
230   if(mc_mem_set)
231     MC_SET_MC_HEAP;
232
233 }
234
235 static void MC_modelcheck_safety_init(void)
236 {
237   int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
238
239   _sg_mc_safety = 1;
240
241   MC_init();
242
243   if (!mc_mem_set)
244     MC_SET_MC_HEAP;
245
246   /* Create exploration stack */
247   mc_stack = xbt_fifo_new();
248
249   MC_SET_STD_HEAP;
250
251   MC_pre_modelcheck_safety();
252
253   MC_SET_MC_HEAP;
254   /* Save the initial state */
255   initial_global_state = xbt_new0(s_mc_global_t, 1);
256   initial_global_state->snapshot = MC_take_snapshot(0);
257   MC_SET_STD_HEAP;
258
259   MC_modelcheck_safety();
260
261   if (mc_mem_set)
262     MC_SET_MC_HEAP;
263
264   xbt_abort();
265   //MC_exit();
266 }
267
268 static void MC_modelcheck_liveness_init()
269 {
270
271   int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
272
273   _sg_mc_liveness = 1;
274
275   MC_init();
276
277   if (!mc_mem_set)
278     MC_SET_MC_HEAP;
279
280   /* Create exploration stack */
281   mc_stack = xbt_fifo_new();
282
283   /* Create the initial state */
284   initial_global_state = xbt_new0(s_mc_global_t, 1);
285
286   MC_SET_STD_HEAP;
287
288   MC_pre_modelcheck_liveness();
289
290   /* We're done */
291   MC_print_statistics(mc_stats);
292   xbt_free(mc_time);
293
294   if (mc_mem_set)
295     MC_SET_MC_HEAP;
296
297 }
298
299 void MC_do_the_modelcheck_for_real()
300 {
301
302   if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
303     XBT_INFO("Check communication determinism");
304     MC_modelcheck_comm_determinism_init();
305   } else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0') {
306     if (mc_reduce_kind == e_mc_reduce_unset)
307       mc_reduce_kind = e_mc_reduce_dpor;
308     XBT_INFO("Check a safety property");
309     MC_modelcheck_safety_init();
310   } else {
311     if (mc_reduce_kind == e_mc_reduce_unset)
312       mc_reduce_kind = e_mc_reduce_none;
313     XBT_INFO("Check the liveness property %s", _sg_mc_property_file);
314     MC_automaton_load(_sg_mc_property_file);
315     MC_modelcheck_liveness_init();
316   }
317 }
318
319
320 void MC_exit(void)
321 {
322   xbt_free(mc_time);
323
324   MC_memory_exit();
325   //xbt_abort();
326 }
327
328 int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max)
329 {
330
331   return simcall->mc_value;
332 }
333
334
335 int MC_random(int min, int max)
336 {
337   /*FIXME: return mc_current_state->executed_transition->random.value; */
338   return simcall_mc_random(min, max);
339 }
340
341 /**
342  * \brief Schedules all the process that are ready to run
343  */
344 void MC_wait_for_requests(void)
345 {
346   smx_process_t process;
347   smx_simcall_t req;
348   unsigned int iter;
349
350   while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
351     SIMIX_process_runall();
352       xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
353       req = &process->simcall;
354       if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
355         SIMIX_simcall_handle(req, 0);
356     }
357   }
358 }
359
360 int MC_deadlock_check()
361 {
362   int deadlock = FALSE;
363   smx_process_t process;
364   if (xbt_swag_size(simix_global->process_list)) {
365     deadlock = TRUE;
366     xbt_swag_foreach(process, simix_global->process_list) {
367       if (MC_request_is_enabled(&process->simcall)) {
368         deadlock = FALSE;
369         break;
370       }
371     }
372   }
373   return deadlock;
374 }
375
376 void mc_update_comm_pattern(mc_call_type call_type, smx_simcall_t req, int value, xbt_dynar_t pattern) {
377   switch(call_type) {
378   case MC_CALL_TYPE_NONE:
379     break;
380   case MC_CALL_TYPE_SEND:
381   case MC_CALL_TYPE_RECV:
382     get_comm_pattern(pattern, req, call_type);
383     break;
384   case MC_CALL_TYPE_WAIT:
385     {
386       smx_synchro_t current_comm = NULL;
387       if (call_type == MC_CALL_TYPE_WAIT)
388         current_comm = simcall_comm_wait__get__comm(req);
389       else
390         current_comm = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_synchro_t);
391       // First wait only must be considered:
392       if (current_comm->comm.refcount == 1)
393         complete_comm_pattern(pattern, current_comm);
394       break;
395     }
396   default:
397     xbt_die("Unexpected call type %i", (int)call_type);
398   }
399 }
400
401 /**
402  * \brief Re-executes from the state at position start all the transitions indicated by
403  *        a given model-checker stack.
404  * \param stack The stack with the transitions to execute.
405  * \param start Start index to begin the re-execution.
406  */
407 void MC_replay(xbt_fifo_t stack, int start)
408 {
409   int raw_mem = (mmalloc_get_current_heap() == mc_heap);
410
411   int value, i = 1, count = 1, j;
412   char *req_str;
413   smx_simcall_t req = NULL, saved_req = NULL;
414   xbt_fifo_item_t item, start_item;
415   mc_state_t state;
416   smx_process_t process = NULL;
417
418   XBT_DEBUG("**** Begin Replay ****");
419
420   if (start == -1) {
421     /* Restore the initial state */
422     MC_restore_snapshot(initial_global_state->snapshot);
423     /* At the moment of taking the snapshot the raw heap was set, so restoring
424      * it will set it back again, we have to unset it to continue  */
425     MC_SET_STD_HEAP;
426   }
427
428   start_item = xbt_fifo_get_last_item(stack);
429   if (start != -1) {
430     while (i != start) {
431       start_item = xbt_fifo_get_prev_item(start_item);
432       i++;
433     }
434   }
435
436   MC_SET_MC_HEAP;
437
438   if (mc_reduce_kind == e_mc_reduce_dpor) {
439     xbt_dict_reset(first_enabled_state);
440     xbt_swag_foreach(process, simix_global->process_list) {
441       if (MC_process_is_enabled(process)) {
442         char *key = bprintf("%lu", process->pid);
443         char *data = bprintf("%d", count);
444         xbt_dict_set(first_enabled_state, key, data, NULL);
445         xbt_free(key);
446       }
447     }
448   }
449
450   if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
451     for (j=0; j<simix_process_maxpid; j++) {
452       xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(communications_pattern, j, xbt_dynar_t));
453     }
454     for (j=0; j<simix_process_maxpid; j++) {
455       xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t));
456     }
457   }
458
459   MC_SET_STD_HEAP;
460
461
462   /* Traverse the stack from the state at position start and re-execute the transitions */
463   for (item = start_item;
464        item != xbt_fifo_get_first_item(stack);
465        item = xbt_fifo_get_prev_item(item)) {
466
467     state = (mc_state_t) xbt_fifo_get_item_content(item);
468     saved_req = MC_state_get_executed_request(state, &value);
469
470     if (mc_reduce_kind == e_mc_reduce_dpor) {
471       MC_SET_MC_HEAP;
472       char *key = bprintf("%lu", saved_req->issuer->pid);
473       if(xbt_dict_get_or_null(first_enabled_state, key))
474          xbt_dict_remove(first_enabled_state, key);
475       xbt_free(key);
476       MC_SET_STD_HEAP;
477     }
478
479     if (saved_req) {
480       /* because we got a copy of the executed request, we have to fetch the  
481          real one, pointed by the request field of the issuer process */
482       req = &saved_req->issuer->simcall;
483
484       /* Debug information */
485       if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
486         req_str = MC_request_to_string(req, value);
487         XBT_DEBUG("Replay: %s (%p)", req_str, state);
488         xbt_free(req_str);
489       }
490
491       /* TODO : handle test and testany simcalls */
492       mc_call_type call = MC_CALL_TYPE_NONE;
493       if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
494         call = mc_get_call_type(req);
495       }
496
497       SIMIX_simcall_handle(req, value);
498
499       if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
500         MC_SET_MC_HEAP;
501         mc_update_comm_pattern(call, req, value, communications_pattern);
502         MC_SET_STD_HEAP;
503       }
504
505       MC_wait_for_requests();
506
507       count++;
508
509       if (mc_reduce_kind == e_mc_reduce_dpor) {
510         MC_SET_MC_HEAP;
511         /* Insert in dict all enabled processes */
512         xbt_swag_foreach(process, simix_global->process_list) {
513           if (MC_process_is_enabled(process) ) {
514             char *key = bprintf("%lu", process->pid);
515             if (xbt_dict_get_or_null(first_enabled_state, key) == NULL) {
516               char *data = bprintf("%d", count);
517               xbt_dict_set(first_enabled_state, key, data, NULL);
518             }
519             xbt_free(key);
520           }
521         }
522         MC_SET_STD_HEAP;
523       }
524     }
525
526     /* Update statistics */
527     mc_stats->visited_states++;
528     mc_stats->executed_transitions++;
529
530   }
531
532   XBT_DEBUG("**** End Replay ****");
533
534   if (raw_mem)
535     MC_SET_MC_HEAP;
536   else
537     MC_SET_STD_HEAP;
538
539
540 }
541
542 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
543 {
544
545   initial_global_state->raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
546
547   xbt_fifo_item_t item;
548   int depth = 1;
549
550   XBT_DEBUG("**** Begin Replay ****");
551
552   /* Restore the initial state */
553   MC_restore_snapshot(initial_global_state->snapshot);
554
555   /* At the moment of taking the snapshot the raw heap was set, so restoring
556    * it will set it back again, we have to unset it to continue  */
557   if (!initial_global_state->raw_mem_set)
558     MC_SET_STD_HEAP;
559
560     /* Traverse the stack from the initial state and re-execute the transitions */
561     for (item = xbt_fifo_get_last_item(stack);
562          all_stack ? depth <= xbt_fifo_size(stack) : item != xbt_fifo_get_first_item(stack);
563          item = xbt_fifo_get_prev_item(item)) {
564
565       mc_pair_t pair = (mc_pair_t) xbt_fifo_get_item_content(item);
566
567       mc_state_t state = (mc_state_t) pair->graph_state;
568       smx_simcall_t req = NULL, saved_req = NULL;
569       int value;
570       char *req_str;
571
572       if (pair->requests > 0) {
573
574         saved_req = MC_state_get_executed_request(state, &value);
575         //XBT_DEBUG("SavedReq->call %u", saved_req->call);
576
577         if (saved_req != NULL) {
578           /* because we got a copy of the executed request, we have to fetch the
579              real one, pointed by the request field of the issuer process */
580           req = &saved_req->issuer->simcall;
581           //XBT_DEBUG("Req->call %u", req->call);
582
583           /* Debug information */
584           if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
585             req_str = MC_request_to_string(req, value);
586             XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
587             xbt_free(req_str);
588           }
589
590         }
591
592         SIMIX_simcall_handle(req, value);
593         MC_wait_for_requests();
594       }
595
596       /* Update statistics */
597       mc_stats->visited_pairs++;
598       mc_stats->executed_transitions++;
599
600       depth++;
601
602     }
603
604   XBT_DEBUG("**** End Replay ****");
605
606   if (initial_global_state->raw_mem_set)
607     MC_SET_MC_HEAP;
608   else
609     MC_SET_STD_HEAP;
610
611 }
612
613 /**
614  * \brief Dumps the contents of a model-checker's stack and shows the actual
615  *        execution trace
616  * \param stack The stack to dump
617  */
618 void MC_dump_stack_safety(xbt_fifo_t stack)
619 {
620
621   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
622
623   MC_show_stack_safety(stack);
624
625   if (!_sg_mc_checkpoint) {
626
627     mc_state_t state;
628
629     MC_SET_MC_HEAP;
630     while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
631       MC_state_delete(state);
632     MC_SET_STD_HEAP;
633
634   }
635
636   if (raw_mem_set)
637     MC_SET_MC_HEAP;
638   else
639     MC_SET_STD_HEAP;
640
641 }
642
643
644 void MC_show_stack_safety(xbt_fifo_t stack)
645 {
646
647   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
648
649   MC_SET_MC_HEAP;
650
651   int value;
652   mc_state_t state;
653   xbt_fifo_item_t item;
654   smx_simcall_t req;
655   char *req_str = NULL;
656
657   for (item = xbt_fifo_get_last_item(stack);
658        (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
659         : (NULL)); item = xbt_fifo_get_prev_item(item)) {
660     req = MC_state_get_executed_request(state, &value);
661     if (req) {
662       req_str = MC_request_to_string(req, value);
663       XBT_INFO("%s", req_str);
664       xbt_free(req_str);
665     }
666   }
667
668   if (!raw_mem_set)
669     MC_SET_STD_HEAP;
670 }
671
672 void MC_show_deadlock(smx_simcall_t req)
673 {
674   /*char *req_str = NULL; */
675   XBT_INFO("**************************");
676   XBT_INFO("*** DEAD-LOCK DETECTED ***");
677   XBT_INFO("**************************");
678   XBT_INFO("Locked request:");
679   /*req_str = MC_request_to_string(req);
680      XBT_INFO("%s", req_str);
681      xbt_free(req_str); */
682   XBT_INFO("Counter-example execution trace:");
683   MC_dump_stack_safety(mc_stack);
684   MC_print_statistics(mc_stats);
685 }
686
687
688 void MC_show_stack_liveness(xbt_fifo_t stack)
689 {
690   int value;
691   mc_pair_t pair;
692   xbt_fifo_item_t item;
693   smx_simcall_t req;
694   char *req_str = NULL;
695
696   for (item = xbt_fifo_get_last_item(stack);
697        (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
698         : (NULL)); item = xbt_fifo_get_prev_item(item)) {
699     req = MC_state_get_executed_request(pair->graph_state, &value);
700     if (req) {
701       if (pair->requests > 0) {
702         req_str = MC_request_to_string(req, value);
703         XBT_INFO("%s", req_str);
704         xbt_free(req_str);
705       } else {
706         XBT_INFO("End of system requests but evolution in Büchi automaton");
707       }
708     }
709   }
710 }
711
712 void MC_dump_stack_liveness(xbt_fifo_t stack)
713 {
714
715   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
716
717   mc_pair_t pair;
718
719   MC_SET_MC_HEAP;
720   while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
721     MC_pair_delete(pair);
722   MC_SET_STD_HEAP;
723
724   if (raw_mem_set)
725     MC_SET_MC_HEAP;
726
727 }
728
729
730 void MC_print_statistics(mc_stats_t stats)
731 {
732   xbt_mheap_t previous_heap = mmalloc_get_current_heap();
733
734   if (stats->expanded_pairs == 0) {
735     XBT_INFO("Expanded states = %lu", stats->expanded_states);
736     XBT_INFO("Visited states = %lu", stats->visited_states);
737   } else {
738     XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
739     XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
740   }
741   XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
742   MC_SET_MC_HEAP;
743   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0')) {
744     fprintf(dot_output, "}\n");
745     fclose(dot_output);
746   }
747   if (initial_global_state != NULL) {
748     if (_sg_mc_comms_determinism)
749       XBT_INFO("Communication-deterministic : %s",
750                !initial_global_state->comm_deterministic ? "No" : "Yes");
751     if (_sg_mc_send_determinism)
752       XBT_INFO("Send-deterministic : %s",
753                !initial_global_state->send_deterministic ? "No" : "Yes");
754   }
755   mmalloc_set_current_heap(previous_heap);
756 }
757
758 void MC_assert(int prop)
759 {
760   if (MC_is_active() && !prop) {
761     XBT_INFO("**************************");
762     XBT_INFO("*** PROPERTY NOT VALID ***");
763     XBT_INFO("**************************");
764     XBT_INFO("Counter-example execution trace:");
765     MC_dump_stack_safety(mc_stack);
766     MC_print_statistics(mc_stats);
767     xbt_abort();
768   }
769 }
770
771 void MC_cut(void)
772 {
773   user_max_depth_reached = 1;
774 }
775
776 void MC_process_clock_add(smx_process_t process, double amount)
777 {
778   mc_time[process->pid] += amount;
779 }
780
781 double MC_process_clock_get(smx_process_t process)
782 {
783   if (mc_time) {
784     if (process != NULL)
785       return mc_time[process->pid];
786     else
787       return -1;
788   } else {
789     return 0;
790   }
791 }
792
793 void MC_automaton_load(const char *file)
794 {
795
796   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
797
798   MC_SET_MC_HEAP;
799
800   if (_mc_property_automaton == NULL)
801     _mc_property_automaton = xbt_automaton_new();
802
803   xbt_automaton_load(_mc_property_automaton, file);
804
805   MC_SET_STD_HEAP;
806
807   if (raw_mem_set)
808     MC_SET_MC_HEAP;
809
810 }
811
812 void MC_automaton_new_propositional_symbol(const char *id, void *fct)
813 {
814
815   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
816
817   MC_SET_MC_HEAP;
818
819   if (_mc_property_automaton == NULL)
820     _mc_property_automaton = xbt_automaton_new();
821
822   xbt_automaton_propositional_symbol_new(_mc_property_automaton, id, fct);
823
824   MC_SET_STD_HEAP;
825
826   if (raw_mem_set)
827     MC_SET_MC_HEAP;
828
829 }
830
831 void MC_dump_stacks(FILE* file)
832 {
833   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
834   MC_SET_MC_HEAP;
835
836   int nstack = 0;
837   stack_region_t current_stack;
838   unsigned cursor;
839   xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
840     unw_context_t * context = (unw_context_t *)current_stack->context;
841     fprintf(file, "Stack %i:\n", nstack);
842
843     int nframe = 0;
844     char buffer[100];
845     unw_cursor_t c;
846     unw_init_local (&c, context);
847     unw_word_t off;
848     do {
849       const char * name = !unw_get_proc_name(&c, buffer, 100, &off) ? buffer : "?";
850       fprintf(file, "  %i: %s\n", nframe, name);
851       ++nframe;
852     } while(unw_step(&c));
853
854     ++nstack;
855   }
856
857   if (raw_mem_set)
858     MC_SET_MC_HEAP;
859 }