1 /* Copyright (c) 2008-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. */
12 #include "simgrid/sg_config.h"
13 #include "../surf/surf_private.h"
14 #include "../simix/smx_private.h"
15 #include "../xbt/mmalloc/mmprivate.h"
17 #include "mc_private.h"
18 #include "xbt/automaton.h"
21 XBT_LOG_NEW_CATEGORY(mc, "All MC categories");
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
23 "Logging specific to MC (global)");
25 /* Configuration support */
26 e_mc_reduce_t mc_reduce_kind=e_mc_reduce_unset;
28 int _sg_do_model_check = 0;
29 int _sg_mc_checkpoint=0;
30 char* _sg_mc_property_file=NULL;
32 int _sg_mc_max_depth=1000;
34 char *_sg_mc_dot_output_file = NULL;
36 int user_max_depth_reached = 0;
38 void _mc_cfg_cb_reduce(const char *name, int pos) {
39 if (_sg_cfg_init_status && !_sg_do_model_check) {
40 xbt_die("You are specifying a reduction strategy after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
42 char *val= xbt_cfg_get_string(_sg_cfg_set, name);
43 if (!strcasecmp(val,"none")) {
44 mc_reduce_kind = e_mc_reduce_none;
45 } else if (!strcasecmp(val,"dpor")) {
46 mc_reduce_kind = e_mc_reduce_dpor;
48 xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",name);
52 void _mc_cfg_cb_checkpoint(const char *name, int pos) {
53 if (_sg_cfg_init_status && !_sg_do_model_check) {
54 xbt_die("You are specifying a checkpointing value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
56 _sg_mc_checkpoint = xbt_cfg_get_int(_sg_cfg_set, name);
58 void _mc_cfg_cb_property(const char *name, int pos) {
59 if (_sg_cfg_init_status && !_sg_do_model_check) {
60 xbt_die("You are specifying a property after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
62 _sg_mc_property_file= xbt_cfg_get_string(_sg_cfg_set, name);
65 void _mc_cfg_cb_timeout(const char *name, int pos) {
66 if (_sg_cfg_init_status && !_sg_do_model_check) {
67 xbt_die("You are specifying a value to enable/disable timeout for wait requests after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
69 _sg_mc_timeout= xbt_cfg_get_boolean(_sg_cfg_set, name);
72 void _mc_cfg_cb_max_depth(const char *name, int pos) {
73 if (_sg_cfg_init_status && !_sg_do_model_check) {
74 xbt_die("You are specifying a max depth value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
76 _sg_mc_max_depth= xbt_cfg_get_int(_sg_cfg_set, name);
79 void _mc_cfg_cb_visited(const char *name, int pos) {
80 if (_sg_cfg_init_status && !_sg_do_model_check) {
81 xbt_die("You are specifying a number of stored visited states after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
83 _sg_mc_visited= xbt_cfg_get_int(_sg_cfg_set, name);
86 void _mc_cfg_cb_dot_output(const char *name, int pos) {
87 if (_sg_cfg_init_status && !_sg_do_model_check) {
88 xbt_die("You are specifying a file name for a dot output of graph state after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
90 _sg_mc_dot_output_file= xbt_cfg_get_string(_sg_cfg_set, name);
93 /* MC global data structures */
94 mc_state_t mc_current_state = NULL;
95 char mc_replay_mode = FALSE;
96 double *mc_time = NULL;
97 __thread mc_comparison_times_t mc_comp_times = NULL;
98 __thread double mc_snapshot_comparison_time;
99 mc_stats_t mc_stats = NULL;
102 xbt_fifo_t mc_stack_safety = NULL;
103 mc_global_t initial_state_safety = NULL;
106 xbt_fifo_t mc_stack_liveness = NULL;
107 mc_global_t initial_state_liveness = NULL;
110 xbt_automaton_t _mc_property_automaton = NULL;
113 xbt_dict_t mc_local_variables_libsimgrid = NULL;
114 xbt_dict_t mc_local_variables_binary = NULL;
115 xbt_dynar_t mc_global_variables_libsimgrid = NULL;
116 xbt_dynar_t mc_global_variables_binary = NULL;
117 xbt_dict_t mc_variables_type_libsimgrid = NULL;
118 xbt_dict_t mc_variables_type_binary = NULL;
120 /* Ignore mechanism */
121 xbt_dynar_t mc_stack_comparison_ignore;
122 xbt_dynar_t mc_data_bss_comparison_ignore;
123 extern xbt_dynar_t mc_heap_comparison_ignore;
124 extern xbt_dynar_t stacks_areas;
127 FILE *dot_output = NULL;
128 const char* colors[13];
131 /******************************* DWARF Information *******************************/
132 /**********************************************************************************/
134 /************************** Free functions *************************/
136 static void dw_location_free(dw_location_t l){
138 if(l->type == e_dw_loclist)
139 xbt_dynar_free(&(l->location.loclist));
140 else if(l->type == e_dw_compose)
141 xbt_dynar_free(&(l->location.compose));
142 else if(l->type == e_dw_arithmetic)
143 xbt_free(l->location.arithmetic);
149 static void dw_location_entry_free(dw_location_entry_t e){
150 dw_location_free(e->location);
154 static void dw_type_free(dw_type_t t){
156 xbt_free(t->dw_type_id);
157 xbt_dynar_free(&(t->members));
161 static void dw_type_free_voidp(void *t){
162 dw_type_free((dw_type_t) * (void **) t);
165 static void dw_variable_free(dw_variable_t v){
168 xbt_free(v->type_origin);
170 dw_location_free(v->address.location);
175 static void dw_variable_free_voidp(void *t){
176 dw_variable_free((dw_variable_t) * (void **) t);
179 /*************************************************************************/
181 static dw_location_t MC_dwarf_get_location(xbt_dict_t location_list, char *expr){
183 dw_location_t loc = xbt_new0(s_dw_location_t, 1);
185 if(location_list != NULL){
187 char *key = bprintf("%lu", strtoul(expr, NULL, 16));
188 loc->type = e_dw_loclist;
189 loc->location.loclist = (xbt_dynar_t)xbt_dict_get_or_null(location_list, key);
190 if(loc->location.loclist == NULL)
191 XBT_INFO("Key not found in loclist");
198 char *tok = NULL, *tok2 = NULL;
200 xbt_dynar_t tokens1 = xbt_str_split(expr, ";");
203 loc->type = e_dw_compose;
204 loc->location.compose = xbt_dynar_new(sizeof(dw_location_t), NULL);
206 while(cursor < xbt_dynar_length(tokens1)){
208 tok = xbt_dynar_get_as(tokens1, cursor, char*);
209 tokens2 = xbt_str_split(tok, " ");
210 tok2 = xbt_dynar_get_as(tokens2, 0, char*);
212 if(strncmp(tok2, "DW_OP_reg", 9) == 0){
213 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
214 new_element->type = e_dw_register;
215 new_element->location.reg = atoi(strtok(tok2, "DW_OP_reg"));
216 xbt_dynar_push(loc->location.compose, &new_element);
217 }else if(strcmp(tok2, "DW_OP_fbreg:") == 0){
218 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
219 new_element->type = e_dw_fbregister_op;
220 new_element->location.fbreg_op = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
221 xbt_dynar_push(loc->location.compose, &new_element);
222 }else if(strncmp(tok2, "DW_OP_breg", 10) == 0){
223 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
224 new_element->type = e_dw_bregister_op;
225 new_element->location.breg_op.reg = atoi(strtok(tok2, "DW_OP_breg"));
226 new_element->location.breg_op.offset = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
227 xbt_dynar_push(loc->location.compose, &new_element);
228 }else if(strncmp(tok2, "DW_OP_lit", 9) == 0){
229 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
230 new_element->type = e_dw_lit;
231 new_element->location.lit = atoi(strtok(tok2, "DW_OP_lit"));
232 xbt_dynar_push(loc->location.compose, &new_element);
233 }else if(strcmp(tok2, "DW_OP_piece:") == 0){
234 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
235 new_element->type = e_dw_piece;
236 new_element->location.piece = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
237 xbt_dynar_push(loc->location.compose, &new_element);
238 }else if(strcmp(tok2, "DW_OP_plus_uconst:") == 0){
239 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
240 new_element->type = e_dw_plus_uconst;
241 new_element->location.plus_uconst = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char *));
242 xbt_dynar_push(loc->location.compose, &new_element);
243 }else if(strcmp(tok, "DW_OP_abs") == 0 ||
244 strcmp(tok, "DW_OP_and") == 0 ||
245 strcmp(tok, "DW_OP_div") == 0 ||
246 strcmp(tok, "DW_OP_minus") == 0 ||
247 strcmp(tok, "DW_OP_mod") == 0 ||
248 strcmp(tok, "DW_OP_mul") == 0 ||
249 strcmp(tok, "DW_OP_neg") == 0 ||
250 strcmp(tok, "DW_OP_not") == 0 ||
251 strcmp(tok, "DW_OP_or") == 0 ||
252 strcmp(tok, "DW_OP_plus") == 0){
253 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
254 new_element->type = e_dw_arithmetic;
255 new_element->location.arithmetic = strdup(strtok(tok2, "DW_OP_"));
256 xbt_dynar_push(loc->location.compose, &new_element);
257 }else if(strcmp(tok, "DW_OP_stack_value") == 0){
258 }else if(strcmp(tok2, "DW_OP_deref_size:") == 0){
259 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
260 new_element->type = e_dw_deref;
261 new_element->location.deref_size = (unsigned int short) atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
262 xbt_dynar_push(loc->location.compose, &new_element);
263 }else if(strcmp(tok, "DW_OP_deref") == 0){
264 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
265 new_element->type = e_dw_deref;
266 new_element->location.deref_size = sizeof(void *);
267 xbt_dynar_push(loc->location.compose, &new_element);
268 }else if(strcmp(tok2, "DW_OP_constu:") == 0){
269 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
270 new_element->type = e_dw_uconstant;
271 new_element->location.uconstant.bytes = 1;
272 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
273 xbt_dynar_push(loc->location.compose, &new_element);
274 }else if(strcmp(tok2, "DW_OP_consts:") == 0){
275 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
276 new_element->type = e_dw_sconstant;
277 new_element->location.sconstant.bytes = 1;
278 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
279 xbt_dynar_push(loc->location.compose, &new_element);
280 }else if(strcmp(tok2, "DW_OP_const1u:") == 0 ||
281 strcmp(tok2, "DW_OP_const2u:") == 0 ||
282 strcmp(tok2, "DW_OP_const4u:") == 0 ||
283 strcmp(tok2, "DW_OP_const8u:") == 0){
284 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
285 new_element->type = e_dw_uconstant;
286 new_element->location.uconstant.bytes = tok2[11] - '0';
287 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
288 xbt_dynar_push(loc->location.compose, &new_element);
289 }else if(strcmp(tok, "DW_OP_const1s") == 0 ||
290 strcmp(tok, "DW_OP_const2s") == 0 ||
291 strcmp(tok, "DW_OP_const4s") == 0 ||
292 strcmp(tok, "DW_OP_const8s") == 0){
293 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
294 new_element->type = e_dw_sconstant;
295 new_element->location.sconstant.bytes = tok2[11] - '0';
296 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
297 xbt_dynar_push(loc->location.compose, &new_element);
299 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
300 new_element->type = e_dw_unsupported;
301 xbt_dynar_push(loc->location.compose, &new_element);
305 xbt_dynar_free(&tokens2);
309 xbt_dynar_free(&tokens1);
317 static xbt_dict_t MC_dwarf_get_location_list(const char *elf_file){
319 char *command = bprintf("objdump -Wo %s", elf_file);
321 FILE *fp = popen(command, "r");
324 perror("popen for objdump failed");
328 int debug = 0; /*Detect if the program has been compiled with -g */
330 xbt_dict_t location_list = xbt_dict_new_homogeneous(NULL);
331 char *line = NULL, *loc_expr = NULL;
335 xbt_dynar_t split = NULL;
337 while ((read = xbt_getline(&line, &n, fp)) != -1) {
339 /* Wipeout the new line character */
340 line[read - 1] = '\0';
342 xbt_str_trim(line, NULL);
347 if(strlen(line) == 0)
352 if(strncmp(line, elf_file, strlen(elf_file)) == 0)
355 if(strncmp(line, "Contents", 8) == 0)
358 if(strncmp(line, "Offset", 6) == 0){
365 XBT_INFO("Your program must be compiled with -g");
369 xbt_dynar_t loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
371 xbt_str_strip_spaces(line);
372 split = xbt_str_split(line, " ");
374 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
376 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
377 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
378 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
381 while(cursor_remove < 3){
382 xbt_dynar_remove_at(split, 0, NULL);
386 loc_expr = xbt_str_join(split, " ");
387 xbt_str_ltrim(loc_expr, "(");
388 xbt_str_rtrim(loc_expr, ")");
389 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
391 xbt_dynar_push(loclist, &new_entry);
393 xbt_dynar_free(&split);
396 read = xbt_getline(&line, &n, fp);
398 line[read - 1] = '\0';
399 xbt_str_strip_spaces(line);
400 split = xbt_str_split(line, " ");
406 char *key = bprintf("%lu", strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
407 xbt_dict_set(location_list, key, loclist, NULL);
410 xbt_dynar_free(&split);
418 return location_list;
421 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
423 xbt_dict_cursor_t cursor = NULL;
427 xbt_dict_foreach(all_variables, cursor, name, res) {
428 if(offset >= res->start && offset < res->end){
429 xbt_dict_cursor_free(&cursor);
434 xbt_dict_cursor_free(&cursor);
439 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
441 unsigned int cursor = 0;
442 dw_variable_t current_var;
444 xbt_dynar_foreach(frame->variables, cursor, current_var){
445 if(strcmp(var, current_var->name) == 0)
452 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
454 if(xbt_dynar_is_empty(variables))
457 unsigned int cursor = 0;
459 int end = xbt_dynar_length(variables) - 1;
460 dw_variable_t var_test = NULL;
463 cursor = (start + end) / 2;
464 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
465 if(strcmp(var_test->name, var) < 0){
467 }else if(strcmp(var_test->name, var) > 0){
470 if(address){ /* global variable */
471 if(var_test->address.address == address)
473 if(var_test->address.address > address)
477 }else{ /* local variable */
483 if(strcmp(var_test->name, var) == 0){
484 if(address && var_test->address.address < address)
488 }else if(strcmp(var_test->name, var) < 0)
496 static void MC_dwarf_get_variables(const char *elf_file, xbt_dict_t location_list, xbt_dict_t *local_variables, xbt_dynar_t *global_variables, xbt_dict_t *types){
498 char *command = bprintf("objdump -Wi %s", elf_file);
500 FILE *fp = popen(command, "r");
503 perror("popen for objdump failed");
505 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
506 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
507 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
508 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
509 *parent_value = NULL;
513 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
514 is_pointer = 0, struct_decl = 0, member_end = 0,
515 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
517 xbt_dynar_t split = NULL, split2 = NULL;
519 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
520 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
522 dw_frame_t variable_frame, subroutine_frame = NULL;
524 e_dw_type_type type_type = -1;
526 read = xbt_getline(&line, &n, fp);
530 /* Wipeout the new line character */
531 line[read - 1] = '\0';
533 if(n == 0 || strlen(line) == 0){
534 read = xbt_getline(&line, &n, fp);
538 xbt_str_ltrim(line, NULL);
539 xbt_str_strip_spaces(line);
542 read = xbt_getline(&line, &n, fp);
546 xbt_dynar_free(&split);
547 split = xbt_str_split(line, " ");
550 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
552 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
554 dw_frame_t frame = NULL;
556 strtok(xbt_dynar_get_as(split, 0, char *), "<");
557 subprogram_start = xbt_strdup(strtok(NULL, "<"));
558 xbt_str_rtrim(subprogram_start, ">:");
560 read = xbt_getline(&line, &n, fp);
564 /* Wipeout the new line character */
565 line[read - 1] = '\0';
567 if(n == 0 || strlen(line) == 0){
568 read = xbt_getline(&line, &n, fp);
572 xbt_dynar_free(&split);
573 xbt_str_rtrim(line, NULL);
574 xbt_str_strip_spaces(line);
575 split = xbt_str_split(line, " ");
577 node_type = xbt_dynar_get_as(split, 1, char *);
579 if(strncmp(node_type, "DW_AT_", 6) != 0)
582 if(strcmp(node_type, "DW_AT_sibling") == 0){
584 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
585 xbt_str_ltrim(subprogram_end, "<0x");
586 xbt_str_rtrim(subprogram_end, ">");
588 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
591 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
592 xbt_str_ltrim(abstract_origin, "<0x");
593 xbt_str_rtrim(abstract_origin, ">");
594 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
595 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
596 xbt_free(abstract_origin);
598 }else if(strcmp(node_type, "DW_AT_name") == 0){
601 xbt_free(current_frame);
602 frame = xbt_new0(s_dw_frame_t, 1);
603 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
604 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
605 frame->frame_base = xbt_new0(s_dw_location_t, 1);
606 current_frame = strdup(frame->name);
608 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
610 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
612 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
614 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
616 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
620 xbt_str_strip_spaces(line);
621 split2 = xbt_str_split(line, "(");
622 xbt_dynar_remove_at(split2, 0, NULL);
623 loc_expr = xbt_str_join(split2, " ");
624 xbt_str_rtrim(loc_expr, ")");
625 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
626 xbt_dynar_free(&split2);
631 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
634 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
636 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
639 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
641 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
643 xbt_free(frame->name);
644 xbt_free(current_frame);
645 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
646 current_frame = strdup(frame->name);
647 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
651 read = xbt_getline(&line, &n, fp);
656 frame->start = strtoul(subprogram_start, NULL, 16);
657 if(subprogram_end != NULL)
658 frame->end = strtoul(subprogram_end, NULL, 16);
659 xbt_dict_set(*local_variables, frame->name, frame, NULL);
662 xbt_free(subprogram_start);
663 xbt_free(subprogram_end);
664 subprogram_end = NULL;
667 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
669 dw_variable_t var = NULL;
671 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
672 parent_value = strtok(parent_value,"<");
673 xbt_str_rtrim(parent_value, ">");
674 parent = atoi(parent_value);
675 xbt_free(parent_value);
680 strtok(xbt_dynar_get_as(split, 0, char *), "<");
681 origin = xbt_strdup(strtok(NULL, "<"));
682 xbt_str_rtrim(origin, ">:");
684 read = xbt_getline(&line, &n, fp);
688 /* Wipeout the new line character */
689 line[read - 1] = '\0';
691 if(n == 0 || strlen(line) == 0){
692 read = xbt_getline(&line, &n, fp);
696 xbt_dynar_free(&split);
697 xbt_str_rtrim(line, NULL);
698 xbt_str_strip_spaces(line);
699 split = xbt_str_split(line, " ");
701 node_type = xbt_dynar_get_as(split, 1, char *);
703 if(strncmp(node_type, "DW_AT_", 6) != 0)
706 if(strcmp(node_type, "DW_AT_name") == 0){
708 var = xbt_new0(s_dw_variable_t, 1);
709 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
710 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
712 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
716 abstract_origin = xbt_dynar_get_as(split, 2, char *);
717 xbt_str_ltrim(abstract_origin, "<0x");
718 xbt_str_rtrim(abstract_origin, ">");
720 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
721 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
722 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
724 }else if(strcmp(node_type, "DW_AT_location") == 0){
728 if(!global_variable){
730 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
732 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
733 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
735 xbt_str_strip_spaces(line);
736 split2 = xbt_str_split(line, "(");
737 xbt_dynar_remove_at(split2, 0, NULL);
738 loc_expr = xbt_str_join(split2, " ");
739 xbt_str_rtrim(loc_expr, ")");
740 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
742 xbt_dynar_free(&split2);
743 split2 = xbt_str_split(loc_expr, " ");
744 if(strcmp(elf_file, xbt_binary_name) != 0)
745 var->address.address = (char *)start_text_libsimgrid + strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
747 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
749 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
751 xbt_dynar_free(&split2);
755 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
756 xbt_str_rtrim(global_address, ")");
757 if(strcmp(elf_file, xbt_binary_name) != 0)
758 var->address.address = (char *)start_text_libsimgrid + strtoul(global_address, NULL, 16);
760 var->address.address = (void *)strtoul(global_address, NULL, 16);
761 xbt_free(global_address);
762 global_address = NULL;
767 }else if(strcmp(node_type, "DW_AT_type") == 0){
769 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
770 xbt_str_ltrim(type_origin, "<0x");
771 xbt_str_rtrim(type_origin, ">");
773 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
777 dw_variable_free(var);
781 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
785 dw_variable_free(var);
791 read = xbt_getline(&line, &n, fp);
795 if(new_variable == 1){
797 if(!global_variable){
798 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
799 var->type_origin = strdup(type_origin);
801 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
803 xbt_dynar_insert_at(variable_frame->variables, index, &var);
805 var->type_origin = strdup(type_origin);
807 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
809 xbt_dynar_insert_at(*global_variables, index, &var);
812 xbt_free(type_origin);
819 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
821 read = xbt_getline(&line, &n, fp);
825 /* Wipeout the new line character */
826 line[read - 1] = '\0';
828 if(n == 0 || strlen(line) == 0){
829 read = xbt_getline(&line, &n, fp);
833 xbt_dynar_free(&split);
834 xbt_str_rtrim(line, NULL);
835 xbt_str_strip_spaces(line);
836 split = xbt_str_split(line, " ");
838 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
841 node_type = xbt_dynar_get_as(split, 1, char *);
843 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
845 origin = xbt_dynar_get_as(split, 2, char *);
846 xbt_str_ltrim(origin, "<0x");
847 xbt_str_rtrim(origin, ">");
849 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
850 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
852 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
854 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
856 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
858 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
861 read = xbt_getline(&line, &n, fp);
865 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
866 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
867 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
868 || strcmp(node_type, "(DW_TAG_typedef)") == 0
869 || strcmp(node_type, "(DW_TAG_const_type)") == 0
870 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
871 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
872 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
874 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
875 type_type = e_dw_base_type;
876 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
877 type_type = e_dw_enumeration_type;
878 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
879 type_type = e_dw_enumerator;
880 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
881 type_type = e_dw_typedef;
882 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
883 type_type = e_dw_const_type;
884 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
885 type_type = e_dw_pointer_type;
886 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
887 type_type = e_dw_subroutine_type;
888 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
889 type_type = e_dw_volatile_type;
891 strtok(xbt_dynar_get_as(split, 0, char *), "<");
892 origin = strdup(strtok(NULL, "<"));
893 xbt_str_rtrim(origin, ">:");
895 read = xbt_getline(&line, &n, fp);
899 /* Wipeout the new line character */
900 line[read - 1] = '\0';
902 if(n == 0 || strlen(line) == 0){
903 read = xbt_getline(&line, &n, fp);
907 xbt_dynar_free(&split);
908 xbt_str_rtrim(line, NULL);
909 xbt_str_strip_spaces(line);
910 split = xbt_str_split(line, " ");
912 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
915 node_type = xbt_dynar_get_as(split, 1, char *);
917 if(strcmp(node_type, "DW_AT_byte_size") == 0){
918 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
919 if(type_type == e_dw_enumeration_type)
920 enumeration_size = size;
921 }else if(strcmp(node_type, "DW_AT_name") == 0){
922 end = xbt_str_join(split, " ");
923 xbt_dynar_free(&split);
924 split = xbt_str_split(end, "):");
925 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
926 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
927 }else if(strcmp(node_type, "DW_AT_type") == 0){
928 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
929 xbt_str_ltrim(type_origin, "<0x");
930 xbt_str_rtrim(type_origin, ">");
933 read = xbt_getline(&line, &n, fp);
936 dw_type_t type = xbt_new0(s_dw_type_t, 1);
937 type->type = type_type;
939 type->name = xbt_strdup(name);
941 type->name = xbt_strdup("undefined");
942 type->is_pointer_type = is_pointer;
943 type->id = (void *)strtoul(origin, NULL, 16);
945 type->dw_type_id = xbt_strdup(type_origin);
946 if(type_type == e_dw_enumerator)
947 type->size = enumeration_size;
950 type->members = NULL;
952 xbt_dict_set(*types, origin, type, NULL);
956 xbt_free(type_origin);
965 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
967 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
972 strtok(xbt_dynar_get_as(split, 0, char *), "<");
973 origin = strdup(strtok(NULL, "<"));
974 xbt_str_rtrim(origin, ">:");
976 read = xbt_getline(&line, &n, fp);
978 dw_type_t type = NULL;
984 /* Wipeout the new line character */
985 line[read - 1] = '\0';
987 if(n == 0 || strlen(line) == 0){
988 read = xbt_getline(&line, &n, fp);
992 xbt_dynar_free(&split);
993 xbt_str_rtrim(line, NULL);
994 xbt_str_strip_spaces(line);
995 split = xbt_str_split(line, " ");
997 node_type = xbt_dynar_get_as(split, 1, char *);
999 if(strncmp(node_type, "DW_AT_", 6) != 0){
1004 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1005 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1006 }else if(strcmp(node_type, "DW_AT_name") == 0){
1008 end = xbt_str_join(split, " ");
1009 xbt_dynar_free(&split);
1010 split = xbt_str_split(end, "):");
1011 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1012 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1013 }else if(strcmp(node_type, "DW_AT_type") == 0){
1014 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1015 xbt_str_ltrim(type_origin, "<0x");
1016 xbt_str_rtrim(type_origin, ">");
1017 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1019 end = xbt_str_join(split, " ");
1020 xbt_dynar_free(&split);
1021 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1022 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1023 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1024 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1027 read = xbt_getline(&line, &n, fp);
1031 if(member_end && type){
1034 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1035 member_type->name = xbt_strdup(name);
1036 member_type->size = size;
1037 member_type->is_pointer_type = is_pointer;
1038 member_type->id = (void *)strtoul(origin, NULL, 16);
1039 member_type->offset = offset;
1041 member_type->dw_type_id = xbt_strdup(type_origin);
1043 xbt_dynar_push(type->members, &member_type);
1049 xbt_free(type_origin);
1056 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1057 origin = strdup(strtok(NULL, "<"));
1058 xbt_str_rtrim(origin, ">:");
1062 if(struct_decl || union_decl){
1063 type = xbt_new0(s_dw_type_t, 1);
1065 type->type = e_dw_structure_type;
1067 type->type = e_dw_union_type;
1068 type->name = xbt_strdup(name);
1070 type->is_pointer_type = is_pointer;
1071 type->id = (void *)strtoul(origin, NULL, 16);
1073 type->dw_type_id = xbt_strdup(type_origin);
1074 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1076 xbt_dict_set(*types, origin, type, NULL);
1082 xbt_free(type_origin);
1090 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1093 read = xbt_getline(&line, &n, fp);
1100 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1102 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1103 origin = strdup(strtok(NULL, "<"));
1104 xbt_str_rtrim(origin, ">:");
1106 read = xbt_getline(&line, &n, fp);
1108 dw_type_t type = NULL;
1114 /* Wipeout the new line character */
1115 line[read - 1] = '\0';
1117 if(n == 0 || strlen(line) == 0){
1118 read = xbt_getline(&line, &n, fp);
1122 xbt_dynar_free(&split);
1123 xbt_str_rtrim(line, NULL);
1124 xbt_str_strip_spaces(line);
1125 split = xbt_str_split(line, " ");
1127 node_type = xbt_dynar_get_as(split, 1, char *);
1129 if(strncmp(node_type, "DW_AT_", 6) != 0)
1132 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1133 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1134 }else if(strcmp(node_type, "DW_AT_name") == 0){
1135 end = xbt_str_join(split, " ");
1136 xbt_dynar_free(&split);
1137 split = xbt_str_split(end, "):");
1138 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1139 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1140 }else if(strcmp(node_type, "DW_AT_type") == 0){
1141 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1142 xbt_str_ltrim(type_origin, "<0x");
1143 xbt_str_rtrim(type_origin, ">");
1146 read = xbt_getline(&line, &n, fp);
1150 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1154 if(subrange && type){
1161 xbt_free(type_origin);
1167 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1168 origin = strdup(strtok(NULL, "<"));
1169 xbt_str_rtrim(origin, ">:");
1173 type = xbt_new0(s_dw_type_t, 1);
1174 type->type = e_dw_array_type;
1175 type->name = xbt_strdup(name);
1176 type->is_pointer_type = is_pointer;
1177 type->id = (void *)strtoul(origin, NULL, 16);
1179 type->dw_type_id = xbt_strdup(type_origin);
1180 type->members = NULL;
1182 xbt_dict_set(*types, origin, type, NULL);
1188 xbt_free(type_origin);
1193 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1196 read = xbt_getline(&line, &n, fp);
1205 read = xbt_getline(&line, &n, fp);
1211 xbt_dynar_free(&split);
1212 xbt_dict_free(&variables_origin);
1213 xbt_dict_free(&subprograms_origin);
1221 /******************************* Ignore mechanism *******************************/
1222 /*********************************************************************************/
1224 xbt_dynar_t mc_checkpoint_ignore;
1226 typedef struct s_mc_stack_ignore_variable{
1229 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1231 typedef struct s_mc_data_bss_ignore_variable{
1233 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1235 /**************************** Free functions ******************************/
1237 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1238 xbt_free(v->var_name);
1243 static void stack_ignore_variable_free_voidp(void *v){
1244 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1247 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1251 void heap_ignore_region_free_voidp(void *r){
1252 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1255 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1260 static void data_bss_ignore_variable_free_voidp(void *v){
1261 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1264 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1268 static void checkpoint_ignore_region_free_voidp(void *r){
1269 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1272 /***********************************************************************/
1274 void MC_ignore_heap(void *address, size_t size){
1276 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1280 mc_heap_ignore_region_t region = NULL;
1281 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1282 region->address = address;
1283 region->size = size;
1285 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1287 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1288 region->fragment = -1;
1289 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1291 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1292 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1295 if(mc_heap_comparison_ignore == NULL){
1296 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1297 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1303 unsigned int cursor = 0;
1304 mc_heap_ignore_region_t current_region = NULL;
1306 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1308 while(start <= end){
1309 cursor = (start + end) / 2;
1310 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1311 if(current_region->address == address){
1312 heap_ignore_region_free(region);
1316 }else if(current_region->address < address){
1323 if(current_region->address < address)
1324 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1326 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1332 void MC_remove_ignore_heap(void *address, size_t size){
1334 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1338 unsigned int cursor = 0;
1340 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1341 mc_heap_ignore_region_t region;
1342 int ignore_found = 0;
1344 while(start <= end){
1345 cursor = (start + end) / 2;
1346 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1347 if(region->address == address){
1350 }else if(region->address < address){
1353 if((char * )region->address <= ((char *)address + size)){
1362 if(ignore_found == 1){
1363 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1364 MC_remove_ignore_heap(address, size);
1372 void MC_ignore_global_variable(const char *name){
1374 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1378 if(mc_global_variables_libsimgrid){
1380 unsigned int cursor = 0;
1381 dw_variable_t current_var;
1383 int end = xbt_dynar_length(mc_global_variables_libsimgrid) - 1;
1385 while(start <= end){
1386 cursor = (start + end) /2;
1387 current_var = (dw_variable_t)xbt_dynar_get_as(mc_global_variables_libsimgrid, cursor, dw_variable_t);
1388 if(strcmp(current_var->name, name) == 0){
1389 xbt_dynar_remove_at(mc_global_variables_libsimgrid, cursor, NULL);
1391 end = xbt_dynar_length(mc_global_variables_libsimgrid) - 1;
1392 }else if(strcmp(current_var->name, name) < 0){
1401 if(mc_data_bss_comparison_ignore == NULL)
1402 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1404 mc_data_bss_ignore_variable_t var = NULL;
1405 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1406 var->name = strdup(name);
1408 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1410 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1414 unsigned int cursor = 0;
1416 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1417 mc_data_bss_ignore_variable_t current_var = NULL;
1419 while(start <= end){
1420 cursor = (start + end) / 2;
1421 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1422 if(strcmp(current_var->name, name) == 0){
1423 data_bss_ignore_variable_free(var);
1427 }else if(strcmp(current_var->name, name) < 0){
1434 if(strcmp(current_var->name, name) < 0)
1435 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1437 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1446 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1448 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1452 if(mc_local_variables_libsimgrid){
1453 unsigned int cursor = 0;
1454 dw_variable_t current_var;
1456 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1457 xbt_dict_cursor_t dict_cursor;
1458 char *current_frame_name;
1460 xbt_dict_foreach(mc_local_variables_libsimgrid, dict_cursor, current_frame_name, frame){
1462 end = xbt_dynar_length(frame->variables) - 1;
1463 while(start <= end){
1464 cursor = (start + end) / 2;
1465 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1466 if(strcmp(current_var->name, var_name) == 0){
1467 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1469 end = xbt_dynar_length(frame->variables) - 1;
1470 }else if(strcmp(current_var->name, var_name) < 0){
1477 xbt_dict_foreach(mc_local_variables_binary, dict_cursor, current_frame_name, frame){
1479 end = xbt_dynar_length(frame->variables) - 1;
1480 while(start <= end){
1481 cursor = (start + end) / 2;
1482 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1483 if(strcmp(current_var->name, var_name) == 0){
1484 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1486 end = xbt_dynar_length(frame->variables) - 1;
1487 }else if(strcmp(current_var->name, var_name) < 0){
1495 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(mc_local_variables_libsimgrid, frame_name))->variables;
1497 end = xbt_dynar_length(variables_list) - 1;
1498 while(start <= end){
1499 cursor = (start + end) / 2;
1500 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1501 if(strcmp(current_var->name, var_name) == 0){
1502 xbt_dynar_remove_at(variables_list, cursor, NULL);
1504 end = xbt_dynar_length(variables_list) - 1;
1505 }else if(strcmp(current_var->name, var_name) < 0){
1514 if(mc_stack_comparison_ignore == NULL)
1515 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1517 mc_stack_ignore_variable_t var = NULL;
1518 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1519 var->var_name = strdup(var_name);
1520 var->frame = strdup(frame_name);
1522 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1524 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1528 unsigned int cursor = 0;
1530 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1531 mc_stack_ignore_variable_t current_var = NULL;
1533 while(start <= end){
1534 cursor = (start + end) / 2;
1535 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1536 if(strcmp(current_var->frame, frame_name) == 0){
1537 if(strcmp(current_var->var_name, var_name) == 0){
1538 stack_ignore_variable_free(var);
1542 }else if(strcmp(current_var->var_name, var_name) < 0){
1547 }else if(strcmp(current_var->frame, frame_name) < 0){
1554 if(strcmp(current_var->frame, frame_name) == 0){
1555 if(strcmp(current_var->var_name, var_name) < 0){
1556 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1558 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1560 }else if(strcmp(current_var->frame, frame_name) < 0){
1561 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1563 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1573 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1575 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1579 if(stacks_areas == NULL)
1580 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1582 stack_region_t region = NULL;
1583 region = xbt_new0(s_stack_region_t, 1);
1584 region->address = stack;
1585 region->process_name = strdup(name);
1586 region->context = context;
1587 region->size = size;
1588 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1589 xbt_dynar_push(stacks_areas, ®ion);
1595 void MC_ignore(void *addr, size_t size){
1597 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1601 if(mc_checkpoint_ignore == NULL)
1602 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1604 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1605 region->addr = addr;
1606 region->size = size;
1608 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1609 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1612 unsigned int cursor = 0;
1614 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1615 mc_checkpoint_ignore_region_t current_region = NULL;
1617 while(start <= end){
1618 cursor = (start + end) / 2;
1619 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1620 if(current_region->addr == addr){
1621 if(current_region->size == size){
1622 checkpoint_ignore_region_free(region);
1626 }else if(current_region->size < size){
1631 }else if(current_region->addr < addr){
1638 if(current_region->addr == addr){
1639 if(current_region->size < size){
1640 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1642 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1644 }else if(current_region->addr < addr){
1645 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1647 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1655 /******************************* Initialisation of MC *******************************/
1656 /*********************************************************************************/
1658 static void MC_dump_ignored_local_variables(void){
1660 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1663 unsigned int cursor = 0;
1664 mc_stack_ignore_variable_t current_var;
1666 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1667 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1670 xbt_dynar_free(&mc_stack_comparison_ignore);
1671 mc_stack_comparison_ignore = NULL;
1675 static void MC_dump_ignored_global_variables(void){
1677 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1680 unsigned int cursor = 0;
1681 mc_data_bss_ignore_variable_t current_var;
1683 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1684 MC_ignore_global_variable(current_var->name);
1687 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1688 mc_data_bss_comparison_ignore = NULL;
1694 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1698 /* Initialize the data structures that must be persistent across every
1699 iteration of the model-checker (in RAW memory) */
1703 MC_init_memory_map_info();
1705 mc_local_variables_libsimgrid = xbt_dict_new_homogeneous(NULL);
1706 mc_local_variables_binary = xbt_dict_new_homogeneous(NULL);
1707 mc_global_variables_libsimgrid = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
1708 mc_global_variables_binary = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
1709 mc_variables_type_libsimgrid = xbt_dict_new_homogeneous(NULL);
1710 mc_variables_type_binary = xbt_dict_new_homogeneous(NULL);
1712 XBT_INFO("Get debug information ...");
1714 /* Get local variables in binary for state equality detection */
1715 xbt_dict_t binary_location_list = MC_dwarf_get_location_list(xbt_binary_name);
1716 MC_dwarf_get_variables(xbt_binary_name, binary_location_list, &mc_local_variables_binary, &mc_global_variables_binary, &mc_variables_type_binary);
1718 /* Get local variables in libsimgrid for state equality detection */
1719 xbt_dict_t libsimgrid_location_list = MC_dwarf_get_location_list(libsimgrid_path);
1720 MC_dwarf_get_variables(libsimgrid_path, libsimgrid_location_list, &mc_local_variables_libsimgrid, &mc_global_variables_libsimgrid, &mc_variables_type_libsimgrid);
1722 xbt_dict_free(&libsimgrid_location_list);
1723 xbt_dict_free(&binary_location_list);
1725 XBT_INFO("Get debug information done !");
1727 /* Remove variables ignored before getting list of variables */
1728 MC_dump_ignored_local_variables();
1729 MC_dump_ignored_global_variables();
1731 /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
1732 MC_get_libsimgrid_plt_section();
1733 MC_get_binary_plt_section();
1736 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1740 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1741 MC_ignore_local_variable("e", "*");
1742 MC_ignore_local_variable("__ex_cleanup", "*");
1743 MC_ignore_local_variable("__ex_mctx_en", "*");
1744 MC_ignore_local_variable("__ex_mctx_me", "*");
1745 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1746 MC_ignore_local_variable("_log_ev", "*");
1747 MC_ignore_local_variable("_throw_ctx", "*");
1748 MC_ignore_local_variable("ctx", "*");
1750 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1751 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1753 /* Ignore local variable about time used for tracing */
1754 MC_ignore_local_variable("start_time", "*");
1756 MC_ignore_global_variable("mc_comp_times");
1757 MC_ignore_global_variable("mc_snapshot_comparison_time");
1758 MC_ignore_global_variable("mc_time");
1759 MC_ignore_global_variable("smpi_current_rank");
1760 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1761 MC_ignore_global_variable("maestro_stack_start");
1762 MC_ignore_global_variable("maestro_stack_end");
1764 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1765 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1766 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1767 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1769 smx_process_t process;
1770 xbt_swag_foreach(process, simix_global->process_list){
1771 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1779 static void MC_init_dot_output(){ /* FIXME : more colors */
1783 colors[2] = "green3";
1784 colors[3] = "goldenrod";
1785 colors[4] = "brown";
1786 colors[5] = "purple";
1787 colors[6] = "magenta";
1788 colors[7] = "turquoise4";
1789 colors[8] = "gray25";
1790 colors[9] = "forestgreen";
1791 colors[10] = "hotpink";
1792 colors[11] = "lightblue";
1795 dot_output = fopen(_sg_mc_dot_output_file, "w");
1797 if(dot_output == NULL){
1798 perror("Error open dot output file");
1802 fprintf(dot_output, "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");
1806 /******************************* Core of MC *******************************/
1807 /**************************************************************************/
1809 void MC_do_the_modelcheck_for_real() {
1812 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1815 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1816 if (mc_reduce_kind==e_mc_reduce_unset)
1817 mc_reduce_kind=e_mc_reduce_dpor;
1819 XBT_INFO("Check a safety property");
1820 MC_modelcheck_safety();
1824 if (mc_reduce_kind==e_mc_reduce_unset)
1825 mc_reduce_kind=e_mc_reduce_none;
1827 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1828 MC_automaton_load(_sg_mc_property_file);
1829 MC_modelcheck_liveness();
1833 void MC_modelcheck_safety(void)
1835 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1837 /* Check if MC is already initialized */
1838 if (initial_state_safety)
1841 mc_time = xbt_new0(double, simix_process_maxpid);
1843 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1844 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1846 /* Initialize the data structures that must be persistent across every
1847 iteration of the model-checker (in RAW memory) */
1851 /* Initialize statistics */
1852 mc_stats = xbt_new0(s_mc_stats_t, 1);
1853 mc_stats->state_size = 1;
1855 /* Create exploration stack */
1856 mc_stack_safety = xbt_fifo_new();
1858 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1859 MC_init_dot_output();
1863 if(_sg_mc_visited > 0){
1867 MC_init_memory_map_info();
1868 MC_get_libsimgrid_plt_section();
1869 MC_get_binary_plt_section();
1876 /* Save the initial state */
1877 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1878 initial_state_safety->snapshot = MC_take_snapshot(0);
1890 void MC_modelcheck_liveness(){
1892 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1896 mc_time = xbt_new0(double, simix_process_maxpid);
1898 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1899 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1903 /* Initialize statistics */
1904 mc_stats = xbt_new0(s_mc_stats_t, 1);
1905 mc_stats->state_size = 1;
1907 /* Create exploration stack */
1908 mc_stack_liveness = xbt_fifo_new();
1910 /* Create the initial state */
1911 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1913 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1914 MC_init_dot_output();
1921 MC_print_statistics(mc_stats);
1937 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1939 return simcall->mc_value;
1943 int MC_random(int min, int max)
1945 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1946 return simcall_mc_random(min, max);
1950 * \brief Schedules all the process that are ready to run
1952 void MC_wait_for_requests(void)
1954 smx_process_t process;
1958 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
1959 SIMIX_process_runall();
1960 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
1961 req = &process->simcall;
1962 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
1963 SIMIX_simcall_pre(req, 0);
1968 int MC_deadlock_check()
1970 int deadlock = FALSE;
1971 smx_process_t process;
1972 if(xbt_swag_size(simix_global->process_list)){
1974 xbt_swag_foreach(process, simix_global->process_list){
1975 if(process->simcall.call != SIMCALL_NONE
1976 && MC_request_is_enabled(&process->simcall)){
1986 * \brief Re-executes from the state at position start all the transitions indicated by
1987 * a given model-checker stack.
1988 * \param stack The stack with the transitions to execute.
1989 * \param start Start index to begin the re-execution.
1991 void MC_replay(xbt_fifo_t stack, int start)
1993 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
1995 int value, i = 1, count = 1;
1997 smx_simcall_t req = NULL, saved_req = NULL;
1998 xbt_fifo_item_t item, start_item;
2000 smx_process_t process = NULL;
2002 XBT_DEBUG("**** Begin Replay ****");
2005 /* Restore the initial state */
2006 MC_restore_snapshot(initial_state_safety->snapshot);
2007 /* At the moment of taking the snapshot the raw heap was set, so restoring
2008 * it will set it back again, we have to unset it to continue */
2012 start_item = xbt_fifo_get_last_item(stack);
2015 start_item = xbt_fifo_get_prev_item(start_item);
2021 xbt_dict_reset(first_enabled_state);
2022 xbt_swag_foreach(process, simix_global->process_list){
2023 if(MC_process_is_enabled(process)){
2024 char *key = bprintf("%lu", process->pid);
2025 char *data = bprintf("%d", count);
2026 xbt_dict_set(first_enabled_state, key, data, NULL);
2033 /* Traverse the stack from the state at position start and re-execute the transitions */
2034 for (item = start_item;
2035 item != xbt_fifo_get_first_item(stack);
2036 item = xbt_fifo_get_prev_item(item)) {
2038 state = (mc_state_t) xbt_fifo_get_item_content(item);
2039 saved_req = MC_state_get_executed_request(state, &value);
2042 char *key = bprintf("%lu", saved_req->issuer->pid);
2043 xbt_dict_remove(first_enabled_state, key);
2048 /* because we got a copy of the executed request, we have to fetch the
2049 real one, pointed by the request field of the issuer process */
2050 req = &saved_req->issuer->simcall;
2052 /* Debug information */
2053 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2054 req_str = MC_request_to_string(req, value);
2055 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2060 SIMIX_simcall_pre(req, value);
2061 MC_wait_for_requests();
2066 /* Insert in dict all enabled processes */
2067 xbt_swag_foreach(process, simix_global->process_list){
2068 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2069 char *key = bprintf("%lu", process->pid);
2070 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2071 char *data = bprintf("%d", count);
2072 xbt_dict_set(first_enabled_state, key, data, NULL);
2079 /* Update statistics */
2080 mc_stats->visited_states++;
2081 mc_stats->executed_transitions++;
2085 XBT_DEBUG("**** End Replay ****");
2095 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2098 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2102 smx_simcall_t req = NULL, saved_req = NULL;
2103 xbt_fifo_item_t item;
2108 XBT_DEBUG("**** Begin Replay ****");
2110 /* Restore the initial state */
2111 MC_restore_snapshot(initial_state_liveness->snapshot);
2113 /* At the moment of taking the snapshot the raw heap was set, so restoring
2114 * it will set it back again, we have to unset it to continue */
2115 if(!initial_state_liveness->raw_mem_set)
2120 item = xbt_fifo_get_last_item(stack);
2122 while(depth <= xbt_fifo_size(stack)){
2124 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2125 state = (mc_state_t) pair->graph_state;
2127 if(pair->requests > 0){
2129 saved_req = MC_state_get_executed_request(state, &value);
2130 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2132 if(saved_req != NULL){
2133 /* because we got a copy of the executed request, we have to fetch the
2134 real one, pointed by the request field of the issuer process */
2135 req = &saved_req->issuer->simcall;
2136 //XBT_DEBUG("Req->call %u", req->call);
2138 /* Debug information */
2139 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2140 req_str = MC_request_to_string(req, value);
2141 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2147 SIMIX_simcall_pre(req, value);
2148 MC_wait_for_requests();
2153 /* Update statistics */
2154 mc_stats->visited_pairs++;
2155 mc_stats->executed_transitions++;
2157 item = xbt_fifo_get_prev_item(item);
2162 /* Traverse the stack from the initial state and re-execute the transitions */
2163 for (item = xbt_fifo_get_last_item(stack);
2164 item != xbt_fifo_get_first_item(stack);
2165 item = xbt_fifo_get_prev_item(item)) {
2167 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2168 state = (mc_state_t) pair->graph_state;
2170 if(pair->requests > 0){
2172 saved_req = MC_state_get_executed_request(state, &value);
2173 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2175 if(saved_req != NULL){
2176 /* because we got a copy of the executed request, we have to fetch the
2177 real one, pointed by the request field of the issuer process */
2178 req = &saved_req->issuer->simcall;
2179 //XBT_DEBUG("Req->call %u", req->call);
2181 /* Debug information */
2182 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2183 req_str = MC_request_to_string(req, value);
2184 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2190 SIMIX_simcall_pre(req, value);
2191 MC_wait_for_requests();
2196 /* Update statistics */
2197 mc_stats->visited_pairs++;
2198 mc_stats->executed_transitions++;
2202 XBT_DEBUG("**** End Replay ****");
2204 if(initial_state_liveness->raw_mem_set)
2212 * \brief Dumps the contents of a model-checker's stack and shows the actual
2214 * \param stack The stack to dump
2216 void MC_dump_stack_safety(xbt_fifo_t stack)
2219 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2221 MC_show_stack_safety(stack);
2223 if(!_sg_mc_checkpoint){
2228 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2229 MC_state_delete(state);
2242 void MC_show_stack_safety(xbt_fifo_t stack)
2245 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2251 xbt_fifo_item_t item;
2253 char *req_str = NULL;
2255 for (item = xbt_fifo_get_last_item(stack);
2256 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2257 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2258 req = MC_state_get_executed_request(state, &value);
2260 req_str = MC_request_to_string(req, value);
2261 XBT_INFO("%s", req_str);
2270 void MC_show_deadlock(smx_simcall_t req)
2272 /*char *req_str = NULL;*/
2273 XBT_INFO("**************************");
2274 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2275 XBT_INFO("**************************");
2276 XBT_INFO("Locked request:");
2277 /*req_str = MC_request_to_string(req);
2278 XBT_INFO("%s", req_str);
2279 xbt_free(req_str);*/
2280 XBT_INFO("Counter-example execution trace:");
2281 MC_dump_stack_safety(mc_stack_safety);
2282 MC_print_statistics(mc_stats);
2286 void MC_show_stack_liveness(xbt_fifo_t stack){
2289 xbt_fifo_item_t item;
2291 char *req_str = NULL;
2293 for (item = xbt_fifo_get_last_item(stack);
2294 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2295 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2296 req = MC_state_get_executed_request(pair->graph_state, &value);
2298 if(pair->requests>0){
2299 req_str = MC_request_to_string(req, value);
2300 XBT_INFO("%s", req_str);
2303 XBT_INFO("End of system requests but evolution in Büchi automaton");
2309 void MC_dump_stack_liveness(xbt_fifo_t stack){
2311 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2316 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2317 MC_pair_delete(pair);
2326 void MC_print_statistics(mc_stats_t stats)
2328 if(stats->expanded_pairs == 0){
2329 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2330 XBT_INFO("Visited states = %lu", stats->visited_states);
2332 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2333 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2335 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2337 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2338 fprintf(dot_output, "}\n");
2344 void MC_assert(int prop)
2346 if (MC_is_active() && !prop){
2347 XBT_INFO("**************************");
2348 XBT_INFO("*** PROPERTY NOT VALID ***");
2349 XBT_INFO("**************************");
2350 XBT_INFO("Counter-example execution trace:");
2351 MC_dump_stack_safety(mc_stack_safety);
2352 MC_print_statistics(mc_stats);
2358 user_max_depth_reached = 1;
2361 void MC_process_clock_add(smx_process_t process, double amount)
2363 mc_time[process->pid] += amount;
2366 double MC_process_clock_get(smx_process_t process)
2370 return mc_time[process->pid];
2378 void MC_automaton_load(const char *file){
2380 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2384 if (_mc_property_automaton == NULL)
2385 _mc_property_automaton = xbt_automaton_new();
2387 xbt_automaton_load(_mc_property_automaton,file);
2396 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2398 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2402 if (_mc_property_automaton == NULL)
2403 _mc_property_automaton = xbt_automaton_new();
2405 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);