Rev 3471 | Rev 3611 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3471 | Rev 3606 | ||
|---|---|---|---|
| Line 33... | Line 33... | ||
| 33 | /** |
33 | /** |
| 34 | * @file |
34 | * @file |
| 35 | * @brief Udebug hooks and data structure management. |
35 | * @brief Udebug hooks and data structure management. |
| 36 | * |
36 | * |
| 37 | * Udebug is an interface that makes userspace debuggers possible. |
37 | * Udebug is an interface that makes userspace debuggers possible. |
| 38 | * |
- | |
| 39 | * Functions in this file are executed directly in each thread, which |
- | |
| 40 | * may or may not be the subject of debugging. The udebug_stoppable_begin/end() |
- | |
| 41 | * functions are also executed in the clock interrupt handler. To avoid |
- | |
| 42 | * deadlock, functions in this file are protected from the interrupt |
- | |
| 43 | * by locking the recursive lock THREAD->udebug.int_lock (just an atomic |
- | |
| 44 | * variable). This prevents udebug_stoppable_begin/end() from being |
- | |
| 45 | * executed in the interrupt handler (they are skipped). |
- | |
| 46 | * |
- | |
| 47 | * Functions in udebug_ops.c and udebug_ipc.c execute in different threads, |
- | |
| 48 | * so they needn't be protected from the (preemptible) interrupt-initiated |
- | |
| 49 | * code. |
- | |
| 50 | */ |
38 | */ |
| 51 | 39 | ||
| 52 | #include <synch/waitq.h> |
40 | #include <synch/waitq.h> |
| 53 | #include <debug.h> |
41 | #include <debug.h> |
| 54 | #include <udebug/udebug.h> |
42 | #include <udebug/udebug.h> |
| 55 | #include <errno.h> |
43 | #include <errno.h> |
| 56 | #include <arch.h> |
44 | #include <arch.h> |
| 57 | 45 | ||
| 58 | static inline void udebug_int_lock(void) |
- | |
| 59 | { |
- | |
| 60 | atomic_inc(&THREAD->udebug.int_lock); |
- | |
| 61 | } |
- | |
| 62 | - | ||
| 63 | static inline void udebug_int_unlock(void) |
- | |
| 64 | { |
- | |
| 65 | atomic_dec(&THREAD->udebug.int_lock); |
- | |
| 66 | } |
- | |
| 67 | 46 | ||
| 68 | /** Initialize udebug part of task structure. |
47 | /** Initialize udebug part of task structure. |
| 69 | * |
48 | * |
| 70 | * Called as part of task structure initialization. |
49 | * Called as part of task structure initialization. |
| 71 | * @param ut Pointer to the structure to initialize. |
50 | * @param ut Pointer to the structure to initialize. |
| Line 87... | Line 66... | ||
| 87 | void udebug_thread_initialize(udebug_thread_t *ut) |
66 | void udebug_thread_initialize(udebug_thread_t *ut) |
| 88 | { |
67 | { |
| 89 | mutex_initialize(&ut->lock, MUTEX_PASSIVE); |
68 | mutex_initialize(&ut->lock, MUTEX_PASSIVE); |
| 90 | waitq_initialize(&ut->go_wq); |
69 | waitq_initialize(&ut->go_wq); |
| 91 | 70 | ||
| 92 | /* |
- | |
| 93 | * At the beginning the thread is stoppable, so int_lock be set, too. |
- | |
| 94 | */ |
- | |
| 95 | atomic_set(&ut->int_lock, 1); |
- | |
| 96 | - | ||
| 97 | ut->go_call = NULL; |
71 | ut->go_call = NULL; |
| 98 | ut->uspace_state = NULL; |
72 | ut->uspace_state = NULL; |
| 99 | ut->stop = true; |
73 | ut->go = false; |
| 100 | ut->stoppable = true; |
74 | ut->stoppable = true; |
| 101 | ut->debug_active = false; |
75 | ut->debug_active = false; |
| 102 | ut->cur_event = 0; /* none */ |
76 | ut->cur_event = 0; /* none */ |
| 103 | } |
77 | } |
| 104 | 78 | ||
| Line 160... | Line 134... | ||
| 160 | call_t *db_call, *go_call; |
134 | call_t *db_call, *go_call; |
| 161 | 135 | ||
| 162 | ASSERT(THREAD); |
136 | ASSERT(THREAD); |
| 163 | ASSERT(TASK); |
137 | ASSERT(TASK); |
| 164 | 138 | ||
| 165 | udebug_int_lock(); |
- | |
| 166 | - | ||
| 167 | /* Early check for undebugged tasks */ |
139 | /* Early check for undebugged tasks */ |
| 168 | if (!udebug_thread_precheck()) { |
140 | if (!udebug_thread_precheck()) { |
| 169 | udebug_int_unlock(); |
- | |
| 170 | return; |
141 | return; |
| 171 | } |
142 | } |
| 172 | 143 | ||
| 173 | mutex_lock(&TASK->udebug.lock); |
144 | mutex_lock(&TASK->udebug.lock); |
| 174 | 145 | ||
| Line 197... | Line 168... | ||
| 197 | } else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) { |
168 | } else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) { |
| 198 | /* |
169 | /* |
| 199 | * Active debugging session |
170 | * Active debugging session |
| 200 | */ |
171 | */ |
| 201 | 172 | ||
| 202 | if (THREAD->udebug.debug_active && THREAD->udebug.stop) { |
173 | if (THREAD->udebug.debug_active == true && |
| - | 174 | THREAD->udebug.go == false) { |
|
| 203 | /* |
175 | /* |
| 204 | * Thread was requested to stop - answer go call |
176 | * Thread was requested to stop - answer go call |
| 205 | */ |
177 | */ |
| 206 | 178 | ||
| 207 | /* Make sure nobody takes this call away from us */ |
179 | /* Make sure nobody takes this call away from us */ |
| Line 229... | Line 201... | ||
| 229 | */ |
201 | */ |
| 230 | void udebug_stoppable_end(void) |
202 | void udebug_stoppable_end(void) |
| 231 | { |
203 | { |
| 232 | /* Early check for undebugged tasks */ |
204 | /* Early check for undebugged tasks */ |
| 233 | if (!udebug_thread_precheck()) { |
205 | if (!udebug_thread_precheck()) { |
| 234 | udebug_int_unlock(); |
- | |
| 235 | return; |
206 | return; |
| 236 | } |
207 | } |
| 237 | 208 | ||
| 238 | restart: |
209 | restart: |
| 239 | mutex_lock(&TASK->udebug.lock); |
210 | mutex_lock(&TASK->udebug.lock); |
| 240 | mutex_lock(&THREAD->udebug.lock); |
211 | mutex_lock(&THREAD->udebug.lock); |
| 241 | 212 | ||
| 242 | if (THREAD->udebug.debug_active && |
213 | if (THREAD->udebug.debug_active && |
| 243 | THREAD->udebug.stop == true) { |
214 | THREAD->udebug.go == false) { |
| 244 | TASK->udebug.begin_call = NULL; |
215 | TASK->udebug.begin_call = NULL; |
| 245 | mutex_unlock(&THREAD->udebug.lock); |
216 | mutex_unlock(&THREAD->udebug.lock); |
| 246 | mutex_unlock(&TASK->udebug.lock); |
217 | mutex_unlock(&TASK->udebug.lock); |
| 247 | 218 | ||
| 248 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
219 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| 249 | 220 | ||
| 250 | goto restart; |
221 | goto restart; |
| 251 | /* must try again - have to lose stoppability atomically */ |
222 | /* Must try again - have to lose stoppability atomically. */ |
| 252 | } else { |
223 | } else { |
| 253 | ++TASK->udebug.not_stoppable_count; |
224 | ++TASK->udebug.not_stoppable_count; |
| 254 | ASSERT(THREAD->udebug.stoppable == true); |
225 | ASSERT(THREAD->udebug.stoppable == true); |
| 255 | THREAD->udebug.stoppable = false; |
226 | THREAD->udebug.stoppable = false; |
| 256 | 227 | ||
| 257 | mutex_unlock(&THREAD->udebug.lock); |
228 | mutex_unlock(&THREAD->udebug.lock); |
| 258 | mutex_unlock(&TASK->udebug.lock); |
229 | mutex_unlock(&TASK->udebug.lock); |
| 259 | } |
230 | } |
| 260 | - | ||
| 261 | udebug_int_unlock(); |
- | |
| 262 | } |
231 | } |
| 263 | 232 | ||
| 264 | /** Upon being scheduled to run, check if the current thread should stop. |
233 | /** Upon being scheduled to run, check if the current thread should stop. |
| 265 | * |
234 | * |
| 266 | * This function is called from clock(). Preemption is enabled. |
235 | * This function is called from clock(). Preemption is enabled. |
| Line 271... | Line 240... | ||
| 271 | void udebug_before_thread_runs(void) |
240 | void udebug_before_thread_runs(void) |
| 272 | { |
241 | { |
| 273 | ipl_t ipl; |
242 | ipl_t ipl; |
| 274 | 243 | ||
| 275 | return; |
244 | return; |
| 276 | ASSERT(!PREEMPTION_DISABLED); |
- | |
| 277 | - | ||
| 278 | /* |
- | |
| 279 | * Prevent agains re-entering, such as when preempted inside this |
- | |
| 280 | * function. |
- | |
| 281 | */ |
- | |
| 282 | if (atomic_get(&THREAD->udebug.int_lock) != 0) |
- | |
| 283 | return; |
- | |
| 284 | - | ||
| 285 | udebug_int_lock(); |
- | |
| 286 | 245 | ||
| 287 | ipl = interrupts_enable(); |
246 | ipl = interrupts_enable(); |
| 288 | 247 | ||
| 289 | /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */ |
248 | /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */ |
| 290 | 249 | ||
| 291 | /* Check if we're supposed to stop */ |
250 | /* Check if we're supposed to stop */ |
| 292 | udebug_stoppable_begin(); |
251 | udebug_stoppable_begin(); |
| 293 | udebug_stoppable_end(); |
252 | udebug_stoppable_end(); |
| 294 | 253 | ||
| 295 | interrupts_restore(ipl); |
254 | interrupts_restore(ipl); |
| 296 | - | ||
| 297 | udebug_int_unlock(); |
- | |
| 298 | } |
255 | } |
| 299 | 256 | ||
| 300 | /** Syscall event hook. |
257 | /** Syscall event hook. |
| 301 | * |
258 | * |
| 302 | * Must be called before and after servicing a system call. This generates |
259 | * Must be called before and after servicing a system call. This generates |
| Line 309... | Line 266... | ||
| 309 | call_t *call; |
266 | call_t *call; |
| 310 | udebug_event_t etype; |
267 | udebug_event_t etype; |
| 311 | 268 | ||
| 312 | etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; |
269 | etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; |
| 313 | 270 | ||
| 314 | udebug_int_lock(); |
- | |
| 315 | - | ||
| 316 | /* Early check for undebugged tasks */ |
271 | /* Early check for undebugged tasks */ |
| 317 | if (!udebug_thread_precheck()) { |
272 | if (!udebug_thread_precheck()) { |
| 318 | udebug_int_unlock(); |
- | |
| 319 | return; |
273 | return; |
| 320 | } |
274 | } |
| 321 | 275 | ||
| 322 | mutex_lock(&TASK->udebug.lock); |
276 | mutex_lock(&TASK->udebug.lock); |
| 323 | mutex_lock(&THREAD->udebug.lock); |
277 | mutex_lock(&THREAD->udebug.lock); |
| 324 | 278 | ||
| 325 | /* Must only generate events when in debugging session and have go */ |
279 | /* Must only generate events when in debugging session and is go. */ |
| 326 | if (THREAD->udebug.debug_active != true || |
280 | if (THREAD->udebug.debug_active != true || |
| 327 | THREAD->udebug.stop == true || |
281 | THREAD->udebug.go == false || |
| 328 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
282 | (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
| 329 | mutex_unlock(&THREAD->udebug.lock); |
283 | mutex_unlock(&THREAD->udebug.lock); |
| 330 | mutex_unlock(&TASK->udebug.lock); |
284 | mutex_unlock(&TASK->udebug.lock); |
| 331 | return; |
285 | return; |
| 332 | } |
286 | } |
| Line 347... | Line 301... | ||
| 347 | THREAD->udebug.syscall_args[3] = a4; |
301 | THREAD->udebug.syscall_args[3] = a4; |
| 348 | THREAD->udebug.syscall_args[4] = a5; |
302 | THREAD->udebug.syscall_args[4] = a5; |
| 349 | THREAD->udebug.syscall_args[5] = a6; |
303 | THREAD->udebug.syscall_args[5] = a6; |
| 350 | 304 | ||
| 351 | /* |
305 | /* |
| 352 | * Make sure udebug.stop is true when going to sleep |
306 | * Make sure udebug.go is false when going to sleep |
| 353 | * in case we get woken up by DEBUG_END. (At which |
307 | * in case we get woken up by DEBUG_END. (At which |
| 354 | * point it must be back to the initial true value). |
308 | * point it must be back to the initial true value). |
| 355 | */ |
309 | */ |
| 356 | THREAD->udebug.stop = true; |
310 | THREAD->udebug.go = false; |
| 357 | THREAD->udebug.cur_event = etype; |
311 | THREAD->udebug.cur_event = etype; |
| 358 | 312 | ||
| 359 | ipc_answer(&TASK->answerbox, call); |
313 | ipc_answer(&TASK->answerbox, call); |
| 360 | 314 | ||
| 361 | mutex_unlock(&THREAD->udebug.lock); |
315 | mutex_unlock(&THREAD->udebug.lock); |
| 362 | mutex_unlock(&TASK->udebug.lock); |
316 | mutex_unlock(&TASK->udebug.lock); |
| 363 | 317 | ||
| 364 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
318 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| 365 | - | ||
| 366 | udebug_int_unlock(); |
- | |
| 367 | } |
319 | } |
| 368 | 320 | ||
| 369 | /** Thread-creation event hook. |
321 | /** Thread-creation event hook. |
| 370 | * |
322 | * |
| 371 | * Must be called when a new userspace thread is created in the debugged |
323 | * Must be called when a new userspace thread is created in the debugged |
| Line 376... | Line 328... | ||
| 376 | */ |
328 | */ |
| 377 | void udebug_thread_b_event(struct thread *t) |
329 | void udebug_thread_b_event(struct thread *t) |
| 378 | { |
330 | { |
| 379 | call_t *call; |
331 | call_t *call; |
| 380 | 332 | ||
| 381 | udebug_int_lock(); |
- | |
| 382 | - | ||
| 383 | mutex_lock(&TASK->udebug.lock); |
333 | mutex_lock(&TASK->udebug.lock); |
| 384 | mutex_lock(&THREAD->udebug.lock); |
334 | mutex_lock(&THREAD->udebug.lock); |
| 385 | 335 | ||
| 386 | LOG("udebug_thread_b_event\n"); |
336 | LOG("udebug_thread_b_event\n"); |
| 387 | LOG("- check state\n"); |
337 | LOG("- check state\n"); |
| 388 | 338 | ||
| 389 | /* Must only generate events when in debugging session */ |
339 | /* Must only generate events when in debugging session */ |
| 390 | if (THREAD->udebug.debug_active != true) { |
340 | if (THREAD->udebug.debug_active != true) { |
| 391 | LOG("- debug_active: %s, udebug.stop: %s\n", |
341 | LOG("- debug_active: %s, udebug.go: %s\n", |
| 392 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
342 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
| 393 | THREAD->udebug.stop ? "yes(-)" : "no(+)"); |
343 | THREAD->udebug.go ? "yes(-)" : "no(+)"); |
| 394 | mutex_unlock(&THREAD->udebug.lock); |
344 | mutex_unlock(&THREAD->udebug.lock); |
| 395 | mutex_unlock(&TASK->udebug.lock); |
345 | mutex_unlock(&TASK->udebug.lock); |
| 396 | return; |
346 | return; |
| 397 | } |
347 | } |
| 398 | 348 | ||
| Line 403... | Line 353... | ||
| 403 | IPC_SET_RETVAL(call->data, 0); |
353 | IPC_SET_RETVAL(call->data, 0); |
| 404 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B); |
354 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B); |
| 405 | IPC_SET_ARG2(call->data, (unative_t)t); |
355 | IPC_SET_ARG2(call->data, (unative_t)t); |
| 406 | 356 | ||
| 407 | /* |
357 | /* |
| 408 | * Make sure udebug.stop is true when going to sleep |
358 | * Make sure udebug.go is false when going to sleep |
| 409 | * in case we get woken up by DEBUG_END. (At which |
359 | * in case we get woken up by DEBUG_END. (At which |
| 410 | * point it must be back to the initial true value). |
360 | * point it must be back to the initial true value). |
| 411 | */ |
361 | */ |
| 412 | THREAD->udebug.stop = true; |
362 | THREAD->udebug.go = false; |
| 413 | THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; |
363 | THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; |
| 414 | 364 | ||
| 415 | ipc_answer(&TASK->answerbox, call); |
365 | ipc_answer(&TASK->answerbox, call); |
| 416 | 366 | ||
| 417 | mutex_unlock(&THREAD->udebug.lock); |
367 | mutex_unlock(&THREAD->udebug.lock); |
| 418 | mutex_unlock(&TASK->udebug.lock); |
368 | mutex_unlock(&TASK->udebug.lock); |
| 419 | 369 | ||
| 420 | LOG("- sleep\n"); |
370 | LOG("- sleep\n"); |
| 421 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
371 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| 422 | - | ||
| 423 | udebug_int_unlock(); |
- | |
| 424 | } |
372 | } |
| 425 | 373 | ||
| 426 | /** Thread-termination event hook. |
374 | /** Thread-termination event hook. |
| 427 | * |
375 | * |
| 428 | * Must be called when the current thread is terminating. |
376 | * Must be called when the current thread is terminating. |
| Line 430... | Line 378... | ||
| 430 | */ |
378 | */ |
| 431 | void udebug_thread_e_event(void) |
379 | void udebug_thread_e_event(void) |
| 432 | { |
380 | { |
| 433 | call_t *call; |
381 | call_t *call; |
| 434 | 382 | ||
| 435 | udebug_int_lock(); |
- | |
| 436 | - | ||
| 437 | mutex_lock(&TASK->udebug.lock); |
383 | mutex_lock(&TASK->udebug.lock); |
| 438 | mutex_lock(&THREAD->udebug.lock); |
384 | mutex_lock(&THREAD->udebug.lock); |
| 439 | 385 | ||
| 440 | LOG("udebug_thread_e_event\n"); |
386 | LOG("udebug_thread_e_event\n"); |
| 441 | LOG("- check state\n"); |
387 | LOG("- check state\n"); |
| 442 | 388 | ||
| 443 | /* Must only generate events when in debugging session */ |
389 | /* Must only generate events when in debugging session. */ |
| 444 | if (THREAD->udebug.debug_active != true) { |
390 | if (THREAD->udebug.debug_active != true) { |
| 445 | /* printf("- debug_active: %s, udebug.stop: %s\n", |
391 | /* printf("- debug_active: %s, udebug.go: %s\n", |
| 446 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
392 | THREAD->udebug.debug_active ? "yes(+)" : "no(-)", |
| 447 | THREAD->udebug.stop ? "yes(-)" : "no(+)");*/ |
393 | THREAD->udebug.go ? "yes(-)" : "no(+)");*/ |
| 448 | mutex_unlock(&THREAD->udebug.lock); |
394 | mutex_unlock(&THREAD->udebug.lock); |
| 449 | mutex_unlock(&TASK->udebug.lock); |
395 | mutex_unlock(&TASK->udebug.lock); |
| 450 | return; |
396 | return; |
| 451 | } |
397 | } |
| 452 | 398 | ||
| Line 455... | Line 401... | ||
| 455 | call = THREAD->udebug.go_call; |
401 | call = THREAD->udebug.go_call; |
| 456 | THREAD->udebug.go_call = NULL; |
402 | THREAD->udebug.go_call = NULL; |
| 457 | IPC_SET_RETVAL(call->data, 0); |
403 | IPC_SET_RETVAL(call->data, 0); |
| 458 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E); |
404 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E); |
| 459 | 405 | ||
| 460 | /* Prevent any further debug activity in thread */ |
406 | /* Prevent any further debug activity in thread. */ |
| 461 | THREAD->udebug.debug_active = false; |
407 | THREAD->udebug.debug_active = false; |
| 462 | THREAD->udebug.cur_event = 0; /* none */ |
408 | THREAD->udebug.cur_event = 0; /* none */ |
| 463 | THREAD->udebug.stop = true; /* set to initial value */ |
409 | THREAD->udebug.go = false; /* set to initial value */ |
| 464 | 410 | ||
| 465 | ipc_answer(&TASK->answerbox, call); |
411 | ipc_answer(&TASK->answerbox, call); |
| 466 | 412 | ||
| 467 | mutex_unlock(&THREAD->udebug.lock); |
413 | mutex_unlock(&THREAD->udebug.lock); |
| 468 | mutex_unlock(&TASK->udebug.lock); |
414 | mutex_unlock(&TASK->udebug.lock); |
| 469 | 415 | ||
| 470 | /* Leave int_lock enabled */ |
416 | /* |
| 471 | /* This event does not sleep - debugging has finished in this thread */ |
417 | * This event does not sleep - debugging has finished |
| - | 418 | * in this thread. |
|
| - | 419 | */ |
|
| 472 | } |
420 | } |
| 473 | 421 | ||
| 474 | static void breakpoint_trap_event(uintptr_t addr, udebug_event_t etype) |
422 | static void breakpoint_trap_event(uintptr_t addr, udebug_event_t etype) |
| 475 | { |
423 | { |
| 476 | call_t *call; |
424 | call_t *call; |
| 477 | 425 | ||
| 478 | udebug_int_lock(); |
- | |
| 479 | - | ||
| 480 | mutex_lock(&TASK->udebug.lock); |
426 | mutex_lock(&TASK->udebug.lock); |
| 481 | mutex_lock(&THREAD->udebug.lock); |
427 | mutex_lock(&THREAD->udebug.lock); |
| 482 | 428 | ||
| 483 | /* Must only generate events when in debugging session and have go */ |
429 | /* Must only generate events when in debugging session and have go. */ |
| 484 | if (THREAD->udebug.debug_active != true || |
430 | if (THREAD->udebug.debug_active != true || |
| 485 | THREAD->udebug.stop == true) { |
431 | THREAD->udebug.go == false) { |
| 486 | mutex_unlock(&THREAD->udebug.lock); |
432 | mutex_unlock(&THREAD->udebug.lock); |
| 487 | mutex_unlock(&TASK->udebug.lock); |
433 | mutex_unlock(&TASK->udebug.lock); |
| 488 | udebug_int_unlock(); |
- | |
| 489 | return; |
434 | return; |
| 490 | } |
435 | } |
| 491 | 436 | ||
| 492 | /* Verify that the event is enabled */ |
437 | /* Verify that the event is enabled */ |
| 493 | if ((TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
438 | if ((TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) { |
| 494 | mutex_unlock(&THREAD->udebug.lock); |
439 | mutex_unlock(&THREAD->udebug.lock); |
| 495 | mutex_unlock(&TASK->udebug.lock); |
440 | mutex_unlock(&TASK->udebug.lock); |
| 496 | udebug_int_unlock(); |
- | |
| 497 | return; |
441 | return; |
| 498 | } |
442 | } |
| 499 | 443 | ||
| 500 | printf("udebug_breakpoint/trap_event\n"); |
444 | printf("udebug_breakpoint/trap_event\n"); |
| 501 | call = THREAD->udebug.go_call; |
445 | call = THREAD->udebug.go_call; |
| Line 504... | Line 448... | ||
| 504 | IPC_SET_RETVAL(call->data, 0); |
448 | IPC_SET_RETVAL(call->data, 0); |
| 505 | IPC_SET_ARG1(call->data, etype); |
449 | IPC_SET_ARG1(call->data, etype); |
| 506 | IPC_SET_ARG2(call->data, addr); |
450 | IPC_SET_ARG2(call->data, addr); |
| 507 | 451 | ||
| 508 | /* |
452 | /* |
| 509 | * Make sure udebug.stop is true when going to sleep |
453 | * Make sure udebug.go is false when going to sleep |
| 510 | * in case we get woken up by DEBUG_END. (At which |
454 | * in case we get woken up by DEBUG_END. (At which |
| 511 | * point it must be back to the initial true value). |
455 | * point it must be back to the initial true value). |
| 512 | */ |
456 | */ |
| 513 | THREAD->udebug.stop = true; |
457 | THREAD->udebug.go = false; |
| 514 | THREAD->udebug.cur_event = etype; |
458 | THREAD->udebug.cur_event = etype; |
| 515 | 459 | ||
| 516 | printf("- send answer\n"); |
460 | printf("- send answer\n"); |
| 517 | ipc_answer(&TASK->answerbox, call); |
461 | ipc_answer(&TASK->answerbox, call); |
| 518 | 462 | ||
| 519 | mutex_unlock(&THREAD->udebug.lock); |
463 | mutex_unlock(&THREAD->udebug.lock); |
| 520 | mutex_unlock(&TASK->udebug.lock); |
464 | mutex_unlock(&TASK->udebug.lock); |
| 521 | 465 | ||
| 522 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
466 | udebug_wait_for_go(&THREAD->udebug.go_wq); |
| 523 | - | ||
| 524 | udebug_int_unlock(); |
- | |
| 525 | } |
467 | } |
| 526 | 468 | ||
| 527 | void udebug_breakpoint_event(uintptr_t addr) |
469 | void udebug_breakpoint_event(uintptr_t addr) |
| 528 | { |
470 | { |
| 529 | breakpoint_trap_event(addr, UDEBUG_EVENT_BREAKPOINT); |
471 | breakpoint_trap_event(addr, UDEBUG_EVENT_BREAKPOINT); |
| Line 552... | Line 494... | ||
| 552 | ipl_t ipl; |
494 | ipl_t ipl; |
| 553 | 495 | ||
| 554 | LOG("udebug_task_cleanup()\n"); |
496 | LOG("udebug_task_cleanup()\n"); |
| 555 | LOG("task %" PRIu64 "\n", ta->taskid); |
497 | LOG("task %" PRIu64 "\n", ta->taskid); |
| 556 | 498 | ||
| 557 | udebug_int_lock(); |
- | |
| 558 | - | ||
| 559 | if (ta->udebug.dt_state != UDEBUG_TS_BEGINNING && |
499 | if (ta->udebug.dt_state != UDEBUG_TS_BEGINNING && |
| 560 | ta->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
500 | ta->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
| 561 | LOG("udebug_task_cleanup(): task not being debugged\n"); |
501 | LOG("udebug_task_cleanup(): task not being debugged\n"); |
| 562 | return EINVAL; |
502 | return EINVAL; |
| 563 | } |
503 | } |
| Line 574... | Line 514... | ||
| 574 | flags = t->flags; |
514 | flags = t->flags; |
| 575 | 515 | ||
| 576 | spinlock_unlock(&t->lock); |
516 | spinlock_unlock(&t->lock); |
| 577 | interrupts_restore(ipl); |
517 | interrupts_restore(ipl); |
| 578 | 518 | ||
| 579 | /* Only process userspace threads */ |
519 | /* Only process userspace threads. */ |
| 580 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
520 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
| 581 | /* Prevent any further debug activity in thread */ |
521 | /* Prevent any further debug activity in thread. */ |
| 582 | t->udebug.debug_active = false; |
522 | t->udebug.debug_active = false; |
| 583 | t->udebug.cur_event = 0; /* none */ |
523 | t->udebug.cur_event = 0; /* none */ |
| 584 | 524 | ||
| 585 | /* Still has go? */ |
525 | /* Is the thread still go? */ |
| 586 | if (t->udebug.stop == false) { |
526 | if (t->udebug.go == true) { |
| 587 | /* |
527 | /* |
| 588 | * Yes, so clear go. As debug_active == false, |
528 | * Yes, so clear go. As debug_active == false, |
| 589 | * this doesn't affect anything. |
529 | * this doesn't affect anything. |
| 590 | */ |
530 | */ |
| 591 | t->udebug.stop = true; |
531 | t->udebug.go = false; |
| 592 | 532 | ||
| 593 | /* Answer GO call */ |
533 | /* Answer GO call */ |
| 594 | LOG("answer GO call with EVENT_FINISHED\n"); |
534 | LOG("answer GO call with EVENT_FINISHED\n"); |
| 595 | IPC_SET_RETVAL(t->udebug.go_call->data, 0); |
535 | IPC_SET_RETVAL(t->udebug.go_call->data, 0); |
| 596 | IPC_SET_ARG1(t->udebug.go_call->data, |
536 | IPC_SET_ARG1(t->udebug.go_call->data, |
| Line 615... | Line 555... | ||
| 615 | } |
555 | } |
| 616 | 556 | ||
| 617 | ta->udebug.dt_state = UDEBUG_TS_INACTIVE; |
557 | ta->udebug.dt_state = UDEBUG_TS_INACTIVE; |
| 618 | ta->udebug.debugger = NULL; |
558 | ta->udebug.debugger = NULL; |
| 619 | 559 | ||
| 620 | udebug_int_unlock(); |
- | |
| 621 | - | ||
| 622 | return 0; |
560 | return 0; |
| 623 | } |
561 | } |
| 624 | 562 | ||
| 625 | 563 | ||
| 626 | /** @} |
564 | /** @} |