From: Gabriel Corona Date: Mon, 14 Mar 2016 10:38:16 +0000 (+0100) Subject: [mc] Move process_vm_readv-based implementation of libunwind in simgrid::mc X-Git-Tag: v3_13~428^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a0abc19be8f29dbf8bd64487b4a3dee7f8501b48 [mc] Move process_vm_readv-based implementation of libunwind in simgrid::mc --- diff --git a/src/mc/Process.cpp b/src/mc/Process.cpp index 1c003948d2..613eec4f8b 100644 --- a/src/mc/Process.cpp +++ b/src/mc/Process.cpp @@ -227,8 +227,9 @@ void Process::init() this->smx_process_infos.clear(); this->smx_old_process_infos.clear(); this->unw_addr_space = unw_create_addr_space(&mc_unw_accessors , __BYTE_ORDER); - this->unw_underlying_addr_space = unw_create_addr_space(&mc_unw_vmread_accessors, __BYTE_ORDER); - this->unw_underlying_context = _UPT_create(this->pid_); + this->unw_underlying_addr_space = simgrid::unw::create_addr_space(); + this->unw_underlying_context = simgrid::unw::create_context( + this->unw_underlying_addr_space, this->pid_); } Process::~Process() diff --git a/src/mc/mc_unw.h b/src/mc/mc_unw.h index 3470bd8580..d27fbd1ce9 100644 --- a/src/mc/mc_unw.h +++ b/src/mc/mc_unw.h @@ -26,29 +26,27 @@ * much here. */ +#include + #include #include -#include "src/mc/Process.hpp" +#include "src/mc/mc_forward.hpp" + +namespace simgrid { +namespace unw { + +XBT_PRIVATE unw_addr_space_t create_addr_space(); +XBT_PRIVATE void* create_context(unw_addr_space_t as, pid_t pid); + +} +} SG_BEGIN_DECL() // ***** Libunwind namespace -/** 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 behaviour (privatisation, snapshots) - * and `ucontext_t`. - * - * It works with `void*` contexts allocated with `_UPT_create(pid)`. - */ -extern XBT_PRIVATE unw_accessors_t mc_unw_vmread_accessors; - /** Virtual table for our `libunwind` implementation * * Stack unwinding on a `simgrid::mc::Process*` (for memory, unwinding information) diff --git a/src/mc/mc_unw_vmread.cpp b/src/mc/mc_unw_vmread.cpp index 29b015be8f..7082dd3849 100644 --- a/src/mc/mc_unw_vmread.cpp +++ b/src/mc/mc_unw_vmread.cpp @@ -11,10 +11,9 @@ #include #include +#include "src/mc/Process.hpp" #include "src/mc/mc_unw.h" -extern "C" { - /** \file * Libunwind namespace implementation using process_vm_readv. *. @@ -23,9 +22,9 @@ extern "C" { /** Partial structure of libunwind-ptrace context in order to get the PID * - * The context type for libunwind-race is an opaque type. We need to get the - * PID which is the first field. This is a hack which might break if the - * libunwind-ptrace structure changes. + * HACK, The context type for libunwind-race is an opaque type. + * We need to get the PID which is the first field. This is a hack + * which might break if the libunwind-ptrace structure changes. */ struct _UPT_info { pid_t pid; @@ -101,16 +100,42 @@ static int access_mem(const unw_addr_space_t as, return _UPT_access_mem(as, addr, valp, write, arg); } -unw_accessors_t mc_unw_vmread_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 { +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 behaviour (privatisation, 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 +}; + +unw_addr_space_t create_addr_space() +{ + return unw_create_addr_space(&accessors, __BYTE_ORDER); +} + +void* create_context(unw_addr_space_t as, pid_t pid) +{ + return _UPT_create(pid); +} } +} \ No newline at end of file