X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3ae4039533d80613612bb81524c164f33384df92..0f86d3285f605e43ba3f845eb2f5ee2502b2aed4:/src/mc/mc_process.cpp diff --git a/src/mc/mc_process.cpp b/src/mc/mc_process.cpp index e80715b5a2..fda88dd9ed 100644 --- a/src/mc/mc_process.cpp +++ b/src/mc/mc_process.cpp @@ -4,6 +4,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#define _FILE_OFFSET_BITS 64 + #include #include #include @@ -44,28 +46,31 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc, // ***** Helper stuff #define SO_RE "\\.so[\\.0-9]*$" -#define VERSION_RE "-[\\.0-9]*$" +#define VERSION_RE "-[\\.0-9-]*$" static const char *const FILTERED_LIBS[] = { - "libstdc++", + "ld", + "libbz2", + "libboost_context", + "libc", "libc++", - "libm", + "libcdt", + "libcgraph", + "libdl", + "libdw", + "libelf", "libgcc_s", + "liblua5.1", + "liblzma", + "libm", "libpthread", + "librt", + "libstdc++", "libunwind", "libunwind-x86_64", "libunwind-x86", "libunwind-ptrace", - "libdw", - "libdl", - "librt", - "liblzma", - "libelf", - "libbz2", - "libz", - "libelf", - "libc", - "ld" + "libz" }; static bool MC_is_simgrid_lib(const char* libname) @@ -106,12 +111,12 @@ static char* MC_get_lib_name(const char* pathname, struct s_mc_memory_map_re* re return libname; } -static ssize_t pread_whole(int fd, void *buf, size_t count, off_t offset) +static ssize_t pread_whole(int fd, void *buf, size_t count, std::uint64_t offset) { char* buffer = (char*) buf; ssize_t real_count = count; while (count) { - ssize_t res = pread(fd, buffer, count, offset); + ssize_t res = pread(fd, buffer, count, (std::int64_t) offset); if (res > 0) { count -= res; buffer += res; @@ -190,13 +195,13 @@ Process::Process(pid_t pid, int sockfd) Process* process = this; process->process_flags = MC_PROCESS_NO_FLAG; - process->socket = sockfd; - process->pid = pid; + process->socket_ = sockfd; + process->pid_ = pid; if (pid==getpid()) process->process_flags |= MC_PROCESS_SELF_FLAG; - process->running = true; - process->status = 0; - process->memory_map = MC_get_memory_map(pid); + process->running_ = true; + process->status_ = 0; + process->memory_map_ = get_memory_map(pid); process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE; process->heap = NULL; process->heap_info = NULL; @@ -206,14 +211,14 @@ Process::Process(pid_t pid, int sockfd) if (process->is_self()) process->memory_file = -1; else { - int fd = open_vm(process->pid, O_RDWR); + int fd = open_vm(process->pid_, O_RDWR); if (fd<0) xbt_die("Could not open file for process virtual address space"); process->memory_file = fd; } // 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) @@ -239,25 +244,18 @@ Process::~Process() { Process* process = this; - process->process_flags = MC_PROCESS_NO_FLAG; - process->pid = 0; + if (this->socket_ >= 0 && close(this->socket_) < 0) + xbt_die("Could not close communication socket"); - MC_free_memory_map(process->memory_map); - process->memory_map = NULL; + process->process_flags = MC_PROCESS_NO_FLAG; + process->pid_ = 0; - process->maestro_stack_start = NULL; - process->maestro_stack_end = NULL; + process->maestro_stack_start_ = nullptr; + process->maestro_stack_end_ = nullptr; 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) { - MC_free_object_info(&process->object_infos[i]); - } - free(process->object_infos); - process->object_infos = NULL; - process->object_infos_size = 0; if (process->memory_file >= 0) { close(process->memory_file); } @@ -323,10 +321,9 @@ void Process::refresh_malloc_info() void Process::init_memory_map_info() { XBT_DEBUG("Get debug information ..."); - this->maestro_stack_start = NULL; - this->maestro_stack_end = NULL; - this->object_infos = NULL; - this->object_infos_size = 0; + this->maestro_stack_start_ = nullptr; + this->maestro_stack_end_ = nullptr; + this->object_infos.resize(0); this->binary_info = NULL; this->libsimgrid_info = NULL; @@ -335,25 +332,27 @@ void Process::init_memory_map_info() if(regcomp(&res.so_re, SO_RE, 0) || regcomp(&res.version_re, VERSION_RE, 0)) xbt_die(".so regexp did not compile"); - memory_map_t maps = this->memory_map; + std::vector const& maps = this->memory_map_; const char* current_name = NULL; - for (ssize_t i=0; i < maps->mapsize; i++) { - map_region_t reg = &(maps->regions[i]); - const char* pathname = maps->regions[i].pathname; + 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(); // Nothing to do - if (maps->regions[i].pathname == NULL) { + if (maps[i].pathname.empty()) { current_name = NULL; continue; } // [stack], [vvar], [vsyscall], [vdso] ... if (pathname[0] == '[') { - if ((reg->prot & PROT_WRITE) && !memcmp(pathname, "[stack]", 7)) { - this->maestro_stack_start = reg->start_addr; - this->maestro_stack_end = reg->end_addr; + if ((reg.prot & PROT_WRITE) && !memcmp(pathname, "[stack]", 7)) { + this->maestro_stack_start_ = remote(reg.start_addr); + this->maestro_stack_end_ = remote(reg.end_addr); } current_name = NULL; continue; @@ -363,7 +362,7 @@ void Process::init_memory_map_info() continue; current_name = pathname; - if (!(reg->prot & PROT_READ) && (reg->prot & PROT_EXEC)) + if (!(reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)) continue; const bool is_executable = !i; @@ -378,12 +377,9 @@ void Process::init_memory_map_info() } } - mc_object_info_t 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++; + std::shared_ptr info = + MC_find_object_info(this->memory_map_, pathname, is_executable); + this->object_infos.push_back(info); if (is_executable) this->binary_info = info; else if (libname && MC_is_simgrid_lib(libname)) @@ -395,81 +391,71 @@ 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"); + xbt_assert(this->maestro_stack_start_, "Did not find maestro_stack_start"); + xbt_assert(this->maestro_stack_end_, "Did not find maestro_stack_end"); 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_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; - else - return MC_file_object_info_find_function(info, (void*) ip.address()); + std::shared_ptr info = this->find_object_info_exec(ip); + return info ? info->find_function((void*) ip.address()) : nullptr; } /** 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 { - 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; + mc_variable_t var = info->find_variable(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) { + mc_variable_t var = info->find_variable(name); if (var) return var; } @@ -479,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) @@ -495,7 +481,7 @@ char* Process::read_string(remote_ptr address) const if (!address) return NULL; if (this->is_self()) - return strdup((char*) address.address()); + return xbt_strdup((char*) address.address()); off_t len = 128; char* res = (char*) malloc(len); @@ -529,15 +515,27 @@ 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 (info.get() && info.get()->privatized()) { if (process_index < 0) xbt_die("Missing process index"); + if (process_index >= (int) MC_smpi_process_count()) + xbt_die("Invalid process index"); + + // Read smpi_privatisation_regions from MCed: + smpi_privatisation_region_t remote_smpi_privatisation_regions = + mc_model_checker->process().read_variable( + "smpi_privatisation_regions"); + + s_smpi_privatisation_region_t privatisation_region = + mc_model_checker->process().read( + remote(remote_smpi_privatisation_regions + process_index)); + // Address translation in the privaization segment: - // TODO, fix me (broken) size_t offset = address.address() - (std::uint64_t)info->start_rw; - address = remote(address.address() - offset); + address = remote((char*)privatisation_region.address + offset); } } @@ -549,8 +547,8 @@ const void *Process::read_bytes(void* buffer, std::size_t size, return buffer; } } else { - if (pread_whole(this->memory_file, buffer, size, (off_t) address.address()) < 0) - xbt_die("Read from process %lli failed", (long long) this->pid); + if (pread_whole(this->memory_file, buffer, size, address.address()) < 0) + xbt_die("Read from process %lli failed", (long long) this->pid_); return buffer; } } @@ -568,7 +566,7 @@ void Process::write_bytes(const void* buffer, size_t len, remote_ptr addre memcpy((void*)address.address(), buffer, len); } else { if (pwrite_whole(this->memory_file, buffer, len, address.address()) < 0) - xbt_die("Write to process %lli failed", (long long) this->pid); + xbt_die("Write to process %lli failed", (long long) this->pid_); } }