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->local_variables = xbt_dict_new_homogeneous(NULL);
184 res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
185 res->types = xbt_dict_new_homogeneous(NULL);
189 void MC_free_object_info(mc_object_info_t* info) {
190 xbt_free(&(*info)->file_name);
191 xbt_dict_free(&(*info)->local_variables);
192 xbt_dynar_free(&(*info)->global_variables);
193 xbt_dict_free(&(*info)->types);
198 /*************************************************************************/
200 static dw_location_t MC_dwarf_get_location(xbt_dict_t location_list, char *expr){
202 dw_location_t loc = xbt_new0(s_dw_location_t, 1);
204 if(location_list != NULL){
206 char *key = bprintf("%d", (int)strtoul(expr, NULL, 16));
207 loc->type = e_dw_loclist;
208 loc->location.loclist = (xbt_dynar_t)xbt_dict_get_or_null(location_list, key);
209 if(loc->location.loclist == NULL)
210 XBT_INFO("Key not found in loclist");
217 char *tok = NULL, *tok2 = NULL;
219 xbt_dynar_t tokens1 = xbt_str_split(expr, ";");
222 loc->type = e_dw_compose;
223 loc->location.compose = xbt_dynar_new(sizeof(dw_location_t), NULL);
225 while(cursor < xbt_dynar_length(tokens1)){
227 tok = xbt_dynar_get_as(tokens1, cursor, char*);
228 tokens2 = xbt_str_split(tok, " ");
229 tok2 = xbt_dynar_get_as(tokens2, 0, char*);
231 if(strncmp(tok2, "DW_OP_reg", 9) == 0){
232 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
233 new_element->type = e_dw_register;
234 new_element->location.reg = atoi(strtok(tok2, "DW_OP_reg"));
235 xbt_dynar_push(loc->location.compose, &new_element);
236 }else if(strcmp(tok2, "DW_OP_fbreg:") == 0){
237 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
238 new_element->type = e_dw_fbregister_op;
239 new_element->location.fbreg_op = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
240 xbt_dynar_push(loc->location.compose, &new_element);
241 }else if(strncmp(tok2, "DW_OP_breg", 10) == 0){
242 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
243 new_element->type = e_dw_bregister_op;
244 new_element->location.breg_op.reg = atoi(strtok(tok2, "DW_OP_breg"));
245 new_element->location.breg_op.offset = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
246 xbt_dynar_push(loc->location.compose, &new_element);
247 }else if(strncmp(tok2, "DW_OP_lit", 9) == 0){
248 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
249 new_element->type = e_dw_lit;
250 new_element->location.lit = atoi(strtok(tok2, "DW_OP_lit"));
251 xbt_dynar_push(loc->location.compose, &new_element);
252 }else if(strcmp(tok2, "DW_OP_piece:") == 0){
253 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
254 new_element->type = e_dw_piece;
255 new_element->location.piece = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
256 xbt_dynar_push(loc->location.compose, &new_element);
257 }else if(strcmp(tok2, "DW_OP_plus_uconst:") == 0){
258 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
259 new_element->type = e_dw_plus_uconst;
260 new_element->location.plus_uconst = 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(tok, "DW_OP_abs") == 0 ||
263 strcmp(tok, "DW_OP_and") == 0 ||
264 strcmp(tok, "DW_OP_div") == 0 ||
265 strcmp(tok, "DW_OP_minus") == 0 ||
266 strcmp(tok, "DW_OP_mod") == 0 ||
267 strcmp(tok, "DW_OP_mul") == 0 ||
268 strcmp(tok, "DW_OP_neg") == 0 ||
269 strcmp(tok, "DW_OP_not") == 0 ||
270 strcmp(tok, "DW_OP_or") == 0 ||
271 strcmp(tok, "DW_OP_plus") == 0){
272 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
273 new_element->type = e_dw_arithmetic;
274 new_element->location.arithmetic = strdup(strtok(tok2, "DW_OP_"));
275 xbt_dynar_push(loc->location.compose, &new_element);
276 }else if(strcmp(tok, "DW_OP_stack_value") == 0){
277 }else if(strcmp(tok2, "DW_OP_deref_size:") == 0){
278 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
279 new_element->type = e_dw_deref;
280 new_element->location.deref_size = (unsigned int short) atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
281 xbt_dynar_push(loc->location.compose, &new_element);
282 }else if(strcmp(tok, "DW_OP_deref") == 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 = sizeof(void *);
286 xbt_dynar_push(loc->location.compose, &new_element);
287 }else if(strcmp(tok2, "DW_OP_constu:") == 0){
288 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
289 new_element->type = e_dw_uconstant;
290 new_element->location.uconstant.bytes = 1;
291 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
292 xbt_dynar_push(loc->location.compose, &new_element);
293 }else if(strcmp(tok2, "DW_OP_consts:") == 0){
294 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
295 new_element->type = e_dw_sconstant;
296 new_element->location.sconstant.bytes = 1;
297 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
298 xbt_dynar_push(loc->location.compose, &new_element);
299 }else if(strcmp(tok2, "DW_OP_const1u:") == 0 ||
300 strcmp(tok2, "DW_OP_const2u:") == 0 ||
301 strcmp(tok2, "DW_OP_const4u:") == 0 ||
302 strcmp(tok2, "DW_OP_const8u:") == 0){
303 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
304 new_element->type = e_dw_uconstant;
305 new_element->location.uconstant.bytes = tok2[11] - '0';
306 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
307 xbt_dynar_push(loc->location.compose, &new_element);
308 }else if(strcmp(tok, "DW_OP_const1s") == 0 ||
309 strcmp(tok, "DW_OP_const2s") == 0 ||
310 strcmp(tok, "DW_OP_const4s") == 0 ||
311 strcmp(tok, "DW_OP_const8s") == 0){
312 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
313 new_element->type = e_dw_sconstant;
314 new_element->location.sconstant.bytes = tok2[11] - '0';
315 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
316 xbt_dynar_push(loc->location.compose, &new_element);
318 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
319 new_element->type = e_dw_unsupported;
320 xbt_dynar_push(loc->location.compose, &new_element);
324 xbt_dynar_free(&tokens2);
328 xbt_dynar_free(&tokens1);
336 /** @brief Extract the location lists from an ELF file (.debug_loc)
338 * @return A map from the offset in the list (in hexadecimal string)
339 * into a location list (dynar of dw_location_entry_t).
341 static xbt_dict_t MC_dwarf_get_location_list(const char *elf_file){
343 char *command = bprintf("LANG=C objdump -Wo %s", elf_file);
345 FILE *fp = popen(command, "r");
348 perror("popen for objdump failed");
352 int debug = 0; /*Detect if the program has been compiled with -g */
354 xbt_dict_t location_list = xbt_dict_new_homogeneous(NULL);
355 char *line = NULL, *loc_expr = NULL;
359 xbt_dynar_t split = NULL;
361 while ((read = xbt_getline(&line, &n, fp)) != -1) {
363 /* Wipeout the new line character */
364 line[read - 1] = '\0';
366 xbt_str_trim(line, NULL);
371 if(strlen(line) == 0)
376 if(strncmp(line, elf_file, strlen(elf_file)) == 0)
379 if(strncmp(line, "Contents", 8) == 0)
382 if(strncmp(line, "Offset", 6) == 0){
389 XBT_INFO("Your program must be compiled with -g");
393 xbt_dynar_t loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
395 xbt_str_strip_spaces(line);
396 split = xbt_str_split(line, " ");
399 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
401 // Take the key from the first line of the list:
403 key = bprintf("%d", (int)strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
406 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
407 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
408 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
411 while(cursor_remove < 3){
412 xbt_dynar_remove_at(split, 0, NULL);
416 loc_expr = xbt_str_join(split, " ");
417 xbt_str_ltrim(loc_expr, "(");
418 xbt_str_rtrim(loc_expr, ")");
419 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
421 xbt_dynar_push(loclist, &new_entry);
423 xbt_dynar_free(&split);
426 read = xbt_getline(&line, &n, fp);
428 line[read - 1] = '\0';
429 xbt_str_strip_spaces(line);
430 split = xbt_str_split(line, " ");
436 xbt_dict_set(location_list, key, loclist, NULL);
439 xbt_dynar_free(&split);
447 return location_list;
450 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
452 xbt_dict_cursor_t cursor = NULL;
456 xbt_dict_foreach(all_variables, cursor, name, res) {
457 if(offset >= res->start && offset < res->end){
458 xbt_dict_cursor_free(&cursor);
463 xbt_dict_cursor_free(&cursor);
468 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
470 unsigned int cursor = 0;
471 dw_variable_t current_var;
473 xbt_dynar_foreach(frame->variables, cursor, current_var){
474 if(strcmp(var, current_var->name) == 0)
481 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
483 if(xbt_dynar_is_empty(variables))
486 unsigned int cursor = 0;
488 int end = xbt_dynar_length(variables) - 1;
489 dw_variable_t var_test = NULL;
492 cursor = (start + end) / 2;
493 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
494 if(strcmp(var_test->name, var) < 0){
496 }else if(strcmp(var_test->name, var) > 0){
499 if(address){ /* global variable */
500 if(var_test->address.address == address)
502 if(var_test->address.address > address)
506 }else{ /* local variable */
512 if(strcmp(var_test->name, var) == 0){
513 if(address && var_test->address.address < address)
517 }else if(strcmp(var_test->name, var) < 0)
524 static void MC_dwarf_get_variables(mc_object_info_t info){
525 mc_object_info_t result = info;
526 const char *elf_file = info->file_name;
528 xbt_dict_t location_list = MC_dwarf_get_location_list(elf_file);
530 char *command = bprintf("LANG=C objdump -Wi %s", elf_file);
532 FILE *fp = popen(command, "r");
535 perror("popen for objdump failed");
537 xbt_dict_t *local_variables = &result->local_variables;
538 xbt_dynar_t *global_variables = &result->global_variables;
539 xbt_dict_t *types = &result->types;
541 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
542 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
543 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
544 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
545 *parent_value = NULL;
549 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
550 is_pointer = 0, struct_decl = 0, member_end = 0,
551 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
553 xbt_dynar_t split = NULL, split2 = NULL;
555 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
556 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
558 dw_frame_t variable_frame, subroutine_frame = NULL;
560 e_dw_type_type type_type = -1;
562 read = xbt_getline(&line, &n, fp);
566 /* Wipeout the new line character */
567 line[read - 1] = '\0';
569 if(n == 0 || strlen(line) == 0){
570 read = xbt_getline(&line, &n, fp);
574 xbt_str_ltrim(line, NULL);
575 xbt_str_strip_spaces(line);
578 read = xbt_getline(&line, &n, fp);
582 xbt_dynar_free(&split);
583 split = xbt_str_split(line, " ");
586 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
588 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
589 /* We build/complete a dw_frame_t object
590 * and append it if necessary to the local_variables dictionnary */
592 dw_frame_t frame = NULL;
594 strtok(xbt_dynar_get_as(split, 0, char *), "<");
595 subprogram_start = xbt_strdup(strtok(NULL, "<"));
596 xbt_str_rtrim(subprogram_start, ">:");
598 read = xbt_getline(&line, &n, fp);
602 /* Wipeout the new line character */
603 line[read - 1] = '\0';
605 if(n == 0 || strlen(line) == 0){
606 read = xbt_getline(&line, &n, fp);
610 xbt_dynar_free(&split);
611 xbt_str_rtrim(line, NULL);
612 xbt_str_strip_spaces(line);
613 split = xbt_str_split(line, " ");
615 node_type = xbt_dynar_get_as(split, 1, char *);
617 if(strncmp(node_type, "DW_AT_", 6) != 0)
620 if(strcmp(node_type, "DW_AT_sibling") == 0){
622 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
623 xbt_str_ltrim(subprogram_end, "<0x");
624 xbt_str_rtrim(subprogram_end, ">");
626 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
629 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
630 xbt_str_ltrim(abstract_origin, "<0x");
631 xbt_str_rtrim(abstract_origin, ">");
632 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
633 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
634 xbt_free(abstract_origin);
636 }else if(strcmp(node_type, "DW_AT_name") == 0){
639 xbt_free(current_frame);
640 frame = xbt_new0(s_dw_frame_t, 1);
641 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
642 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
643 frame->frame_base = xbt_new0(s_dw_location_t, 1);
644 current_frame = strdup(frame->name);
646 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
648 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
650 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
652 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
654 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
658 xbt_str_strip_spaces(line);
659 split2 = xbt_str_split(line, "(");
660 xbt_dynar_remove_at(split2, 0, NULL);
661 loc_expr = xbt_str_join(split2, " ");
662 xbt_str_rtrim(loc_expr, ")");
663 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
664 xbt_dynar_free(&split2);
669 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
672 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
674 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
677 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
679 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
681 xbt_free(frame->name);
682 xbt_free(current_frame);
683 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
684 current_frame = strdup(frame->name);
685 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
689 read = xbt_getline(&line, &n, fp);
694 frame->start = strtoul(subprogram_start, NULL, 16);
695 if(subprogram_end != NULL)
696 frame->end = strtoul(subprogram_end, NULL, 16);
697 xbt_dict_set(*local_variables, frame->name, frame, NULL);
700 xbt_free(subprogram_start);
701 xbt_free(subprogram_end);
702 subprogram_end = NULL;
705 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
706 /* We build a dw_variable_t object and append it either to
707 the list of variables of the frame (local variable)
708 or to the list of global variables (global variables). */
710 dw_variable_t var = NULL;
712 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
713 parent_value = strtok(parent_value,"<");
714 xbt_str_rtrim(parent_value, ">");
715 parent = atoi(parent_value);
716 xbt_free(parent_value);
721 strtok(xbt_dynar_get_as(split, 0, char *), "<");
722 origin = xbt_strdup(strtok(NULL, "<"));
723 xbt_str_rtrim(origin, ">:");
725 read = xbt_getline(&line, &n, fp);
729 /* Wipeout the new line character */
730 line[read - 1] = '\0';
732 if(n == 0 || strlen(line) == 0){
733 read = xbt_getline(&line, &n, fp);
737 xbt_dynar_free(&split);
738 xbt_str_rtrim(line, NULL);
739 xbt_str_strip_spaces(line);
740 split = xbt_str_split(line, " ");
742 node_type = xbt_dynar_get_as(split, 1, char *);
744 if(strncmp(node_type, "DW_AT_", 6) != 0)
747 if(strcmp(node_type, "DW_AT_name") == 0){
749 var = xbt_new0(s_dw_variable_t, 1);
750 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
751 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
753 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
757 abstract_origin = xbt_dynar_get_as(split, 2, char *);
758 xbt_str_ltrim(abstract_origin, "<0x");
759 xbt_str_rtrim(abstract_origin, ">");
761 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
762 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
763 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
765 }else if(strcmp(node_type, "DW_AT_location") == 0){
769 if(!global_variable){
771 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
773 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
774 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
776 xbt_str_strip_spaces(line);
777 split2 = xbt_str_split(line, "(");
778 xbt_dynar_remove_at(split2, 0, NULL);
779 loc_expr = xbt_str_join(split2, " ");
780 xbt_str_rtrim(loc_expr, ")");
781 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
783 xbt_dynar_free(&split2);
784 split2 = xbt_str_split(loc_expr, " ");
785 if(strcmp(elf_file, xbt_binary_name) != 0)
786 var->address.address = (char *) info->start_text + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
788 // Why is it different ?
789 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
791 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
793 xbt_dynar_free(&split2);
797 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
798 xbt_str_rtrim(global_address, ")");
799 if(strcmp(elf_file, xbt_binary_name) != 0)
800 var->address.address = (char *) info->start_text + (long)((void *)strtoul(global_address, NULL, 16));
802 // Why is it different ?
803 var->address.address = (void *)strtoul(global_address, NULL, 16);
804 xbt_free(global_address);
805 global_address = NULL;
810 }else if(strcmp(node_type, "DW_AT_type") == 0){
812 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
813 xbt_str_ltrim(type_origin, "<0x");
814 xbt_str_rtrim(type_origin, ">");
816 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
820 dw_variable_free(var);
824 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
828 dw_variable_free(var);
834 read = xbt_getline(&line, &n, fp);
838 if(new_variable == 1){
840 if(!global_variable){
841 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
842 var->type_origin = strdup(type_origin);
844 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
846 xbt_dynar_insert_at(variable_frame->variables, index, &var);
848 var->type_origin = strdup(type_origin);
850 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
852 xbt_dynar_insert_at(*global_variables, index, &var);
855 xbt_free(type_origin);
862 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
863 /* Update the information on the frame (we should duplicate it instead). */
865 read = xbt_getline(&line, &n, fp);
869 /* Wipeout the new line character */
870 line[read - 1] = '\0';
872 if(n == 0 || strlen(line) == 0){
873 read = xbt_getline(&line, &n, fp);
877 xbt_dynar_free(&split);
878 xbt_str_rtrim(line, NULL);
879 xbt_str_strip_spaces(line);
880 split = xbt_str_split(line, " ");
882 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
885 node_type = xbt_dynar_get_as(split, 1, char *);
887 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
889 origin = xbt_dynar_get_as(split, 2, char *);
890 xbt_str_ltrim(origin, "<0x");
891 xbt_str_rtrim(origin, ">");
893 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
894 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
896 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
898 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
900 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
902 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
905 read = xbt_getline(&line, &n, fp);
909 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
910 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
911 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
912 || strcmp(node_type, "(DW_TAG_typedef)") == 0
913 || strcmp(node_type, "(DW_TAG_const_type)") == 0
914 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
915 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
916 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
918 /* Create the and add it to the types dictionnary */
920 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
921 type_type = e_dw_base_type;
922 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
923 type_type = e_dw_enumeration_type;
924 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
925 type_type = e_dw_enumerator;
926 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
927 type_type = e_dw_typedef;
928 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
929 type_type = e_dw_const_type;
930 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
931 type_type = e_dw_pointer_type;
932 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
933 type_type = e_dw_subroutine_type;
934 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
935 type_type = e_dw_volatile_type;
937 strtok(xbt_dynar_get_as(split, 0, char *), "<");
938 origin = strdup(strtok(NULL, "<"));
939 xbt_str_rtrim(origin, ">:");
941 read = xbt_getline(&line, &n, fp);
945 /* Wipeout the new line character */
946 line[read - 1] = '\0';
948 if(n == 0 || strlen(line) == 0){
949 read = xbt_getline(&line, &n, fp);
953 xbt_dynar_free(&split);
954 xbt_str_rtrim(line, NULL);
955 xbt_str_strip_spaces(line);
956 split = xbt_str_split(line, " ");
958 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
961 node_type = xbt_dynar_get_as(split, 1, char *);
963 if(strcmp(node_type, "DW_AT_byte_size") == 0){
964 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
965 if(type_type == e_dw_enumeration_type)
966 enumeration_size = size;
967 }else if(strcmp(node_type, "DW_AT_name") == 0){
968 end = xbt_str_join(split, " ");
969 xbt_dynar_free(&split);
970 split = xbt_str_split(end, "):");
971 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
972 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
973 }else if(strcmp(node_type, "DW_AT_type") == 0){
974 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
975 xbt_str_ltrim(type_origin, "<0x");
976 xbt_str_rtrim(type_origin, ">");
979 read = xbt_getline(&line, &n, fp);
982 dw_type_t type = xbt_new0(s_dw_type_t, 1);
983 type->type = type_type;
985 type->name = xbt_strdup(name);
987 type->name = xbt_strdup("undefined");
988 type->is_pointer_type = is_pointer;
989 type->id = (void *)strtoul(origin, NULL, 16);
991 type->dw_type_id = xbt_strdup(type_origin);
992 if(type_type == e_dw_enumerator)
993 type->size = enumeration_size;
996 type->members = NULL;
998 xbt_dict_set(*types, origin, type, NULL);
1002 xbt_free(type_origin);
1011 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
1013 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
1018 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1019 origin = strdup(strtok(NULL, "<"));
1020 xbt_str_rtrim(origin, ">:");
1022 read = xbt_getline(&line, &n, fp);
1024 dw_type_t type = NULL;
1030 /* Wipeout the new line character */
1031 line[read - 1] = '\0';
1033 if(n == 0 || strlen(line) == 0){
1034 read = xbt_getline(&line, &n, fp);
1038 xbt_dynar_free(&split);
1039 xbt_str_rtrim(line, NULL);
1040 xbt_str_strip_spaces(line);
1041 split = xbt_str_split(line, " ");
1043 node_type = xbt_dynar_get_as(split, 1, char *);
1045 if(strncmp(node_type, "DW_AT_", 6) != 0){
1050 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1051 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1052 }else if(strcmp(node_type, "DW_AT_name") == 0){
1054 end = xbt_str_join(split, " ");
1055 xbt_dynar_free(&split);
1056 split = xbt_str_split(end, "):");
1057 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1058 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1059 }else if(strcmp(node_type, "DW_AT_type") == 0){
1060 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1061 xbt_str_ltrim(type_origin, "<0x");
1062 xbt_str_rtrim(type_origin, ">");
1063 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1065 end = xbt_str_join(split, " ");
1066 xbt_dynar_free(&split);
1067 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1068 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1069 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1070 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1073 read = xbt_getline(&line, &n, fp);
1077 if(member_end && type){
1080 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1081 member_type->name = xbt_strdup(name);
1082 member_type->size = size;
1083 member_type->is_pointer_type = is_pointer;
1084 member_type->id = (void *)strtoul(origin, NULL, 16);
1085 member_type->offset = offset;
1087 member_type->dw_type_id = xbt_strdup(type_origin);
1089 xbt_dynar_push(type->members, &member_type);
1095 xbt_free(type_origin);
1102 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1103 origin = strdup(strtok(NULL, "<"));
1104 xbt_str_rtrim(origin, ">:");
1108 if(struct_decl || union_decl){
1109 type = xbt_new0(s_dw_type_t, 1);
1111 type->type = e_dw_structure_type;
1113 type->type = e_dw_union_type;
1114 type->name = xbt_strdup(name);
1116 type->is_pointer_type = is_pointer;
1117 type->id = (void *)strtoul(origin, NULL, 16);
1119 type->dw_type_id = xbt_strdup(type_origin);
1120 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1122 xbt_dict_set(*types, origin, type, NULL);
1128 xbt_free(type_origin);
1136 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1139 read = xbt_getline(&line, &n, fp);
1146 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1148 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1149 origin = strdup(strtok(NULL, "<"));
1150 xbt_str_rtrim(origin, ">:");
1152 read = xbt_getline(&line, &n, fp);
1154 dw_type_t type = NULL;
1160 /* Wipeout the new line character */
1161 line[read - 1] = '\0';
1163 if(n == 0 || strlen(line) == 0){
1164 read = xbt_getline(&line, &n, fp);
1168 xbt_dynar_free(&split);
1169 xbt_str_rtrim(line, NULL);
1170 xbt_str_strip_spaces(line);
1171 split = xbt_str_split(line, " ");
1173 node_type = xbt_dynar_get_as(split, 1, char *);
1175 if(strncmp(node_type, "DW_AT_", 6) != 0)
1178 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1179 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1180 }else if(strcmp(node_type, "DW_AT_name") == 0){
1181 end = xbt_str_join(split, " ");
1182 xbt_dynar_free(&split);
1183 split = xbt_str_split(end, "):");
1184 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1185 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1186 }else if(strcmp(node_type, "DW_AT_type") == 0){
1187 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1188 xbt_str_ltrim(type_origin, "<0x");
1189 xbt_str_rtrim(type_origin, ">");
1192 read = xbt_getline(&line, &n, fp);
1196 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1200 if(subrange && type){
1207 xbt_free(type_origin);
1213 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1214 origin = strdup(strtok(NULL, "<"));
1215 xbt_str_rtrim(origin, ">:");
1219 type = xbt_new0(s_dw_type_t, 1);
1220 type->type = e_dw_array_type;
1221 type->name = xbt_strdup(name);
1222 type->is_pointer_type = is_pointer;
1223 type->id = (void *)strtoul(origin, NULL, 16);
1225 type->dw_type_id = xbt_strdup(type_origin);
1226 type->members = NULL;
1228 xbt_dict_set(*types, origin, type, NULL);
1234 xbt_free(type_origin);
1239 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1242 read = xbt_getline(&line, &n, fp);
1251 read = xbt_getline(&line, &n, fp);
1257 xbt_dynar_free(&split);
1258 xbt_dict_free(&variables_origin);
1259 xbt_dict_free(&subprograms_origin);
1262 xbt_dict_free(&location_list);
1268 /******************************* Ignore mechanism *******************************/
1269 /*********************************************************************************/
1271 xbt_dynar_t mc_checkpoint_ignore;
1273 typedef struct s_mc_stack_ignore_variable{
1276 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1278 typedef struct s_mc_data_bss_ignore_variable{
1280 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1282 /**************************** Free functions ******************************/
1284 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1285 xbt_free(v->var_name);
1290 static void stack_ignore_variable_free_voidp(void *v){
1291 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1294 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1298 void heap_ignore_region_free_voidp(void *r){
1299 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1302 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1307 static void data_bss_ignore_variable_free_voidp(void *v){
1308 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1311 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1315 static void checkpoint_ignore_region_free_voidp(void *r){
1316 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1319 /***********************************************************************/
1321 void MC_ignore_heap(void *address, size_t size){
1323 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1327 mc_heap_ignore_region_t region = NULL;
1328 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1329 region->address = address;
1330 region->size = size;
1332 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1334 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1335 region->fragment = -1;
1336 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1338 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1339 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1342 if(mc_heap_comparison_ignore == NULL){
1343 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1344 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1350 unsigned int cursor = 0;
1351 mc_heap_ignore_region_t current_region = NULL;
1353 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1355 while(start <= end){
1356 cursor = (start + end) / 2;
1357 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1358 if(current_region->address == address){
1359 heap_ignore_region_free(region);
1363 }else if(current_region->address < address){
1370 if(current_region->address < address)
1371 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1373 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1379 void MC_remove_ignore_heap(void *address, size_t size){
1381 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1385 unsigned int cursor = 0;
1387 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1388 mc_heap_ignore_region_t region;
1389 int ignore_found = 0;
1391 while(start <= end){
1392 cursor = (start + end) / 2;
1393 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1394 if(region->address == address){
1397 }else if(region->address < address){
1400 if((char * )region->address <= ((char *)address + size)){
1409 if(ignore_found == 1){
1410 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1411 MC_remove_ignore_heap(address, size);
1419 void MC_ignore_global_variable(const char *name){
1421 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1425 if(mc_libsimgrid_info){
1427 unsigned int cursor = 0;
1428 dw_variable_t current_var;
1430 int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1432 while(start <= end){
1433 cursor = (start + end) /2;
1434 current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
1435 if(strcmp(current_var->name, name) == 0){
1436 xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
1438 end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1439 }else if(strcmp(current_var->name, name) < 0){
1448 if(mc_data_bss_comparison_ignore == NULL)
1449 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1451 mc_data_bss_ignore_variable_t var = NULL;
1452 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1453 var->name = strdup(name);
1455 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1457 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1461 unsigned int cursor = 0;
1463 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1464 mc_data_bss_ignore_variable_t current_var = NULL;
1466 while(start <= end){
1467 cursor = (start + end) / 2;
1468 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1469 if(strcmp(current_var->name, name) == 0){
1470 data_bss_ignore_variable_free(var);
1474 }else if(strcmp(current_var->name, name) < 0){
1481 if(strcmp(current_var->name, name) < 0)
1482 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1484 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1493 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1495 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1499 if(mc_libsimgrid_info){
1500 unsigned int cursor = 0;
1501 dw_variable_t current_var;
1503 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1504 xbt_dict_cursor_t dict_cursor;
1505 char *current_frame_name;
1507 xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
1509 end = xbt_dynar_length(frame->variables) - 1;
1510 while(start <= end){
1511 cursor = (start + end) / 2;
1512 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1513 if(strcmp(current_var->name, var_name) == 0){
1514 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1516 end = xbt_dynar_length(frame->variables) - 1;
1517 }else if(strcmp(current_var->name, var_name) < 0){
1524 xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
1526 end = xbt_dynar_length(frame->variables) - 1;
1527 while(start <= end){
1528 cursor = (start + end) / 2;
1529 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1530 if(strcmp(current_var->name, var_name) == 0){
1531 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1533 end = xbt_dynar_length(frame->variables) - 1;
1534 }else if(strcmp(current_var->name, var_name) < 0){
1542 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
1543 mc_libsimgrid_info->local_variables, frame_name))->variables;
1545 end = xbt_dynar_length(variables_list) - 1;
1546 while(start <= end){
1547 cursor = (start + end) / 2;
1548 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1549 if(strcmp(current_var->name, var_name) == 0){
1550 xbt_dynar_remove_at(variables_list, cursor, NULL);
1552 end = xbt_dynar_length(variables_list) - 1;
1553 }else if(strcmp(current_var->name, var_name) < 0){
1562 if(mc_stack_comparison_ignore == NULL)
1563 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1565 mc_stack_ignore_variable_t var = NULL;
1566 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1567 var->var_name = strdup(var_name);
1568 var->frame = strdup(frame_name);
1570 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1572 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1576 unsigned int cursor = 0;
1578 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1579 mc_stack_ignore_variable_t current_var = NULL;
1581 while(start <= end){
1582 cursor = (start + end) / 2;
1583 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1584 if(strcmp(current_var->frame, frame_name) == 0){
1585 if(strcmp(current_var->var_name, var_name) == 0){
1586 stack_ignore_variable_free(var);
1590 }else if(strcmp(current_var->var_name, var_name) < 0){
1595 }else if(strcmp(current_var->frame, frame_name) < 0){
1602 if(strcmp(current_var->frame, frame_name) == 0){
1603 if(strcmp(current_var->var_name, var_name) < 0){
1604 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1606 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1608 }else if(strcmp(current_var->frame, frame_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);
1621 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1623 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1627 if(stacks_areas == NULL)
1628 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1630 stack_region_t region = NULL;
1631 region = xbt_new0(s_stack_region_t, 1);
1632 region->address = stack;
1633 region->process_name = strdup(name);
1634 region->context = context;
1635 region->size = size;
1636 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1637 xbt_dynar_push(stacks_areas, ®ion);
1643 void MC_ignore(void *addr, size_t size){
1645 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1649 if(mc_checkpoint_ignore == NULL)
1650 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1652 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1653 region->addr = addr;
1654 region->size = size;
1656 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1657 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1660 unsigned int cursor = 0;
1662 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1663 mc_checkpoint_ignore_region_t current_region = NULL;
1665 while(start <= end){
1666 cursor = (start + end) / 2;
1667 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1668 if(current_region->addr == addr){
1669 if(current_region->size == size){
1670 checkpoint_ignore_region_free(region);
1674 }else if(current_region->size < size){
1679 }else if(current_region->addr < addr){
1686 if(current_region->addr == addr){
1687 if(current_region->size < size){
1688 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1690 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1692 }else if(current_region->addr < addr){
1693 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1695 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1703 /******************************* Initialisation of MC *******************************/
1704 /*********************************************************************************/
1706 static void MC_dump_ignored_local_variables(void){
1708 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1711 unsigned int cursor = 0;
1712 mc_stack_ignore_variable_t current_var;
1714 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1715 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1718 xbt_dynar_free(&mc_stack_comparison_ignore);
1719 mc_stack_comparison_ignore = NULL;
1723 static void MC_dump_ignored_global_variables(void){
1725 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1728 unsigned int cursor = 0;
1729 mc_data_bss_ignore_variable_t current_var;
1731 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1732 MC_ignore_global_variable(current_var->name);
1735 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1736 mc_data_bss_comparison_ignore = NULL;
1742 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1746 /* Initialize the data structures that must be persistent across every
1747 iteration of the model-checker (in RAW memory) */
1751 MC_init_memory_map_info();
1753 XBT_INFO("Get debug information ...");
1755 memory_map_t maps = MC_get_memory_map();
1757 /* Get local variables for state equality detection */
1759 mc_binary_info = MC_find_object_address(maps, xbt_binary_name);
1760 MC_dwarf_get_variables(mc_binary_info);
1762 mc_libsimgrid_info = MC_find_object_address(maps, libsimgrid_path);
1763 MC_dwarf_get_variables(mc_libsimgrid_info);
1765 XBT_INFO("Get debug information done !");
1767 /* Remove variables ignored before getting list of variables */
1768 MC_dump_ignored_local_variables();
1769 MC_dump_ignored_global_variables();
1771 /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
1772 MC_get_libsimgrid_plt_section();
1773 MC_get_binary_plt_section();
1776 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1778 MC_free_memory_map(maps);
1782 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1783 MC_ignore_local_variable("e", "*");
1784 MC_ignore_local_variable("__ex_cleanup", "*");
1785 MC_ignore_local_variable("__ex_mctx_en", "*");
1786 MC_ignore_local_variable("__ex_mctx_me", "*");
1787 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1788 MC_ignore_local_variable("_log_ev", "*");
1789 MC_ignore_local_variable("_throw_ctx", "*");
1790 MC_ignore_local_variable("ctx", "*");
1792 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1793 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1795 /* Ignore local variable about time used for tracing */
1796 MC_ignore_local_variable("start_time", "*");
1798 MC_ignore_global_variable("mc_comp_times");
1799 MC_ignore_global_variable("mc_snapshot_comparison_time");
1800 MC_ignore_global_variable("mc_time");
1801 MC_ignore_global_variable("smpi_current_rank");
1802 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1803 MC_ignore_global_variable("maestro_stack_start");
1804 MC_ignore_global_variable("maestro_stack_end");
1806 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1807 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1808 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1809 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1811 smx_process_t process;
1812 xbt_swag_foreach(process, simix_global->process_list){
1813 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1821 static void MC_init_dot_output(){ /* FIXME : more colors */
1825 colors[2] = "green3";
1826 colors[3] = "goldenrod";
1827 colors[4] = "brown";
1828 colors[5] = "purple";
1829 colors[6] = "magenta";
1830 colors[7] = "turquoise4";
1831 colors[8] = "gray25";
1832 colors[9] = "forestgreen";
1833 colors[10] = "hotpink";
1834 colors[11] = "lightblue";
1837 dot_output = fopen(_sg_mc_dot_output_file, "w");
1839 if(dot_output == NULL){
1840 perror("Error open dot output file");
1844 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");
1848 /******************************* Core of MC *******************************/
1849 /**************************************************************************/
1851 void MC_do_the_modelcheck_for_real() {
1854 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1857 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1858 if (mc_reduce_kind==e_mc_reduce_unset)
1859 mc_reduce_kind=e_mc_reduce_dpor;
1861 XBT_INFO("Check a safety property");
1862 MC_modelcheck_safety();
1866 if (mc_reduce_kind==e_mc_reduce_unset)
1867 mc_reduce_kind=e_mc_reduce_none;
1869 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1870 MC_automaton_load(_sg_mc_property_file);
1871 MC_modelcheck_liveness();
1875 void MC_modelcheck_safety(void)
1877 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1879 /* Check if MC is already initialized */
1880 if (initial_state_safety)
1883 mc_time = xbt_new0(double, simix_process_maxpid);
1885 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1886 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1888 /* Initialize the data structures that must be persistent across every
1889 iteration of the model-checker (in RAW memory) */
1893 /* Initialize statistics */
1894 mc_stats = xbt_new0(s_mc_stats_t, 1);
1895 mc_stats->state_size = 1;
1897 /* Create exploration stack */
1898 mc_stack_safety = xbt_fifo_new();
1900 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1901 MC_init_dot_output();
1905 if(_sg_mc_visited > 0){
1909 MC_init_memory_map_info();
1910 MC_get_libsimgrid_plt_section();
1911 MC_get_binary_plt_section();
1918 /* Save the initial state */
1919 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1920 initial_state_safety->snapshot = MC_take_snapshot(0);
1932 void MC_modelcheck_liveness(){
1934 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1938 mc_time = xbt_new0(double, simix_process_maxpid);
1940 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1941 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1945 /* Initialize statistics */
1946 mc_stats = xbt_new0(s_mc_stats_t, 1);
1947 mc_stats->state_size = 1;
1949 /* Create exploration stack */
1950 mc_stack_liveness = xbt_fifo_new();
1952 /* Create the initial state */
1953 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1955 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1956 MC_init_dot_output();
1963 MC_print_statistics(mc_stats);
1979 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1981 return simcall->mc_value;
1985 int MC_random(int min, int max)
1987 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1988 return simcall_mc_random(min, max);
1992 * \brief Schedules all the process that are ready to run
1994 void MC_wait_for_requests(void)
1996 smx_process_t process;
2000 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
2001 SIMIX_process_runall();
2002 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
2003 req = &process->simcall;
2004 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
2005 SIMIX_simcall_pre(req, 0);
2010 int MC_deadlock_check()
2012 int deadlock = FALSE;
2013 smx_process_t process;
2014 if(xbt_swag_size(simix_global->process_list)){
2016 xbt_swag_foreach(process, simix_global->process_list){
2017 if(process->simcall.call != SIMCALL_NONE
2018 && MC_request_is_enabled(&process->simcall)){
2028 * \brief Re-executes from the state at position start all the transitions indicated by
2029 * a given model-checker stack.
2030 * \param stack The stack with the transitions to execute.
2031 * \param start Start index to begin the re-execution.
2033 void MC_replay(xbt_fifo_t stack, int start)
2035 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2037 int value, i = 1, count = 1;
2039 smx_simcall_t req = NULL, saved_req = NULL;
2040 xbt_fifo_item_t item, start_item;
2042 smx_process_t process = NULL;
2044 XBT_DEBUG("**** Begin Replay ****");
2047 /* Restore the initial state */
2048 MC_restore_snapshot(initial_state_safety->snapshot);
2049 /* At the moment of taking the snapshot the raw heap was set, so restoring
2050 * it will set it back again, we have to unset it to continue */
2054 start_item = xbt_fifo_get_last_item(stack);
2057 start_item = xbt_fifo_get_prev_item(start_item);
2063 xbt_dict_reset(first_enabled_state);
2064 xbt_swag_foreach(process, simix_global->process_list){
2065 if(MC_process_is_enabled(process)){
2066 char *key = bprintf("%lu", process->pid);
2067 char *data = bprintf("%d", count);
2068 xbt_dict_set(first_enabled_state, key, data, NULL);
2075 /* Traverse the stack from the state at position start and re-execute the transitions */
2076 for (item = start_item;
2077 item != xbt_fifo_get_first_item(stack);
2078 item = xbt_fifo_get_prev_item(item)) {
2080 state = (mc_state_t) xbt_fifo_get_item_content(item);
2081 saved_req = MC_state_get_executed_request(state, &value);
2084 char *key = bprintf("%lu", saved_req->issuer->pid);
2085 xbt_dict_remove(first_enabled_state, key);
2090 /* because we got a copy of the executed request, we have to fetch the
2091 real one, pointed by the request field of the issuer process */
2092 req = &saved_req->issuer->simcall;
2094 /* Debug information */
2095 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2096 req_str = MC_request_to_string(req, value);
2097 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2102 SIMIX_simcall_pre(req, value);
2103 MC_wait_for_requests();
2108 /* Insert in dict all enabled processes */
2109 xbt_swag_foreach(process, simix_global->process_list){
2110 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2111 char *key = bprintf("%lu", process->pid);
2112 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2113 char *data = bprintf("%d", count);
2114 xbt_dict_set(first_enabled_state, key, data, NULL);
2121 /* Update statistics */
2122 mc_stats->visited_states++;
2123 mc_stats->executed_transitions++;
2127 XBT_DEBUG("**** End Replay ****");
2137 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2140 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2144 smx_simcall_t req = NULL, saved_req = NULL;
2145 xbt_fifo_item_t item;
2150 XBT_DEBUG("**** Begin Replay ****");
2152 /* Restore the initial state */
2153 MC_restore_snapshot(initial_state_liveness->snapshot);
2155 /* At the moment of taking the snapshot the raw heap was set, so restoring
2156 * it will set it back again, we have to unset it to continue */
2157 if(!initial_state_liveness->raw_mem_set)
2162 item = xbt_fifo_get_last_item(stack);
2164 while(depth <= xbt_fifo_size(stack)){
2166 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2167 state = (mc_state_t) pair->graph_state;
2169 if(pair->requests > 0){
2171 saved_req = MC_state_get_executed_request(state, &value);
2172 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2174 if(saved_req != NULL){
2175 /* because we got a copy of the executed request, we have to fetch the
2176 real one, pointed by the request field of the issuer process */
2177 req = &saved_req->issuer->simcall;
2178 //XBT_DEBUG("Req->call %u", req->call);
2180 /* Debug information */
2181 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2182 req_str = MC_request_to_string(req, value);
2183 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2189 SIMIX_simcall_pre(req, value);
2190 MC_wait_for_requests();
2195 /* Update statistics */
2196 mc_stats->visited_pairs++;
2197 mc_stats->executed_transitions++;
2199 item = xbt_fifo_get_prev_item(item);
2204 /* Traverse the stack from the initial state and re-execute the transitions */
2205 for (item = xbt_fifo_get_last_item(stack);
2206 item != xbt_fifo_get_first_item(stack);
2207 item = xbt_fifo_get_prev_item(item)) {
2209 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2210 state = (mc_state_t) pair->graph_state;
2212 if(pair->requests > 0){
2214 saved_req = MC_state_get_executed_request(state, &value);
2215 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2217 if(saved_req != NULL){
2218 /* because we got a copy of the executed request, we have to fetch the
2219 real one, pointed by the request field of the issuer process */
2220 req = &saved_req->issuer->simcall;
2221 //XBT_DEBUG("Req->call %u", req->call);
2223 /* Debug information */
2224 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2225 req_str = MC_request_to_string(req, value);
2226 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2232 SIMIX_simcall_pre(req, value);
2233 MC_wait_for_requests();
2238 /* Update statistics */
2239 mc_stats->visited_pairs++;
2240 mc_stats->executed_transitions++;
2244 XBT_DEBUG("**** End Replay ****");
2246 if(initial_state_liveness->raw_mem_set)
2254 * \brief Dumps the contents of a model-checker's stack and shows the actual
2256 * \param stack The stack to dump
2258 void MC_dump_stack_safety(xbt_fifo_t stack)
2261 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2263 MC_show_stack_safety(stack);
2265 if(!_sg_mc_checkpoint){
2270 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2271 MC_state_delete(state);
2284 void MC_show_stack_safety(xbt_fifo_t stack)
2287 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2293 xbt_fifo_item_t item;
2295 char *req_str = NULL;
2297 for (item = xbt_fifo_get_last_item(stack);
2298 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2299 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2300 req = MC_state_get_executed_request(state, &value);
2302 req_str = MC_request_to_string(req, value);
2303 XBT_INFO("%s", req_str);
2312 void MC_show_deadlock(smx_simcall_t req)
2314 /*char *req_str = NULL;*/
2315 XBT_INFO("**************************");
2316 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2317 XBT_INFO("**************************");
2318 XBT_INFO("Locked request:");
2319 /*req_str = MC_request_to_string(req);
2320 XBT_INFO("%s", req_str);
2321 xbt_free(req_str);*/
2322 XBT_INFO("Counter-example execution trace:");
2323 MC_dump_stack_safety(mc_stack_safety);
2324 MC_print_statistics(mc_stats);
2328 void MC_show_stack_liveness(xbt_fifo_t stack){
2331 xbt_fifo_item_t item;
2333 char *req_str = NULL;
2335 for (item = xbt_fifo_get_last_item(stack);
2336 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2337 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2338 req = MC_state_get_executed_request(pair->graph_state, &value);
2340 if(pair->requests>0){
2341 req_str = MC_request_to_string(req, value);
2342 XBT_INFO("%s", req_str);
2345 XBT_INFO("End of system requests but evolution in Büchi automaton");
2351 void MC_dump_stack_liveness(xbt_fifo_t stack){
2353 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2358 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2359 MC_pair_delete(pair);
2368 void MC_print_statistics(mc_stats_t stats)
2370 if(stats->expanded_pairs == 0){
2371 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2372 XBT_INFO("Visited states = %lu", stats->visited_states);
2374 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2375 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2377 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2379 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2380 fprintf(dot_output, "}\n");
2386 void MC_assert(int prop)
2388 if (MC_is_active() && !prop){
2389 XBT_INFO("**************************");
2390 XBT_INFO("*** PROPERTY NOT VALID ***");
2391 XBT_INFO("**************************");
2392 XBT_INFO("Counter-example execution trace:");
2393 MC_dump_stack_safety(mc_stack_safety);
2394 MC_print_statistics(mc_stats);
2400 user_max_depth_reached = 1;
2403 void MC_process_clock_add(smx_process_t process, double amount)
2405 mc_time[process->pid] += amount;
2408 double MC_process_clock_get(smx_process_t process)
2412 return mc_time[process->pid];
2420 void MC_automaton_load(const char *file){
2422 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2426 if (_mc_property_automaton == NULL)
2427 _mc_property_automaton = xbt_automaton_new();
2429 xbt_automaton_load(_mc_property_automaton,file);
2438 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2440 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2444 if (_mc_property_automaton == NULL)
2445 _mc_property_automaton = xbt_automaton_new();
2447 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);