X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/40334ce6fe520b2fa7d1e240716e4f34a5fdc74e..6e1633c43c1a58d11116dff425e13abb49b2162c:/src/mc/mc_object_info.cpp diff --git a/src/mc/mc_object_info.cpp b/src/mc/mc_object_info.cpp index 95f9e2a952..3d3703c3c6 100644 --- a/src/mc/mc_object_info.cpp +++ b/src/mc/mc_object_info.cpp @@ -11,38 +11,150 @@ #include "mc_object_info.h" #include "mc_private.h" -extern "C" { +namespace simgrid { +namespace mc { -dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip) +// Free functions + +static void mc_frame_free(void* frame) +{ + delete (simgrid::mc::Frame*)frame; +} + +static void mc_type_free(void* t) +{ + delete (simgrid::mc::Type*)t; +} + +// Type + +Type::Type() +{ + this->type = 0; + this->id = 0; + this->byte_size = 0; + this->element_count = 0; + this->is_pointer_type = 0; + this->type_id = 0; + this->subtype = nullptr; + this->full_type = nullptr; +} + +// Type + +Variable::Variable() +{ + this->dwarf_offset = 0; + this->global = 0; + this->type = nullptr; + this->type_id = 0; + this->address = nullptr; + this->start_scope = 0; + this->object_info = nullptr; +} + +// Frame + +Frame::Frame() { - xbt_dynar_t dynar = info->functions_index; - mc_function_index_item_t base = - (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0); + this->tag = 0; + this->low_pc = nullptr; + this->high_pc = nullptr; + this->id = 0; + this->abstract_origin_id = 0; + this->object_info = nullptr; +} + +// ObjectInformations + +ObjectInformation::ObjectInformation() +{ + this->flags = 0; + this->start = nullptr; + this->end = nullptr; + this->start_exec = nullptr; + this->end_exec = nullptr; + this->start_rw = nullptr; + this->end_rw = nullptr; + this->start_ro = nullptr; + this->end_ro = nullptr; +} + +/** Find the DWARF offset for this ELF object + * + * An offset is applied to address found in DWARF: + * + * * for an executable obejct, addresses are virtual address + * (there is no offset) i.e. + * \f$\text{virtual address} = \{dwarf address}\f$; + * + * * for a shared object, the addreses are offset from the begining + * of the shared object (the base address of the mapped shared + * object must be used as offset + * i.e. \f$\text{virtual address} = \text{shared object base address} + * + \text{dwarf address}\f$. + */ +void *ObjectInformation::base_address() const +{ + if (this->executable()) + return nullptr; + + void *result = this->start_exec; + if (this->start_rw != NULL && result > (void *) this->start_rw) + result = this->start_rw; + if (this->start_ro != NULL && result > (void *) this->start_ro) + result = this->start_ro; + return result; +} + +/* Find a function by instruction pointer */ +simgrid::mc::Frame* ObjectInformation::find_function(const void *ip) const +{ + /* This is implemented by binary search on a sorted array. + * + * We do quite a lot ot those so we want this to be cache efficient. + * We pack the only information we need in the index entries in order + * to successfully do the binary search. We do not need the high_pc + * during the binary search (only at the end) so it is not included + * in the index entry. We could use parallel arrays as well. + * + * We cannot really use the std:: alogrithm for this. + * We could use std::binary_search by including the high_pc inside + * the FunctionIndexEntry. + */ + const simgrid::mc::FunctionIndexEntry* base = + this->functions_index.data(); int i = 0; - int j = xbt_dynar_length(dynar) - 1; + int j = this->functions_index.size() - 1; while (j >= i) { int k = i + ((j - i) / 2); - if (ip < base[k].low_pc) { + + /* In most of the search, we do not dereference the base[k].function. + * This way the memory accesses are located in the base[k] array. */ + if (ip < base[k].low_pc) j = k - 1; - } else if (ip >= base[k].high_pc) { + else if (k < j && ip >= base[k + 1].low_pc) i = k + 1; - } else { + + /* At this point, the search is over. + * Either we have found the correct function or we do not know + * any function corresponding to this instruction address. + * Only at the point do we derefernce the function pointer. */ + else if (ip < base[k].function->high_pc) return base[k].function; - } + else + return nullptr; } - return NULL; + return nullptr; } -dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, const char* name) +simgrid::mc::Variable* ObjectInformation::find_variable(const char* name) const { - unsigned int cursor = 0; - dw_variable_t variable; - xbt_dynar_foreach(info->global_variables, cursor, variable){ - if(!strcmp(name, variable->name)) - return variable; - } - - return NULL; + for (simgrid::mc::Variable& variable : this->global_variables) + if(variable.name == name) + return &variable; + return nullptr; } } +} \ No newline at end of file