Subversion Repositories HelenOS

Rev

Rev 2813 | Rev 2825 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /** @addtogroup generic
  2.  * @{
  3.  */
  4.  
  5. /**
  6.  * @file
  7.  * @brief   Tdebug.
  8.  */
  9.  
  10. #include <synch/waitq.h>
  11. #include <console/klog.h>
  12. #include <udebug/udebug.h>
  13. #include <arch.h>
  14.  
  15. void udebug_stoppable_begin(void)
  16. {
  17.     int nsc;
  18.     call_t *db_call;
  19.     ipl_t ipl;
  20.  
  21.     ipl = interrupts_disable();
  22.     spinlock_lock(&TASK->lock);
  23.  
  24.     nsc = --TASK->not_stoppable_count;
  25.     db_call = TASK->debug_begin_call;
  26.  
  27.     if (TASK->stop_request == true) {
  28.         klog_printf("udebug_stoppable_begin");
  29.         klog_printf(" - nsc := %d", nsc);
  30.     }
  31.  
  32.     if (TASK->stop_request == true && nsc == 0) {
  33.         TASK->stop_request = false;
  34.         TASK->debug_begin_call = NULL;
  35.         spinlock_unlock(&TASK->lock);
  36.         interrupts_restore(ipl);
  37.  
  38.         IPC_SET_RETVAL(db_call->data, 0);
  39.         klog_printf("udebug_stoppable_begin/ipc_answer");
  40.         ipc_answer(&TASK->answerbox, db_call);     
  41.     } else {
  42.             spinlock_unlock(&TASK->lock);
  43.         interrupts_restore(ipl);
  44.     }
  45. }
  46.  
  47. void udebug_stoppable_end(void)
  48. {
  49.     ipl_t ipl;
  50.  
  51. restart:
  52.     ipl = interrupts_disable();
  53.     spinlock_lock(&TASK->lock);
  54.  
  55.     if (TASK->stop_request) {
  56.         TASK->debug_begin_call = NULL;
  57.         spinlock_unlock(&TASK->lock);
  58.         interrupts_restore(ipl);
  59.  
  60.         klog_printf("udebug_stoppable_end: waitq_sleep");
  61.         waitq_sleep(&THREAD->go_wq);
  62.         goto restart;
  63.         /* must try again - have to lose stoppability atomically */
  64.     } else {
  65.         ++TASK->not_stoppable_count;
  66.         spinlock_unlock(&TASK->lock);
  67.         interrupts_restore(ipl);
  68.     }
  69. }
  70.  
  71. void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
  72.     unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc)
  73. {
  74.     call_t *call;
  75.     ipl_t ipl;
  76.  
  77.     ipl = interrupts_disable();
  78.     spinlock_lock(&TASK->lock);
  79.  
  80.     /* being debugged + have go */
  81.     if (TASK->being_debugged && !TASK->stop_request) {
  82.         klog_printf("udebug_syscall_event");
  83.         call = TASK->debug_go_call;
  84.         IPC_SET_RETVAL(call->data, 0);
  85.         IPC_SET_ARG1(call->data, UDEBUG_EVENT_SYSCALL);
  86.         IPC_SET_ARG2(call->data, id);
  87.         IPC_SET_ARG3(call->data, rc);
  88.         klog_printf("udebug_syscall_event/ipc_answer");
  89.  
  90.         THREAD->syscall_args[0] = a1;
  91.         THREAD->syscall_args[1] = a2;
  92.         THREAD->syscall_args[2] = a3;
  93.         THREAD->syscall_args[3] = a4;
  94.         THREAD->syscall_args[4] = a5;
  95.         THREAD->syscall_args[5] = a6;
  96.  
  97.         ipc_answer(&TASK->answerbox, TASK->debug_go_call);
  98.         spinlock_unlock(&TASK->lock);
  99.         interrupts_restore(ipl);
  100.  
  101.         waitq_sleep(&THREAD->go_wq);
  102.     } else {
  103.         spinlock_unlock(&TASK->lock);
  104.         interrupts_restore(ipl);
  105.     }
  106. }
  107.  
  108. /** @}
  109.  */
  110.