gdb: change single_displaced_buffer_manager into multiple_displaced_buffer_manager
[deliverable/binutils-gdb.git] / gdb / displaced-stepping.h
1 #ifndef DISPLACED_STEPPING_H
2 #define DISPLACED_STEPPING_H
3
4 #include "gdbsupport/array-view.h"
5 #include "gdbsupport/byte-vector.h"
6
7 struct gdbarch;
8 struct thread_info;
9
10 enum displaced_step_prepare_status
11 {
12 /* A displaced stepping buffer was successfully allocated and prepared. */
13 DISPLACED_STEP_PREPARE_STATUS_OK,
14
15 /* Something bad happened. */
16 DISPLACED_STEP_PREPARE_STATUS_ERROR,
17
18 /* Not enough resources are available at this time, try again later. */
19 DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE,
20 };
21
22 enum displaced_step_finish_status
23 {
24 /* The instruction was stepped and fixed up. */
25 DISPLACED_STEP_FINISH_STATUS_OK,
26
27 /* The instruction was not stepped. */
28 DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED,
29 };
30
31 /* Data returned by a gdbarch displaced_step_copy_insn method, to be passed to
32 the matching displaced_step_fixup method. */
33
34 struct displaced_step_copy_insn_closure
35 {
36 virtual ~displaced_step_copy_insn_closure () = 0;
37 };
38
39 typedef std::unique_ptr<displaced_step_copy_insn_closure>
40 displaced_step_copy_insn_closure_up;
41
42 /* A simple displaced step closure that contains only a byte buffer. */
43
44 struct buf_displaced_step_copy_insn_closure : displaced_step_copy_insn_closure
45 {
46 buf_displaced_step_copy_insn_closure (int buf_size)
47 : buf (buf_size)
48 {}
49
50 gdb::byte_vector buf;
51 };
52
53 /* Per-inferior displaced stepping state. */
54
55 struct displaced_step_inferior_state
56 {
57 displaced_step_inferior_state ()
58 {
59 reset ();
60 }
61
62 /* Put this object back in its original state. */
63 void reset ()
64 {
65 failed_before = false;
66 }
67
68 /* True if preparing a displaced step ever failed. If so, we won't
69 try displaced stepping for this inferior again. */
70 bool failed_before;
71
72 bool unavailable = false;
73 };
74
75 /* Per-thread displaced stepping state. */
76
77 struct displaced_step_thread_state
78 {
79 /* Return true if this thread is currently executing a displaced step. */
80 bool in_progress () const
81 { return m_original_gdbarch != nullptr; }
82
83 /* Return the gdbarch of the thread prior to the step. */
84 gdbarch *get_original_gdbarch () const
85 { return m_original_gdbarch; }
86
87 /* Mark this thread as currently executing a displaced step.
88
89 ORIGINAL_GDBARCH is the current gdbarch of the thread (before the step
90 is executed). */
91 void set (gdbarch *original_gdbarch)
92 { m_original_gdbarch = original_gdbarch; }
93
94 /* mark this thread as no longer executing a displaced step. */
95 void reset ()
96 { m_original_gdbarch = nullptr; }
97
98 private:
99 gdbarch *m_original_gdbarch = nullptr;
100 };
101
102 struct displaced_step_buffer_state
103 {
104 displaced_step_buffer_state (CORE_ADDR buffer_addr)
105 : m_buffer_addr (buffer_addr)
106 {}
107
108 const CORE_ADDR m_buffer_addr;
109
110 /* When a displaced step operation is using this buffer, this is the original
111 PC of the instruction currently begin stepped. */
112 CORE_ADDR m_original_pc = 0;
113
114 /* If set, the thread currently using the buffer. If unset, the buffer is not
115 used. */
116 thread_info *m_current_thread = nullptr;
117
118 /* Saved copy of the bytes in the displaced buffer, to be restored once the
119 buffer is no longer used. */
120 gdb::byte_vector m_saved_copy;
121
122 /* Closure obtained from gdbarch_displaced_step_copy_insn, to be passed to
123 gdbarch_displaced_step_fixup_insn. */
124 displaced_step_copy_insn_closure_up m_copy_insn_closure;
125 };
126
127 /* Manage access to a single displaced stepping buffer, without any
128 sharing. */
129
130 struct multiple_displaced_buffer_manager
131 {
132 multiple_displaced_buffer_manager (gdb::array_view<CORE_ADDR> buffer_addrs)
133 {
134 gdb_assert (buffer_addrs.size () > 0);
135
136 for (CORE_ADDR buffer_addr : buffer_addrs)
137 m_buffers.emplace_back (buffer_addr);
138 }
139
140 displaced_step_prepare_status prepare (thread_info *thread);
141
142 displaced_step_finish_status finish (gdbarch *arch, thread_info *thread,
143 gdb_signal sig);
144
145 private:
146 std::vector<displaced_step_buffer_state> m_buffers;
147 };
148
149
150 #endif /* DISPLACED_STEPPING_H */
This page took 0.032309 seconds and 4 git commands to generate.