Logo AND Algorithmique Numérique Distribuée

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