Logo AND Algorithmique Numérique Distribuée

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