+static int compare_global_variables(int region_type, mc_mem_region_t r1, mc_mem_region_t r2){
+
+ if(!compared_pointers){
+ compared_pointers = xbt_dynar_new(sizeof(pointers_pair_t), NULL);
+ MC_ignore_global_variable("compared_pointers", 1);
+ }else{
+ xbt_dynar_reset(compared_pointers);
+ }
+
+ xbt_dynar_t variables;
+ xbt_dict_t types, other_types;
+ int res;
+ unsigned int cursor = 0;
+ dw_variable_t current_var;
+ size_t offset;
+ void *start_data;
+
+ if(region_type == 2){
+ variables = mc_global_variables_binary;
+ types = mc_variables_type_binary;
+ other_types = mc_variables_type_libsimgrid;
+ start_data = start_data_binary;
+ }else{
+ variables = mc_global_variables_libsimgrid;
+ types = mc_variables_type_libsimgrid;
+ other_types = mc_variables_type_binary;
+ start_data = start_data_libsimgrid;
+ }
+
+ xbt_dynar_foreach(variables, cursor, current_var){
+
+ if(region_type == 2)
+ offset = (char *)current_var->address.address - (char *)start_data_binary;
+ else
+ offset = (char *)current_var->address.address - (char *)start_data_libsimgrid;
+
+ res = compare_areas_with_type((char *)r1->data + offset, (char *)r2->data + offset, types, other_types, current_var->type_origin, r1->size, region_type, start_data, 0);
+ if(res == -1){
+ xbt_dynar_cursor_rm(variables, &cursor);
+ }else if(res == 1){
+ XBT_VERB("Global variable %s is different between snapshots", current_var->name);
+ return 1;
+ }
+
+ }
+ return 0;
+
+}
+
+static int compare_local_variables(mc_snapshot_stack_t stack1, mc_snapshot_stack_t stack2, void *heap1, void *heap2){
+
+ if(!compared_pointers){
+ compared_pointers = xbt_dynar_new(sizeof(pointers_pair_t), NULL);
+ MC_ignore_global_variable("compared_pointers", 1);
+ }else{
+ xbt_dynar_reset(compared_pointers);
+ }
+
+ if(xbt_dynar_length(stack1->local_variables) != xbt_dynar_length(stack2->local_variables)){
+ XBT_VERB("Different number of local variables");
+ return 1;
+ }else{
+ unsigned int cursor = 0;
+ local_variable_t current_var1, current_var2;
+ int offset1, offset2, res;
+ while(cursor < xbt_dynar_length(stack1->local_variables)){
+ current_var1 = (local_variable_t)xbt_dynar_get_as(stack1->local_variables, cursor, local_variable_t);
+ current_var2 = (local_variable_t)xbt_dynar_get_as(stack2->local_variables, cursor, local_variable_t);
+ if(strcmp(current_var1->name, current_var2->name) != 0 || strcmp(current_var1->frame, current_var2->frame) != 0 || current_var1->ip != current_var2->ip)
+ return 1;
+ offset1 = (char *)current_var1->address - (char *)std_heap;
+ offset2 = (char *)current_var2->address - (char *)std_heap;
+ if(current_var1->region == 1)
+ res = compare_areas_with_type( (char *)heap1 + offset1, (char *)heap2 + offset2, mc_variables_type_libsimgrid, mc_variables_type_binary, current_var1->type, 0, 1, start_data_libsimgrid, 0l);
+ else
+ res = compare_areas_with_type( (char *)heap1 + offset1, (char *)heap2 + offset2, mc_variables_type_binary, mc_variables_type_libsimgrid, current_var1->type, 0, 2, start_data_binary, 0l);
+ if(res != 0){
+ XBT_VERB("Local variable %s in frame %s is different between snapshots", current_var1->name, current_var1->frame);
+ return res;
+ }
+ cursor++;
+ }
+ return 0;
+ }
+}
+
+