1 | /* |
---|
2 | * Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.org>. |
---|
3 | * All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
8 | * 1. Redistributions of source code must retain the above copyright |
---|
9 | * notice, this list of conditions and the following disclaimer. |
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer in the |
---|
12 | * documentation and/or other materials provided with the distribution. |
---|
13 | * |
---|
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
24 | * SUCH DAMAGE. |
---|
25 | */ |
---|
26 | |
---|
27 | /* |
---|
28 | * Debugger for RTEMS. |
---|
29 | */ |
---|
30 | |
---|
31 | #ifndef _RTEMS_DEBUGGER_THREADS_h |
---|
32 | #define _RTEMS_DEBUGGER_THREADS_h |
---|
33 | |
---|
34 | #include <rtems/debugger/rtems-debugger-server.h> |
---|
35 | |
---|
36 | #include <rtems/score/thread.h> |
---|
37 | |
---|
38 | #include "rtems-debugger-block.h" |
---|
39 | |
---|
40 | #ifdef __cplusplus |
---|
41 | extern "C" { |
---|
42 | #endif /* __cplusplus */ |
---|
43 | |
---|
44 | /** |
---|
45 | * Debugger thread name size, fixed size. ASCIIZ format. |
---|
46 | */ |
---|
47 | #define RTEMS_DEBUGGER_THREAD_NAME_SIZE (5) |
---|
48 | |
---|
49 | /** |
---|
50 | * Debugger thread allocation block size. |
---|
51 | */ |
---|
52 | #define RTEMS_DEBUGGER_THREAD_BLOCK_SIZE (32) |
---|
53 | |
---|
54 | /** |
---|
55 | * Debugger thread flags. |
---|
56 | */ |
---|
57 | #define RTEMS_DEBUGGER_THREAD_FLAG_EXCEPTION (1 << 0) |
---|
58 | #define RTEMS_DEBUGGER_THREAD_FLAG_REG_VALID (1 << 1) |
---|
59 | #define RTEMS_DEBUGGER_THREAD_FLAG_REG_DIRTY (1 << 2) |
---|
60 | #define RTEMS_DEBUGGER_THREAD_FLAG_CONTINUE (1 << 3) |
---|
61 | #define RTEMS_DEBUGGER_THREAD_FLAG_STEP (1 << 4) |
---|
62 | #define RTEMS_DEBUGGER_THREAD_FLAG_STEPPING (1 << 5) |
---|
63 | #define RTEMS_DEBUGGER_THREAD_FLAG_INTS_DISABLED (1 << 6) |
---|
64 | /* Target specific flags for use by the target backend. */ |
---|
65 | #define RTEMS_DEBUGGER_THREAD_FLAG_TARGET_BASE (24) |
---|
66 | #define RTEMS_DEBUGGER_THREAD_FLAG_TARGET_MASK (0xff << RTEMS_DEBUGGER_THREAD_FLAG_TARGET_BASE) |
---|
67 | |
---|
68 | /** |
---|
69 | * Resume this thread. |
---|
70 | */ |
---|
71 | #define RTEMS_DEBUGGER_THREAD_FLAG_RESUME \ |
---|
72 | (RTEMS_DEBUGGER_THREAD_FLAG_CONTINUE | \ |
---|
73 | RTEMS_DEBUGGER_THREAD_FLAG_STEP | \ |
---|
74 | RTEMS_DEBUGGER_THREAD_FLAG_STEPPING) |
---|
75 | |
---|
76 | /** |
---|
77 | * Step an instruction. |
---|
78 | */ |
---|
79 | #define RTEMS_DEBUGGER_THREAD_FLAG_STEP_INSTR \ |
---|
80 | (RTEMS_DEBUGGER_THREAD_FLAG_STEP | \ |
---|
81 | RTEMS_DEBUGGER_THREAD_FLAG_STEPPING) |
---|
82 | |
---|
83 | /** |
---|
84 | * Debugger thread. |
---|
85 | */ |
---|
86 | typedef struct rtems_debugger_thread |
---|
87 | { |
---|
88 | uint32_t flags; |
---|
89 | const char name[RTEMS_DEBUGGER_THREAD_NAME_SIZE]; |
---|
90 | Thread_Control* tcb; |
---|
91 | rtems_id id; |
---|
92 | int cpu; |
---|
93 | uint8_t* registers; |
---|
94 | int signal; |
---|
95 | void* frame; |
---|
96 | } rtems_debugger_thread; |
---|
97 | |
---|
98 | /** |
---|
99 | * Debugger stepping thread. This is a thread that steps while inside an |
---|
100 | * address range. |
---|
101 | */ |
---|
102 | typedef struct rtems_debugger_thread_stepper |
---|
103 | { |
---|
104 | rtems_debugger_thread* thread; |
---|
105 | DB_UINT start; |
---|
106 | DB_UINT end; |
---|
107 | } rtems_debugger_thread_stepper; |
---|
108 | |
---|
109 | /** |
---|
110 | * Debugger thread control. |
---|
111 | */ |
---|
112 | struct rtems_debugger_threads |
---|
113 | { |
---|
114 | rtems_debugger_block current; /**< The threads currently available. */ |
---|
115 | rtems_debugger_block registers; /**< The threads that have stopped. */ |
---|
116 | rtems_debugger_block excludes; /**< The threads we cannot touch. */ |
---|
117 | rtems_debugger_block stopped; /**< The threads that have stopped. */ |
---|
118 | rtems_debugger_block steppers; /**< The threads that are stepping. */ |
---|
119 | size_t next; /**< An iterator. */ |
---|
120 | int selector_gen; /**< General thread selector. */ |
---|
121 | int selector_cont; /**< Continue thread selector. */ |
---|
122 | }; |
---|
123 | |
---|
124 | /** |
---|
125 | * Create the thread support. |
---|
126 | */ |
---|
127 | extern int rtems_debugger_thread_create(void); |
---|
128 | |
---|
129 | /** |
---|
130 | * Destroy the thread support. |
---|
131 | */ |
---|
132 | extern int rtems_debugger_thread_destroy(void); |
---|
133 | |
---|
134 | /** |
---|
135 | * Find the index in the thread table for the ID. |
---|
136 | */ |
---|
137 | extern int rtems_debugger_thread_find_index(rtems_id id); |
---|
138 | |
---|
139 | /** |
---|
140 | * Suspend the system. |
---|
141 | */ |
---|
142 | extern int rtems_debugger_thread_system_suspend(void); |
---|
143 | |
---|
144 | /** |
---|
145 | * Resume the system. |
---|
146 | */ |
---|
147 | extern int rtems_debugger_thread_system_resume(bool detaching); |
---|
148 | |
---|
149 | /** |
---|
150 | * Continue all threads. |
---|
151 | */ |
---|
152 | extern int rtems_debugger_thread_continue_all(void); |
---|
153 | |
---|
154 | /** |
---|
155 | * Continue a thread. |
---|
156 | */ |
---|
157 | extern int rtems_debugger_thread_continue(rtems_debugger_thread* thread); |
---|
158 | |
---|
159 | /** |
---|
160 | * Step a thread. |
---|
161 | */ |
---|
162 | extern int rtems_debugger_thread_step(rtems_debugger_thread* thread); |
---|
163 | |
---|
164 | /** |
---|
165 | * Thread is stepping so record the details. |
---|
166 | */ |
---|
167 | extern int rtems_debugger_thread_stepping(rtems_debugger_thread* thread, |
---|
168 | DB_UINT start, |
---|
169 | DB_UINT end); |
---|
170 | |
---|
171 | /** |
---|
172 | * Thread's PC in the stepping range? Returns the stepper is in range else |
---|
173 | * NULL. |
---|
174 | */ |
---|
175 | extern const rtems_debugger_thread_stepper* |
---|
176 | rtems_debugger_thread_is_stepping(rtems_id id, DB_UINT pc); |
---|
177 | |
---|
178 | /** |
---|
179 | * Return the thread's current priority/ |
---|
180 | */ |
---|
181 | extern int rtems_debugger_thread_current_priority(rtems_debugger_thread* thread); |
---|
182 | |
---|
183 | /** |
---|
184 | * Return the thread's real priority. |
---|
185 | */ |
---|
186 | extern int rtems_debugger_thread_real_priority(rtems_debugger_thread* thread); |
---|
187 | |
---|
188 | /** |
---|
189 | * Return the thread's state. |
---|
190 | */ |
---|
191 | extern int rtems_debugger_thread_state(rtems_debugger_thread* thread); |
---|
192 | |
---|
193 | /** |
---|
194 | * Return the thread's state. |
---|
195 | */ |
---|
196 | //extern bool rtems_debugger_thread_state_debugger(rtems_debugger_thread* thread); |
---|
197 | |
---|
198 | /** |
---|
199 | * Return a string of the thread's state. |
---|
200 | */ |
---|
201 | extern int rtems_debugger_thread_state_str(rtems_debugger_thread* thread, |
---|
202 | char* buffer, |
---|
203 | size_t size); |
---|
204 | |
---|
205 | /** |
---|
206 | * Return the thread's stack size. |
---|
207 | */ |
---|
208 | extern unsigned long rtems_debugger_thread_stack_size(rtems_debugger_thread* thread); |
---|
209 | |
---|
210 | /** |
---|
211 | * Return the thread's stack area address. |
---|
212 | */ |
---|
213 | extern void* rtems_debugger_thread_stack_area(rtems_debugger_thread* thread); |
---|
214 | |
---|
215 | /** |
---|
216 | * Check a thread's flag and return true if any of the bits in the mask are |
---|
217 | * set. |
---|
218 | */ |
---|
219 | static inline bool |
---|
220 | rtems_debugger_thread_flag(rtems_debugger_thread* thread, uint32_t mask) |
---|
221 | { |
---|
222 | return (thread->flags & mask) != 0; |
---|
223 | } |
---|
224 | |
---|
225 | /** |
---|
226 | * Get the current threads. |
---|
227 | */ |
---|
228 | static inline rtems_debugger_thread* |
---|
229 | rtems_debugger_thread_current(rtems_debugger_threads* threads) |
---|
230 | { |
---|
231 | return threads->current.block; |
---|
232 | } |
---|
233 | |
---|
234 | /** |
---|
235 | * Get the registers. |
---|
236 | */ |
---|
237 | static inline uint8_t* |
---|
238 | rtems_debugger_thread_registers(rtems_debugger_threads* threads) |
---|
239 | { |
---|
240 | return threads->registers.block; |
---|
241 | } |
---|
242 | |
---|
243 | /** |
---|
244 | * Get the excludes. |
---|
245 | */ |
---|
246 | static inline rtems_id* |
---|
247 | rtems_debugger_thread_excludes(rtems_debugger_threads* threads) |
---|
248 | { |
---|
249 | return threads->excludes.block; |
---|
250 | } |
---|
251 | |
---|
252 | /** |
---|
253 | * Get the stopped. |
---|
254 | */ |
---|
255 | static inline rtems_id* |
---|
256 | rtems_debugger_thread_stopped(rtems_debugger_threads* threads) |
---|
257 | { |
---|
258 | return threads->stopped.block; |
---|
259 | } |
---|
260 | |
---|
261 | /** |
---|
262 | * Get the steppers. |
---|
263 | */ |
---|
264 | static inline rtems_debugger_thread_stepper* |
---|
265 | rtems_debugger_thread_steppers(rtems_debugger_threads* threads) |
---|
266 | { |
---|
267 | return threads->steppers.block; |
---|
268 | } |
---|
269 | |
---|
270 | #ifdef __cplusplus |
---|
271 | } |
---|
272 | #endif /* __cplusplus */ |
---|
273 | |
---|
274 | #endif |
---|