Logo AND Algorithmique Numérique Distribuée

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