From e0040bdd2da0584c51ac1d223bc0aaf0748be66b Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 20 Feb 2014 11:41:03 +0100 Subject: [PATCH 1/1] [mc] Use resolved addresses in frame->low_pc and frame->high_pc --- src/mc/mc_dwarf.c | 9 +++++++-- src/mc/mc_global.c | 10 ++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/mc/mc_dwarf.c b/src/mc/mc_dwarf.c index 5a371c9409..b4427da5d2 100644 --- a/src/mc/mc_dwarf.c +++ b/src/mc/mc_dwarf.c @@ -879,10 +879,15 @@ static void MC_dwarf_handle_subprogram_die(mc_object_info_t info, Dwarf_Die* die name = MC_dwarf_attr_string(die, DW_AT_name); frame->name = xbt_strdup(name); + // This is the base address for DWARF addresses. + // Relocated addresses are offset from this base address. + // See DWARF4 spec 7.5 + void* base = info->flags & MC_OBJECT_INFO_EXECUTABLE ? 0 : MC_object_base_address(info); + // Variables are filled in the (recursive) call of MC_dwarf_handle_children: frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp); - frame->high_pc = (void*) MC_dwarf_attr_addr(die, DW_AT_high_pc); - frame->low_pc = (void*) MC_dwarf_attr_addr(die, DW_AT_low_pc); + frame->high_pc = ((char*) base) + MC_dwarf_attr_addr(die, DW_AT_high_pc); + frame->low_pc = ((char*) base) + MC_dwarf_attr_addr(die, DW_AT_low_pc); frame->frame_base = MC_dwarf_at_location(die, DW_AT_frame_base); frame->end = -1; // This one is now useless: diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index 2b56b16b43..adc2241d7f 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -225,12 +225,6 @@ static int MC_compare_frame_index_items(mc_function_index_item_t a, mc_function_ static void MC_make_functions_index(mc_object_info_t info) { xbt_dynar_t index = xbt_dynar_new(sizeof(s_mc_function_index_item_t), NULL); - // The base address of the function must be used to offset the addresses. - // This should be fixed this in the frame_t structure instead. - // Relocated addresses are offset for shared objets and constant for executables objects. - // See DWARF4 spec 7.5 - void* offset = info->flags & MC_OBJECT_INFO_EXECUTABLE ? 0 : MC_object_base_address(info); - // Populate the array: dw_frame_t frame = NULL; xbt_dict_cursor_t cursor = NULL; @@ -239,8 +233,8 @@ static void MC_make_functions_index(mc_object_info_t info) { if(frame->low_pc==NULL) continue; s_mc_function_index_item_t entry; - entry.low_pc = (char*) frame->low_pc + (unsigned long) offset; - entry.high_pc = (char*) frame->high_pc + (unsigned long) offset; + entry.low_pc = frame->low_pc; + entry.high_pc = frame->high_pc; entry.function = frame; xbt_dynar_push(index, &entry); } -- 2.20.1