From: Gabriel Corona Date: Mon, 20 Jul 2015 09:47:54 +0000 (+0200) Subject: [mc] C++ify Variable X-Git-Tag: v3_12~438^2~35 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f0d9c752a61e9cbef5ffb5c4ff0ea4a7fac5cddf [mc] C++ify Variable --- diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 5b16ad1505..07178543cf 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -260,7 +260,7 @@ void MC_find_object_address(std::vector const& maps, mc_obje * \param ip Instruction pointer * \return true if the variable is valid * */ -static bool mc_valid_variable(dw_variable_t var, dw_frame_t scope, +static bool mc_valid_variable(mc_variable_t var, dw_frame_t scope, const void *ip) { // The variable is not yet valid: @@ -281,7 +281,7 @@ static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame, return; unsigned cursor = 0; - dw_variable_t current_variable; + mc_variable_t current_variable; xbt_dynar_foreach(scope->variables, cursor, current_variable) { if (!mc_valid_variable(current_variable, scope, (void *) stack_frame->ip)) @@ -304,10 +304,10 @@ 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->locations.size != 0) { + } else if (current_variable->location_list.size != 0) { s_mc_location_t location; mc_dwarf_resolve_locations( - &location, ¤t_variable->locations, + &location, ¤t_variable->location_list, current_variable->object_info, &(stack_frame->unw_cursor), (void *) stack_frame->frame_base, diff --git a/src/mc/mc_compare.cpp b/src/mc/mc_compare.cpp index ed81cf6d40..5aca919662 100644 --- a/src/mc/mc_compare.cpp +++ b/src/mc/mc_compare.cpp @@ -210,7 +210,7 @@ static int compare_areas_with_type(struct mc_compare_state& state, else if (region1->contain(simgrid::mc::remote(addr_pointed1))) { if (!region2->contain(simgrid::mc::remote(addr_pointed2))) return 1; - if (type->dw_type_id.empty()) + if (type->type_id.empty()) return (addr_pointed1 != addr_pointed2); else { return compare_areas_with_type(state, process_index, @@ -297,7 +297,7 @@ static int compare_global_variables(mc_object_info_t object_info, xbt_dynar_t variables; int res; unsigned int cursor = 0; - dw_variable_t current_var; + mc_variable_t current_var; variables = object_info->global_variables; @@ -319,7 +319,8 @@ static int compare_global_variables(mc_object_info_t object_info, if (res == 1) { XBT_TRACE3(mc, global_diff, -1, -1, current_var->name); XBT_VERB("Global variable %s (%p) is different between snapshots", - current_var->name, (char *) current_var->address); + current_var->name.c_str(), + (char *) current_var->address); return 1; } diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index f83f1464e9..7a7c6e54dd 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -18,13 +18,13 @@ #include "mc_object_info.h" #include "mc_private.h" -static void dw_variable_free(dw_variable_t v); -static void dw_variable_free_voidp(void *t); +static void mc_variable_free(mc_variable_t v); +static void mc_variable_free_voidp(void *t); -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); +static void MC_dwarf_register_global_variable(mc_object_info_t info, mc_variable_t variable); +static void MC_register_variable(mc_object_info_t info, dw_frame_t frame, mc_variable_t variable); +static void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, mc_variable_t variable); +static void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame, mc_variable_t variable); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing"); @@ -100,7 +100,7 @@ static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die * die, * \param die DIE * \return DW_TAG_type attribute as a new string (NULL if none) */ -static char *MC_dwarf_at_type(Dwarf_Die * die); +static std::string MC_dwarf_at_type(Dwarf_Die * die); /** \brief A class of DWARF tags (DW_TAG_*) */ @@ -305,10 +305,16 @@ static Dwarf_Off MC_dwarf_attr_integrate_dieoffset(Dwarf_Die * die, * \param dit the DIE * \return DW_AT_type reference as a global offset in hexadecimal (or NULL) */ -static char *MC_dwarf_at_type(Dwarf_Die * die) +static +std::string MC_dwarf_at_type(Dwarf_Die * die) { Dwarf_Off offset = MC_dwarf_attr_integrate_dieoffset(die, DW_AT_type); - return offset == 0 ? NULL : bprintf("%" PRIx64, offset); + if (offset == 0) + return std::string(); + char* s = bprintf("%" PRIx64, offset); + std::string res(s); + free(s); + return std::move(res); } static uint64_t MC_dwarf_attr_integrate_addr(Dwarf_Die * die, int attribute) @@ -568,12 +574,7 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die, member.byte_size = MC_dwarf_attr_integrate_uint(&child, DW_AT_byte_size, 0); member.element_count = -1; - - char* type_id = MC_dwarf_at_type(&child); - if (type_id) { - member.dw_type_id = type_id; - free(type_id); - } + member.type_id = MC_dwarf_at_type(&child); if (dwarf_hasattr(&child, DW_AT_data_bit_offset)) { xbt_die("Can't groke DW_AT_data_bit_offset."); @@ -581,7 +582,7 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die, MC_dwarf_fill_member_location(type, &member, &child); - if (member.dw_type_id.empty()) { + if (member.type_id.empty()) { xbt_die("Missing type for member %s of <%" PRIx64 ">%s", member.name.c_str(), (uint64_t) type->id, type->name.c_str()); @@ -637,11 +638,7 @@ static mc_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die, free(full_name); } - char* type_id = MC_dwarf_at_type(die); - if (type_id) { - type->dw_type_id = type_id; - free(type_id); - } + type->type_id = MC_dwarf_at_type(die); // Some compilers do not emit DW_AT_byte_size for pointer_type, // so we fill this. We currently assume that the model-checked process is in @@ -704,7 +701,7 @@ static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die, static int mc_anonymous_variable_index = 0; -static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, +static mc_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, const char *ns) { @@ -722,15 +719,15 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, return NULL; } - dw_variable_t variable = xbt_new0(s_dw_variable_t, 1); + simgrid::mc::Variable* variable = new simgrid::mc::Variable(); variable->dwarf_offset = dwarf_dieoffset(die); variable->global = frame == NULL; // Can be override base on DW_AT_location variable->object_info = info; const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name); - variable->name = xbt_strdup(name); - - variable->type_origin = MC_dwarf_at_type(die); + if (name) + variable->name = name; + variable->type_id = MC_dwarf_at_type(die); int form = dwarf_whatform(&attr_location); int klass = @@ -744,9 +741,11 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, Dwarf_Op *expr; size_t len; if (dwarf_getlocation(&attr_location, &expr, &len)) { - xbt_die - ("Could not read location expression in DW_AT_location of variable <%" - PRIx64 ">%s", (uint64_t) variable->dwarf_offset, variable->name); + xbt_die( + "Could not read location expression in DW_AT_location " + "of variable <%" PRIx64 ">%s", + (uint64_t) variable->dwarf_offset, + variable->name.c_str()); } if (len == 1 && expr[0].atom == DW_OP_addr) { @@ -755,8 +754,9 @@ static dw_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->locations, len, - expr); + mc_dwarf_location_list_init_from_expression( + &variable->location_list, len, + expr); } break; @@ -764,13 +764,16 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, case MC_DW_CLASS_LOCLISTPTR: case MC_DW_CLASS_CONSTANT: // Reference to location list: - mc_dwarf_location_list_init(&variable->locations, info, die, - &attr_location); + mc_dwarf_location_list_init( + &variable->location_list, info, die, + &attr_location); break; default: - xbt_die("Unexpected form 0x%x (%i), class 0x%x (%i) list for location in <%" - PRIx64 ">%s", form, form, klass, klass, - (uint64_t) variable->dwarf_offset, variable->name); + xbt_die("Unexpected form 0x%x (%i), class 0x%x (%i) list for location " + "in <%" PRIx64 ">%s", + form, form, klass, klass, + (uint64_t) variable->dwarf_offset, + variable->name.c_str()); } // Handle start_scope: @@ -795,16 +798,15 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, } } - if (ns && variable->global) { - char *old_name = variable->name; - variable->name = bprintf("%s::%s", ns, old_name); - free(old_name); - } + if (ns && variable->global) + variable->name = + std::string(ns) + "::" + variable->name; + // The current code needs a variable name, // generate a fake one: - if (!variable->name) { - variable->name = bprintf("@anonymous#%i", mc_anonymous_variable_index++); - } + if (variable->name.empty()) + variable->name = + "@anonymous#" + std::to_string(mc_anonymous_variable_index++); return variable; } @@ -813,7 +815,7 @@ static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, const char *ns) { - dw_variable_t variable = + mc_variable_t variable = MC_die_to_variable(info, die, unit, frame, ns); if (variable == NULL) return; @@ -864,7 +866,7 @@ static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die, // 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); + xbt_dynar_new(sizeof(mc_variable_t), mc_variable_free_voidp); // TODO, support DW_AT_ranges uint64_t low_pc = MC_dwarf_attr_integrate_addr(die, DW_AT_low_pc); @@ -1041,21 +1043,9 @@ static void dw_type_free(mc_type_t t) delete t; } -void dw_variable_free(dw_variable_t v) -{ - if (v) { - xbt_free(v->name); - xbt_free(v->type_origin); - - if (v->locations.locations) - mc_dwarf_location_list_clear(&v->locations); - xbt_free(v); - } -} - -void dw_variable_free_voidp(void *t) +void mc_variable_free_voidp(void *t) { - dw_variable_free((dw_variable_t) * (void **) t); + delete *(simgrid::mc::Variable**)t; } // ***** object_info @@ -1077,7 +1067,7 @@ ObjectInformation::ObjectInformation() this->end_ro = nullptr; this->subprograms = xbt_dict_new_homogeneous((void (*)(void *)) mc_frame_free); this->global_variables = - xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp); + xbt_dynar_new(sizeof(mc_variable_t), mc_variable_free_voidp); this->types = xbt_dict_new_homogeneous((void (*)(void *)) dw_type_free); this->full_types_by_name = xbt_dict_new_homogeneous(NULL); this->functions_index = nullptr; @@ -1171,12 +1161,11 @@ static void MC_make_functions_index(mc_object_info_t info) static void MC_post_process_variables(mc_object_info_t info) { unsigned cursor = 0; - dw_variable_t variable = NULL; - xbt_dynar_foreach(info->global_variables, cursor, variable) { - if (variable->type_origin) { - variable->type = (mc_type_t) xbt_dict_get_or_null(info->types, variable->type_origin); - } - } + mc_variable_t variable = nullptr; + xbt_dynar_foreach(info->global_variables, cursor, variable) + if (!variable->type_id.empty()) + variable->type = (mc_type_t) xbt_dict_get_or_null( + info->types, variable->type_id.c_str()); } static void mc_post_process_scope(mc_object_info_t info, dw_frame_t scope) @@ -1192,17 +1181,17 @@ static void mc_post_process_scope(mc_object_info_t info, dw_frame_t scope) scope->name = xbt_strdup(abstract_origin->name); } + // Direct: unsigned cursor = 0; - dw_variable_t variable = NULL; - xbt_dynar_foreach(scope->variables, cursor, variable) { - if (variable->type_origin) { - variable->type = (mc_type_t) xbt_dict_get_or_null(info->types, variable->type_origin); - } - } + mc_variable_t variable = nullptr; + xbt_dynar_foreach(scope->variables, cursor, variable) + if (!variable->type_id.empty()) + variable->type = (mc_type_t) xbt_dict_get_or_null( + info->types, variable->type_id.c_str()); // Recursive post-processing of nested-scopes: - dw_frame_t nested_scope = NULL; + dw_frame_t nested_scope = nullptr; xbt_dynar_foreach(scope->scopes, cursor, nested_scope) mc_post_process_scope(info, nested_scope); @@ -1224,10 +1213,10 @@ static void MC_post_process_functions(mc_object_info_t info) static void MC_resolve_subtype(mc_object_info_t info, mc_type_t type) { - if (type->dw_type_id.empty()) + if (type->type_id.empty()) return; type->subtype = (mc_type_t) xbt_dict_get_or_null( - info->types, type->dw_type_id.c_str()); + info->types, type->type_id.c_str()); if (type->subtype == NULL) return; if (type->subtype->byte_size != 0) @@ -1280,7 +1269,7 @@ std::shared_ptr MC_find_object_info( /*************************************************************************/ -static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char *var, +static int MC_dwarf_get_variable_index(xbt_dynar_t variables, const char *var, void *address) { @@ -1290,15 +1279,15 @@ static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char *var, unsigned int cursor = 0; int start = 0; int end = xbt_dynar_length(variables) - 1; - dw_variable_t var_test = NULL; + mc_variable_t var_test = NULL; while (start <= end) { cursor = (start + end) / 2; var_test = - (dw_variable_t) xbt_dynar_get_as(variables, cursor, dw_variable_t); - if (strcmp(var_test->name, var) < 0) { + (mc_variable_t) xbt_dynar_get_as(variables, cursor, mc_variable_t); + if (strcmp(var_test->name.c_str(), var) < 0) { start = cursor + 1; - } else if (strcmp(var_test->name, var) > 0) { + } else if (strcmp(var_test->name.c_str(), var) > 0) { end = cursor - 1; } else { if (address) { /* global variable */ @@ -1314,12 +1303,12 @@ static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char *var, } } - if (strcmp(var_test->name, var) == 0) { + if (strcmp(var_test->name.c_str(), var) == 0) { if (address && var_test->address < address) return cursor + 1; else return cursor; - } else if (strcmp(var_test->name, var) < 0) + } else if (strcmp(var_test->name.c_str(), var) < 0) return cursor + 1; else return cursor; @@ -1327,11 +1316,12 @@ static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char *var, } void MC_dwarf_register_global_variable(mc_object_info_t info, - dw_variable_t variable) + mc_variable_t variable) { int index = - MC_dwarf_get_variable_index(info->global_variables, variable->name, - variable->address); + MC_dwarf_get_variable_index(info->global_variables, + variable->name.c_str(), + variable->address); if (index != -1) xbt_dynar_insert_at(info->global_variables, index, &variable); // TODO, else ? @@ -1339,18 +1329,19 @@ void MC_dwarf_register_global_variable(mc_object_info_t info, void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, - dw_variable_t variable) + mc_variable_t variable) { xbt_assert(frame, "Frame is NULL"); int index = - MC_dwarf_get_variable_index(frame->variables, variable->name, NULL); + MC_dwarf_get_variable_index( + frame->variables, variable->name.c_str(), NULL); if (index != -1) xbt_dynar_insert_at(frame->variables, index, &variable); // TODO, else ? } void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame, - dw_variable_t variable) + mc_variable_t variable) { if (variable->global) MC_dwarf_register_global_variable(info, variable); diff --git a/src/mc/mc_forward.h b/src/mc/mc_forward.h index f2de3460a6..2cc0c34399 100644 --- a/src/mc/mc_forward.h +++ b/src/mc/mc_forward.h @@ -24,6 +24,7 @@ class Process; class Snapshot; class ObjectInformation; class Type; +class Variable; } } @@ -35,6 +36,7 @@ typedef ::simgrid::mc::Process s_mc_process_t; typedef ::simgrid::mc::Snapshot s_mc_snapshot_t; typedef ::simgrid::mc::ObjectInformation s_mc_object_info_t; typedef ::simgrid::mc::Type s_mc_type_t; +typedef ::simgrid::mc::Variable s_mc_variable_t; #else @@ -45,11 +47,11 @@ typedef struct _s_mc_process_t s_mc_process_t; typedef struct _s_mc_snapshot_t s_mc_snapshot_t; typedef struct _s_mc_object_info_t s_mc_object_info_t; typedef struct _s_mc_type_t s_mc_type_t; +typedef struct _s_mc_variable_t s_mc_variable_t; #endif typedef struct s_memory_map s_memory_map_t, *memory_map_t; -typedef struct s_dw_variable s_dw_variable_t, *dw_variable_t; typedef struct s_dw_frame s_dw_frame_t, *dw_frame_t; typedef s_mc_pages_store_t *mc_pages_store_t; @@ -59,6 +61,7 @@ typedef s_mc_process_t *mc_process_t; typedef s_mc_snapshot_t *mc_snapshot_t; typedef s_mc_object_info_t *mc_object_info_t; typedef s_mc_type_t *mc_type_t; +typedef s_mc_variable_t *mc_variable_t; SG_BEGIN_DECL() extern mc_model_checker_t mc_model_checker; diff --git a/src/mc/mc_hash.cpp b/src/mc/mc_hash.cpp index 9e6b2c1886..4b7f246ec0 100644 --- a/src/mc/mc_hash.cpp +++ b/src/mc/mc_hash.cpp @@ -190,7 +190,7 @@ top: if (type->subtype == NULL) { XBT_DEBUG("Missing type for %p (type=%s)", - pointed, type->dw_type_id.c_str()); + pointed, type->type_id.c_str()); return; } @@ -211,11 +211,11 @@ static void mc_hash_object_globals(hash_type * hash, mc_hashing_state * state, mc_object_info_t info) { unsigned int cursor = 0; - dw_variable_t variable; + mc_variable_t variable; xbt_dynar_foreach(info->global_variables, cursor, variable) { XBT_DEBUG("Hash global variable %s", variable->name); - if (variable->type_origin == NULL) { + if (variable->type_id == NULL) { // Nothing continue; } @@ -249,10 +249,10 @@ static void mc_hash_stack_frame(mc_hash_t * hash, // return; // TEMP unsigned int cursor = 0; - dw_variable_t variable; + mc_variable_t variable; xbt_dynar_foreach(frame->variables, cursor, variable) { - if (variable->type_origin == NULL) { + if (variable->type_id == NULL) { XBT_DEBUG("Hash local variable %s without type", variable->name); continue; } diff --git a/src/mc/mc_object_info.cpp b/src/mc/mc_object_info.cpp index 5027e08111..b05c69ee48 100644 --- a/src/mc/mc_object_info.cpp +++ b/src/mc/mc_object_info.cpp @@ -27,6 +27,25 @@ Type::Type() this->full_type = nullptr; } +// Type + +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); +} + // ObjectInformations dw_frame_t ObjectInformation::find_function(const void *ip) const @@ -49,15 +68,13 @@ dw_frame_t ObjectInformation::find_function(const void *ip) const return nullptr; } -dw_variable_t ObjectInformation::find_variable(const char* name) const +mc_variable_t ObjectInformation::find_variable(const char* name) const { unsigned int cursor = 0; - dw_variable_t variable; - xbt_dynar_foreach(this->global_variables, cursor, variable){ - if(!strcmp(name, variable->name)) + mc_variable_t variable; + xbt_dynar_foreach(this->global_variables, cursor, variable) + if(variable->name == name) return variable; - } - return nullptr; } diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index 237d1cbc76..dbe815fbca 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -50,7 +50,7 @@ public: std::string name; /* Name of the type */ int byte_size; /* Size in bytes */ int element_count; /* Number of elements for array type */ - std::string dw_type_id; /* DW_AT_type id */ + std::string type_id; /* DW_AT_type id */ std::vector members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/ int is_pointer_type; @@ -113,7 +113,7 @@ public: char *start_ro; char *end_ro; // read-only segment xbt_dict_t subprograms; // xbt_dict_t - xbt_dynar_t global_variables; // xbt_dynar_t + xbt_dynar_t global_variables; // xbt_dynar_t xbt_dict_t types; // xbt_dict_t xbt_dict_t full_types_by_name; // xbt_dict_t (full defined type only) @@ -135,7 +135,7 @@ public: void* base_address() const; dw_frame_t find_function(const void *ip) const; - dw_variable_t find_variable(const char* name) const; + mc_variable_t find_variable(const char* name) const; }; @@ -153,15 +153,24 @@ XBT_INTERNAL const char* MC_dwarf_tagname(int tag); XBT_INTERNAL void* mc_member_resolve(const void* base, mc_type_t type, mc_type_t member, mc_address_space_t snapshot, int process_index); -struct s_dw_variable{ +namespace simgrid { +namespace mc { + +class Variable { +public: + Variable(); + ~Variable(); + Variable(Variable const&) = delete; + Variable& operator=(Variable const&) = delete; + Dwarf_Off dwarf_offset; /* Global offset of the field. */ int global; - char *name; - char *type_origin; + std::string name; + std::string type_id; mc_type_t type; // Use either of: - s_mc_location_list_t locations; + s_mc_location_list_t location_list; void* address; size_t start_scope; @@ -169,13 +178,16 @@ struct s_dw_variable{ }; +} +} + struct s_dw_frame{ int tag; char *name; void *low_pc; void *high_pc; s_mc_location_list_t frame_base; - xbt_dynar_t /* */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/ + 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; Dwarf_Off abstract_origin_id; diff --git a/src/mc/mc_process.cpp b/src/mc/mc_process.cpp index 3ebec2a3a7..512cba0836 100644 --- a/src/mc/mc_process.cpp +++ b/src/mc/mc_process.cpp @@ -218,7 +218,7 @@ Process::Process(pid_t pid, int sockfd) } // Read std_heap (is a struct mdesc*): - dw_variable_t std_heap_var = process->find_variable("__mmalloc_default_mdp"); + mc_variable_t std_heap_var = process->find_variable("__mmalloc_default_mdp"); if (!std_heap_var) xbt_die("No heap information in the target process"); if(!std_heap_var->address) @@ -441,7 +441,7 @@ dw_frame_t Process::find_function(remote_ptr ip) const /** Find (one occurence of) the named variable definition */ -dw_variable_t Process::find_variable(const char* name) const +mc_variable_t Process::find_variable(const char* name) const { // First lookup the variable in the executable shared object. // A global variable used directly by the executable code from a library @@ -449,13 +449,13 @@ dw_variable_t Process::find_variable(const char* name) const // We need to look up the variable in the execvutable first. if (this->binary_info) { std::shared_ptr const& info = this->binary_info; - dw_variable_t var = info->find_variable(name); + mc_variable_t var = info->find_variable(name); if (var) return var; } for (std::shared_ptr const& info : this->object_infos) { - dw_variable_t var = info->find_variable(name); + mc_variable_t var = info->find_variable(name); if (var) return var; } @@ -465,7 +465,7 @@ dw_variable_t Process::find_variable(const char* name) const void Process::read_variable(const char* name, void* target, size_t size) const { - dw_variable_t var = this->find_variable(name); + mc_variable_t var = this->find_variable(name); if (!var->address) xbt_die("No simple location for this variable"); if (!var->type->full_type) diff --git a/src/mc/mc_process.h b/src/mc/mc_process.h index b357134907..3b79fb43ca 100644 --- a/src/mc/mc_process.h +++ b/src/mc/mc_process.h @@ -93,7 +93,7 @@ public: std::shared_ptr find_object_info_exec(remote_ptr addr) const; std::shared_ptr find_object_info_rw(remote_ptr addr) const; dw_frame_t find_function(remote_ptr ip) const; - dw_variable_t find_variable(const char* name) const; + mc_variable_t find_variable(const char* name) const; // Heap access: xbt_mheap_t get_heap() diff --git a/src/mc/mcer_ignore.cpp b/src/mc/mcer_ignore.cpp index ed25728772..bd7e6a290a 100644 --- a/src/mc/mcer_ignore.cpp +++ b/src/mc/mcer_ignore.cpp @@ -121,14 +121,15 @@ void MCer_ignore_global_variable(const char *name) int end = xbt_dynar_length(info->global_variables) - 1; while (start <= end) { unsigned int cursor = (start + end) / 2; - dw_variable_t current_var = - (dw_variable_t) xbt_dynar_get_as(info->global_variables, - cursor, dw_variable_t); - if (strcmp(current_var->name, name) == 0) { + mc_variable_t current_var = + (mc_variable_t) xbt_dynar_get_as(info->global_variables, + cursor, mc_variable_t); + int cmp = strcmp(current_var->name.c_str(), name); + if (cmp == 0) { xbt_dynar_remove_at(info->global_variables, cursor, NULL); start = 0; end = xbt_dynar_length(info->global_variables) - 1; - } else if (strcmp(current_var->name, name) < 0) { + } else if (cmp < 0) { start = cursor + 1; } else { end = cursor - 1; @@ -198,11 +199,11 @@ static void mc_ignore_local_variable_in_scope(const char *var_name, // Dichotomic search: while (start <= end) { int cursor = (start + end) / 2; - dw_variable_t current_var = - (dw_variable_t) xbt_dynar_get_as(scope->variables, cursor, - dw_variable_t); + mc_variable_t current_var = + (mc_variable_t) xbt_dynar_get_as(scope->variables, cursor, + mc_variable_t); - int compare = strcmp(current_var->name, var_name); + int compare = strcmp(current_var->name.c_str(), var_name); if (compare == 0) { // Variable found, remove it: xbt_dynar_remove_at(scope->variables, cursor, NULL); diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index 930e72aaac..bf42cab879 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -43,22 +43,22 @@ static dw_frame_t find_function_by_name(mc_object_info_t info, const char* name) return NULL; } -static dw_variable_t find_local_variable(dw_frame_t frame, const char* argument_name) { +static mc_variable_t find_local_variable( + dw_frame_t frame, const char* argument_name) { unsigned int cursor = 0; - dw_variable_t variable; - xbt_dynar_foreach(frame->variables, cursor, variable){ - if(!strcmp(argument_name, variable->name)) + mc_variable_t variable; + xbt_dynar_foreach(frame->variables, cursor, variable) + if(argument_name == variable->name) return variable; - } - dw_frame_t scope = NULL; + dw_frame_t scope = nullptr; xbt_dynar_foreach(frame->scopes, cursor, scope) { variable = find_local_variable(scope, argument_name); if(variable) return variable; } - return NULL; + return nullptr; } static void test_local_variable(mc_object_info_t info, const char* function, const char* variable, void* address, unw_cursor_t* cursor) { @@ -66,14 +66,14 @@ static void test_local_variable(mc_object_info_t info, const char* function, con assert(subprogram); // TODO, Lookup frame by IP and test against name instead - dw_variable_t var = find_local_variable(subprogram, variable); + mc_variable_t var = find_local_variable(subprogram, variable); assert(var); void* frame_base = mc_find_frame_base(subprogram, info, cursor); s_mc_location_t location; mc_dwarf_resolve_locations(&location, - &var->locations, info, cursor, frame_base, NULL, -1); + &var->location_list, info, cursor, frame_base, NULL, -1); xbt_assert(mc_get_location_type(&location)==MC_LOCATION_TYPE_ADDRESS, "Unexpected location type for variable %s of %s", variable, function); @@ -83,16 +83,19 @@ static void test_local_variable(mc_object_info_t info, const char* function, con } -static dw_variable_t test_global_variable(mc_process_t process, mc_object_info_t info, const char* name, void* address, long byte_size) { +static mc_variable_t test_global_variable(mc_process_t process, mc_object_info_t info, const char* name, void* address, long byte_size) { - dw_variable_t variable = info->find_variable(name); + mc_variable_t variable = info->find_variable(name); xbt_assert(variable, "Global variable %s was not found", name); - xbt_assert(!strcmp(variable->name, name), "Name mismatch for %s", name); + xbt_assert(variable->name == name, + "Name mismatch for %s", name); xbt_assert(variable->global, "Variable %s is not global", name); xbt_assert(variable->address == address, - "Address mismatch for %s : %p expected but %p found", name, address, variable->address); + "Address mismatch for %s : %p expected but %p found", + name, address, variable->address); - mc_type_t type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, variable->type_origin); + mc_type_t type = (mc_type_t) xbt_dict_get_or_null( + process->binary_info->types, variable->type_id.c_str()); xbt_assert(type!=NULL, "Missing type for %s", name); xbt_assert(type->byte_size = byte_size, "Byte size mismatch for %s", name); return variable; @@ -118,7 +121,7 @@ int main(int argc, char** argv) { SIMIX_global_init(&argc, argv); - dw_variable_t var; + mc_variable_t var; mc_type_t type; s_mc_process_t p(getpid(), -1); @@ -129,12 +132,14 @@ int main(int argc, char** argv) var = test_global_variable(process, process->binary_info.get(), "test_some_array", &test_some_array, sizeof(test_some_array)); - type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin); + type = (mc_type_t) xbt_dict_get_or_null( + process->binary_info->types, var->type_id.c_str()); xbt_assert(type->element_count == 6*5*4, "element_count mismatch in test_some_array : %i / %i", type->element_count, 6*5*4); var = test_global_variable(process, process->binary_info.get(), "test_some_struct", &test_some_struct, sizeof(test_some_struct)); - type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin); + type = (mc_type_t) xbt_dict_get_or_null( + process->binary_info->types, var->type_id.c_str()); assert(find_member(process->binary_info.get(), "first", type)->offset() == 0); assert(find_member(process->binary_info.get(), "second", type)->offset() == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);