gdb: move displaced stepping types to displaced-stepping.{h,c}
[deliverable/binutils-gdb.git] / gdb / displaced-stepping.h
1 /* Displaced stepping related things.
2
3 Copyright (C) 2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef DISPLACED_STEPPING_H
21 #define DISPLACED_STEPPING_H
22
23 #include "gdbsupport/byte-vector.h"
24
25 struct thread_info;
26
27 /* True if we are debugging displaced stepping. */
28
29 extern bool debug_displaced;
30
31 /* Print a "displaced" debug statement. */
32
33 #define displaced_debug_printf(fmt, ...) \
34 do \
35 { \
36 if (debug_displaced) \
37 debug_prefixed_printf ("displaced", __func__, fmt, ##__VA_ARGS__); \
38 } \
39 while (0)
40
41 enum displaced_step_prepare_status
42 {
43 /* A displaced stepping buffer was successfully allocated and prepared. */
44 DISPLACED_STEP_PREPARE_STATUS_OK,
45
46 /* This particular instruction can't be displaced stepped, GDB should fall
47 back on in-line stepping. */
48 DISPLACED_STEP_PREPARE_STATUS_CANT,
49
50 /* Not enough resources are available at this time, try again later. */
51 DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE,
52 };
53
54 enum displaced_step_finish_status
55 {
56 /* Either the instruction was stepped and fixed up, or the specified thread
57 wasn't executing a displaced step (in which case there's nothing to
58 finish). */
59 DISPLACED_STEP_FINISH_STATUS_OK,
60
61 /* The thread started a displaced step, but didn't complete it. */
62 DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED,
63 };
64
65 /* Base class for displaced stepping closures (the arch-specific data). */
66
67 struct displaced_step_copy_insn_closure
68 {
69 virtual ~displaced_step_copy_insn_closure () = 0;
70 };
71
72 using displaced_step_copy_insn_closure_up
73 = std::unique_ptr<displaced_step_copy_insn_closure>;
74
75 /* A simple displaced step closure that contains only a byte buffer. */
76
77 struct buf_displaced_step_copy_insn_closure : displaced_step_copy_insn_closure
78 {
79 buf_displaced_step_copy_insn_closure (int buf_size)
80 : buf (buf_size)
81 {}
82
83 gdb::byte_vector buf;
84 };
85
86 /* Per-inferior displaced stepping state. */
87
88 struct displaced_step_inferior_state
89 {
90 displaced_step_inferior_state ()
91 {
92 reset ();
93 }
94
95 /* Put this object back in its original state. */
96 void reset ()
97 {
98 failed_before = 0;
99 step_thread = nullptr;
100 step_gdbarch = nullptr;
101 step_closure.reset ();
102 step_original = 0;
103 step_copy = 0;
104 step_saved_copy.clear ();
105 }
106
107 /* True if preparing a displaced step ever failed. If so, we won't
108 try displaced stepping for this inferior again. */
109 int failed_before;
110
111 /* If this is not nullptr, this is the thread carrying out a
112 displaced single-step in process PID. This thread's state will
113 require fixing up once it has completed its step. */
114 thread_info *step_thread;
115
116 /* The architecture the thread had when we stepped it. */
117 gdbarch *step_gdbarch;
118
119 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
120 for post-step cleanup. */
121 displaced_step_copy_insn_closure_up step_closure;
122
123 /* The address of the original instruction, and the copy we
124 made. */
125 CORE_ADDR step_original, step_copy;
126
127 /* Saved contents of copy area. */
128 gdb::byte_vector step_saved_copy;
129 };
130
131 #endif /* DISPLACED_STEPPING_H */
This page took 0.039676 seconds and 5 git commands to generate.