From 1b98995f4b33aa88c1ae66e20fe3669c2b2dfabf Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 11 Jun 2019 22:43:26 +0200 Subject: [PATCH] MC: cosmetics --- src/mc/Session.cpp | 3 ++- src/mc/inspect/mc_unw_vmread.cpp | 22 +++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index 5d00dbc95c..a5721e3e46 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -76,10 +76,11 @@ Session::Session(const std::function& code) // Parent (model-checker): ::close(sockets[0]); + xbt_assert(mc_model_checker == nullptr, "Did you manage to start the MC twice in this process?"); + std::unique_ptr process(new simgrid::mc::RemoteClient(pid, sockets[1])); model_checker_.reset(new simgrid::mc::ModelChecker(std::move(process))); - xbt_assert(mc_model_checker == nullptr); mc_model_checker = model_checker_.get(); mc_model_checker->start(); } diff --git a/src/mc/inspect/mc_unw_vmread.cpp b/src/mc/inspect/mc_unw_vmread.cpp index 1b52e68ca4..5f2acba289 100644 --- a/src/mc/inspect/mc_unw_vmread.cpp +++ b/src/mc/inspect/mc_unw_vmread.cpp @@ -36,8 +36,7 @@ static inline pid_t _UPT_getpid(void* arg) return info->pid; } -/** Read from the memory, avoid using `ptrace` (libunwind method) - */ +/** Read from the memory, avoid using `ptrace` (libunwind method) */ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word_t* const valp, const int write, void* const arg) { @@ -46,7 +45,7 @@ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word pid_t pid = _UPT_getpid(arg); size_t size = sizeof(unw_word_t); -#if HAVE_PROCESS_VM_READV +#if HAVE_PROCESS_VM_READV /* linux but not freebsd */ // process_vm_read implementation. // This is only available since Linux 3.2. @@ -72,27 +71,24 @@ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word int fd = simgrid::mc::open_vm(pid, O_RDONLY); if (fd < 0) return -UNW_EINVAL; - while (1) { + + while (count > 0) { ssize_t nread = pread(fd, buf, count, off); if (nread == 0) { close(fd); return -UNW_EINVAL; } if (nread == -1) - break; + // ptrace implementation. + // We need to have PTRACE_ATTACH-ed it before. + return _UPT_access_mem(as, addr, valp, write, arg); + count -= nread; buf += nread; off += nread; - if (count == 0) { - close(fd); - return 0; - } } close(fd); - - // ptrace implementation. - // We need to have PTRACE_ATTACH-ed it before. - return _UPT_access_mem(as, addr, valp, write, arg); + return 0; } namespace simgrid { -- 2.20.1