Logo AND Algorithmique Numérique Distribuée

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