From: Gabriel Corona Date: Thu, 20 Feb 2014 11:26:24 +0000 (+0100) Subject: [mc] Avoid (slow) type lookups by name or ID (xbt_dict_get_or_null) X-Git-Tag: v3_11~199^2~2^2~24^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/594467781e41cea1d841b9fc501a8cc0cc0f7081 [mc] Avoid (slow) type lookups by name or ID (xbt_dict_get_or_null) --- diff --git a/src/include/mc/datatypes.h b/src/include/mc/datatypes.h index ddcb573dcd..baeb22d8cc 100644 --- a/src/include/mc/datatypes.h +++ b/src/include/mc/datatypes.h @@ -64,6 +64,7 @@ struct s_dw_type{ int is_pointer_type; int offset; dw_type_t subtype; + dw_type_t other_object_same_type; // The same (but more complete) type in the other object. }; char* get_type_description(mc_object_info_t info, char *type_name); diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index f04d8e9370..9a923b26c5 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -45,7 +45,6 @@ static void MC_snapshot_stack_free_voidp(void *s){ static void local_variable_free(local_variable_t v){ xbt_free(v->frame); xbt_free(v->name); - xbt_free(v->type); xbt_free(v); } @@ -259,7 +258,7 @@ static xbt_dynar_t MC_get_local_variables_values(xbt_dynar_t stack_frames){ new_var->frame = xbt_strdup(stack_frame->frame_name); new_var->ip = stack_frame->ip; new_var->name = xbt_strdup(current_variable->name); - new_var->type = strdup(current_variable->type_origin); + new_var->type = current_variable->type; new_var->region= region_type; /* if(current_variable->address!=NULL) { diff --git a/src/mc/mc_compare.c b/src/mc/mc_compare.c index b872692b7a..5b0e1df0d5 100644 --- a/src/mc/mc_compare.c +++ b/src/mc/mc_compare.c @@ -151,7 +151,7 @@ static int compare_areas_with_type(void *area1, void *area2, mc_object_info_t in case DW_TAG_structure_type: case DW_TAG_union_type: if(subtype->byte_size == 0){ /*declaration of the type, need the complete description */ - subtype = xbt_dict_get_or_null(other_info->types_by_name, subtype->name); + subtype = subtype->other_object_same_type; switch_types = 1; } elm_size = subtype->byte_size; @@ -161,7 +161,7 @@ static int compare_areas_with_type(void *area1, void *area2, mc_object_info_t in case DW_TAG_volatile_type: subsubtype = subtype->subtype; if(subsubtype->byte_size == 0){ /*declaration of the type, need the complete description */ - subsubtype = xbt_dict_get_or_null(other_info->types_by_name, subsubtype->name); + subsubtype = subsubtype->other_object_same_type; switch_types = 1; } elm_size = subsubtype->byte_size; @@ -180,7 +180,7 @@ static int compare_areas_with_type(void *area1, void *area2, mc_object_info_t in } break; case DW_TAG_pointer_type: - if(type->dw_type_id && ((dw_type_t)xbt_dict_get_or_null(info->types, type->dw_type_id))->type == DW_TAG_subroutine_type){ + if(type->subtype && type->subtype->type == DW_TAG_subroutine_type){ addr_pointed1 = *((void **)(area1)); addr_pointed2 = *((void **)(area2)); return (addr_pointed1 != addr_pointed2); @@ -284,7 +284,7 @@ static int compare_global_variables(int region_type, mc_mem_region_t r1, mc_mem_ offset = (char *)current_var->address - (char *)object_info->start_rw; - dw_type_t bvariable_type = xbt_dict_get_or_null(object_info->types, current_var->type_origin); + dw_type_t bvariable_type = current_var->type; res = compare_areas_with_type((char *)r1->data + offset, (char *)r2->data + offset, object_info, other_object_info, bvariable_type, r1->size, region_type, start_data, 0); if(res == 1){ XBT_VERB("Global variable %s (%p - %p) is different between snapshots", current_var->name, (char *)r1->data + offset, (char *)r2->data + offset); @@ -336,10 +336,10 @@ static int compare_local_variables(mc_snapshot_stack_t stack1, mc_snapshot_stack if(current_var1->region == 1) { - dw_type_t subtype = xbt_dict_get_or_null(mc_libsimgrid_info->types, current_var1->type); + dw_type_t subtype = current_var1->type; res = compare_areas_with_type( (char *)heap1 + offset1, (char *)heap2 + offset2, mc_libsimgrid_info, mc_binary_info, subtype, 0, 1, start_data_libsimgrid, 0); } else { - dw_type_t subtype = xbt_dict_get_or_null(mc_binary_info->types, current_var1->type); + dw_type_t subtype = current_var2->type; res = compare_areas_with_type( (char *)heap1 + offset1, (char *)heap2 + offset2, mc_binary_info, mc_libsimgrid_info, subtype, 0, 2, start_data_binary, 0); } if(res == 1){ diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index adc2241d7f..588ba67183 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -288,6 +288,31 @@ dw_frame_t MC_find_function_by_ip(void* ip) { return MC_find_function_by_ip_and_object(ip, info); } +static void MC_post_process_variables(mc_object_info_t info) { + unsigned cursor = 0; + dw_variable_t variable = NULL; + xbt_dynar_foreach(info->global_variables, cursor, variable) { + if(variable->type_origin) { + variable->type = xbt_dict_get_or_null(info->types, variable->type_origin); + } + } +} + +static void MC_post_process_functions(mc_object_info_t info) { + xbt_dict_cursor_t cursor = NULL; + char* key = NULL; + dw_frame_t function = NULL; + xbt_dict_foreach(info->local_variables, cursor, key, function) { + unsigned cursor2 = 0; + dw_variable_t variable = NULL; + xbt_dynar_foreach(function->variables, cursor2, variable) { + if(variable->type_origin) { + variable->type = xbt_dict_get_or_null(info->types, variable->type_origin); + } + } + } +} + /** \brief Finds informations about a given shared object/executable */ mc_object_info_t MC_find_object_info(memory_map_t maps, char* name, int executable) { mc_object_info_t result = MC_new_object_info(); @@ -297,6 +322,8 @@ mc_object_info_t MC_find_object_info(memory_map_t maps, char* name, int executab MC_find_object_address(maps, result); MC_dwarf_get_variables(result); MC_post_process_types(result); + MC_post_process_variables(result); + MC_post_process_functions(result); MC_make_functions_index(result); return result; } @@ -869,8 +896,19 @@ void MC_ignore(void *addr, size_t size){ /******************************* Initialisation of MC *******************************/ /*********************************************************************************/ -static void MC_init_debug_info(); -static void MC_init_debug_info() { +static void MC_post_process_object_info(mc_object_info_t info) { + mc_object_info_t other_info = info == mc_binary_info ? mc_libsimgrid_info : mc_binary_info; + xbt_dict_cursor_t cursor = NULL; + char* key = NULL; + dw_type_t type = NULL; + xbt_dict_foreach(info->types, cursor, key, type){ + if(type->name && type->byte_size == 0) { + type->other_object_same_type = xbt_dict_get_or_null(other_info->types_by_name, type->name); + } + } +} + +static void MC_init_debug_info(void) { XBT_INFO("Get debug information ..."); memory_map_t maps = MC_get_memory_map(); @@ -879,6 +917,10 @@ static void MC_init_debug_info() { mc_binary_info = MC_find_object_info(maps, xbt_binary_name, 1); mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path, 0); + // Use information of the other objects: + MC_post_process_object_info(mc_binary_info); + MC_post_process_object_info(mc_libsimgrid_info); + MC_free_memory_map(maps); XBT_INFO("Get debug information done !"); } diff --git a/src/mc/mc_hash.c b/src/mc/mc_hash.c index 4e8c536f39..533548bff4 100644 --- a/src/mc/mc_hash.c +++ b/src/mc/mc_hash.c @@ -197,7 +197,7 @@ static void mc_hash_object_globals(mc_hash_t *hash, mc_hashing_state* state, mc_ continue; } - dw_type_t type = xbt_dict_get_or_null(info->types, variable->type_origin); + dw_type_t type = variable->type; if(type==NULL) { // Nothing continue; @@ -237,7 +237,7 @@ static void mc_hash_stack_frame( void* variable_address = (void*) MC_dwarf_resolve_location(unw_cursor, variable->location, frame_pointer); - dw_type_t type = xbt_dict_get_or_null(info->types, variable->type_origin); + dw_type_t type = variable->type; if(type==NULL) { XBT_DEBUG("Hash local variable %s without loctypeation", variable->name); continue; diff --git a/src/mc/mc_private.h b/src/mc/mc_private.h index 60a07695a5..ecf5bf12e6 100644 --- a/src/mc/mc_private.h +++ b/src/mc/mc_private.h @@ -437,6 +437,7 @@ typedef struct s_dw_variable{ int global; char *name; char *type_origin; + dw_type_t type; // Use either of: dw_location_t location; @@ -480,7 +481,7 @@ typedef struct s_local_variable{ char *frame; unsigned long ip; char *name; - char *type; + dw_type_t type; void *address; int region; }s_local_variable_t, *local_variable_t;