Logo AND Algorithmique Numérique Distribuée

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