From: Gabriel Corona Date: Mon, 20 Jul 2015 11:46:30 +0000 (+0200) Subject: [mc] C++ location lists and expressions X-Git-Tag: v3_12~438^2~33 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4b6ea22affbf2fb45a2e80779c789047121ceff6 [mc] C++ location lists and expressions --- diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 9d38793d4c..13c9397b9a 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -304,7 +304,7 @@ static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame, if (current_variable->address != NULL) { new_var.address = current_variable->address; - } else if (current_variable->location_list.size != 0) { + } else if (!current_variable->location_list.empty()) { s_mc_location_t location; mc_dwarf_resolve_locations( &location, ¤t_variable->location_list, diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index 976264c0be..ee1b4ee363 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -761,9 +761,9 @@ static mc_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, uintptr_t base = (uintptr_t) info->base_address(); variable->address = (void *) (base + offset); } else { - mc_dwarf_location_list_init_from_expression( - &variable->location_list, len, - expr); + simgrid::mc::LocationListEntry entry; + entry.expression = {expr, expr + len}; + variable->location_list = { std::move(entry) }; } break; diff --git a/src/mc/mc_dwarf_expression.cpp b/src/mc/mc_dwarf_expression.cpp index b96efb97ff..3e4d99e873 100644 --- a/src/mc/mc_dwarf_expression.cpp +++ b/src/mc/mc_dwarf_expression.cpp @@ -429,7 +429,7 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops, * \deprecated Use mc_dwarf_resolve_expression */ void mc_dwarf_resolve_location(mc_location_t location, - mc_expression_t expression, + simgrid::mc::DwarfExpression* expression, mc_object_info_t object_info, unw_cursor_t * c, void *frame_pointer_address, @@ -443,10 +443,12 @@ void mc_dwarf_resolve_location(mc_location_t location, state.object_info = object_info; state.process_index = process_index; - if (expression->size >= 1 - && expression->ops[0].atom >=DW_OP_reg0 && expression->ops[0].atom <= DW_OP_reg31) { - int dwarf_register = expression->ops[0].atom - DW_OP_reg0; - xbt_assert(c, "Missing frame context for register operation DW_OP_reg%i", + if (expression->size() >= 1 + && (*expression)[0].atom >=DW_OP_reg0 + && (*expression)[0].atom <= DW_OP_reg31) { + int dwarf_register = (*expression)[0].atom - DW_OP_reg0; + xbt_assert(c, + "Missing frame context for register operation DW_OP_reg%i", dwarf_register); location->memory_location = NULL; location->cursor = c; @@ -454,7 +456,8 @@ void mc_dwarf_resolve_location(mc_location_t location, return; } - if (mc_dwarf_execute_expression(expression->size, expression->ops, &state)) + if (mc_dwarf_execute_expression( + expression->size(), expression->data(), &state)) xbt_die("Error evaluating DWARF expression"); if (state.stack_size == 0) xbt_die("No value on the stack"); @@ -465,24 +468,23 @@ void mc_dwarf_resolve_location(mc_location_t location, } } -static mc_expression_t mc_find_expression(mc_location_list_t locations, unw_word_t ip) { - for (size_t i = 0; i != locations->size; ++i) { - mc_expression_t expression = locations->locations + i; - if ((expression->lowpc == NULL && expression->highpc == NULL) - || (ip && ip >= (unw_word_t) expression->lowpc - && ip < (unw_word_t) expression->highpc)) { - return expression; - } - } - return NULL; +// TODO, move this in a method of LocationList +static simgrid::mc::DwarfExpression* mc_find_expression( + simgrid::mc::LocationList* locations, unw_word_t ip) +{ + for (simgrid::mc::LocationListEntry& entry : *locations) + if (entry.valid_for_ip(ip)) + return &entry.expression; + return nullptr; } void mc_dwarf_resolve_locations(mc_location_t location, - mc_location_list_t locations, - mc_object_info_t object_info, - unw_cursor_t * c, - void *frame_pointer_address, - mc_address_space_t address_space, int process_index) + simgrid::mc::LocationList* locations, + mc_object_info_t object_info, + unw_cursor_t * c, + void *frame_pointer_address, + mc_address_space_t address_space, + int process_index) { unw_word_t ip = 0; @@ -491,7 +493,7 @@ void mc_dwarf_resolve_locations(mc_location_t location, xbt_die("Could not resolve IP"); } - mc_expression_t expression = mc_find_expression(locations, ip); + simgrid::mc::DwarfExpression* expression = mc_find_expression(locations, ip); if (expression) { mc_dwarf_resolve_location(location, expression, object_info, c, @@ -534,50 +536,11 @@ void *mc_find_frame_base(mc_frame_t frame, mc_object_info_t object_info, } } -void mc_dwarf_expression_clear(mc_expression_t expression) -{ - free(expression->ops); - expression->ops = NULL; - expression->size = 0; - expression->lowpc = NULL; - expression->highpc = NULL; -} - -void mc_dwarf_location_list_clear(mc_location_list_t list) -{ - for (size_t i = 0; i != list->size; ++i) { - mc_dwarf_expression_clear(list->locations + i); - } - free(list->locations); - list->locations = NULL; - list->size = 0; -} - -void mc_dwarf_expression_init(mc_expression_t expression, size_t len, - Dwarf_Op * ops) +void mc_dwarf_location_list_init( + simgrid::mc::LocationList* list, mc_object_info_t info, + Dwarf_Die * die, Dwarf_Attribute * attr) { - expression->lowpc = NULL; - expression->highpc = NULL; - expression->size = len; - expression->ops = (Dwarf_Op*) xbt_malloc(len * sizeof(Dwarf_Op)); - memcpy(expression->ops, ops, len * sizeof(Dwarf_Op)); -} - -void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, - size_t len, Dwarf_Op * ops) -{ - target->size = 1; - target->locations = (mc_expression_t) xbt_malloc(sizeof(s_mc_expression_t)); - mc_dwarf_expression_init(target->locations, len, ops); -} - -void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info, - Dwarf_Die * die, Dwarf_Attribute * attr) -{ - if (list->locations) { - mc_dwarf_location_list_clear(list); - } - list->size = 0; + list->clear(); ptrdiff_t offset = 0; Dwarf_Addr base, start, end; @@ -592,19 +555,15 @@ void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info, else if (offset == -1) xbt_die("Error while loading location list"); - int i = list->size; - list->size++; - list->locations = - (mc_expression_t) realloc(list->locations, - list->size * sizeof(s_mc_expression_t)); - mc_expression_t expression = list->locations + i; - expression->ops = NULL; - mc_dwarf_expression_init(expression, len, ops); + simgrid::mc::LocationListEntry entry; + entry.expression = simgrid::mc::DwarfExpression(ops, ops + len); void *base = info->base_address(); // If start == 0, this is not a location list: - expression->lowpc = start == 0 ? NULL : (char *) base + start; - expression->highpc = start == 0 ? NULL : (char *) base + end; + entry.lowpc = start == 0 ? NULL : (char *) base + start; + entry.highpc = start == 0 ? NULL : (char *) base + end; + + list->push_back(std::move(entry)); } } diff --git a/src/mc/mc_location.h b/src/mc/mc_location.h index 5d884daf65..7f603281a8 100644 --- a/src/mc/mc_location.h +++ b/src/mc/mc_location.h @@ -25,25 +25,30 @@ namespace mc { typedef std::vector DwarfExpression; + +/** \brief A DWARF expression with optional validity contraints */ +class LocationListEntry { +public: + DwarfExpression expression; + void* lowpc, *highpc; + + LocationListEntry() : lowpc(nullptr), highpc(nullptr) {} + + bool valid_for_ip(unw_word_t ip) + { + return (this->lowpc == nullptr && this->highpc == nullptr) + || (ip >= (unw_word_t) this->lowpc + && ip < (unw_word_t) this->highpc); + } +}; + +typedef std::vector LocationList; + } } SG_BEGIN_DECL() -/** \brief a DWARF expression with optional validity contraints */ -typedef struct s_mc_expression { - size_t size; - Dwarf_Op* ops; - // Optional validity: - void* lowpc, *highpc; -} s_mc_expression_t, *mc_expression_t; - -/** A location list (list of location expressions) */ -typedef struct s_mc_location_list { - size_t size; - mc_expression_t locations; -} s_mc_location_list_t, *mc_location_list_t; - /** A location is either a location in memory of a register location * * Usage: @@ -85,16 +90,20 @@ enum mc_location_type mc_get_location_type(mc_location_t location) { } } -XBT_INTERNAL void mc_dwarf_resolve_location(mc_location_t location, mc_expression_t expression, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_address_space_t address_space, int process_index); -MC_SHOULD_BE_INTERNAL void mc_dwarf_resolve_locations(mc_location_t location, mc_location_list_t locations, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_address_space_t address_space, int process_index); - -XBT_INTERNAL void mc_dwarf_expression_clear(mc_expression_t expression); -XBT_INTERNAL void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops); - -XBT_INTERNAL void mc_dwarf_location_list_clear(mc_location_list_t list); - -XBT_INTERNAL void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops); -XBT_INTERNAL void mc_dwarf_location_list_init(mc_location_list_t target, mc_object_info_t info, Dwarf_Die* die, Dwarf_Attribute* attr); +XBT_INTERNAL void mc_dwarf_resolve_location( + mc_location_t location, simgrid::mc::DwarfExpression* expression, + mc_object_info_t object_info, unw_cursor_t* c, + void* frame_pointer_address, mc_address_space_t address_space, + int process_index); +MC_SHOULD_BE_INTERNAL void mc_dwarf_resolve_locations( + mc_location_t location, simgrid::mc::LocationList* locations, + mc_object_info_t object_info, unw_cursor_t* c, + void* frame_pointer_address, mc_address_space_t address_space, + int process_index); + +XBT_INTERNAL void mc_dwarf_location_list_init( + simgrid::mc::LocationList*, mc_object_info_t info, Dwarf_Die* die, + Dwarf_Attribute* attr); #define MC_EXPRESSION_STACK_SIZE 64 diff --git a/src/mc/mc_object_info.cpp b/src/mc/mc_object_info.cpp index e88aee015a..5222260291 100644 --- a/src/mc/mc_object_info.cpp +++ b/src/mc/mc_object_info.cpp @@ -47,18 +47,11 @@ Variable::Variable() this->dwarf_offset = 0; this->global = 0; this->type = nullptr; - this->location_list = {0, nullptr}; this->address = nullptr; this->start_scope = 0; this->object_info = nullptr; } -Variable::~Variable() -{ - if (this->location_list.locations) - mc_dwarf_location_list_clear(&this->location_list); -} - // Frame Frame::Frame() @@ -66,7 +59,6 @@ Frame::Frame() this->tag = 0; this->low_pc = nullptr; this->high_pc = nullptr; - this->frame_base = {0, nullptr}; this->variables = xbt_dynar_new( sizeof(mc_variable_t), mc_variable_free_voidp); this->id = 0; @@ -78,7 +70,6 @@ Frame::Frame() Frame::~Frame() { - mc_dwarf_location_list_clear(&(this->frame_base)); xbt_dynar_free(&(this->variables)); xbt_dynar_free(&(this->scopes)); } diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index c44f0badb7..e7a5a1bce1 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -159,7 +159,6 @@ namespace mc { class Variable { public: Variable(); - ~Variable(); Variable(Variable const&) = delete; Variable& operator=(Variable const&) = delete; @@ -170,7 +169,7 @@ public: mc_type_t type; // Use either of: - s_mc_location_list_t location_list; + simgrid::mc::LocationList location_list; void* address; size_t start_scope; @@ -189,7 +188,7 @@ public: std::string name; void *low_pc; void *high_pc; - s_mc_location_list_t frame_base; + simgrid::mc::LocationList frame_base; xbt_dynar_t /* */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/ unsigned long int id; /* DWARF offset of the subprogram */ xbt_dynar_t /* */ scopes;