X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8dc7e6f4409d5d9f262ebb319eda835a78ef1bc4..5f2e051a9bb2b088d3b3543982d3a244b7b7b1c4:/src/mc/inspect/mc_unw_vmread.cpp diff --git a/src/mc/inspect/mc_unw_vmread.cpp b/src/mc/inspect/mc_unw_vmread.cpp index 8bd6292092..671fccd1dd 100644 --- a/src/mc/inspect/mc_unw_vmread.cpp +++ b/src/mc/inspect/mc_unw_vmread.cpp @@ -1,10 +1,12 @@ -/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved. */ +/** \file Libunwind namespace implementation using process_vm_readv. */ + +/* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved. */ /* 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. */ #include "src/mc/inspect/mc_unw.hpp" -#include "src/mc/remote/RemoteSimulation.hpp" +#include "src/mc/remote/RemoteProcess.hpp" #include #include @@ -13,9 +15,6 @@ #include #include -/** \file - * Libunwind namespace implementation using process_vm_readv. - */ /** Partial structure of libunwind-ptrace context in order to get the PID * @@ -28,21 +27,13 @@ struct _UPT_info { // Other things... }; -/** Get the PID of a `libunwind-ptrace` context - */ -static inline pid_t _UPT_getpid(void* arg) -{ - const _UPT_info* info = static_cast<_UPT_info*>(arg); - return info->pid; -} - /** 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) { if (write) return -UNW_EINVAL; - pid_t pid = _UPT_getpid(arg); + pid_t pid = static_cast<_UPT_info*>(arg)->pid; size_t size = sizeof(unw_word_t); #if HAVE_PROCESS_VM_READV /* linux but not freebsd */ @@ -51,8 +42,7 @@ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word struct iovec local = {valp, size}; struct iovec remote = {(void*)addr, size}; - ssize_t s = process_vm_readv(pid, &local, 1, &remote, 1, 0); - if (s >= 0) { + if (ssize_t s = process_vm_readv(pid, &local, 1, &remote, 1, 0); s >= 0) { if ((size_t)s != size) return -UNW_EINVAL; else @@ -91,28 +81,26 @@ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word return 0; } -namespace simgrid { -namespace unw { - -/** Virtual table for our `libunwind-process_vm_readv` implementation. - * - * This implementation reuse most the code of `libunwind-ptrace` but - * does not use ptrace() to read the target process memory by - * `process_vm_readv()` or `/dev/${pid}/mem` if possible. - * - * Does not support any MC-specific behavior (privatization, snapshots) - * and `ucontext_t`. - * - * It works with `void*` contexts allocated with `_UPT_create(pid)`. - */ -// TODO, we could get rid of this if we properly stop the model-checked -// process before reading the memory. -static unw_accessors_t accessors = {&_UPT_find_proc_info, &_UPT_put_unwind_info, &_UPT_get_dyn_info_list_addr, - &access_mem, &_UPT_access_reg, &_UPT_access_fpreg, - &_UPT_resume, &_UPT_get_proc_name}; +namespace simgrid::unw { unw_addr_space_t create_addr_space() { + /** Virtual table for our `libunwind-process_vm_readv` implementation. + * + * This implementation reuse most the code of `libunwind-ptrace` but + * does not use ptrace() to read the target process memory by + * `process_vm_readv()` or `/dev/${pid}/mem` if possible. + * + * Does not support any MC-specific behavior (privatization, snapshots) + * and `ucontext_t`. + * + * It works with `void*` contexts allocated with `_UPT_create(pid)`. + */ + // TODO, we could get rid of this if we properly stop the model-checked + // process before reading the memory. + unw_accessors_t accessors = {&_UPT_find_proc_info, &_UPT_put_unwind_info, &_UPT_get_dyn_info_list_addr, + &access_mem, &_UPT_access_reg, &_UPT_access_fpreg, + &_UPT_resume, &_UPT_get_proc_name}; return unw_create_addr_space(&accessors, BYTE_ORDER); } @@ -121,5 +109,4 @@ void* create_context(unw_addr_space_t /*as*/, pid_t pid) return _UPT_create(pid); } -} // namespace unw -} // namespace simgrid +} // namespace simgrid::unw