Logo AND Algorithmique Numérique Distribuée

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