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->local_variables = xbt_dict_new_homogeneous(NULL);
180 res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
181 res->types = xbt_dict_new_homogeneous(NULL);
185 void MC_free_object_info(mc_object_info_t* info) {
186 xbt_dict_free(&(*info)->local_variables);
187 xbt_dynar_free(&(*info)->global_variables);
188 xbt_dict_free(&(*info)->types);
193 /*************************************************************************/
195 static dw_location_t MC_dwarf_get_location(xbt_dict_t location_list, char *expr){
197 dw_location_t loc = xbt_new0(s_dw_location_t, 1);
199 if(location_list != NULL){
201 char *key = bprintf("%d", (int)strtoul(expr, NULL, 16));
202 loc->type = e_dw_loclist;
203 loc->location.loclist = (xbt_dynar_t)xbt_dict_get_or_null(location_list, key);
204 if(loc->location.loclist == NULL)
205 XBT_INFO("Key not found in loclist");
212 char *tok = NULL, *tok2 = NULL;
214 xbt_dynar_t tokens1 = xbt_str_split(expr, ";");
217 loc->type = e_dw_compose;
218 loc->location.compose = xbt_dynar_new(sizeof(dw_location_t), NULL);
220 while(cursor < xbt_dynar_length(tokens1)){
222 tok = xbt_dynar_get_as(tokens1, cursor, char*);
223 tokens2 = xbt_str_split(tok, " ");
224 tok2 = xbt_dynar_get_as(tokens2, 0, char*);
226 if(strncmp(tok2, "DW_OP_reg", 9) == 0){
227 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
228 new_element->type = e_dw_register;
229 new_element->location.reg = atoi(strtok(tok2, "DW_OP_reg"));
230 xbt_dynar_push(loc->location.compose, &new_element);
231 }else if(strcmp(tok2, "DW_OP_fbreg:") == 0){
232 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
233 new_element->type = e_dw_fbregister_op;
234 new_element->location.fbreg_op = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
235 xbt_dynar_push(loc->location.compose, &new_element);
236 }else if(strncmp(tok2, "DW_OP_breg", 10) == 0){
237 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
238 new_element->type = e_dw_bregister_op;
239 new_element->location.breg_op.reg = atoi(strtok(tok2, "DW_OP_breg"));
240 new_element->location.breg_op.offset = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
241 xbt_dynar_push(loc->location.compose, &new_element);
242 }else if(strncmp(tok2, "DW_OP_lit", 9) == 0){
243 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
244 new_element->type = e_dw_lit;
245 new_element->location.lit = atoi(strtok(tok2, "DW_OP_lit"));
246 xbt_dynar_push(loc->location.compose, &new_element);
247 }else if(strcmp(tok2, "DW_OP_piece:") == 0){
248 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
249 new_element->type = e_dw_piece;
250 new_element->location.piece = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
251 xbt_dynar_push(loc->location.compose, &new_element);
252 }else if(strcmp(tok2, "DW_OP_plus_uconst:") == 0){
253 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
254 new_element->type = e_dw_plus_uconst;
255 new_element->location.plus_uconst = 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(tok, "DW_OP_abs") == 0 ||
258 strcmp(tok, "DW_OP_and") == 0 ||
259 strcmp(tok, "DW_OP_div") == 0 ||
260 strcmp(tok, "DW_OP_minus") == 0 ||
261 strcmp(tok, "DW_OP_mod") == 0 ||
262 strcmp(tok, "DW_OP_mul") == 0 ||
263 strcmp(tok, "DW_OP_neg") == 0 ||
264 strcmp(tok, "DW_OP_not") == 0 ||
265 strcmp(tok, "DW_OP_or") == 0 ||
266 strcmp(tok, "DW_OP_plus") == 0){
267 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
268 new_element->type = e_dw_arithmetic;
269 new_element->location.arithmetic = strdup(strtok(tok2, "DW_OP_"));
270 xbt_dynar_push(loc->location.compose, &new_element);
271 }else if(strcmp(tok, "DW_OP_stack_value") == 0){
272 }else if(strcmp(tok2, "DW_OP_deref_size:") == 0){
273 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
274 new_element->type = e_dw_deref;
275 new_element->location.deref_size = (unsigned int short) atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
276 xbt_dynar_push(loc->location.compose, &new_element);
277 }else if(strcmp(tok, "DW_OP_deref") == 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 = sizeof(void *);
281 xbt_dynar_push(loc->location.compose, &new_element);
282 }else if(strcmp(tok2, "DW_OP_constu:") == 0){
283 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
284 new_element->type = e_dw_uconstant;
285 new_element->location.uconstant.bytes = 1;
286 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
287 xbt_dynar_push(loc->location.compose, &new_element);
288 }else if(strcmp(tok2, "DW_OP_consts:") == 0){
289 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
290 new_element->type = e_dw_sconstant;
291 new_element->location.sconstant.bytes = 1;
292 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
293 xbt_dynar_push(loc->location.compose, &new_element);
294 }else if(strcmp(tok2, "DW_OP_const1u:") == 0 ||
295 strcmp(tok2, "DW_OP_const2u:") == 0 ||
296 strcmp(tok2, "DW_OP_const4u:") == 0 ||
297 strcmp(tok2, "DW_OP_const8u:") == 0){
298 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
299 new_element->type = e_dw_uconstant;
300 new_element->location.uconstant.bytes = tok2[11] - '0';
301 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
302 xbt_dynar_push(loc->location.compose, &new_element);
303 }else if(strcmp(tok, "DW_OP_const1s") == 0 ||
304 strcmp(tok, "DW_OP_const2s") == 0 ||
305 strcmp(tok, "DW_OP_const4s") == 0 ||
306 strcmp(tok, "DW_OP_const8s") == 0){
307 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
308 new_element->type = e_dw_sconstant;
309 new_element->location.sconstant.bytes = tok2[11] - '0';
310 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
311 xbt_dynar_push(loc->location.compose, &new_element);
313 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
314 new_element->type = e_dw_unsupported;
315 xbt_dynar_push(loc->location.compose, &new_element);
319 xbt_dynar_free(&tokens2);
323 xbt_dynar_free(&tokens1);
331 /** @brief Extract the location lists from an ELF file (.debug_loc)
333 * @return A map from the offset in the list (in hexadecimal string)
334 * into a location list (dynar of dw_location_entry_t).
336 static xbt_dict_t MC_dwarf_get_location_list(const char *elf_file){
338 char *command = bprintf("LANG=C objdump -Wo %s", elf_file);
340 FILE *fp = popen(command, "r");
343 perror("popen for objdump failed");
347 int debug = 0; /*Detect if the program has been compiled with -g */
349 xbt_dict_t location_list = xbt_dict_new_homogeneous(NULL);
350 char *line = NULL, *loc_expr = NULL;
354 xbt_dynar_t split = NULL;
356 while ((read = xbt_getline(&line, &n, fp)) != -1) {
358 /* Wipeout the new line character */
359 line[read - 1] = '\0';
361 xbt_str_trim(line, NULL);
366 if(strlen(line) == 0)
371 if(strncmp(line, elf_file, strlen(elf_file)) == 0)
374 if(strncmp(line, "Contents", 8) == 0)
377 if(strncmp(line, "Offset", 6) == 0){
384 XBT_INFO("Your program must be compiled with -g");
388 xbt_dynar_t loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
390 xbt_str_strip_spaces(line);
391 split = xbt_str_split(line, " ");
394 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
396 // Take the key from the first line of the list:
398 key = bprintf("%d", (int)strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
401 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
402 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
403 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
406 while(cursor_remove < 3){
407 xbt_dynar_remove_at(split, 0, NULL);
411 loc_expr = xbt_str_join(split, " ");
412 xbt_str_ltrim(loc_expr, "(");
413 xbt_str_rtrim(loc_expr, ")");
414 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
416 xbt_dynar_push(loclist, &new_entry);
418 xbt_dynar_free(&split);
421 read = xbt_getline(&line, &n, fp);
423 line[read - 1] = '\0';
424 xbt_str_strip_spaces(line);
425 split = xbt_str_split(line, " ");
431 xbt_dict_set(location_list, key, loclist, NULL);
434 xbt_dynar_free(&split);
442 return location_list;
445 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
447 xbt_dict_cursor_t cursor = NULL;
451 xbt_dict_foreach(all_variables, cursor, name, res) {
452 if(offset >= res->start && offset < res->end){
453 xbt_dict_cursor_free(&cursor);
458 xbt_dict_cursor_free(&cursor);
463 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
465 unsigned int cursor = 0;
466 dw_variable_t current_var;
468 xbt_dynar_foreach(frame->variables, cursor, current_var){
469 if(strcmp(var, current_var->name) == 0)
476 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
478 if(xbt_dynar_is_empty(variables))
481 unsigned int cursor = 0;
483 int end = xbt_dynar_length(variables) - 1;
484 dw_variable_t var_test = NULL;
487 cursor = (start + end) / 2;
488 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
489 if(strcmp(var_test->name, var) < 0){
491 }else if(strcmp(var_test->name, var) > 0){
494 if(address){ /* global variable */
495 if(var_test->address.address == address)
497 if(var_test->address.address > address)
501 }else{ /* local variable */
507 if(strcmp(var_test->name, var) == 0){
508 if(address && var_test->address.address < address)
512 }else if(strcmp(var_test->name, var) < 0)
519 static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
521 xbt_dict_t location_list = MC_dwarf_get_location_list(elf_file);
523 char *command = bprintf("LANG=C objdump -Wi %s", elf_file);
525 FILE *fp = popen(command, "r");
528 perror("popen for objdump failed");
530 mc_object_info_t result = MC_new_object_info();
531 xbt_dict_t *local_variables = &result->local_variables;
532 xbt_dynar_t *global_variables = &result->global_variables;
533 xbt_dict_t *types = &result->types;
535 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
536 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
537 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
538 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
539 *parent_value = NULL;
543 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
544 is_pointer = 0, struct_decl = 0, member_end = 0,
545 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0, index = 0;
547 xbt_dynar_t split = NULL, split2 = NULL;
549 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
550 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
552 dw_frame_t variable_frame, subroutine_frame = NULL;
554 e_dw_type_type type_type = -1;
556 read = xbt_getline(&line, &n, fp);
560 /* Wipeout the new line character */
561 line[read - 1] = '\0';
563 if(n == 0 || strlen(line) == 0){
564 read = xbt_getline(&line, &n, fp);
568 xbt_str_ltrim(line, NULL);
569 xbt_str_strip_spaces(line);
572 read = xbt_getline(&line, &n, fp);
576 xbt_dynar_free(&split);
577 split = xbt_str_split(line, " ");
580 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
582 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
583 /* We build/complete a dw_frame_t object
584 * and append it if necessary to the local_variables dictionnary */
586 dw_frame_t frame = NULL;
588 strtok(xbt_dynar_get_as(split, 0, char *), "<");
589 subprogram_start = xbt_strdup(strtok(NULL, "<"));
590 xbt_str_rtrim(subprogram_start, ">:");
592 read = xbt_getline(&line, &n, fp);
596 /* Wipeout the new line character */
597 line[read - 1] = '\0';
599 if(n == 0 || strlen(line) == 0){
600 read = xbt_getline(&line, &n, fp);
604 xbt_dynar_free(&split);
605 xbt_str_rtrim(line, NULL);
606 xbt_str_strip_spaces(line);
607 split = xbt_str_split(line, " ");
609 node_type = xbt_dynar_get_as(split, 1, char *);
611 if(strncmp(node_type, "DW_AT_", 6) != 0)
614 if(strcmp(node_type, "DW_AT_sibling") == 0){
616 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
617 xbt_str_ltrim(subprogram_end, "<0x");
618 xbt_str_rtrim(subprogram_end, ">");
620 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
623 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
624 xbt_str_ltrim(abstract_origin, "<0x");
625 xbt_str_rtrim(abstract_origin, ">");
626 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
627 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
628 xbt_free(abstract_origin);
630 }else if(strcmp(node_type, "DW_AT_name") == 0){
633 xbt_free(current_frame);
634 frame = xbt_new0(s_dw_frame_t, 1);
635 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
636 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
637 frame->frame_base = xbt_new0(s_dw_location_t, 1);
638 current_frame = strdup(frame->name);
640 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
642 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
644 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
646 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
648 frame->frame_base = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
652 xbt_str_strip_spaces(line);
653 split2 = xbt_str_split(line, "(");
654 xbt_dynar_remove_at(split2, 0, NULL);
655 loc_expr = xbt_str_join(split2, " ");
656 xbt_str_rtrim(loc_expr, ")");
657 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
658 xbt_dynar_free(&split2);
663 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
666 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
668 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
671 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
673 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
675 xbt_free(frame->name);
676 xbt_free(current_frame);
677 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
678 current_frame = strdup(frame->name);
679 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
683 read = xbt_getline(&line, &n, fp);
688 frame->start = strtoul(subprogram_start, NULL, 16);
689 if(subprogram_end != NULL)
690 frame->end = strtoul(subprogram_end, NULL, 16);
691 xbt_dict_set(*local_variables, frame->name, frame, NULL);
694 xbt_free(subprogram_start);
695 xbt_free(subprogram_end);
696 subprogram_end = NULL;
699 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
700 /* We build a dw_variable_t object and append it either to
701 the list of variables of the frame (local variable)
702 or to the list of global variables (global variables). */
704 dw_variable_t var = NULL;
706 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
707 parent_value = strtok(parent_value,"<");
708 xbt_str_rtrim(parent_value, ">");
709 parent = atoi(parent_value);
710 xbt_free(parent_value);
715 strtok(xbt_dynar_get_as(split, 0, char *), "<");
716 origin = xbt_strdup(strtok(NULL, "<"));
717 xbt_str_rtrim(origin, ">:");
719 read = xbt_getline(&line, &n, fp);
723 /* Wipeout the new line character */
724 line[read - 1] = '\0';
726 if(n == 0 || strlen(line) == 0){
727 read = xbt_getline(&line, &n, fp);
731 xbt_dynar_free(&split);
732 xbt_str_rtrim(line, NULL);
733 xbt_str_strip_spaces(line);
734 split = xbt_str_split(line, " ");
736 node_type = xbt_dynar_get_as(split, 1, char *);
738 if(strncmp(node_type, "DW_AT_", 6) != 0)
741 if(strcmp(node_type, "DW_AT_name") == 0){
743 var = xbt_new0(s_dw_variable_t, 1);
744 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
745 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
747 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
751 abstract_origin = xbt_dynar_get_as(split, 2, char *);
752 xbt_str_ltrim(abstract_origin, "<0x");
753 xbt_str_rtrim(abstract_origin, ">");
755 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
756 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
757 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
759 }else if(strcmp(node_type, "DW_AT_location") == 0){
763 if(!global_variable){
765 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
767 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
768 var->address.location = MC_dwarf_get_location(location_list, xbt_dynar_get_as(split, 3, char *));
770 xbt_str_strip_spaces(line);
771 split2 = xbt_str_split(line, "(");
772 xbt_dynar_remove_at(split2, 0, NULL);
773 loc_expr = xbt_str_join(split2, " ");
774 xbt_str_rtrim(loc_expr, ")");
775 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
777 xbt_dynar_free(&split2);
778 split2 = xbt_str_split(loc_expr, " ");
779 if(strcmp(elf_file, xbt_binary_name) != 0)
780 var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
782 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
784 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
786 xbt_dynar_free(&split2);
790 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
791 xbt_str_rtrim(global_address, ")");
792 if(strcmp(elf_file, xbt_binary_name) != 0)
793 var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(global_address, NULL, 16));
795 var->address.address = (void *)strtoul(global_address, NULL, 16);
796 xbt_free(global_address);
797 global_address = NULL;
802 }else if(strcmp(node_type, "DW_AT_type") == 0){
804 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
805 xbt_str_ltrim(type_origin, "<0x");
806 xbt_str_rtrim(type_origin, ">");
808 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
812 dw_variable_free(var);
816 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
820 dw_variable_free(var);
826 read = xbt_getline(&line, &n, fp);
830 if(new_variable == 1){
832 if(!global_variable){
833 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
834 var->type_origin = strdup(type_origin);
836 index = MC_dwarf_get_variable_index(variable_frame->variables, var->name, NULL);
838 xbt_dynar_insert_at(variable_frame->variables, index, &var);
840 var->type_origin = strdup(type_origin);
842 index = MC_dwarf_get_variable_index(*global_variables, var->name, var->address.address);
844 xbt_dynar_insert_at(*global_variables, index, &var);
847 xbt_free(type_origin);
854 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
855 /* Update the information on the frame (we should duplicate it instead). */
857 read = xbt_getline(&line, &n, fp);
861 /* Wipeout the new line character */
862 line[read - 1] = '\0';
864 if(n == 0 || strlen(line) == 0){
865 read = xbt_getline(&line, &n, fp);
869 xbt_dynar_free(&split);
870 xbt_str_rtrim(line, NULL);
871 xbt_str_strip_spaces(line);
872 split = xbt_str_split(line, " ");
874 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
877 node_type = xbt_dynar_get_as(split, 1, char *);
879 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
881 origin = xbt_dynar_get_as(split, 2, char *);
882 xbt_str_ltrim(origin, "<0x");
883 xbt_str_rtrim(origin, ">");
885 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
886 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
888 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
890 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
892 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
894 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
897 read = xbt_getline(&line, &n, fp);
901 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
902 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
903 || strcmp(node_type, "(DW_TAG_enumerator)") == 0
904 || strcmp(node_type, "(DW_TAG_typedef)") == 0
905 || strcmp(node_type, "(DW_TAG_const_type)") == 0
906 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
907 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
908 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
910 /* Create the and add it to the types dictionnary */
912 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
913 type_type = e_dw_base_type;
914 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
915 type_type = e_dw_enumeration_type;
916 else if(strcmp(node_type, "(DW_TAG_enumerator)") == 0)
917 type_type = e_dw_enumerator;
918 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
919 type_type = e_dw_typedef;
920 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
921 type_type = e_dw_const_type;
922 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
923 type_type = e_dw_pointer_type;
924 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
925 type_type = e_dw_subroutine_type;
926 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
927 type_type = e_dw_volatile_type;
929 strtok(xbt_dynar_get_as(split, 0, char *), "<");
930 origin = strdup(strtok(NULL, "<"));
931 xbt_str_rtrim(origin, ">:");
933 read = xbt_getline(&line, &n, fp);
937 /* Wipeout the new line character */
938 line[read - 1] = '\0';
940 if(n == 0 || strlen(line) == 0){
941 read = xbt_getline(&line, &n, fp);
945 xbt_dynar_free(&split);
946 xbt_str_rtrim(line, NULL);
947 xbt_str_strip_spaces(line);
948 split = xbt_str_split(line, " ");
950 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
953 node_type = xbt_dynar_get_as(split, 1, char *);
955 if(strcmp(node_type, "DW_AT_byte_size") == 0){
956 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
957 if(type_type == e_dw_enumeration_type)
958 enumeration_size = size;
959 }else if(strcmp(node_type, "DW_AT_name") == 0){
960 end = xbt_str_join(split, " ");
961 xbt_dynar_free(&split);
962 split = xbt_str_split(end, "):");
963 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
964 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
965 }else if(strcmp(node_type, "DW_AT_type") == 0){
966 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
967 xbt_str_ltrim(type_origin, "<0x");
968 xbt_str_rtrim(type_origin, ">");
971 read = xbt_getline(&line, &n, fp);
974 dw_type_t type = xbt_new0(s_dw_type_t, 1);
975 type->type = type_type;
977 type->name = xbt_strdup(name);
979 type->name = xbt_strdup("undefined");
980 type->is_pointer_type = is_pointer;
981 type->id = (void *)strtoul(origin, NULL, 16);
983 type->dw_type_id = xbt_strdup(type_origin);
984 if(type_type == e_dw_enumerator)
985 type->size = enumeration_size;
988 type->members = NULL;
990 xbt_dict_set(*types, origin, type, NULL);
994 xbt_free(type_origin);
1003 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
1005 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
1010 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1011 origin = strdup(strtok(NULL, "<"));
1012 xbt_str_rtrim(origin, ">:");
1014 read = xbt_getline(&line, &n, fp);
1016 dw_type_t type = NULL;
1022 /* Wipeout the new line character */
1023 line[read - 1] = '\0';
1025 if(n == 0 || strlen(line) == 0){
1026 read = xbt_getline(&line, &n, fp);
1030 xbt_dynar_free(&split);
1031 xbt_str_rtrim(line, NULL);
1032 xbt_str_strip_spaces(line);
1033 split = xbt_str_split(line, " ");
1035 node_type = xbt_dynar_get_as(split, 1, char *);
1037 if(strncmp(node_type, "DW_AT_", 6) != 0){
1042 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1043 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1044 }else if(strcmp(node_type, "DW_AT_name") == 0){
1046 end = xbt_str_join(split, " ");
1047 xbt_dynar_free(&split);
1048 split = xbt_str_split(end, "):");
1049 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1050 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1051 }else if(strcmp(node_type, "DW_AT_type") == 0){
1052 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1053 xbt_str_ltrim(type_origin, "<0x");
1054 xbt_str_rtrim(type_origin, ">");
1055 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1057 end = xbt_str_join(split, " ");
1058 xbt_dynar_free(&split);
1059 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1060 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1061 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1062 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1065 read = xbt_getline(&line, &n, fp);
1069 if(member_end && type){
1072 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1073 member_type->name = xbt_strdup(name);
1074 member_type->size = size;
1075 member_type->is_pointer_type = is_pointer;
1076 member_type->id = (void *)strtoul(origin, NULL, 16);
1077 member_type->offset = offset;
1079 member_type->dw_type_id = xbt_strdup(type_origin);
1081 xbt_dynar_push(type->members, &member_type);
1087 xbt_free(type_origin);
1094 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1095 origin = strdup(strtok(NULL, "<"));
1096 xbt_str_rtrim(origin, ">:");
1100 if(struct_decl || union_decl){
1101 type = xbt_new0(s_dw_type_t, 1);
1103 type->type = e_dw_structure_type;
1105 type->type = e_dw_union_type;
1106 type->name = xbt_strdup(name);
1108 type->is_pointer_type = is_pointer;
1109 type->id = (void *)strtoul(origin, NULL, 16);
1111 type->dw_type_id = xbt_strdup(type_origin);
1112 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1114 xbt_dict_set(*types, origin, type, NULL);
1120 xbt_free(type_origin);
1128 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1131 read = xbt_getline(&line, &n, fp);
1138 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1140 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1141 origin = strdup(strtok(NULL, "<"));
1142 xbt_str_rtrim(origin, ">:");
1144 read = xbt_getline(&line, &n, fp);
1146 dw_type_t type = NULL;
1152 /* Wipeout the new line character */
1153 line[read - 1] = '\0';
1155 if(n == 0 || strlen(line) == 0){
1156 read = xbt_getline(&line, &n, fp);
1160 xbt_dynar_free(&split);
1161 xbt_str_rtrim(line, NULL);
1162 xbt_str_strip_spaces(line);
1163 split = xbt_str_split(line, " ");
1165 node_type = xbt_dynar_get_as(split, 1, char *);
1167 if(strncmp(node_type, "DW_AT_", 6) != 0)
1170 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1171 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1172 }else if(strcmp(node_type, "DW_AT_name") == 0){
1173 end = xbt_str_join(split, " ");
1174 xbt_dynar_free(&split);
1175 split = xbt_str_split(end, "):");
1176 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1177 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1178 }else if(strcmp(node_type, "DW_AT_type") == 0){
1179 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1180 xbt_str_ltrim(type_origin, "<0x");
1181 xbt_str_rtrim(type_origin, ">");
1184 read = xbt_getline(&line, &n, fp);
1188 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1192 if(subrange && type){
1199 xbt_free(type_origin);
1205 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1206 origin = strdup(strtok(NULL, "<"));
1207 xbt_str_rtrim(origin, ">:");
1211 type = xbt_new0(s_dw_type_t, 1);
1212 type->type = e_dw_array_type;
1213 type->name = xbt_strdup(name);
1214 type->is_pointer_type = is_pointer;
1215 type->id = (void *)strtoul(origin, NULL, 16);
1217 type->dw_type_id = xbt_strdup(type_origin);
1218 type->members = NULL;
1220 xbt_dict_set(*types, origin, type, NULL);
1226 xbt_free(type_origin);
1231 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1234 read = xbt_getline(&line, &n, fp);
1243 read = xbt_getline(&line, &n, fp);
1249 xbt_dynar_free(&split);
1250 xbt_dict_free(&variables_origin);
1251 xbt_dict_free(&subprograms_origin);
1254 xbt_dict_free(&location_list);
1261 /******************************* Ignore mechanism *******************************/
1262 /*********************************************************************************/
1264 xbt_dynar_t mc_checkpoint_ignore;
1266 typedef struct s_mc_stack_ignore_variable{
1269 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1271 typedef struct s_mc_data_bss_ignore_variable{
1273 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1275 /**************************** Free functions ******************************/
1277 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1278 xbt_free(v->var_name);
1283 static void stack_ignore_variable_free_voidp(void *v){
1284 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1287 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1291 void heap_ignore_region_free_voidp(void *r){
1292 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1295 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1300 static void data_bss_ignore_variable_free_voidp(void *v){
1301 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1304 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1308 static void checkpoint_ignore_region_free_voidp(void *r){
1309 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1312 /***********************************************************************/
1314 void MC_ignore_heap(void *address, size_t size){
1316 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1320 mc_heap_ignore_region_t region = NULL;
1321 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1322 region->address = address;
1323 region->size = size;
1325 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1327 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1328 region->fragment = -1;
1329 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1331 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1332 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1335 if(mc_heap_comparison_ignore == NULL){
1336 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1337 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1343 unsigned int cursor = 0;
1344 mc_heap_ignore_region_t current_region = NULL;
1346 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1348 while(start <= end){
1349 cursor = (start + end) / 2;
1350 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1351 if(current_region->address == address){
1352 heap_ignore_region_free(region);
1356 }else if(current_region->address < address){
1363 if(current_region->address < address)
1364 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1366 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1372 void MC_remove_ignore_heap(void *address, size_t size){
1374 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1378 unsigned int cursor = 0;
1380 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1381 mc_heap_ignore_region_t region;
1382 int ignore_found = 0;
1384 while(start <= end){
1385 cursor = (start + end) / 2;
1386 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1387 if(region->address == address){
1390 }else if(region->address < address){
1393 if((char * )region->address <= ((char *)address + size)){
1402 if(ignore_found == 1){
1403 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1404 MC_remove_ignore_heap(address, size);
1412 void MC_ignore_global_variable(const char *name){
1414 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1418 if(mc_libsimgrid_info){
1420 unsigned int cursor = 0;
1421 dw_variable_t current_var;
1423 int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1425 while(start <= end){
1426 cursor = (start + end) /2;
1427 current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
1428 if(strcmp(current_var->name, name) == 0){
1429 xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
1431 end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1432 }else if(strcmp(current_var->name, name) < 0){
1441 if(mc_data_bss_comparison_ignore == NULL)
1442 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1444 mc_data_bss_ignore_variable_t var = NULL;
1445 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1446 var->name = strdup(name);
1448 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1450 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1454 unsigned int cursor = 0;
1456 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1457 mc_data_bss_ignore_variable_t current_var = NULL;
1459 while(start <= end){
1460 cursor = (start + end) / 2;
1461 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1462 if(strcmp(current_var->name, name) == 0){
1463 data_bss_ignore_variable_free(var);
1467 }else if(strcmp(current_var->name, name) < 0){
1474 if(strcmp(current_var->name, name) < 0)
1475 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1477 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1486 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1488 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1492 if(mc_libsimgrid_info){
1493 unsigned int cursor = 0;
1494 dw_variable_t current_var;
1496 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1497 xbt_dict_cursor_t dict_cursor;
1498 char *current_frame_name;
1500 xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
1502 end = xbt_dynar_length(frame->variables) - 1;
1503 while(start <= end){
1504 cursor = (start + end) / 2;
1505 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1506 if(strcmp(current_var->name, var_name) == 0){
1507 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1509 end = xbt_dynar_length(frame->variables) - 1;
1510 }else if(strcmp(current_var->name, var_name) < 0){
1517 xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
1519 end = xbt_dynar_length(frame->variables) - 1;
1520 while(start <= end){
1521 cursor = (start + end) / 2;
1522 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1523 if(strcmp(current_var->name, var_name) == 0){
1524 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1526 end = xbt_dynar_length(frame->variables) - 1;
1527 }else if(strcmp(current_var->name, var_name) < 0){
1535 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
1536 mc_libsimgrid_info->local_variables, frame_name))->variables;
1538 end = xbt_dynar_length(variables_list) - 1;
1539 while(start <= end){
1540 cursor = (start + end) / 2;
1541 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1542 if(strcmp(current_var->name, var_name) == 0){
1543 xbt_dynar_remove_at(variables_list, cursor, NULL);
1545 end = xbt_dynar_length(variables_list) - 1;
1546 }else if(strcmp(current_var->name, var_name) < 0){
1555 if(mc_stack_comparison_ignore == NULL)
1556 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1558 mc_stack_ignore_variable_t var = NULL;
1559 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1560 var->var_name = strdup(var_name);
1561 var->frame = strdup(frame_name);
1563 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1565 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1569 unsigned int cursor = 0;
1571 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1572 mc_stack_ignore_variable_t current_var = NULL;
1574 while(start <= end){
1575 cursor = (start + end) / 2;
1576 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1577 if(strcmp(current_var->frame, frame_name) == 0){
1578 if(strcmp(current_var->var_name, var_name) == 0){
1579 stack_ignore_variable_free(var);
1583 }else if(strcmp(current_var->var_name, var_name) < 0){
1588 }else if(strcmp(current_var->frame, frame_name) < 0){
1595 if(strcmp(current_var->frame, frame_name) == 0){
1596 if(strcmp(current_var->var_name, var_name) < 0){
1597 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1599 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1601 }else if(strcmp(current_var->frame, frame_name) < 0){
1602 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1604 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1614 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1616 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1620 if(stacks_areas == NULL)
1621 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1623 stack_region_t region = NULL;
1624 region = xbt_new0(s_stack_region_t, 1);
1625 region->address = stack;
1626 region->process_name = strdup(name);
1627 region->context = context;
1628 region->size = size;
1629 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1630 xbt_dynar_push(stacks_areas, ®ion);
1636 void MC_ignore(void *addr, size_t size){
1638 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1642 if(mc_checkpoint_ignore == NULL)
1643 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1645 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1646 region->addr = addr;
1647 region->size = size;
1649 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1650 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1653 unsigned int cursor = 0;
1655 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1656 mc_checkpoint_ignore_region_t current_region = NULL;
1658 while(start <= end){
1659 cursor = (start + end) / 2;
1660 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1661 if(current_region->addr == addr){
1662 if(current_region->size == size){
1663 checkpoint_ignore_region_free(region);
1667 }else if(current_region->size < size){
1672 }else if(current_region->addr < addr){
1679 if(current_region->addr == addr){
1680 if(current_region->size < size){
1681 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1683 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1685 }else if(current_region->addr < addr){
1686 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1688 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1696 /******************************* Initialisation of MC *******************************/
1697 /*********************************************************************************/
1699 static void MC_dump_ignored_local_variables(void){
1701 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1704 unsigned int cursor = 0;
1705 mc_stack_ignore_variable_t current_var;
1707 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1708 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1711 xbt_dynar_free(&mc_stack_comparison_ignore);
1712 mc_stack_comparison_ignore = NULL;
1716 static void MC_dump_ignored_global_variables(void){
1718 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1721 unsigned int cursor = 0;
1722 mc_data_bss_ignore_variable_t current_var;
1724 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1725 MC_ignore_global_variable(current_var->name);
1728 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1729 mc_data_bss_comparison_ignore = NULL;
1735 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1739 /* Initialize the data structures that must be persistent across every
1740 iteration of the model-checker (in RAW memory) */
1744 MC_init_memory_map_info();
1746 XBT_INFO("Get debug information ...");
1748 /* Get local variables for state equality detection */
1749 mc_binary_info = MC_dwarf_get_variables(xbt_binary_name);
1750 mc_libsimgrid_info = MC_dwarf_get_variables(libsimgrid_path);
1752 XBT_INFO("Get debug information done !");
1754 /* Remove variables ignored before getting list of variables */
1755 MC_dump_ignored_local_variables();
1756 MC_dump_ignored_global_variables();
1758 /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
1759 MC_get_libsimgrid_plt_section();
1760 MC_get_binary_plt_section();
1763 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1767 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1768 MC_ignore_local_variable("e", "*");
1769 MC_ignore_local_variable("__ex_cleanup", "*");
1770 MC_ignore_local_variable("__ex_mctx_en", "*");
1771 MC_ignore_local_variable("__ex_mctx_me", "*");
1772 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1773 MC_ignore_local_variable("_log_ev", "*");
1774 MC_ignore_local_variable("_throw_ctx", "*");
1775 MC_ignore_local_variable("ctx", "*");
1777 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1778 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1780 /* Ignore local variable about time used for tracing */
1781 MC_ignore_local_variable("start_time", "*");
1783 MC_ignore_global_variable("mc_comp_times");
1784 MC_ignore_global_variable("mc_snapshot_comparison_time");
1785 MC_ignore_global_variable("mc_time");
1786 MC_ignore_global_variable("smpi_current_rank");
1787 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1788 MC_ignore_global_variable("maestro_stack_start");
1789 MC_ignore_global_variable("maestro_stack_end");
1791 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1792 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1793 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1794 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1796 smx_process_t process;
1797 xbt_swag_foreach(process, simix_global->process_list){
1798 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1806 static void MC_init_dot_output(){ /* FIXME : more colors */
1810 colors[2] = "green3";
1811 colors[3] = "goldenrod";
1812 colors[4] = "brown";
1813 colors[5] = "purple";
1814 colors[6] = "magenta";
1815 colors[7] = "turquoise4";
1816 colors[8] = "gray25";
1817 colors[9] = "forestgreen";
1818 colors[10] = "hotpink";
1819 colors[11] = "lightblue";
1822 dot_output = fopen(_sg_mc_dot_output_file, "w");
1824 if(dot_output == NULL){
1825 perror("Error open dot output file");
1829 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");
1833 /******************************* Core of MC *******************************/
1834 /**************************************************************************/
1836 void MC_do_the_modelcheck_for_real() {
1839 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1842 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1843 if (mc_reduce_kind==e_mc_reduce_unset)
1844 mc_reduce_kind=e_mc_reduce_dpor;
1846 XBT_INFO("Check a safety property");
1847 MC_modelcheck_safety();
1851 if (mc_reduce_kind==e_mc_reduce_unset)
1852 mc_reduce_kind=e_mc_reduce_none;
1854 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1855 MC_automaton_load(_sg_mc_property_file);
1856 MC_modelcheck_liveness();
1860 void MC_modelcheck_safety(void)
1862 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1864 /* Check if MC is already initialized */
1865 if (initial_state_safety)
1868 mc_time = xbt_new0(double, simix_process_maxpid);
1870 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1871 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1873 /* Initialize the data structures that must be persistent across every
1874 iteration of the model-checker (in RAW memory) */
1878 /* Initialize statistics */
1879 mc_stats = xbt_new0(s_mc_stats_t, 1);
1880 mc_stats->state_size = 1;
1882 /* Create exploration stack */
1883 mc_stack_safety = xbt_fifo_new();
1885 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1886 MC_init_dot_output();
1890 if(_sg_mc_visited > 0){
1894 MC_init_memory_map_info();
1895 MC_get_libsimgrid_plt_section();
1896 MC_get_binary_plt_section();
1903 /* Save the initial state */
1904 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1905 initial_state_safety->snapshot = MC_take_snapshot(0);
1917 void MC_modelcheck_liveness(){
1919 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1923 mc_time = xbt_new0(double, simix_process_maxpid);
1925 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1926 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1930 /* Initialize statistics */
1931 mc_stats = xbt_new0(s_mc_stats_t, 1);
1932 mc_stats->state_size = 1;
1934 /* Create exploration stack */
1935 mc_stack_liveness = xbt_fifo_new();
1937 /* Create the initial state */
1938 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
1940 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1941 MC_init_dot_output();
1948 MC_print_statistics(mc_stats);
1964 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
1966 return simcall->mc_value;
1970 int MC_random(int min, int max)
1972 /*FIXME: return mc_current_state->executed_transition->random.value;*/
1973 return simcall_mc_random(min, max);
1977 * \brief Schedules all the process that are ready to run
1979 void MC_wait_for_requests(void)
1981 smx_process_t process;
1985 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
1986 SIMIX_process_runall();
1987 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
1988 req = &process->simcall;
1989 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
1990 SIMIX_simcall_pre(req, 0);
1995 int MC_deadlock_check()
1997 int deadlock = FALSE;
1998 smx_process_t process;
1999 if(xbt_swag_size(simix_global->process_list)){
2001 xbt_swag_foreach(process, simix_global->process_list){
2002 if(process->simcall.call != SIMCALL_NONE
2003 && MC_request_is_enabled(&process->simcall)){
2013 * \brief Re-executes from the state at position start all the transitions indicated by
2014 * a given model-checker stack.
2015 * \param stack The stack with the transitions to execute.
2016 * \param start Start index to begin the re-execution.
2018 void MC_replay(xbt_fifo_t stack, int start)
2020 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2022 int value, i = 1, count = 1;
2024 smx_simcall_t req = NULL, saved_req = NULL;
2025 xbt_fifo_item_t item, start_item;
2027 smx_process_t process = NULL;
2029 XBT_DEBUG("**** Begin Replay ****");
2032 /* Restore the initial state */
2033 MC_restore_snapshot(initial_state_safety->snapshot);
2034 /* At the moment of taking the snapshot the raw heap was set, so restoring
2035 * it will set it back again, we have to unset it to continue */
2039 start_item = xbt_fifo_get_last_item(stack);
2042 start_item = xbt_fifo_get_prev_item(start_item);
2048 xbt_dict_reset(first_enabled_state);
2049 xbt_swag_foreach(process, simix_global->process_list){
2050 if(MC_process_is_enabled(process)){
2051 char *key = bprintf("%lu", process->pid);
2052 char *data = bprintf("%d", count);
2053 xbt_dict_set(first_enabled_state, key, data, NULL);
2060 /* Traverse the stack from the state at position start and re-execute the transitions */
2061 for (item = start_item;
2062 item != xbt_fifo_get_first_item(stack);
2063 item = xbt_fifo_get_prev_item(item)) {
2065 state = (mc_state_t) xbt_fifo_get_item_content(item);
2066 saved_req = MC_state_get_executed_request(state, &value);
2069 char *key = bprintf("%lu", saved_req->issuer->pid);
2070 xbt_dict_remove(first_enabled_state, key);
2075 /* because we got a copy of the executed request, we have to fetch the
2076 real one, pointed by the request field of the issuer process */
2077 req = &saved_req->issuer->simcall;
2079 /* Debug information */
2080 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2081 req_str = MC_request_to_string(req, value);
2082 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2087 SIMIX_simcall_pre(req, value);
2088 MC_wait_for_requests();
2093 /* Insert in dict all enabled processes */
2094 xbt_swag_foreach(process, simix_global->process_list){
2095 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2096 char *key = bprintf("%lu", process->pid);
2097 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2098 char *data = bprintf("%d", count);
2099 xbt_dict_set(first_enabled_state, key, data, NULL);
2106 /* Update statistics */
2107 mc_stats->visited_states++;
2108 mc_stats->executed_transitions++;
2112 XBT_DEBUG("**** End Replay ****");
2122 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2125 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2129 smx_simcall_t req = NULL, saved_req = NULL;
2130 xbt_fifo_item_t item;
2135 XBT_DEBUG("**** Begin Replay ****");
2137 /* Restore the initial state */
2138 MC_restore_snapshot(initial_state_liveness->snapshot);
2140 /* At the moment of taking the snapshot the raw heap was set, so restoring
2141 * it will set it back again, we have to unset it to continue */
2142 if(!initial_state_liveness->raw_mem_set)
2147 item = xbt_fifo_get_last_item(stack);
2149 while(depth <= xbt_fifo_size(stack)){
2151 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2152 state = (mc_state_t) pair->graph_state;
2154 if(pair->requests > 0){
2156 saved_req = MC_state_get_executed_request(state, &value);
2157 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2159 if(saved_req != NULL){
2160 /* because we got a copy of the executed request, we have to fetch the
2161 real one, pointed by the request field of the issuer process */
2162 req = &saved_req->issuer->simcall;
2163 //XBT_DEBUG("Req->call %u", req->call);
2165 /* Debug information */
2166 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2167 req_str = MC_request_to_string(req, value);
2168 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2174 SIMIX_simcall_pre(req, value);
2175 MC_wait_for_requests();
2180 /* Update statistics */
2181 mc_stats->visited_pairs++;
2182 mc_stats->executed_transitions++;
2184 item = xbt_fifo_get_prev_item(item);
2189 /* Traverse the stack from the initial state and re-execute the transitions */
2190 for (item = xbt_fifo_get_last_item(stack);
2191 item != xbt_fifo_get_first_item(stack);
2192 item = xbt_fifo_get_prev_item(item)) {
2194 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2195 state = (mc_state_t) pair->graph_state;
2197 if(pair->requests > 0){
2199 saved_req = MC_state_get_executed_request(state, &value);
2200 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2202 if(saved_req != NULL){
2203 /* because we got a copy of the executed request, we have to fetch the
2204 real one, pointed by the request field of the issuer process */
2205 req = &saved_req->issuer->simcall;
2206 //XBT_DEBUG("Req->call %u", req->call);
2208 /* Debug information */
2209 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2210 req_str = MC_request_to_string(req, value);
2211 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2217 SIMIX_simcall_pre(req, value);
2218 MC_wait_for_requests();
2223 /* Update statistics */
2224 mc_stats->visited_pairs++;
2225 mc_stats->executed_transitions++;
2229 XBT_DEBUG("**** End Replay ****");
2231 if(initial_state_liveness->raw_mem_set)
2239 * \brief Dumps the contents of a model-checker's stack and shows the actual
2241 * \param stack The stack to dump
2243 void MC_dump_stack_safety(xbt_fifo_t stack)
2246 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2248 MC_show_stack_safety(stack);
2250 if(!_sg_mc_checkpoint){
2255 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2256 MC_state_delete(state);
2269 void MC_show_stack_safety(xbt_fifo_t stack)
2272 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2278 xbt_fifo_item_t item;
2280 char *req_str = NULL;
2282 for (item = xbt_fifo_get_last_item(stack);
2283 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2284 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2285 req = MC_state_get_executed_request(state, &value);
2287 req_str = MC_request_to_string(req, value);
2288 XBT_INFO("%s", req_str);
2297 void MC_show_deadlock(smx_simcall_t req)
2299 /*char *req_str = NULL;*/
2300 XBT_INFO("**************************");
2301 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2302 XBT_INFO("**************************");
2303 XBT_INFO("Locked request:");
2304 /*req_str = MC_request_to_string(req);
2305 XBT_INFO("%s", req_str);
2306 xbt_free(req_str);*/
2307 XBT_INFO("Counter-example execution trace:");
2308 MC_dump_stack_safety(mc_stack_safety);
2309 MC_print_statistics(mc_stats);
2313 void MC_show_stack_liveness(xbt_fifo_t stack){
2316 xbt_fifo_item_t item;
2318 char *req_str = NULL;
2320 for (item = xbt_fifo_get_last_item(stack);
2321 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2322 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2323 req = MC_state_get_executed_request(pair->graph_state, &value);
2325 if(pair->requests>0){
2326 req_str = MC_request_to_string(req, value);
2327 XBT_INFO("%s", req_str);
2330 XBT_INFO("End of system requests but evolution in Büchi automaton");
2336 void MC_dump_stack_liveness(xbt_fifo_t stack){
2338 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2343 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2344 MC_pair_delete(pair);
2353 void MC_print_statistics(mc_stats_t stats)
2355 if(stats->expanded_pairs == 0){
2356 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2357 XBT_INFO("Visited states = %lu", stats->visited_states);
2359 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2360 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2362 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2364 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2365 fprintf(dot_output, "}\n");
2371 void MC_assert(int prop)
2373 if (MC_is_active() && !prop){
2374 XBT_INFO("**************************");
2375 XBT_INFO("*** PROPERTY NOT VALID ***");
2376 XBT_INFO("**************************");
2377 XBT_INFO("Counter-example execution trace:");
2378 MC_dump_stack_safety(mc_stack_safety);
2379 MC_print_statistics(mc_stats);
2385 user_max_depth_reached = 1;
2388 void MC_process_clock_add(smx_process_t process, double amount)
2390 mc_time[process->pid] += amount;
2393 double MC_process_clock_get(smx_process_t process)
2397 return mc_time[process->pid];
2405 void MC_automaton_load(const char *file){
2407 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2411 if (_mc_property_automaton == NULL)
2412 _mc_property_automaton = xbt_automaton_new();
2414 xbt_automaton_load(_mc_property_automaton,file);
2423 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2425 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2429 if (_mc_property_automaton == NULL)
2430 _mc_property_automaton = xbt_automaton_new();
2432 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);