Logo AND Algorithmique Numérique Distribuée

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