summaryrefslogtreecommitdiffstats
path: root/cpukit/libdebugger/rtems-debugger-threads.h
blob: 200dbbe1c7f9e9bd1f3b6d10d77817432fca99ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.org>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * Debugger for RTEMS.
 */

#ifndef _RTEMS_DEBUGGER_THREADS_h
#define _RTEMS_DEBUGGER_THREADS_h

#include <rtems/debugger/rtems-debugger-server.h>

#include <rtems/score/thread.h>

#include "rtems-debugger-block.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * Debugger thread name size, fixed size. ASCIIZ format.
 */
#define RTEMS_DEBUGGER_THREAD_NAME_SIZE (5)

/**
 * Debugger thread allocation block size.
 */
#define RTEMS_DEBUGGER_THREAD_BLOCK_SIZE (32)

/**
 * Debugger thread flags.
 */
#define RTEMS_DEBUGGER_THREAD_FLAG_EXCEPTION      (1 << 0)
#define RTEMS_DEBUGGER_THREAD_FLAG_REG_VALID      (1 << 1)
#define RTEMS_DEBUGGER_THREAD_FLAG_REG_DIRTY      (1 << 2)
#define RTEMS_DEBUGGER_THREAD_FLAG_CONTINUE       (1 << 3)
#define RTEMS_DEBUGGER_THREAD_FLAG_STEP           (1 << 4)
#define RTEMS_DEBUGGER_THREAD_FLAG_STEPPING       (1 << 5)
#define RTEMS_DEBUGGER_THREAD_FLAG_INTS_DISABLED  (1 << 6)
/* Target specific flags for use by the target backend. */
#define RTEMS_DEBUGGER_THREAD_FLAG_TARGET_BASE    (24)
#define RTEMS_DEBUGGER_THREAD_FLAG_TARGET_MASK    (0xff << RTEMS_DEBUGGER_THREAD_FLAG_TARGET_BASE)

/**
 * Resume this thread.
 */
#define RTEMS_DEBUGGER_THREAD_FLAG_RESUME \
  (RTEMS_DEBUGGER_THREAD_FLAG_CONTINUE | \
   RTEMS_DEBUGGER_THREAD_FLAG_STEP | \
   RTEMS_DEBUGGER_THREAD_FLAG_STEPPING)

/**
 * Step an instruction.
 */
#define RTEMS_DEBUGGER_THREAD_FLAG_STEP_INSTR \
  (RTEMS_DEBUGGER_THREAD_FLAG_STEP | \
   RTEMS_DEBUGGER_THREAD_FLAG_STEPPING)

/**
 * Debugger thread.
 */
typedef struct rtems_debugger_thread
{
  uint32_t        flags;
  const char      name[RTEMS_DEBUGGER_THREAD_NAME_SIZE];
  Thread_Control* tcb;
  rtems_id        id;
  int             cpu;
  uint8_t*        registers;
  int             signal;
  void*           frame;
} rtems_debugger_thread;

/**
 * Debugger stepping thread. This is a thread that steps while inside an
 * address range.
 */
typedef struct rtems_debugger_thread_stepper
{
  rtems_debugger_thread* thread;
  DB_UINT                start;
  DB_UINT                end;
} rtems_debugger_thread_stepper;

/**
 * Debugger thread control.
 */
struct rtems_debugger_threads
{
  rtems_debugger_block current;       /**< The threads currently available. */
  rtems_debugger_block registers;     /**< The threads that have stopped. */
  rtems_debugger_block excludes;      /**< The threads we cannot touch. */
  rtems_debugger_block stopped;       /**< The threads that have stopped. */
  rtems_debugger_block steppers;      /**< The threads that are stepping. */
  size_t               next;          /**< An iterator. */
  int                  selector_gen;  /**< General thread selector. */
  int                  selector_cont; /**< Continue thread selector. */
};

/**
 * Create the thread support.
 */
extern int rtems_debugger_thread_create(void);

/**
 * Destroy the thread support.
 */
extern int rtems_debugger_thread_destroy(void);

/**
 * Find the index in the thread table for the ID.
 */
extern int rtems_debugger_thread_find_index(rtems_id id);

/**
 * Suspend the system.
 */
extern int rtems_debugger_thread_system_suspend(void);

/**
 * Resume the system.
 */
extern int rtems_debugger_thread_system_resume(bool detaching);

/**
 * Continue all threads.
 */
extern int rtems_debugger_thread_continue_all(void);

/**
 * Continue a thread.
 */
extern int rtems_debugger_thread_continue(rtems_debugger_thread* thread);

/**
 * Step a thread.
 */
extern int rtems_debugger_thread_step(rtems_debugger_thread* thread);

/**
 * Thread is stepping so record the details.
 */
extern int rtems_debugger_thread_stepping(rtems_debugger_thread* thread,
                                          DB_UINT                start,
                                          DB_UINT                end);

/**
 * Thread's PC in the stepping range? Returns the stepper is in range else
 * NULL.
 */
extern const rtems_debugger_thread_stepper*
rtems_debugger_thread_is_stepping(rtems_id id, DB_UINT pc);

/**
 * Return the thread's current priority/
 */
extern int rtems_debugger_thread_current_priority(rtems_debugger_thread* thread);

/**
 * Return the thread's real priority.
 */
extern int rtems_debugger_thread_real_priority(rtems_debugger_thread* thread);

/**
 * Return the thread's state.
 */
extern int rtems_debugger_thread_state(rtems_debugger_thread* thread);

/**
 * Return the thread's state.
 */
//extern bool rtems_debugger_thread_state_debugger(rtems_debugger_thread* thread);

/**
 * Return a string of the thread's state.
 */
extern int rtems_debugger_thread_state_str(rtems_debugger_thread* thread,
                                           char*                  buffer,
                                           size_t                 size);

/**
 * Return the thread's stack size.
 */
extern unsigned long rtems_debugger_thread_stack_size(rtems_debugger_thread* thread);

/**
 * Return the thread's stack area address.
 */
extern void* rtems_debugger_thread_stack_area(rtems_debugger_thread* thread);

/**
 * Check a thread's flag and return true if any of the bits in the mask are
 * set.
 */
static inline bool
rtems_debugger_thread_flag(rtems_debugger_thread* thread, uint32_t mask)
{
  return (thread->flags & mask) != 0;
}

/**
 * Get the current threads.
 */
static inline rtems_debugger_thread*
rtems_debugger_thread_current(rtems_debugger_threads* threads)
{
  return threads->current.block;
}

/**
 * Get the registers.
 */
static inline uint8_t*
rtems_debugger_thread_registers(rtems_debugger_threads* threads)
{
  return threads->registers.block;
}

/**
 * Get the excludes.
 */
static inline rtems_id*
rtems_debugger_thread_excludes(rtems_debugger_threads* threads)
{
  return threads->excludes.block;
}

/**
 * Get the stopped.
 */
static inline rtems_id*
rtems_debugger_thread_stopped(rtems_debugger_threads* threads)
{
  return threads->stopped.block;
}

/**
 * Get the steppers.
 */
static inline rtems_debugger_thread_stepper*
rtems_debugger_thread_steppers(rtems_debugger_threads* threads)
{
  return threads->steppers.block;
}

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif