1 /* Copyright (c) 2008-2013. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "simgrid/sg_config.h"
14 #include "../surf/surf_private.h"
15 #include "../simix/smx_private.h"
16 #include "../xbt/mmalloc/mmprivate.h"
18 #include "mc_private.h"
19 #include "xbt/automaton.h"
22 static void MC_post_process_types(mc_object_info_t info);
24 XBT_LOG_NEW_CATEGORY(mc, "All MC categories");
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
26 "Logging specific to MC (global)");
28 /* Configuration support */
29 e_mc_reduce_t mc_reduce_kind=e_mc_reduce_unset;
31 int _sg_do_model_check = 0;
32 int _sg_mc_checkpoint=0;
33 char* _sg_mc_property_file=NULL;
35 int _sg_mc_max_depth=1000;
37 char *_sg_mc_dot_output_file = NULL;
39 int user_max_depth_reached = 0;
41 void _mc_cfg_cb_reduce(const char *name, int pos) {
42 if (_sg_cfg_init_status && !_sg_do_model_check) {
43 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.");
45 char *val= xbt_cfg_get_string(_sg_cfg_set, name);
46 if (!strcasecmp(val,"none")) {
47 mc_reduce_kind = e_mc_reduce_none;
48 } else if (!strcasecmp(val,"dpor")) {
49 mc_reduce_kind = e_mc_reduce_dpor;
51 xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",name);
55 void _mc_cfg_cb_checkpoint(const char *name, int pos) {
56 if (_sg_cfg_init_status && !_sg_do_model_check) {
57 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.");
59 _sg_mc_checkpoint = xbt_cfg_get_int(_sg_cfg_set, name);
61 void _mc_cfg_cb_property(const char *name, int pos) {
62 if (_sg_cfg_init_status && !_sg_do_model_check) {
63 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.");
65 _sg_mc_property_file= xbt_cfg_get_string(_sg_cfg_set, name);
68 void _mc_cfg_cb_timeout(const char *name, int pos) {
69 if (_sg_cfg_init_status && !_sg_do_model_check) {
70 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.");
72 _sg_mc_timeout= xbt_cfg_get_boolean(_sg_cfg_set, name);
75 void _mc_cfg_cb_max_depth(const char *name, int pos) {
76 if (_sg_cfg_init_status && !_sg_do_model_check) {
77 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.");
79 _sg_mc_max_depth= xbt_cfg_get_int(_sg_cfg_set, name);
82 void _mc_cfg_cb_visited(const char *name, int pos) {
83 if (_sg_cfg_init_status && !_sg_do_model_check) {
84 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.");
86 _sg_mc_visited= xbt_cfg_get_int(_sg_cfg_set, name);
89 void _mc_cfg_cb_dot_output(const char *name, int pos) {
90 if (_sg_cfg_init_status && !_sg_do_model_check) {
91 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.");
93 _sg_mc_dot_output_file= xbt_cfg_get_string(_sg_cfg_set, name);
96 /* MC global data structures */
97 mc_state_t mc_current_state = NULL;
98 char mc_replay_mode = FALSE;
99 double *mc_time = NULL;
100 __thread mc_comparison_times_t mc_comp_times = NULL;
101 __thread double mc_snapshot_comparison_time;
102 mc_stats_t mc_stats = NULL;
105 xbt_fifo_t mc_stack_safety = NULL;
106 mc_global_t initial_state_safety = NULL;
109 xbt_fifo_t mc_stack_liveness = NULL;
110 mc_global_t initial_state_liveness = NULL;
113 xbt_automaton_t _mc_property_automaton = NULL;
116 mc_object_info_t mc_libsimgrid_info = NULL;
117 mc_object_info_t mc_binary_info = NULL;
119 /* Ignore mechanism */
120 xbt_dynar_t mc_stack_comparison_ignore;
121 xbt_dynar_t mc_data_bss_comparison_ignore;
122 extern xbt_dynar_t mc_heap_comparison_ignore;
123 extern xbt_dynar_t stacks_areas;
126 FILE *dot_output = NULL;
127 const char* colors[13];
130 /******************************* DWARF Information *******************************/
131 /**********************************************************************************/
133 /************************** Free functions *************************/
135 static void dw_location_free(dw_location_t l){
137 if(l->type == e_dw_loclist)
138 xbt_dynar_free(&(l->location.loclist));
139 else if(l->type == e_dw_compose)
140 xbt_dynar_free(&(l->location.compose));
141 else if(l->type == e_dw_arithmetic)
142 xbt_free(l->location.arithmetic);
148 static void dw_location_entry_free(dw_location_entry_t e){
149 dw_location_free(e->location);
153 void dw_type_free(dw_type_t t){
155 xbt_free(t->dw_type_id);
156 xbt_dynar_free(&(t->members));
160 static void dw_type_free_voidp(void *t){
161 dw_type_free((dw_type_t) * (void **) t);
164 void dw_variable_free(dw_variable_t v){
167 xbt_free(v->type_origin);
169 dw_location_free(v->address.location);
174 void dw_variable_free_voidp(void *t){
175 dw_variable_free((dw_variable_t) * (void **) t);
180 mc_object_info_t MC_new_object_info(void) {
181 mc_object_info_t res = xbt_new(s_mc_object_info_t, 1);
182 res->file_name = NULL;
183 res->start_text = NULL;
184 res->start_data = NULL;
185 res->start_bss = NULL;
186 res->local_variables = xbt_dict_new_homogeneous(NULL);
187 res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
188 res->types = xbt_dict_new_homogeneous(NULL);
192 void MC_free_object_info(mc_object_info_t* info) {
193 xbt_free(&(*info)->file_name);
194 xbt_dict_free(&(*info)->local_variables);
195 xbt_dynar_free(&(*info)->global_variables);
196 xbt_dict_free(&(*info)->types);
197 xbt_dict_free(&((*info)->location_list));
202 /*************************************************************************/
204 static dw_location_t MC_dwarf_get_location(xbt_dict_t location_list, char *expr){
206 dw_location_t loc = xbt_new0(s_dw_location_t, 1);
208 if(location_list != NULL){
210 char *key = bprintf("%d", (int)strtoul(expr, NULL, 16));
211 loc->type = e_dw_loclist;
212 loc->location.loclist = (xbt_dynar_t)xbt_dict_get_or_null(location_list, key);
213 if(loc->location.loclist == NULL)
214 XBT_INFO("Key not found in loclist");
221 char *tok = NULL, *tok2 = NULL;
223 xbt_dynar_t tokens1 = xbt_str_split(expr, ";");
226 loc->type = e_dw_compose;
227 loc->location.compose = xbt_dynar_new(sizeof(dw_location_t), NULL);
229 while(cursor < xbt_dynar_length(tokens1)){
231 tok = xbt_dynar_get_as(tokens1, cursor, char*);
232 tokens2 = xbt_str_split(tok, " ");
233 tok2 = xbt_dynar_get_as(tokens2, 0, char*);
235 if(strncmp(tok2, "DW_OP_reg", 9) == 0){
236 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
237 new_element->type = e_dw_register;
238 new_element->location.reg = atoi(strtok(tok2, "DW_OP_reg"));
239 xbt_dynar_push(loc->location.compose, &new_element);
240 }else if(strcmp(tok2, "DW_OP_fbreg:") == 0){
241 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
242 new_element->type = e_dw_fbregister_op;
243 new_element->location.fbreg_op = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
244 xbt_dynar_push(loc->location.compose, &new_element);
245 }else if(strncmp(tok2, "DW_OP_breg", 10) == 0){
246 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
247 new_element->type = e_dw_bregister_op;
248 new_element->location.breg_op.reg = atoi(strtok(tok2, "DW_OP_breg"));
249 new_element->location.breg_op.offset = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
250 xbt_dynar_push(loc->location.compose, &new_element);
251 }else if(strncmp(tok2, "DW_OP_lit", 9) == 0){
252 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
253 new_element->type = e_dw_lit;
254 new_element->location.lit = atoi(strtok(tok2, "DW_OP_lit"));
255 xbt_dynar_push(loc->location.compose, &new_element);
256 }else if(strcmp(tok2, "DW_OP_piece:") == 0){
257 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
258 new_element->type = e_dw_piece;
259 new_element->location.piece = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
260 xbt_dynar_push(loc->location.compose, &new_element);
261 }else if(strcmp(tok2, "DW_OP_plus_uconst:") == 0){
262 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
263 new_element->type = e_dw_plus_uconst;
264 new_element->location.plus_uconst = atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char *));
265 xbt_dynar_push(loc->location.compose, &new_element);
266 }else if(strcmp(tok, "DW_OP_abs") == 0 ||
267 strcmp(tok, "DW_OP_and") == 0 ||
268 strcmp(tok, "DW_OP_div") == 0 ||
269 strcmp(tok, "DW_OP_minus") == 0 ||
270 strcmp(tok, "DW_OP_mod") == 0 ||
271 strcmp(tok, "DW_OP_mul") == 0 ||
272 strcmp(tok, "DW_OP_neg") == 0 ||
273 strcmp(tok, "DW_OP_not") == 0 ||
274 strcmp(tok, "DW_OP_or") == 0 ||
275 strcmp(tok, "DW_OP_plus") == 0){
276 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
277 new_element->type = e_dw_arithmetic;
278 new_element->location.arithmetic = strdup(strtok(tok2, "DW_OP_"));
279 xbt_dynar_push(loc->location.compose, &new_element);
280 }else if(strcmp(tok, "DW_OP_stack_value") == 0){
281 }else if(strcmp(tok2, "DW_OP_deref_size:") == 0){
282 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
283 new_element->type = e_dw_deref;
284 new_element->location.deref_size = (unsigned int short) atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*));
285 xbt_dynar_push(loc->location.compose, &new_element);
286 }else if(strcmp(tok, "DW_OP_deref") == 0){
287 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
288 new_element->type = e_dw_deref;
289 new_element->location.deref_size = sizeof(void *);
290 xbt_dynar_push(loc->location.compose, &new_element);
291 }else if(strcmp(tok2, "DW_OP_constu:") == 0){
292 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
293 new_element->type = e_dw_uconstant;
294 new_element->location.uconstant.bytes = 1;
295 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
296 xbt_dynar_push(loc->location.compose, &new_element);
297 }else if(strcmp(tok2, "DW_OP_consts:") == 0){
298 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
299 new_element->type = e_dw_sconstant;
300 new_element->location.sconstant.bytes = 1;
301 new_element->location.sconstant.value = (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(tok2, "DW_OP_const1u:") == 0 ||
304 strcmp(tok2, "DW_OP_const2u:") == 0 ||
305 strcmp(tok2, "DW_OP_const4u:") == 0 ||
306 strcmp(tok2, "DW_OP_const8u:") == 0){
307 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
308 new_element->type = e_dw_uconstant;
309 new_element->location.uconstant.bytes = tok2[11] - '0';
310 new_element->location.uconstant.value = (unsigned long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
311 xbt_dynar_push(loc->location.compose, &new_element);
312 }else if(strcmp(tok, "DW_OP_const1s") == 0 ||
313 strcmp(tok, "DW_OP_const2s") == 0 ||
314 strcmp(tok, "DW_OP_const4s") == 0 ||
315 strcmp(tok, "DW_OP_const8s") == 0){
316 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
317 new_element->type = e_dw_sconstant;
318 new_element->location.sconstant.bytes = tok2[11] - '0';
319 new_element->location.sconstant.value = (long int)(atoi(xbt_dynar_get_as(tokens2, xbt_dynar_length(tokens2) - 1, char*)));
320 xbt_dynar_push(loc->location.compose, &new_element);
322 dw_location_t new_element = xbt_new0(s_dw_location_t, 1);
323 new_element->type = e_dw_unsupported;
324 xbt_dynar_push(loc->location.compose, &new_element);
328 xbt_dynar_free(&tokens2);
332 xbt_dynar_free(&tokens1);
340 /** @brief Extract the location lists from an ELF file (.debug_loc)
342 * @return A map from the offset in the list (in hexadecimal string)
343 * into a location list (dynar of dw_location_entry_t).
345 xbt_dict_t MC_dwarf_get_location_list(const char *elf_file){
347 char *command = bprintf("LANG=C objdump -Wo %s", elf_file);
349 FILE *fp = popen(command, "r");
352 perror("popen for objdump failed");
356 int debug = 0; /*Detect if the program has been compiled with -g */
358 xbt_dict_t location_list = xbt_dict_new_homogeneous(NULL);
359 char *line = NULL, *loc_expr = NULL;
363 xbt_dynar_t split = NULL;
365 while ((read = xbt_getline(&line, &n, fp)) != -1) {
367 /* Wipeout the new line character */
368 line[read - 1] = '\0';
370 xbt_str_trim(line, NULL);
375 if(strlen(line) == 0)
380 if(strncmp(line, elf_file, strlen(elf_file)) == 0)
383 if(strncmp(line, "Contents", 8) == 0)
386 if(strncmp(line, "Offset", 6) == 0){
393 XBT_INFO("Your program must be compiled with -g");
397 xbt_dynar_t loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
399 xbt_str_strip_spaces(line);
400 split = xbt_str_split(line, " ");
403 while(read != -1 && strcmp("<End", (char *)xbt_dynar_get_as(split, 1, char *)) != 0){
405 // Take the key from the first line of the list:
407 key = bprintf("%d", (int)strtoul((char *)xbt_dynar_get_as(split, 0, char *), NULL, 16));
410 dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
411 new_entry->lowpc = strtoul((char *)xbt_dynar_get_as(split, 1, char *), NULL, 16);
412 new_entry->highpc = strtoul((char *)xbt_dynar_get_as(split, 2, char *), NULL, 16);
415 while(cursor_remove < 3){
416 xbt_dynar_remove_at(split, 0, NULL);
420 loc_expr = xbt_str_join(split, " ");
421 xbt_str_ltrim(loc_expr, "(");
422 xbt_str_rtrim(loc_expr, ")");
423 new_entry->location = MC_dwarf_get_location(NULL, loc_expr);
425 xbt_dynar_push(loclist, &new_entry);
427 xbt_dynar_free(&split);
430 read = xbt_getline(&line, &n, fp);
432 line[read - 1] = '\0';
433 xbt_str_strip_spaces(line);
434 split = xbt_str_split(line, " ");
440 xbt_dict_set(location_list, key, loclist, NULL);
443 xbt_dynar_free(&split);
451 return location_list;
454 /** \brief Finds a frame (DW_TAG_subprogram) from an DWARF offset in the rangd of this subprogram
456 * The offset can be an offset of a child DW_TAG_variable.
458 static dw_frame_t MC_dwarf_get_frame_by_offset(xbt_dict_t all_variables, unsigned long int offset){
460 xbt_dict_cursor_t cursor = NULL;
464 xbt_dict_foreach(all_variables, cursor, name, res) {
465 if(offset >= res->start && offset < res->end){
466 xbt_dict_cursor_free(&cursor);
471 xbt_dict_cursor_free(&cursor);
476 static dw_variable_t MC_dwarf_get_variable_by_name(dw_frame_t frame, char *var){
478 unsigned int cursor = 0;
479 dw_variable_t current_var;
481 xbt_dynar_foreach(frame->variables, cursor, current_var){
482 if(strcmp(var, current_var->name) == 0)
489 static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *address){
491 if(xbt_dynar_is_empty(variables))
494 unsigned int cursor = 0;
496 int end = xbt_dynar_length(variables) - 1;
497 dw_variable_t var_test = NULL;
500 cursor = (start + end) / 2;
501 var_test = (dw_variable_t)xbt_dynar_get_as(variables, cursor, dw_variable_t);
502 if(strcmp(var_test->name, var) < 0){
504 }else if(strcmp(var_test->name, var) > 0){
507 if(address){ /* global variable */
508 if(var_test->address.address == address)
510 if(var_test->address.address > address)
514 }else{ /* local variable */
520 if(strcmp(var_test->name, var) == 0){
521 if(address && var_test->address.address < address)
525 }else if(strcmp(var_test->name, var) < 0)
532 void MC_dwarf_get_variables_legacy(mc_object_info_t info);
534 /** \brief Fill DWARf debug infomations (types, frames, variables ...). */
535 void MC_dwarf_get_variables(mc_object_info_t info) {
537 MC_dwarf_get_variables_libdw(info);
538 MC_post_process_types(info);
540 MC_dwarf_get_variables_legacy(info);
544 void MC_dwarf_get_variables_legacy(mc_object_info_t info) {
546 mc_object_info_t result = info;
547 const char *elf_file = info->file_name;
549 char *command = bprintf("LANG=C objdump -Wi %s", elf_file);
551 FILE *fp = popen(command, "r");
554 perror("popen for objdump failed");
556 xbt_dict_t *local_variables = &result->local_variables;
557 xbt_dict_t *types = &result->types;
559 char *line = NULL, *origin, *abstract_origin, *current_frame = NULL,
560 *subprogram_name = NULL, *subprogram_start = NULL, *subprogram_end = NULL,
561 *node_type = NULL, *location_type = NULL, *variable_name = NULL,
562 *loc_expr = NULL, *name = NULL, *end =NULL, *type_origin = NULL, *global_address = NULL,
563 *parent_value = NULL;
567 int global_variable = 0, parent = 0, new_frame = 0, new_variable = 1, size = 0,
568 is_pointer = 0, struct_decl = 0, member_end = 0,
569 enumeration_size = 0, subrange = 0, union_decl = 0, offset = 0;
571 xbt_dynar_t split = NULL, split2 = NULL;
573 xbt_dict_t variables_origin = xbt_dict_new_homogeneous(xbt_free);
574 xbt_dict_t subprograms_origin = xbt_dict_new_homogeneous(xbt_free);
576 dw_frame_t variable_frame, subroutine_frame = NULL;
578 e_dw_type_type type_type = -1;
580 read = xbt_getline(&line, &n, fp);
584 /* Wipeout the new line character */
585 line[read - 1] = '\0';
587 if(n == 0 || strlen(line) == 0){
588 read = xbt_getline(&line, &n, fp);
592 xbt_str_ltrim(line, NULL);
593 xbt_str_strip_spaces(line);
596 read = xbt_getline(&line, &n, fp);
600 xbt_dynar_free(&split);
601 split = xbt_str_split(line, " ");
604 node_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
606 if(strcmp(node_type, "(DW_TAG_subprogram)") == 0){ /* New frame */
607 /* We build/complete a dw_frame_t object
608 * and append it if necessary to the local_variables dictionnary */
610 dw_frame_t frame = NULL;
612 strtok(xbt_dynar_get_as(split, 0, char *), "<");
613 subprogram_start = xbt_strdup(strtok(NULL, "<"));
614 xbt_str_rtrim(subprogram_start, ">:");
616 read = xbt_getline(&line, &n, fp);
620 /* Wipeout the new line character */
621 line[read - 1] = '\0';
623 if(n == 0 || strlen(line) == 0){
624 read = xbt_getline(&line, &n, fp);
628 xbt_dynar_free(&split);
629 xbt_str_rtrim(line, NULL);
630 xbt_str_strip_spaces(line);
631 split = xbt_str_split(line, " ");
633 node_type = xbt_dynar_get_as(split, 1, char *);
635 if(strncmp(node_type, "DW_AT_", 6) != 0)
638 if(strcmp(node_type, "DW_AT_sibling") == 0){
640 subprogram_end = xbt_strdup(xbt_dynar_get_as(split, 3, char*));
641 xbt_str_ltrim(subprogram_end, "<0x");
642 xbt_str_rtrim(subprogram_end, ">");
644 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){ /* Frame already in dict */
647 abstract_origin = xbt_strdup(xbt_dynar_get_as(split, 2, char*));
648 xbt_str_ltrim(abstract_origin, "<0x");
649 xbt_str_rtrim(abstract_origin, ">");
650 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, abstract_origin);
651 frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
652 xbt_free(abstract_origin);
654 }else if(strcmp(node_type, "DW_AT_name") == 0){
657 xbt_free(current_frame);
658 frame = xbt_new0(s_dw_frame_t, 1);
659 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
660 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
661 frame->frame_base = xbt_new0(s_dw_location_t, 1);
662 current_frame = strdup(frame->name);
664 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
666 }else if(strcmp(node_type, "DW_AT_frame_base") == 0){
668 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
670 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
672 frame->frame_base = MC_dwarf_get_location(info->location_list, xbt_dynar_get_as(split, 3, char *));
676 xbt_str_strip_spaces(line);
677 split2 = xbt_str_split(line, "(");
678 xbt_dynar_remove_at(split2, 0, NULL);
679 loc_expr = xbt_str_join(split2, " ");
680 xbt_str_rtrim(loc_expr, ")");
681 frame->frame_base = MC_dwarf_get_location(NULL, loc_expr);
682 xbt_dynar_free(&split2);
687 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
690 frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
692 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
695 frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
697 }else if(strcmp(node_type, "DW_AT_MIPS_linkage_name:") == 0){
699 xbt_free(frame->name);
700 xbt_free(current_frame);
701 frame->name = strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
702 current_frame = strdup(frame->name);
703 xbt_dict_set(subprograms_origin, subprogram_start, xbt_strdup(frame->name), NULL);
707 read = xbt_getline(&line, &n, fp);
712 frame->start = strtoul(subprogram_start, NULL, 16);
713 if(subprogram_end != NULL)
714 frame->end = strtoul(subprogram_end, NULL, 16);
715 xbt_dict_set(*local_variables, frame->name, frame, NULL);
718 xbt_free(subprogram_start);
719 xbt_free(subprogram_end);
720 subprogram_end = NULL;
723 }else if(strcmp(node_type, "(DW_TAG_variable)") == 0){ /* New variable */
724 /* We build a dw_variable_t object and append it either to
725 the list of variables of the frame (local variable)
726 or to the list of global variables (global variables). */
728 dw_variable_t var = NULL;
730 parent_value = strdup(xbt_dynar_get_as(split, 0, char *));
731 parent_value = strtok(parent_value,"<");
732 xbt_str_rtrim(parent_value, ">");
733 parent = atoi(parent_value);
734 xbt_free(parent_value);
739 strtok(xbt_dynar_get_as(split, 0, char *), "<");
740 origin = xbt_strdup(strtok(NULL, "<"));
741 xbt_str_rtrim(origin, ">:");
743 read = xbt_getline(&line, &n, fp);
747 /* Wipeout the new line character */
748 line[read - 1] = '\0';
750 if(n == 0 || strlen(line) == 0){
751 read = xbt_getline(&line, &n, fp);
755 xbt_dynar_free(&split);
756 xbt_str_rtrim(line, NULL);
757 xbt_str_strip_spaces(line);
758 split = xbt_str_split(line, " ");
760 node_type = xbt_dynar_get_as(split, 1, char *);
762 if(strncmp(node_type, "DW_AT_", 6) != 0)
765 if(strcmp(node_type, "DW_AT_name") == 0){
767 var = xbt_new0(s_dw_variable_t, 1);
768 var->dwarf_offset = 0;
769 var->name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
770 xbt_dict_set(variables_origin, origin, xbt_strdup(var->name), NULL);
772 }else if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
776 abstract_origin = xbt_dynar_get_as(split, 2, char *);
777 xbt_str_ltrim(abstract_origin, "<0x");
778 xbt_str_rtrim(abstract_origin, ">");
780 variable_name = (char *)xbt_dict_get_or_null(variables_origin, abstract_origin);
781 variable_frame = MC_dwarf_get_frame_by_offset(*local_variables, strtoul(abstract_origin, NULL, 16));
782 var = MC_dwarf_get_variable_by_name(variable_frame, variable_name);
784 }else if(strcmp(node_type, "DW_AT_location") == 0){
788 if(!global_variable){
790 location_type = xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *);
792 if(strcmp(location_type, "list)") == 0){ /* Search location in location list */
793 var->address.location = MC_dwarf_get_location(info->location_list, xbt_dynar_get_as(split, 3, char *));
795 xbt_str_strip_spaces(line);
796 split2 = xbt_str_split(line, "(");
797 xbt_dynar_remove_at(split2, 0, NULL);
798 loc_expr = xbt_str_join(split2, " ");
799 xbt_str_rtrim(loc_expr, ")");
800 if(strncmp("DW_OP_addr", loc_expr, 10) == 0){
802 xbt_dynar_free(&split2);
803 split2 = xbt_str_split(loc_expr, " ");
804 if(strcmp(elf_file, xbt_binary_name) != 0)
805 var->address.address = (char *) info->start_text + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
807 // Why is it different ?
808 var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
810 var->address.location = MC_dwarf_get_location(NULL, loc_expr);
812 xbt_dynar_free(&split2);
816 global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
817 xbt_str_rtrim(global_address, ")");
818 if(strcmp(elf_file, xbt_binary_name) != 0)
819 var->address.address = (char *) info->start_text + (long)((void *)strtoul(global_address, NULL, 16));
821 // Why is it different ?
822 var->address.address = (void *)strtoul(global_address, NULL, 16);
823 xbt_free(global_address);
824 global_address = NULL;
829 }else if(strcmp(node_type, "DW_AT_type") == 0){
831 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
832 xbt_str_ltrim(type_origin, "<0x");
833 xbt_str_rtrim(type_origin, ">");
835 }else if(strcmp(node_type, "DW_AT_declaration") == 0){
839 dw_variable_free(var);
843 }else if(strcmp(node_type, "DW_AT_artificial") == 0){
847 dw_variable_free(var);
853 read = xbt_getline(&line, &n, fp);
857 if(new_variable == 1){
859 var->global = global_variable;
860 var->type_origin = strdup(type_origin);
861 if(!global_variable){
862 variable_frame = xbt_dict_get_or_null(*local_variables, current_frame);
863 MC_dwarf_register_non_global_variable(info, variable_frame, var);
865 MC_dwarf_register_global_variable(info, var);
868 xbt_free(type_origin);
875 }else if(strcmp(node_type, "(DW_TAG_inlined_subroutine)") == 0){
876 /* Update the information on the frame (we should duplicate it instead). */
878 read = xbt_getline(&line, &n, fp);
882 /* Wipeout the new line character */
883 line[read - 1] = '\0';
885 if(n == 0 || strlen(line) == 0){
886 read = xbt_getline(&line, &n, fp);
890 xbt_dynar_free(&split);
891 xbt_str_rtrim(line, NULL);
892 xbt_str_strip_spaces(line);
893 split = xbt_str_split(line, " ");
895 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
898 node_type = xbt_dynar_get_as(split, 1, char *);
900 if(strcmp(node_type, "DW_AT_abstract_origin:") == 0){
902 origin = xbt_dynar_get_as(split, 2, char *);
903 xbt_str_ltrim(origin, "<0x");
904 xbt_str_rtrim(origin, ">");
906 subprogram_name = (char *)xbt_dict_get_or_null(subprograms_origin, origin);
907 subroutine_frame = xbt_dict_get_or_null(*local_variables, subprogram_name);
909 }else if(strcmp(node_type, "DW_AT_low_pc") == 0){
911 subroutine_frame->low_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
913 }else if(strcmp(node_type, "DW_AT_high_pc") == 0){
915 subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
918 read = xbt_getline(&line, &n, fp);
922 }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0
923 || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
924 || strcmp(node_type, "(DW_TAG_typedef)") == 0
925 || strcmp(node_type, "(DW_TAG_const_type)") == 0
926 || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
927 || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
928 || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
930 /* Create the and add it to the types dictionnary */
932 if(strcmp(node_type, "(DW_TAG_base_type)") == 0)
933 type_type = DW_TAG_base_type;
934 else if(strcmp(node_type, "(DW_TAG_enumeration_type)") == 0)
935 type_type = DW_TAG_enumeration_type;
936 else if(strcmp(node_type, "(DW_TAG_typedef)") == 0)
937 type_type = DW_TAG_typedef;
938 else if(strcmp(node_type, "(DW_TAG_const_type)") == 0)
939 type_type = DW_TAG_const_type;
940 else if(strcmp(node_type, "(DW_TAG_pointer_type)") == 0)
941 type_type = DW_TAG_pointer_type;
942 else if(strcmp(node_type, "(DW_TAG_subroutine_type)") == 0)
943 type_type = DW_TAG_subroutine_type;
944 else if(strcmp(node_type, "(DW_TAG_volatile_type)") == 0)
945 type_type = DW_TAG_volatile_type;
947 strtok(xbt_dynar_get_as(split, 0, char *), "<");
948 origin = strdup(strtok(NULL, "<"));
949 xbt_str_rtrim(origin, ">:");
951 read = xbt_getline(&line, &n, fp);
955 /* Wipeout the new line character */
956 line[read - 1] = '\0';
958 if(n == 0 || strlen(line) == 0){
959 read = xbt_getline(&line, &n, fp);
963 xbt_dynar_free(&split);
964 xbt_str_rtrim(line, NULL);
965 xbt_str_strip_spaces(line);
966 split = xbt_str_split(line, " ");
968 if(strncmp(xbt_dynar_get_as(split, 1, char *), "DW_AT_", 6) != 0)
971 node_type = xbt_dynar_get_as(split, 1, char *);
973 if(strcmp(node_type, "DW_AT_byte_size") == 0){
974 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
975 if(type_type == DW_TAG_enumeration_type)
976 enumeration_size = size;
977 }else if(strcmp(node_type, "DW_AT_name") == 0){
978 end = xbt_str_join(split, " ");
979 xbt_dynar_free(&split);
980 split = xbt_str_split(end, "):");
981 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
982 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
983 }else if(strcmp(node_type, "DW_AT_type") == 0){
984 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
985 xbt_str_ltrim(type_origin, "<0x");
986 xbt_str_rtrim(type_origin, ">");
989 read = xbt_getline(&line, &n, fp);
992 dw_type_t type = xbt_new0(s_dw_type_t, 1);
993 type->type = type_type;
995 type->name = xbt_strdup(name);
997 type->name = xbt_strdup("undefined");
998 type->is_pointer_type = is_pointer;
999 type->id = (void *)strtoul(origin, NULL, 16);
1001 type->dw_type_id = xbt_strdup(type_origin);
1003 type->byte_size = size;
1005 type->element_count = -1;
1007 type->members = NULL;
1009 xbt_dict_set(*types, origin, type, NULL);
1013 xbt_free(type_origin);
1022 }else if(strcmp(node_type, "(DW_TAG_structure_type)") == 0 || strcmp(node_type, "(DW_TAG_union_type)") == 0){
1024 if(strcmp(node_type, "(DW_TAG_structure_type)") == 0)
1029 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1030 origin = strdup(strtok(NULL, "<"));
1031 xbt_str_rtrim(origin, ">:");
1033 read = xbt_getline(&line, &n, fp);
1035 dw_type_t type = NULL;
1041 /* Wipeout the new line character */
1042 line[read - 1] = '\0';
1044 if(n == 0 || strlen(line) == 0){
1045 read = xbt_getline(&line, &n, fp);
1049 xbt_dynar_free(&split);
1050 xbt_str_rtrim(line, NULL);
1051 xbt_str_strip_spaces(line);
1052 split = xbt_str_split(line, " ");
1054 node_type = xbt_dynar_get_as(split, 1, char *);
1056 if(strncmp(node_type, "DW_AT_", 6) != 0){
1061 if(strcmp(node_type, "DW_AT_byte_size") == 0){
1062 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1063 }else if(strcmp(node_type, "DW_AT_name") == 0){
1065 end = xbt_str_join(split, " ");
1066 xbt_dynar_free(&split);
1067 split = xbt_str_split(end, "):");
1068 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1069 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1070 }else if(strcmp(node_type, "DW_AT_type") == 0){
1071 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1072 xbt_str_ltrim(type_origin, "<0x");
1073 xbt_str_rtrim(type_origin, ">");
1074 }else if(strcmp(node_type, "DW_AT_data_member_location:") == 0){
1076 end = xbt_str_join(split, " ");
1077 xbt_dynar_free(&split);
1078 split = xbt_str_split(end, "DW_OP_plus_uconst:");
1079 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), NULL);
1080 xbt_str_rtrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), ")");
1081 offset = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1084 read = xbt_getline(&line, &n, fp);
1088 if(member_end && type){
1091 // Why are we not simply referencing, the DW_AT_type?
1092 dw_type_t member_type = xbt_new0(s_dw_type_t, 1);
1093 member_type->name = xbt_strdup(name);
1094 member_type->byte_size = size;
1095 member_type->element_count = -1;
1096 member_type->is_pointer_type = is_pointer;
1097 member_type->id = (void *)strtoul(origin, NULL, 16);
1098 member_type->offset = offset;
1100 member_type->dw_type_id = xbt_strdup(type_origin);
1102 xbt_dynar_push(type->members, &member_type);
1108 xbt_free(type_origin);
1115 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1116 origin = strdup(strtok(NULL, "<"));
1117 xbt_str_rtrim(origin, ">:");
1121 if(struct_decl || union_decl){
1122 type = xbt_new0(s_dw_type_t, 1);
1124 type->type = DW_TAG_structure_type;
1126 type->type = DW_TAG_union_type;
1127 type->name = xbt_strdup(name);
1128 type->byte_size = size;
1129 type->element_count = -1;
1130 type->is_pointer_type = is_pointer;
1131 type->id = (void *)strtoul(origin, NULL, 16);
1133 type->dw_type_id = xbt_strdup(type_origin);
1134 type->members = xbt_dynar_new(sizeof(dw_type_t), dw_type_free_voidp);
1136 xbt_dict_set(*types, origin, type, NULL);
1142 xbt_free(type_origin);
1150 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_member)") != 0)
1153 read = xbt_getline(&line, &n, fp);
1160 }else if(strcmp(node_type, "(DW_TAG_array_type)") == 0){
1162 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1163 origin = strdup(strtok(NULL, "<"));
1164 xbt_str_rtrim(origin, ">:");
1166 read = xbt_getline(&line, &n, fp);
1168 dw_type_t type = NULL;
1170 // Read DW_TAG_subrange_type children:
1173 // Read attributes of the DW_TAG_subrange_type:
1176 /* Wipeout the new line character */
1177 line[read - 1] = '\0';
1179 if(n == 0 || strlen(line) == 0){
1180 read = xbt_getline(&line, &n, fp);
1184 xbt_dynar_free(&split);
1185 xbt_str_rtrim(line, NULL);
1186 xbt_str_strip_spaces(line);
1187 split = xbt_str_split(line, " ");
1189 node_type = xbt_dynar_get_as(split, 1, char *);
1191 if(strncmp(node_type, "DW_AT_", 6) != 0)
1194 if(strcmp(node_type, "DW_AT_upper_bound") == 0){
1195 size = strtol(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL, 10);
1196 }else if(strcmp(node_type, "DW_AT_name") == 0){
1197 end = xbt_str_join(split, " ");
1198 xbt_dynar_free(&split);
1199 split = xbt_str_split(end, "):");
1200 xbt_str_ltrim(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*), NULL);
1201 name = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char*));
1202 }else if(strcmp(node_type, "DW_AT_type") == 0){
1203 type_origin = xbt_strdup(xbt_dynar_get_as(split, 3, char *));
1204 xbt_str_ltrim(type_origin, "<0x");
1205 xbt_str_rtrim(type_origin, ">");
1208 read = xbt_getline(&line, &n, fp);
1212 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") == 0){
1216 if(subrange && type){
1217 type->element_count = size;
1223 xbt_free(type_origin);
1229 strtok(xbt_dynar_get_as(split, 0, char *), "<");
1230 origin = strdup(strtok(NULL, "<"));
1231 xbt_str_rtrim(origin, ">:");
1235 type = xbt_new0(s_dw_type_t, 1);
1236 type->type = DW_TAG_array_type;
1237 type->name = xbt_strdup(name);
1238 type->is_pointer_type = is_pointer;
1239 type->id = (void *)strtoul(origin, NULL, 16);
1241 type->dw_type_id = xbt_strdup(type_origin);
1242 type->members = NULL;
1244 // Filled in a post processing step:
1245 type-> byte_size = 0;
1247 xbt_dict_set(*types, origin, type, NULL);
1253 xbt_free(type_origin);
1258 if(strcmp(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *), "(DW_TAG_subrange_type)") != 0)
1261 read = xbt_getline(&line, &n, fp);
1270 read = xbt_getline(&line, &n, fp);
1276 xbt_dynar_free(&split);
1277 xbt_dict_free(&variables_origin);
1278 xbt_dict_free(&subprograms_origin);
1285 void MC_dwarf_register_global_variable(mc_object_info_t info, dw_variable_t variable) {
1286 int index = MC_dwarf_get_variable_index(info->global_variables, variable->name, variable->address.address);
1288 xbt_dynar_insert_at(info->global_variables, index, &variable);
1292 void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable) {
1293 xbt_assert(frame, "Frame is NULL");
1294 int index = MC_dwarf_get_variable_index(frame->variables, variable->name, NULL);
1296 xbt_dynar_insert_at(frame->variables, index, &variable);
1300 void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable) {
1301 if(variable->global)
1302 MC_dwarf_register_global_variable(info, variable);
1303 else if(frame==NULL)
1304 xbt_die("No frame for this local variable");
1306 MC_dwarf_register_non_global_variable(info, frame, variable);
1309 static void MC_post_process_array_size(mc_object_info_t info, dw_type_t type) {
1310 xbt_assert(type->dw_type_id, "No base type for array <%p>%s", type->id, type->name);
1311 dw_type_t subtype = xbt_dict_get_or_null(info->types, type->dw_type_id);
1312 xbt_assert(subtype, "Unkown base type <%s> for array <%p>%s", type->dw_type_id, type->id, type->name);
1313 if(subtype->type==DW_TAG_array_type && type->byte_size==0) {
1314 MC_post_process_array_size(info, subtype);
1316 type->byte_size = type->element_count*subtype->byte_size;
1319 static void MC_post_process_types(mc_object_info_t info) {
1320 xbt_dict_cursor_t cursor;
1323 xbt_dict_foreach(info->types, cursor, origin, type){
1324 if(type->type==DW_TAG_array_type && type->byte_size==0)
1325 MC_post_process_array_size(info, type);
1329 /******************************* Ignore mechanism *******************************/
1330 /*********************************************************************************/
1332 xbt_dynar_t mc_checkpoint_ignore;
1334 typedef struct s_mc_stack_ignore_variable{
1337 }s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
1339 typedef struct s_mc_data_bss_ignore_variable{
1341 }s_mc_data_bss_ignore_variable_t, *mc_data_bss_ignore_variable_t;
1343 /**************************** Free functions ******************************/
1345 static void stack_ignore_variable_free(mc_stack_ignore_variable_t v){
1346 xbt_free(v->var_name);
1351 static void stack_ignore_variable_free_voidp(void *v){
1352 stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
1355 void heap_ignore_region_free(mc_heap_ignore_region_t r){
1359 void heap_ignore_region_free_voidp(void *r){
1360 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
1363 static void data_bss_ignore_variable_free(mc_data_bss_ignore_variable_t v){
1368 static void data_bss_ignore_variable_free_voidp(void *v){
1369 data_bss_ignore_variable_free((mc_data_bss_ignore_variable_t) * (void **) v);
1372 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r){
1376 static void checkpoint_ignore_region_free_voidp(void *r){
1377 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
1380 /***********************************************************************/
1382 void MC_ignore_heap(void *address, size_t size){
1384 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1388 mc_heap_ignore_region_t region = NULL;
1389 region = xbt_new0(s_mc_heap_ignore_region_t, 1);
1390 region->address = address;
1391 region->size = size;
1393 region->block = ((char*)address - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1395 if(((xbt_mheap_t)std_heap)->heapinfo[region->block].type == 0){
1396 region->fragment = -1;
1397 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_block.ignore++;
1399 region->fragment = ((uintptr_t) (ADDR2UINT (address) % (BLOCKSIZE))) >> ((xbt_mheap_t)std_heap)->heapinfo[region->block].type;
1400 ((xbt_mheap_t)std_heap)->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
1403 if(mc_heap_comparison_ignore == NULL){
1404 mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
1405 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
1411 unsigned int cursor = 0;
1412 mc_heap_ignore_region_t current_region = NULL;
1414 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1416 while(start <= end){
1417 cursor = (start + end) / 2;
1418 current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1419 if(current_region->address == address){
1420 heap_ignore_region_free(region);
1424 }else if(current_region->address < address){
1431 if(current_region->address < address)
1432 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
1434 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
1440 void MC_remove_ignore_heap(void *address, size_t size){
1442 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1446 unsigned int cursor = 0;
1448 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
1449 mc_heap_ignore_region_t region;
1450 int ignore_found = 0;
1452 while(start <= end){
1453 cursor = (start + end) / 2;
1454 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
1455 if(region->address == address){
1458 }else if(region->address < address){
1461 if((char * )region->address <= ((char *)address + size)){
1470 if(ignore_found == 1){
1471 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
1472 MC_remove_ignore_heap(address, size);
1480 void MC_ignore_global_variable(const char *name){
1482 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1486 if(mc_libsimgrid_info){
1488 unsigned int cursor = 0;
1489 dw_variable_t current_var;
1491 int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1493 while(start <= end){
1494 cursor = (start + end) /2;
1495 current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
1496 if(strcmp(current_var->name, name) == 0){
1497 xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
1499 end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
1500 }else if(strcmp(current_var->name, name) < 0){
1509 if(mc_data_bss_comparison_ignore == NULL)
1510 mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
1512 mc_data_bss_ignore_variable_t var = NULL;
1513 var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
1514 var->name = strdup(name);
1516 if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
1518 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
1522 unsigned int cursor = 0;
1524 int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
1525 mc_data_bss_ignore_variable_t current_var = NULL;
1527 while(start <= end){
1528 cursor = (start + end) / 2;
1529 current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
1530 if(strcmp(current_var->name, name) == 0){
1531 data_bss_ignore_variable_free(var);
1535 }else if(strcmp(current_var->name, name) < 0){
1542 if(strcmp(current_var->name, name) < 0)
1543 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
1545 xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
1554 void MC_ignore_local_variable(const char *var_name, const char *frame_name){
1556 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1560 if(mc_libsimgrid_info){
1561 unsigned int cursor = 0;
1562 dw_variable_t current_var;
1564 if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
1565 xbt_dict_cursor_t dict_cursor;
1566 char *current_frame_name;
1568 xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
1570 end = xbt_dynar_length(frame->variables) - 1;
1571 while(start <= end){
1572 cursor = (start + end) / 2;
1573 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1574 if(strcmp(current_var->name, var_name) == 0){
1575 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1577 end = xbt_dynar_length(frame->variables) - 1;
1578 }else if(strcmp(current_var->name, var_name) < 0){
1585 xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
1587 end = xbt_dynar_length(frame->variables) - 1;
1588 while(start <= end){
1589 cursor = (start + end) / 2;
1590 current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
1591 if(strcmp(current_var->name, var_name) == 0){
1592 xbt_dynar_remove_at(frame->variables, cursor, NULL);
1594 end = xbt_dynar_length(frame->variables) - 1;
1595 }else if(strcmp(current_var->name, var_name) < 0){
1603 xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
1604 mc_libsimgrid_info->local_variables, frame_name))->variables;
1606 end = xbt_dynar_length(variables_list) - 1;
1607 while(start <= end){
1608 cursor = (start + end) / 2;
1609 current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
1610 if(strcmp(current_var->name, var_name) == 0){
1611 xbt_dynar_remove_at(variables_list, cursor, NULL);
1613 end = xbt_dynar_length(variables_list) - 1;
1614 }else if(strcmp(current_var->name, var_name) < 0){
1623 if(mc_stack_comparison_ignore == NULL)
1624 mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
1626 mc_stack_ignore_variable_t var = NULL;
1627 var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
1628 var->var_name = strdup(var_name);
1629 var->frame = strdup(frame_name);
1631 if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
1633 xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
1637 unsigned int cursor = 0;
1639 int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
1640 mc_stack_ignore_variable_t current_var = NULL;
1642 while(start <= end){
1643 cursor = (start + end) / 2;
1644 current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
1645 if(strcmp(current_var->frame, frame_name) == 0){
1646 if(strcmp(current_var->var_name, var_name) == 0){
1647 stack_ignore_variable_free(var);
1651 }else if(strcmp(current_var->var_name, var_name) < 0){
1656 }else if(strcmp(current_var->frame, frame_name) < 0){
1663 if(strcmp(current_var->frame, frame_name) == 0){
1664 if(strcmp(current_var->var_name, var_name) < 0){
1665 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1667 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1669 }else if(strcmp(current_var->frame, frame_name) < 0){
1670 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
1672 xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
1682 void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
1684 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1688 if(stacks_areas == NULL)
1689 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
1691 stack_region_t region = NULL;
1692 region = xbt_new0(s_stack_region_t, 1);
1693 region->address = stack;
1694 region->process_name = strdup(name);
1695 region->context = context;
1696 region->size = size;
1697 region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
1698 xbt_dynar_push(stacks_areas, ®ion);
1704 void MC_ignore(void *addr, size_t size){
1706 int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
1710 if(mc_checkpoint_ignore == NULL)
1711 mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
1713 mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
1714 region->addr = addr;
1715 region->size = size;
1717 if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
1718 xbt_dynar_push(mc_checkpoint_ignore, ®ion);
1721 unsigned int cursor = 0;
1723 int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
1724 mc_checkpoint_ignore_region_t current_region = NULL;
1726 while(start <= end){
1727 cursor = (start + end) / 2;
1728 current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
1729 if(current_region->addr == addr){
1730 if(current_region->size == size){
1731 checkpoint_ignore_region_free(region);
1735 }else if(current_region->size < size){
1740 }else if(current_region->addr < addr){
1747 if(current_region->addr == addr){
1748 if(current_region->size < size){
1749 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1751 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1753 }else if(current_region->addr < addr){
1754 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
1756 xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
1764 /******************************* Initialisation of MC *******************************/
1765 /*********************************************************************************/
1767 static void MC_dump_ignored_local_variables(void){
1769 if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
1772 unsigned int cursor = 0;
1773 mc_stack_ignore_variable_t current_var;
1775 xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
1776 MC_ignore_local_variable(current_var->var_name, current_var->frame);
1779 xbt_dynar_free(&mc_stack_comparison_ignore);
1780 mc_stack_comparison_ignore = NULL;
1784 static void MC_dump_ignored_global_variables(void){
1786 if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
1789 unsigned int cursor = 0;
1790 mc_data_bss_ignore_variable_t current_var;
1792 xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
1793 MC_ignore_global_variable(current_var->name);
1796 xbt_dynar_free(&mc_data_bss_comparison_ignore);
1797 mc_data_bss_comparison_ignore = NULL;
1801 static void MC_init_debug_info();
1802 static void MC_init_debug_info() {
1803 XBT_INFO("Get debug information ...");
1805 memory_map_t maps = MC_get_memory_map();
1807 /* Get local variables for state equality detection */
1808 mc_binary_info = MC_find_object_info(maps, xbt_binary_name);
1809 mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path);
1811 MC_free_memory_map(maps);
1812 XBT_INFO("Get debug information done !");
1817 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1821 /* Initialize the data structures that must be persistent across every
1822 iteration of the model-checker (in RAW memory) */
1826 MC_init_memory_map_info();
1827 MC_init_debug_info();
1829 /* Remove variables ignored before getting list of variables */
1830 MC_dump_ignored_local_variables();
1831 MC_dump_ignored_global_variables();
1834 parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
1838 /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
1839 MC_ignore_local_variable("e", "*");
1840 MC_ignore_local_variable("__ex_cleanup", "*");
1841 MC_ignore_local_variable("__ex_mctx_en", "*");
1842 MC_ignore_local_variable("__ex_mctx_me", "*");
1843 MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
1844 MC_ignore_local_variable("_log_ev", "*");
1845 MC_ignore_local_variable("_throw_ctx", "*");
1846 MC_ignore_local_variable("ctx", "*");
1848 MC_ignore_local_variable("next_context", "smx_ctx_sysv_suspend_serial");
1849 MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
1851 /* Ignore local variable about time used for tracing */
1852 MC_ignore_local_variable("start_time", "*");
1854 MC_ignore_global_variable("mc_comp_times");
1855 MC_ignore_global_variable("mc_snapshot_comparison_time");
1856 MC_ignore_global_variable("mc_time");
1857 MC_ignore_global_variable("smpi_current_rank");
1858 MC_ignore_global_variable("counter"); /* Static variable used for tracing */
1859 MC_ignore_global_variable("maestro_stack_start");
1860 MC_ignore_global_variable("maestro_stack_end");
1862 MC_ignore_heap(&(simix_global->process_to_run), sizeof(simix_global->process_to_run));
1863 MC_ignore_heap(&(simix_global->process_that_ran), sizeof(simix_global->process_that_ran));
1864 MC_ignore_heap(simix_global->process_to_run, sizeof(*(simix_global->process_to_run)));
1865 MC_ignore_heap(simix_global->process_that_ran, sizeof(*(simix_global->process_that_ran)));
1867 smx_process_t process;
1868 xbt_swag_foreach(process, simix_global->process_list){
1869 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
1877 static void MC_init_dot_output(){ /* FIXME : more colors */
1881 colors[2] = "green3";
1882 colors[3] = "goldenrod";
1883 colors[4] = "brown";
1884 colors[5] = "purple";
1885 colors[6] = "magenta";
1886 colors[7] = "turquoise4";
1887 colors[8] = "gray25";
1888 colors[9] = "forestgreen";
1889 colors[10] = "hotpink";
1890 colors[11] = "lightblue";
1893 dot_output = fopen(_sg_mc_dot_output_file, "w");
1895 if(dot_output == NULL){
1896 perror("Error open dot output file");
1900 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");
1904 /******************************* Core of MC *******************************/
1905 /**************************************************************************/
1907 void MC_do_the_modelcheck_for_real() {
1910 mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
1913 if (!_sg_mc_property_file || _sg_mc_property_file[0]=='\0') {
1914 if (mc_reduce_kind==e_mc_reduce_unset)
1915 mc_reduce_kind=e_mc_reduce_dpor;
1917 XBT_INFO("Check a safety property");
1918 MC_modelcheck_safety();
1922 if (mc_reduce_kind==e_mc_reduce_unset)
1923 mc_reduce_kind=e_mc_reduce_none;
1925 XBT_INFO("Check the liveness property %s",_sg_mc_property_file);
1926 MC_automaton_load(_sg_mc_property_file);
1927 MC_modelcheck_liveness();
1931 void MC_modelcheck_safety(void)
1933 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1935 /* Check if MC is already initialized */
1936 if (initial_state_safety)
1939 mc_time = xbt_new0(double, simix_process_maxpid);
1941 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1942 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
1944 /* Initialize the data structures that must be persistent across every
1945 iteration of the model-checker (in RAW memory) */
1949 /* Initialize statistics */
1950 mc_stats = xbt_new0(s_mc_stats_t, 1);
1951 mc_stats->state_size = 1;
1953 /* Create exploration stack */
1954 mc_stack_safety = xbt_fifo_new();
1956 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
1957 MC_init_dot_output();
1961 if(_sg_mc_visited > 0){
1965 MC_init_memory_map_info();
1966 MC_init_debug_info();
1973 /* Save the initial state */
1974 initial_state_safety = xbt_new0(s_mc_global_t, 1);
1975 initial_state_safety->snapshot = MC_take_snapshot(0);
1987 void MC_modelcheck_liveness(){
1989 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
1993 mc_time = xbt_new0(double, simix_process_maxpid);
1995 /* mc_time refers to clock for each process -> ignore it for heap comparison */
1996 MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
2000 /* Initialize statistics */
2001 mc_stats = xbt_new0(s_mc_stats_t, 1);
2002 mc_stats->state_size = 1;
2004 /* Create exploration stack */
2005 mc_stack_liveness = xbt_fifo_new();
2007 /* Create the initial state */
2008 initial_state_liveness = xbt_new0(s_mc_global_t, 1);
2010 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0'))
2011 MC_init_dot_output();
2018 MC_print_statistics(mc_stats);
2034 int SIMIX_pre_mc_random(smx_simcall_t simcall, int min, int max){
2036 return simcall->mc_value;
2040 int MC_random(int min, int max)
2042 /*FIXME: return mc_current_state->executed_transition->random.value;*/
2043 return simcall_mc_random(min, max);
2047 * \brief Schedules all the process that are ready to run
2049 void MC_wait_for_requests(void)
2051 smx_process_t process;
2055 while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
2056 SIMIX_process_runall();
2057 xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
2058 req = &process->simcall;
2059 if (req->call != SIMCALL_NONE && !MC_request_is_visible(req))
2060 SIMIX_simcall_pre(req, 0);
2065 int MC_deadlock_check()
2067 int deadlock = FALSE;
2068 smx_process_t process;
2069 if(xbt_swag_size(simix_global->process_list)){
2071 xbt_swag_foreach(process, simix_global->process_list){
2072 if(process->simcall.call != SIMCALL_NONE
2073 && MC_request_is_enabled(&process->simcall)){
2083 * \brief Re-executes from the state at position start all the transitions indicated by
2084 * a given model-checker stack.
2085 * \param stack The stack with the transitions to execute.
2086 * \param start Start index to begin the re-execution.
2088 void MC_replay(xbt_fifo_t stack, int start)
2090 int raw_mem = (mmalloc_get_current_heap() == raw_heap);
2092 int value, i = 1, count = 1;
2094 smx_simcall_t req = NULL, saved_req = NULL;
2095 xbt_fifo_item_t item, start_item;
2097 smx_process_t process = NULL;
2099 XBT_DEBUG("**** Begin Replay ****");
2102 /* Restore the initial state */
2103 MC_restore_snapshot(initial_state_safety->snapshot);
2104 /* At the moment of taking the snapshot the raw heap was set, so restoring
2105 * it will set it back again, we have to unset it to continue */
2109 start_item = xbt_fifo_get_last_item(stack);
2112 start_item = xbt_fifo_get_prev_item(start_item);
2118 xbt_dict_reset(first_enabled_state);
2119 xbt_swag_foreach(process, simix_global->process_list){
2120 if(MC_process_is_enabled(process)){
2121 char *key = bprintf("%lu", process->pid);
2122 char *data = bprintf("%d", count);
2123 xbt_dict_set(first_enabled_state, key, data, NULL);
2130 /* Traverse the stack from the state at position start and re-execute the transitions */
2131 for (item = start_item;
2132 item != xbt_fifo_get_first_item(stack);
2133 item = xbt_fifo_get_prev_item(item)) {
2135 state = (mc_state_t) xbt_fifo_get_item_content(item);
2136 saved_req = MC_state_get_executed_request(state, &value);
2139 char *key = bprintf("%lu", saved_req->issuer->pid);
2140 xbt_dict_remove(first_enabled_state, key);
2145 /* because we got a copy of the executed request, we have to fetch the
2146 real one, pointed by the request field of the issuer process */
2147 req = &saved_req->issuer->simcall;
2149 /* Debug information */
2150 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2151 req_str = MC_request_to_string(req, value);
2152 XBT_DEBUG("Replay: %s (%p)", req_str, state);
2157 SIMIX_simcall_pre(req, value);
2158 MC_wait_for_requests();
2163 /* Insert in dict all enabled processes */
2164 xbt_swag_foreach(process, simix_global->process_list){
2165 if(MC_process_is_enabled(process) /*&& !MC_state_process_is_done(state, process)*/){
2166 char *key = bprintf("%lu", process->pid);
2167 if(xbt_dict_get_or_null(first_enabled_state, key) == NULL){
2168 char *data = bprintf("%d", count);
2169 xbt_dict_set(first_enabled_state, key, data, NULL);
2176 /* Update statistics */
2177 mc_stats->visited_states++;
2178 mc_stats->executed_transitions++;
2182 XBT_DEBUG("**** End Replay ****");
2192 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
2195 initial_state_liveness->raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2199 smx_simcall_t req = NULL, saved_req = NULL;
2200 xbt_fifo_item_t item;
2205 XBT_DEBUG("**** Begin Replay ****");
2207 /* Restore the initial state */
2208 MC_restore_snapshot(initial_state_liveness->snapshot);
2210 /* At the moment of taking the snapshot the raw heap was set, so restoring
2211 * it will set it back again, we have to unset it to continue */
2212 if(!initial_state_liveness->raw_mem_set)
2217 item = xbt_fifo_get_last_item(stack);
2219 while(depth <= xbt_fifo_size(stack)){
2221 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2222 state = (mc_state_t) pair->graph_state;
2224 if(pair->requests > 0){
2226 saved_req = MC_state_get_executed_request(state, &value);
2227 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2229 if(saved_req != NULL){
2230 /* because we got a copy of the executed request, we have to fetch the
2231 real one, pointed by the request field of the issuer process */
2232 req = &saved_req->issuer->simcall;
2233 //XBT_DEBUG("Req->call %u", req->call);
2235 /* Debug information */
2236 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2237 req_str = MC_request_to_string(req, value);
2238 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2244 SIMIX_simcall_pre(req, value);
2245 MC_wait_for_requests();
2250 /* Update statistics */
2251 mc_stats->visited_pairs++;
2252 mc_stats->executed_transitions++;
2254 item = xbt_fifo_get_prev_item(item);
2259 /* Traverse the stack from the initial state and re-execute the transitions */
2260 for (item = xbt_fifo_get_last_item(stack);
2261 item != xbt_fifo_get_first_item(stack);
2262 item = xbt_fifo_get_prev_item(item)) {
2264 pair = (mc_pair_t) xbt_fifo_get_item_content(item);
2265 state = (mc_state_t) pair->graph_state;
2267 if(pair->requests > 0){
2269 saved_req = MC_state_get_executed_request(state, &value);
2270 //XBT_DEBUG("SavedReq->call %u", saved_req->call);
2272 if(saved_req != NULL){
2273 /* because we got a copy of the executed request, we have to fetch the
2274 real one, pointed by the request field of the issuer process */
2275 req = &saved_req->issuer->simcall;
2276 //XBT_DEBUG("Req->call %u", req->call);
2278 /* Debug information */
2279 if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){
2280 req_str = MC_request_to_string(req, value);
2281 XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
2287 SIMIX_simcall_pre(req, value);
2288 MC_wait_for_requests();
2293 /* Update statistics */
2294 mc_stats->visited_pairs++;
2295 mc_stats->executed_transitions++;
2299 XBT_DEBUG("**** End Replay ****");
2301 if(initial_state_liveness->raw_mem_set)
2309 * \brief Dumps the contents of a model-checker's stack and shows the actual
2311 * \param stack The stack to dump
2313 void MC_dump_stack_safety(xbt_fifo_t stack)
2316 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2318 MC_show_stack_safety(stack);
2320 if(!_sg_mc_checkpoint){
2325 while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
2326 MC_state_delete(state);
2339 void MC_show_stack_safety(xbt_fifo_t stack)
2342 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2348 xbt_fifo_item_t item;
2350 char *req_str = NULL;
2352 for (item = xbt_fifo_get_last_item(stack);
2353 (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
2354 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2355 req = MC_state_get_executed_request(state, &value);
2357 req_str = MC_request_to_string(req, value);
2358 XBT_INFO("%s", req_str);
2367 void MC_show_deadlock(smx_simcall_t req)
2369 /*char *req_str = NULL;*/
2370 XBT_INFO("**************************");
2371 XBT_INFO("*** DEAD-LOCK DETECTED ***");
2372 XBT_INFO("**************************");
2373 XBT_INFO("Locked request:");
2374 /*req_str = MC_request_to_string(req);
2375 XBT_INFO("%s", req_str);
2376 xbt_free(req_str);*/
2377 XBT_INFO("Counter-example execution trace:");
2378 MC_dump_stack_safety(mc_stack_safety);
2379 MC_print_statistics(mc_stats);
2383 void MC_show_stack_liveness(xbt_fifo_t stack){
2386 xbt_fifo_item_t item;
2388 char *req_str = NULL;
2390 for (item = xbt_fifo_get_last_item(stack);
2391 (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
2392 : (NULL)); item = xbt_fifo_get_prev_item(item)) {
2393 req = MC_state_get_executed_request(pair->graph_state, &value);
2395 if(pair->requests>0){
2396 req_str = MC_request_to_string(req, value);
2397 XBT_INFO("%s", req_str);
2400 XBT_INFO("End of system requests but evolution in Büchi automaton");
2406 void MC_dump_stack_liveness(xbt_fifo_t stack){
2408 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2413 while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
2414 MC_pair_delete(pair);
2423 void MC_print_statistics(mc_stats_t stats)
2425 if(stats->expanded_pairs == 0){
2426 XBT_INFO("Expanded states = %lu", stats->expanded_states);
2427 XBT_INFO("Visited states = %lu", stats->visited_states);
2429 XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
2430 XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
2432 XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
2434 if((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0]!='\0')){
2435 fprintf(dot_output, "}\n");
2441 void MC_assert(int prop)
2443 if (MC_is_active() && !prop){
2444 XBT_INFO("**************************");
2445 XBT_INFO("*** PROPERTY NOT VALID ***");
2446 XBT_INFO("**************************");
2447 XBT_INFO("Counter-example execution trace:");
2448 MC_dump_stack_safety(mc_stack_safety);
2449 MC_print_statistics(mc_stats);
2455 user_max_depth_reached = 1;
2458 void MC_process_clock_add(smx_process_t process, double amount)
2460 mc_time[process->pid] += amount;
2463 double MC_process_clock_get(smx_process_t process)
2467 return mc_time[process->pid];
2475 void MC_automaton_load(const char *file){
2477 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2481 if (_mc_property_automaton == NULL)
2482 _mc_property_automaton = xbt_automaton_new();
2484 xbt_automaton_load(_mc_property_automaton,file);
2493 void MC_automaton_new_propositional_symbol(const char* id, void* fct) {
2495 int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
2499 if (_mc_property_automaton == NULL)
2500 _mc_property_automaton = xbt_automaton_new();
2502 xbt_automaton_propositional_symbol_new(_mc_property_automaton,id,fct);