Logo AND Algorithmique Numérique Distribuée

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