Subversion Repositories HelenOS

Rev

Rev 2899 | Rev 2902 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2899 Rev 2901
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
 
37
 
38
#include <synch/waitq.h>
38
#include <synch/waitq.h>
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
void udebug_stoppable_begin(void)
44
void udebug_stoppable_begin(void)
45
{
45
{
46
    int nsc;
46
    int nsc;
47
    call_t *db_call, *go_call;
47
    call_t *db_call, *go_call;
48
    ipl_t ipl;
48
    ipl_t ipl;
49
 
49
 
50
    ipl = interrupts_disable();
50
    ipl = interrupts_disable();
51
    spinlock_lock(&TASK->lock);
51
    spinlock_lock(&TASK->lock);
52
 
52
 
53
    nsc = --TASK->not_stoppable_count;
53
    nsc = --TASK->not_stoppable_count;
54
    db_call = TASK->debug_begin_call;
54
    db_call = TASK->debug_begin_call;
55
 
55
 
56
    if (TASK->dt_state == UDEBUG_TS_BEGINNING) {
56
    if (TASK->dt_state == UDEBUG_TS_BEGINNING) {
57
        klog_printf("udebug_stoppable_begin");
57
        klog_printf("udebug_stoppable_begin");
58
        klog_printf(" - nsc := %d", nsc);
58
        klog_printf(" - nsc := %d", nsc);
59
    }
59
    }
60
 
60
 
61
    if (TASK->dt_state == UDEBUG_TS_BEGINNING && nsc == 0) {
61
    if (TASK->dt_state == UDEBUG_TS_BEGINNING && nsc == 0) {
62
        /*
62
        /*
63
         * This was the last non-stoppable thread. Reply to
63
         * This was the last non-stoppable thread. Reply to
64
         * DEBUG_BEGIN call.
64
         * DEBUG_BEGIN call.
65
         */
65
         */
66
 
66
 
67
        /* Lock order OK, THREAD->debug_lock is after TASK->lock */
67
        /* Lock order OK, THREAD->debug_lock is after TASK->lock */
68
        spinlock_lock(&THREAD->debug_lock);
68
        spinlock_lock(&THREAD->debug_lock);
69
        THREAD->debug_stoppable = true;
69
        THREAD->debug_stoppable = true;
70
        spinlock_unlock(&THREAD->debug_lock);
70
        spinlock_unlock(&THREAD->debug_lock);
71
 
71
 
72
        TASK->dt_state = UDEBUG_TS_ACTIVE;
72
        TASK->dt_state = UDEBUG_TS_ACTIVE;
73
        TASK->debug_begin_call = NULL;
73
        TASK->debug_begin_call = NULL;
74
        spinlock_unlock(&TASK->lock);
74
        spinlock_unlock(&TASK->lock);
75
        interrupts_restore(ipl);
75
        interrupts_restore(ipl);
76
 
76
 
77
        IPC_SET_RETVAL(db_call->data, 0);
77
        IPC_SET_RETVAL(db_call->data, 0);
78
        klog_printf("udebug_stoppable_begin/ipc_answer");
78
        klog_printf("udebug_stoppable_begin/ipc_answer");
79
        ipc_answer(&TASK->answerbox, db_call);     
79
        ipc_answer(&TASK->answerbox, db_call);     
80
 
80
 
81
    } else if (TASK->dt_state == UDEBUG_TS_ACTIVE) {
81
    } else if (TASK->dt_state == UDEBUG_TS_ACTIVE) {
82
        /*
82
        /*
83
         * Active debugging session
83
         * Active debugging session
84
         */
84
         */
85
 
85
 
86
        /* Lock order OK, THREAD->debug_lock is after TASK->lock */
86
        /* Lock order OK, THREAD->debug_lock is after TASK->lock */
87
        spinlock_lock(&THREAD->debug_lock);
87
        spinlock_lock(&THREAD->debug_lock);
88
        THREAD->debug_stoppable = true;
88
        THREAD->debug_stoppable = true;
89
 
89
 
90
        if (THREAD->debug_stop) {
90
        if (THREAD->debug_stop) {
91
            /*
91
            /*
92
             * Thread was requested to stop - answer go call
92
             * Thread was requested to stop - answer go call
93
             */
93
             */
94
 
94
 
95
            /* Make sure nobody takes this call away from us */
95
            /* Make sure nobody takes this call away from us */
96
            go_call = THREAD->debug_go_call;
96
            go_call = THREAD->debug_go_call;
97
            THREAD->debug_go_call = NULL;
97
            THREAD->debug_go_call = NULL;
98
 
98
 
99
            IPC_SET_RETVAL(go_call->data, 0);
99
            IPC_SET_RETVAL(go_call->data, 0);
100
            IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP);
100
            IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP);
101
 
101
 
102
            THREAD->cur_event = UDEBUG_EVENT_STOP;
102
            THREAD->cur_event = UDEBUG_EVENT_STOP;
103
            spinlock_unlock(&THREAD->debug_lock);
103
            spinlock_unlock(&THREAD->debug_lock);
104
 
104
 
105
                ipc_answer(&TASK->answerbox, go_call);
105
                ipc_answer(&TASK->answerbox, go_call);
106
 
106
 
107
                spinlock_unlock(&TASK->lock);
107
                spinlock_unlock(&TASK->lock);
108
            interrupts_restore(ipl);
108
            interrupts_restore(ipl);
109
        } else {
109
        } else {
110
            /*
110
            /*
111
             * No stop request - nothing happens.
111
             * No stop request - nothing happens.
112
             */
112
             */
113
            spinlock_unlock(&THREAD->debug_lock);
113
            spinlock_unlock(&THREAD->debug_lock);
114
                spinlock_unlock(&TASK->lock);
114
                spinlock_unlock(&TASK->lock);
115
            interrupts_restore(ipl);
115
            interrupts_restore(ipl);
116
        }
116
        }
117
    } else {
117
    } else {
118
        /*
118
        /*
119
         * All other cases - nothing special happens.
119
         * All other cases - nothing special happens.
120
         */
120
         */
121
 
121
 
122
        /* Lock order OK, THREAD->debug_lock is after TASK->lock */
122
        /* Lock order OK, THREAD->debug_lock is after TASK->lock */
123
        spinlock_lock(&THREAD->debug_lock);
123
        spinlock_lock(&THREAD->debug_lock);
124
        THREAD->debug_stoppable = true;
124
        THREAD->debug_stoppable = true;
125
        spinlock_unlock(&THREAD->debug_lock);
125
        spinlock_unlock(&THREAD->debug_lock);
126
 
126
 
127
            spinlock_unlock(&TASK->lock);
127
            spinlock_unlock(&TASK->lock);
128
        interrupts_restore(ipl);
128
        interrupts_restore(ipl);
129
    }
129
    }
