From: Gabriel Corona Date: Mon, 8 Jun 2015 23:23:01 +0000 (+0200) Subject: [mc] Make Process:object_infos a srd::vector of std::shared_ptr X-Git-Tag: v3_12~638^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/aa7c7f8010d855deb98bd45b5e80e702277c8d8b [mc] Make Process:object_infos a srd::vector of std::shared_ptr --- diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 37aa48a756..32f3f99b52 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -157,13 +157,15 @@ static void MC_snapshot_add_region(int index, mc_snapshot_t snapshot, static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot) { - const size_t n = process->object_infos_size; + const size_t n = process->object_infos.size(); snapshot->snapshot_regions.resize(n + 1); - for (size_t i = 0; i != n; ++i) { - mc_object_info_t object_info = process->object_infos[i]; - MC_snapshot_add_region(i, snapshot, simgrid::mc::RegionType::Data, object_info, + int i = 0; + for (auto const& object_info : process->object_infos) { + MC_snapshot_add_region(i, snapshot, simgrid::mc::RegionType::Data, + object_info.get(), object_info->start_rw, object_info->start_rw, object_info->end_rw - object_info->start_rw); + ++i; } xbt_mheap_t heap = process->get_heap(); diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index f2c702eca4..67bb0e3ee5 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -1281,20 +1281,21 @@ static void MC_post_process_types(mc_object_info_t info) } /** \brief Finds informations about a given shared object/executable */ -mc_object_info_t MC_find_object_info( +std::shared_ptr MC_find_object_info( std::vector const& maps, const char *name, int executable) { - mc_object_info_t result = new s_mc_object_info_t(); + std::shared_ptr result = + std::make_shared(); if (executable) result->flags |= MC_OBJECT_INFO_EXECUTABLE; result->file_name = xbt_strdup(name); - MC_find_object_address(maps, result); - MC_dwarf_get_variables(result); - MC_post_process_types(result); - MC_post_process_variables(result); - MC_post_process_functions(result); - MC_make_functions_index(result); - return result; + MC_find_object_address(maps, result.get()); + MC_dwarf_get_variables(result.get()); + MC_post_process_types(result.get()); + MC_post_process_variables(result.get()); + MC_post_process_functions(result.get()); + MC_make_functions_index(result.get()); + return std::move(result); } /*************************************************************************/ @@ -1397,9 +1398,9 @@ void MC_post_process_object_info(mc_process_t process, mc_object_info_t info) // Resolve full_type: if (subtype->name && subtype->byte_size == 0) { - for (size_t i = 0; i != process->object_infos_size; ++i) { + for (auto const& object_info : process->object_infos) { dw_type_t same_type = (dw_type_t) - xbt_dict_get_or_null(process->object_infos[i]->full_types_by_name, + xbt_dict_get_or_null(object_info->full_types_by_name, subtype->name); if (same_type && same_type->name && same_type->byte_size) { type->full_type = same_type; diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index 4c02bca005..3b1f60a8c0 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -115,7 +115,7 @@ bool MC_object_info_is_privatized(mc_object_info_t info) */ XBT_INTERNAL void* MC_object_base_address(mc_object_info_t info); -XBT_INTERNAL mc_object_info_t MC_find_object_info( +XBT_INTERNAL std::shared_ptr MC_find_object_info( std::vector const& maps, const char* name, int executable); XBT_INTERNAL void MC_free_object_info(mc_object_info_t* p); diff --git a/src/mc/mc_process.cpp b/src/mc/mc_process.cpp index de73e05729..381d55b60e 100644 --- a/src/mc/mc_process.cpp +++ b/src/mc/mc_process.cpp @@ -252,14 +252,6 @@ Process::~Process() xbt_dynar_free(&process->smx_process_infos); xbt_dynar_free(&process->smx_old_process_infos); - size_t i; - for (i=0; i!=process->object_infos_size; ++i) { - delete process->object_infos[i]; - process->object_infos[i] = nullptr; - } - free(process->object_infos); - process->object_infos = NULL; - process->object_infos_size = 0; if (process->memory_file >= 0) { close(process->memory_file); } @@ -327,8 +319,7 @@ void Process::init_memory_map_info() XBT_DEBUG("Get debug information ..."); this->maestro_stack_start_ = nullptr; this->maestro_stack_end_ = nullptr; - this->object_infos = NULL; - this->object_infos_size = 0; + this->object_infos.resize(0); this->binary_info = NULL; this->libsimgrid_info = NULL; @@ -341,6 +332,8 @@ void Process::init_memory_map_info() const char* current_name = NULL; + this->object_infos.resize(0); + for (size_t i=0; i < maps.size(); i++) { simgrid::mc::VmMap const& reg = maps[i]; const char* pathname = maps[i].pathname.c_str(); @@ -380,12 +373,9 @@ void Process::init_memory_map_info() } } - mc_object_info_t info = + std::shared_ptr info = MC_find_object_info(this->memory_map_, pathname, is_executable); - this->object_infos = (mc_object_info_t*) realloc(this->object_infos, - (this->object_infos_size+1) * sizeof(mc_object_info_t)); - this->object_infos[this->object_infos_size] = info; - this->object_infos_size++; + this->object_infos.push_back(info); if (is_executable) this->binary_info = info; else if (libname && MC_is_simgrid_lib(libname)) @@ -397,8 +387,8 @@ void Process::init_memory_map_info() regfree(&res.version_re); // Resolve time (including accross differents objects): - for (size_t i=0; i!=this->object_infos_size; ++i) - MC_post_process_object_info(this, this->object_infos[i]); + for (auto const& object_info : this->object_infos) + MC_post_process_object_info(this, object_info.get()); xbt_assert(this->maestro_stack_start_, "Did not find maestro_stack_start"); xbt_assert(this->maestro_stack_end_, "Did not find maestro_stack_end"); @@ -406,72 +396,65 @@ void Process::init_memory_map_info() XBT_DEBUG("Get debug information done !"); } -mc_object_info_t Process::find_object_info(remote_ptr addr) const +std::shared_ptr Process::find_object_info(remote_ptr addr) const { - size_t i; - for (i = 0; i != this->object_infos_size; ++i) { - if (addr.address() >= (std::uint64_t)this->object_infos[i]->start - && addr.address() <= (std::uint64_t)this->object_infos[i]->end) { - return this->object_infos[i]; + for (auto const& object_info : this->object_infos) { + if (addr.address() >= (std::uint64_t)object_info->start + && addr.address() <= (std::uint64_t)object_info->end) { + return object_info; } } return NULL; } -mc_object_info_t Process::find_object_info_exec(remote_ptr addr) const +std::shared_ptr Process::find_object_info_exec(remote_ptr addr) const { - size_t i; - for (i = 0; i != this->object_infos_size; ++i) { - if (addr.address() >= (std::uint64_t)this->object_infos[i]->start_exec - && addr.address() <= (std::uint64_t)this->object_infos[i]->end_exec) { - return this->object_infos[i]; + for (std::shared_ptr const& info : this->object_infos) { + if (addr.address() >= (std::uint64_t) info->start_exec + && addr.address() <= (std::uint64_t) info->end_exec) { + return info; } } - return NULL; + return nullptr; } -mc_object_info_t Process::find_object_info_rw(remote_ptr addr) const +std::shared_ptr Process::find_object_info_rw(remote_ptr addr) const { - size_t i; - for (i = 0; i != this->object_infos_size; ++i) { - if (addr.address() >= (std::uint64_t)this->object_infos[i]->start_rw - && addr.address() <= (std::uint64_t)this->object_infos[i]->end_rw) { - return this->object_infos[i]; + for (std::shared_ptr const& info : this->object_infos) { + if (addr.address() >= (std::uint64_t)info->start_rw + && addr.address() <= (std::uint64_t)info->end_rw) { + return info; } } - return NULL; + return nullptr; } dw_frame_t Process::find_function(remote_ptr ip) const { - mc_object_info_t info = this->find_object_info_exec(ip); - if (info == NULL) - return NULL; + std::shared_ptr info = this->find_object_info_exec(ip); + if (!info) + return nullptr; else - return MC_file_object_info_find_function(info, (void*) ip.address()); + return MC_file_object_info_find_function(info.get(), (void*) ip.address()); } /** Find (one occurence of) the named variable definition */ dw_variable_t Process::find_variable(const char* name) const { - const size_t n = this->object_infos_size; - size_t i; - // First lookup the variable in the executable shared object. // A global variable used directly by the executable code from a library // is reinstanciated in the executable memory .data/.bss. // We need to look up the variable in the execvutable first. if (this->binary_info) { - mc_object_info_t info = this->binary_info; - dw_variable_t var = MC_file_object_info_find_variable_by_name(info, name); + std::shared_ptr const& info = this->binary_info; + dw_variable_t var = MC_file_object_info_find_variable_by_name(info.get(), name); if (var) return var; } - for (i=0; i!=n; ++i) { - mc_object_info_t info = this->object_infos[i]; - dw_variable_t var = MC_file_object_info_find_variable_by_name(info, name); + for (std::shared_ptr const& info : this->object_infos) { + dw_variable_t var = MC_file_object_info_find_variable_by_name(info.get(), name); if (var) return var; } @@ -531,9 +514,10 @@ const void *Process::read_bytes(void* buffer, std::size_t size, AddressSpace::ReadMode mode) const { if (process_index != simgrid::mc::ProcessIndexDisabled) { - mc_object_info_t info = this->find_object_info_rw((void*)address.address()); + std::shared_ptr const& info = + this->find_object_info_rw((void*)address.address()); // Segment overlap is not handled. - if (MC_object_info_is_privatized(info)) { + if (MC_object_info_is_privatized(info.get())) { if (process_index < 0) xbt_die("Missing process index"); if (process_index >= (int) MC_smpi_process_count()) diff --git a/src/mc/mc_process.h b/src/mc/mc_process.h index a453d464aa..e3513b7739 100644 --- a/src/mc/mc_process.h +++ b/src/mc/mc_process.h @@ -12,6 +12,7 @@ #include #include +#include #include "simgrid_config.h" #include @@ -87,9 +88,9 @@ public: void clear_bytes(remote_ptr address, size_t len); // Debug information: - mc_object_info_t find_object_info(remote_ptr addr) const; - mc_object_info_t find_object_info_exec(remote_ptr addr) const; - mc_object_info_t find_object_info_rw(remote_ptr addr) const; + std::shared_ptr find_object_info(remote_ptr addr) const; + 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; @@ -172,10 +173,9 @@ private: public: // object info // TODO, make private (first, objectify mc_object_info_t) - mc_object_info_t libsimgrid_info; - mc_object_info_t binary_info; - mc_object_info_t* object_infos; - size_t object_infos_size; + std::vector> object_infos; + std::shared_ptr libsimgrid_info; + std::shared_ptr binary_info; public: // Copies of MCed SMX data structures /** Copy of `simix_global->process_list` diff --git a/src/mc/mcer_ignore.cpp b/src/mc/mcer_ignore.cpp index 55b56d022c..ed25728772 100644 --- a/src/mc/mcer_ignore.cpp +++ b/src/mc/mcer_ignore.cpp @@ -112,11 +112,9 @@ void MC_heap_region_ignore_remove(void *address, size_t size) void MCer_ignore_global_variable(const char *name) { mc_process_t process = &mc_model_checker->process(); - xbt_assert(process->object_infos, "MC subsystem not initialized"); + xbt_assert(!process->object_infos.empty(), "MC subsystem not initialized"); - size_t n = process->object_infos_size; - for (size_t i=0; i!=n; ++i) { - mc_object_info_t info = process->object_infos[i]; + for (std::shared_ptr const& info : process->object_infos) { // Binary search: int start = 0; @@ -155,11 +153,8 @@ void MC_ignore_local_variable(const char *var_name, const char *frame_name) if (strcmp(frame_name, "*") == 0) frame_name = NULL; - size_t n = process->object_infos_size; - size_t i; - for (i=0; i!=n; ++i) { - MC_ignore_local_variable_in_object(var_name, frame_name, process->object_infos[i]); - } + for (std::shared_ptr const& info : process->object_infos) + MC_ignore_local_variable_in_object(var_name, frame_name, info.get()); } static void MC_ignore_local_variable_in_object(const char *var_name, diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index 36e6a7ec40..5c07416324 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -128,16 +128,19 @@ int main(int argc, char** argv) s_mc_process_t p(getpid(), -1); mc_process_t process = &p; - test_global_variable(process, process->binary_info, "some_local_variable", &some_local_variable, sizeof(int)); + test_global_variable(process, process->binary_info.get(), + "some_local_variable", &some_local_variable, sizeof(int)); - var = test_global_variable(process, process->binary_info, "test_some_array", &test_some_array, sizeof(test_some_array)); + var = test_global_variable(process, process->binary_info.get(), + "test_some_array", &test_some_array, sizeof(test_some_array)); type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin); 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, "test_some_struct", &test_some_struct, sizeof(test_some_struct)); + var = test_global_variable(process, process->binary_info.get(), + "test_some_struct", &test_some_struct, sizeof(test_some_struct)); type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin); - assert(find_member(process->binary_info, "first", type)->offset == 0); - assert(find_member(process->binary_info, "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; @@ -145,11 +148,12 @@ int main(int argc, char** argv) unw_getcontext(&context); unw_init_local(&cursor, &context); - test_local_variable(process->binary_info, "main", "argc", &argc, &cursor); + test_local_variable(process->binary_info.get(), "main", "argc", &argc, &cursor); { int lexical_block_variable = 50; - test_local_variable(process->binary_info, "main", "lexical_block_variable", &lexical_block_variable, &cursor); + test_local_variable(process->binary_info.get(), "main", + "lexical_block_variable", &lexical_block_variable, &cursor); } s_foo my_foo;