From ad5ee977c604c3348f24ef6f27e2ba160c87ae7b Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 18 Mar 2014 14:40:20 +0100 Subject: [PATCH] [mc] Fix type name handling * use a suitable prefix for type names (struct/class/union); * rename "types_by_name" into "full_types_by_name" to be more descriptive. --- src/mc/mc_checkpoint.c | 2 +- src/mc/mc_dwarf.c | 21 ++++++++++++++++++--- src/mc/mc_global.c | 6 +++--- src/mc/mc_private.h | 2 +- src/xbt/mmalloc/mm_diff.c | 20 ++++++++++---------- testsuite/mc/dwarf.c | 12 +++++++++--- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index e72bef316a..8c49abb216 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -163,7 +163,7 @@ static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type) { // Try to find a more complete description of the type: // We need to fix in order to support C++. - dw_type_t subtype = xbt_dict_get_or_null(info->types_by_name, type->subtype->name); + dw_type_t subtype = xbt_dict_get_or_null(info->full_types_by_name, type->subtype->name); if(subtype!=NULL) { type->subtype = subtype; } diff --git a/src/mc/mc_dwarf.c b/src/mc/mc_dwarf.c index 80b9bddf18..1ee1468c7b 100644 --- a/src/mc/mc_dwarf.c +++ b/src/mc/mc_dwarf.c @@ -520,9 +520,24 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die* die, Dwa // Global Offset type->id = (void *) dwarf_dieoffset(die); + char* prefix = ""; + switch (type->type) { + case DW_TAG_structure_type: + prefix = "struct "; + break; + case DW_TAG_union_type: + prefix = "union "; + break; + case DW_TAG_class_type: + prefix = "class "; + break; + default: + prefix = ""; + } + const char* name = MC_dwarf_attr_string(die, DW_AT_name); if (name!=NULL) { - type->name = xbt_strdup(name); + type->name = namespace ? bprintf("%s%s::%s", prefix, namespace, name) : bprintf("%s%s", prefix, name); } XBT_DEBUG("Processing type <%p>%s", type->id, type->name); @@ -556,7 +571,7 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die* die, Dwa case DW_TAG_class_type: MC_dwarf_add_members(info, die, unit, type); char* new_namespace = namespace == NULL ? xbt_strdup(type->name) - : bprintf("%s::%s", namespace, type->name); + : bprintf("%s::%s", namespace, name); MC_dwarf_handle_children(info, die, unit, frame, new_namespace); free(new_namespace); break; @@ -572,7 +587,7 @@ static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die* die, Dwar xbt_dict_set(info->types, key, type, NULL); if(type->name && type->byte_size!=0) { - xbt_dict_set(info->types_by_name, type->name, type, NULL); + xbt_dict_set(info->full_types_by_name, type->name, type, NULL); } } diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index f5d183b3f9..47ab4acd9c 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -186,7 +186,7 @@ mc_object_info_t MC_new_object_info(void) { res->subprograms = xbt_dynar_new(sizeof(dw_frame_t), NULL); res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp); res->types = xbt_dict_new_homogeneous(NULL); - res->types_by_name = xbt_dict_new_homogeneous(NULL); + res->full_types_by_name = xbt_dict_new_homogeneous(NULL); return res; } @@ -195,7 +195,7 @@ void MC_free_object_info(mc_object_info_t* info) { xbt_dynar_free(&(*info)->subprograms); xbt_dynar_free(&(*info)->global_variables); xbt_dict_free(&(*info)->types); - xbt_dict_free(&(*info)->types_by_name); + xbt_dict_free(&(*info)->full_types_by_name); xbt_free(info); xbt_dynar_free(&(*info)->functions_index); *info = NULL; @@ -741,7 +741,7 @@ static void MC_post_process_object_info(mc_object_info_t info) { 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); + type->other_object_same_type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name); } } } diff --git a/src/mc/mc_private.h b/src/mc/mc_private.h index fa2945f8eb..47fb84c208 100644 --- a/src/mc/mc_private.h +++ b/src/mc/mc_private.h @@ -349,7 +349,7 @@ struct s_mc_object_info { xbt_dynar_t subprograms; // xbt_dynar_t xbt_dynar_t global_variables; // xbt_dynar_t xbt_dict_t types; // xbt_dict_t - xbt_dict_t types_by_name; // xbt_dict_t (full defined type only) + xbt_dict_t full_types_by_name; // xbt_dict_t (full defined type only) // Here we sort the minimal information for an efficient (and cache-efficient) // lookup of a function given an instruction pointer. diff --git a/src/xbt/mmalloc/mm_diff.c b/src/xbt/mmalloc/mm_diff.c index a634e67550..07419b6446 100644 --- a/src/xbt/mmalloc/mm_diff.c +++ b/src/xbt/mmalloc/mm_diff.c @@ -875,7 +875,7 @@ static int compare_heap_area_with_type(struct s_mm_diff *state, void *real_area1 case DW_TAG_class_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 = xbt_dict_get_or_null(other_info->full_types_by_name, subtype->name); switch_types = 1; } elm_size = subtype->byte_size; @@ -886,7 +886,7 @@ static int compare_heap_area_with_type(struct s_mm_diff *state, void *real_area1 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, subtype->name); + subsubtype = xbt_dict_get_or_null(other_info->full_types_by_name, subtype->name); switch_types = 1; } elm_size = subsubtype->byte_size; @@ -938,11 +938,11 @@ static int compare_heap_area_with_type(struct s_mm_diff *state, void *real_area1 case DW_TAG_structure_type: case DW_TAG_class_type: if(type->byte_size == 0){ /*declaration of the structure, need the complete description */ - dw_type_t full_type = xbt_dict_get_or_null(info->types_by_name, type->name); + dw_type_t full_type = xbt_dict_get_or_null(info->full_types_by_name, type->name); if(full_type){ type = full_type; }else{ - type = xbt_dict_get_or_null(other_info->types_by_name, type->name); + type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name); switch_types = 1; } } @@ -1018,19 +1018,19 @@ static char* get_offset_type(void* real_base_address, char* type_id, int offset, case DW_TAG_class_type: if(type->byte_size == 0){ /*declaration of the structure, need the complete description */ if(*switch_type == 0){ - dw_type_t full_type = xbt_dict_get_or_null(info->types_by_name, type->name); + dw_type_t full_type = xbt_dict_get_or_null(info->full_types_by_name, type->name); if(full_type){ type = full_type; }else{ - type = xbt_dict_get_or_null(other_info->types_by_name, type->name); + type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name); *switch_type = 1; } }else{ - dw_type_t full_type = xbt_dict_get_or_null(other_info->types_by_name, type->name); + dw_type_t full_type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name); if(full_type){ type = full_type; }else{ - type = xbt_dict_get_or_null(info->types_by_name, type->name); + type = xbt_dict_get_or_null(info->full_types_by_name, type->name); *switch_type = 0; } } @@ -1142,11 +1142,11 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap type = xbt_dict_get_or_null(info->types, type_id); if(type->byte_size == 0){ if(type->subtype == NULL){ - dw_type_t full_type = xbt_dict_get_or_null(info->types_by_name, type->name); + dw_type_t full_type = xbt_dict_get_or_null(info->full_types_by_name, type->name); if(full_type) type = full_type; else - type = xbt_dict_get_or_null(other_info->types_by_name, type->name); + type = xbt_dict_get_or_null(other_info->full_types_by_name, type->name); }else{ type = type->subtype; } diff --git a/testsuite/mc/dwarf.c b/testsuite/mc/dwarf.c index 08b93a39e6..c6b1fe5565 100644 --- a/testsuite/mc/dwarf.c +++ b/testsuite/mc/dwarf.c @@ -87,7 +87,7 @@ static dw_variable_t test_global_variable(mc_object_info_t info, const char* nam return variable; } -static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t type) { +static dw_type_t find_member(mc_object_info_t info, const char* name, dw_type_t type) { unsigned int cursor = 0; dw_type_t member; xbt_dynar_foreach(type->members, cursor, member){ @@ -99,6 +99,8 @@ static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t ty int some_local_variable = 0; +typedef struct foo {int i;} s_foo; + int main(int argc, char** argv) { // xbt_init(&argc, argv); @@ -117,8 +119,8 @@ int main(int argc, char** argv) { var = test_global_variable(mc_binary_info, "test_some_struct", &test_some_struct, sizeof(test_some_struct)); type = xbt_dict_get_or_null(mc_binary_info->types, var->type_origin); - assert(find_type(mc_binary_info, "first", type)->offset == 0); - assert(find_type(mc_binary_info, "second", type)->offset + assert(find_member(mc_binary_info, "first", type)->offset == 0); + assert(find_member(mc_binary_info, "second", type)->offset == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct); unw_context_t context; @@ -128,5 +130,9 @@ int main(int argc, char** argv) { test_local_variable(mc_binary_info, "main", "argc", &argc, &cursor); + s_foo my_foo; + + assert(xbt_dict_get_or_null(mc_binary_info->full_types_by_name, "struct foo")); + _exit(0); } -- 2.20.1