source: mainline/kernel/generic/include/udebug/udebug.h@ e515b21a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e515b21a was 80487bc5, checked in by Jiri Svoboda <jiri@…>, 16 years ago

Allow taskdump to read register state and extract PC, FP (not implemented for all arches).

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Copyright (c) 2008 Jiri Svoboda
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup generic
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_UDEBUG_H_
36#define KERN_UDEBUG_H_
37
38#include <ipc/ipc.h>
39
40typedef enum { /* udebug_method_t */
41
42/** Start debugging the recipient.
43 * Causes all threads in the receiving task to stop. When they
44 * are all stoped, an answer with retval 0 is generated.
45 */
46UDEBUG_M_BEGIN = 1,
47
48/** Finish debugging the recipient.
49 * Answers all pending GO and GUARD messages.
50 */
51UDEBUG_M_END,
52
53/** Set which events should be captured.
54 */
55UDEBUG_M_SET_EVMASK,
56
57/** Make sure the debugged task is still there.
58 * This message is answered when the debugged task dies
59 * or the debugging session ends.
60 */
61UDEBUG_M_GUARD,
62
63/** Run a thread until a debugging event occurs.
64 * This message is answered when the thread stops
65 * in a debugging event.
66 *
67 * - ARG2 - id of the thread to run
68 */
69UDEBUG_M_GO,
70
71/** Stop a thread being debugged.
72 * Creates a special STOP event in the thread, causing
73 * it to answer a pending GO message (if any).
74 */
75UDEBUG_M_STOP,
76
77/** Read arguments of a syscall.
78 *
79 * - ARG2 - thread identification
80 * - ARG3 - destination address in the caller's address space
81 *
82 */
83UDEBUG_M_ARGS_READ,
84
85/** Read thread's userspace register state (istate_t).
86 *
87 * - ARG2 - thread identification
88 * - ARG3 - destination address in the caller's address space
89 *
90 * or, on error, retval will be
91 * - ENOENT - thread does not exist
92 * - EBUSY - register state not available
93 */
94UDEBUG_M_REGS_READ,
95
96/** Read the list of the debugged tasks's threads.
97 *
98 * - ARG2 - destination address in the caller's address space
99 * - ARG3 - size of receiving buffer in bytes
100 *
101 * The kernel fills the buffer with a series of sysarg_t values
102 * (thread ids). On answer, the kernel will set:
103 *
104 * - ARG2 - number of bytes that were actually copied
105 * - ARG3 - number of bytes of the complete data
106 *
107 */
108UDEBUG_M_THREAD_READ,
109
110/** Read the list of the debugged task's address space areas.
111 *
112 * - ARG2 - destination address in the caller's address space
113 * - ARG3 - size of receiving buffer in bytes
114 *
115 * The kernel fills the buffer with a series of as_area_info_t structures.
116 * Upon answer, the kernel will set:
117 *
118 * - ARG2 - number of bytes that were actually copied
119 * - ARG3 - number of bytes of the complete data
120 *
121 */
122UDEBUG_M_AREAS_READ,
123
124/** Read the debugged tasks's memory.
125 *
126 * - ARG2 - destination address in the caller's address space
127 * - ARG3 - source address in the recipient's address space
128 * - ARG4 - size of receiving buffer in bytes
129 *
130 */
131UDEBUG_M_MEM_READ,
132
133} udebug_method_t;
134
135
136typedef enum {
137 UDEBUG_EVENT_FINISHED = 1, /**< Debuging session has finished */
138 UDEBUG_EVENT_STOP, /**< Stopped on DEBUG_STOP request */
139 UDEBUG_EVENT_SYSCALL_B, /**< Before beginning syscall execution */
140 UDEBUG_EVENT_SYSCALL_E, /**< After finishing syscall execution */
141 UDEBUG_EVENT_THREAD_B, /**< The task created a new thread */
142 UDEBUG_EVENT_THREAD_E /**< A thread exited */
143} udebug_event_t;
144
145#define UDEBUG_EVMASK(event) (1 << ((event) - 1))
146
147typedef enum {
148 UDEBUG_EM_FINISHED = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
149 UDEBUG_EM_STOP = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
150 UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
151 UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
152 UDEBUG_EM_THREAD_B = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
153 UDEBUG_EM_THREAD_E = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
154 UDEBUG_EM_ALL =
155 UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
156 UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
157 UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
158 UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
159 UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
160 UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E)
161} udebug_evmask_t;
162
163#ifdef KERNEL
164
165#include <synch/mutex.h>
166#include <synch/condvar.h>
167#include <arch/interrupt.h>
168#include <atomic.h>
169
170typedef enum {
171 /** Task is not being debugged */
172 UDEBUG_TS_INACTIVE,
173 /** BEGIN operation in progress (waiting for threads to stop) */
174 UDEBUG_TS_BEGINNING,
175 /** Debugger fully connected */
176 UDEBUG_TS_ACTIVE
177} udebug_task_state_t;
178
179/** Debugging part of task_t structure.
180 */
181typedef struct {
182 /** Synchronize debug ops on this task / access to this structure */
183 mutex_t lock;
184 char *lock_owner;
185
186 udebug_task_state_t dt_state;
187 call_t *begin_call;
188 int not_stoppable_count;
189 struct task *debugger;
190 udebug_evmask_t evmask;
191} udebug_task_t;
192
193/** Debugging part of thread_t structure.
194 */
195typedef struct {
196 /** Synchronize debug ops on this thread / access to this structure. */
197 mutex_t lock;
198
199 waitq_t go_wq;
200 call_t *go_call;
201 unative_t syscall_args[6];
202 istate_t *uspace_state;
203
204 /** What type of event are we stopped in or 0 if none. */
205 udebug_event_t cur_event;
206 bool go; /**< thread is GO */
207 bool stoppable; /**< thread is stoppable */
208 bool active; /**< thread is in a debugging session */
209 condvar_t active_cv;
210} udebug_thread_t;
211
212struct task;
213struct thread;
214
215void udebug_task_init(udebug_task_t *ut);
216void udebug_thread_initialize(udebug_thread_t *ut);
217
218void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
219 unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
220 bool end_variant);
221
222void udebug_thread_b_event_attach(struct thread *t, struct task *ta);
223void udebug_thread_e_event(void);
224
225void udebug_stoppable_begin(void);
226void udebug_stoppable_end(void);
227
228void udebug_before_thread_runs(void);
229
230int udebug_task_cleanup(struct task *ta);
231void udebug_thread_fault(void);
232
233#endif
234
235#endif
236
237/** @}
238 */
Note: See TracBrowser for help on using the repository browser.