130
}
130
}
131
 
131
 
132
void udebug_stoppable_end(void)
132
void udebug_stoppable_end(void)
133
{
133
{
134
    ipl_t ipl;
134
    ipl_t ipl;
135
 
135
 
136
restart:
136
restart:
137
    ipl = interrupts_disable();
137
    ipl = interrupts_disable();
138
    spinlock_lock(&TASK->lock);
138
    spinlock_lock(&TASK->lock);
139
 
139
 
140
    /* Lock order OK, THREAD->debug_lock is after TASK->lock */
140
    /* Lock order OK, THREAD->debug_lock is after TASK->lock */
141
    spinlock_lock(&THREAD->debug_lock);
141
    spinlock_lock(&THREAD->debug_lock);
142
 
142
 
143
    if (TASK->dt_state == UDEBUG_TS_ACTIVE) {
143
    if (TASK->dt_state == UDEBUG_TS_ACTIVE) {
144
        klog_printf("udebug_stoppable_end");
144
        klog_printf("udebug_stoppable_end");
145
        klog_printf("debug_stop=%d", THREAD->debug_stop);
145
        klog_printf("debug_stop=%d", THREAD->debug_stop);
146
    }
146
    }
147
 
147
 
148
    if ((TASK->dt_state == UDEBUG_TS_BEGINNING ||
148
    if ((TASK->dt_state == UDEBUG_TS_BEGINNING ||
149
        TASK->dt_state == UDEBUG_TS_ACTIVE) &&
149
        TASK->dt_state == UDEBUG_TS_ACTIVE) &&
150
        THREAD->debug_stop == true) {
150
        THREAD->debug_stop == true) {
151
        TASK->debug_begin_call = NULL;
151
        TASK->debug_begin_call = NULL;
152
        spinlock_unlock(&THREAD->debug_lock);
152
        spinlock_unlock(&THREAD->debug_lock);
153
        spinlock_unlock(&TASK->lock);
153
        spinlock_unlock(&TASK->lock);
154
        interrupts_restore(ipl);
154
        interrupts_restore(ipl);
155
 
155
 
156
        klog_printf("udebug_stoppable_end: waitq_sleep");
156
        klog_printf("udebug_stoppable_end: waitq_sleep");
157
        waitq_sleep(&THREAD->go_wq);
157
        waitq_sleep(&THREAD->go_wq);
158
        goto restart;
158
        goto restart;
159
        /* must try again - have to lose stoppability atomically */
159
        /* must try again - have to lose stoppability atomically */
160
    } else {
160
    } else {
161
        ++TASK->not_stoppable_count;
161
        ++TASK->not_stoppable_count;
162
        THREAD->debug_stoppable = false;
162
        THREAD->debug_stoppable = false;
163
 
163
 
164
        spinlock_unlock(&THREAD->debug_lock);
164
        spinlock_unlock(&THREAD->debug_lock);
165
        spinlock_unlock(&TASK->lock);
165
        spinlock_unlock(&TASK->lock);
166
        interrupts_restore(ipl);
166
        interrupts_restore(ipl);
167
    }
167
    }
168
}
168
}
169
 
