Logo AND Algorithmique Numérique Distribuée

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