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