Logo AND Algorithmique Numérique Distribuée

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