X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b40c2e9bf3cf6e8b2fad15594852ce186bf99574..41626f8a47c96f54fa3b1ee61a90fb0af699dcbc:/src/mc/mc_dwarf.c diff --git a/src/mc/mc_dwarf.c b/src/mc/mc_dwarf.c index c1fd44722d..55de42ecb9 100644 --- a/src/mc/mc_dwarf.c +++ b/src/mc/mc_dwarf.c @@ -14,8 +14,14 @@ #include #include +#include "mc_object_info.h" #include "mc_private.h" +static void MC_dwarf_register_global_variable(mc_object_info_t info, dw_variable_t variable); +static void MC_register_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable); +static void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable); +static void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable); + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing"); /** \brief The default DW_TAG_lower_bound for a given DW_AT_language. @@ -159,7 +165,6 @@ static mc_tag_class MC_dwarf_tag_classify(int tag) case DW_TAG_restrict_type: case DW_TAG_interface_type: case DW_TAG_unspecified_type: - case DW_TAG_mutable_type: case DW_TAG_shared_type: return mc_tag_type; @@ -1019,7 +1024,7 @@ void MC_dwarf_get_variables(mc_object_info_t info) } Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ); if (dwarf == NULL) { - xbt_die("Your program must be compiled with -g"); + xbt_die("Your program must be compiled with -g (%s)", info->file_name); } // For each compilation unit: Dwarf_Off offset = 0; @@ -1167,48 +1172,6 @@ static void MC_make_functions_index(mc_object_info_t info) info->functions_index = index; } -mc_object_info_t MC_ip_find_object_info(void *ip) -{ - size_t i; - for (i = 0; i != mc_object_infos_size; ++i) { - if (ip >= (void *) mc_object_infos[i]->start_exec - && ip <= (void *) mc_object_infos[i]->end_exec) { - return mc_object_infos[i]; - } - } - return NULL; -} - -static dw_frame_t MC_find_function_by_ip_and_object(void *ip, - mc_object_info_t info) -{ - xbt_dynar_t dynar = info->functions_index; - mc_function_index_item_t base = - (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0); - int i = 0; - int j = xbt_dynar_length(dynar) - 1; - while (j >= i) { - int k = i + ((j - i) / 2); - if (ip < base[k].low_pc) { - j = k - 1; - } else if (ip >= base[k].high_pc) { - i = k + 1; - } else { - return base[k].function; - } - } - return NULL; -} - -dw_frame_t MC_find_function_by_ip(void *ip) -{ - mc_object_info_t info = MC_ip_find_object_info(ip); - if (info == NULL) - return NULL; - else - return MC_find_function_by_ip_and_object(ip, info); -} - static void MC_post_process_variables(mc_object_info_t info) { unsigned cursor = 0; @@ -1259,8 +1222,53 @@ static void MC_post_process_functions(mc_object_info_t info) } } + +/** \brief Fill/lookup the "subtype" field. + */ +static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type) +{ + + if (type->dw_type_id == NULL) + return; + type->subtype = xbt_dict_get_or_null(info->types, type->dw_type_id); + if (type->subtype == NULL) + return; + if (type->subtype->byte_size != 0) + return; + if (type->subtype->name == NULL) + return; + // 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->full_types_by_name, type->subtype->name); + if (subtype != NULL) { + type->subtype = subtype; + } + +} + +static void MC_post_process_types(mc_object_info_t info) +{ + xbt_dict_cursor_t cursor = NULL; + char *origin; + dw_type_t type; + + // Lookup "subtype" field: + xbt_dict_foreach(info->types, cursor, origin, type) { + MC_resolve_subtype(info, type); + + dw_type_t member; + unsigned int i = 0; + if (type->members != NULL) + xbt_dynar_foreach(type->members, i, member) { + MC_resolve_subtype(info, member); + } + } +} + /** \brief Finds informations about a given shared object/executable */ -mc_object_info_t MC_find_object_info(memory_map_t maps, char *name, +mc_object_info_t MC_find_object_info(memory_map_t maps, const char *name, int executable) { mc_object_info_t result = MC_new_object_info(); @@ -1358,25 +1366,34 @@ void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame, MC_dwarf_register_non_global_variable(info, frame, variable); } -void MC_post_process_object_info(mc_object_info_t info) +void MC_post_process_object_info(mc_process_t process, mc_object_info_t info) { xbt_dict_cursor_t cursor = NULL; char *key = NULL; dw_type_t type = NULL; xbt_dict_foreach(info->types, cursor, key, type) { + dw_type_t subtype = type; + while (subtype->type == DW_TAG_typedef || subtype->type == DW_TAG_volatile_type + || subtype->type == DW_TAG_const_type) { + if (subtype->subtype) + subtype = subtype->subtype; + else + break; + } + // Resolve full_type: - if (type->name && type->byte_size == 0) { - for (size_t i = 0; i != mc_object_infos_size; ++i) { + if (subtype->name && subtype->byte_size == 0) { + for (size_t i = 0; i != process->object_infos_size; ++i) { dw_type_t same_type = - xbt_dict_get_or_null(mc_object_infos[i]->full_types_by_name, - type->name); + xbt_dict_get_or_null(process->object_infos[i]->full_types_by_name, + subtype->name); if (same_type && same_type->name && same_type->byte_size) { type->full_type = same_type; break; } } - } + } else type->full_type = subtype; } }