From d4bb65aef6bed4db7389e777dfa7828bdebd1c02 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Fri, 10 Jan 2014 15:42:51 +0100 Subject: [PATCH 1/1] [mc] Deduplicate address location resolution in MC_dwarf_resolve_location() --- src/include/mc/datatypes.h | 1 + src/mc/mc_checkpoint.c | 67 ++++---------------------------------- src/mc/mc_dwarf.c | 36 ++++++++++++++++++++ src/mc/mc_private.h | 2 ++ 4 files changed, 45 insertions(+), 61 deletions(-) diff --git a/src/include/mc/datatypes.h b/src/include/mc/datatypes.h index 028a89192d..d13ce8c2d2 100644 --- a/src/include/mc/datatypes.h +++ b/src/include/mc/datatypes.h @@ -10,6 +10,7 @@ #include "xbt/swag.h" #include "xbt/fifo.h" +#include #include SG_BEGIN_DECL() diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index 898c0d1214..63d6104cd5 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -13,6 +13,8 @@ #include +#include "mc_private.h" + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, "Logging specific to mc_checkpoint"); @@ -440,6 +442,8 @@ static void MC_get_hash_local(char *snapshot_hash, xbt_dynar_t stacks){ } + + static xbt_dynar_t MC_get_local_variables_values(void *stack_context){ unw_cursor_t c; @@ -499,31 +503,7 @@ static xbt_dynar_t MC_get_local_variables_values(void *stack_context){ entry = xbt_dynar_get_as(frame->frame_base->location.loclist, cursor, dw_location_entry_t); if((true_ip >= entry->lowpc) && (true_ip < entry->highpc)){ frame_found = 1; - switch(entry->location->type){ - case e_dw_compose: - if(xbt_dynar_length(entry->location->location.compose) > 1){ - frame_pointer_address = NULL; /* TODO : location list with optimizations enabled */ - }else{ - location_entry = xbt_dynar_get_as(entry->location->location.compose, 0, dw_location_t); - switch(location_entry->type){ - case e_dw_register: - unw_get_reg(&c, location_entry->location.reg, &res); - frame_pointer_address = (void*)(long)res; - break; - case e_dw_bregister_op: - unw_get_reg(&c, location_entry->location.breg_op.reg, &res); - frame_pointer_address = (void*)((long)res + location_entry->location.breg_op.offset); - break; - default: - frame_pointer_address = NULL; /* FIXME : implement other cases (with optimizations enabled) */ - break; - } - } - break; - default: - frame_pointer_address = NULL; /* FIXME : implement other cases (with optimizations enabled) */ - break; - } + frame_pointer_address = (void*) MC_dwarf_resolve_location(&c, entry->location, NULL); } cursor++; } @@ -551,42 +531,7 @@ static xbt_dynar_t MC_get_local_variables_values(void *stack_context){ new_var->region= region_type; if(current_variable->address.location != NULL){ - switch(current_variable->address.location->type){ - case e_dw_compose: - if(xbt_dynar_length(current_variable->address.location->location.compose) > 1){ - /* TODO : location list with optimizations enabled */ - }else{ - location_entry = xbt_dynar_get_as(current_variable->address.location->location.compose, 0, dw_location_t); - - switch(location_entry->type){ - case e_dw_register: - unw_get_reg(&c, location_entry->location.reg, &res); - value = (long)res; - break; - case e_dw_bregister_op: - unw_get_reg(&c, location_entry->location.breg_op.reg, &res); - value = (long)res + location_entry->location.breg_op.offset; - break; - case e_dw_fbregister_op: - if(frame_pointer_address != NULL) - value = (long)((char *)frame_pointer_address + location_entry->location.fbreg_op); - else - value = 0; - break; - default: - value = 0; /* FIXME : implement other cases (with optimizations enabled)*/ - break; - } - - if(value) - new_var->address = (void *)value; - else - new_var->address = NULL; - } - break; - default : - break; - } + new_var->address = MC_dwarf_resolve_location(&c, current_variable->address.location, frame_pointer_address); } xbt_dynar_push(variables, &new_var); diff --git a/src/mc/mc_dwarf.c b/src/mc/mc_dwarf.c index 9cf1046e9d..6d7833f395 100644 --- a/src/mc/mc_dwarf.c +++ b/src/mc/mc_dwarf.c @@ -61,6 +61,8 @@ static inline const char* MC_dwarf_die_tagname(Dwarf_Die* die) { return MC_dwarf_tagname(dwarf_tag(die)); } +// ***** Attributes + static const char* MC_dwarf_attr_string(Dwarf_Die* die, int attribute) { Dwarf_Attribute attr; if (!dwarf_attr_integrate(die, attribute, &attr)) { @@ -160,6 +162,40 @@ static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit) { return result; } +// ***** Location + +Dwarf_Off MC_dwarf_resolve_location(unw_cursor_t* c, dw_location_t location, void* frame_pointer_address) { + unw_word_t res; + switch (location->type){ + case e_dw_compose: + if (xbt_dynar_length(location->location.compose) > 1){ + return 0; /* TODO : location list with optimizations enabled */ + } + dw_location_t location_entry = xbt_dynar_get_as(location->location.compose, 0, dw_location_t); + switch (location_entry->type){ + case e_dw_register: + unw_get_reg(c, location_entry->location.reg, &res); + return res; + case e_dw_bregister_op: + unw_get_reg(c, location_entry->location.breg_op.reg, &res); + return (Dwarf_Off) ((long)res + location_entry->location.breg_op.offset); + break; + case e_dw_fbregister_op: + if (frame_pointer_address != NULL) + return (Dwarf_Off)((char *)frame_pointer_address + location_entry->location.fbreg_op); + else + return 0; + default: + return 0; /* FIXME : implement other cases (with optimizations enabled) */ + } + break; + default: + return 0; + } +} + +// ***** dw_type_t + static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member, Dwarf_Die* child) { if (dwarf_hasattr(child, DW_AT_data_bit_offset)) { xbt_die("Can't groke DW_AT_data_bit_offset."); diff --git a/src/mc/mc_private.h b/src/mc/mc_private.h index 180d6f9c98..10287cada8 100644 --- a/src/mc/mc_private.h +++ b/src/mc/mc_private.h @@ -431,6 +431,8 @@ void dw_type_free(dw_type_t t); /********************************** DWARF **********************************/ +Dwarf_Off MC_dwarf_resolve_location(unw_cursor_t* c, dw_location_t location, void* frame_pointer_address); + /********************************** Miscellaneous **********************************/ typedef struct s_local_variable{ -- 2.20.1