1 /* Copyright (c) 2008-2013. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "simgrid/sg_config.h"
13 #include "../surf/surf_private.h"
14 #include "../simix/smx_private.h"
15 #include "../xbt/mmalloc/mmprivate.h"
17 #include "mc_private.h"
18 #include "xbt/automaton.h"
21 XBT_LOG_NEW_CATEGORY(mc, "All MC categories");
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
23 "Logging specific to MC (global)");
25 /* Configuration support */
26 e_mc_reduce_t mc_reduce_kind=e_mc_reduce_unset;
28 int _sg_do_model_check = 0;
29 int _sg_mc_checkpoint=0;
30 char* _sg_mc_property_file=NULL;
32 int _sg_mc_max_depth=1000;
34 char *_sg_mc_dot_output_file = NULL;
36 int user_max_depth_reached = 0;
38 void _mc_cfg_cb_reduce(const char *name, int pos) {
39 if (_sg_cfg_init_status && !_sg_do_model_check) {
40 xbt_die("You are specifying a reduction strategy after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
42 char *val= xbt_cfg_get_string(_sg_cfg_set, name);
43 if (!strcasecmp(val,"none")) {
44 mc_reduce_kind = e_mc_reduce_none;
45 } else if (!strcasecmp(val,"dpor")) {
46 mc_reduce_kind = e_mc_reduce_dpor;
48 xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",name);
52 void _mc_cfg_cb_checkpoint(const char *name, int pos) {
53 if (_sg_cfg_init_status && !_sg_do_model_check) {
54 xbt_die("You are specifying a checkpointing value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
56 _sg_mc_checkpoint = xbt_cfg_get_int(_sg_cfg_set, name);
58 void _mc_cfg_cb_property(const char *name, int pos) {
59 if (_sg_cfg_init_status && !_sg_do_model_check) {
60 xbt_die("You are specifying a property after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
62 _sg_mc_property_file= xbt_cfg_get_string(_sg_cfg_set, name);
65 void _mc_cfg_cb_timeout(const char *name, int pos) {
66 if (_sg_cfg_init_status && !_sg_do_model_check) {
67 xbt_die("You are specifying a value to enable/disable timeout for wait requests after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
69 _sg_mc_timeout= xbt_cfg_get_boolean(_sg_cfg_set, name);
72 void _mc_cfg_cb_max_depth(const char *name, int pos) {
73 if (_sg_cfg_init_status && !_sg_do_model_check) {
74 xbt_die("You are specifying a max depth value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
76 _sg_mc_max_depth= xbt_cfg_get_int(_sg_cfg_set, name);
79 void _mc_cfg_cb_visited(const char *name, int pos) {
80 if (_sg_cfg_init_status && !_sg_do_model_check) {
81 xbt_die("You are specifying a number of stored visited states after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
83 _sg_mc_visited= xbt_cfg_get_int(_sg_cfg_set, name);
86 void _mc_cfg_cb_dot_output(const char *name, int pos) {
87 if (_sg_cfg_init_status && !_sg_do_model_check) {
88 xbt_die("You are specifying a file name for a dot output of graph state after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
90 _sg_mc_dot_output_file= xbt_cfg_get_string(_sg_cfg_set, name);
93 /* MC global data structures */
94 mc_state_t mc_current_state = NULL;
95 char mc_replay_mode = FALSE;
96 double *mc_time = NULL;
97 __thread mc_comparison_times_t mc_comp_times = NULL;
98 __thread double mc_snapshot_comparison_time;
99 mc_stats_t mc_stats = NULL;
102 xbt_fifo_t mc_stack_safety = NULL;
103 mc_global_t initial_state_safety = NULL;
106 xbt_fifo_t mc_stack_liveness = NULL;
107 mc_global_t initial_state_liveness = NULL;
110 xbt_automaton_t _mc_property_automaton = NULL;
113 mc_object_info_t mc_libsimgrid_info = NULL;
114 mc_object_info_t mc_binary_info = NULL;
116 /* Ignore mechanism */
117 xbt_dynar_t mc_stack_comparison_ignore;
118 xbt_dynar_t mc_data_bss_comparison_ignore;
119 extern xbt_dynar_t mc_heap_comparison_ignore;
120 extern xbt_dynar_t stacks_areas;
123 FILE *dot_output = NULL;
124 const char* colors[13];
127 /******************************* DWARF Information *******************************/
128 /**********************************************************************************/
130 /************************** Free functions *************************/
132 static void dw_location_free(dw_location_t l){
134 if(l->type == e_dw_loclist)
135 xbt_dynar_free(&(l->location.loclist));
136 else if(l->type == e_dw_compose)
137 xbt_dynar_free(&(l->location.compose));
138 else if(l->type == e_dw_arithmetic)
139 xbt_free(l->location.arithmetic);
145 static void dw_location_entry_free(dw_location_entry_t e){
146 dw_location_free(e->location);
150 static void dw_type_free(dw_type_t t){
152 xbt_free(t->dw_type_id);
153 xbt_dynar_free(&(t->members));
157 static void dw_type_free_voidp(void *t){
158 dw_type_free((dw_type_t) * (void **) t);
161 static void dw_variable_free(dw_variable_t v){
164 xbt_free(v->type_origin);
166 dw_location_free(v->address.location);
171 static void dw_variable_free_voidp(void *t){
172 dw_variable_free((dw_variable_t) * (void **) t);
177 mc_object_info_t MC_new_object_info() {
178 mc_object_info_t res = xbt_new(s_mc_object_info_t, 1);
179 res->file_name = NULL;
180 res->local_variables = xbt_dict_new_homogeneous(NULL);
181 res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
182 res->types = xbt_dict_new_homogeneous(NULL);
186 void MC_free_object_info(mc_object_info_t* info) {
187 xbt_free(&(*info)->file_name);
188 xbt_dict_free(&(*info)->local_variables);
189 xbt_dynar_free(&(*info)->global_variables);
190 xbt_dict_free(&(*info)->types);
195 /*************************************************************************/
197 static dw_location_t MC_dwarf_get_location(xbt_dict_t location_list, char *expr){
199 dw_location_t loc = xbt_new0(s_dw_location_t, 1);
201 if(location_list != NULL){
203 char *key = bprintf("%d", (int)strtoul(expr, NULL, 16));
204 loc->type = e_dw_loclist;
205 loc->location.loclist = (xbt_dynar_t)xbt_dict_get_or_null(location_list, key);
206 if(loc->location.loclist == NULL)
207 XBT_INFO("Key not found in loclist");
214 char *tok = NULL, *tok2 = NULL;
216 xbt_dynar_t tokens1 = xbt_str_split(expr, ";");
219 loc->type = e_dw_compose;
220 loc->location.compose = xbt_dynar_new(sizeof(dw_location_t), NULL);
222 while(cursor < xbt_dynar_length(tokens1)){
224 tok = xbt_dynar_get_as(tokens1, cursor, char*);
225 tokens2 = xbt_str_split(tok, " ");
226 tok2 = xbt_dynar_get_as(tokens2, 0, char*);
228 if(strncmp(tok2, "DW_OP_reg", 9) == 0){
229 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
230 new_element->type = e_dw_register;
231 new_element->location.reg = atoi(strtok(tok2, "DW_OP_reg"));
232 xbt_dynar_push(loc->location.compose, &new_element);
233 }else if(strcmp(tok2, "DW_OP_fbreg:") == 0){
234 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
235 new_element->type = e_dw_fbregister_op;
236 new_element->location.fbreg_op = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
237 xbt_dynar_push(loc->location.compose, &new_element);
238 }else if(strncmp(tok2, "DW_OP_breg", 10) == 0){
239 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
240 new_element->type = e_dw_bregister_op;
241 new_element->location.breg_op.reg = atoi(strtok(tok2, "DW_OP_breg"));
242 new_element->location.breg_op.offset = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
243 xbt_dynar_push(loc->location.compose, &new_element);
244 }else if(strncmp(tok2, "DW_OP_lit", 9) == 0){
245 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
246 new_element->type = e_dw_lit;
247 new_element->location.lit = atoi(strtok(tok2, "DW_OP_lit"));
248 xbt_dynar_push(loc->location.compose, &new_element);
249 }else if(strcmp(tok2, "DW_OP_piece:") == 0){
250 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
251 new_element->type = e_dw_piece;
252 new_element->location.piece = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
253 xbt_dynar_push(loc->location.compose, &new_element);
254 }else if(strcmp(tok2, "DW_OP_plus_uconst:") == 0){
255 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
256 new_element->type = e_dw_plus_uconst;
257 new_element->location.plus_uconst = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char *));
258 xbt_dynar_push(loc->location.compose, &new_element);
259 }else if(strcmp(tok, "DW_OP_abs") == 0 ||
260 strcmp(tok, "DW_OP_and") == 0 ||
261 strcmp(tok, "DW_OP_div") == 0 ||
262 strcmp(tok, "DW_OP_minus") == 0 ||
263 strcmp(tok, "DW_OP_mod") == 0 ||
264 strcmp(tok, "DW_OP_mul") == 0 ||
265 strcmp(tok, "DW_OP_neg") == 0 ||
266 strcmp(tok, "DW_OP_not") == 0 ||
267 strcmp(tok, "DW_OP_or") == 0 ||
268 strcmp(tok, "DW_OP_plus") == 0){
269 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
270 new_element->type = e_dw_arithmetic;
271 new_element->location.arithmetic = strdup(strtok(tok2, "DW_OP_"));
272 xbt_dynar_push(loc->location.compose, &new_element);
273 }else if(strcmp(tok, "DW_OP_stack_value") == 0){
274 }else if(strcmp(tok2, "DW_OP_deref_size:") == 0){
275 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
276 new_element->type = e_dw_deref;
277 new_element->location.deref_size = (unsigned int short) atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
278 xbt_dynar_push(loc->location.compose, &new_element);
279 }else if(strcmp(tok, "DW_OP_deref") == 0){
280 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
281 new_element->type = e_dw_deref;
282 new_element->location.deref_size = sizeof(void *);
283 xbt_dynar_push(loc->location.compose, &new_element);
284 }else if(strcmp(tok2, "DW_OP_constu:") == 0){
285 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
286 new_element->type = e_dw_uconstant;
287 new_element->location.uconstant.bytes = 1;
288 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
289 xbt_dynar_push(loc->location.compose, &new_element);
290 }else if(strcmp(tok2, "DW_OP_consts:") == 0){
291 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
292 new_element->type = e_dw_sconstant;
293 new_element->location.sconstant.bytes = 1;
294 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
295 xbt_dynar_push(loc->location.compose, &new_element);
296 }else if(strcmp(tok2, "DW_OP_const1u:") == 0 ||
297 strcmp(tok2, "DW_OP_const2u:") == 0 ||
298 strcmp(tok2, "DW_OP_const4u:") == 0 ||
299 strcmp(tok2, "DW_OP_const8u:") == 0){
300 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
301 new_element->type = e_dw_uconstant;
302 new_element->location.uconstant.bytes = tok2[11] - '0';
303 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
304 xbt_dynar_push(loc->location.compose, &new_element);
305 }else if(strcmp(tok, "DW_OP_const1s") == 0 ||
306 strcmp(tok, "DW_OP_const2s") == 0 ||
307 strcmp(tok, "DW_OP_const4s") == 0 ||
308 strcmp(tok, "DW_OP_const8s") == 0){
309 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
310 new_element->type = e_dw_sconstant;
311 new_element->location.sconstant.bytes = tok2[11] - '0';
312 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
313 xbt_dynar_push(loc->location.compose, &new_element);
315 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
316 new_element->type = e_dw_unsupported;
317 xbt_dynar_push(loc->location.compose, &new_element);
321 xbt_dynar_free(&tokens2);
325 xbt_dynar_free(&tokens1);
333 /** @brief Extract the location lists from an ELF file (.debug_loc)
335 * @return A map from the offset in the list (in hexadecimal string)
336 * into a location list (dynar of dw_location_entry_t).
338 static xbt_dict_t MC_dwarf_get_location_list(const char *elf_file){
340 char *command = bprintf("LANG=C objdump -Wo %s", elf_file);
342 FILE *fp = popen(command, "r");
345 perror("popen for objdump failed");
349 int debug = 0; /*Detect if the program has been compiled with -g */
351 xbt_dict_t location_list = xbt_dict_new_homogeneous(NULL);
352 char *line = NULL, *loc_expr = NULL;
356 xbt_dynar_t split = NULL;
358 while ((read = xbt_getline(&line, &n, fp)) != -1) {
360 /* Wipeout the new line character */
361 line[read - 1] = '\0';
363 xbt_str_trim(line, NULL);
368 if(strlen(line) == 0)
373 if(strncmp(line, elf_file, strlen(elf_file)) == 0)
376 if(strncmp(line, "Contents", 8) == 0)
379 if(strncmp(line, "Offset", 6) == 0){
386 XBT_INFO("Your program must be compiled with -g");
390 xbt_dynar_t loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
392 xbt_str_strip_spaces(line);
393 split = xbt_str_split(line, " ");
396 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
398 // Take the key from the first line of the list:
400 key = bprintf("%d", (int)strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
403 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
404 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
405 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
408 while(cursor_remove < 3){
409 xbt_dynar_remove_at(split, 0, NULL);
413 loc_expr = xbt_str_join(split, " ");
414 xbt_str_ltrim(loc_expr, "(");
415 xbt_str_rtrim(loc_expr, ")");
416 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
418 xbt_dynar_push(loclist, &new_entry);
420 xbt_dynar_free(&split);
423 read = xbt_getline(&line, &n, fp);
425 line[read - 1] = '\0';
426 xbt_str_strip_spaces(line);
427 split = xbt_str_split(line, " ");
433 xbt_dict_set(location_list, key, loclist, NULL);
436 xbt_dynar_free(&split);
444 return location_list;
447 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
449 xbt_dict_cursor_t cursor = NULL;
453 xbt_dict_foreach(all_variables, cursor, name, res) {
454 if(offset >= res->start && offset < res->end){
455 xbt_dict_cursor_free(&cursor);
460 xbt_dict_cursor_free(&cursor);
465 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
467 unsigned int cursor = 0;
468 dw_variable_t current_var;
470 xbt_dynar_foreach(frame->variables, cursor, current_var){
471 if(strcmp(var, current_var->name) == 0)
478 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
480 if(xbt_dynar_is_empty(variables))
483 unsigned int cursor = 0;
485 int end = xbt_dynar_length(variables) - 1;
486 dw_variable_t var_test = NULL;
489 cursor = (start + end) / 2;
490 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
491 if(strcmp(var_test->name, var) < 0){
493 }else if(strcmp(var_test->name, var) > 0){
496 if(address){ /* global variable */
497 if(var_test->address.address == address)
499 if(var_test->address.address > address)
503 }else{ /* local variable */
509 if(strcmp(var_test->name, var) == 0){
510 if(address && var_test->address.address < address)
514 }else if(strcmp(var_test->name, var) < 0)
521 static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
523 xbt_dict_t location_list = MC_dwarf_get_location_list(elf_file);
525 char *command = bprintf("LANG=C objdump -Wi %s", elf_file);
527 FILE *fp = popen(command, "r");
530 perror("popen for objdump failed");
532 mc_object_info_t result = MC_new_object_info();
533 result->file_name = xbt_strdup(elf_file);
535 xbt_dict_t *local_variables = &result->local_variables;
536 xbt_dynar_t *global_variables = &result->global_variables;
537 xbt_dict_t *types = &result->types;
539 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
540 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
541 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
542 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
543 *parent_value = NULL;
547 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
548 is_pointer = 0, struct_decl = 0, member_end = 0,
549 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
551 xbt_dynar_t split = NULL, split2 = NULL;
553 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
554 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
556 dw_frame_t variable_frame, subroutine_frame = NULL;
558 e_dw_type_type type_type = -1;
560 read = xbt_getline(&line, &n, fp);
564 /* Wipeout the new line character */
565 line[read - 1] = '\0';
567 if(n == 0 || strlen(line) == 0){
568 read = xbt_getline(&line, &n, fp);
572 xbt_str_ltrim(line, NULL);
573 xbt_str_strip_spaces(line);
576 read = xbt_getline(&line, &n, fp);
580 xbt_dynar_free(&split);
581 split = xbt_str_split(line, " ");
584 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
586 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
587 /* We build/complete a dw_frame_t object
588 * and append it if necessary to the local_variables dictionnary */
590 dw_frame_t frame = NULL;
592 strtok(xbt_dynar_get_as(split, 0, char *), "<");
593 subprogram_start = xbt_strdup(strtok(NULL, "<"));
594 xbt_str_rtrim(subprogram_start, ">:");
596 read = xbt_getline(&line, &n, fp);
600 /* Wipeout the new line character */
601 line[read - 1] = '\0';
603 if(n == 0 || strlen(line) == 0){
604 read = xbt_getline(&line, &n, fp);
608 xbt_dynar_free(&split);
609 xbt_str_rtrim(line, NULL);
610 xbt_str_strip_spaces(line);
611 split = xbt_str_split(line, " ");
613 node_type = xbt_dynar_get_as(split, 1, char *);
615 if(strncmp(node_type, "DW_AT_", 6) != 0)
618 if(strcmp(node_type, "DW_AT_sibling") == 0){
620 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
621 xbt_str_ltrim(subprogram_end, "<0x");
622 xbt_str_rtrim(subprogram_end, ">");
624 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
627 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
628 xbt_str_ltrim(abstract_origin, "<0x");
629 xbt_str_rtrim(abstract_origin, ">");
630 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
631 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
632 xbt_free(abstract_origin);
634 }else if(strcmp(node_type, "DW_AT_name") == 0){
637 xbt_free(current_frame);
638 frame = xbt_new0(s_dw_frame_t, 1);
639 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
640 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
641 frame->frame_base = xbt_new0(s_dw_location_t, 1);
642 current_frame = strdup(frame->name);
644 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
646 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
648 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
650 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
652 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
656 xbt_str_strip_spaces(line);
657 split2 = xbt_str_split(line, "(");
658 xbt_dynar_remove_at(split2, 0, NULL);
659 loc_expr = xbt_str_join(split2, " ");
660 xbt_str_rtrim(loc_expr, ")");
661 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
662 xbt_dynar_free(&split2);
667 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
670 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
672 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
675 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
677 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
679 xbt_free(frame->name);
680 xbt_free(current_frame);
681 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
682 current_frame = strdup(frame->name);
683 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
687 read = xbt_getline(&line, &n, fp);
692 frame->start = strtoul(subprogram_start, NULL, 16);
693 if(subprogram_end != NULL)
694 frame->end = strtoul(subprogram_end, NULL, 16);
695 xbt_dict_set(*local_variables, frame->name, frame, NULL);
698 xbt_free(subprogram_start);
699 xbt_free(subprogram_end);
700 subprogram_end = NULL;
703 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
704 /* We build a dw_variable_t object and append it either to
705 the list of variables of the frame (local variable)
706 or to the list of global variables (global variables). */
708 dw_variable_t var = NULL;
710 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
711 parent_value = strtok(parent_value,"<");
712 xbt_str_rtrim(parent_value, ">");
713 parent = atoi(parent_value);
714 xbt_free(parent_value);
719 strtok(xbt_dynar_get_as(split, 0, char *), "<");
720 origin = xbt_strdup(strtok(NULL, "<"));
721 xbt_str_rtrim(origin, ">:");
723 read = xbt_getline(&line, &n, fp);
727 /* Wipeout the new line character */
728 line[read - 1] = '\0';
730 if(n == 0 || strlen(line) == 0){
731 read = xbt_getline(&line, &n, fp);
735 xbt_dynar_free(&split);
736 xbt_str_rtrim(line, NULL);
737 xbt_str_strip_spaces(line);
738 split = xbt_str_split(line, " ");
740 node_type = xbt_dynar_get_as(split, 1, char *);
742 if(strncmp(node_type, "DW_AT_", 6) != 0)
745 if(strcmp(node_type, "DW_AT_name") == 0){
747 var = xbt_new0(s_dw_variable_t, 1);
748 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
749 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
751 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
755 abstract_origin = xbt_dynar_get_as(split, 2, char *);
756 xbt_str_ltrim(abstract_origin, "<0x");
757 xbt_str_rtrim(abstract_origin, ">");
759 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
760 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
761 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
763 }else if(strcmp(node_type, "DW_AT_location") == 0){
767 if(!global_variable){
769 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
771 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
772 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
774 xbt_str_strip_spaces(line);
775 split2 = xbt_str_split(line, "(");
776 xbt_dynar_remove_at(split2, 0, NULL);
777 loc_expr = xbt_str_join(split2, " ");
778 xbt_str_rtrim(loc_expr, ")");
779 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
781 xbt_dynar_free(&split2);
782 split2 = xbt_str_split(loc_expr, " ");
783 if(strcmp(elf_file, xbt_binary_name) != 0)
784 var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
786 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
788 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
790 xbt_dynar_free(&split2);
794 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
795 xbt_str_rtrim(global_address, ")");
796 if(strcmp(elf_file, xbt_binary_name) != 0)
797 var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(global_address, NULL, 16));
799 var->address.address = (void *)strtoul(global_address, NULL, 16);
800 xbt_free(global_address);
801 global_address = NULL;
806 }else if(strcmp(node_type, "DW_AT_type") == 0){
808 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
809 xbt_str_ltrim(type_origin, "<0x");
810 xbt_str_rtrim(type_origin, ">");
812 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
816 dw_variable_free(var);
820 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
824 dw_variable_free(var);
830 read = xbt_getline(&line, &n, fp);
834 if(new_variable == 1){
836 if(!global_variable){
837 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
838 var->type_origin = strdup(type_origin);
840 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
842 xbt_dynar_insert_at(variable_frame->variables, index, &var);
844 var->type_origin = strdup(type_origin);
846 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
848 xbt_dynar_insert_at(*global_variables, index, &var);
851 xbt_free(type_origin);
858 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
859 /* Update the information on the frame (we should duplicate it instead). */
861 read = xbt_getline(&line, &n, fp);
865 /* Wipeout the new line character */
866 line[read - 1] = '\0';
868 if(n == 0 || strlen(line) == 0){
869 read = xbt_getline(&line, &n, fp);
873 xbt_dynar_free(&split);
874 xbt_str_rtrim(line, NULL);
875 xbt_str_strip_spaces(line);
876 split = xbt_str_split(line, " ");
878 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
881 node_type = xbt_dynar_get_as(split, 1, char *);
883 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
885 origin = xbt_dynar_get_as(split, 2, char *);
886 xbt_str_ltrim(origin, "<0x");
887 xbt_str_rtrim(origin, ">");
889 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
890 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
892 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
894 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
896 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
898 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
901 read = xbt_getline(&line, &n, fp);
905 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
906 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
907 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
908 || strcmp(node_type, "(DW_TAG_typedef)") == 0
909 || strcmp(node_type, "(DW_TAG_const_type)") == 0
910 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
911 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
912 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
914 /* Create the and add it to the types dictionnary */
916 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
917 type_type = e_dw_base_type;
918 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
919 type_type = e_dw_enumeration_type;
920 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
921 type_type = e_dw_enumerator;
922 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
923 type_type = e_dw_typedef;
924 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
925 type_type = e_dw_const_type;
926 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
927 type_type = e_dw_pointer_type;
928 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
929 type_type = e_dw_subroutine_type;
930 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
931 type_type = e_dw_volatile_type;
933 strtok(xbt_dynar_get_as(split, 0, char *), "<");
934 origin = strdup(strtok(NULL, "<"));
935 xbt_str_rtrim(origin, ">:");
937 read = xbt_getline(&line, &n, fp);
941 /* Wipeout the new line character */
942 line[read - 1] = '\0';
944 if(n == 0 || strlen(line) == 0){
945 read = xbt_getline(&line, &n, fp);
949 xbt_dynar_free(&split);
950 xbt_str_rtrim(line, NULL);
951 xbt_str_strip_spaces(line);
952 split = xbt_str_split(line, " ");
954 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
957 node_type = xbt_dynar_get_as(split, 1, char *);
959 if(strcmp(node_type, "DW_AT_byte_size") == 0){
960 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
961 if(type_type == e_dw_enumeration_type)
962 enumeration_size = size;
963 }else if(strcmp(node_type, "DW_AT_name") == 0){
964 end = xbt_str_join(split, " ");
965 xbt_dynar_free(&split);
966 split = xbt_str_split(end, "):");
967 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
968 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
969 }else if(strcmp(node_type, "DW_AT_type") == 0){
970 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
971 xbt_str_ltrim(type_origin, "<0x");
972 xbt_str_rtrim(type_origin, ">");
975 read = xbt_getline(&line, &n, fp);
978 dw_type_t type = xbt_new0(s_dw_type_t, 1);
979 type->type = type_type;
981 type->name = xbt_strdup(name);
983 type->name = xbt_strdup("undefined");
984 type->is_pointer_type = is_pointer;
985 type->id = (void *)strtoul(origin, NULL, 16);
987 type->dw_type_id = xbt_strdup(type_origin);
988 if(type_type == e_dw_enumerator)
989 type->size = enumeration_size;
992 type->members = NULL;
994 xbt_dict_set(*types, origin, type, NULL);
998 xbt_free(type_origin);
1007 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
1009 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
1014 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1015 origin = strdup(strtok(NULL, "<"));
1016 xbt_str_rtrim(origin, ">:");
1018 read = xbt_getline(&line, &n, fp);
1020 dw_type_t type = NULL;
1026 /* Wipeout the new line character */
1027 line[read - 1] = '\0';
1029 if(n == 0 || strlen(line) == 0){
1030 read = xbt_getline(&line, &n, fp);
1034 xbt_dynar_free(&split);
1035 xbt_str_rtrim(line, NULL);
1036 xbt_str_strip_spaces(line);
1037 split = xbt_str_split(line, " ");
1039 node_type = xbt_dynar_get_as(split, 1, char *);
1041 if(strncmp(node_type, "DW_AT_", 6) != 0){
1046 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1047 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1048 }else if(strcmp(node_type, "DW_AT_name") == 0){
1050 end = xbt_str_join(split, " ");
1051 xbt_dynar_free(&split);
1052 split = xbt_str_split(end, "):");
1053 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1054 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1055 }else if(strcmp(node_type, "DW_AT_type") == 0){
1056 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1057 xbt_str_ltrim(type_origin, "<0x");
1058 xbt_str_rtrim(type_origin, ">");
1059 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1061 end = xbt_str_join(split, " ");
1062 xbt_dynar_free(&split);
1063 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1064 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1065 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1066 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1069 read = xbt_getline(&line, &n, fp);
1073 if(member_end && type){
1076 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1077 member_type->name = xbt_strdup(name);
1078 member_type->size = size;
1079 member_type->is_pointer_type = is_pointer;
1080 member_type->id = (void *)strtoul(origin, NULL, 16);
1081 member_type->offset = offset;
1083 member_type->dw_type_id = xbt_strdup(type_origin);
1085 xbt_dynar_push(type->members, &member_type);
1091 xbt_free(type_origin);
1098 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1099 origin = strdup(strtok(NULL, "<"));
1100 xbt_str_rtrim(origin, ">:");
1104 if(struct_decl || union_decl){
1105 type = xbt_new0(s_dw_type_t, 1);
1107 type->type = e_dw_structure_type;
1109 type->type = e_dw_union_type;
1110 type->name = xbt_strdup(name);
1112 type->is_pointer_type = is_pointer;
1113 type->id = (void *)strtoul(origin, NULL, 16);
1115 type->dw_type_id = xbt_strdup(type_origin);
1116 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1118 xbt_dict_set(*types, origin, type, NULL);
1124 xbt_free(type_origin);
1132 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1135 read = xbt_getline(&line, &n, fp);
1142 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1144 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1145 origin = strdup(strtok(NULL, "<"));
1146 xbt_str_rtrim(origin, ">:");
1148 read = xbt_getline(&line, &n, fp);
1150 dw_type_t type = NULL;
1156 /* Wipeout the new line character */
1157 line[read - 1] = '\0';
1159 if(n == 0 || strlen(line) == 0){
1160 read = xbt_getline(&line, &n, fp);
1164 xbt_dynar_free(&split);
1165 xbt_str_rtrim(line, NULL);
1166 xbt_str_strip_spaces(line);
1167 split = xbt_str_split(line, " ");
1169 node_type = xbt_dynar_get_as(split, 1, char *);
1171 if(strncmp(node_type, "DW_AT_", 6) != 0)
1174 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1175 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1176 }else if(strcmp(node_type, "DW_AT_name") == 0){
1177 end = xbt_str_join(split, " ");
1178 xbt_dynar_free(&split);
1179 split = xbt_str_split(end, "):");
1180 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1181 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1182 }else if(strcmp(node_type, "DW_AT_type") == 0){
1183 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1184 xbt_str_ltrim(type_origin, "<0x");
1185 xbt_str_rtrim(type_origin, ">");
1188 read = xbt_getline(&line, &n, fp);
1192 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1196 if(subrange && type){
1203 xbt_free(type_origin);
1209 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1210 origin = strdup(strtok(NULL, "<"));
1211 xbt_str_rtrim(origin, ">:");
1215 type = xbt_new0(s_dw_type_t, 1);
1216 type->type = e_dw_array_type;
1217 type->name = xbt_strdup(name);
1218 type->is_pointer_type = is_pointer;
1219 type->id = (void *)strtoul(origin, NULL, 16);
1221 type->dw_type_id = xbt_strdup(type_origin);
1222 type->members = NULL;
1224 xbt_dict_set(*types, origin, type, NULL);
1230 xbt_free(type_origin);
1235 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1238 read = xbt_getline(&line, &n, fp);
1247 read = xbt_getline(&line, &n, fp);
1253 xbt_dynar_free(&split);
1254 xbt_dict_free(&variables_origin);
1255 xbt_dict_free(&subprograms_origin);
1258 xbt_dict_free(&location_list);
1265 /******************************* Ignore mechanism *******************************/
1266 /*********************************************************************************/
1268 xbt_dynar_t mc_checkpoint_ignore;
1270 typedef struct s_mc_stack_ignore_variable{
1273 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1275 typedef struct s_mc_data_bss_ignore_variable{
1277 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1279 /**************************** Free functions ******************************/
1281 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1282 xbt_free(v->var_name);
1287 static void stack_ignore_variable_free_voidp(void *v){
1288 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1291 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1295 void heap_ignore_region_free_voidp(void *r){
1296 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1299 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1304 static void data_bss_ignore_variable_free_voidp(void *v){
1305 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1308 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1312 static void checkpoint_ignore_region_free_voidp(void *r){
1313 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1316 /***********************************************************************/
1318 void MC_ignore_heap(void *address, size_t size){
1320 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1324 mc_heap_ignore_region_t region = NULL;
1325 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1326 region->address = address;
1327 region->size = size;
1329 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1331 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1332 region->fragment = -1;
1333 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1335 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1336 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1339 if(mc_heap_comparison_ignore == NULL){
1340 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1341 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1347 unsigned int cursor = 0;
1348 mc_heap_ignore_region_t current_region = NULL;
1350 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1352 while(start <= end){
1353 cursor = (start + end) / 2;
1354 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1355 if(current_region->address == address){
1356 heap_ignore_region_free(region);
1360 }else if(current_region->address < address){
1367 if(current_region->address < address)
1368 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1370 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1376 void MC_remove_ignore_heap(void *address, size_t size){
1378 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1382 unsigned int cursor = 0;
1384 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1385 mc_heap_ignore_region_t region;
1386 int ignore_found = 0;
1388 while(start <= end){
1389 cursor = (start + end) / 2;
1390 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1391 if(region->address == address){
1394 }else if(region->address < address){
1397 if((char * )region->address <= ((char *)address + size)){
1406 if(ignore_found == 1){
1407 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1408 MC_remove_ignore_heap(address, size);
1416 void MC_ignore_global_variable(const char *name){
1418 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1422 if(mc_libsimgrid_info){
1424 unsigned int cursor = 0;
1425 dw_variable_t current_var;
1427 int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1429 while(start <= end){
1430 cursor = (start + end) /2;
1431 current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
1432 if(strcmp(current_var->name, name) == 0){
1433 xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
1435 end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1436 }else if(strcmp(current_var->name, name) < 0){
1445 if(mc_data_bss_comparison_ignore == NULL)
1446 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1448 mc_data_bss_ignore_variable_t var = NULL;
1449 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1450 var->name = strdup(name);
1452 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1454 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1458 unsigned int cursor = 0;
1460 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1461 mc_data_bss_ignore_variable_t current_var = NULL;
1463 while(start <= end){
1464 cursor = (start + end) / 2;
1465 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1466 if(strcmp(current_var->name, name) == 0){
1467 data_bss_ignore_variable_free(var);
1471 }else if(strcmp(current_var->name, name) < 0){
1478 if(strcmp(current_var->name, name) < 0)
1479 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1481 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1490 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1492 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1496 if(mc_libsimgrid_info){
1497 unsigned int cursor = 0;
1498 dw_variable_t current_var;
1500 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1501 xbt_dict_cursor_t dict_cursor;
1502 char *current_frame_name;
1504 xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
1506 end = xbt_dynar_length(frame->variables) - 1;
1507 while(start <= end){
1508 cursor = (start + end) / 2;
1509 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1510 if(strcmp(current_var->name, var_name) == 0){
1511 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1513 end = xbt_dynar_length(frame->variables) - 1;
1514 }else if(strcmp(current_var->name, var_name) < 0){
1521 xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
1523 end = xbt_dynar_length(frame->variables) - 1;
1524 while(start <= end){
1525 cursor = (start + end) / 2;
1526 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1527 if(strcmp(current_var->name, var_name) == 0){
1528 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1530 end = xbt_dynar_length(frame->variables) - 1;
1531 }else if(strcmp(current_var->name, var_name) < 0){
1539 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
1540 mc_libsimgrid_info->local_variables, frame_name))->variables;
1542 end = xbt_dynar_length(variables_list) - 1;
1543 while(start <= end){
1544 cursor = (start + end) / 2;
1545 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1546 if(strcmp(current_var->name, var_name) == 0){
1547 xbt_dynar_remove_at(variables_list, cursor, NULL);
1549 end = xbt_dynar_length(variables_list) - 1;
1550 }else if(strcmp(current_var->name, var_name) < 0){
1559 if(mc_stack_comparison_ignore == NULL)
1560 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1562 mc_stack_ignore_variable_t var = NULL;
1563 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1564 var->var_name = strdup(var_name);
1565 var->frame = strdup(frame_name);
1567 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1569 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1573 unsigned int cursor = 0;
1575 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1576 mc_stack_ignore_variable_t current_var = NULL;
1578 while(start <= end){
1579 cursor = (start + end) / 2;
1580 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1581 if(strcmp(current_var->frame, frame_name) == 0){
1582 if(strcmp(current_var->var_name, var_name) == 0){
1583 stack_ignore_variable_free(var);
1587 }else if(strcmp(current_var->var_name, var_name) < 0){
1592 }else if(strcmp(current_var->frame, frame_name) < 0){
1599 if(strcmp(current_var->frame, frame_name) == 0){
1600 if(strcmp(current_var->var_name, var_name) < 0){
1601 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1603 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1605 }else if(strcmp(current_var->frame, frame_name) < 0){
1606 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1608 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1618 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1620 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1624 if(stacks_areas == NULL)
1625 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1627 stack_region_t region = NULL;
1628 region = xbt_new0(s_stack_region_t, 1);
1629 region->address = stack;
1630 region->process_name = strdup(name);
1631 region->context = context;
1632 region->size = size;
1633 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1634 xbt_dynar_push(stacks_areas, ®ion);
1640 void MC_ignore(void *addr, size_t size){
1642 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1646 if(mc_checkpoint_ignore == NULL)
1647 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1649 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1650 region->addr = addr;
1651 region->size = size;
1653 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1654 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1657 unsigned int cursor = 0;
1659 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1660 mc_checkpoint_ignore_region_t current_region = NULL;
1662 while(start <= end){
1663 cursor = (start + end) / 2;
1664 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1665 if(current_region->addr == addr){
1666 if(current_region->size == size){
1667 checkpoint_ignore_region_free(region);
1671 }else if(current_region->size < size){
1676 }else if(current_region->addr < addr){
1683 if(current_region->addr == addr){
1684 if(current_region->size < size){
1685 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1687 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1689 }else if(current_region->addr < addr){
1690 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1692 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1700 /******************************* Initialisation of MC *******************************/
1701 /*********************************************************************************/
1703 static void MC_dump_ignored_local_variables(void){
1705 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1708 unsigned int cursor = 0;
1709 mc_stack_ignore_variable_t current_var;
1711 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1712 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1715 xbt_dynar_free(&mc_stack_comparison_ignore);
1716 mc_stack_comparison_ignore = NULL;
1720 static void MC_dump_ignored_global_variables(void){
1722 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1725 unsigned int cursor = 0;
1726 mc_data_bss_ignore_variable_t current_var;
1728 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1729 MC_ignore_global_variable(current_var->name);
1732 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1733 mc_data_bss_comparison_ignore = NULL;
1739 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1743 /* Initialize the data structures that must be persistent across every
1744 iteration of the model-checker (in RAW memory) */
1748 MC_init_memory_map_info();
1750 XBT_INFO("Get debug information ...");
1752 /* Get local variables for state equality detection */
1753 mc_binary_info = MC_dwarf_get_variables(xbt_binary_name);
1754 mc_libsimgrid_info = MC_dwarf_get_variables(libsimgrid_path);
1756 XBT_INFO("Get debug information done !");
1758 /* Remove variables ignored before getting list of variables */
1759 MC_dump_ignored_local_variables();
1760 MC_dump_ignored_global_variables();
1762 /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
1763 MC_get_libsimgrid_plt_section();
1764 MC_get_binary_plt_section();
1767 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1771 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1772 MC_ignore_local_variable("e", "*");
1773 MC_ignore_local_variable("__ex_cleanup", "*");
1774 MC_ignore_local_variable("__ex_mctx_en", "*");
1775 MC_ignore_local_variable("__ex_mctx_me", "*");
1776 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1777 MC_ignore_local_variable("_log_ev", "*");
1778 MC_ignore_local_variable("_throw_ctx", "*");
1779 MC_ignore_local_variable("ctx", "*");
1781 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1782 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1784 /* Ignore local variable about time used for tracing */
1785 MC_ignore_local_variable("start_time", "*");
1787 MC_ignore_global_variable("mc_comp_times");
1788 MC_ignore_global_variable("mc_snapshot_comparison_time");
1789 MC_ignore_global_variable("mc_time");
1790 MC_ignore_global_variable("smpi_current_rank");
1791 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1792 MC_ignore_global_variable("maestro_stack_start");
1793 MC_ignore_global_variable("maestro_stack_end");
1795 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1796 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1797 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1798 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1800 smx_process_t process;
1801 xbt_swag_foreach(process, simix_global->process_list){
1802 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1810 static void MC_init_dot_output(){ /* FIXME : more colors */
1814 colors[2] = "green3";
1815 colors[3] = "goldenrod";
1816 colors[4] = "brown";
1817 colors[5] = "purple";
1818 colors[6] = "magenta";
1819 colors[7] = "turquoise4";
1820 colors[8] = "gray25";
1821 colors[9] = "forestgreen";
1822 colors[10] = "hotpink";
1823 colors[11] = "lightblue";
1826 dot_output = fopen(_sg_mc_dot_output_file, "w");
1828 if(dot_output == NULL){
1829 perror("Error open dot output file");
1833 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");
1837 /******************************* Core of MC *******************************/
1838 /**************************************************************************/
1840 void MC_do_the_modelcheck_for_real() {
1843 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1846 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1847 if (mc_reduce_kind==e_mc_reduce_unset)
1848 mc_reduce_kind=e_mc_reduce_dpor;
1850 XBT_INFO("Check a safety property");
1851 MC_modelcheck_safety();
1855 if (mc_reduce_kind==e_mc_reduce_unset)
1856 mc_reduce_kind=e_mc_reduce_none;
1858 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1859 MC_automaton_load(_sg_mc_property_file);
1860 MC_modelcheck_liveness();
1864 void MC_modelcheck_safety(void)
1866 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1868 /* Check if MC is already initialized */
1869 if (initial_state_safety)
1872 mc_time = xbt_new0(double, simix_process_maxpid);
1874 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1875 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1877 /* Initialize the data structures that must be persistent across every
1878 iteration of the model-checker (in RAW memory) */
1882 /* Initialize statistics */
1883 mc_stats = xbt_new0(s_mc_stats_t, 1);
1884 mc_stats->state_size = 1;
1886 /* Create exploration stack */
1887 mc_stack_safety = xbt_fifo_new();
1889 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1890 MC_init_dot_output();
1894 if(_sg_mc_visited > 0){
1898 MC_init_memory_map_info();
1899 MC_get_libsimgrid_plt_section();
1900 MC_get_binary_plt_section();
1907 /* Save the initial state */
1908 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1909 initial_state_safety->snapshot = MC_take_snapshot(0);
1921 void MC_modelcheck_liveness(){
1923 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1927 mc_time = xbt_new0(double, simix_process_maxpid);
1929 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1930 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1934 /* Initialize statistics */
1935 mc_stats = xbt_new0(s_mc_stats_t, 1);
1936 mc_stats->state_size = 1;
1938 /* Create exploration stack */
1939 mc_stack_liveness = xbt_fifo_new();
1941 /* Create the initial state */
1942 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1944 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1945 MC_init_dot_output();
1952 MC_print_statistics(mc_stats);
1968 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1970 return simcall->mc_value;
1974 int MC_random(int min, int max)
1976 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1977 return simcall_mc_random(min, max);
1981 * \brief Schedules all the process that are ready to run
1983 void MC_wait_for_requests(void)
1985 smx_process_t process;
1989 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
1990 SIMIX_process_runall();
1991 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
1992 req = &process->simcall;
1993 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
1994 SIMIX_simcall_pre(req, 0);
1999 int MC_deadlock_check()
2001 int deadlock = FALSE;
2002 smx_process_t process;
2003 if(xbt_swag_size(simix_global->process_list)){
2005 xbt_swag_foreach(process, simix_global->process_list){
2006 if(process->simcall.call != SIMCALL_NONE
2007 && MC_request_is_enabled(&process->simcall)){
2017 * \brief Re-executes from the state at position start all the transitions indicated by
2018 * a given model-checker stack.
2019 * \param stack The stack with the transitions to execute.
2020 * \param start Start index to begin the re-execution.
2022 void MC_replay(xbt_fifo_t stack, int start)
2024 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2026 int value, i = 1, count = 1;
2028 smx_simcall_t req = NULL, saved_req = NULL;
2029 xbt_fifo_item_t item, start_item;
2031 smx_process_t process = NULL;
2033 XBT_DEBUG("**** Begin Replay ****");
2036 /* Restore the initial state */
2037 MC_restore_snapshot(initial_state_safety->snapshot);
2038 /* At the moment of taking the snapshot the raw heap was set, so restoring
2039 * it will set it back again, we have to unset it to continue */
2043 start_item = xbt_fifo_get_last_item(stack);
2046 start_item = xbt_fifo_get_prev_item(start_item);
2052 xbt_dict_reset(first_enabled_state);
2053 xbt_swag_foreach(process, simix_global->process_list){
2054 if(MC_process_is_enabled(process)){
2055 char *key = bprintf("%lu", process->pid);
2056 char *data = bprintf("%d", count);
2057 xbt_dict_set(first_enabled_state, key, data, NULL);
2064 /* Traverse the stack from the state at position start and re-execute the transitions */
2065 for (item = start_item;
2066 item != xbt_fifo_get_first_item(stack);
2067 item = xbt_fifo_get_prev_item(item)) {
2069 state = (mc_state_t) xbt_fifo_get_item_content(item);
2070 saved_req = MC_state_get_executed_request(state, &value);
2073 char *key = bprintf("%lu", saved_req->issuer->pid);
2074 xbt_dict_remove(first_enabled_state, key);
2079 /* because we got a copy of the executed request, we have to fetch the
2080 real one, pointed by the request field of the issuer process */
2081 req = &saved_req->issuer->simcall;
2083 /* Debug information */
2084 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2085 req_str = MC_request_to_string(req, value);
2086 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2091 SIMIX_simcall_pre(req, value);
2092 MC_wait_for_requests();
2097 /* Insert in dict all enabled processes */
2098 xbt_swag_foreach(process, simix_global->process_list){
2099 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2100 char *key = bprintf("%lu", process->pid);
2101 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2102 char *data = bprintf("%d", count);
2103 xbt_dict_set(first_enabled_state, key, data, NULL);
2110 /* Update statistics */
2111 mc_stats->visited_states++;
2112 mc_stats->executed_transitions++;
2116 XBT_DEBUG("**** End Replay ****");
2126 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2129 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2133 smx_simcall_t req = NULL, saved_req = NULL;
2134 xbt_fifo_item_t item;
2139 XBT_DEBUG("**** Begin Replay ****");
2141 /* Restore the initial state */
2142 MC_restore_snapshot(initial_state_liveness->snapshot);
2144 /* At the moment of taking the snapshot the raw heap was set, so restoring
2145 * it will set it back again, we have to unset it to continue */
2146 if(!initial_state_liveness->raw_mem_set)
2151 item = xbt_fifo_get_last_item(stack);
2153 while(depth <= xbt_fifo_size(stack)){
2155 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2156 state = (mc_state_t) pair->graph_state;
2158 if(pair->requests > 0){
2160 saved_req = MC_state_get_executed_request(state, &value);
2161 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2163 if(saved_req != NULL){
2164 /* because we got a copy of the executed request, we have to fetch the
2165 real one, pointed by the request field of the issuer process */
2166 req = &saved_req->issuer->simcall;
2167 //XBT_DEBUG("Req->call %u", req->call);
2169 /* Debug information */
2170 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2171 req_str = MC_request_to_string(req, value);
2172 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2178 SIMIX_simcall_pre(req, value);
2179 MC_wait_for_requests();
2184 /* Update statistics */
2185 mc_stats->visited_pairs++;
2186 mc_stats->executed_transitions++;
2188 item = xbt_fifo_get_prev_item(item);
2193 /* Traverse the stack from the initial state and re-execute the transitions */
2194 for (item = xbt_fifo_get_last_item(stack);
2195 item != xbt_fifo_get_first_item(stack);
2196 item = xbt_fifo_get_prev_item(item)) {
2198 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2199 state = (mc_state_t) pair->graph_state;
2201 if(pair->requests > 0){
2203 saved_req = MC_state_get_executed_request(state, &value);
2204 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2206 if(saved_req != NULL){
2207 /* because we got a copy of the executed request, we have to fetch the
2208 real one, pointed by the request field of the issuer process */
2209 req = &saved_req->issuer->simcall;
2210 //XBT_DEBUG("Req->call %u", req->call);
2212 /* Debug information */
2213 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2214 req_str = MC_request_to_string(req, value);
2215 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2221 SIMIX_simcall_pre(req, value);
2222 MC_wait_for_requests();
2227 /* Update statistics */
2228 mc_stats->visited_pairs++;
2229 mc_stats->executed_transitions++;
2233 XBT_DEBUG("**** End Replay ****");
2235 if(initial_state_liveness->raw_mem_set)
2243 * \brief Dumps the contents of a model-checker's stack and shows the actual
2245 * \param stack The stack to dump
2247 void MC_dump_stack_safety(xbt_fifo_t stack)
2250 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2252 MC_show_stack_safety(stack);
2254 if(!_sg_mc_checkpoint){
2259 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2260 MC_state_delete(state);
2273 void MC_show_stack_safety(xbt_fifo_t stack)
2276 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2282 xbt_fifo_item_t item;
2284 char *req_str = NULL;
2286 for (item = xbt_fifo_get_last_item(stack);
2287 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2288 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2289 req = MC_state_get_executed_request(state, &value);
2291 req_str = MC_request_to_string(req, value);
2292 XBT_INFO("%s", req_str);
2301 void MC_show_deadlock(smx_simcall_t req)
2303 /*char *req_str = NULL;*/
2304 XBT_INFO("**************************");
2305 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2306 XBT_INFO("**************************");
2307 XBT_INFO("Locked request:");
2308 /*req_str = MC_request_to_string(req);
2309 XBT_INFO("%s", req_str);
2310 xbt_free(req_str);*/
2311 XBT_INFO("Counter-example execution trace:");
2312 MC_dump_stack_safety(mc_stack_safety);
2313 MC_print_statistics(mc_stats);
2317 void MC_show_stack_liveness(xbt_fifo_t stack){
2320 xbt_fifo_item_t item;
2322 char *req_str = NULL;
2324 for (item = xbt_fifo_get_last_item(stack);
2325 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2326 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2327 req = MC_state_get_executed_request(pair->graph_state, &value);
2329 if(pair->requests>0){
2330 req_str = MC_request_to_string(req, value);
2331 XBT_INFO("%s", req_str);
2334 XBT_INFO("End of system requests but evolution in Büchi automaton");
2340 void MC_dump_stack_liveness(xbt_fifo_t stack){
2342 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2347 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2348 MC_pair_delete(pair);
2357 void MC_print_statistics(mc_stats_t stats)
2359 if(stats->expanded_pairs == 0){
2360 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2361 XBT_INFO("Visited states = %lu", stats->visited_states);
2363 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2364 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2366 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2368 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2369 fprintf(dot_output, "}\n");
2375 void MC_assert(int prop)
2377 if (MC_is_active() && !prop){
2378 XBT_INFO("**************************");
2379 XBT_INFO("*** PROPERTY NOT VALID ***");
2380 XBT_INFO("**************************");
2381 XBT_INFO("Counter-example execution trace:");
2382 MC_dump_stack_safety(mc_stack_safety);
2383 MC_print_statistics(mc_stats);
2389 user_max_depth_reached = 1;
2392 void MC_process_clock_add(smx_process_t process, double amount)
2394 mc_time[process->pid] += amount;
2397 double MC_process_clock_get(smx_process_t process)
2401 return mc_time[process->pid];
2409 void MC_automaton_load(const char *file){
2411 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2415 if (_mc_property_automaton == NULL)
2416 _mc_property_automaton = xbt_automaton_new();
2418 xbt_automaton_load(_mc_property_automaton,file);
2427 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2429 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2433 if (_mc_property_automaton == NULL)
2434 _mc_property_automaton = xbt_automaton_new();
2436 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);