1 /* Displaced stepping related things.
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #ifndef DISPLACED_STEPPING_H
21 #define DISPLACED_STEPPING_H
23 #include "gdbsupport/byte-vector.h"
27 /* True if we are debugging displaced stepping. */
29 extern bool debug_displaced
;
31 /* Print a "displaced" debug statement. */
33 #define displaced_debug_printf(fmt, ...) \
36 if (debug_displaced) \
37 debug_prefixed_printf ("displaced", __func__, fmt, ##__VA_ARGS__); \
41 enum displaced_step_prepare_status
43 /* A displaced stepping buffer was successfully allocated and prepared. */
44 DISPLACED_STEP_PREPARE_STATUS_OK
,
46 /* This particular instruction can't be displaced stepped, GDB should fall
47 back on in-line stepping. */
48 DISPLACED_STEP_PREPARE_STATUS_CANT
,
50 /* Not enough resources are available at this time, try again later. */
51 DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
,
54 enum displaced_step_finish_status
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
59 DISPLACED_STEP_FINISH_STATUS_OK
,
61 /* The thread started a displaced step, but didn't complete it. */
62 DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
,
65 /* Base class for displaced stepping closures (the arch-specific data). */
67 struct displaced_step_copy_insn_closure
69 virtual ~displaced_step_copy_insn_closure () = 0;
72 using displaced_step_copy_insn_closure_up
73 = std::unique_ptr
<displaced_step_copy_insn_closure
>;
75 /* A simple displaced step closure that contains only a byte buffer. */
77 struct buf_displaced_step_copy_insn_closure
: displaced_step_copy_insn_closure
79 buf_displaced_step_copy_insn_closure (int buf_size
)
86 /* Per-inferior displaced stepping state. */
88 struct displaced_step_inferior_state
90 displaced_step_inferior_state ()
95 /* Put this object back in its original state. */
99 step_thread
= nullptr;
100 step_gdbarch
= nullptr;
101 step_closure
.reset ();
104 step_saved_copy
.clear ();
107 /* True if preparing a displaced step ever failed. If so, we won't
108 try displaced stepping for this inferior again. */
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
;
116 /* The architecture the thread had when we stepped it. */
117 gdbarch
*step_gdbarch
;
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
;
123 /* The address of the original instruction, and the copy we
125 CORE_ADDR step_original
, step_copy
;
127 /* Saved contents of copy area. */
128 gdb::byte_vector step_saved_copy
;
131 #endif /* DISPLACED_STEPPING_H */