169
 
170
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
170
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
171
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc)
171
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
-
 
172
    bool end_variant)
172
{
173
{
173
    call_t *call;
174
    call_t *call;
174
    ipl_t ipl;
175
    ipl_t ipl;
-
 
176
    udebug_event_t etype;
-
 
177
 
-
 
178
    etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B;
175
 
179
 
176
    ipl = interrupts_disable();
180
    ipl = interrupts_disable();
177
    spinlock_lock(&THREAD->debug_lock);
181
    spinlock_lock(&THREAD->debug_lock);
178
 
182
 
179
    /* Must only generate events when in debugging session and have go */
183
    /* Must only generate events when in debugging session and have go */
180
    if (THREAD->debug_active != true ||
184
    if (THREAD->debug_active != true ||
181
        THREAD->debug_stop == true ||
185
        THREAD->debug_stop == true ||
182
        (TASK->debug_evmask & UDEBUG_EM_SYSCALL) == 0) {
186
        (TASK->debug_evmask & UDEBUG_EVMASK(etype)) == 0) {
183
        spinlock_unlock(&THREAD->debug_lock);
187
        spinlock_unlock(&THREAD->debug_lock);
184
        interrupts_restore(ipl);
188
        interrupts_restore(ipl);
185
        return;
189
        return;
186
    }
190
    }
187
 
191
 
188
    klog_printf("udebug_syscall_event");
192
    klog_printf("udebug_syscall_event");
189
    call = THREAD->debug_go_call;
193
    call = THREAD->debug_go_call;
190
    IPC_SET_RETVAL(call->data, 0);
194
    IPC_SET_RETVAL(call->data, 0);
191
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_SYSCALL);
195
    IPC_SET_ARG1(call->data, etype);
192
    IPC_SET_ARG2(call->data, id);
196
    IPC_SET_ARG2(call->data, id);
193
    IPC_SET_ARG3(call->data, rc);
197
    IPC_SET_ARG3(call->data, rc);
194
    klog_printf("udebug_syscall_event/ipc_answer");
198
    klog_printf("udebug_syscall_event/ipc_answer");
195
 
199
 
196
    THREAD->syscall_args[0] = a1;
200
    THREAD->syscall_args[0] = a1;
197
    THREAD->syscall_args[1] = a2;
201
    THREAD->syscall_args[1] = a2;
198
    THREAD->syscall_args[2] = a3;
202
    THREAD->syscall_args[2] = a3;
199
    THREAD->syscall_args[3] = a4;
203
    THREAD->syscall_args[3] = a4;
200
    THREAD->syscall_args[4] = a5;
204
    THREAD->syscall_args[4] = a5;
201
    THREAD->syscall_args[5] = a6;
205
    THREAD->syscall_args[5] = a6;
202
 
206
 
203
    /*
207
    /*
204
     * Make sure debug_stop is true when going to sleep
208
     * Make sure debug_stop is true when going to sleep
205
     * in case we get woken up by DEBUG_END. (At which
209
     * in case we get woken up by DEBUG_END. (At which
206
     * point it must be back to the initial true value).
210
     * point it must be back to the initial true value).
207
     */
211
     */
208
    THREAD->debug_stop = true;
212
    THREAD->debug_stop = true;
209
 
213
 
210
    THREAD->cur_event = UDEBUG_EVENT_SYSCALL;
214
    THREAD->cur_event = etype;
211
    spinlock_unlock(&THREAD->debug_lock);
215
    spinlock_unlock(&THREAD->debug_lock);
212
 
216
 
213
    spinlock_lock(&TASK->lock);
217
    spinlock_lock(&TASK->lock);
214
    ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
218
    ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
215
    spinlock_unlock(&TASK->lock);
219
    spinlock_unlock(&TASK->lock);
216
 
220
 
217
    interrupts_restore(ipl);
221
    interrupts_restore(ipl);
218
 
222
 
219
    waitq_sleep(&THREAD->go_wq);
223
    waitq_sleep(&THREAD->go_wq);
220
}
224
}
221
 
