Logo AND Algorithmique Numérique Distribuée

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