Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[simgrid.git] / src / mc / mc_unw.h
1 /* Copyright (c) 2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_UNW_H
8 #define SIMGRID_MC_UNW_H
9
10 /** \file
11  *  Libunwind implementation for the model-checker
12  *
13  *  Libunwind provides an pluggable stack unwinding API: the way the current
14  *  registers and memory is accessed, the way unwinding informations is found
15  *  is pluggable.
16  *
17  *  This component implements the libunwind API for he model-checker:
18  *
19  *    * reading memory from a simgrid::mc::AddressSpace*;
20  *
21  *    * reading stack registers from a saved snapshot (context).
22  *
23  *  Parts of the libunwind information fetching is currently handled by the
24  *  standard `libunwind` implementations (either the local one or the ptrace one)
25  *  because parsing `.eh_frame` section is not fun and `libdw` does not help
26  *  much here.
27  */
28
29 #include <xbt/base.h>
30
31 #include "src/mc/Process.hpp"
32
33 SG_BEGIN_DECL()
34
35 // ***** Libunwind namespace
36
37 /** Virtual table for our `libunwind-process_vm_readv` implementation.
38  *
39  *  This implementation reuse most the code of `libunwind-ptrace` but
40  *  does not use ptrace() to read the target process memory by
41  *  `process_vm_readv()` or `/dev/${pid}/mem` if possible.
42  *
43  *  Does not support any MC-specific behaviour (privatisation, snapshots)
44  *  and `ucontext_t`.
45  *
46  *  It works with `void*` contexts allocated with `_UPT_create(pid)`.
47  */
48 extern XBT_PRIVATE unw_accessors_t mc_unw_vmread_accessors;
49
50 /** Virtual table for our `libunwind` implementation
51  *
52  *  Stack unwinding on a `simgrid::mc::Process*` (for memory, unwinding information)
53  *  and `ucontext_t` (for processor registers).
54  *
55  *  It works with the `s_mc_unw_context_t` context.
56  */
57 extern XBT_PRIVATE unw_accessors_t mc_unw_accessors;
58
59 // ***** Libunwind context
60
61 /** A `libunwind` context
62  */
63 typedef struct XBT_PRIVATE s_mc_unw_context {
64   simgrid::mc::AddressSpace* address_space;
65   simgrid::mc::Process*       process;
66   unw_context_t      context;
67 } s_mc_unw_context_t, *mc_unw_context_t;
68
69 /** Initialises an already allocated context */
70 XBT_PRIVATE int mc_unw_init_context(
71   mc_unw_context_t context, simgrid::mc::Process* process, unw_context_t* c);
72
73 // ***** Libunwind cursor
74
75 /** Initialises a `libunwind` cursor */
76 XBT_PRIVATE int mc_unw_init_cursor(unw_cursor_t *cursor, mc_unw_context_t context);
77
78 SG_END_DECL()
79
80 #endif