225
 
222
void udebug_new_thread_event(struct thread *t)
226
void udebug_new_thread_event(struct thread *t)
223
{
227
{
224
    call_t *call;
228
    call_t *call;
225
    ipl_t ipl;
229
    ipl_t ipl;
226
 
230
 
227
    ipl = interrupts_disable();
231
    ipl = interrupts_disable();
228
    spinlock_lock(&THREAD->debug_lock);
232
    spinlock_lock(&THREAD->debug_lock);
229
 
233
 
230
    klog_printf("udebug_new_thread_event");
234
    klog_printf("udebug_new_thread_event");
231
    klog_printf("- check state");
235
    klog_printf("- check state");
232
 
236
 
233
    /* Must only generate events when in debugging session */
237
    /* Must only generate events when in debugging session */
234
    if (THREAD->debug_active != true) {
238
    if (THREAD->debug_active != true) {
235
        klog_printf("- debug_active: %s, debug_stop: %s",
239
        klog_printf("- debug_active: %s, debug_stop: %s",
236
            THREAD->debug_active ? "yes(+)" : "no(-)",
240
            THREAD->debug_active ? "yes(+)" : "no(-)",
237
            THREAD->debug_stop ? "yes(-)" : "no(+)");
241
            THREAD->debug_stop ? "yes(-)" : "no(+)");
238
        spinlock_unlock(&THREAD->debug_lock);
242
        spinlock_unlock(&THREAD->debug_lock);
239
        interrupts_restore(ipl);
243
        interrupts_restore(ipl);
240
        return;
244
        return;
241
    }
245
    }
242
 
246
 
243
    klog_printf("- trigger event");
247
    klog_printf("- trigger event");
244
 
248
 
245
    call = THREAD->debug_go_call;
249
    call = THREAD->debug_go_call;
246
    IPC_SET_RETVAL(call->data, 0);
250
    IPC_SET_RETVAL(call->data, 0);
247
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_NEW_THREAD);
251
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_NEW_THREAD);
248
    IPC_SET_ARG2(call->data, (unative_t)t);
252
    IPC_SET_ARG2(call->data, (unative_t)t);
249
 
253
 
250
    /*
254
    /*
251
     * Make sure debug_stop is true when going to sleep
255
     * Make sure debug_stop is true when going to sleep
252
     * in case we get woken up by DEBUG_END. (At which
256
     * in case we get woken up by DEBUG_END. (At which
253
     * point it must be back to the initial true value).
257
     * point it must be back to the initial true value).
254
     */
258
     */
255
    THREAD->debug_stop = true;
259
    THREAD->debug_stop = true;
256
 
260
 
257
    THREAD->cur_event = UDEBUG_EVENT_NEW_THREAD;
261
    THREAD->cur_event = UDEBUG_EVENT_NEW_THREAD;
258
    spinlock_unlock(&THREAD->debug_lock);
262
    spinlock_unlock(&THREAD->debug_lock);
259
 
263
 
260
    spinlock_lock(&TASK->lock);
264
    spinlock_lock(&TASK->lock);
261
    ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
265
    ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
262
    spinlock_unlock(&TASK->lock);
266
    spinlock_unlock(&TASK->lock);
263
 
267
 
264
    interrupts_restore(ipl);
268
    interrupts_restore(ipl);
265
    klog_printf("- sleep");
269
    klog_printf("- sleep");
266
 
270
 
267
    waitq_sleep(&THREAD->go_wq);
271
    waitq_sleep(&THREAD->go_wq);
268
}
272
}
269
 
273
 
270
/**
274
/**
271
 * Terminate task debugging session.
275
 * Terminate task debugging session.
272
 *
276
 *
273
 * \param ta Must be already locked and interrupts must be disabled.
277
 * \param ta Must be already locked and interrupts must be disabled.
274
 * \return Zero on success or negative error code.
278
 * \return Zero on success or negative error code.
275
 */
279
 */
