Rev 2823 | Rev 2826 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2823 | Rev 2825 | ||
---|---|---|---|
1 | /** @addtogroup generic |
1 | /** @addtogroup generic |
2 | * @{ |
2 | * @{ |
3 | */ |
3 | */ |
4 | 4 | ||
5 | /** |
5 | /** |
6 | * @file |
6 | * @file |
7 | * @brief Tdebug. |
7 | * @brief Tdebug. |
8 | */ |
8 | */ |
9 | 9 | ||
10 | #include <synch/waitq.h> |
10 | #include <synch/waitq.h> |
11 | #include <console/klog.h> |
11 | #include <console/klog.h> |
12 | #include <udebug/udebug.h> |
12 | #include <udebug/udebug.h> |
13 | #include <arch.h> |
13 | #include <arch.h> |
14 | 14 | ||
15 | void udebug_stoppable_begin(void) |
15 | void udebug_stoppable_begin(void) |
16 | { |
16 | { |
17 | int nsc; |
17 | int nsc; |
18 | call_t *db_call; |
18 | call_t *db_call; |
19 | ipl_t ipl; |
19 | ipl_t ipl; |
20 | 20 | ||
21 | ipl = interrupts_disable(); |
21 | ipl = interrupts_disable(); |
22 | spinlock_lock(&TASK->lock); |
22 | spinlock_lock(&TASK->lock); |
23 | 23 | ||
24 | nsc = --TASK->not_stoppable_count; |
24 | nsc = --TASK->not_stoppable_count; |
25 | db_call = TASK->debug_begin_call; |
25 | db_call = TASK->debug_begin_call; |
26 | 26 | ||
27 | if (TASK->stop_request == true) { |
27 | if (TASK->dt_state == UDEBUG_TS_BEGINNING) { |
28 | klog_printf("udebug_stoppable_begin"); |
28 | klog_printf("udebug_stoppable_begin"); |
29 | klog_printf(" - nsc := %d", nsc); |
29 | klog_printf(" - nsc := %d", nsc); |
30 | } |
30 | } |
31 | 31 | ||
32 | if (TASK->stop_request == true && nsc == 0) { |
32 | if (TASK->dt_state == UDEBUG_TS_BEGINNING && nsc == 0) { |
33 | TASK->stop_request = false; |
33 | TASK->dt_state = UDEBUG_TS_ACTIVE; |
34 | TASK->debug_begin_call = NULL; |
34 | TASK->debug_begin_call = NULL; |
35 | spinlock_unlock(&TASK->lock); |
35 | spinlock_unlock(&TASK->lock); |
36 | interrupts_restore(ipl); |
36 | interrupts_restore(ipl); |
37 | 37 | ||
38 | IPC_SET_RETVAL(db_call->data, 0); |
38 | IPC_SET_RETVAL(db_call->data, 0); |
39 | klog_printf("udebug_stoppable_begin/ipc_answer"); |
39 | klog_printf("udebug_stoppable_begin/ipc_answer"); |
40 | ipc_answer(&TASK->answerbox, db_call); |
40 | ipc_answer(&TASK->answerbox, db_call); |
41 | } else { |
41 | } else { |
42 | spinlock_unlock(&TASK->lock); |
42 | spinlock_unlock(&TASK->lock); |
43 | interrupts_restore(ipl); |
43 | interrupts_restore(ipl); |
44 | } |
44 | } |
45 | } |
45 | } |
46 | 46 | ||
47 | void udebug_stoppable_end(void) |
47 | void udebug_stoppable_end(void) |
48 | { |
48 | { |
49 | ipl_t ipl; |
49 | ipl_t ipl; |
50 | 50 | ||
51 | restart: |
51 | restart: |
52 | ipl = interrupts_disable(); |
52 | ipl = interrupts_disable(); |
53 | spinlock_lock(&TASK->lock); |
53 | spinlock_lock(&TASK->lock); |
54 | 54 | ||
- | 55 | if ((TASK->dt_state == UDEBUG_TS_BEGINNING || |
|
- | 56 | TASK->dt_state == UDEBUG_TS_ACTIVE) && |
|
55 | if (TASK->stop_request) { |
57 | THREAD->debug_stop == true) { |
56 | TASK->debug_begin_call = NULL; |
58 | TASK->debug_begin_call = NULL; |
57 | spinlock_unlock(&TASK->lock); |
59 | spinlock_unlock(&TASK->lock); |
58 | interrupts_restore(ipl); |
60 | interrupts_restore(ipl); |
59 | 61 | ||
60 | klog_printf("udebug_stoppable_end: waitq_sleep"); |
62 | klog_printf("udebug_stoppable_end: waitq_sleep"); |
61 | waitq_sleep(&THREAD->go_wq); |
63 | waitq_sleep(&THREAD->go_wq); |
62 | goto restart; |
64 | goto restart; |
63 | /* must try again - have to lose stoppability atomically */ |
65 | /* must try again - have to lose stoppability atomically */ |
64 | } else { |
66 | } else { |
65 | ++TASK->not_stoppable_count; |
67 | ++TASK->not_stoppable_count; |
66 | spinlock_unlock(&TASK->lock); |
68 | spinlock_unlock(&TASK->lock); |
67 | interrupts_restore(ipl); |
69 | interrupts_restore(ipl); |
68 | } |
70 | } |
69 | } |
71 | } |
70 | 72 | ||
71 | void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3, |
73 | 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) |
74 | unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc) |
73 | { |
75 | { |
74 | call_t *call; |
76 | call_t *call; |
75 | ipl_t ipl; |
77 | ipl_t ipl; |
76 | 78 | ||
77 | ipl = interrupts_disable(); |
79 | ipl = interrupts_disable(); |
78 | spinlock_lock(&TASK->lock); |
80 | spinlock_lock(&TASK->lock); |
79 | 81 | ||
80 | /* being debugged + have go */ |
- | |
81 | if (TASK->being_debugged && !TASK->stop_request) { |
82 | if (TASK->dt_state == UDEBUG_TS_ACTIVE) { |
82 | klog_printf("udebug_syscall_event"); |
83 | klog_printf("udebug_syscall_event"); |
83 | call = TASK->debug_go_call; |
84 | call = TASK->debug_go_call; |
84 | IPC_SET_RETVAL(call->data, 0); |
85 | IPC_SET_RETVAL(call->data, 0); |
85 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_SYSCALL); |
86 | IPC_SET_ARG1(call->data, UDEBUG_EVENT_SYSCALL); |
86 | IPC_SET_ARG2(call->data, id); |
87 | IPC_SET_ARG2(call->data, id); |
87 | IPC_SET_ARG3(call->data, rc); |
88 | IPC_SET_ARG3(call->data, rc); |
88 | klog_printf("udebug_syscall_event/ipc_answer"); |
89 | klog_printf("udebug_syscall_event/ipc_answer"); |
89 | 90 | ||
90 | THREAD->syscall_args[0] = a1; |
91 | THREAD->syscall_args[0] = a1; |
91 | THREAD->syscall_args[1] = a2; |
92 | THREAD->syscall_args[1] = a2; |
92 | THREAD->syscall_args[2] = a3; |
93 | THREAD->syscall_args[2] = a3; |
93 | THREAD->syscall_args[3] = a4; |
94 | THREAD->syscall_args[3] = a4; |
94 | THREAD->syscall_args[4] = a5; |
95 | THREAD->syscall_args[4] = a5; |
95 | THREAD->syscall_args[5] = a6; |
96 | THREAD->syscall_args[5] = a6; |
96 | 97 | ||
- | 98 | /* |
|
- | 99 | * Make sure debug_stop is true when going to sleep |
|
- | 100 | * in case we get woken up by DEBUG_END. (At which |
|
- | 101 | * point it must be back to the initial true value). |
|
- | 102 | */ |
|
- | 103 | THREAD->debug_stop = true; |
|
- | 104 | ||
97 | ipc_answer(&TASK->answerbox, TASK->debug_go_call); |
105 | ipc_answer(&TASK->answerbox, TASK->debug_go_call); |
98 | spinlock_unlock(&TASK->lock); |
106 | spinlock_unlock(&TASK->lock); |
99 | interrupts_restore(ipl); |
107 | interrupts_restore(ipl); |
100 | 108 | ||
101 | waitq_sleep(&THREAD->go_wq); |
109 | waitq_sleep(&THREAD->go_wq); |
102 | } else { |
110 | } else { |
103 | spinlock_unlock(&TASK->lock); |
111 | spinlock_unlock(&TASK->lock); |
104 | interrupts_restore(ipl); |
112 | interrupts_restore(ipl); |
105 | } |
113 | } |
106 | } |
114 | } |
107 | 115 | ||
108 | /** @} |
116 | /** @} |
109 | */ |
117 | */ |
110 | 118 |