X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ffe8ce65fd9a8e18a0469f26f067c3ea6d5d60d4..f35db13138682b1be530a509d1eeadeafff84ca7:/src/mc/mc_unw.h diff --git a/src/mc/mc_unw.h b/src/mc/mc_unw.h index 267c850ca8..945fb4f657 100644 --- a/src/mc/mc_unw.h +++ b/src/mc/mc_unw.h @@ -1,14 +1,12 @@ -/* Copyright (c) 2015. The SimGrid Team. - -/ * All rights reserved. */ +/* Copyright (c) 2015-2017. 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. */ -#ifndef MC_UNW_H -#define MC_UNW_H +#ifndef SIMGRID_MC_UNW_H +#define SIMGRID_MC_UNW_H -/** \file +/** @file * Libunwind implementation for the model-checker * * Libunwind provides an pluggable stack unwinding API: the way the current @@ -17,7 +15,7 @@ * * This component implements the libunwind API for he model-checker: * - * * reading memory from a mc_address_space_t; + * * reading memory from a simgrid::mc::AddressSpace*; * * * reading stack registers from a saved snapshot (context). * @@ -27,56 +25,72 @@ * much here. */ -#include "mc_process.h" - -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 unw_accessors_t mc_unw_vmread_accessors; - -/** Virtual table for our `libunwind` implementation - * - * Stack unwinding on a `mc_process_t` (for memory, unwinding information) - * and `ucontext_t` (for processor registers). - * - * It works with the `s_mc_unw_context_t` context. - */ -extern unw_accessors_t mc_unw_accessors; - -// ***** Libunwind context - -/** A `libunwind` context - */ -typedef struct s_mc_unw_context { - mc_address_space_t address_space; - mc_process_t process; - unw_context_t context; -} s_mc_unw_context_t, *mc_unw_context_t; - -/** Initialises an already allocated context */ -int mc_unw_init_context( - mc_unw_context_t context, mc_process_t process, unw_context_t* c); - -/** Destroys (but not not `free`) a context */ -int mc_unw_destroy_context(mc_unw_context_t context); - -// ***** Libunwind cursor - -/** Initialises a `libunwind` cursor */ -int mc_unw_init_cursor(unw_cursor_t *cursor, mc_unw_context_t context); - -SG_END_DECL() +#include + +#include + +#include + +#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); + +} +} + +namespace simgrid { +namespace mc { + +class UnwindContext { + simgrid::mc::AddressSpace* addressSpace_ = nullptr; + simgrid::mc::Process* process_ = nullptr; + unw_context_t unwindContext_; +public: + UnwindContext() {} + ~UnwindContext() { clear(); } + void initialize(simgrid::mc::Process* process, unw_context_t* c); + void clear(); + unw_cursor_t cursor(); + +private: // Methods and virtual table for libunwind + static int find_proc_info(unw_addr_space_t as, + unw_word_t ip, unw_proc_info_t *pip, + int need_unwind_info, void* arg) noexcept; + static void put_unwind_info(unw_addr_space_t as, + unw_proc_info_t *pip, void* arg) noexcept; + static int get_dyn_info_list_addr(unw_addr_space_t as, + unw_word_t *dilap, void* arg) noexcept; + static int access_mem(unw_addr_space_t as, + unw_word_t addr, unw_word_t *valp, + int write, void* arg) noexcept; + static void* get_reg(unw_context_t* context, unw_regnum_t regnum) noexcept; + static int access_reg(unw_addr_space_t as, + unw_regnum_t regnum, unw_word_t *valp, + int write, void* arg) noexcept; + static int access_fpreg(unw_addr_space_t as, + unw_regnum_t regnum, unw_fpreg_t *fpvalp, + int write, void* arg) noexcept; + static int resume(unw_addr_space_t as, + unw_cursor_t *cp, void* arg) noexcept; + static int get_proc_name(unw_addr_space_t as, + unw_word_t addr, char *bufp, + size_t buf_len, unw_word_t *offp, + void* arg) noexcept; + static unw_accessors_t accessors; +public: + // Create a libunwind address space: + static unw_addr_space_t createUnwindAddressSpace(); +}; + +void MC_dump_stack_unw(FILE* file, unw_cursor_t cursor); +void dumpStack(FILE* file, unw_cursor_t cursor); +void dumpStack(FILE* file, pid_t pid); + +} +} #endif