Rev 3018 | Rev 3030 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3018 | Rev 3026 | ||
|---|---|---|---|
| Line 39... | Line 39... | ||
| 39 | #include <console/klog.h> |
39 | #include <console/klog.h> |
| 40 | #include <udebug/udebug.h> |
40 | #include <udebug/udebug.h> |
| 41 | #include <errno.h> |
41 | #include <errno.h> |
| 42 | #include <arch.h> |
42 | #include <arch.h> |
| 43 | 43 | ||
| - | 44 | /* |
|
| - | 45 | * FIXME: Don't grab TASK->udebug.lock in this module, synchronize |
|
| - | 46 | * only with THREAD->udebug.lock. |
|
| - | 47 | * |
|
| - | 48 | * For this reason, TASK->udebug.lock is not guarded against the interrupt |
|
| - | 49 | * handler in udebug_ops.c. (which could deadlock) |
|
| - | 50 | */ |
|
| - | 51 | ||
| - | 52 | static inline void udebug_int_lock(void) |
|
| - | 53 | { |
|
| - | 54 | atomic_inc(&THREAD->udebug.int_lock); |
|
| - | 55 | } |
|
| - | 56 | ||
| - | 57 | static inline void udebug_int_unlock(void) |
|
| - | 58 | { |
|
| - | 59 | atomic_dec(&THREAD->udebug.int_lock); |
|
| - | 60 | } |
|
| - | 61 | ||
| 44 | void udebug_task_init(udebug_task_t *ut) |
62 | void udebug_task_init(udebug_task_t *ut) |
| 45 | { |
63 | { |
| 46 | mutex_initialize(&ut->lock); |
64 | mutex_initialize(&ut->lock); |
| 47 | ut->dt_state = UDEBUG_TS_INACTIVE; |
65 | ut->dt_state = UDEBUG_TS_INACTIVE; |
| 48 | ut->begin_call = NULL; |
66 | ut->begin_call = NULL; |
| Line 50... | Line 68... | ||
| 50 | ut->evmask = 0; |
68 | ut->evmask = 0; |
| 51 | } |
69 | } |
| 52 | 70 | ||
| 53 | void udebug_thread_initialize(udebug_thread_t *ut) |
71 | void udebug_thread_initialize(udebug_thread_t *ut) |
| 54 | { |
72 | { |
| - | 73 | mutex_initialize(&ut->lock); |
|
| 55 | waitq_initialize(&ut->go_wq); |
74 | waitq_initialize(&ut->go_wq); |
| - | 75 | ||
| - | 76 | /* |
|
| - | 77 | * At the beginning the thread is stoppable, so int_lock be set, too. |
|
| - | 78 | */ |
|
| - | 79 | atomic_set(&ut->int_lock, 1); |
|
| - | 80 | ||
| 56 | ut->go_call = NULL; |
81 | ut->go_call = NULL; |
| 57 | ut->uspace_state = NULL; |
82 | ut->uspace_state = NULL; |
| 58 | ut->stop = true; |
83 | ut->stop = true; |
| 59 | ut->stoppable = true; |
84 | ut->stoppable = true; |
| 60 | ut->debug_active = false; |
85 | ut->debug_active = false; |
| Line 76... | Line 101... | ||
| 76 | 101 | ||
| 77 | void udebug_stoppable_begin(void) |
102 | void udebug_stoppable_begin(void) |
| 78 | { |
103 | { |
| 79 | int nsc; |
104 | int nsc; |
| 80 | call_t *db_call, *go_call; |
105 | call_t *db_call, *go_call; |
| 81 | ipl_t ipl; |
- | |
| 82 | 106 | ||
| 83 | ASSERT(THREAD); |
107 | ASSERT(THREAD); |
| 84 | ASSERT(TASK); |
108 | ASSERT(TASK); |
| 85 | 109 | ||
| - | 110 | udebug_int_lock(); |
|
| - | 111 | ||
| 86 | mutex_lock(&TASK->udebug.lock); |
112 | mutex_lock(&TASK->udebug.lock); |
| 87 | 113 | ||
| 88 | nsc = --TASK->udebug.not_stoppable_count; |
114 | nsc = --TASK->udebug.not_stoppable_count; |
| 89 | 115 | ||
| 90 | if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING) { |
116 | if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING) { |
| Line 100... | Line 126... | ||
| 100 | 126 | ||
| 101 | db_call = TASK->udebug.begin_call; |
127 | db_call = TASK->udebug.begin_call; |
| 102 | ASSERT(db_call); |
128 | ASSERT(db_call); |
| 103 | 129 | ||
| 104 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
130 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
| 105 | ipl = interrupts_disable(); |
131 | mutex_lock(&THREAD->udebug.lock); |
| 106 | spinlock_lock(&THREAD->udebug.lock); |
132 | ASSERT(THREAD->udebug.stoppable == false); |
| 107 | THREAD->udebug.stoppable = true; |
133 | THREAD->udebug.stoppable = true; |
| 108 | spinlock_unlock(&THREAD->udebug.lock); |
134 | mutex_unlock(&THREAD->udebug.lock); |
| 109 | interrupts_restore(ipl); |
- | |
| 110 | 135 | ||
| 111 | TASK->udebug.dt_state = UDEBUG_TS_ACTIVE; |
136 | TASK->udebug.dt_state = UDEBUG_TS_ACTIVE; |
| 112 | TASK->udebug.begin_call = NULL; |
137 | TASK->udebug.begin_call = NULL; |
| 113 | mutex_unlock(&TASK->udebug.lock); |
138 | mutex_unlock(&TASK->udebug.lock); |
| 114 | 139 | ||
| Line 120... | Line 145... | ||
| 120 | /* |
145 | /* |
| 121 | * Active debugging session |
146 | * Active debugging session |
| 122 | */ |
147 | */ |
| 123 | 148 | ||
| 124 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
149 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
| 125 | ipl = interrupts_disable(); |
150 | mutex_lock(&THREAD->udebug.lock); |
| 126 | spinlock_lock(&THREAD->udebug.lock); |
151 | ASSERT(THREAD->udebug.stoppable == false); |
| 127 | THREAD->udebug.stoppable = true; |
152 | THREAD->udebug.stoppable = true; |
| 128 | 153 | ||
| 129 | if (THREAD->udebug.debug_active && THREAD->udebug.stop) { |
154 | if (THREAD->udebug.debug_active && THREAD->udebug.stop) { |
| 130 | /* |
155 | /* |
| 131 | * Thread was requested to stop - answer go call |
156 | * Thread was requested to stop - answer go call |
| Line 138... | Line 163... | ||
| 138 | 163 | ||
| 139 | IPC_SET_RETVAL(go_call->data, 0); |
164 | IPC_SET_RETVAL(go_call->data, 0); |
| 140 | IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP); |
165 | IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP); |
| 141 | 166 | ||
| 142 | THREAD->udebug.cur_event = UDEBUG_EVENT_STOP; |
167 | THREAD->udebug.cur_event = UDEBUG_EVENT_STOP; |
| 143 | spinlock_unlock(&THREAD->udebug.lock); |
168 | mutex_unlock(&THREAD->udebug.lock); |
| 144 | interrupts_restore(ipl); |
- | |
| 145 | 169 | ||
| 146 | ipc_answer(&TASK->answerbox, go_call); |
170 | ipc_answer(&TASK->answerbox, go_call); |
| 147 | 171 | ||
| 148 | mutex_unlock(&TASK->udebug.lock); |
172 | mutex_unlock(&TASK->udebug.lock); |
| 149 | } else { |
173 | } else { |
| 150 | /* |
174 | /* |
| 151 | * No stop request - nothing happens. |
175 | * No stop request - nothing happens. |
| 152 | */ |
176 | */ |
| 153 | spinlock_unlock(&THREAD->udebug.lock); |
177 | mutex_unlock(&THREAD->udebug.lock); |
| 154 | interrupts_restore(ipl); |
- | |
| 155 | mutex_unlock(&TASK->udebug.lock); |
178 | mutex_unlock(&TASK->udebug.lock); |
| 156 | } |
179 | } |
| 157 | } else { |
180 | } else { |
| 158 | /* |
181 | /* |
| 159 | * All other cases - nothing special happens. |
182 | * All other cases - nothing special happens. |
| 160 | */ |
183 | */ |
| 161 | 184 | ||
| 162 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
185 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
| 163 | ipl = interrupts_disable(); |
186 | mutex_lock(&THREAD->udebug.lock); |
| 164 | spinlock_lock(&THREAD->udebug.lock); |
187 | ASSERT(THREAD->udebug.stoppable == false); |
| 165 | THREAD->udebug.stoppable = true; |
188 | THREAD->udebug.stoppable = true; |
| 166 | spinlock_unlock(&THREAD->udebug.lock); |
189 | mutex_unlock(&THREAD->udebug.lock); |
| 167 | interrupts_restore(ipl); |
- | |
| 168 | 190 | ||
| 169 | mutex_unlock(&TASK->udebug.lock); |
191 | mutex_unlock(&TASK->udebug.lock); |
| 170 | } |
192 | } |
| 171 | } |
193 | } |
| 172 | 194 | ||
| 173 | void udebug_stoppable_end(void) |
195 | void udebug_stoppable_end(void) |
| 174 | { |
196 | { |
| 175 | ipl_t ipl; |
- | |
| 176 | - | ||
| 177 | restart: |
197 | restart: |
| 178 | mutex_lock(&TASK->udebug.lock); |
198 | mutex_lock(&TASK->udebug.lock); |
| 179 | 199 | ||
| 180 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
200 | /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ |
| 181 | ipl = interrupts_disable(); |
- | |
| 182 | spinlock_lock(&THREAD->udebug.lock); |
201 | mutex_lock(&THREAD->udebug.lock); |
| 183 | 202 | ||
| 184 | if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) { |
203 | if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) { |
| 185 | //klog_printf("udebug_stoppable_end"); |
204 | //klog_printf("udebug_stoppable_end"); |
| 186 | //klog_printf("udebug.stop=%d", THREAD->udebug.stop); |
205 | //klog_printf("udebug.stop=%d", THREAD->udebug.stop); |
| 187 | } |
206 | } |
| 188 | 207 | ||
| 189 | if (THREAD->udebug.debug_active && |
208 | if (THREAD->udebug.debug_active && |
| 190 | THREAD->udebug.stop == true) { |
209 | THREAD->udebug.stop == true) { |
| 191 | TASK->udebug.begin_call = NULL; |
210 | TASK->udebug.begin_call = NULL; |
| 192 | spinlock_unlock(&THREAD->udebug.lock); |
211 | mutex_unlock(&THREAD->udebug.lock); |
| 193 | interrupts_restore(ipl); |
- | |
| 194 | mutex_unlock(&TASK->udebug.lock); |
212 | mutex_unlock(&TASK->udebug.lock); |
| 195 | 213 | ||
| 196 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
214 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| 197 | 215 | ||
| 198 | goto restart; |
216 | goto restart; |
| 199 | /* must try again - have to lose stoppability atomically */ |
217 | /* must try again - have to lose stoppability atomically */ |
| 200 | } else { |
218 | } else { |
| 201 | ++TASK->udebug.not_stoppable_count; |
219 | ++TASK->udebug.not_stoppable_count; |
| - | 220 | ASSERT(THREAD->udebug.stoppable == true); |
|
| 202 | THREAD->udebug.stoppable = false; |
221 | THREAD->udebug.stoppable = false; |
| 203 | 222 | ||
| 204 | spinlock_unlock(&THREAD->udebug.lock); |
223 | mutex_unlock(&THREAD->udebug.lock); |
| 205 | interrupts_restore(ipl); |
- | |
| 206 | mutex_unlock(&TASK->udebug.lock); |
224 | mutex_unlock(&TASK->udebug.lock); |
| 207 | } |
225 | } |
| - | 226 | ||
| - | 227 | udebug_int_unlock(); |
|
| 208 | } |
228 | } |
| 209 | 229 | ||
| 210 | /** Upon being scheduled to run, check if the current thread should stop. |
230 | /** Upon being scheduled to run, check if the current thread should stop. |
| 211 | * |
231 | * |
| 212 | * This function is called from clock(). Preemption is enabled. |
232 | * This function is called from clock(). Preemption is enabled. |
| 213 | * interrupts are disabled, but since this is called after |
233 | * interrupts are disabled, but since this is called after |
| 214 | * being scheduled-in, we can enable them, if we're careful enough |
234 | * being scheduled-in, we can enable them, if we're careful enough |
| 215 | * not to allow arbitrary recursion. |
235 | * not to allow arbitrary recursion or deadlock with the thread context. |
| 216 | */ |
236 | */ |
| 217 | void udebug_before_thread_runs(void) |
237 | void udebug_before_thread_runs(void) |
| 218 | { |
238 | { |
| 219 | ipl_t ipl; |
239 | ipl_t ipl; |
| 220 | 240 | ||
| - | 241 | ASSERT(!PREEMPTION_DISABLED); |
|
| - | 242 | ||
| - | 243 | /* |
|
| 221 | /* This will happen if we get preempted inside this function. */ |
244 | * Prevent agains re-entering, such as when preempted inside this |
| - | 245 | * function. |
|
| - | 246 | */ |
|
| 222 | if (THREAD->udebug.in_before_thread_runs) |
247 | if (atomic_get(&THREAD->udebug.int_lock) != 0) |
| 223 | return; |
248 | return; |
| 224 | 249 | ||
| 225 | THREAD->udebug.in_before_thread_runs = true; |
250 | udebug_int_lock(); |
| - | 251 | ||
| 226 | ipl = interrupts_enable(); |
252 | ipl = interrupts_enable(); |
| 227 | 253 | ||
| 228 | /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */ |
254 | /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */ |
| 229 | 255 | ||
| 230 | /* Check if we're supposed to stop */ |
256 | /* Check if we're supposed to stop */ |
| 231 | udebug_stoppable_begin(); |
257 | udebug_stoppable_begin(); |
| 232 | udebug_stoppable_end(); |
258 | udebug_stoppable_end(); |
| 233 | 259 | ||
| 234 | interrupts_restore(ipl); |
260 | interrupts_restore(ipl); |
| - | 261 | ||
| 235 | THREAD->udebug.in_before_thread_runs = false; |
262 | udebug_int_unlock(); |
| 236 | } |
263 | } |
| 237 | 264 | ||
| 238 | void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3, |
265 | void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3, |
| 239 | unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc, |
266 | unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc, |
| 240 | bool end_variant) |
267 | bool end_variant) |
| 241 | { |
268 | { |
| 242 | call_t *call; |
269 | call_t *call; |
| 243 | ipl_t ipl; |
- | |
| 244 | udebug_event_t etype; |
270 | udebug_event_t etype; |
| 245 | 271 | ||
| 246 | etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; |
272 | etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; |
| 247 | 273 | ||
| 248 | mutex_lock(&TASK->udebug.lock); |
274 | udebug_int_lock(); |
| 249 | 275 | ||
| 250 | ipl = interrupts_disable(); |
276 | mutex_lock(&TASK->udebug.lock); |
| 251 | spinlock_lock(&THREAD->udebug.lock); |
277 | mutex_lock(&THREAD->udebug.lock); |
| 252 | 278 | ||
| 253 | /* Must only generate events when in debugging session and have go */ |
279 | /* Must only generate events when in debugging session and have go */ |
| 254 | if (THREAD->udebug.debug_active != true || |
280 | if (THREAD->udebug.debug_active != true || |
| 255 | THREAD->udebug.stop == true || |
281 | THREAD->udebug.stop == true || |
| 256 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
282 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
| 257 | spinlock_unlock(&THREAD->udebug.lock); |
283 | mutex_unlock(&THREAD->udebug.lock); |
| 258 | interrupts_restore(ipl); |
- | |
| 259 | mutex_unlock(&TASK->udebug.lock); |
284 | mutex_unlock(&TASK->udebug.lock); |
| 260 | return; |
285 | return; |
| 261 | } |
286 | } |
| 262 | 287 | ||
| 263 | //klog_printf("udebug_syscall_event"); |
288 | //klog_printf("udebug_syscall_event"); |
| Line 283... | Line 308... | ||
| 283 | * point it must be back to the initial true value). |
308 | * point it must be back to the initial true value). |
| 284 | */ |
309 | */ |
| 285 | THREAD->udebug.stop = true; |
310 | THREAD->udebug.stop = true; |
| 286 | 311 | ||
| 287 | THREAD->udebug.cur_event = etype; |
312 | THREAD->udebug.cur_event = etype; |
| 288 | spinlock_unlock(&THREAD->udebug.lock); |
313 | mutex_unlock(&THREAD->udebug.lock); |
| 289 | interrupts_restore(ipl); |
- | |
| 290 | 314 | ||
| 291 | ipc_answer(&TASK->answerbox, call); |
315 | ipc_answer(&TASK->answerbox, call); |
| 292 | 316 | ||
| 293 | mutex_unlock(&TASK->udebug.lock); |
317 | mutex_unlock(&TASK->udebug.lock); |
| 294 | 318 | ||
| 295 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
319 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| - | 320 | ||
| - | 321 | udebug_int_unlock(); |
|
| 296 | } |
322 | } |
| 297 | 323 | ||
| 298 | void udebug_thread_b_event(struct thread *t) |
324 | void udebug_thread_b_event(struct thread *t) |
| 299 | { |
325 | { |
| 300 | call_t *call; |
326 | call_t *call; |
| 301 | ipl_t ipl; |
- | |
| 302 | 327 | ||
| 303 | mutex_lock(&TASK->udebug.lock); |
328 | udebug_int_lock(); |
| 304 | 329 | ||
| 305 | ipl = interrupts_disable(); |
330 | mutex_lock(&TASK->udebug.lock); |
| 306 | spinlock_lock(&THREAD->udebug.lock); |
331 | mutex_lock(&THREAD->udebug.lock); |
| 307 | 332 | ||
| 308 | klog_printf("udebug_thread_b_event"); |
333 | klog_printf("udebug_thread_b_event"); |
| 309 | klog_printf("- check state"); |
334 | klog_printf("- check state"); |
| 310 | 335 | ||
| 311 | /* Must only generate events when in debugging session */ |
336 | /* Must only generate events when in debugging session */ |
| 312 | if (THREAD->udebug.debug_active != true) { |
337 | if (THREAD->udebug.debug_active != true) { |
| 313 | klog_printf("- debug_active: %s, udebug.stop: %s", |
338 | klog_printf("- debug_active: %s, udebug.stop: %s", |
| 314 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
339 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
| 315 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
340 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
| 316 | spinlock_unlock(&THREAD->udebug.lock); |
341 | mutex_unlock(&THREAD->udebug.lock); |
| 317 | interrupts_restore(ipl); |
- | |
| 318 | mutex_unlock(&TASK->udebug.lock); |
342 | mutex_unlock(&TASK->udebug.lock); |
| 319 | return; |
343 | return; |
| 320 | } |
344 | } |
| 321 | 345 | ||
| 322 | klog_printf("- trigger event"); |
346 | klog_printf("- trigger event"); |
| Line 333... | Line 357... | ||
| 333 | * point it must be back to the initial true value). |
357 | * point it must be back to the initial true value). |
| 334 | */ |
358 | */ |
| 335 | THREAD->udebug.stop = true; |
359 | THREAD->udebug.stop = true; |
| 336 | 360 | ||
| 337 | THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; |
361 | THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; |
| 338 | spinlock_unlock(&THREAD->udebug.lock); |
362 | mutex_unlock(&THREAD->udebug.lock); |
| 339 | interrupts_restore(ipl); |
- | |
| 340 | 363 | ||
| 341 | ipc_answer(&TASK->answerbox, call); |
364 | ipc_answer(&TASK->answerbox, call); |
| 342 | 365 | ||
| 343 | mutex_unlock(&TASK->udebug.lock); |
366 | mutex_unlock(&TASK->udebug.lock); |
| 344 | 367 | ||
| 345 | klog_printf("- sleep"); |
368 | klog_printf("- sleep"); |
| 346 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
369 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| - | 370 | ||
| - | 371 | udebug_int_unlock(); |
|
| 347 | } |
372 | } |
| 348 | 373 | ||
| 349 | void udebug_thread_e_event(void) |
374 | void udebug_thread_e_event(void) |
| 350 | { |
375 | { |
| 351 | call_t *call; |
376 | call_t *call; |
| 352 | ipl_t ipl; |
- | |
| 353 | 377 | ||
| 354 | mutex_lock(&TASK->udebug.lock); |
378 | udebug_int_lock(); |
| 355 | 379 | ||
| 356 | ipl = interrupts_disable(); |
380 | mutex_lock(&TASK->udebug.lock); |
| 357 | spinlock_lock(&THREAD->udebug.lock); |
381 | mutex_lock(&THREAD->udebug.lock); |
| 358 | 382 | ||
| 359 | klog_printf("udebug_thread_e_event"); |
383 | klog_printf("udebug_thread_e_event"); |
| 360 | klog_printf("- check state"); |
384 | klog_printf("- check state"); |
| 361 | 385 | ||
| 362 | /* Must only generate events when in debugging session */ |
386 | /* Must only generate events when in debugging session */ |
| 363 | if (THREAD->udebug.debug_active != true) { |
387 | if (THREAD->udebug.debug_active != true) { |
| 364 | klog_printf("- debug_active: %s, udebug.stop: %s", |
388 | klog_printf("- debug_active: %s, udebug.stop: %s", |
| 365 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
389 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
| 366 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
390 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
| 367 | spinlock_unlock(&THREAD->udebug.lock); |
391 | mutex_unlock(&THREAD->udebug.lock); |
| 368 | interrupts_restore(ipl); |
- | |
| 369 | mutex_unlock(&TASK->udebug.lock); |
392 | mutex_unlock(&TASK->udebug.lock); |
| 370 | return; |
393 | return; |
| 371 | } |
394 | } |
| 372 | 395 | ||
| 373 | klog_printf("- trigger event"); |
396 | klog_printf("- trigger event"); |
| Line 380... | Line 403... | ||
| 380 | /* Prevent any further debug activity in thread */ |
403 | /* Prevent any further debug activity in thread */ |
| 381 | THREAD->udebug.debug_active = false; |
404 | THREAD->udebug.debug_active = false; |
| 382 | THREAD->udebug.cur_event = 0; /* none */ |
405 | THREAD->udebug.cur_event = 0; /* none */ |
| 383 | THREAD->udebug.stop = true; /* set to initial value */ |
406 | THREAD->udebug.stop = true; /* set to initial value */ |
| 384 | 407 | ||
| 385 | spinlock_unlock(&THREAD->udebug.lock); |
408 | mutex_unlock(&THREAD->udebug.lock); |
| 386 | interrupts_restore(ipl); |
- | |
| 387 | 409 | ||
| 388 | ipc_answer(&TASK->answerbox, call); |
410 | ipc_answer(&TASK->answerbox, call); |
| 389 | 411 | ||
| 390 | mutex_unlock(&TASK->udebug.lock); |
412 | mutex_unlock(&TASK->udebug.lock); |
| 391 | 413 | ||
| - | 414 | /* Leave int_lock enabled */ |
|
| 392 | /* This event does not sleep - debugging has finished in this thread */ |
415 | /* This event does not sleep - debugging has finished in this thread */ |
| 393 | } |
416 | } |
| 394 | 417 | ||
| 395 | static void breakpoint_trap_event(uintptr_t addr, udebug_event_t etype) |
418 | static void breakpoint_trap_event(uintptr_t addr, udebug_event_t etype) |
| 396 | { |
419 | { |
| 397 | call_t *call; |
420 | call_t *call; |
| 398 | ipl_t ipl; |
- | |
| 399 | 421 | ||
| 400 | mutex_lock(&TASK->udebug.lock); |
422 | udebug_int_lock(); |
| 401 | 423 | ||
| 402 | ipl = interrupts_disable(); |
424 | mutex_lock(&TASK->udebug.lock); |
| 403 | spinlock_lock(&THREAD->udebug.lock); |
425 | mutex_lock(&THREAD->udebug.lock); |
| 404 | 426 | ||
| 405 | /* Must only generate events when in debugging session and have go */ |
427 | /* Must only generate events when in debugging session and have go */ |
| 406 | if (THREAD->udebug.debug_active != true || |
428 | if (THREAD->udebug.debug_active != true || |
| 407 | THREAD->udebug.stop == true || |
429 | THREAD->udebug.stop == true || |
| 408 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
430 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
| 409 | spinlock_unlock(&THREAD->udebug.lock); |
431 | mutex_unlock(&THREAD->udebug.lock); |
| 410 | interrupts_restore(ipl); |
- | |
| 411 | mutex_unlock(&TASK->udebug.lock); |
432 | mutex_unlock(&TASK->udebug.lock); |
| 412 | return; |
433 | return; |
| 413 | } |
434 | } |
| 414 | 435 | ||
| 415 | klog_printf("udebug_breakpoint/trap_event"); |
436 | klog_printf("udebug_breakpoint/trap_event"); |
| Line 426... | Line 447... | ||
| 426 | * point it must be back to the initial true value). |
447 | * point it must be back to the initial true value). |
| 427 | */ |
448 | */ |
| 428 | THREAD->udebug.stop = true; |
449 | THREAD->udebug.stop = true; |
| 429 | 450 | ||
| 430 | THREAD->udebug.cur_event = etype; |
451 | THREAD->udebug.cur_event = etype; |
| 431 | spinlock_unlock(&THREAD->udebug.lock); |
452 | mutex_unlock(&THREAD->udebug.lock); |
| 432 | interrupts_restore(ipl); |
- | |
| - | 453 | ||
| 433 | klog_printf("- send answer"); |
454 | klog_printf("- send answer"); |
| 434 | 455 | ||
| 435 | ipc_answer(&TASK->answerbox, call); |
456 | ipc_answer(&TASK->answerbox, call); |
| 436 | mutex_unlock(&TASK->udebug.lock); |
457 | mutex_unlock(&TASK->udebug.lock); |
| 437 | 458 | ||
| 438 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
459 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| - | 460 | ||
| - | 461 | udebug_int_unlock(); |
|
| 439 | } |
462 | } |
| 440 | 463 | ||
| 441 | void udebug_breakpoint_event(uintptr_t addr) |
464 | void udebug_breakpoint_event(uintptr_t addr) |
| 442 | { |
465 | { |
| 443 | breakpoint_trap_event(addr, UDEBUG_EVENT_BREAKPOINT); |
466 | breakpoint_trap_event(addr, UDEBUG_EVENT_BREAKPOINT); |
| Line 462... | Line 485... | ||
| 462 | ipl_t ipl; |
485 | ipl_t ipl; |
| 463 | 486 | ||
| 464 | klog_printf("udebug_task_cleanup()"); |
487 | klog_printf("udebug_task_cleanup()"); |
| 465 | klog_printf("task %llu", ta->taskid); |
488 | klog_printf("task %llu", ta->taskid); |
| 466 | 489 | ||
| - | 490 | udebug_int_lock(); |
|
| - | 491 | ||
| 467 | if (ta->udebug.dt_state == UDEBUG_TS_BEGINNING && |
492 | if (ta->udebug.dt_state == UDEBUG_TS_BEGINNING && |
| 468 | ta->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
493 | ta->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
| 469 | klog_printf("udebug_task_cleanup(): task not being debugged"); |
494 | klog_printf("udebug_task_cleanup(): task not being debugged"); |
| 470 | return EINVAL; |
495 | return EINVAL; |
| 471 | } |
496 | } |
| 472 | 497 | ||
| 473 | /* Finish debugging of all userspace threads */ |
498 | /* Finish debugging of all userspace threads */ |
| 474 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
499 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
| 475 | t = list_get_instance(cur, thread_t, th_link); |
500 | t = list_get_instance(cur, thread_t, th_link); |
| 476 | 501 | ||
| - | 502 | mutex_lock(&t->udebug.lock); |
|
| - | 503 | ||
| 477 | ipl = interrupts_disable(); |
504 | ipl = interrupts_disable(); |
| 478 | spinlock_lock(&t->udebug.lock); |
- | |
| 479 | spinlock_lock(&t->lock); |
505 | spinlock_lock(&t->lock); |
| 480 | 506 | ||
| 481 | flags = t->flags; |
507 | flags = t->flags; |
| 482 | 508 | ||
| 483 | spinlock_unlock(&t->lock); |
509 | spinlock_unlock(&t->lock); |
| - | 510 | interrupts_restore(ipl); |
|
| 484 | 511 | ||
| 485 | /* Only process userspace threads */ |
512 | /* Only process userspace threads */ |
| 486 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
513 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
| 487 | /* Prevent any further debug activity in thread */ |
514 | /* Prevent any further debug activity in thread */ |
| 488 | t->udebug.debug_active = false; |
515 | t->udebug.debug_active = false; |
| Line 498... | Line 525... | ||
| 498 | 525 | ||
| 499 | /* Answer GO call */ |
526 | /* Answer GO call */ |
| 500 | klog_printf("answer GO call with EVENT_FINISHED"); |
527 | klog_printf("answer GO call with EVENT_FINISHED"); |
| 501 | IPC_SET_RETVAL(t->udebug.go_call->data, 0); |
528 | IPC_SET_RETVAL(t->udebug.go_call->data, 0); |
| 502 | IPC_SET_ARG1(t->udebug.go_call->data, UDEBUG_EVENT_FINISHED); |
529 | IPC_SET_ARG1(t->udebug.go_call->data, UDEBUG_EVENT_FINISHED); |
| 503 | /* FIXME: must not call with interrupts disabled!!*/ |
- | |
| - | 530 | ||
| 504 | ipc_answer(&ta->answerbox, t->udebug.go_call); |
531 | ipc_answer(&ta->answerbox, t->udebug.go_call); |
| 505 | t->udebug.go_call = NULL; |
532 | t->udebug.go_call = NULL; |
| 506 | } else { |
533 | } else { |
| 507 | /* |
534 | /* |
| 508 | * Debug_stop is already at initial value. |
535 | * Debug_stop is already at initial value. |
| Line 514... | Line 541... | ||
| 514 | * waitq_wakeup. |
541 | * waitq_wakeup. |
| 515 | */ |
542 | */ |
| 516 | waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST); |
543 | waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST); |
| 517 | } |
544 | } |
| 518 | } |
545 | } |
| 519 | spinlock_unlock(&t->udebug.lock); |
546 | mutex_unlock(&t->udebug.lock); |
| 520 | interrupts_restore(ipl); |
- | |
| 521 | } |
547 | } |
| 522 | 548 | ||
| 523 | ta->udebug.dt_state = UDEBUG_TS_INACTIVE; |
549 | ta->udebug.dt_state = UDEBUG_TS_INACTIVE; |
| 524 | ta->udebug.debugger = NULL; |
550 | ta->udebug.debugger = NULL; |
| 525 | 551 | ||
| - | 552 | udebug_int_unlock(); |
|
| - | 553 | ||
| 526 | return 0; |
554 | return 0; |
| 527 | } |
555 | } |
| 528 | 556 | ||
| 529 | 557 | ||
| 530 | /** @} |
558 | /** @} |