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 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
457 xbt_dict_cursor_t cursor = NULL;
461 xbt_dict_foreach(all_variables, cursor, name, res) {
462 if(offset >= res->start && offset < res->end){
463 xbt_dict_cursor_free(&cursor);
468 xbt_dict_cursor_free(&cursor);
473 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
475 unsigned int cursor = 0;
476 dw_variable_t current_var;
478 xbt_dynar_foreach(frame->variables, cursor, current_var){
479 if(strcmp(var, current_var->name) == 0)
486 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
488 if(xbt_dynar_is_empty(variables))
491 unsigned int cursor = 0;
493 int end = xbt_dynar_length(variables) - 1;
494 dw_variable_t var_test = NULL;
497 cursor = (start + end) / 2;
498 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
499 if(strcmp(var_test->name, var) < 0){
501 }else if(strcmp(var_test->name, var) > 0){
504 if(address){ /* global variable */
505 if(var_test->address.address == address)
507 if(var_test->address.address > address)
511 }else{ /* local variable */
517 if(strcmp(var_test->name, var) == 0){
518 if(address && var_test->address.address < address)
522 }else if(strcmp(var_test->name, var) < 0)
529 static void MC_dwarf_get_variables(mc_object_info_t info){
530 mc_object_info_t result = info;
531 const char *elf_file = info->file_name;
533 xbt_dict_t location_list = MC_dwarf_get_location_list(elf_file);
535 char *command = bprintf("LANG=C objdump -Wi %s", elf_file);
537 FILE *fp = popen(command, "r");
540 perror("popen for objdump failed");
542 xbt_dict_t *local_variables = &result->local_variables;
543 xbt_dynar_t *global_variables = &result->global_variables;
544 xbt_dict_t *types = &result->types;
546 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
547 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
548 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
549 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
550 *parent_value = NULL;
554 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
555 is_pointer = 0, struct_decl = 0, member_end = 0,
556 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
558 xbt_dynar_t split = NULL, split2 = NULL;
560 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
561 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
563 dw_frame_t variable_frame, subroutine_frame = NULL;
565 e_dw_type_type type_type = -1;
567 read = xbt_getline(&line, &n, fp);
571 /* Wipeout the new line character */
572 line[read - 1] = '\0';
574 if(n == 0 || strlen(line) == 0){
575 read = xbt_getline(&line, &n, fp);
579 xbt_str_ltrim(line, NULL);
580 xbt_str_strip_spaces(line);
583 read = xbt_getline(&line, &n, fp);
587 xbt_dynar_free(&split);
588 split = xbt_str_split(line, " ");
591 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
593 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
594 /* We build/complete a dw_frame_t object
595 * and append it if necessary to the local_variables dictionnary */
597 dw_frame_t frame = NULL;
599 strtok(xbt_dynar_get_as(split, 0, char *), "<");
600 subprogram_start = xbt_strdup(strtok(NULL, "<"));
601 xbt_str_rtrim(subprogram_start, ">:");
603 read = xbt_getline(&line, &n, fp);
607 /* Wipeout the new line character */
608 line[read - 1] = '\0';
610 if(n == 0 || strlen(line) == 0){
611 read = xbt_getline(&line, &n, fp);
615 xbt_dynar_free(&split);
616 xbt_str_rtrim(line, NULL);
617 xbt_str_strip_spaces(line);
618 split = xbt_str_split(line, " ");
620 node_type = xbt_dynar_get_as(split, 1, char *);
622 if(strncmp(node_type, "DW_AT_", 6) != 0)
625 if(strcmp(node_type, "DW_AT_sibling") == 0){
627 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
628 xbt_str_ltrim(subprogram_end, "<0x");
629 xbt_str_rtrim(subprogram_end, ">");
631 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
634 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
635 xbt_str_ltrim(abstract_origin, "<0x");
636 xbt_str_rtrim(abstract_origin, ">");
637 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
638 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
639 xbt_free(abstract_origin);
641 }else if(strcmp(node_type, "DW_AT_name") == 0){
644 xbt_free(current_frame);
645 frame = xbt_new0(s_dw_frame_t, 1);
646 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
647 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
648 frame->frame_base = xbt_new0(s_dw_location_t, 1);
649 current_frame = strdup(frame->name);
651 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
653 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
655 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
657 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
659 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
663 xbt_str_strip_spaces(line);
664 split2 = xbt_str_split(line, "(");
665 xbt_dynar_remove_at(split2, 0, NULL);
666 loc_expr = xbt_str_join(split2, " ");
667 xbt_str_rtrim(loc_expr, ")");
668 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
669 xbt_dynar_free(&split2);
674 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
677 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
679 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
682 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
684 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
686 xbt_free(frame->name);
687 xbt_free(current_frame);
688 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
689 current_frame = strdup(frame->name);
690 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
694 read = xbt_getline(&line, &n, fp);
699 frame->start = strtoul(subprogram_start, NULL, 16);
700 if(subprogram_end != NULL)
701 frame->end = strtoul(subprogram_end, NULL, 16);
702 xbt_dict_set(*local_variables, frame->name, frame, NULL);
705 xbt_free(subprogram_start);
706 xbt_free(subprogram_end);
707 subprogram_end = NULL;
710 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
711 /* We build a dw_variable_t object and append it either to
712 the list of variables of the frame (local variable)
713 or to the list of global variables (global variables). */
715 dw_variable_t var = NULL;
717 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
718 parent_value = strtok(parent_value,"<");
719 xbt_str_rtrim(parent_value, ">");
720 parent = atoi(parent_value);
721 xbt_free(parent_value);
726 strtok(xbt_dynar_get_as(split, 0, char *), "<");
727 origin = xbt_strdup(strtok(NULL, "<"));
728 xbt_str_rtrim(origin, ">:");
730 read = xbt_getline(&line, &n, fp);
734 /* Wipeout the new line character */
735 line[read - 1] = '\0';
737 if(n == 0 || strlen(line) == 0){
738 read = xbt_getline(&line, &n, fp);
742 xbt_dynar_free(&split);
743 xbt_str_rtrim(line, NULL);
744 xbt_str_strip_spaces(line);
745 split = xbt_str_split(line, " ");
747 node_type = xbt_dynar_get_as(split, 1, char *);
749 if(strncmp(node_type, "DW_AT_", 6) != 0)
752 if(strcmp(node_type, "DW_AT_name") == 0){
754 var = xbt_new0(s_dw_variable_t, 1);
755 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
756 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
758 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
762 abstract_origin = xbt_dynar_get_as(split, 2, char *);
763 xbt_str_ltrim(abstract_origin, "<0x");
764 xbt_str_rtrim(abstract_origin, ">");
766 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
767 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
768 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
770 }else if(strcmp(node_type, "DW_AT_location") == 0){
774 if(!global_variable){
776 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
778 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
779 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
781 xbt_str_strip_spaces(line);
782 split2 = xbt_str_split(line, "(");
783 xbt_dynar_remove_at(split2, 0, NULL);
784 loc_expr = xbt_str_join(split2, " ");
785 xbt_str_rtrim(loc_expr, ")");
786 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
788 xbt_dynar_free(&split2);
789 split2 = xbt_str_split(loc_expr, " ");
790 if(strcmp(elf_file, xbt_binary_name) != 0)
791 var->address.address = (char *) info->start_text + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
793 // Why is it different ?
794 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
796 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
798 xbt_dynar_free(&split2);
802 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
803 xbt_str_rtrim(global_address, ")");
804 if(strcmp(elf_file, xbt_binary_name) != 0)
805 var->address.address = (char *) info->start_text + (long)((void *)strtoul(global_address, NULL, 16));
807 // Why is it different ?
808 var->address.address = (void *)strtoul(global_address, NULL, 16);
809 xbt_free(global_address);
810 global_address = NULL;
815 }else if(strcmp(node_type, "DW_AT_type") == 0){
817 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
818 xbt_str_ltrim(type_origin, "<0x");
819 xbt_str_rtrim(type_origin, ">");
821 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
825 dw_variable_free(var);
829 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
833 dw_variable_free(var);
839 read = xbt_getline(&line, &n, fp);
843 if(new_variable == 1){
845 if(!global_variable){
846 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
847 var->type_origin = strdup(type_origin);
849 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
851 xbt_dynar_insert_at(variable_frame->variables, index, &var);
853 var->type_origin = strdup(type_origin);
855 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
857 xbt_dynar_insert_at(*global_variables, index, &var);
860 xbt_free(type_origin);
867 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
868 /* Update the information on the frame (we should duplicate it instead). */
870 read = xbt_getline(&line, &n, fp);
874 /* Wipeout the new line character */
875 line[read - 1] = '\0';
877 if(n == 0 || strlen(line) == 0){
878 read = xbt_getline(&line, &n, fp);
882 xbt_dynar_free(&split);
883 xbt_str_rtrim(line, NULL);
884 xbt_str_strip_spaces(line);
885 split = xbt_str_split(line, " ");
887 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
890 node_type = xbt_dynar_get_as(split, 1, char *);
892 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
894 origin = xbt_dynar_get_as(split, 2, char *);
895 xbt_str_ltrim(origin, "<0x");
896 xbt_str_rtrim(origin, ">");
898 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
899 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
901 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
903 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
905 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
907 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
910 read = xbt_getline(&line, &n, fp);
914 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
915 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
916 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
917 || strcmp(node_type, "(DW_TAG_typedef)") == 0
918 || strcmp(node_type, "(DW_TAG_const_type)") == 0
919 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
920 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
921 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
923 /* Create the and add it to the types dictionnary */
925 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
926 type_type = e_dw_base_type;
927 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
928 type_type = e_dw_enumeration_type;
929 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
930 type_type = e_dw_enumerator;
931 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
932 type_type = e_dw_typedef;
933 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
934 type_type = e_dw_const_type;
935 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
936 type_type = e_dw_pointer_type;
937 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
938 type_type = e_dw_subroutine_type;
939 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
940 type_type = e_dw_volatile_type;
942 strtok(xbt_dynar_get_as(split, 0, char *), "<");
943 origin = strdup(strtok(NULL, "<"));
944 xbt_str_rtrim(origin, ">:");
946 read = xbt_getline(&line, &n, fp);
950 /* Wipeout the new line character */
951 line[read - 1] = '\0';
953 if(n == 0 || strlen(line) == 0){
954 read = xbt_getline(&line, &n, fp);
958 xbt_dynar_free(&split);
959 xbt_str_rtrim(line, NULL);
960 xbt_str_strip_spaces(line);
961 split = xbt_str_split(line, " ");
963 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
966 node_type = xbt_dynar_get_as(split, 1, char *);
968 if(strcmp(node_type, "DW_AT_byte_size") == 0){
969 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
970 if(type_type == e_dw_enumeration_type)
971 enumeration_size = size;
972 }else if(strcmp(node_type, "DW_AT_name") == 0){
973 end = xbt_str_join(split, " ");
974 xbt_dynar_free(&split);
975 split = xbt_str_split(end, "):");
976 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
977 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
978 }else if(strcmp(node_type, "DW_AT_type") == 0){
979 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
980 xbt_str_ltrim(type_origin, "<0x");
981 xbt_str_rtrim(type_origin, ">");
984 read = xbt_getline(&line, &n, fp);
987 dw_type_t type = xbt_new0(s_dw_type_t, 1);
988 type->type = type_type;
990 type->name = xbt_strdup(name);
992 type->name = xbt_strdup("undefined");
993 type->is_pointer_type = is_pointer;
994 type->id = (void *)strtoul(origin, NULL, 16);
996 type->dw_type_id = xbt_strdup(type_origin);
997 if(type_type == e_dw_enumerator)
998 type->size = enumeration_size;
1001 type->members = NULL;
1003 xbt_dict_set(*types, origin, type, NULL);
1007 xbt_free(type_origin);
1016 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
1018 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
1023 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1024 origin = strdup(strtok(NULL, "<"));
1025 xbt_str_rtrim(origin, ">:");
1027 read = xbt_getline(&line, &n, fp);
1029 dw_type_t type = NULL;
1035 /* Wipeout the new line character */
1036 line[read - 1] = '\0';
1038 if(n == 0 || strlen(line) == 0){
1039 read = xbt_getline(&line, &n, fp);
1043 xbt_dynar_free(&split);
1044 xbt_str_rtrim(line, NULL);
1045 xbt_str_strip_spaces(line);
1046 split = xbt_str_split(line, " ");
1048 node_type = xbt_dynar_get_as(split, 1, char *);
1050 if(strncmp(node_type, "DW_AT_", 6) != 0){
1055 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1056 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1057 }else if(strcmp(node_type, "DW_AT_name") == 0){
1059 end = xbt_str_join(split, " ");
1060 xbt_dynar_free(&split);
1061 split = xbt_str_split(end, "):");
1062 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1063 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1064 }else if(strcmp(node_type, "DW_AT_type") == 0){
1065 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1066 xbt_str_ltrim(type_origin, "<0x");
1067 xbt_str_rtrim(type_origin, ">");
1068 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1070 end = xbt_str_join(split, " ");
1071 xbt_dynar_free(&split);
1072 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1073 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1074 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1075 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1078 read = xbt_getline(&line, &n, fp);
1082 if(member_end && type){
1085 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1086 member_type->name = xbt_strdup(name);
1087 member_type->size = size;
1088 member_type->is_pointer_type = is_pointer;
1089 member_type->id = (void *)strtoul(origin, NULL, 16);
1090 member_type->offset = offset;
1092 member_type->dw_type_id = xbt_strdup(type_origin);
1094 xbt_dynar_push(type->members, &member_type);
1100 xbt_free(type_origin);
1107 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1108 origin = strdup(strtok(NULL, "<"));
1109 xbt_str_rtrim(origin, ">:");
1113 if(struct_decl || union_decl){
1114 type = xbt_new0(s_dw_type_t, 1);
1116 type->type = e_dw_structure_type;
1118 type->type = e_dw_union_type;
1119 type->name = xbt_strdup(name);
1121 type->is_pointer_type = is_pointer;
1122 type->id = (void *)strtoul(origin, NULL, 16);
1124 type->dw_type_id = xbt_strdup(type_origin);
1125 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1127 xbt_dict_set(*types, origin, type, NULL);
1133 xbt_free(type_origin);
1141 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1144 read = xbt_getline(&line, &n, fp);
1151 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1153 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1154 origin = strdup(strtok(NULL, "<"));
1155 xbt_str_rtrim(origin, ">:");
1157 read = xbt_getline(&line, &n, fp);
1159 dw_type_t type = NULL;
1165 /* Wipeout the new line character */
1166 line[read - 1] = '\0';
1168 if(n == 0 || strlen(line) == 0){
1169 read = xbt_getline(&line, &n, fp);
1173 xbt_dynar_free(&split);
1174 xbt_str_rtrim(line, NULL);
1175 xbt_str_strip_spaces(line);
1176 split = xbt_str_split(line, " ");
1178 node_type = xbt_dynar_get_as(split, 1, char *);
1180 if(strncmp(node_type, "DW_AT_", 6) != 0)
1183 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1184 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1185 }else if(strcmp(node_type, "DW_AT_name") == 0){
1186 end = xbt_str_join(split, " ");
1187 xbt_dynar_free(&split);
1188 split = xbt_str_split(end, "):");
1189 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1190 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1191 }else if(strcmp(node_type, "DW_AT_type") == 0){
1192 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1193 xbt_str_ltrim(type_origin, "<0x");
1194 xbt_str_rtrim(type_origin, ">");
1197 read = xbt_getline(&line, &n, fp);
1201 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1205 if(subrange && type){
1212 xbt_free(type_origin);
1218 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1219 origin = strdup(strtok(NULL, "<"));
1220 xbt_str_rtrim(origin, ">:");
1224 type = xbt_new0(s_dw_type_t, 1);
1225 type->type = e_dw_array_type;
1226 type->name = xbt_strdup(name);
1227 type->is_pointer_type = is_pointer;
1228 type->id = (void *)strtoul(origin, NULL, 16);
1230 type->dw_type_id = xbt_strdup(type_origin);
1231 type->members = NULL;
1233 xbt_dict_set(*types, origin, type, NULL);
1239 xbt_free(type_origin);
1244 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1247 read = xbt_getline(&line, &n, fp);
1256 read = xbt_getline(&line, &n, fp);
1262 xbt_dynar_free(&split);
1263 xbt_dict_free(&variables_origin);
1264 xbt_dict_free(&subprograms_origin);
1267 xbt_dict_free(&location_list);
1273 /******************************* Ignore mechanism *******************************/
1274 /*********************************************************************************/
1276 xbt_dynar_t mc_checkpoint_ignore;
1278 typedef struct s_mc_stack_ignore_variable{
1281 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1283 typedef struct s_mc_data_bss_ignore_variable{
1285 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1287 /**************************** Free functions ******************************/
1289 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1290 xbt_free(v->var_name);
1295 static void stack_ignore_variable_free_voidp(void *v){
1296 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1299 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1303 void heap_ignore_region_free_voidp(void *r){
1304 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1307 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1312 static void data_bss_ignore_variable_free_voidp(void *v){
1313 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1316 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1320 static void checkpoint_ignore_region_free_voidp(void *r){
1321 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1324 /***********************************************************************/
1326 void MC_ignore_heap(void *address, size_t size){
1328 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1332 mc_heap_ignore_region_t region = NULL;
1333 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1334 region->address = address;
1335 region->size = size;
1337 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1339 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1340 region->fragment = -1;
1341 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1343 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1344 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1347 if(mc_heap_comparison_ignore == NULL){
1348 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1349 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1355 unsigned int cursor = 0;
1356 mc_heap_ignore_region_t current_region = NULL;
1358 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1360 while(start <= end){
1361 cursor = (start + end) / 2;
1362 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1363 if(current_region->address == address){
1364 heap_ignore_region_free(region);
1368 }else if(current_region->address < address){
1375 if(current_region->address < address)
1376 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1378 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1384 void MC_remove_ignore_heap(void *address, size_t size){
1386 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1390 unsigned int cursor = 0;
1392 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1393 mc_heap_ignore_region_t region;
1394 int ignore_found = 0;
1396 while(start <= end){
1397 cursor = (start + end) / 2;
1398 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1399 if(region->address == address){
1402 }else if(region->address < address){
1405 if((char * )region->address <= ((char *)address + size)){
1414 if(ignore_found == 1){
1415 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1416 MC_remove_ignore_heap(address, size);
1424 void MC_ignore_global_variable(const char *name){
1426 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1430 if(mc_libsimgrid_info){
1432 unsigned int cursor = 0;
1433 dw_variable_t current_var;
1435 int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1437 while(start <= end){
1438 cursor = (start + end) /2;
1439 current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
1440 if(strcmp(current_var->name, name) == 0){
1441 xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
1443 end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1444 }else if(strcmp(current_var->name, name) < 0){
1453 if(mc_data_bss_comparison_ignore == NULL)
1454 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1456 mc_data_bss_ignore_variable_t var = NULL;
1457 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1458 var->name = strdup(name);
1460 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1462 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1466 unsigned int cursor = 0;
1468 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1469 mc_data_bss_ignore_variable_t current_var = NULL;
1471 while(start <= end){
1472 cursor = (start + end) / 2;
1473 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1474 if(strcmp(current_var->name, name) == 0){
1475 data_bss_ignore_variable_free(var);
1479 }else if(strcmp(current_var->name, name) < 0){
1486 if(strcmp(current_var->name, name) < 0)
1487 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1489 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1498 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1500 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1504 if(mc_libsimgrid_info){
1505 unsigned int cursor = 0;
1506 dw_variable_t current_var;
1508 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1509 xbt_dict_cursor_t dict_cursor;
1510 char *current_frame_name;
1512 xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
1514 end = xbt_dynar_length(frame->variables) - 1;
1515 while(start <= end){
1516 cursor = (start + end) / 2;
1517 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1518 if(strcmp(current_var->name, var_name) == 0){
1519 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1521 end = xbt_dynar_length(frame->variables) - 1;
1522 }else if(strcmp(current_var->name, var_name) < 0){
1529 xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
1531 end = xbt_dynar_length(frame->variables) - 1;
1532 while(start <= end){
1533 cursor = (start + end) / 2;
1534 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1535 if(strcmp(current_var->name, var_name) == 0){
1536 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1538 end = xbt_dynar_length(frame->variables) - 1;
1539 }else if(strcmp(current_var->name, var_name) < 0){
1547 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
1548 mc_libsimgrid_info->local_variables, frame_name))->variables;
1550 end = xbt_dynar_length(variables_list) - 1;
1551 while(start <= end){
1552 cursor = (start + end) / 2;
1553 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1554 if(strcmp(current_var->name, var_name) == 0){
1555 xbt_dynar_remove_at(variables_list, cursor, NULL);
1557 end = xbt_dynar_length(variables_list) - 1;
1558 }else if(strcmp(current_var->name, var_name) < 0){
1567 if(mc_stack_comparison_ignore == NULL)
1568 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1570 mc_stack_ignore_variable_t var = NULL;
1571 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1572 var->var_name = strdup(var_name);
1573 var->frame = strdup(frame_name);
1575 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1577 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1581 unsigned int cursor = 0;
1583 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1584 mc_stack_ignore_variable_t current_var = NULL;
1586 while(start <= end){
1587 cursor = (start + end) / 2;
1588 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1589 if(strcmp(current_var->frame, frame_name) == 0){
1590 if(strcmp(current_var->var_name, var_name) == 0){
1591 stack_ignore_variable_free(var);
1595 }else if(strcmp(current_var->var_name, var_name) < 0){
1600 }else if(strcmp(current_var->frame, frame_name) < 0){
1607 if(strcmp(current_var->frame, frame_name) == 0){
1608 if(strcmp(current_var->var_name, var_name) < 0){
1609 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1611 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1613 }else if(strcmp(current_var->frame, frame_name) < 0){
1614 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1616 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1626 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1628 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1632 if(stacks_areas == NULL)
1633 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1635 stack_region_t region = NULL;
1636 region = xbt_new0(s_stack_region_t, 1);
1637 region->address = stack;
1638 region->process_name = strdup(name);
1639 region->context = context;
1640 region->size = size;
1641 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1642 xbt_dynar_push(stacks_areas, ®ion);
1648 void MC_ignore(void *addr, size_t size){
1650 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1654 if(mc_checkpoint_ignore == NULL)
1655 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1657 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1658 region->addr = addr;
1659 region->size = size;
1661 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1662 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1665 unsigned int cursor = 0;
1667 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1668 mc_checkpoint_ignore_region_t current_region = NULL;
1670 while(start <= end){
1671 cursor = (start + end) / 2;
1672 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1673 if(current_region->addr == addr){
1674 if(current_region->size == size){
1675 checkpoint_ignore_region_free(region);
1679 }else if(current_region->size < size){
1684 }else if(current_region->addr < addr){
1691 if(current_region->addr == addr){
1692 if(current_region->size < size){
1693 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1695 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1697 }else if(current_region->addr < addr){
1698 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1700 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1708 /******************************* Initialisation of MC *******************************/
1709 /*********************************************************************************/
1711 static void MC_dump_ignored_local_variables(void){
1713 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1716 unsigned int cursor = 0;
1717 mc_stack_ignore_variable_t current_var;
1719 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1720 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1723 xbt_dynar_free(&mc_stack_comparison_ignore);
1724 mc_stack_comparison_ignore = NULL;
1728 static void MC_dump_ignored_global_variables(void){
1730 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1733 unsigned int cursor = 0;
1734 mc_data_bss_ignore_variable_t current_var;
1736 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1737 MC_ignore_global_variable(current_var->name);
1740 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1741 mc_data_bss_comparison_ignore = NULL;
1745 static void MC_init_debug_info();
1746 static void MC_init_debug_info() {
1747 XBT_INFO("Get debug information ...");
1749 memory_map_t maps = MC_get_memory_map();
1751 /* Get local variables for state equality detection */
1753 mc_binary_info = MC_find_object_address(maps, xbt_binary_name);
1754 MC_dwarf_get_variables(mc_binary_info);
1756 mc_libsimgrid_info = MC_find_object_address(maps, libsimgrid_path);
1757 MC_dwarf_get_variables(mc_libsimgrid_info);
1759 MC_free_memory_map(maps);
1761 XBT_INFO("Get debug information done !");
1766 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1770 /* Initialize the data structures that must be persistent across every
1771 iteration of the model-checker (in RAW memory) */
1775 MC_init_memory_map_info();
1776 MC_init_debug_info();
1778 /* Remove variables ignored before getting list of variables */
1779 MC_dump_ignored_local_variables();
1780 MC_dump_ignored_global_variables();
1783 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1787 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1788 MC_ignore_local_variable("e", "*");
1789 MC_ignore_local_variable("__ex_cleanup", "*");
1790 MC_ignore_local_variable("__ex_mctx_en", "*");
1791 MC_ignore_local_variable("__ex_mctx_me", "*");
1792 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1793 MC_ignore_local_variable("_log_ev", "*");
1794 MC_ignore_local_variable("_throw_ctx", "*");
1795 MC_ignore_local_variable("ctx", "*");
1797 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1798 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1800 /* Ignore local variable about time used for tracing */
1801 MC_ignore_local_variable("start_time", "*");
1803 MC_ignore_global_variable("mc_comp_times");
1804 MC_ignore_global_variable("mc_snapshot_comparison_time");
1805 MC_ignore_global_variable("mc_time");
1806 MC_ignore_global_variable("smpi_current_rank");
1807 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1808 MC_ignore_global_variable("maestro_stack_start");
1809 MC_ignore_global_variable("maestro_stack_end");
1811 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1812 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
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)));
1816 smx_process_t process;
1817 xbt_swag_foreach(process, simix_global->process_list){
1818 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1826 static void MC_init_dot_output(){ /* FIXME : more colors */
1830 colors[2] = "green3";
1831 colors[3] = "goldenrod";
1832 colors[4] = "brown";
1833 colors[5] = "purple";
1834 colors[6] = "magenta";
1835 colors[7] = "turquoise4";
1836 colors[8] = "gray25";
1837 colors[9] = "forestgreen";
1838 colors[10] = "hotpink";
1839 colors[11] = "lightblue";
1842 dot_output = fopen(_sg_mc_dot_output_file, "w");
1844 if(dot_output == NULL){
1845 perror("Error open dot output file");
1849 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");
1853 /******************************* Core of MC *******************************/
1854 /**************************************************************************/
1856 void MC_do_the_modelcheck_for_real() {
1859 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1862 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1863 if (mc_reduce_kind==e_mc_reduce_unset)
1864 mc_reduce_kind=e_mc_reduce_dpor;
1866 XBT_INFO("Check a safety property");
1867 MC_modelcheck_safety();
1871 if (mc_reduce_kind==e_mc_reduce_unset)
1872 mc_reduce_kind=e_mc_reduce_none;
1874 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1875 MC_automaton_load(_sg_mc_property_file);
1876 MC_modelcheck_liveness();
1880 void MC_modelcheck_safety(void)
1882 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1884 /* Check if MC is already initialized */
1885 if (initial_state_safety)
1888 mc_time = xbt_new0(double, simix_process_maxpid);
1890 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1891 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1893 /* Initialize the data structures that must be persistent across every
1894 iteration of the model-checker (in RAW memory) */
1898 /* Initialize statistics */
1899 mc_stats = xbt_new0(s_mc_stats_t, 1);
1900 mc_stats->state_size = 1;
1902 /* Create exploration stack */
1903 mc_stack_safety = xbt_fifo_new();
1905 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1906 MC_init_dot_output();
1910 if(_sg_mc_visited > 0){
1914 MC_init_memory_map_info();
1922 /* Save the initial state */
1923 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1924 initial_state_safety->snapshot = MC_take_snapshot(0);
1936 void MC_modelcheck_liveness(){
1938 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1942 mc_time = xbt_new0(double, simix_process_maxpid);
1944 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1945 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1949 /* Initialize statistics */
1950 mc_stats = xbt_new0(s_mc_stats_t, 1);
1951 mc_stats->state_size = 1;
1953 /* Create exploration stack */
1954 mc_stack_liveness = xbt_fifo_new();
1956 /* Create the initial state */
1957 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1959 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1960 MC_init_dot_output();
1967 MC_print_statistics(mc_stats);
1983 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1985 return simcall->mc_value;
1989 int MC_random(int min, int max)
1991 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1992 return simcall_mc_random(min, max);
1996 * \brief Schedules all the process that are ready to run
1998 void MC_wait_for_requests(void)
2000 smx_process_t process;
2004 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
2005 SIMIX_process_runall();
2006 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
2007 req = &process->simcall;
2008 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
2009 SIMIX_simcall_pre(req, 0);
2014 int MC_deadlock_check()
2016 int deadlock = FALSE;
2017 smx_process_t process;
2018 if(xbt_swag_size(simix_global->process_list)){
2020 xbt_swag_foreach(process, simix_global->process_list){
2021 if(process->simcall.call != SIMCALL_NONE
2022 && MC_request_is_enabled(&process->simcall)){
2032 * \brief Re-executes from the state at position start all the transitions indicated by
2033 * a given model-checker stack.
2034 * \param stack The stack with the transitions to execute.
2035 * \param start Start index to begin the re-execution.
2037 void MC_replay(xbt_fifo_t stack, int start)
2039 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2041 int value, i = 1, count = 1;
2043 smx_simcall_t req = NULL, saved_req = NULL;
2044 xbt_fifo_item_t item, start_item;
2046 smx_process_t process = NULL;
2048 XBT_DEBUG("**** Begin Replay ****");
2051 /* Restore the initial state */
2052 MC_restore_snapshot(initial_state_safety->snapshot);
2053 /* At the moment of taking the snapshot the raw heap was set, so restoring
2054 * it will set it back again, we have to unset it to continue */
2058 start_item = xbt_fifo_get_last_item(stack);
2061 start_item = xbt_fifo_get_prev_item(start_item);
2067 xbt_dict_reset(first_enabled_state);
2068 xbt_swag_foreach(process, simix_global->process_list){
2069 if(MC_process_is_enabled(process)){
2070 char *key = bprintf("%lu", process->pid);
2071 char *data = bprintf("%d", count);
2072 xbt_dict_set(first_enabled_state, key, data, NULL);
2079 /* Traverse the stack from the state at position start and re-execute the transitions */
2080 for (item = start_item;
2081 item != xbt_fifo_get_first_item(stack);
2082 item = xbt_fifo_get_prev_item(item)) {
2084 state = (mc_state_t) xbt_fifo_get_item_content(item);
2085 saved_req = MC_state_get_executed_request(state, &value);
2088 char *key = bprintf("%lu", saved_req->issuer->pid);
2089 xbt_dict_remove(first_enabled_state, key);
2094 /* because we got a copy of the executed request, we have to fetch the
2095 real one, pointed by the request field of the issuer process */
2096 req = &saved_req->issuer->simcall;
2098 /* Debug information */
2099 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2100 req_str = MC_request_to_string(req, value);
2101 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2106 SIMIX_simcall_pre(req, value);
2107 MC_wait_for_requests();
2112 /* Insert in dict all enabled processes */
2113 xbt_swag_foreach(process, simix_global->process_list){
2114 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2115 char *key = bprintf("%lu", process->pid);
2116 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2117 char *data = bprintf("%d", count);
2118 xbt_dict_set(first_enabled_state, key, data, NULL);
2125 /* Update statistics */
2126 mc_stats->visited_states++;
2127 mc_stats->executed_transitions++;
2131 XBT_DEBUG("**** End Replay ****");
2141 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2144 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2148 smx_simcall_t req = NULL, saved_req = NULL;
2149 xbt_fifo_item_t item;
2154 XBT_DEBUG("**** Begin Replay ****");
2156 /* Restore the initial state */
2157 MC_restore_snapshot(initial_state_liveness->snapshot);
2159 /* At the moment of taking the snapshot the raw heap was set, so restoring
2160 * it will set it back again, we have to unset it to continue */
2161 if(!initial_state_liveness->raw_mem_set)
2166 item = xbt_fifo_get_last_item(stack);
2168 while(depth <= xbt_fifo_size(stack)){
2170 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2171 state = (mc_state_t) pair->graph_state;
2173 if(pair->requests > 0){
2175 saved_req = MC_state_get_executed_request(state, &value);
2176 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2178 if(saved_req != NULL){
2179 /* because we got a copy of the executed request, we have to fetch the
2180 real one, pointed by the request field of the issuer process */
2181 req = &saved_req->issuer->simcall;
2182 //XBT_DEBUG("Req->call %u", req->call);
2184 /* Debug information */
2185 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2186 req_str = MC_request_to_string(req, value);
2187 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2193 SIMIX_simcall_pre(req, value);
2194 MC_wait_for_requests();
2199 /* Update statistics */
2200 mc_stats->visited_pairs++;
2201 mc_stats->executed_transitions++;
2203 item = xbt_fifo_get_prev_item(item);
2208 /* Traverse the stack from the initial state and re-execute the transitions */
2209 for (item = xbt_fifo_get_last_item(stack);
2210 item != xbt_fifo_get_first_item(stack);
2211 item = xbt_fifo_get_prev_item(item)) {
2213 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2214 state = (mc_state_t) pair->graph_state;
2216 if(pair->requests > 0){
2218 saved_req = MC_state_get_executed_request(state, &value);
2219 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2221 if(saved_req != NULL){
2222 /* because we got a copy of the executed request, we have to fetch the
2223 real one, pointed by the request field of the issuer process */
2224 req = &saved_req->issuer->simcall;
2225 //XBT_DEBUG("Req->call %u", req->call);
2227 /* Debug information */
2228 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2229 req_str = MC_request_to_string(req, value);
2230 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2236 SIMIX_simcall_pre(req, value);
2237 MC_wait_for_requests();
2242 /* Update statistics */
2243 mc_stats->visited_pairs++;
2244 mc_stats->executed_transitions++;
2248 XBT_DEBUG("**** End Replay ****");
2250 if(initial_state_liveness->raw_mem_set)
2258 * \brief Dumps the contents of a model-checker's stack and shows the actual
2260 * \param stack The stack to dump
2262 void MC_dump_stack_safety(xbt_fifo_t stack)
2265 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2267 MC_show_stack_safety(stack);
2269 if(!_sg_mc_checkpoint){
2274 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2275 MC_state_delete(state);
2288 void MC_show_stack_safety(xbt_fifo_t stack)
2291 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2297 xbt_fifo_item_t item;
2299 char *req_str = NULL;
2301 for (item = xbt_fifo_get_last_item(stack);
2302 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2303 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2304 req = MC_state_get_executed_request(state, &value);
2306 req_str = MC_request_to_string(req, value);
2307 XBT_INFO("%s", req_str);
2316 void MC_show_deadlock(smx_simcall_t req)
2318 /*char *req_str = NULL;*/
2319 XBT_INFO("**************************");
2320 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2321 XBT_INFO("**************************");
2322 XBT_INFO("Locked request:");
2323 /*req_str = MC_request_to_string(req);
2324 XBT_INFO("%s", req_str);
2325 xbt_free(req_str);*/
2326 XBT_INFO("Counter-example execution trace:");
2327 MC_dump_stack_safety(mc_stack_safety);
2328 MC_print_statistics(mc_stats);
2332 void MC_show_stack_liveness(xbt_fifo_t stack){
2335 xbt_fifo_item_t item;
2337 char *req_str = NULL;
2339 for (item = xbt_fifo_get_last_item(stack);
2340 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2341 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2342 req = MC_state_get_executed_request(pair->graph_state, &value);
2344 if(pair->requests>0){
2345 req_str = MC_request_to_string(req, value);
2346 XBT_INFO("%s", req_str);
2349 XBT_INFO("End of system requests but evolution in Büchi automaton");
2355 void MC_dump_stack_liveness(xbt_fifo_t stack){
2357 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2362 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2363 MC_pair_delete(pair);
2372 void MC_print_statistics(mc_stats_t stats)
2374 if(stats->expanded_pairs == 0){
2375 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2376 XBT_INFO("Visited states = %lu", stats->visited_states);
2378 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2379 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2381 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2383 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2384 fprintf(dot_output, "}\n");
2390 void MC_assert(int prop)
2392 if (MC_is_active() && !prop){
2393 XBT_INFO("**************************");
2394 XBT_INFO("*** PROPERTY NOT VALID ***");
2395 XBT_INFO("**************************");
2396 XBT_INFO("Counter-example execution trace:");
2397 MC_dump_stack_safety(mc_stack_safety);
2398 MC_print_statistics(mc_stats);
2404 user_max_depth_reached = 1;
2407 void MC_process_clock_add(smx_process_t process, double amount)
2409 mc_time[process->pid] += amount;
2412 double MC_process_clock_get(smx_process_t process)
2416 return mc_time[process->pid];
2424 void MC_automaton_load(const char *file){
2426 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2430 if (_mc_property_automaton == NULL)
2431 _mc_property_automaton = xbt_automaton_new();
2433 xbt_automaton_load(_mc_property_automaton,file);
2442 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2444 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2448 if (_mc_property_automaton == NULL)
2449 _mc_property_automaton = xbt_automaton_new();
2451 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);