Logo AND Algorithmique Numérique Distribuée

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