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. */
13 #include "simgrid/sg_config.h"
14 #include "../surf/surf_private.h"
15 #include "../simix/smx_private.h"
16 #include "../xbt/mmalloc/mmprivate.h"
18 #include "mc_private.h"
19 #include "xbt/automaton.h"
22 XBT_LOG_NEW_CATEGORY(mc, "All MC categories");
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
24 "Logging specific to MC (global)");
26 /* Configuration support */
27 e_mc_reduce_t mc_reduce_kind=e_mc_reduce_unset;
29 int _sg_do_model_check = 0;
30 int _sg_mc_checkpoint=0;
31 char* _sg_mc_property_file=NULL;
33 int _sg_mc_max_depth=1000;
35 char *_sg_mc_dot_output_file = NULL;
37 int user_max_depth_reached = 0;
39 void _mc_cfg_cb_reduce(const char *name, int pos) {
40 if (_sg_cfg_init_status && !_sg_do_model_check) {
41 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.");
43 char *val= xbt_cfg_get_string(_sg_cfg_set, name);
44 if (!strcasecmp(val,"none")) {
45 mc_reduce_kind = e_mc_reduce_none;
46 } else if (!strcasecmp(val,"dpor")) {
47 mc_reduce_kind = e_mc_reduce_dpor;
49 xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",name);
53 void _mc_cfg_cb_checkpoint(const char *name, int pos) {
54 if (_sg_cfg_init_status && !_sg_do_model_check) {
55 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.");
57 _sg_mc_checkpoint = xbt_cfg_get_int(_sg_cfg_set, name);
59 void _mc_cfg_cb_property(const char *name, int pos) {
60 if (_sg_cfg_init_status && !_sg_do_model_check) {
61 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.");
63 _sg_mc_property_file= xbt_cfg_get_string(_sg_cfg_set, name);
66 void _mc_cfg_cb_timeout(const char *name, int pos) {
67 if (_sg_cfg_init_status && !_sg_do_model_check) {
68 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.");
70 _sg_mc_timeout= xbt_cfg_get_boolean(_sg_cfg_set, name);
73 void _mc_cfg_cb_max_depth(const char *name, int pos) {
74 if (_sg_cfg_init_status && !_sg_do_model_check) {
75 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.");
77 _sg_mc_max_depth= xbt_cfg_get_int(_sg_cfg_set, name);
80 void _mc_cfg_cb_visited(const char *name, int pos) {
81 if (_sg_cfg_init_status && !_sg_do_model_check) {
82 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.");
84 _sg_mc_visited= xbt_cfg_get_int(_sg_cfg_set, name);
87 void _mc_cfg_cb_dot_output(const char *name, int pos) {
88 if (_sg_cfg_init_status && !_sg_do_model_check) {
89 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.");
91 _sg_mc_dot_output_file= xbt_cfg_get_string(_sg_cfg_set, name);
94 /* MC global data structures */
95 mc_state_t mc_current_state = NULL;
96 char mc_replay_mode = FALSE;
97 double *mc_time = NULL;
98 __thread mc_comparison_times_t mc_comp_times = NULL;
99 __thread double mc_snapshot_comparison_time;
100 mc_stats_t mc_stats = NULL;
103 xbt_fifo_t mc_stack_safety = NULL;
104 mc_global_t initial_state_safety = NULL;
107 xbt_fifo_t mc_stack_liveness = NULL;
108 mc_global_t initial_state_liveness = NULL;
111 xbt_automaton_t _mc_property_automaton = NULL;
114 mc_object_info_t mc_libsimgrid_info = NULL;
115 mc_object_info_t mc_binary_info = NULL;
117 /* Ignore mechanism */
118 xbt_dynar_t mc_stack_comparison_ignore;
119 xbt_dynar_t mc_data_bss_comparison_ignore;
120 extern xbt_dynar_t mc_heap_comparison_ignore;
121 extern xbt_dynar_t stacks_areas;
124 FILE *dot_output = NULL;
125 const char* colors[13];
128 /******************************* DWARF Information *******************************/
129 /**********************************************************************************/
131 /************************** Free functions *************************/
133 static void dw_location_free(dw_location_t l){
135 if(l->type == e_dw_loclist)
136 xbt_dynar_free(&(l->location.loclist));
137 else if(l->type == e_dw_compose)
138 xbt_dynar_free(&(l->location.compose));
139 else if(l->type == e_dw_arithmetic)
140 xbt_free(l->location.arithmetic);
146 static void dw_location_entry_free(dw_location_entry_t e){
147 dw_location_free(e->location);
151 static void dw_type_free(dw_type_t t){
153 xbt_free(t->dw_type_id);
154 xbt_dynar_free(&(t->members));
158 static void dw_type_free_voidp(void *t){
159 dw_type_free((dw_type_t) * (void **) t);
162 static void dw_variable_free(dw_variable_t v){
165 xbt_free(v->type_origin);
167 dw_location_free(v->address.location);
172 static void dw_variable_free_voidp(void *t){
173 dw_variable_free((dw_variable_t) * (void **) t);
178 mc_object_info_t MC_new_object_info() {
179 mc_object_info_t res = xbt_new(s_mc_object_info_t, 1);
180 res->file_name = NULL;
181 res->start_text = NULL;
182 res->start_data = NULL;
183 res->start_bss = NULL;
184 res->start_plt = NULL;
186 res->start_got_plt = NULL;
187 res->end_got_plt = NULL;
188 res->local_variables = xbt_dict_new_homogeneous(NULL);
189 res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
190 res->types = xbt_dict_new_homogeneous(NULL);
194 void MC_free_object_info(mc_object_info_t* info) {
195 xbt_free(&(*info)->file_name);
196 xbt_dict_free(&(*info)->local_variables);
197 xbt_dynar_free(&(*info)->global_variables);
198 xbt_dict_free(&(*info)->types);
203 /*************************************************************************/
205 static dw_location_t MC_dwarf_get_location(xbt_dict_t location_list, char *expr){
207 dw_location_t loc = xbt_new0(s_dw_location_t, 1);
209 if(location_list != NULL){
211 char *key = bprintf("%d", (int)strtoul(expr, NULL, 16));
212 loc->type = e_dw_loclist;
213 loc->location.loclist = (xbt_dynar_t)xbt_dict_get_or_null(location_list, key);
214 if(loc->location.loclist == NULL)
215 XBT_INFO("Key not found in loclist");
222 char *tok = NULL, *tok2 = NULL;
224 xbt_dynar_t tokens1 = xbt_str_split(expr, ";");
227 loc->type = e_dw_compose;
228 loc->location.compose = xbt_dynar_new(sizeof(dw_location_t), NULL);
230 while(cursor < xbt_dynar_length(tokens1)){
232 tok = xbt_dynar_get_as(tokens1, cursor, char*);
233 tokens2 = xbt_str_split(tok, " ");
234 tok2 = xbt_dynar_get_as(tokens2, 0, char*);
236 if(strncmp(tok2, "DW_OP_reg", 9) == 0){
237 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
238 new_element->type = e_dw_register;
239 new_element->location.reg = atoi(strtok(tok2, "DW_OP_reg"));
240 xbt_dynar_push(loc->location.compose, &new_element);
241 }else if(strcmp(tok2, "DW_OP_fbreg:") == 0){
242 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
243 new_element->type = e_dw_fbregister_op;
244 new_element->location.fbreg_op = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
245 xbt_dynar_push(loc->location.compose, &new_element);
246 }else if(strncmp(tok2, "DW_OP_breg", 10) == 0){
247 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
248 new_element->type = e_dw_bregister_op;
249 new_element->location.breg_op.reg = atoi(strtok(tok2, "DW_OP_breg"));
250 new_element->location.breg_op.offset = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
251 xbt_dynar_push(loc->location.compose, &new_element);
252 }else if(strncmp(tok2, "DW_OP_lit", 9) == 0){
253 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
254 new_element->type = e_dw_lit;
255 new_element->location.lit = atoi(strtok(tok2, "DW_OP_lit"));
256 xbt_dynar_push(loc->location.compose, &new_element);
257 }else if(strcmp(tok2, "DW_OP_piece:") == 0){
258 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
259 new_element->type = e_dw_piece;
260 new_element->location.piece = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
261 xbt_dynar_push(loc->location.compose, &new_element);
262 }else if(strcmp(tok2, "DW_OP_plus_uconst:") == 0){
263 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
264 new_element->type = e_dw_plus_uconst;
265 new_element->location.plus_uconst = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char *));
266 xbt_dynar_push(loc->location.compose, &new_element);
267 }else if(strcmp(tok, "DW_OP_abs") == 0 ||
268 strcmp(tok, "DW_OP_and") == 0 ||
269 strcmp(tok, "DW_OP_div") == 0 ||
270 strcmp(tok, "DW_OP_minus") == 0 ||
271 strcmp(tok, "DW_OP_mod") == 0 ||
272 strcmp(tok, "DW_OP_mul") == 0 ||
273 strcmp(tok, "DW_OP_neg") == 0 ||
274 strcmp(tok, "DW_OP_not") == 0 ||
275 strcmp(tok, "DW_OP_or") == 0 ||
276 strcmp(tok, "DW_OP_plus") == 0){
277 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
278 new_element->type = e_dw_arithmetic;
279 new_element->location.arithmetic = strdup(strtok(tok2, "DW_OP_"));
280 xbt_dynar_push(loc->location.compose, &new_element);
281 }else if(strcmp(tok, "DW_OP_stack_value") == 0){
282 }else if(strcmp(tok2, "DW_OP_deref_size:") == 0){
283 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
284 new_element->type = e_dw_deref;
285 new_element->location.deref_size = (unsigned int short) atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
286 xbt_dynar_push(loc->location.compose, &new_element);
287 }else if(strcmp(tok, "DW_OP_deref") == 0){
288 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
289 new_element->type = e_dw_deref;
290 new_element->location.deref_size = sizeof(void *);
291 xbt_dynar_push(loc->location.compose, &new_element);
292 }else if(strcmp(tok2, "DW_OP_constu:") == 0){
293 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
294 new_element->type = e_dw_uconstant;
295 new_element->location.uconstant.bytes = 1;
296 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
297 xbt_dynar_push(loc->location.compose, &new_element);
298 }else if(strcmp(tok2, "DW_OP_consts:") == 0){
299 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
300 new_element->type = e_dw_sconstant;
301 new_element->location.sconstant.bytes = 1;
302 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
303 xbt_dynar_push(loc->location.compose, &new_element);
304 }else if(strcmp(tok2, "DW_OP_const1u:") == 0 ||
305 strcmp(tok2, "DW_OP_const2u:") == 0 ||
306 strcmp(tok2, "DW_OP_const4u:") == 0 ||
307 strcmp(tok2, "DW_OP_const8u:") == 0){
308 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
309 new_element->type = e_dw_uconstant;
310 new_element->location.uconstant.bytes = tok2[11] - '0';
311 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
312 xbt_dynar_push(loc->location.compose, &new_element);
313 }else if(strcmp(tok, "DW_OP_const1s") == 0 ||
314 strcmp(tok, "DW_OP_const2s") == 0 ||
315 strcmp(tok, "DW_OP_const4s") == 0 ||
316 strcmp(tok, "DW_OP_const8s") == 0){
317 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
318 new_element->type = e_dw_sconstant;
319 new_element->location.sconstant.bytes = tok2[11] - '0';
320 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
321 xbt_dynar_push(loc->location.compose, &new_element);
323 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
324 new_element->type = e_dw_unsupported;
325 xbt_dynar_push(loc->location.compose, &new_element);
329 xbt_dynar_free(&tokens2);
333 xbt_dynar_free(&tokens1);
341 /** @brief Extract the location lists from an ELF file (.debug_loc)
343 * @return A map from the offset in the list (in hexadecimal string)
344 * into a location list (dynar of dw_location_entry_t).
346 static xbt_dict_t MC_dwarf_get_location_list(const char *elf_file){
348 char *command = bprintf("LANG=C objdump -Wo %s", elf_file);
350 FILE *fp = popen(command, "r");
353 perror("popen for objdump failed");
357 int debug = 0; /*Detect if the program has been compiled with -g */
359 xbt_dict_t location_list = xbt_dict_new_homogeneous(NULL);
360 char *line = NULL, *loc_expr = NULL;
364 xbt_dynar_t split = NULL;
366 while ((read = xbt_getline(&line, &n, fp)) != -1) {
368 /* Wipeout the new line character */
369 line[read - 1] = '\0';
371 xbt_str_trim(line, NULL);
376 if(strlen(line) == 0)
381 if(strncmp(line, elf_file, strlen(elf_file)) == 0)
384 if(strncmp(line, "Contents", 8) == 0)
387 if(strncmp(line, "Offset", 6) == 0){
394 XBT_INFO("Your program must be compiled with -g");
398 xbt_dynar_t loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
400 xbt_str_strip_spaces(line);
401 split = xbt_str_split(line, " ");
404 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
406 // Take the key from the first line of the list:
408 key = bprintf("%d", (int)strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
411 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
412 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
413 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
416 while(cursor_remove < 3){
417 xbt_dynar_remove_at(split, 0, NULL);
421 loc_expr = xbt_str_join(split, " ");
422 xbt_str_ltrim(loc_expr, "(");
423 xbt_str_rtrim(loc_expr, ")");
424 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
426 xbt_dynar_push(loclist, &new_entry);
428 xbt_dynar_free(&split);
431 read = xbt_getline(&line, &n, fp);
433 line[read - 1] = '\0';
434 xbt_str_strip_spaces(line);
435 split = xbt_str_split(line, " ");
441 xbt_dict_set(location_list, key, loclist, NULL);
444 xbt_dynar_free(&split);
452 return location_list;
455 /** \brief Finds a frame (DW_TAG_subprogram) from an DWARF offset in the rangd of this subprogram
457 * The offset can be an offset of a child DW_TAG_variable.
459 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
461 xbt_dict_cursor_t cursor = NULL;
465 xbt_dict_foreach(all_variables, cursor, name, res) {
466 if(offset >= res->start && offset < res->end){
467 xbt_dict_cursor_free(&cursor);
472 xbt_dict_cursor_free(&cursor);
477 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
479 unsigned int cursor = 0;
480 dw_variable_t current_var;
482 xbt_dynar_foreach(frame->variables, cursor, current_var){
483 if(strcmp(var, current_var->name) == 0)
490 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
492 if(xbt_dynar_is_empty(variables))
495 unsigned int cursor = 0;
497 int end = xbt_dynar_length(variables) - 1;
498 dw_variable_t var_test = NULL;
501 cursor = (start + end) / 2;
502 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
503 if(strcmp(var_test->name, var) < 0){
505 }else if(strcmp(var_test->name, var) > 0){
508 if(address){ /* global variable */
509 if(var_test->address.address == address)
511 if(var_test->address.address > address)
515 }else{ /* local variable */
521 if(strcmp(var_test->name, var) == 0){
522 if(address && var_test->address.address < address)
526 }else if(strcmp(var_test->name, var) < 0)
533 /** \brief Fill DWARf debug infomations (types, frames, variables ...). */
534 void MC_dwarf_get_variables(mc_object_info_t info) {
535 mc_object_info_t result = info;
536 const char *elf_file = info->file_name;
538 xbt_dict_t location_list = MC_dwarf_get_location_list(elf_file);
540 char *command = bprintf("LANG=C objdump -Wi %s", elf_file);
542 FILE *fp = popen(command, "r");
545 perror("popen for objdump failed");
547 xbt_dict_t *local_variables = &result->local_variables;
548 xbt_dynar_t *global_variables = &result->global_variables;
549 xbt_dict_t *types = &result->types;
551 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
552 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
553 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
554 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
555 *parent_value = NULL;
559 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
560 is_pointer = 0, struct_decl = 0, member_end = 0,
561 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
563 xbt_dynar_t split = NULL, split2 = NULL;
565 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
566 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
568 dw_frame_t variable_frame, subroutine_frame = NULL;
570 e_dw_type_type type_type = -1;
572 read = xbt_getline(&line, &n, fp);
576 /* Wipeout the new line character */
577 line[read - 1] = '\0';
579 if(n == 0 || strlen(line) == 0){
580 read = xbt_getline(&line, &n, fp);
584 xbt_str_ltrim(line, NULL);
585 xbt_str_strip_spaces(line);
588 read = xbt_getline(&line, &n, fp);
592 xbt_dynar_free(&split);
593 split = xbt_str_split(line, " ");
596 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
598 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
599 /* We build/complete a dw_frame_t object
600 * and append it if necessary to the local_variables dictionnary */
602 dw_frame_t frame = NULL;
604 strtok(xbt_dynar_get_as(split, 0, char *), "<");
605 subprogram_start = xbt_strdup(strtok(NULL, "<"));
606 xbt_str_rtrim(subprogram_start, ">:");
608 read = xbt_getline(&line, &n, fp);
612 /* Wipeout the new line character */
613 line[read - 1] = '\0';
615 if(n == 0 || strlen(line) == 0){
616 read = xbt_getline(&line, &n, fp);
620 xbt_dynar_free(&split);
621 xbt_str_rtrim(line, NULL);
622 xbt_str_strip_spaces(line);
623 split = xbt_str_split(line, " ");
625 node_type = xbt_dynar_get_as(split, 1, char *);
627 if(strncmp(node_type, "DW_AT_", 6) != 0)
630 if(strcmp(node_type, "DW_AT_sibling") == 0){
632 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
633 xbt_str_ltrim(subprogram_end, "<0x");
634 xbt_str_rtrim(subprogram_end, ">");
636 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
639 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
640 xbt_str_ltrim(abstract_origin, "<0x");
641 xbt_str_rtrim(abstract_origin, ">");
642 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
643 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
644 xbt_free(abstract_origin);
646 }else if(strcmp(node_type, "DW_AT_name") == 0){
649 xbt_free(current_frame);
650 frame = xbt_new0(s_dw_frame_t, 1);
651 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
652 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
653 frame->frame_base = xbt_new0(s_dw_location_t, 1);
654 current_frame = strdup(frame->name);
656 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
658 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
660 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
662 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
664 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
668 xbt_str_strip_spaces(line);
669 split2 = xbt_str_split(line, "(");
670 xbt_dynar_remove_at(split2, 0, NULL);
671 loc_expr = xbt_str_join(split2, " ");
672 xbt_str_rtrim(loc_expr, ")");
673 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
674 xbt_dynar_free(&split2);
679 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
682 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
684 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
687 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
689 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
691 xbt_free(frame->name);
692 xbt_free(current_frame);
693 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
694 current_frame = strdup(frame->name);
695 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
699 read = xbt_getline(&line, &n, fp);
704 frame->start = strtoul(subprogram_start, NULL, 16);
705 if(subprogram_end != NULL)
706 frame->end = strtoul(subprogram_end, NULL, 16);
707 xbt_dict_set(*local_variables, frame->name, frame, NULL);
710 xbt_free(subprogram_start);
711 xbt_free(subprogram_end);
712 subprogram_end = NULL;
715 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
716 /* We build a dw_variable_t object and append it either to
717 the list of variables of the frame (local variable)
718 or to the list of global variables (global variables). */
720 dw_variable_t var = NULL;
722 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
723 parent_value = strtok(parent_value,"<");
724 xbt_str_rtrim(parent_value, ">");
725 parent = atoi(parent_value);
726 xbt_free(parent_value);
731 strtok(xbt_dynar_get_as(split, 0, char *), "<");
732 origin = xbt_strdup(strtok(NULL, "<"));
733 xbt_str_rtrim(origin, ">:");
735 read = xbt_getline(&line, &n, fp);
739 /* Wipeout the new line character */
740 line[read - 1] = '\0';
742 if(n == 0 || strlen(line) == 0){
743 read = xbt_getline(&line, &n, fp);
747 xbt_dynar_free(&split);
748 xbt_str_rtrim(line, NULL);
749 xbt_str_strip_spaces(line);
750 split = xbt_str_split(line, " ");
752 node_type = xbt_dynar_get_as(split, 1, char *);
754 if(strncmp(node_type, "DW_AT_", 6) != 0)
757 if(strcmp(node_type, "DW_AT_name") == 0){
759 var = xbt_new0(s_dw_variable_t, 1);
760 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
761 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
763 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
767 abstract_origin = xbt_dynar_get_as(split, 2, char *);
768 xbt_str_ltrim(abstract_origin, "<0x");
769 xbt_str_rtrim(abstract_origin, ">");
771 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
772 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
773 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
775 }else if(strcmp(node_type, "DW_AT_location") == 0){
779 if(!global_variable){
781 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
783 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
784 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
786 xbt_str_strip_spaces(line);
787 split2 = xbt_str_split(line, "(");
788 xbt_dynar_remove_at(split2, 0, NULL);
789 loc_expr = xbt_str_join(split2, " ");
790 xbt_str_rtrim(loc_expr, ")");
791 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
793 xbt_dynar_free(&split2);
794 split2 = xbt_str_split(loc_expr, " ");
795 if(strcmp(elf_file, xbt_binary_name) != 0)
796 var->address.address = (char *) info->start_text + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
798 // Why is it different ?
799 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
801 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
803 xbt_dynar_free(&split2);
807 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
808 xbt_str_rtrim(global_address, ")");
809 if(strcmp(elf_file, xbt_binary_name) != 0)
810 var->address.address = (char *) info->start_text + (long)((void *)strtoul(global_address, NULL, 16));
812 // Why is it different ?
813 var->address.address = (void *)strtoul(global_address, NULL, 16);
814 xbt_free(global_address);
815 global_address = NULL;
820 }else if(strcmp(node_type, "DW_AT_type") == 0){
822 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
823 xbt_str_ltrim(type_origin, "<0x");
824 xbt_str_rtrim(type_origin, ">");
826 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
830 dw_variable_free(var);
834 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
838 dw_variable_free(var);
844 read = xbt_getline(&line, &n, fp);
848 if(new_variable == 1){
850 if(!global_variable){
851 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
852 var->type_origin = strdup(type_origin);
854 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
856 xbt_dynar_insert_at(variable_frame->variables, index, &var);
858 var->type_origin = strdup(type_origin);
860 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
862 xbt_dynar_insert_at(*global_variables, index, &var);
865 xbt_free(type_origin);
872 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
873 /* Update the information on the frame (we should duplicate it instead). */
875 read = xbt_getline(&line, &n, fp);
879 /* Wipeout the new line character */
880 line[read - 1] = '\0';
882 if(n == 0 || strlen(line) == 0){
883 read = xbt_getline(&line, &n, fp);
887 xbt_dynar_free(&split);
888 xbt_str_rtrim(line, NULL);
889 xbt_str_strip_spaces(line);
890 split = xbt_str_split(line, " ");
892 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
895 node_type = xbt_dynar_get_as(split, 1, char *);
897 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
899 origin = xbt_dynar_get_as(split, 2, char *);
900 xbt_str_ltrim(origin, "<0x");
901 xbt_str_rtrim(origin, ">");
903 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
904 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
906 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
908 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
910 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
912 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
915 read = xbt_getline(&line, &n, fp);
919 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
920 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
921 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
922 || strcmp(node_type, "(DW_TAG_typedef)") == 0
923 || strcmp(node_type, "(DW_TAG_const_type)") == 0
924 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
925 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
926 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
928 /* Create the and add it to the types dictionnary */
930 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
931 type_type = e_dw_base_type;
932 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
933 type_type = e_dw_enumeration_type;
934 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
935 type_type = e_dw_enumerator;
936 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
937 type_type = e_dw_typedef;
938 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
939 type_type = e_dw_const_type;
940 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
941 type_type = e_dw_pointer_type;
942 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
943 type_type = e_dw_subroutine_type;
944 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
945 type_type = e_dw_volatile_type;
947 strtok(xbt_dynar_get_as(split, 0, char *), "<");
948 origin = strdup(strtok(NULL, "<"));
949 xbt_str_rtrim(origin, ">:");
951 read = xbt_getline(&line, &n, fp);
955 /* Wipeout the new line character */
956 line[read - 1] = '\0';
958 if(n == 0 || strlen(line) == 0){
959 read = xbt_getline(&line, &n, fp);
963 xbt_dynar_free(&split);
964 xbt_str_rtrim(line, NULL);
965 xbt_str_strip_spaces(line);
966 split = xbt_str_split(line, " ");
968 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
971 node_type = xbt_dynar_get_as(split, 1, char *);
973 if(strcmp(node_type, "DW_AT_byte_size") == 0){
974 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
975 if(type_type == e_dw_enumeration_type)
976 enumeration_size = size;
977 }else if(strcmp(node_type, "DW_AT_name") == 0){
978 end = xbt_str_join(split, " ");
979 xbt_dynar_free(&split);
980 split = xbt_str_split(end, "):");
981 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
982 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
983 }else if(strcmp(node_type, "DW_AT_type") == 0){
984 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
985 xbt_str_ltrim(type_origin, "<0x");
986 xbt_str_rtrim(type_origin, ">");
989 read = xbt_getline(&line, &n, fp);
992 dw_type_t type = xbt_new0(s_dw_type_t, 1);
993 type->type = type_type;
995 type->name = xbt_strdup(name);
997 type->name = xbt_strdup("undefined");
998 type->is_pointer_type = is_pointer;
999 type->id = (void *)strtoul(origin, NULL, 16);
1001 type->dw_type_id = xbt_strdup(type_origin);
1002 if(type_type == e_dw_enumerator)
1003 type->size = enumeration_size;
1006 type->members = NULL;
1008 xbt_dict_set(*types, origin, type, NULL);
1012 xbt_free(type_origin);
1021 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
1023 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
1028 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1029 origin = strdup(strtok(NULL, "<"));
1030 xbt_str_rtrim(origin, ">:");
1032 read = xbt_getline(&line, &n, fp);
1034 dw_type_t type = NULL;
1040 /* Wipeout the new line character */
1041 line[read - 1] = '\0';
1043 if(n == 0 || strlen(line) == 0){
1044 read = xbt_getline(&line, &n, fp);
1048 xbt_dynar_free(&split);
1049 xbt_str_rtrim(line, NULL);
1050 xbt_str_strip_spaces(line);
1051 split = xbt_str_split(line, " ");
1053 node_type = xbt_dynar_get_as(split, 1, char *);
1055 if(strncmp(node_type, "DW_AT_", 6) != 0){
1060 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1061 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1062 }else if(strcmp(node_type, "DW_AT_name") == 0){
1064 end = xbt_str_join(split, " ");
1065 xbt_dynar_free(&split);
1066 split = xbt_str_split(end, "):");
1067 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1068 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1069 }else if(strcmp(node_type, "DW_AT_type") == 0){
1070 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1071 xbt_str_ltrim(type_origin, "<0x");
1072 xbt_str_rtrim(type_origin, ">");
1073 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1075 end = xbt_str_join(split, " ");
1076 xbt_dynar_free(&split);
1077 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1078 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1079 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1080 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1083 read = xbt_getline(&line, &n, fp);
1087 if(member_end && type){
1090 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1091 member_type->name = xbt_strdup(name);
1092 member_type->size = size;
1093 member_type->is_pointer_type = is_pointer;
1094 member_type->id = (void *)strtoul(origin, NULL, 16);
1095 member_type->offset = offset;
1097 member_type->dw_type_id = xbt_strdup(type_origin);
1099 xbt_dynar_push(type->members, &member_type);
1105 xbt_free(type_origin);
1112 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1113 origin = strdup(strtok(NULL, "<"));
1114 xbt_str_rtrim(origin, ">:");
1118 if(struct_decl || union_decl){
1119 type = xbt_new0(s_dw_type_t, 1);
1121 type->type = e_dw_structure_type;
1123 type->type = e_dw_union_type;
1124 type->name = xbt_strdup(name);
1126 type->is_pointer_type = is_pointer;
1127 type->id = (void *)strtoul(origin, NULL, 16);
1129 type->dw_type_id = xbt_strdup(type_origin);
1130 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1132 xbt_dict_set(*types, origin, type, NULL);
1138 xbt_free(type_origin);
1146 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1149 read = xbt_getline(&line, &n, fp);
1156 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1158 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1159 origin = strdup(strtok(NULL, "<"));
1160 xbt_str_rtrim(origin, ">:");
1162 read = xbt_getline(&line, &n, fp);
1164 dw_type_t type = NULL;
1166 // Read DW_TAG_subrange_type children:
1169 // Read attributes of the DW_TAG_subrange_type:
1172 /* Wipeout the new line character */
1173 line[read - 1] = '\0';
1175 if(n == 0 || strlen(line) == 0){
1176 read = xbt_getline(&line, &n, fp);
1180 xbt_dynar_free(&split);
1181 xbt_str_rtrim(line, NULL);
1182 xbt_str_strip_spaces(line);
1183 split = xbt_str_split(line, " ");
1185 node_type = xbt_dynar_get_as(split, 1, char *);
1187 if(strncmp(node_type, "DW_AT_", 6) != 0)
1190 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1191 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1192 }else if(strcmp(node_type, "DW_AT_name") == 0){
1193 end = xbt_str_join(split, " ");
1194 xbt_dynar_free(&split);
1195 split = xbt_str_split(end, "):");
1196 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1197 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1198 }else if(strcmp(node_type, "DW_AT_type") == 0){
1199 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1200 xbt_str_ltrim(type_origin, "<0x");
1201 xbt_str_rtrim(type_origin, ">");
1204 read = xbt_getline(&line, &n, fp);
1208 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1212 if(subrange && type){
1219 xbt_free(type_origin);
1225 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1226 origin = strdup(strtok(NULL, "<"));
1227 xbt_str_rtrim(origin, ">:");
1231 type = xbt_new0(s_dw_type_t, 1);
1232 type->type = e_dw_array_type;
1233 type->name = xbt_strdup(name);
1234 type->is_pointer_type = is_pointer;
1235 type->id = (void *)strtoul(origin, NULL, 16);
1237 type->dw_type_id = xbt_strdup(type_origin);
1238 type->members = NULL;
1240 xbt_dict_set(*types, origin, type, NULL);
1246 xbt_free(type_origin);
1251 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1254 read = xbt_getline(&line, &n, fp);
1263 read = xbt_getline(&line, &n, fp);
1269 xbt_dynar_free(&split);
1270 xbt_dict_free(&variables_origin);
1271 xbt_dict_free(&subprograms_origin);
1274 xbt_dict_free(&location_list);
1280 /******************************* Ignore mechanism *******************************/
1281 /*********************************************************************************/
1283 xbt_dynar_t mc_checkpoint_ignore;
1285 typedef struct s_mc_stack_ignore_variable{
1288 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1290 typedef struct s_mc_data_bss_ignore_variable{
1292 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1294 /**************************** Free functions ******************************/
1296 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1297 xbt_free(v->var_name);
1302 static void stack_ignore_variable_free_voidp(void *v){
1303 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1306 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1310 void heap_ignore_region_free_voidp(void *r){
1311 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1314 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1319 static void data_bss_ignore_variable_free_voidp(void *v){
1320 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1323 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1327 static void checkpoint_ignore_region_free_voidp(void *r){
1328 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1331 /***********************************************************************/
1333 void MC_ignore_heap(void *address, size_t size){
1335 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1339 mc_heap_ignore_region_t region = NULL;
1340 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1341 region->address = address;
1342 region->size = size;
1344 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1346 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1347 region->fragment = -1;
1348 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1350 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1351 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1354 if(mc_heap_comparison_ignore == NULL){
1355 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1356 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1362 unsigned int cursor = 0;
1363 mc_heap_ignore_region_t current_region = NULL;
1365 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1367 while(start <= end){
1368 cursor = (start + end) / 2;
1369 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1370 if(current_region->address == address){
1371 heap_ignore_region_free(region);
1375 }else if(current_region->address < address){
1382 if(current_region->address < address)
1383 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1385 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1391 void MC_remove_ignore_heap(void *address, size_t size){
1393 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1397 unsigned int cursor = 0;
1399 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1400 mc_heap_ignore_region_t region;
1401 int ignore_found = 0;
1403 while(start <= end){
1404 cursor = (start + end) / 2;
1405 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1406 if(region->address == address){
1409 }else if(region->address < address){
1412 if((char * )region->address <= ((char *)address + size)){
1421 if(ignore_found == 1){
1422 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1423 MC_remove_ignore_heap(address, size);
1431 void MC_ignore_global_variable(const char *name){
1433 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1437 if(mc_libsimgrid_info){
1439 unsigned int cursor = 0;
1440 dw_variable_t current_var;
1442 int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1444 while(start <= end){
1445 cursor = (start + end) /2;
1446 current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
1447 if(strcmp(current_var->name, name) == 0){
1448 xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
1450 end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1451 }else if(strcmp(current_var->name, name) < 0){
1460 if(mc_data_bss_comparison_ignore == NULL)
1461 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1463 mc_data_bss_ignore_variable_t var = NULL;
1464 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1465 var->name = strdup(name);
1467 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1469 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1473 unsigned int cursor = 0;
1475 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1476 mc_data_bss_ignore_variable_t current_var = NULL;
1478 while(start <= end){
1479 cursor = (start + end) / 2;
1480 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1481 if(strcmp(current_var->name, name) == 0){
1482 data_bss_ignore_variable_free(var);
1486 }else if(strcmp(current_var->name, name) < 0){
1493 if(strcmp(current_var->name, name) < 0)
1494 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1496 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1505 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1507 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1511 if(mc_libsimgrid_info){
1512 unsigned int cursor = 0;
1513 dw_variable_t current_var;
1515 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1516 xbt_dict_cursor_t dict_cursor;
1517 char *current_frame_name;
1519 xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
1521 end = xbt_dynar_length(frame->variables) - 1;
1522 while(start <= end){
1523 cursor = (start + end) / 2;
1524 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1525 if(strcmp(current_var->name, var_name) == 0){
1526 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1528 end = xbt_dynar_length(frame->variables) - 1;
1529 }else if(strcmp(current_var->name, var_name) < 0){
1536 xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
1538 end = xbt_dynar_length(frame->variables) - 1;
1539 while(start <= end){
1540 cursor = (start + end) / 2;
1541 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1542 if(strcmp(current_var->name, var_name) == 0){
1543 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1545 end = xbt_dynar_length(frame->variables) - 1;
1546 }else if(strcmp(current_var->name, var_name) < 0){
1554 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
1555 mc_libsimgrid_info->local_variables, frame_name))->variables;
1557 end = xbt_dynar_length(variables_list) - 1;
1558 while(start <= end){
1559 cursor = (start + end) / 2;
1560 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1561 if(strcmp(current_var->name, var_name) == 0){
1562 xbt_dynar_remove_at(variables_list, cursor, NULL);
1564 end = xbt_dynar_length(variables_list) - 1;
1565 }else if(strcmp(current_var->name, var_name) < 0){
1574 if(mc_stack_comparison_ignore == NULL)
1575 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1577 mc_stack_ignore_variable_t var = NULL;
1578 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1579 var->var_name = strdup(var_name);
1580 var->frame = strdup(frame_name);
1582 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1584 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1588 unsigned int cursor = 0;
1590 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1591 mc_stack_ignore_variable_t current_var = NULL;
1593 while(start <= end){
1594 cursor = (start + end) / 2;
1595 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1596 if(strcmp(current_var->frame, frame_name) == 0){
1597 if(strcmp(current_var->var_name, var_name) == 0){
1598 stack_ignore_variable_free(var);
1602 }else if(strcmp(current_var->var_name, var_name) < 0){
1607 }else if(strcmp(current_var->frame, frame_name) < 0){
1614 if(strcmp(current_var->frame, frame_name) == 0){
1615 if(strcmp(current_var->var_name, var_name) < 0){
1616 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1618 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1620 }else if(strcmp(current_var->frame, frame_name) < 0){
1621 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1623 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1633 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1635 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1639 if(stacks_areas == NULL)
1640 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1642 stack_region_t region = NULL;
1643 region = xbt_new0(s_stack_region_t, 1);
1644 region->address = stack;
1645 region->process_name = strdup(name);
1646 region->context = context;
1647 region->size = size;
1648 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1649 xbt_dynar_push(stacks_areas, ®ion);
1655 void MC_ignore(void *addr, size_t size){
1657 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1661 if(mc_checkpoint_ignore == NULL)
1662 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1664 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1665 region->addr = addr;
1666 region->size = size;
1668 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1669 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1672 unsigned int cursor = 0;
1674 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1675 mc_checkpoint_ignore_region_t current_region = NULL;
1677 while(start <= end){
1678 cursor = (start + end) / 2;
1679 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1680 if(current_region->addr == addr){
1681 if(current_region->size == size){
1682 checkpoint_ignore_region_free(region);
1686 }else if(current_region->size < size){
1691 }else if(current_region->addr < addr){
1698 if(current_region->addr == addr){
1699 if(current_region->size < size){
1700 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1702 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1704 }else if(current_region->addr < addr){
1705 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1707 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1715 /******************************* Initialisation of MC *******************************/
1716 /*********************************************************************************/
1718 static void MC_dump_ignored_local_variables(void){
1720 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1723 unsigned int cursor = 0;
1724 mc_stack_ignore_variable_t current_var;
1726 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1727 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1730 xbt_dynar_free(&mc_stack_comparison_ignore);
1731 mc_stack_comparison_ignore = NULL;
1735 static void MC_dump_ignored_global_variables(void){
1737 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1740 unsigned int cursor = 0;
1741 mc_data_bss_ignore_variable_t current_var;
1743 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1744 MC_ignore_global_variable(current_var->name);
1747 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1748 mc_data_bss_comparison_ignore = NULL;
1752 static void MC_init_debug_info();
1753 static void MC_init_debug_info() {
1754 XBT_INFO("Get debug information ...");
1756 memory_map_t maps = MC_get_memory_map();
1758 /* Get local variables for state equality detection */
1759 mc_binary_info = MC_find_object_info(maps, xbt_binary_name);
1760 mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path);
1762 MC_free_memory_map(maps);
1763 XBT_INFO("Get debug information done !");
1768 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1772 /* Initialize the data structures that must be persistent across every
1773 iteration of the model-checker (in RAW memory) */
1777 MC_init_memory_map_info();
1778 MC_init_debug_info();
1780 /* Remove variables ignored before getting list of variables */
1781 MC_dump_ignored_local_variables();
1782 MC_dump_ignored_global_variables();
1785 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1789 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1790 MC_ignore_local_variable("e", "*");
1791 MC_ignore_local_variable("__ex_cleanup", "*");
1792 MC_ignore_local_variable("__ex_mctx_en", "*");
1793 MC_ignore_local_variable("__ex_mctx_me", "*");
1794 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1795 MC_ignore_local_variable("_log_ev", "*");
1796 MC_ignore_local_variable("_throw_ctx", "*");
1797 MC_ignore_local_variable("ctx", "*");
1799 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1800 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1802 /* Ignore local variable about time used for tracing */
1803 MC_ignore_local_variable("start_time", "*");
1805 MC_ignore_global_variable("mc_comp_times");
1806 MC_ignore_global_variable("mc_snapshot_comparison_time");
1807 MC_ignore_global_variable("mc_time");
1808 MC_ignore_global_variable("smpi_current_rank");
1809 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1810 MC_ignore_global_variable("maestro_stack_start");
1811 MC_ignore_global_variable("maestro_stack_end");
1813 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1814 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1815 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1816 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1818 smx_process_t process;
1819 xbt_swag_foreach(process, simix_global->process_list){
1820 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1828 static void MC_init_dot_output(){ /* FIXME : more colors */
1832 colors[2] = "green3";
1833 colors[3] = "goldenrod";
1834 colors[4] = "brown";
1835 colors[5] = "purple";
1836 colors[6] = "magenta";
1837 colors[7] = "turquoise4";
1838 colors[8] = "gray25";
1839 colors[9] = "forestgreen";
1840 colors[10] = "hotpink";
1841 colors[11] = "lightblue";
1844 dot_output = fopen(_sg_mc_dot_output_file, "w");
1846 if(dot_output == NULL){
1847 perror("Error open dot output file");
1851 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");
1855 /******************************* Core of MC *******************************/
1856 /**************************************************************************/
1858 void MC_do_the_modelcheck_for_real() {
1861 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1864 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1865 if (mc_reduce_kind==e_mc_reduce_unset)
1866 mc_reduce_kind=e_mc_reduce_dpor;
1868 XBT_INFO("Check a safety property");
1869 MC_modelcheck_safety();
1873 if (mc_reduce_kind==e_mc_reduce_unset)
1874 mc_reduce_kind=e_mc_reduce_none;
1876 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1877 MC_automaton_load(_sg_mc_property_file);
1878 MC_modelcheck_liveness();
1882 void MC_modelcheck_safety(void)
1884 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1886 /* Check if MC is already initialized */
1887 if (initial_state_safety)
1890 mc_time = xbt_new0(double, simix_process_maxpid);
1892 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1893 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1895 /* Initialize the data structures that must be persistent across every
1896 iteration of the model-checker (in RAW memory) */
1900 /* Initialize statistics */
1901 mc_stats = xbt_new0(s_mc_stats_t, 1);
1902 mc_stats->state_size = 1;
1904 /* Create exploration stack */
1905 mc_stack_safety = xbt_fifo_new();
1907 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1908 MC_init_dot_output();
1912 if(_sg_mc_visited > 0){
1916 MC_init_memory_map_info();
1917 MC_init_debug_info();
1924 /* Save the initial state */
1925 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1926 initial_state_safety->snapshot = MC_take_snapshot(0);
1938 void MC_modelcheck_liveness(){
1940 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1944 mc_time = xbt_new0(double, simix_process_maxpid);
1946 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1947 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1951 /* Initialize statistics */
1952 mc_stats = xbt_new0(s_mc_stats_t, 1);
1953 mc_stats->state_size = 1;
1955 /* Create exploration stack */
1956 mc_stack_liveness = xbt_fifo_new();
1958 /* Create the initial state */
1959 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1961 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1962 MC_init_dot_output();
1969 MC_print_statistics(mc_stats);
1985 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1987 return simcall->mc_value;
1991 int MC_random(int min, int max)
1993 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1994 return simcall_mc_random(min, max);
1998 * \brief Schedules all the process that are ready to run
2000 void MC_wait_for_requests(void)
2002 smx_process_t process;
2006 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
2007 SIMIX_process_runall();
2008 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
2009 req = &process->simcall;
2010 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
2011 SIMIX_simcall_pre(req, 0);
2016 int MC_deadlock_check()
2018 int deadlock = FALSE;
2019 smx_process_t process;
2020 if(xbt_swag_size(simix_global->process_list)){
2022 xbt_swag_foreach(process, simix_global->process_list){
2023 if(process->simcall.call != SIMCALL_NONE
2024 && MC_request_is_enabled(&process->simcall)){
2034 * \brief Re-executes from the state at position start all the transitions indicated by
2035 * a given model-checker stack.
2036 * \param stack The stack with the transitions to execute.
2037 * \param start Start index to begin the re-execution.
2039 void MC_replay(xbt_fifo_t stack, int start)
2041 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2043 int value, i = 1, count = 1;
2045 smx_simcall_t req = NULL, saved_req = NULL;
2046 xbt_fifo_item_t item, start_item;
2048 smx_process_t process = NULL;
2050 XBT_DEBUG("**** Begin Replay ****");
2053 /* Restore the initial state */
2054 MC_restore_snapshot(initial_state_safety->snapshot);
2055 /* At the moment of taking the snapshot the raw heap was set, so restoring
2056 * it will set it back again, we have to unset it to continue */
2060 start_item = xbt_fifo_get_last_item(stack);
2063 start_item = xbt_fifo_get_prev_item(start_item);
2069 xbt_dict_reset(first_enabled_state);
2070 xbt_swag_foreach(process, simix_global->process_list){
2071 if(MC_process_is_enabled(process)){
2072 char *key = bprintf("%lu", process->pid);
2073 char *data = bprintf("%d", count);
2074 xbt_dict_set(first_enabled_state, key, data, NULL);
2081 /* Traverse the stack from the state at position start and re-execute the transitions */
2082 for (item = start_item;
2083 item != xbt_fifo_get_first_item(stack);
2084 item = xbt_fifo_get_prev_item(item)) {
2086 state = (mc_state_t) xbt_fifo_get_item_content(item);
2087 saved_req = MC_state_get_executed_request(state, &value);
2090 char *key = bprintf("%lu", saved_req->issuer->pid);
2091 xbt_dict_remove(first_enabled_state, key);
2096 /* because we got a copy of the executed request, we have to fetch the
2097 real one, pointed by the request field of the issuer process */
2098 req = &saved_req->issuer->simcall;
2100 /* Debug information */
2101 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2102 req_str = MC_request_to_string(req, value);
2103 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2108 SIMIX_simcall_pre(req, value);
2109 MC_wait_for_requests();
2114 /* Insert in dict all enabled processes */
2115 xbt_swag_foreach(process, simix_global->process_list){
2116 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2117 char *key = bprintf("%lu", process->pid);
2118 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2119 char *data = bprintf("%d", count);
2120 xbt_dict_set(first_enabled_state, key, data, NULL);
2127 /* Update statistics */
2128 mc_stats->visited_states++;
2129 mc_stats->executed_transitions++;
2133 XBT_DEBUG("**** End Replay ****");
2143 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2146 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2150 smx_simcall_t req = NULL, saved_req = NULL;
2151 xbt_fifo_item_t item;
2156 XBT_DEBUG("**** Begin Replay ****");
2158 /* Restore the initial state */
2159 MC_restore_snapshot(initial_state_liveness->snapshot);
2161 /* At the moment of taking the snapshot the raw heap was set, so restoring
2162 * it will set it back again, we have to unset it to continue */
2163 if(!initial_state_liveness->raw_mem_set)
2168 item = xbt_fifo_get_last_item(stack);
2170 while(depth <= xbt_fifo_size(stack)){
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++;
2205 item = xbt_fifo_get_prev_item(item);
2210 /* Traverse the stack from the initial state and re-execute the transitions */
2211 for (item = xbt_fifo_get_last_item(stack);
2212 item != xbt_fifo_get_first_item(stack);
2213 item = xbt_fifo_get_prev_item(item)) {
2215 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2216 state = (mc_state_t) pair->graph_state;
2218 if(pair->requests > 0){
2220 saved_req = MC_state_get_executed_request(state, &value);
2221 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2223 if(saved_req != NULL){
2224 /* because we got a copy of the executed request, we have to fetch the
2225 real one, pointed by the request field of the issuer process */
2226 req = &saved_req->issuer->simcall;
2227 //XBT_DEBUG("Req->call %u", req->call);
2229 /* Debug information */
2230 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2231 req_str = MC_request_to_string(req, value);
2232 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2238 SIMIX_simcall_pre(req, value);
2239 MC_wait_for_requests();
2244 /* Update statistics */
2245 mc_stats->visited_pairs++;
2246 mc_stats->executed_transitions++;
2250 XBT_DEBUG("**** End Replay ****");
2252 if(initial_state_liveness->raw_mem_set)
2260 * \brief Dumps the contents of a model-checker's stack and shows the actual
2262 * \param stack The stack to dump
2264 void MC_dump_stack_safety(xbt_fifo_t stack)
2267 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2269 MC_show_stack_safety(stack);
2271 if(!_sg_mc_checkpoint){
2276 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2277 MC_state_delete(state);
2290 void MC_show_stack_safety(xbt_fifo_t stack)
2293 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2299 xbt_fifo_item_t item;
2301 char *req_str = NULL;
2303 for (item = xbt_fifo_get_last_item(stack);
2304 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2305 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2306 req = MC_state_get_executed_request(state, &value);
2308 req_str = MC_request_to_string(req, value);
2309 XBT_INFO("%s", req_str);
2318 void MC_show_deadlock(smx_simcall_t req)
2320 /*char *req_str = NULL;*/
2321 XBT_INFO("**************************");
2322 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2323 XBT_INFO("**************************");
2324 XBT_INFO("Locked request:");
2325 /*req_str = MC_request_to_string(req);
2326 XBT_INFO("%s", req_str);
2327 xbt_free(req_str);*/
2328 XBT_INFO("Counter-example execution trace:");
2329 MC_dump_stack_safety(mc_stack_safety);
2330 MC_print_statistics(mc_stats);
2334 void MC_show_stack_liveness(xbt_fifo_t stack){
2337 xbt_fifo_item_t item;
2339 char *req_str = NULL;
2341 for (item = xbt_fifo_get_last_item(stack);
2342 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2343 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2344 req = MC_state_get_executed_request(pair->graph_state, &value);
2346 if(pair->requests>0){
2347 req_str = MC_request_to_string(req, value);
2348 XBT_INFO("%s", req_str);
2351 XBT_INFO("End of system requests but evolution in Büchi automaton");
2357 void MC_dump_stack_liveness(xbt_fifo_t stack){
2359 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2364 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2365 MC_pair_delete(pair);
2374 void MC_print_statistics(mc_stats_t stats)
2376 if(stats->expanded_pairs == 0){
2377 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2378 XBT_INFO("Visited states = %lu", stats->visited_states);
2380 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2381 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2383 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2385 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2386 fprintf(dot_output, "}\n");
2392 void MC_assert(int prop)
2394 if (MC_is_active() && !prop){
2395 XBT_INFO("**************************");
2396 XBT_INFO("*** PROPERTY NOT VALID ***");
2397 XBT_INFO("**************************");
2398 XBT_INFO("Counter-example execution trace:");
2399 MC_dump_stack_safety(mc_stack_safety);
2400 MC_print_statistics(mc_stats);
2406 user_max_depth_reached = 1;
2409 void MC_process_clock_add(smx_process_t process, double amount)
2411 mc_time[process->pid] += amount;
2414 double MC_process_clock_get(smx_process_t process)
2418 return mc_time[process->pid];
2426 void MC_automaton_load(const char *file){
2428 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2432 if (_mc_property_automaton == NULL)
2433 _mc_property_automaton = xbt_automaton_new();
2435 xbt_automaton_load(_mc_property_automaton,file);
2444 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2446 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2450 if (_mc_property_automaton == NULL)
2451 _mc_property_automaton = xbt_automaton_new();
2453 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);