source: rtems/cpukit/libdebugger/rtems-debugger-threads.h @ 7f95cc0

5
Last change on this file since 7f95cc0 was a0d4e99, checked in by Chris Johns <chrisj@…>, on 11/25/16 at 04:13:36

cpukit: Add libdebugger, a remote debugger agent for GDB.

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