Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Basic infrastructure for a real model-checker process
[simgrid.git] / src / mc / mc_private.h
1 /* Copyright (c) 2007-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 #ifndef MC_PRIVATE_H
8 #define MC_PRIVATE_H
9
10 #include <sys/types.h>
11
12 #include "simgrid_config.h"
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <stdbool.h>
16 #ifndef WIN32
17 #include <sys/mman.h>
18 #endif
19 #include <elfutils/libdw.h>
20
21 #include "mc/mc.h"
22 #include "mc_base.h"
23 #include "mc/datatypes.h"
24 #include "xbt/fifo.h"
25 #include "xbt/config.h"
26
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"
32 #include "xbt/hash.h"
33 #include "msg/msg.h"
34 #include "msg/datatypes.h"
35 #include "xbt/strbuff.h"
36 #include "xbt/parmap.h"
37
38 #include "mc_forward.h"
39
40 SG_BEGIN_DECL()
41
42 typedef struct s_mc_function_index_item s_mc_function_index_item_t, *mc_function_index_item_t;
43
44 /****************************** Snapshots ***********************************/
45
46 extern xbt_dynar_t mc_checkpoint_ignore;
47
48 /********************************* MC Global **********************************/
49
50 /** Initialisation of the model-checker
51  *
52  * @param pid     PID of the target process
53  * @param socket  FD for the communication socket **in server mode** (or -1 otherwise)
54  */
55 void MC_init_pid(pid_t pid, int socket);
56
57 extern FILE *dot_output;
58 extern const char* colors[13];
59 extern xbt_parmap_t parmap;
60
61 extern int user_max_depth_reached;
62
63 int MC_deadlock_check(void);
64 void MC_replay(xbt_fifo_t stack, int start);
65 void MC_replay_liveness(xbt_fifo_t stack, int all_stack);
66 void MC_show_deadlock(smx_simcall_t req);
67 void MC_show_stack_safety(xbt_fifo_t stack);
68 void MC_dump_stack_safety(xbt_fifo_t stack);
69
70 /** Stack (of `mc_state_t`) representing the current position of the
71  *  the MC in the exploration graph
72  *
73  *  It is managed by its head (`xbt_fifo_shift` and `xbt_fifo_unshift`).
74  */
75 extern xbt_fifo_t mc_stack;
76
77 int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max);
78
79
80 /****************************** Statistics ************************************/
81
82 typedef struct mc_stats {
83   unsigned long state_size;
84   unsigned long visited_states;
85   unsigned long visited_pairs;
86   unsigned long expanded_states;
87   unsigned long expanded_pairs;
88   unsigned long executed_transitions;
89 } s_mc_stats_t, *mc_stats_t;
90
91 extern mc_stats_t mc_stats;
92
93 void MC_print_statistics(mc_stats_t stats);
94
95 /********************************** Snapshot comparison **********************************/
96
97 typedef struct s_mc_comparison_times{
98   double nb_processes_comparison_time;
99   double bytes_used_comparison_time;
100   double stacks_sizes_comparison_time;
101   double global_variables_comparison_time;
102   double heap_comparison_time;
103   double stacks_comparison_time;
104 }s_mc_comparison_times_t, *mc_comparison_times_t;
105
106 extern __thread mc_comparison_times_t mc_comp_times;
107 extern __thread double mc_snapshot_comparison_time;
108
109 int snapshot_compare(void *state1, void *state2);
110 void print_comparison_times(void);
111
112 //#define MC_DEBUG 1
113 #define MC_VERBOSE 1
114
115 /********************************** Variables with DWARF **********************************/
116
117 void MC_find_object_address(memory_map_t maps, mc_object_info_t result);
118
119 /********************************** Miscellaneous **********************************/
120
121 typedef struct s_local_variable{
122   dw_frame_t subprogram;
123   unsigned long ip;
124   char *name;
125   dw_type_t type;
126   void *address;
127   int region;
128 }s_local_variable_t, *local_variable_t;
129
130 /* *********** Sets *********** */
131
132 typedef struct s_mc_address_set *mc_address_set_t;
133
134 mc_address_set_t mc_address_set_new(void);
135 void mc_address_set_free(mc_address_set_t* p);
136 void mc_address_add(mc_address_set_t p, const void* value);
137 bool mc_address_test(mc_address_set_t p, const void* value);
138
139 /* *********** Hash *********** */
140
141 /** \brief Hash the current state
142  *  \param num_state number of states
143  *  \param stacks stacks (mc_snapshot_stak_t) used fot the stack unwinding informations
144  *  \result resulting hash
145  * */
146 uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks);
147
148 /* *********** Snapshot *********** */
149
150 #define MC_LOG_REQUEST(log, req, value) \
151   if (XBT_LOG_ISENABLED(log, xbt_log_priority_debug)) { \
152     char* req_str = MC_request_to_string(req, value); \
153     XBT_DEBUG("Execute: %s", req_str); \
154     xbt_free(req_str); \
155   }
156
157 /** @brief Dump the stacks of the application processes
158  *
159  *   This functions is currently not used but it is quite convenient
160  *   to call from the debugger.
161  *
162  *   Does not work when an application thread is running.
163  */
164 void MC_dump_stacks(FILE* file);
165
166 SG_END_DECL()
167
168 #endif