+ unsigned int cursor = 0;
+ mc_heap_ignore_region_t current_region = NULL;
+ int start = 0;
+ int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
+ if(current_region->address == address){
+ heap_ignore_region_free(region);
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+ return;
+ }else if(current_region->address < address){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+
+ if(current_region->address < address)
+ xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
+ else
+ xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
+
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+}
+
+void MC_remove_ignore_heap(void *address, size_t size){
+
+ int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+
+ MC_SET_RAW_MEM;
+
+ unsigned int cursor = 0;
+ int start = 0;
+ int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
+ mc_heap_ignore_region_t region;
+ int ignore_found = 0;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
+ if(region->address == address){
+ ignore_found = 1;
+ break;
+ }else if(region->address < address){
+ start = cursor + 1;
+ }else{
+ if((char * )region->address <= ((char *)address + size)){
+ ignore_found = 1;
+ break;
+ }else{
+ end = cursor - 1;
+ }
+ }
+ }
+
+ if(ignore_found == 1){
+ xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
+ MC_remove_ignore_heap(address, size);
+ }
+
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+
+}
+
+void MC_ignore_global_variable(const char *name){
+
+ int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+
+ MC_SET_RAW_MEM;
+
+ if(mc_libsimgrid_info){
+
+ unsigned int cursor = 0;
+ dw_variable_t current_var;
+ int start = 0;
+ int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
+
+ while(start <= end){
+ cursor = (start + end) /2;
+ current_var = (dw_variable_t)xbt_dynar_get_as(mc_libsimgrid_info->global_variables, cursor, dw_variable_t);
+ if(strcmp(current_var->name, name) == 0){
+ xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
+ start = 0;
+ end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
+ }else if(strcmp(current_var->name, name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+
+ }else{
+
+ if(mc_data_bss_comparison_ignore == NULL)
+ mc_data_bss_comparison_ignore = xbt_dynar_new(sizeof(mc_data_bss_ignore_variable_t), data_bss_ignore_variable_free_voidp);
+
+ mc_data_bss_ignore_variable_t var = NULL;
+ var = xbt_new0(s_mc_data_bss_ignore_variable_t, 1);
+ var->name = strdup(name);
+
+ if(xbt_dynar_is_empty(mc_data_bss_comparison_ignore)){
+
+ xbt_dynar_insert_at(mc_data_bss_comparison_ignore, 0, &var);
+
+ }else{
+
+ unsigned int cursor = 0;
+ int start = 0;
+ int end = xbt_dynar_length(mc_data_bss_comparison_ignore) - 1;
+ mc_data_bss_ignore_variable_t current_var = NULL;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_var = (mc_data_bss_ignore_variable_t)xbt_dynar_get_as(mc_data_bss_comparison_ignore, cursor, mc_data_bss_ignore_variable_t);
+ if(strcmp(current_var->name, name) == 0){
+ data_bss_ignore_variable_free(var);
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+ return;
+ }else if(strcmp(current_var->name, name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+
+ if(strcmp(current_var->name, name) < 0)
+ xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor + 1, &var);
+ else
+ xbt_dynar_insert_at(mc_data_bss_comparison_ignore, cursor, &var);
+
+ }
+ }
+
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+}
+
+void MC_ignore_local_variable(const char *var_name, const char *frame_name){
+
+ int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+
+ MC_SET_RAW_MEM;
+
+ if(mc_libsimgrid_info){
+ unsigned int cursor = 0;
+ dw_variable_t current_var;
+ int start, end;
+ if(strcmp(frame_name, "*") == 0){ /* Remove variable in all frames */
+ xbt_dict_cursor_t dict_cursor;
+ char *current_frame_name;
+ dw_frame_t frame;
+ xbt_dict_foreach(mc_libsimgrid_info->local_variables, dict_cursor, current_frame_name, frame){
+ start = 0;
+ end = xbt_dynar_length(frame->variables) - 1;
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
+ if(strcmp(current_var->name, var_name) == 0){
+ xbt_dynar_remove_at(frame->variables, cursor, NULL);
+ start = 0;
+ end = xbt_dynar_length(frame->variables) - 1;
+ }else if(strcmp(current_var->name, var_name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+ }
+ xbt_dict_foreach(mc_binary_info->local_variables, dict_cursor, current_frame_name, frame){
+ start = 0;
+ end = xbt_dynar_length(frame->variables) - 1;
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_var = (dw_variable_t)xbt_dynar_get_as(frame->variables, cursor, dw_variable_t);
+ if(strcmp(current_var->name, var_name) == 0){
+ xbt_dynar_remove_at(frame->variables, cursor, NULL);
+ start = 0;
+ end = xbt_dynar_length(frame->variables) - 1;
+ }else if(strcmp(current_var->name, var_name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+ }
+ }else{
+ xbt_dynar_t variables_list = ((dw_frame_t)xbt_dict_get_or_null(
+ mc_libsimgrid_info->local_variables, frame_name))->variables;
+ start = 0;
+ end = xbt_dynar_length(variables_list) - 1;
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_var = (dw_variable_t)xbt_dynar_get_as(variables_list, cursor, dw_variable_t);
+ if(strcmp(current_var->name, var_name) == 0){
+ xbt_dynar_remove_at(variables_list, cursor, NULL);
+ start = 0;
+ end = xbt_dynar_length(variables_list) - 1;
+ }else if(strcmp(current_var->name, var_name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+ }
+ }else{
+
+ if(mc_stack_comparison_ignore == NULL)
+ mc_stack_comparison_ignore = xbt_dynar_new(sizeof(mc_stack_ignore_variable_t), stack_ignore_variable_free_voidp);
+
+ mc_stack_ignore_variable_t var = NULL;
+ var = xbt_new0(s_mc_stack_ignore_variable_t, 1);
+ var->var_name = strdup(var_name);
+ var->frame = strdup(frame_name);
+
+ if(xbt_dynar_is_empty(mc_stack_comparison_ignore)){
+
+ xbt_dynar_insert_at(mc_stack_comparison_ignore, 0, &var);
+
+ }else{
+
+ unsigned int cursor = 0;
+ int start = 0;
+ int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
+ mc_stack_ignore_variable_t current_var = NULL;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
+ if(strcmp(current_var->frame, frame_name) == 0){
+ if(strcmp(current_var->var_name, var_name) == 0){
+ stack_ignore_variable_free(var);
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+ return;
+ }else if(strcmp(current_var->var_name, var_name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }else if(strcmp(current_var->frame, frame_name) < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+
+ if(strcmp(current_var->frame, frame_name) == 0){
+ if(strcmp(current_var->var_name, var_name) < 0){
+ xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
+ }else{
+ xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
+ }
+ }else if(strcmp(current_var->frame, frame_name) < 0){
+ xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor + 1, &var);
+ }else{
+ xbt_dynar_insert_at(mc_stack_comparison_ignore, cursor, &var);
+ }
+ }
+ }
+
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+
+}
+
+void MC_new_stack_area(void *stack, char *name, void* context, size_t size){
+
+ int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+
+ MC_SET_RAW_MEM;
+
+ if(stacks_areas == NULL)
+ stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
+
+ stack_region_t region = NULL;
+ region = xbt_new0(s_stack_region_t, 1);
+ region->address = stack;
+ region->process_name = strdup(name);
+ region->context = context;
+ region->size = size;
+ region->block = ((char*)stack - (char*)((xbt_mheap_t)std_heap)->heapbase) / BLOCKSIZE + 1;
+ xbt_dynar_push(stacks_areas, ®ion);
+
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+}
+
+void MC_ignore(void *addr, size_t size){
+
+ int raw_mem_set= (mmalloc_get_current_heap() == raw_heap);
+
+ MC_SET_RAW_MEM;
+
+ if(mc_checkpoint_ignore == NULL)
+ mc_checkpoint_ignore = xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t), checkpoint_ignore_region_free_voidp);
+
+ mc_checkpoint_ignore_region_t region = xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
+ region->addr = addr;
+ region->size = size;
+
+ if(xbt_dynar_is_empty(mc_checkpoint_ignore)){
+ xbt_dynar_push(mc_checkpoint_ignore, ®ion);
+ }else{
+
+ unsigned int cursor = 0;
+ int start = 0;
+ int end = xbt_dynar_length(mc_checkpoint_ignore) -1;
+ mc_checkpoint_ignore_region_t current_region = NULL;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ current_region = (mc_checkpoint_ignore_region_t)xbt_dynar_get_as(mc_checkpoint_ignore, cursor, mc_checkpoint_ignore_region_t);
+ if(current_region->addr == addr){
+ if(current_region->size == size){
+ checkpoint_ignore_region_free(region);
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+ return;
+ }else if(current_region->size < size){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }else if(current_region->addr < addr){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }
+ }
+
+ if(current_region->addr == addr){
+ if(current_region->size < size){
+ xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
+ }else{
+ xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
+ }
+ }else if(current_region->addr < addr){
+ xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
+ }else{
+ xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
+ }
+ }
+
+ if(!raw_mem_set)
+ MC_UNSET_RAW_MEM;
+}
+
+/******************************* Initialisation of MC *******************************/
+/*********************************************************************************/
+
+static void MC_dump_ignored_local_variables(void){
+
+ if(mc_stack_comparison_ignore == NULL || xbt_dynar_is_empty(mc_stack_comparison_ignore))
+ return;
+
+ unsigned int cursor = 0;
+ mc_stack_ignore_variable_t current_var;
+
+ xbt_dynar_foreach(mc_stack_comparison_ignore, cursor, current_var){
+ MC_ignore_local_variable(current_var->var_name, current_var->frame);
+ }
+
+ xbt_dynar_free(&mc_stack_comparison_ignore);
+ mc_stack_comparison_ignore = NULL;
+
+}
+
+static void MC_dump_ignored_global_variables(void){
+
+ if(mc_data_bss_comparison_ignore == NULL || xbt_dynar_is_empty(mc_data_bss_comparison_ignore))
+ return;
+
+ unsigned int cursor = 0;
+ mc_data_bss_ignore_variable_t current_var;
+
+ xbt_dynar_foreach(mc_data_bss_comparison_ignore, cursor, current_var){
+ MC_ignore_global_variable(current_var->name);
+ }
+
+ xbt_dynar_free(&mc_data_bss_comparison_ignore);
+ mc_data_bss_comparison_ignore = NULL;
+
+}
+
+static void MC_init_debug_info();
+static void MC_init_debug_info() {
+ XBT_INFO("Get debug information ...");
+
+ memory_map_t maps = MC_get_memory_map();
+
+ /* Get local variables for state equality detection */
+ mc_binary_info = MC_find_object_info(maps, xbt_binary_name);
+ mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path);
+
+ MC_free_memory_map(maps);
+ XBT_INFO("Get debug information done !");
+}
+
+void MC_init(){
+
+ int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+
+ compare = 0;