Rev 3441 | Rev 3474 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3441 | Rev 3448 | ||
---|---|---|---|
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 | 32 | ||
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | * @brief Udebug. |
35 | * @brief Udebug. |
36 | * |
36 | * |
37 | * Functions in this file are executed directly in each thread, which |
37 | * Functions in this file are executed directly in each thread, which |
38 | * may or may not be the subject of debugging. The udebug_stoppable_begin/end() |
38 | * may or may not be the subject of debugging. The udebug_stoppable_begin/end() |
39 | * functions are also executed in the clock interrupt handler. To avoid |
39 | * functions are also executed in the clock interrupt handler. To avoid |
40 | * deadlock, functions in this file are protected from the interrupt |
40 | * deadlock, functions in this file are protected from the interrupt |
41 | * by locking the recursive lock THREAD->udebug.int_lock (just an atomic |
41 | * by locking the recursive lock THREAD->udebug.int_lock (just an atomic |
42 | * variable). This prevents udebug_stoppable_begin/end() from being |
42 | * variable). This prevents udebug_stoppable_begin/end() from being |
43 | * executed in the interrupt handler (they are skipped). |
43 | * executed in the interrupt handler (they are skipped). |
44 | * |
44 | * |
45 | * Functions in udebug_ops.c and udebug_ipc.c execute in different threads, |
45 | * Functions in udebug_ops.c and udebug_ipc.c execute in different threads, |
46 | * so they needn't be protected from the (preemptible) interrupt-initiated |
46 | * so they needn't be protected from the (preemptible) interrupt-initiated |
47 | * code. |
47 | * code. |
48 | */ |
48 | */ |
49 | 49 | ||
50 | #include <synch/waitq.h> |
50 | #include <synch/waitq.h> |
51 | #include <debug.h> |
51 | #include <debug.h> |
52 | #include <udebug/udebug.h> |
52 | #include <udebug/udebug.h> |
53 | #include <errno.h> |
53 | #include <errno.h> |
54 | #include <arch.h> |
54 | #include <arch.h> |
55 | 55 | ||
56 | static inline void udebug_int_lock(void) |
56 | static inline void udebug_int_lock(void) |
57 | { |
57 | { |
58 | atomic_inc(&THREAD->udebug.int_lock); |
58 | atomic_inc(&THREAD->udebug.int_lock); |
59 | } |
59 | } |
60 | 60 | ||
61 | static inline void udebug_int_unlock(void) |
61 | static inline void udebug_int_unlock(void) |
62 | { |
62 | { |
63 | atomic_dec(&THREAD->udebug.int_lock); |
63 | atomic_dec(&THREAD->udebug.int_lock); |
64 | } |
64 | } |
65 | 65 | ||
66 | void udebug_task_init(udebug_task_t *ut) |
66 | void udebug_task_init(udebug_task_t *ut) |
67 | { |
67 | { |
68 | mutex_initialize(&ut->lock, MUTEX_PASSIVE); |
68 | mutex_initialize(&ut->lock, MUTEX_PASSIVE); |
69 | ut->dt_state = UDEBUG_TS_INACTIVE; |
69 | ut->dt_state = UDEBUG_TS_INACTIVE; |
70 | ut->begin_call = NULL; |
70 | ut->begin_call = NULL; |
71 | ut->not_stoppable_count = 0; |
71 | ut->not_stoppable_count = 0; |
72 | ut->evmask = 0; |
72 | ut->evmask = 0; |
73 | } |
73 | } |
74 | 74 | ||
75 | void udebug_thread_initialize(udebug_thread_t *ut) |
75 | void udebug_thread_initialize(udebug_thread_t *ut) |
76 | { |
76 | { |
77 | mutex_initialize(&ut->lock, MUTEX_PASSIVE); |
77 | mutex_initialize(&ut->lock, MUTEX_PASSIVE); |
78 | waitq_initialize(&ut->go_wq); |
78 | waitq_initialize(&ut->go_wq); |
79 | 79 | ||
80 | /* |
80 | /* |
81 | * At the beginning the thread is stoppable, so int_lock be set, too. |
81 | * At the beginning the thread is stoppable, so int_lock be set, too. |
82 | */ |
82 | */ |
83 | atomic_set(&ut->int_lock, 1); |
83 | atomic_set(&ut->int_lock, 1); |
84 | 84 | ||
85 | ut->go_call = NULL; |
85 | ut->go_call = NULL; |
86 | ut->stop = true; |
86 | ut->stop = true; |
87 | ut->stoppable = true; |
87 | ut->stoppable = true; |
88 | ut->debug_active = false; |
88 | ut->debug_active = false; |
89 | ut->cur_event = 0; /* none */ |
89 | ut->cur_event = 0; /* none */ |
90 | } |
90 | } |
91 | 91 | ||
92 | static void udebug_wait_for_go(waitq_t *wq) |
92 | static void udebug_wait_for_go(waitq_t *wq) |
93 | { |
93 | { |
94 | int rc; |
94 | int rc; |
95 | ipl_t ipl; |
95 | ipl_t ipl; |
96 | 96 | ||
97 | ipl = waitq_sleep_prepare(wq); |
97 | ipl = waitq_sleep_prepare(wq); |
98 | 98 | ||
99 | wq->missed_wakeups = 0; /* Enforce blocking. */ |
99 | wq->missed_wakeups = 0; /* Enforce blocking. */ |
100 | rc = waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); |
100 | rc = waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); |
101 | 101 | ||
102 | waitq_sleep_finish(wq, rc, ipl); |
102 | waitq_sleep_finish(wq, rc, ipl); |
103 | } |
103 | } |
104 | 104 | ||
105 | /** Do a preliminary check that a debugging session is in progress. |
105 | /** Do a preliminary check that a debugging session is in progress. |
106 | * |
106 | * |
107 | * This only requires the THREAD->udebug.lock mutex (and not |
107 | * This only requires the THREAD->udebug.lock mutex (and not |
108 | * TASK->udebug.lock mutex). For an undebugged task, this will |
108 | * TASK->udebug.lock mutex). For an undebugged task, this will |
109 | * never block (while there could be collisions by different threads |
109 | * never block (while there could be collisions by different threads |
110 | * on the TASK mutex), thus improving SMP perormance for undebugged tasks. |
110 | * on the TASK mutex), thus improving SMP perormance for undebugged tasks. |
111 | */ |
111 | */ |
112 | static bool udebug_thread_precheck(void) |
112 | static bool udebug_thread_precheck(void) |
113 | { |
113 | { |
114 | bool res; |
114 | bool res; |
115 | 115 | ||
116 | mutex_lock(&THREAD->udebug.lock); |
116 | mutex_lock(&THREAD->udebug.lock); |
117 | res = THREAD->udebug.debug_active; |
117 | res = THREAD->udebug.debug_active; |
118 | mutex_unlock(&THREAD->udebug.lock); |
118 | mutex_unlock(&THREAD->udebug.lock); |
119 | 119 | ||
120 | return res; |
120 | return res; |
121 | } |
121 | } |
122 | 122 | ||
123 | void udebug_stoppable_begin(void) |
123 | void udebug_stoppable_begin(void) |
124 | { |
124 | { |
125 | int nsc; |
125 | int nsc; |
126 | call_t *db_call, *go_call; |
126 | call_t *db_call, *go_call; |
127 | 127 | ||
128 | ASSERT(THREAD); |
128 | ASSERT(THREAD); |
129 | ASSERT(TASK); |
129 | ASSERT(TASK); |
130 | 130 | ||
131 | udebug_int_lock(); |
131 | udebug_int_lock(); |
132 | 132 | ||
133 | /* Early check for undebugged tasks */ |
133 | /* Early check for undebugged tasks */ |
134 | if (!udebug_thread_precheck()) { |
134 | if (!udebug_thread_precheck()) { |
135 | udebug_int_unlock(); |
135 | udebug_int_unlock(); |
136 | return; |
136 | return; |
137 | } |
137 | } |
138 | 138 | ||
139 | mutex_lock(&TASK->udebug.lock); |
139 | mutex_lock(&TASK->udebug.lock); |
140 | 140 | ||
141 | nsc = --TASK->udebug.not_stoppable_count; |
141 | nsc = --TASK->udebug.not_stoppable_count; |
142 | 142 | ||
143 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
143 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
144 | mutex_lock(&THREAD->udebug.lock); |
144 | mutex_lock(&THREAD->udebug.lock); |
145 | ASSERT(THREAD->udebug.stoppable == false); |
145 | ASSERT(THREAD->udebug.stoppable == false); |
146 | THREAD->udebug.stoppable = true; |
146 | THREAD->udebug.stoppable = true; |
147 | 147 | ||
148 | if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING && nsc == 0) { |
148 | if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING && nsc == 0) { |
149 | /* |
149 | /* |
150 | * This was the last non-stoppable thread. Reply to |
150 | * This was the last non-stoppable thread. Reply to |
151 | * DEBUG_BEGIN call. |
151 | * DEBUG_BEGIN call. |
152 | */ |
152 | */ |
153 | 153 | ||
154 | db_call = TASK->udebug.begin_call; |
154 | db_call = TASK->udebug.begin_call; |
155 | ASSERT(db_call); |
155 | ASSERT(db_call); |
156 | 156 | ||
157 | TASK->udebug.dt_state = UDEBUG_TS_ACTIVE; |
157 | TASK->udebug.dt_state = UDEBUG_TS_ACTIVE; |
158 | TASK->udebug.begin_call = NULL; |
158 | TASK->udebug.begin_call = NULL; |
159 | 159 | ||
160 | IPC_SET_RETVAL(db_call->data, 0); |
160 | IPC_SET_RETVAL(db_call->data, 0); |
161 | ipc_answer(&TASK->answerbox, db_call); |
161 | ipc_answer(&TASK->answerbox, db_call); |
162 | 162 | ||
163 | } else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) { |
163 | } else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) { |
164 | /* |
164 | /* |
165 | * Active debugging session |
165 | * Active debugging session |
166 | */ |
166 | */ |
167 | 167 | ||
168 | if (THREAD->udebug.debug_active && THREAD->udebug.stop) { |
168 | if (THREAD->udebug.debug_active && THREAD->udebug.stop) { |
169 | /* |
169 | /* |
170 | * Thread was requested to stop - answer go call |
170 | * Thread was requested to stop - answer go call |
171 | */ |
171 | */ |
172 | 172 | ||
173 | /* Make sure nobody takes this call away from us */ |
173 | /* Make sure nobody takes this call away from us */ |
174 | go_call = THREAD->udebug.go_call; |
174 | go_call = THREAD->udebug.go_call; |
175 | THREAD->udebug.go_call = NULL; |
175 | THREAD->udebug.go_call = NULL; |
176 | ASSERT(go_call); |
176 | ASSERT(go_call); |
177 | 177 | ||
178 | IPC_SET_RETVAL(go_call->data, 0); |
178 | IPC_SET_RETVAL(go_call->data, 0); |
179 | IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP); |
179 | IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP); |
180 | 180 | ||
181 | THREAD->udebug.cur_event = UDEBUG_EVENT_STOP; |
181 | THREAD->udebug.cur_event = UDEBUG_EVENT_STOP; |
182 | 182 | ||
183 | ipc_answer(&TASK->answerbox, go_call); |
183 | ipc_answer(&TASK->answerbox, go_call); |
184 | } |
184 | } |
185 | } |
185 | } |
186 | 186 | ||
187 | mutex_unlock(&THREAD->udebug.lock); |
187 | mutex_unlock(&THREAD->udebug.lock); |
188 | mutex_unlock(&TASK->udebug.lock); |
188 | mutex_unlock(&TASK->udebug.lock); |
189 | } |
189 | } |
190 | 190 | ||
191 | void udebug_stoppable_end(void) |
191 | void udebug_stoppable_end(void) |
192 | { |
192 | { |
193 | /* Early check for undebugged tasks */ |
193 | /* Early check for undebugged tasks */ |
194 | if (!udebug_thread_precheck()) { |
194 | if (!udebug_thread_precheck()) { |
195 | udebug_int_unlock(); |
195 | udebug_int_unlock(); |
196 | return; |
196 | return; |
197 | } |
197 | } |
198 | 198 | ||
199 | restart: |
199 | restart: |
200 | mutex_lock(&TASK->udebug.lock); |
200 | mutex_lock(&TASK->udebug.lock); |
201 | mutex_lock(&THREAD->udebug.lock); |
201 | mutex_lock(&THREAD->udebug.lock); |
202 | 202 | ||
203 | if (THREAD->udebug.debug_active && |
203 | if (THREAD->udebug.debug_active && |
204 | THREAD->udebug.stop == true) { |
204 | THREAD->udebug.stop == true) { |
205 | TASK->udebug.begin_call = NULL; |
205 | TASK->udebug.begin_call = NULL; |
206 | mutex_unlock(&THREAD->udebug.lock); |
206 | mutex_unlock(&THREAD->udebug.lock); |
207 | mutex_unlock(&TASK->udebug.lock); |
207 | mutex_unlock(&TASK->udebug.lock); |
208 | 208 | ||
209 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
209 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
210 | 210 | ||
211 | goto restart; |
211 | goto restart; |
212 | /* must try again - have to lose stoppability atomically */ |
212 | /* must try again - have to lose stoppability atomically */ |
213 | } else { |
213 | } else { |
214 | ++TASK->udebug.not_stoppable_count; |
214 | ++TASK->udebug.not_stoppable_count; |
215 | ASSERT(THREAD->udebug.stoppable == true); |
215 | ASSERT(THREAD->udebug.stoppable == true); |
216 | THREAD->udebug.stoppable = false; |
216 | THREAD->udebug.stoppable = false; |
217 | 217 | ||
218 | mutex_unlock(&THREAD->udebug.lock); |
218 | mutex_unlock(&THREAD->udebug.lock); |
219 | mutex_unlock(&TASK->udebug.lock); |
219 | mutex_unlock(&TASK->udebug.lock); |
220 | } |
220 | } |
221 | 221 | ||
222 | udebug_int_unlock(); |
222 | udebug_int_unlock(); |
223 | } |
223 | } |
224 | 224 | ||
225 | /** Upon being scheduled to run, check if the current thread should stop. |
225 | /** Upon being scheduled to run, check if the current thread should stop. |
226 | * |
226 | * |
227 | * This function is called from clock(). Preemption is enabled. |
227 | * This function is called from clock(). Preemption is enabled. |
228 | * interrupts are disabled, but since this is called after |
228 | * interrupts are disabled, but since this is called after |
229 | * being scheduled-in, we can enable them, if we're careful enough |
229 | * being scheduled-in, we can enable them, if we're careful enough |
230 | * not to allow arbitrary recursion or deadlock with the thread context. |
230 | * not to allow arbitrary recursion or deadlock with the thread context. |
231 | */ |
231 | */ |
232 | void udebug_before_thread_runs(void) |
232 | void udebug_before_thread_runs(void) |
233 | { |
233 | { |
234 | ipl_t ipl; |
234 | ipl_t ipl; |
235 | 235 | ||
236 | return; |
236 | return; |
237 | ASSERT(!PREEMPTION_DISABLED); |
237 | ASSERT(!PREEMPTION_DISABLED); |
238 | 238 | ||
239 | /* |
239 | /* |
240 | * Prevent agains re-entering, such as when preempted inside this |
240 | * Prevent agains re-entering, such as when preempted inside this |
241 | * function. |
241 | * function. |
242 | */ |
242 | */ |
243 | if (atomic_get(&THREAD->udebug.int_lock) != 0) |
243 | if (atomic_get(&THREAD->udebug.int_lock) != 0) |
244 | return; |
244 | return; |
245 | 245 | ||
246 | udebug_int_lock(); |
246 | udebug_int_lock(); |
247 | 247 | ||
248 | ipl = interrupts_enable(); |
248 | ipl = interrupts_enable(); |
249 | 249 | ||
250 | /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */ |
250 | /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */ |
251 | 251 | ||
252 | /* Check if we're supposed to stop */ |
252 | /* Check if we're supposed to stop */ |
253 | udebug_stoppable_begin(); |
253 | udebug_stoppable_begin(); |
254 | udebug_stoppable_end(); |
254 | udebug_stoppable_end(); |
255 | 255 | ||
256 | interrupts_restore(ipl); |
256 | interrupts_restore(ipl); |
257 | 257 | ||
258 | udebug_int_unlock(); |
258 | udebug_int_unlock(); |
259 | } |
259 | } |
260 | 260 | ||
261 | void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3, |
261 | void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3, |
262 | unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc, |
262 | unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc, |
263 | bool end_variant) |
263 | bool end_variant) |
264 | { |
264 | { |
265 | call_t *call; |
265 | call_t *call; |
266 | udebug_event_t etype; |
266 | udebug_event_t etype; |
267 | 267 | ||
268 | etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; |
268 | etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; |
269 | 269 | ||
270 | udebug_int_lock(); |
270 | udebug_int_lock(); |
271 | 271 | ||
272 | /* Early check for undebugged tasks */ |
272 | /* Early check for undebugged tasks */ |
273 | if (!udebug_thread_precheck()) { |
273 | if (!udebug_thread_precheck()) { |
274 | udebug_int_unlock(); |
274 | udebug_int_unlock(); |
275 | return; |
275 | return; |
276 | } |
276 | } |
277 | 277 | ||
278 | mutex_lock(&TASK->udebug.lock); |
278 | mutex_lock(&TASK->udebug.lock); |
279 | mutex_lock(&THREAD->udebug.lock); |
279 | mutex_lock(&THREAD->udebug.lock); |
280 | 280 | ||
281 | /* Must only generate events when in debugging session and have go */ |
281 | /* Must only generate events when in debugging session and have go */ |
282 | if (THREAD->udebug.debug_active != true || |
282 | if (THREAD->udebug.debug_active != true || |
283 | THREAD->udebug.stop == true || |
283 | THREAD->udebug.stop == true || |
284 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
284 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
285 | mutex_unlock(&THREAD->udebug.lock); |
285 | mutex_unlock(&THREAD->udebug.lock); |
286 | mutex_unlock(&TASK->udebug.lock); |
286 | mutex_unlock(&TASK->udebug.lock); |
287 | return; |
287 | return; |
288 | } |
288 | } |
289 | 289 | ||
290 | //printf("udebug_syscall_event\n"); |
290 | //printf("udebug_syscall_event\n"); |
291 | call = THREAD->udebug.go_call; |
291 | call = THREAD->udebug.go_call; |
292 | THREAD->udebug.go_call = NULL; |
292 | THREAD->udebug.go_call = NULL; |
293 | 293 | ||
294 | IPC_SET_RETVAL(call->data, 0); |
294 | IPC_SET_RETVAL(call->data, 0); |
295 | IPC_SET_ARG1(call->data, etype); |
295 | IPC_SET_ARG1(call->data, etype); |
296 | IPC_SET_ARG2(call->data, id); |
296 | IPC_SET_ARG2(call->data, id); |
297 | IPC_SET_ARG3(call->data, rc); |
297 | IPC_SET_ARG3(call->data, rc); |
298 | //printf("udebug_syscall_event/ipc_answer\n"); |
298 | //printf("udebug_syscall_event/ipc_answer\n"); |
299 | 299 | ||
300 | THREAD->udebug.syscall_args[0] = a1; |
300 | THREAD->udebug.syscall_args[0] = a1; |
301 | THREAD->udebug.syscall_args[1] = a2; |
301 | THREAD->udebug.syscall_args[1] = a2; |
302 | THREAD->udebug.syscall_args[2] = a3; |
302 | THREAD->udebug.syscall_args[2] = a3; |
303 | THREAD->udebug.syscall_args[3] = a4; |
303 | THREAD->udebug.syscall_args[3] = a4; |
304 | THREAD->udebug.syscall_args[4] = a5; |
304 | THREAD->udebug.syscall_args[4] = a5; |
305 | THREAD->udebug.syscall_args[5] = a6; |
305 | THREAD->udebug.syscall_args[5] = a6; |
306 | 306 | ||
307 | /* |
307 | /* |
308 | * Make sure udebug.stop is true when going to sleep |
308 | * Make sure udebug.stop is true when going to sleep |
309 | * in case we get woken up by DEBUG_END. (At which |
309 | * in case we get woken up by DEBUG_END. (At which |
310 | * point it must be back to the initial true value). |
310 | * point it must be back to the initial true value). |
311 | */ |
311 | */ |
312 | THREAD->udebug.stop = true; |
312 | THREAD->udebug.stop = true; |
313 | THREAD->udebug.cur_event = etype; |
313 | THREAD->udebug.cur_event = etype; |
314 | 314 | ||
315 | ipc_answer(&TASK->answerbox, call); |
315 | ipc_answer(&TASK->answerbox, call); |
316 | 316 | ||
317 | mutex_unlock(&THREAD->udebug.lock); |
317 | mutex_unlock(&THREAD->udebug.lock); |
318 | mutex_unlock(&TASK->udebug.lock); |
318 | mutex_unlock(&TASK->udebug.lock); |
319 | 319 | ||
320 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
320 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
321 | 321 | ||
322 | udebug_int_unlock(); |
322 | udebug_int_unlock(); |
323 | } |
323 | } |
324 | 324 | ||
325 | void udebug_thread_b_event(struct thread *t) |
325 | void udebug_thread_b_event(struct thread *t) |
326 | { |
326 | { |
327 | call_t *call; |
327 | call_t *call; |
328 | 328 | ||
329 | udebug_int_lock(); |
329 | udebug_int_lock(); |
330 | 330 | ||
331 | mutex_lock(&TASK->udebug.lock); |
331 | mutex_lock(&TASK->udebug.lock); |
332 | mutex_lock(&THREAD->udebug.lock); |
332 | mutex_lock(&THREAD->udebug.lock); |
333 | 333 | ||
334 | LOG("udebug_thread_b_event\n"); |
334 | LOG("udebug_thread_b_event\n"); |
335 | LOG("- check state\n"); |
335 | LOG("- check state\n"); |
336 | 336 | ||
337 | /* Must only generate events when in debugging session */ |
337 | /* Must only generate events when in debugging session */ |
338 | if (THREAD->udebug.debug_active != true) { |
338 | if (THREAD->udebug.debug_active != true) { |
339 | LOG("- debug_active: %s, udebug.stop: %s\n", |
339 | LOG("- debug_active: %s, udebug.stop: %s\n", |
340 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
340 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
341 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
341 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
342 | mutex_unlock(&THREAD->udebug.lock); |
342 | mutex_unlock(&THREAD->udebug.lock); |
343 | mutex_unlock(&TASK->udebug.lock); |
343 | mutex_unlock(&TASK->udebug.lock); |
344 | return; |
344 | return; |
345 | } |
345 | } |
346 | 346 | ||
347 | LOG("- trigger event\n"); |
347 | LOG("- trigger event\n"); |
348 | 348 | ||
349 | call = THREAD->udebug.go_call; |
349 | call = THREAD->udebug.go_call; |
350 | THREAD->udebug.go_call = NULL; |
350 | THREAD->udebug.go_call = NULL; |
351 | IPC_SET_RETVAL(call->data, 0); |
351 | IPC_SET_RETVAL(call->data, 0); |
352 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B); |
352 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B); |
353 | IPC_SET_ARG2(call->data, (unative_t)t); |
353 | IPC_SET_ARG2(call->data, (unative_t)t); |
354 | 354 | ||
355 | /* |
355 | /* |
356 | * Make sure udebug.stop is true when going to sleep |
356 | * Make sure udebug.stop is true when going to sleep |
357 | * in case we get woken up by DEBUG_END. (At which |
357 | * in case we get woken up by DEBUG_END. (At which |
358 | * point it must be back to the initial true value). |
358 | * point it must be back to the initial true value). |
359 | */ |
359 | */ |
360 | THREAD->udebug.stop = true; |
360 | THREAD->udebug.stop = true; |
361 | THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; |
361 | THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; |
362 | 362 | ||
363 | ipc_answer(&TASK->answerbox, call); |
363 | ipc_answer(&TASK->answerbox, call); |
364 | 364 | ||
365 | mutex_unlock(&THREAD->udebug.lock); |
365 | mutex_unlock(&THREAD->udebug.lock); |
366 | mutex_unlock(&TASK->udebug.lock); |
366 | mutex_unlock(&TASK->udebug.lock); |
367 | 367 | ||
368 | LOG("- sleep\n"); |
368 | LOG("- sleep\n"); |
369 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
369 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
370 | 370 | ||
371 | udebug_int_unlock(); |
371 | udebug_int_unlock(); |
372 | } |
372 | } |
373 | 373 | ||
374 | void udebug_thread_e_event(void) |
374 | void udebug_thread_e_event(void) |
375 | { |
375 | { |
376 | call_t *call; |
376 | call_t *call; |
377 | 377 | ||
378 | udebug_int_lock(); |
378 | udebug_int_lock(); |
379 | 379 | ||
380 | mutex_lock(&TASK->udebug.lock); |
380 | mutex_lock(&TASK->udebug.lock); |
381 | mutex_lock(&THREAD->udebug.lock); |
381 | mutex_lock(&THREAD->udebug.lock); |
382 | 382 | ||
383 | LOG("udebug_thread_e_event\n"); |
383 | LOG("udebug_thread_e_event\n"); |
384 | LOG("- check state\n"); |
384 | LOG("- check state\n"); |
385 | 385 | ||
386 | /* Must only generate events when in debugging session */ |
386 | /* Must only generate events when in debugging session */ |
387 | if (THREAD->udebug.debug_active != true) { |
387 | if (THREAD->udebug.debug_active != true) { |
388 | /* printf("- debug_active: %s, udebug.stop: %s\n", |
388 | /* printf("- debug_active: %s, udebug.stop: %s\n", |
389 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
389 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
390 | THREAD->udebug.stop ? "yes(-)" : "no(+)");*/ |
390 | THREAD->udebug.stop ? "yes(-)" : "no(+)");*/ |
391 | mutex_unlock(&THREAD->udebug.lock); |
391 | mutex_unlock(&THREAD->udebug.lock); |
392 | mutex_unlock(&TASK->udebug.lock); |
392 | mutex_unlock(&TASK->udebug.lock); |
393 | return; |
393 | return; |
394 | } |
394 | } |
395 | 395 | ||
396 | LOG("- trigger event\n"); |
396 | LOG("- trigger event\n"); |
397 | 397 | ||
398 | call = THREAD->udebug.go_call; |
398 | call = THREAD->udebug.go_call; |
399 | THREAD->udebug.go_call = NULL; |
399 | THREAD->udebug.go_call = NULL; |
400 | IPC_SET_RETVAL(call->data, 0); |
400 | IPC_SET_RETVAL(call->data, 0); |
401 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E); |
401 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E); |
402 | 402 | ||
403 | /* Prevent any further debug activity in thread */ |
403 | /* Prevent any further debug activity in thread */ |
404 | THREAD->udebug.debug_active = false; |
404 | THREAD->udebug.debug_active = false; |
405 | THREAD->udebug.cur_event = 0; /* none */ |
405 | THREAD->udebug.cur_event = 0; /* none */ |
406 | THREAD->udebug.stop = true; /* set to initial value */ |
406 | THREAD->udebug.stop = true; /* set to initial value */ |
407 | 407 | ||
408 | ipc_answer(&TASK->answerbox, call); |
408 | ipc_answer(&TASK->answerbox, call); |
409 | 409 | ||
410 | mutex_unlock(&THREAD->udebug.lock); |
410 | mutex_unlock(&THREAD->udebug.lock); |
411 | mutex_unlock(&TASK->udebug.lock); |
411 | mutex_unlock(&TASK->udebug.lock); |
412 | 412 | ||
413 | /* Leave int_lock enabled */ |
413 | /* Leave int_lock enabled */ |
414 | /* This event does not sleep - debugging has finished in this thread */ |
414 | /* This event does not sleep - debugging has finished in this thread */ |
415 | } |
415 | } |
416 | 416 | ||
417 | /** |
417 | /** |
418 | * Terminate task debugging session. |
418 | * Terminate task debugging session. |
419 | * |
419 | * |
420 | * \param ta->udebug.lock must be already locked. |
420 | * \param ta->udebug.lock must be already locked. |
421 | * \return Zero on success or negative error code. |
421 | * \return Zero on success or negative error code. |
422 | */ |
422 | */ |
423 | int udebug_task_cleanup(struct task *ta) |
423 | int udebug_task_cleanup(struct task *ta) |
424 | { |
424 | { |
425 | thread_t *t; |
425 | thread_t *t; |
426 | link_t *cur; |
426 | link_t *cur; |
427 | int flags; |
427 | int flags; |
428 | ipl_t ipl; |
428 | ipl_t ipl; |
429 | 429 | ||
430 | LOG("udebug_task_cleanup()\n"); |
430 | LOG("udebug_task_cleanup()\n"); |
431 | LOG("task %" PRIu64 "\n", ta->taskid); |
431 | LOG("task %" PRIu64 "\n", ta->taskid); |
432 | 432 | ||
433 | udebug_int_lock(); |
433 | udebug_int_lock(); |
434 | 434 | ||
435 | if (ta->udebug.dt_state != UDEBUG_TS_BEGINNING && |
435 | if (ta->udebug.dt_state != UDEBUG_TS_BEGINNING && |
436 | ta->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
436 | ta->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
437 | LOG("udebug_task_cleanup(): task not being debugged\n"); |
437 | LOG("udebug_task_cleanup(): task not being debugged\n"); |
438 | return EINVAL; |
438 | return EINVAL; |
439 | } |
439 | } |
440 | 440 | ||
441 | /* Finish debugging of all userspace threads */ |
441 | /* Finish debugging of all userspace threads */ |
442 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
442 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
443 | t = list_get_instance(cur, thread_t, th_link); |
443 | t = list_get_instance(cur, thread_t, th_link); |
444 | 444 | ||
445 | mutex_lock(&t->udebug.lock); |
445 | mutex_lock(&t->udebug.lock); |
446 | 446 | ||
447 | ipl = interrupts_disable(); |
447 | ipl = interrupts_disable(); |
448 | spinlock_lock(&t->lock); |
448 | spinlock_lock(&t->lock); |
449 | 449 | ||
450 | flags = t->flags; |
450 | flags = t->flags; |
451 | 451 | ||
452 | spinlock_unlock(&t->lock); |
452 | spinlock_unlock(&t->lock); |
453 | interrupts_restore(ipl); |
453 | interrupts_restore(ipl); |
454 | 454 | ||
455 | /* Only process userspace threads */ |
455 | /* Only process userspace threads */ |
456 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
456 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
457 | /* Prevent any further debug activity in thread */ |
457 | /* Prevent any further debug activity in thread */ |
458 | t->udebug.debug_active = false; |
458 | t->udebug.debug_active = false; |
459 | t->udebug.cur_event = 0; /* none */ |
459 | t->udebug.cur_event = 0; /* none */ |
460 | 460 | ||
461 | /* Still has go? */ |
461 | /* Still has go? */ |
462 | if (t->udebug.stop == false) { |
462 | if (t->udebug.stop == false) { |
463 | /* |
463 | /* |
464 | * Yes, so clear go. As debug_active == false, |
464 | * Yes, so clear go. As debug_active == false, |
465 | * this doesn't affect anything. |
465 | * this doesn't affect anything. |
466 | */ |
466 | */ |
467 | t->udebug.stop = true; |
467 | t->udebug.stop = true; |
468 | 468 | ||
469 | /* Answer GO call */ |
469 | /* Answer GO call */ |
470 | LOG("answer GO call with EVENT_FINISHED\n"); |
470 | LOG("answer GO call with EVENT_FINISHED\n"); |
471 | IPC_SET_RETVAL(t->udebug.go_call->data, 0); |
471 | IPC_SET_RETVAL(t->udebug.go_call->data, 0); |
472 | IPC_SET_ARG1(t->udebug.go_call->data, UDEBUG_EVENT_FINISHED); |
472 | IPC_SET_ARG1(t->udebug.go_call->data, UDEBUG_EVENT_FINISHED); |
473 | 473 | ||
474 | ipc_answer(&ta->answerbox, t->udebug.go_call); |
474 | ipc_answer(&ta->answerbox, t->udebug.go_call); |
475 | t->udebug.go_call = NULL; |
475 | t->udebug.go_call = NULL; |
476 | } else { |
476 | } else { |
477 | /* |
477 | /* |
478 | * Debug_stop is already at initial value. |
478 | * Debug_stop is already at initial value. |
479 | * Yet this means the thread needs waking up. |
479 | * Yet this means the thread needs waking up. |
480 | */ |
480 | */ |
481 | 481 | ||
482 | /* |
482 | /* |
483 | * t's lock must not be held when calling |
483 | * t's lock must not be held when calling |
484 | * waitq_wakeup. |
484 | * waitq_wakeup. |
485 | */ |
485 | */ |
486 | waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST); |
486 | waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST); |
487 | } |
487 | } |
488 | } |
488 | } |
489 | mutex_unlock(&t->udebug.lock); |
489 | mutex_unlock(&t->udebug.lock); |
490 | } |
490 | } |
491 | 491 | ||
492 | ta->udebug.dt_state = UDEBUG_TS_INACTIVE; |
492 | ta->udebug.dt_state = UDEBUG_TS_INACTIVE; |
493 | ta->udebug.debugger = NULL; |
493 | ta->udebug.debugger = NULL; |
494 | 494 | ||
495 | udebug_int_unlock(); |
495 | udebug_int_unlock(); |
496 | 496 | ||
497 | return 0; |
497 | return 0; |
498 | } |
498 | } |
499 | 499 | ||
500 | 500 | ||
501 | /** @} |
501 | /** @} |
502 | */ |
502 | */ |
503 | 503 |