1 /* Copyright (c) 2008-2013. 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("%d", (int)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, " ");
375 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
377 // Take the key from the first line of the list:
379 key = bprintf("%d", (int)strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
382 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
383 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
384 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
387 while(cursor_remove < 3){
388 xbt_dynar_remove_at(split, 0, NULL);
392 loc_expr = xbt_str_join(split, " ");
393 xbt_str_ltrim(loc_expr, "(");
394 xbt_str_rtrim(loc_expr, ")");
395 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
397 xbt_dynar_push(loclist, &new_entry);
399 xbt_dynar_free(&split);
402 read = xbt_getline(&line, &n, fp);
404 line[read - 1] = '\0';
405 xbt_str_strip_spaces(line);
406 split = xbt_str_split(line, " ");
412 xbt_dict_set(location_list, key, loclist, NULL);
415 xbt_dynar_free(&split);
423 return location_list;
426 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
428 xbt_dict_cursor_t cursor = NULL;
432 xbt_dict_foreach(all_variables, cursor, name, res) {
433 if(offset >= res->start && offset < res->end){
434 xbt_dict_cursor_free(&cursor);
439 xbt_dict_cursor_free(&cursor);
444 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
446 unsigned int cursor = 0;
447 dw_variable_t current_var;
449 xbt_dynar_foreach(frame->variables, cursor, current_var){
450 if(strcmp(var, current_var->name) == 0)
457 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
459 if(xbt_dynar_is_empty(variables))
462 unsigned int cursor = 0;
464 int end = xbt_dynar_length(variables) - 1;
465 dw_variable_t var_test = NULL;
468 cursor = (start + end) / 2;
469 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
470 if(strcmp(var_test->name, var) < 0){
472 }else if(strcmp(var_test->name, var) > 0){
475 if(address){ /* global variable */
476 if(var_test->address.address == address)
478 if(var_test->address.address > address)
482 }else{ /* local variable */
488 if(strcmp(var_test->name, var) == 0){
489 if(address && var_test->address.address < address)
493 }else if(strcmp(var_test->name, var) < 0)
501 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){
503 char *command = bprintf("objdump -Wi %s", elf_file);
505 FILE *fp = popen(command, "r");
508 perror("popen for objdump failed");
510 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
511 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
512 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
513 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
514 *parent_value = NULL;
518 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
519 is_pointer = 0, struct_decl = 0, member_end = 0,
520 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
522 xbt_dynar_t split = NULL, split2 = NULL;
524 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
525 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
527 dw_frame_t variable_frame, subroutine_frame = NULL;
529 e_dw_type_type type_type = -1;
531 read = xbt_getline(&line, &n, fp);
535 /* Wipeout the new line character */
536 line[read - 1] = '\0';
538 if(n == 0 || strlen(line) == 0){
539 read = xbt_getline(&line, &n, fp);
543 xbt_str_ltrim(line, NULL);
544 xbt_str_strip_spaces(line);
547 read = xbt_getline(&line, &n, fp);
551 xbt_dynar_free(&split);
552 split = xbt_str_split(line, " ");
555 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
557 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
559 dw_frame_t frame = NULL;
561 strtok(xbt_dynar_get_as(split, 0, char *), "<");
562 subprogram_start = xbt_strdup(strtok(NULL, "<"));
563 xbt_str_rtrim(subprogram_start, ">:");
565 read = xbt_getline(&line, &n, fp);
569 /* Wipeout the new line character */
570 line[read - 1] = '\0';
572 if(n == 0 || strlen(line) == 0){
573 read = xbt_getline(&line, &n, fp);
577 xbt_dynar_free(&split);
578 xbt_str_rtrim(line, NULL);
579 xbt_str_strip_spaces(line);
580 split = xbt_str_split(line, " ");
582 node_type = xbt_dynar_get_as(split, 1, char *);
584 if(strncmp(node_type, "DW_AT_", 6) != 0)
587 if(strcmp(node_type, "DW_AT_sibling") == 0){
589 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
590 xbt_str_ltrim(subprogram_end, "<0x");
591 xbt_str_rtrim(subprogram_end, ">");
593 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
596 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
597 xbt_str_ltrim(abstract_origin, "<0x");
598 xbt_str_rtrim(abstract_origin, ">");
599 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
600 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
601 xbt_free(abstract_origin);
603 }else if(strcmp(node_type, "DW_AT_name") == 0){
606 xbt_free(current_frame);
607 frame = xbt_new0(s_dw_frame_t, 1);
608 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
609 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
610 frame->frame_base = xbt_new0(s_dw_location_t, 1);
611 current_frame = strdup(frame->name);
613 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
615 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
617 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
619 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
621 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
625 xbt_str_strip_spaces(line);
626 split2 = xbt_str_split(line, "(");
627 xbt_dynar_remove_at(split2, 0, NULL);
628 loc_expr = xbt_str_join(split2, " ");
629 xbt_str_rtrim(loc_expr, ")");
630 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
631 xbt_dynar_free(&split2);
636 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
639 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
641 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
644 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
646 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
648 xbt_free(frame->name);
649 xbt_free(current_frame);
650 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
651 current_frame = strdup(frame->name);
652 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
656 read = xbt_getline(&line, &n, fp);
661 frame->start = strtoul(subprogram_start, NULL, 16);
662 if(subprogram_end != NULL)
663 frame->end = strtoul(subprogram_end, NULL, 16);
664 xbt_dict_set(*local_variables, frame->name, frame, NULL);
667 xbt_free(subprogram_start);
668 xbt_free(subprogram_end);
669 subprogram_end = NULL;
672 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
674 dw_variable_t var = NULL;
676 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
677 parent_value = strtok(parent_value,"<");
678 xbt_str_rtrim(parent_value, ">");
679 parent = atoi(parent_value);
680 xbt_free(parent_value);
685 strtok(xbt_dynar_get_as(split, 0, char *), "<");
686 origin = xbt_strdup(strtok(NULL, "<"));
687 xbt_str_rtrim(origin, ">:");
689 read = xbt_getline(&line, &n, fp);
693 /* Wipeout the new line character */
694 line[read - 1] = '\0';
696 if(n == 0 || strlen(line) == 0){
697 read = xbt_getline(&line, &n, fp);
701 xbt_dynar_free(&split);
702 xbt_str_rtrim(line, NULL);
703 xbt_str_strip_spaces(line);
704 split = xbt_str_split(line, " ");
706 node_type = xbt_dynar_get_as(split, 1, char *);
708 if(strncmp(node_type, "DW_AT_", 6) != 0)
711 if(strcmp(node_type, "DW_AT_name") == 0){
713 var = xbt_new0(s_dw_variable_t, 1);
714 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
715 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
717 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
721 abstract_origin = xbt_dynar_get_as(split, 2, char *);
722 xbt_str_ltrim(abstract_origin, "<0x");
723 xbt_str_rtrim(abstract_origin, ">");
725 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
726 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
727 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
729 }else if(strcmp(node_type, "DW_AT_location") == 0){
733 if(!global_variable){
735 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
737 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
738 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
740 xbt_str_strip_spaces(line);
741 split2 = xbt_str_split(line, "(");
742 xbt_dynar_remove_at(split2, 0, NULL);
743 loc_expr = xbt_str_join(split2, " ");
744 xbt_str_rtrim(loc_expr, ")");
745 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
747 xbt_dynar_free(&split2);
748 split2 = xbt_str_split(loc_expr, " ");
749 if(strcmp(elf_file, xbt_binary_name) != 0)
750 var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
752 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
754 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
756 xbt_dynar_free(&split2);
760 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
761 xbt_str_rtrim(global_address, ")");
762 if(strcmp(elf_file, xbt_binary_name) != 0)
763 var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(global_address, NULL, 16));
765 var->address.address = (void *)strtoul(global_address, NULL, 16);
766 xbt_free(global_address);
767 global_address = NULL;
772 }else if(strcmp(node_type, "DW_AT_type") == 0){
774 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
775 xbt_str_ltrim(type_origin, "<0x");
776 xbt_str_rtrim(type_origin, ">");
778 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
782 dw_variable_free(var);
786 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
790 dw_variable_free(var);
796 read = xbt_getline(&line, &n, fp);
800 if(new_variable == 1){
802 if(!global_variable){
803 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
804 var->type_origin = strdup(type_origin);
806 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
808 xbt_dynar_insert_at(variable_frame->variables, index, &var);
810 var->type_origin = strdup(type_origin);
812 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
814 xbt_dynar_insert_at(*global_variables, index, &var);
817 xbt_free(type_origin);
824 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
826 read = xbt_getline(&line, &n, fp);
830 /* Wipeout the new line character */
831 line[read - 1] = '\0';
833 if(n == 0 || strlen(line) == 0){
834 read = xbt_getline(&line, &n, fp);
838 xbt_dynar_free(&split);
839 xbt_str_rtrim(line, NULL);
840 xbt_str_strip_spaces(line);
841 split = xbt_str_split(line, " ");
843 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
846 node_type = xbt_dynar_get_as(split, 1, char *);
848 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
850 origin = xbt_dynar_get_as(split, 2, char *);
851 xbt_str_ltrim(origin, "<0x");
852 xbt_str_rtrim(origin, ">");
854 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
855 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
857 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
859 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
861 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
863 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
866 read = xbt_getline(&line, &n, fp);
870 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
871 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
872 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
873 || strcmp(node_type, "(DW_TAG_typedef)") == 0
874 || strcmp(node_type, "(DW_TAG_const_type)") == 0
875 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
876 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
877 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
879 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
880 type_type = e_dw_base_type;
881 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
882 type_type = e_dw_enumeration_type;
883 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
884 type_type = e_dw_enumerator;
885 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
886 type_type = e_dw_typedef;
887 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
888 type_type = e_dw_const_type;
889 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
890 type_type = e_dw_pointer_type;
891 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
892 type_type = e_dw_subroutine_type;
893 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
894 type_type = e_dw_volatile_type;
896 strtok(xbt_dynar_get_as(split, 0, char *), "<");
897 origin = strdup(strtok(NULL, "<"));
898 xbt_str_rtrim(origin, ">:");
900 read = xbt_getline(&line, &n, fp);
904 /* Wipeout the new line character */
905 line[read - 1] = '\0';
907 if(n == 0 || strlen(line) == 0){
908 read = xbt_getline(&line, &n, fp);
912 xbt_dynar_free(&split);
913 xbt_str_rtrim(line, NULL);
914 xbt_str_strip_spaces(line);
915 split = xbt_str_split(line, " ");
917 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
920 node_type = xbt_dynar_get_as(split, 1, char *);
922 if(strcmp(node_type, "DW_AT_byte_size") == 0){
923 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
924 if(type_type == e_dw_enumeration_type)
925 enumeration_size = size;
926 }else if(strcmp(node_type, "DW_AT_name") == 0){
927 end = xbt_str_join(split, " ");
928 xbt_dynar_free(&split);
929 split = xbt_str_split(end, "):");
930 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
931 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
932 }else if(strcmp(node_type, "DW_AT_type") == 0){
933 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
934 xbt_str_ltrim(type_origin, "<0x");
935 xbt_str_rtrim(type_origin, ">");
938 read = xbt_getline(&line, &n, fp);
941 dw_type_t type = xbt_new0(s_dw_type_t, 1);
942 type->type = type_type;
944 type->name = xbt_strdup(name);
946 type->name = xbt_strdup("undefined");
947 type->is_pointer_type = is_pointer;
948 type->id = (void *)strtoul(origin, NULL, 16);
950 type->dw_type_id = xbt_strdup(type_origin);
951 if(type_type == e_dw_enumerator)
952 type->size = enumeration_size;
955 type->members = NULL;
957 xbt_dict_set(*types, origin, type, NULL);
961 xbt_free(type_origin);
970 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
972 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
977 strtok(xbt_dynar_get_as(split, 0, char *), "<");
978 origin = strdup(strtok(NULL, "<"));
979 xbt_str_rtrim(origin, ">:");
981 read = xbt_getline(&line, &n, fp);
983 dw_type_t type = NULL;
989 /* Wipeout the new line character */
990 line[read - 1] = '\0';
992 if(n == 0 || strlen(line) == 0){
993 read = xbt_getline(&line, &n, fp);
997 xbt_dynar_free(&split);
998 xbt_str_rtrim(line, NULL);
999 xbt_str_strip_spaces(line);
1000 split = xbt_str_split(line, " ");
1002 node_type = xbt_dynar_get_as(split, 1, char *);
1004 if(strncmp(node_type, "DW_AT_", 6) != 0){
1009 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1010 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1011 }else if(strcmp(node_type, "DW_AT_name") == 0){
1013 end = xbt_str_join(split, " ");
1014 xbt_dynar_free(&split);
1015 split = xbt_str_split(end, "):");
1016 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1017 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1018 }else if(strcmp(node_type, "DW_AT_type") == 0){
1019 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1020 xbt_str_ltrim(type_origin, "<0x");
1021 xbt_str_rtrim(type_origin, ">");
1022 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1024 end = xbt_str_join(split, " ");
1025 xbt_dynar_free(&split);
1026 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1027 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1028 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1029 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1032 read = xbt_getline(&line, &n, fp);
1036 if(member_end && type){
1039 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1040 member_type->name = xbt_strdup(name);
1041 member_type->size = size;
1042 member_type->is_pointer_type = is_pointer;
1043 member_type->id = (void *)strtoul(origin, NULL, 16);
1044 member_type->offset = offset;
1046 member_type->dw_type_id = xbt_strdup(type_origin);
1048 xbt_dynar_push(type->members, &member_type);
1054 xbt_free(type_origin);
1061 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1062 origin = strdup(strtok(NULL, "<"));
1063 xbt_str_rtrim(origin, ">:");
1067 if(struct_decl || union_decl){
1068 type = xbt_new0(s_dw_type_t, 1);
1070 type->type = e_dw_structure_type;
1072 type->type = e_dw_union_type;
1073 type->name = xbt_strdup(name);
1075 type->is_pointer_type = is_pointer;
1076 type->id = (void *)strtoul(origin, NULL, 16);
1078 type->dw_type_id = xbt_strdup(type_origin);
1079 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1081 xbt_dict_set(*types, origin, type, NULL);
1087 xbt_free(type_origin);
1095 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1098 read = xbt_getline(&line, &n, fp);
1105 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1107 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1108 origin = strdup(strtok(NULL, "<"));
1109 xbt_str_rtrim(origin, ">:");
1111 read = xbt_getline(&line, &n, fp);
1113 dw_type_t type = NULL;
1119 /* Wipeout the new line character */
1120 line[read - 1] = '\0';
1122 if(n == 0 || strlen(line) == 0){
1123 read = xbt_getline(&line, &n, fp);
1127 xbt_dynar_free(&split);
1128 xbt_str_rtrim(line, NULL);
1129 xbt_str_strip_spaces(line);
1130 split = xbt_str_split(line, " ");
1132 node_type = xbt_dynar_get_as(split, 1, char *);
1134 if(strncmp(node_type, "DW_AT_", 6) != 0)
1137 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1138 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1139 }else if(strcmp(node_type, "DW_AT_name") == 0){
1140 end = xbt_str_join(split, " ");
1141 xbt_dynar_free(&split);
1142 split = xbt_str_split(end, "):");
1143 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1144 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1145 }else if(strcmp(node_type, "DW_AT_type") == 0){
1146 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1147 xbt_str_ltrim(type_origin, "<0x");
1148 xbt_str_rtrim(type_origin, ">");
1151 read = xbt_getline(&line, &n, fp);
1155 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1159 if(subrange && type){
1166 xbt_free(type_origin);
1172 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1173 origin = strdup(strtok(NULL, "<"));
1174 xbt_str_rtrim(origin, ">:");
1178 type = xbt_new0(s_dw_type_t, 1);
1179 type->type = e_dw_array_type;
1180 type->name = xbt_strdup(name);
1181 type->is_pointer_type = is_pointer;
1182 type->id = (void *)strtoul(origin, NULL, 16);
1184 type->dw_type_id = xbt_strdup(type_origin);
1185 type->members = NULL;
1187 xbt_dict_set(*types, origin, type, NULL);
1193 xbt_free(type_origin);
1198 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1201 read = xbt_getline(&line, &n, fp);
1210 read = xbt_getline(&line, &n, fp);
1216 xbt_dynar_free(&split);
1217 xbt_dict_free(&variables_origin);
1218 xbt_dict_free(&subprograms_origin);
1226 /******************************* Ignore mechanism *******************************/
1227 /*********************************************************************************/
1229 xbt_dynar_t mc_checkpoint_ignore;
1231 typedef struct s_mc_stack_ignore_variable{
1234 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1236 typedef struct s_mc_data_bss_ignore_variable{
1238 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1240 /**************************** Free functions ******************************/
1242 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1243 xbt_free(v->var_name);
1248 static void stack_ignore_variable_free_voidp(void *v){
1249 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1252 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1256 void heap_ignore_region_free_voidp(void *r){
1257 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1260 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1265 static void data_bss_ignore_variable_free_voidp(void *v){
1266 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1269 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1273 static void checkpoint_ignore_region_free_voidp(void *r){
1274 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1277 /***********************************************************************/
1279 void MC_ignore_heap(void *address, size_t size){
1281 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1285 mc_heap_ignore_region_t region = NULL;
1286 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1287 region->address = address;
1288 region->size = size;
1290 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1292 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1293 region->fragment = -1;
1294 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1296 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1297 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1300 if(mc_heap_comparison_ignore == NULL){
1301 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1302 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1308 unsigned int cursor = 0;
1309 mc_heap_ignore_region_t current_region = NULL;
1311 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1313 while(start <= end){
1314 cursor = (start + end) / 2;
1315 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1316 if(current_region->address == address){
1317 heap_ignore_region_free(region);
1321 }else if(current_region->address < address){
1328 if(current_region->address < address)
1329 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1331 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1337 void MC_remove_ignore_heap(void *address, size_t size){
1339 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1343 unsigned int cursor = 0;
1345 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1346 mc_heap_ignore_region_t region;
1347 int ignore_found = 0;
1349 while(start <= end){
1350 cursor = (start + end) / 2;
1351 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1352 if(region->address == address){
1355 }else if(region->address < address){
1358 if((char * )region->address <= ((char *)address + size)){
1367 if(ignore_found == 1){
1368 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1369 MC_remove_ignore_heap(address, size);
1377 void MC_ignore_global_variable(const char *name){
1379 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1383 if(mc_global_variables_libsimgrid){
1385 unsigned int cursor = 0;
1386 dw_variable_t current_var;
1388 int end = xbt_dynar_length(mc_global_variables_libsimgrid) - 1;
1390 while(start <= end){
1391 cursor = (start + end) /2;
1392 current_var = (dw_variable_t)xbt_dynar_get_as(mc_global_variables_libsimgrid, cursor, dw_variable_t);
1393 if(strcmp(current_var->name, name) == 0){
1394 xbt_dynar_remove_at(mc_global_variables_libsimgrid, cursor, NULL);
1396 end = xbt_dynar_length(mc_global_variables_libsimgrid) - 1;
1397 }else if(strcmp(current_var->name, name) < 0){
1406 if(mc_data_bss_comparison_ignore == NULL)
1407 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1409 mc_data_bss_ignore_variable_t var = NULL;
1410 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1411 var->name = strdup(name);
1413 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1415 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1419 unsigned int cursor = 0;
1421 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1422 mc_data_bss_ignore_variable_t current_var = NULL;
1424 while(start <= end){
1425 cursor = (start + end) / 2;
1426 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1427 if(strcmp(current_var->name, name) == 0){
1428 data_bss_ignore_variable_free(var);
1432 }else if(strcmp(current_var->name, name) < 0){
1439 if(strcmp(current_var->name, name) < 0)
1440 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1442 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1451 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1453 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1457 if(mc_local_variables_libsimgrid){
1458 unsigned int cursor = 0;
1459 dw_variable_t current_var;
1461 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1462 xbt_dict_cursor_t dict_cursor;
1463 char *current_frame_name;
1465 xbt_dict_foreach(mc_local_variables_libsimgrid, dict_cursor, current_frame_name, frame){
1467 end = xbt_dynar_length(frame->variables) - 1;
1468 while(start <= end){
1469 cursor = (start + end) / 2;
1470 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1471 if(strcmp(current_var->name, var_name) == 0){
1472 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1474 end = xbt_dynar_length(frame->variables) - 1;
1475 }else if(strcmp(current_var->name, var_name) < 0){
1482 xbt_dict_foreach(mc_local_variables_binary, dict_cursor, current_frame_name, frame){
1484 end = xbt_dynar_length(frame->variables) - 1;
1485 while(start <= end){
1486 cursor = (start + end) / 2;
1487 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1488 if(strcmp(current_var->name, var_name) == 0){
1489 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1491 end = xbt_dynar_length(frame->variables) - 1;
1492 }else if(strcmp(current_var->name, var_name) < 0){
1500 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(mc_local_variables_libsimgrid, frame_name))->variables;
1502 end = xbt_dynar_length(variables_list) - 1;
1503 while(start <= end){
1504 cursor = (start + end) / 2;
1505 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1506 if(strcmp(current_var->name, var_name) == 0){
1507 xbt_dynar_remove_at(variables_list, cursor, NULL);
1509 end = xbt_dynar_length(variables_list) - 1;
1510 }else if(strcmp(current_var->name, var_name) < 0){
1519 if(mc_stack_comparison_ignore == NULL)
1520 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1522 mc_stack_ignore_variable_t var = NULL;
1523 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1524 var->var_name = strdup(var_name);
1525 var->frame = strdup(frame_name);
1527 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1529 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1533 unsigned int cursor = 0;
1535 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1536 mc_stack_ignore_variable_t current_var = NULL;
1538 while(start <= end){
1539 cursor = (start + end) / 2;
1540 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1541 if(strcmp(current_var->frame, frame_name) == 0){
1542 if(strcmp(current_var->var_name, var_name) == 0){
1543 stack_ignore_variable_free(var);
1547 }else if(strcmp(current_var->var_name, var_name) < 0){
1552 }else if(strcmp(current_var->frame, frame_name) < 0){
1559 if(strcmp(current_var->frame, frame_name) == 0){
1560 if(strcmp(current_var->var_name, var_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);
1565 }else if(strcmp(current_var->frame, frame_name) < 0){
1566 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1568 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1578 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1580 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1584 if(stacks_areas == NULL)
1585 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1587 stack_region_t region = NULL;
1588 region = xbt_new0(s_stack_region_t, 1);
1589 region->address = stack;
1590 region->process_name = strdup(name);
1591 region->context = context;
1592 region->size = size;
1593 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1594 xbt_dynar_push(stacks_areas, ®ion);
1600 void MC_ignore(void *addr, size_t size){
1602 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1606 if(mc_checkpoint_ignore == NULL)
1607 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1609 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1610 region->addr = addr;
1611 region->size = size;
1613 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1614 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1617 unsigned int cursor = 0;
1619 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1620 mc_checkpoint_ignore_region_t current_region = NULL;
1622 while(start <= end){
1623 cursor = (start + end) / 2;
1624 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1625 if(current_region->addr == addr){
1626 if(current_region->size == size){
1627 checkpoint_ignore_region_free(region);
1631 }else if(current_region->size < size){
1636 }else if(current_region->addr < addr){
1643 if(current_region->addr == addr){
1644 if(current_region->size < size){
1645 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1647 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1649 }else if(current_region->addr < addr){
1650 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1652 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1660 /******************************* Initialisation of MC *******************************/
1661 /*********************************************************************************/
1663 static void MC_dump_ignored_local_variables(void){
1665 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1668 unsigned int cursor = 0;
1669 mc_stack_ignore_variable_t current_var;
1671 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1672 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1675 xbt_dynar_free(&mc_stack_comparison_ignore);
1676 mc_stack_comparison_ignore = NULL;
1680 static void MC_dump_ignored_global_variables(void){
1682 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1685 unsigned int cursor = 0;
1686 mc_data_bss_ignore_variable_t current_var;
1688 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1689 MC_ignore_global_variable(current_var->name);
1692 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1693 mc_data_bss_comparison_ignore = NULL;
1699 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1703 /* Initialize the data structures that must be persistent across every
1704 iteration of the model-checker (in RAW memory) */
1708 MC_init_memory_map_info();
1710 mc_local_variables_libsimgrid = xbt_dict_new_homogeneous(NULL);
1711 mc_local_variables_binary = xbt_dict_new_homogeneous(NULL);
1712 mc_global_variables_libsimgrid = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
1713 mc_global_variables_binary = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
1714 mc_variables_type_libsimgrid = xbt_dict_new_homogeneous(NULL);
1715 mc_variables_type_binary = xbt_dict_new_homogeneous(NULL);
1717 XBT_INFO("Get debug information ...");
1719 /* Get local variables in binary for state equality detection */
1720 xbt_dict_t binary_location_list = MC_dwarf_get_location_list(xbt_binary_name);
1721 MC_dwarf_get_variables(xbt_binary_name, binary_location_list, &mc_local_variables_binary, &mc_global_variables_binary, &mc_variables_type_binary);
1723 /* Get local variables in libsimgrid for state equality detection */
1724 xbt_dict_t libsimgrid_location_list = MC_dwarf_get_location_list(libsimgrid_path);
1725 MC_dwarf_get_variables(libsimgrid_path, libsimgrid_location_list, &mc_local_variables_libsimgrid, &mc_global_variables_libsimgrid, &mc_variables_type_libsimgrid);
1727 xbt_dict_free(&libsimgrid_location_list);
1728 xbt_dict_free(&binary_location_list);
1730 XBT_INFO("Get debug information done !");
1732 /* Remove variables ignored before getting list of variables */
1733 MC_dump_ignored_local_variables();
1734 MC_dump_ignored_global_variables();
1736 /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
1737 MC_get_libsimgrid_plt_section();
1738 MC_get_binary_plt_section();
1741 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1745 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1746 MC_ignore_local_variable("e", "*");
1747 MC_ignore_local_variable("__ex_cleanup", "*");
1748 MC_ignore_local_variable("__ex_mctx_en", "*");
1749 MC_ignore_local_variable("__ex_mctx_me", "*");
1750 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1751 MC_ignore_local_variable("_log_ev", "*");
1752 MC_ignore_local_variable("_throw_ctx", "*");
1753 MC_ignore_local_variable("ctx", "*");
1755 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1756 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1758 /* Ignore local variable about time used for tracing */
1759 MC_ignore_local_variable("start_time", "*");
1761 MC_ignore_global_variable("mc_comp_times");
1762 MC_ignore_global_variable("mc_snapshot_comparison_time");
1763 MC_ignore_global_variable("mc_time");
1764 MC_ignore_global_variable("smpi_current_rank");
1765 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1766 MC_ignore_global_variable("maestro_stack_start");
1767 MC_ignore_global_variable("maestro_stack_end");
1769 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1770 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1771 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1772 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1774 smx_process_t process;
1775 xbt_swag_foreach(process, simix_global->process_list){
1776 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1784 static void MC_init_dot_output(){ /* FIXME : more colors */
1788 colors[2] = "green3";
1789 colors[3] = "goldenrod";
1790 colors[4] = "brown";
1791 colors[5] = "purple";
1792 colors[6] = "magenta";
1793 colors[7] = "turquoise4";
1794 colors[8] = "gray25";
1795 colors[9] = "forestgreen";
1796 colors[10] = "hotpink";
1797 colors[11] = "lightblue";
1800 dot_output = fopen(_sg_mc_dot_output_file, "w");
1802 if(dot_output == NULL){
1803 perror("Error open dot output file");
1807 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");
1811 /******************************* Core of MC *******************************/
1812 /**************************************************************************/
1814 void MC_do_the_modelcheck_for_real() {
1817 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1820 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1821 if (mc_reduce_kind==e_mc_reduce_unset)
1822 mc_reduce_kind=e_mc_reduce_dpor;
1824 XBT_INFO("Check a safety property");
1825 MC_modelcheck_safety();
1829 if (mc_reduce_kind==e_mc_reduce_unset)
1830 mc_reduce_kind=e_mc_reduce_none;
1832 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1833 MC_automaton_load(_sg_mc_property_file);
1834 MC_modelcheck_liveness();
1838 void MC_modelcheck_safety(void)
1840 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1842 /* Check if MC is already initialized */
1843 if (initial_state_safety)
1846 mc_time = xbt_new0(double, simix_process_maxpid);
1848 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1849 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1851 /* Initialize the data structures that must be persistent across every
1852 iteration of the model-checker (in RAW memory) */
1856 /* Initialize statistics */
1857 mc_stats = xbt_new0(s_mc_stats_t, 1);
1858 mc_stats->state_size = 1;
1860 /* Create exploration stack */
1861 mc_stack_safety = xbt_fifo_new();
1863 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1864 MC_init_dot_output();
1868 if(_sg_mc_visited > 0){
1872 MC_init_memory_map_info();
1873 MC_get_libsimgrid_plt_section();
1874 MC_get_binary_plt_section();
1881 /* Save the initial state */
1882 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1883 initial_state_safety->snapshot = MC_take_snapshot(0);
1895 void MC_modelcheck_liveness(){
1897 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1901 mc_time = xbt_new0(double, simix_process_maxpid);
1903 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1904 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1908 /* Initialize statistics */
1909 mc_stats = xbt_new0(s_mc_stats_t, 1);
1910 mc_stats->state_size = 1;
1912 /* Create exploration stack */
1913 mc_stack_liveness = xbt_fifo_new();
1915 /* Create the initial state */
1916 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1918 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1919 MC_init_dot_output();
1926 MC_print_statistics(mc_stats);
1942 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1944 return simcall->mc_value;
1948 int MC_random(int min, int max)
1950 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1951 return simcall_mc_random(min, max);
1955 * \brief Schedules all the process that are ready to run
1957 void MC_wait_for_requests(void)
1959 smx_process_t process;
1963 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
1964 SIMIX_process_runall();
1965 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
1966 req = &process->simcall;
1967 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
1968 SIMIX_simcall_pre(req, 0);
1973 int MC_deadlock_check()
1975 int deadlock = FALSE;
1976 smx_process_t process;
1977 if(xbt_swag_size(simix_global->process_list)){
1979 xbt_swag_foreach(process, simix_global->process_list){
1980 if(process->simcall.call != SIMCALL_NONE
1981 && MC_request_is_enabled(&process->simcall)){
1991 * \brief Re-executes from the state at position start all the transitions indicated by
1992 * a given model-checker stack.
1993 * \param stack The stack with the transitions to execute.
1994 * \param start Start index to begin the re-execution.
1996 void MC_replay(xbt_fifo_t stack, int start)
1998 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2000 int value, i = 1, count = 1;
2002 smx_simcall_t req = NULL, saved_req = NULL;
2003 xbt_fifo_item_t item, start_item;
2005 smx_process_t process = NULL;
2007 XBT_DEBUG("**** Begin Replay ****");
2010 /* Restore the initial state */
2011 MC_restore_snapshot(initial_state_safety->snapshot);
2012 /* At the moment of taking the snapshot the raw heap was set, so restoring
2013 * it will set it back again, we have to unset it to continue */
2017 start_item = xbt_fifo_get_last_item(stack);
2020 start_item = xbt_fifo_get_prev_item(start_item);
2026 xbt_dict_reset(first_enabled_state);
2027 xbt_swag_foreach(process, simix_global->process_list){
2028 if(MC_process_is_enabled(process)){
2029 char *key = bprintf("%lu", process->pid);
2030 char *data = bprintf("%d", count);
2031 xbt_dict_set(first_enabled_state, key, data, NULL);
2038 /* Traverse the stack from the state at position start and re-execute the transitions */
2039 for (item = start_item;
2040 item != xbt_fifo_get_first_item(stack);
2041 item = xbt_fifo_get_prev_item(item)) {
2043 state = (mc_state_t) xbt_fifo_get_item_content(item);
2044 saved_req = MC_state_get_executed_request(state, &value);
2047 char *key = bprintf("%lu", saved_req->issuer->pid);
2048 xbt_dict_remove(first_enabled_state, key);
2053 /* because we got a copy of the executed request, we have to fetch the
2054 real one, pointed by the request field of the issuer process */
2055 req = &saved_req->issuer->simcall;
2057 /* Debug information */
2058 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2059 req_str = MC_request_to_string(req, value);
2060 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2065 SIMIX_simcall_pre(req, value);
2066 MC_wait_for_requests();
2071 /* Insert in dict all enabled processes */
2072 xbt_swag_foreach(process, simix_global->process_list){
2073 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2074 char *key = bprintf("%lu", process->pid);
2075 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2076 char *data = bprintf("%d", count);
2077 xbt_dict_set(first_enabled_state, key, data, NULL);
2084 /* Update statistics */
2085 mc_stats->visited_states++;
2086 mc_stats->executed_transitions++;
2090 XBT_DEBUG("**** End Replay ****");
2100 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2103 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2107 smx_simcall_t req = NULL, saved_req = NULL;
2108 xbt_fifo_item_t item;
2113 XBT_DEBUG("**** Begin Replay ****");
2115 /* Restore the initial state */
2116 MC_restore_snapshot(initial_state_liveness->snapshot);
2118 /* At the moment of taking the snapshot the raw heap was set, so restoring
2119 * it will set it back again, we have to unset it to continue */
2120 if(!initial_state_liveness->raw_mem_set)
2125 item = xbt_fifo_get_last_item(stack);
2127 while(depth <= xbt_fifo_size(stack)){
2129 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2130 state = (mc_state_t) pair->graph_state;
2132 if(pair->requests > 0){
2134 saved_req = MC_state_get_executed_request(state, &value);
2135 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2137 if(saved_req != NULL){
2138 /* because we got a copy of the executed request, we have to fetch the
2139 real one, pointed by the request field of the issuer process */
2140 req = &saved_req->issuer->simcall;
2141 //XBT_DEBUG("Req->call %u", req->call);
2143 /* Debug information */
2144 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2145 req_str = MC_request_to_string(req, value);
2146 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2152 SIMIX_simcall_pre(req, value);
2153 MC_wait_for_requests();
2158 /* Update statistics */
2159 mc_stats->visited_pairs++;
2160 mc_stats->executed_transitions++;
2162 item = xbt_fifo_get_prev_item(item);
2167 /* Traverse the stack from the initial state and re-execute the transitions */
2168 for (item = xbt_fifo_get_last_item(stack);
2169 item != xbt_fifo_get_first_item(stack);
2170 item = xbt_fifo_get_prev_item(item)) {
2172 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2173 state = (mc_state_t) pair->graph_state;
2175 if(pair->requests > 0){
2177 saved_req = MC_state_get_executed_request(state, &value);
2178 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2180 if(saved_req != NULL){
2181 /* because we got a copy of the executed request, we have to fetch the
2182 real one, pointed by the request field of the issuer process */
2183 req = &saved_req->issuer->simcall;
2184 //XBT_DEBUG("Req->call %u", req->call);
2186 /* Debug information */
2187 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2188 req_str = MC_request_to_string(req, value);
2189 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2195 SIMIX_simcall_pre(req, value);
2196 MC_wait_for_requests();
2201 /* Update statistics */
2202 mc_stats->visited_pairs++;
2203 mc_stats->executed_transitions++;
2207 XBT_DEBUG("**** End Replay ****");
2209 if(initial_state_liveness->raw_mem_set)
2217 * \brief Dumps the contents of a model-checker's stack and shows the actual
2219 * \param stack The stack to dump
2221 void MC_dump_stack_safety(xbt_fifo_t stack)
2224 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2226 MC_show_stack_safety(stack);
2228 if(!_sg_mc_checkpoint){
2233 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2234 MC_state_delete(state);
2247 void MC_show_stack_safety(xbt_fifo_t stack)
2250 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2256 xbt_fifo_item_t item;
2258 char *req_str = NULL;
2260 for (item = xbt_fifo_get_last_item(stack);
2261 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2262 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2263 req = MC_state_get_executed_request(state, &value);
2265 req_str = MC_request_to_string(req, value);
2266 XBT_INFO("%s", req_str);
2275 void MC_show_deadlock(smx_simcall_t req)
2277 /*char *req_str = NULL;*/
2278 XBT_INFO("**************************");
2279 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2280 XBT_INFO("**************************");
2281 XBT_INFO("Locked request:");
2282 /*req_str = MC_request_to_string(req);
2283 XBT_INFO("%s", req_str);
2284 xbt_free(req_str);*/
2285 XBT_INFO("Counter-example execution trace:");
2286 MC_dump_stack_safety(mc_stack_safety);
2287 MC_print_statistics(mc_stats);
2291 void MC_show_stack_liveness(xbt_fifo_t stack){
2294 xbt_fifo_item_t item;
2296 char *req_str = NULL;
2298 for (item = xbt_fifo_get_last_item(stack);
2299 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2300 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2301 req = MC_state_get_executed_request(pair->graph_state, &value);
2303 if(pair->requests>0){
2304 req_str = MC_request_to_string(req, value);
2305 XBT_INFO("%s", req_str);
2308 XBT_INFO("End of system requests but evolution in Büchi automaton");
2314 void MC_dump_stack_liveness(xbt_fifo_t stack){
2316 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2321 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2322 MC_pair_delete(pair);
2331 void MC_print_statistics(mc_stats_t stats)
2333 if(stats->expanded_pairs == 0){
2334 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2335 XBT_INFO("Visited states = %lu", stats->visited_states);
2337 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2338 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2340 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2342 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2343 fprintf(dot_output, "}\n");
2349 void MC_assert(int prop)
2351 if (MC_is_active() && !prop){
2352 XBT_INFO("**************************");
2353 XBT_INFO("*** PROPERTY NOT VALID ***");
2354 XBT_INFO("**************************");
2355 XBT_INFO("Counter-example execution trace:");
2356 MC_dump_stack_safety(mc_stack_safety);
2357 MC_print_statistics(mc_stats);
2363 user_max_depth_reached = 1;
2366 void MC_process_clock_add(smx_process_t process, double amount)
2368 mc_time[process->pid] += amount;
2371 double MC_process_clock_get(smx_process_t process)
2375 return mc_time[process->pid];
2383 void MC_automaton_load(const char *file){
2385 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2389 if (_mc_property_automaton == NULL)
2390 _mc_property_automaton = xbt_automaton_new();
2392 xbt_automaton_load(_mc_property_automaton,file);
2401 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2403 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2407 if (_mc_property_automaton == NULL)
2408 _mc_property_automaton = xbt_automaton_new();
2410 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);