276
int udebug_task_cleanup(struct task *ta)
280
int udebug_task_cleanup(struct task *ta)
277
{
281
{
278
    thread_t *t;
282
    thread_t *t;
279
    link_t *cur;
283
    link_t *cur;
280
    int flags;
284
    int flags;
281
 
285
 
282
    klog_printf("udebug_task_cleanup()");
286
    klog_printf("udebug_task_cleanup()");
283
    klog_printf("task %llu", ta->taskid);
287
    klog_printf("task %llu", ta->taskid);
284
 
288
 
285
    if (ta->dt_state == UDEBUG_TS_BEGINNING &&
289
    if (ta->dt_state == UDEBUG_TS_BEGINNING &&
286
        ta->dt_state != UDEBUG_TS_ACTIVE) {
290
        ta->dt_state != UDEBUG_TS_ACTIVE) {
287
        klog_printf("udebug_task_cleanup(): task not being debugged");
291
        klog_printf("udebug_task_cleanup(): task not being debugged");
288
        return EINVAL;
292
        return EINVAL;
289
    }
293
    }
290
 
294
 
291
    /* Finish debugging of all userspace threads */
295
    /* Finish debugging of all userspace threads */
292
    for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
296
    for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
293
        t = list_get_instance(cur, thread_t, th_link);
297
        t = list_get_instance(cur, thread_t, th_link);
294
 
298
 
295
        spinlock_lock(&t->debug_lock);
299
        spinlock_lock(&t->debug_lock);
296
        spinlock_lock(&t->lock);
300
        spinlock_lock(&t->lock);
297
 
301
 
298
        flags = t->flags;
302
        flags = t->flags;
299
 
303
 
300
        spinlock_unlock(&t->lock);
304
        spinlock_unlock(&t->lock);
301
 
305
 
302
        /* Only process userspace threads */
306
        /* Only process userspace threads */
303
        if ((flags & THREAD_FLAG_USPACE) != 0) {
307
        if ((flags & THREAD_FLAG_USPACE) != 0) {
304
            /* Prevent any further debug activity in thread */
308
            /* Prevent any further debug activity in thread */
305
            t->debug_active = false;
309
            t->debug_active = false;
306
            t->cur_event = 0;   /* none */
310
            t->cur_event = 0;   /* none */
307
 
311
 
308
            /* Still has go? */
312
            /* Still has go? */
309
            if (t->debug_stop == false) {
313
            if (t->debug_stop == false) {
310
                /*
314
                /*
311
                * Yes, so clear go. As debug_active == false,
315
                * Yes, so clear go. As debug_active == false,
312
                 * this doesn't affect anything.
316
                 * this doesn't affect anything.
313
                 */
317
                 */
314
                t->debug_stop = true;  
318
                t->debug_stop = true;  
315
 
319
 
316
                /* Answer GO call */
320
                /* Answer GO call */
317
                klog_printf("answer GO call with EVENT_FINISHED");
321
                klog_printf("answer GO call with EVENT_FINISHED");
318
                IPC_SET_RETVAL(t->debug_go_call->data, 0);
322
                IPC_SET_RETVAL(t->debug_go_call->data, 0);
319
                IPC_SET_ARG1(t->debug_go_call->data, UDEBUG_EVENT_FINISHED);
323
                IPC_SET_ARG1(t->debug_go_call->data, UDEBUG_EVENT_FINISHED);
320
                ipc_answer(&ta->answerbox, t->debug_go_call);
324
                ipc_answer(&ta->answerbox, t->debug_go_call);
321
            } else {
325
            } else {
322
                /*
326
                /*
323
                 * Debug_stop is already at initial value.
327
                 * Debug_stop is already at initial value.
324
                 * Yet this means the thread needs waking up.
328
                 * Yet this means the thread needs waking up.
325
                 */
329
                 */
326
 
330
 
327
                /*
331
                /*
328
                 * t's lock must not be held when calling
332
                 * t's lock must not be held when calling
329
                 * waitq_wakeup.
333
                 * waitq_wakeup.
330
                 */
334
                 */
331
                waitq_wakeup(&t->go_wq, WAKEUP_FIRST);
335
                waitq_wakeup(&t->go_wq, WAKEUP_FIRST);
332
            }
336
            }
333
        }
337
        }
334
        spinlock_unlock(&t->debug_lock);
338
        spinlock_unlock(&t->debug_lock);
335
    }
339
    }
336
 
340
 
337
    ta->dt_state = UDEBUG_TS_INACTIVE;
341
    ta->dt_state = UDEBUG_TS_INACTIVE;
338
    ta->debugger = NULL;
342
    ta->debugger = NULL;
339
 
343
 
340
    return 0;
344
    return 0;
341
}
345
}
342
 
346
 
343
 
347
 
344
/** @}
348
/** @}
345
 */
349
 */
346
 
350