From: Gabriel Corona Date: Mon, 20 Jul 2015 09:14:41 +0000 (+0200) Subject: [mc] OOPify/C++ify Type (cont) X-Git-Tag: v3_12~438^2~37 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/deaddec5dc5d4dda8dc1b9692869970e253facfa [mc] OOPify/C++ify Type (cont) Make location expression a std::vector. --- diff --git a/src/mc/mc_diff.cpp b/src/mc/mc_diff.cpp index b3940c2a55..7e3bb37fd1 100644 --- a/src/mc/mc_diff.cpp +++ b/src/mc/mc_diff.cpp @@ -1108,9 +1108,9 @@ static mc_type_t get_offset_type(void *real_base_address, mc_type_t type, mc_type_t member; xbt_dynar_foreach(type->members, cursor, member) { - if (!member->location.size) { + if (member->has_offset_location()) { // We have the offset, use it directly (shortcut): - if (member->offset == offset) + if (member->offset() == offset) return member->subtype; } else { void *real_member = diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index 7bdc76ef88..ea43d50626 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -496,11 +496,7 @@ static void MC_dwarf_fill_member_location(mc_type_t type, mc_type_t member, PRIx64 ">%s", MC_dwarf_attr_integrate_string(child, DW_AT_name), (uint64_t) type->id, type->name.c_str()); } - if (len == 1 && expr[0].atom == DW_OP_plus_uconst) { - member->offset = expr[0].number; - } else { - mc_dwarf_expression_init(&member->location, len, expr); - } + simgrid::mc::DwarfExpression(expr, expr+len); break; } case MC_DW_CLASS_CONSTANT: @@ -508,7 +504,7 @@ static void MC_dwarf_fill_member_location(mc_type_t type, mc_type_t member, { Dwarf_Word offset; if (!dwarf_formudata(&attr, &offset)) - member->offset = offset; + member->offset(offset); else xbt_die("Cannot get %s location <%" PRIx64 ">%s", MC_dwarf_attr_integrate_string(child, DW_AT_name), diff --git a/src/mc/mc_location.h b/src/mc/mc_location.h index d6f6fe435d..1bafe6c5bd 100644 --- a/src/mc/mc_location.h +++ b/src/mc/mc_location.h @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -18,6 +20,14 @@ #include "mc_forward.h" #include "AddressSpace.hpp" +namespace simgrid { +namespace mc { + +typedef std::vector DwarfExpression; + +} +} + SG_BEGIN_DECL() /** \brief a DWARF expression with optional validity contraints */ @@ -115,4 +125,17 @@ MC_SHOULD_BE_INTERNAL void* mc_find_frame_base( SG_END_DECL() +namespace simgrid { +namespace mc { + +inline +int execute(DwarfExpression const& expression, mc_expression_state_t state) +{ + return mc_dwarf_execute_expression( + expression.size(), expression.data(), state); +} + +} +} + #endif diff --git a/src/mc/mc_member.cpp b/src/mc/mc_member.cpp index 1fde63e5c2..b96a30fbb6 100644 --- a/src/mc/mc_member.cpp +++ b/src/mc/mc_member.cpp @@ -20,9 +20,9 @@ void *mc_member_resolve(const void *base, mc_type_t type, mc_type_t member, mc_address_space_t address_space, int process_index) { - if (!member->location.size) { - return ((char *) base) + member->offset; - } + // TODO, get rid of this? + if (!member->has_offset_location()) + return ((char *) base) + member->offset(); s_mc_expression_state_t state; memset(&state, 0, sizeof(s_mc_expression_state_t)); @@ -33,8 +33,8 @@ void *mc_member_resolve(const void *base, mc_type_t type, mc_type_t member, state.stack[0] = (uintptr_t) base; state.process_index = process_index; - if (mc_dwarf_execute_expression - (member->location.size, member->location.ops, &state)) + if (simgrid::mc::execute( + member->location_expression, &state)) xbt_die("Error evaluating DWARF expression"); if (state.stack_size == 0) xbt_die("No value on the stack"); diff --git a/src/mc/mc_object_info.cpp b/src/mc/mc_object_info.cpp index 67e4d353dd..8301068fd8 100644 --- a/src/mc/mc_object_info.cpp +++ b/src/mc/mc_object_info.cpp @@ -20,13 +20,10 @@ Type::Type() { this->type = 0; this->id = 0; - this->name = std::string(); this->byte_size = 0; this->element_count = 0; this->members = nullptr; this->is_pointer_type = 0; - this->location = {0, 0, 0, 0}; - this->offset = 0; this->subtype = nullptr; this->full_type = nullptr; } @@ -34,7 +31,6 @@ Type::Type() Type::~Type() { xbt_dynar_free(&this->members); - mc_dwarf_expression_clear(&this->location); } // ObjectInformations diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index 553bee152e..9dbbf53a96 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -19,6 +19,8 @@ #include #include +#include + #include "mc_forward.h" #include "mc_location.h" #include "mc_process.h" @@ -31,6 +33,10 @@ typedef int e_mc_type_type; namespace simgrid { namespace mc { +/** Represents a type in the program + * + * It is currently used to represent members of structs and unions as well. + */ class Type { public: Type(); @@ -48,11 +54,31 @@ public: int is_pointer_type; // Location (for members) is either of: - struct s_mc_expression location; - int offset; + simgrid::mc::DwarfExpression location_expression; mc_type_t subtype; // DW_AT_type mc_type_t full_type; // The same (but more complete) type + + bool has_offset_location() const + { + return location_expression.size() == 1 && + location_expression[0].atom == DW_OP_plus_uconst; + } + + // TODO, check if this shortcut is really necessary + int offset() const + { + xbt_assert(this->has_offset_location()); + return this->location_expression[0].number; + } + + void offset(int new_offset) + { + Dwarf_Op op; + op.atom = DW_OP_plus_uconst; + op.number = new_offset; + this->location_expression = { op }; + } }; } diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index cf95adfece..399795add7 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -136,8 +136,8 @@ int main(int argc, char** argv) 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); - assert(find_member(process->binary_info.get(), "first", type)->offset == 0); - assert(find_member(process->binary_info.get(), "second", type)->offset + 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); unw_context_t context;