1 /* Copyright (c) 2007-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
10 #include <sys/types.h>
12 #include "simgrid_config.h"
19 #include <elfutils/libdw.h>
23 #include "mc/datatypes.h"
25 #include "xbt/config.h"
27 #include "xbt/function_types.h"
28 #include "xbt/mmalloc.h"
29 #include "../simix/smx_private.h"
30 #include "../xbt/mmalloc/mmprivate.h"
31 #include "xbt/automaton.h"
34 #include "msg/datatypes.h"
35 #include "xbt/strbuff.h"
36 #include "xbt/parmap.h"
38 #include "mc_forward.h"
42 typedef struct s_mc_function_index_item s_mc_function_index_item_t, *mc_function_index_item_t;
44 /********************************* MC Global **********************************/
46 /** Initialisation of the model-checker
48 * @param pid PID of the target process
49 * @param socket FD for the communication socket **in server mode** (or -1 otherwise)
51 void MC_init_pid(pid_t pid, int socket);
53 extern FILE *dot_output;
54 extern const char* colors[13];
55 extern xbt_parmap_t parmap;
57 extern int user_max_depth_reached;
59 int MC_deadlock_check(void);
60 void MC_replay(xbt_fifo_t stack, int start);
61 void MC_replay_liveness(xbt_fifo_t stack, int all_stack);
62 void MC_show_deadlock(smx_simcall_t req);
63 void MC_show_stack_safety(xbt_fifo_t stack);
64 void MC_dump_stack_safety(xbt_fifo_t stack);
66 /** Stack (of `mc_state_t`) representing the current position of the
67 * the MC in the exploration graph
69 * It is managed by its head (`xbt_fifo_shift` and `xbt_fifo_unshift`).
71 extern xbt_fifo_t mc_stack;
73 int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max);
76 /****************************** Statistics ************************************/
78 typedef struct mc_stats {
79 unsigned long state_size;
80 unsigned long visited_states;
81 unsigned long visited_pairs;
82 unsigned long expanded_states;
83 unsigned long expanded_pairs;
84 unsigned long executed_transitions;
85 } s_mc_stats_t, *mc_stats_t;
87 extern mc_stats_t mc_stats;
89 void MC_print_statistics(mc_stats_t stats);
91 /********************************** Snapshot comparison **********************************/
93 typedef struct s_mc_comparison_times{
94 double nb_processes_comparison_time;
95 double bytes_used_comparison_time;
96 double stacks_sizes_comparison_time;
97 double global_variables_comparison_time;
98 double heap_comparison_time;
99 double stacks_comparison_time;
100 }s_mc_comparison_times_t, *mc_comparison_times_t;
102 extern __thread mc_comparison_times_t mc_comp_times;
103 extern __thread double mc_snapshot_comparison_time;
105 int snapshot_compare(void *state1, void *state2);
106 void print_comparison_times(void);
111 /********************************** Variables with DWARF **********************************/
113 void MC_find_object_address(memory_map_t maps, mc_object_info_t result);
115 /********************************** Miscellaneous **********************************/
117 typedef struct s_local_variable{
118 dw_frame_t subprogram;
124 }s_local_variable_t, *local_variable_t;
126 /* *********** Sets *********** */
128 typedef struct s_mc_address_set *mc_address_set_t;
130 mc_address_set_t mc_address_set_new(void);
131 void mc_address_set_free(mc_address_set_t* p);
132 void mc_address_add(mc_address_set_t p, const void* value);
133 bool mc_address_test(mc_address_set_t p, const void* value);
135 /* *********** Hash *********** */
137 /** \brief Hash the current state
138 * \param num_state number of states
139 * \param stacks stacks (mc_snapshot_stak_t) used fot the stack unwinding informations
140 * \result resulting hash
142 uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks);
144 /* *********** Snapshot *********** */
146 #define MC_LOG_REQUEST(log, req, value) \
147 if (XBT_LOG_ISENABLED(log, xbt_log_priority_debug)) { \
148 char* req_str = MC_request_to_string(req, value); \
149 XBT_DEBUG("Execute: %s", req_str); \
153 /** @brief Dump the stacks of the application processes
155 * This functions is currently not used but it is quite convenient
156 * to call from the debugger.
158 * Does not work when an application thread is running.
160 void MC_dump_stacks(FILE* file);