Subversion Repositories HelenOS

Rev

Rev 3018 | Rev 3030 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2894 svoboda 1
/*
2
 * Copyright (c) 2008 Jiri Svoboda
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
2801 svoboda 29
/** @addtogroup generic
30
 * @{
31
 */
32
 
33
/**
34
 * @file
2894 svoboda 35
 * @brief   Udebug.
2801 svoboda 36
 */
37
 
38
#include <synch/waitq.h>
39
#include <console/klog.h>
2813 svoboda 40
#include <udebug/udebug.h>
2870 svoboda 41
#include <errno.h>
2801 svoboda 42
#include <arch.h>
43
 
3026 svoboda 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
 
3014 svoboda 62
void udebug_task_init(udebug_task_t *ut)
63
{
3016 svoboda 64
    mutex_initialize(&ut->lock);
3014 svoboda 65
    ut->dt_state = UDEBUG_TS_INACTIVE;
66
    ut->begin_call = NULL;
67
    ut->not_stoppable_count = 0;
68
    ut->evmask = 0;
69
}
70
 
3018 svoboda 71
void udebug_thread_initialize(udebug_thread_t *ut)
72
{
3026 svoboda 73
    mutex_initialize(&ut->lock);
3018 svoboda 74
    waitq_initialize(&ut->go_wq);
3026 svoboda 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
 
3018 svoboda 81
    ut->go_call = NULL;
82
    ut->uspace_state = NULL;
83
    ut->stop = true;
84
    ut->stoppable = true;
85
    ut->debug_active = false;
86
    ut->cur_event = 0; /* none */
87
}
88
 
2917 svoboda 89
static void udebug_wait_for_go(waitq_t *wq)
90
{
91
    int rc;
92
    ipl_t ipl;
93
 
94
    ipl = waitq_sleep_prepare(wq);
95
 
96
    wq->missed_wakeups = 0; /* Enforce blocking. */
97
    rc = waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
98
 
99
    waitq_sleep_finish(wq, rc, ipl);
100
}
101
 
2804 svoboda 102
void udebug_stoppable_begin(void)
2801 svoboda 103
{
2804 svoboda 104
    int nsc;
2898 svoboda 105
    call_t *db_call, *go_call;
2804 svoboda 106
 
2902 svoboda 107
    ASSERT(THREAD);
108
    ASSERT(TASK);
109
 
3026 svoboda 110
    udebug_int_lock();
111
 
3016 svoboda 112
    mutex_lock(&TASK->udebug.lock);
2804 svoboda 113
 
3014 svoboda 114
    nsc = --TASK->udebug.not_stoppable_count;
2804 svoboda 115
 
3014 svoboda 116
    if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING) {
2804 svoboda 117
        klog_printf("udebug_stoppable_begin");
118
        klog_printf(" - nsc := %d", nsc);
119
    }
120
 
3014 svoboda 121
    if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING && nsc == 0) {
2898 svoboda 122
        /*
123
         * This was the last non-stoppable thread. Reply to
124
         * DEBUG_BEGIN call.
125
         */
126
 
3014 svoboda 127
        db_call = TASK->udebug.begin_call;
2902 svoboda 128
        ASSERT(db_call);
129
 
3018 svoboda 130
        /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */
3026 svoboda 131
        mutex_lock(&THREAD->udebug.lock);
132
        ASSERT(THREAD->udebug.stoppable == false);
3018 svoboda 133
        THREAD->udebug.stoppable = true;
3026 svoboda 134
        mutex_unlock(&THREAD->udebug.lock);
2898 svoboda 135
 
3014 svoboda 136
        TASK->udebug.dt_state = UDEBUG_TS_ACTIVE;
137
        TASK->udebug.begin_call = NULL;
3016 svoboda 138
        mutex_unlock(&TASK->udebug.lock);
2804 svoboda 139
 
140
        IPC_SET_RETVAL(db_call->data, 0);
2913 svoboda 141
        //klog_printf("udebug_stoppable_begin/ipc_answer");
2804 svoboda 142
        ipc_answer(&TASK->answerbox, db_call);     
2898 svoboda 143
 
3014 svoboda 144
    } else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) {
2898 svoboda 145
        /*
146
         * Active debugging session
147
         */
148
 
3018 svoboda 149
        /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */
3026 svoboda 150
        mutex_lock(&THREAD->udebug.lock);
151
        ASSERT(THREAD->udebug.stoppable == false);
3018 svoboda 152
        THREAD->udebug.stoppable = true;
2898 svoboda 153
 
3018 svoboda 154
        if (THREAD->udebug.debug_active && THREAD->udebug.stop) {
2898 svoboda 155
            /*
156
             * Thread was requested to stop - answer go call
157
             */
158
 
159
            /* Make sure nobody takes this call away from us */
3018 svoboda 160
            go_call = THREAD->udebug.go_call;
161
            THREAD->udebug.go_call = NULL;
2902 svoboda 162
            ASSERT(go_call);
2898 svoboda 163
 
164
            IPC_SET_RETVAL(go_call->data, 0);
165
            IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP);
166
 
3018 svoboda 167
            THREAD->udebug.cur_event = UDEBUG_EVENT_STOP;
3026 svoboda 168
            mutex_unlock(&THREAD->udebug.lock);
2898 svoboda 169
 
170
                ipc_answer(&TASK->answerbox, go_call);
171
 
3016 svoboda 172
                mutex_unlock(&TASK->udebug.lock);
2898 svoboda 173
        } else {
174
            /*
175
             * No stop request - nothing happens.
176
             */
3026 svoboda 177
            mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 178
                mutex_unlock(&TASK->udebug.lock);
2898 svoboda 179
        }
2804 svoboda 180
    } else {
2898 svoboda 181
        /*
182
         * All other cases - nothing special happens.
183
         */
184
 
3018 svoboda 185
        /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */
3026 svoboda 186
        mutex_lock(&THREAD->udebug.lock);
187
        ASSERT(THREAD->udebug.stoppable == false);
3018 svoboda 188
        THREAD->udebug.stoppable = true;
3026 svoboda 189
        mutex_unlock(&THREAD->udebug.lock);
2898 svoboda 190
 
3016 svoboda 191
            mutex_unlock(&TASK->udebug.lock);
2804 svoboda 192
    }
193
}
194
 
195
void udebug_stoppable_end(void)
196
{
197
restart:
3016 svoboda 198
    mutex_lock(&TASK->udebug.lock);
199
 
3018 svoboda 200
    /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */
3026 svoboda 201
    mutex_lock(&THREAD->udebug.lock);
2898 svoboda 202
 
3014 svoboda 203
    if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) {
2913 svoboda 204
        //klog_printf("udebug_stoppable_end");
3018 svoboda 205
        //klog_printf("udebug.stop=%d", THREAD->udebug.stop);
2898 svoboda 206
    }
207
 
3018 svoboda 208
    if (THREAD->udebug.debug_active &&
209
        THREAD->udebug.stop == true) {
3014 svoboda 210
        TASK->udebug.begin_call = NULL;
3026 svoboda 211
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 212
        mutex_unlock(&TASK->udebug.lock);
2823 svoboda 213
 
3018 svoboda 214
        udebug_wait_for_go(&THREAD->udebug.go_wq);
2917 svoboda 215
 
2804 svoboda 216
        goto restart;
217
        /* must try again - have to lose stoppability atomically */
218
    } else {
3014 svoboda 219
        ++TASK->udebug.not_stoppable_count;
3026 svoboda 220
        ASSERT(THREAD->udebug.stoppable == true);
3018 svoboda 221
        THREAD->udebug.stoppable = false;
2898 svoboda 222
 
3026 svoboda 223
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 224
        mutex_unlock(&TASK->udebug.lock);
2801 svoboda 225
    }
3026 svoboda 226
 
227
    udebug_int_unlock();
2801 svoboda 228
}
229
 
3015 svoboda 230
/** Upon being scheduled to run, check if the current thread should stop.
231
 *
232
 * This function is called from clock(). Preemption is enabled.
233
 * interrupts are disabled, but since this is called after
234
 * being scheduled-in, we can enable them, if we're careful enough
3026 svoboda 235
 * not to allow arbitrary recursion or deadlock with the thread context.
3015 svoboda 236
 */
237
void udebug_before_thread_runs(void)
238
{
239
    ipl_t ipl;
240
 
3026 svoboda 241
    ASSERT(!PREEMPTION_DISABLED);
242
 
243
    /*
244
     * Prevent agains re-entering, such as when preempted inside this
245
     * function.
246
     */
247
    if (atomic_get(&THREAD->udebug.int_lock) != 0)
3015 svoboda 248
        return;
249
 
3026 svoboda 250
    udebug_int_lock();
251
 
3015 svoboda 252
    ipl = interrupts_enable();
253
 
3016 svoboda 254
    /* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */
3015 svoboda 255
 
256
    /* Check if we're supposed to stop */
257
    udebug_stoppable_begin();
258
    udebug_stoppable_end();
259
 
260
    interrupts_restore(ipl);
3026 svoboda 261
 
262
    udebug_int_unlock();
3015 svoboda 263
}
264
 
2805 svoboda 265
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
2901 svoboda 266
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
267
    bool end_variant)
2801 svoboda 268
{
2805 svoboda 269
    call_t *call;
2901 svoboda 270
    udebug_event_t etype;
2805 svoboda 271
 
2901 svoboda 272
    etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B;
273
 
3026 svoboda 274
    udebug_int_lock();
275
 
3016 svoboda 276
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 277
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 278
 
2854 svoboda 279
    /* Must only generate events when in debugging session and have go */
3018 svoboda 280
    if (THREAD->udebug.debug_active != true ||
281
        THREAD->udebug.stop == true ||
3014 svoboda 282
        (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) {
3026 svoboda 283
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 284
        mutex_unlock(&TASK->udebug.lock);
2867 svoboda 285
        return;
286
    }
2804 svoboda 287
 
2913 svoboda 288
    //klog_printf("udebug_syscall_event");
3018 svoboda 289
    call = THREAD->udebug.go_call;
290
    THREAD->udebug.go_call = NULL;
3016 svoboda 291
 
2867 svoboda 292
    IPC_SET_RETVAL(call->data, 0);
2901 svoboda 293
    IPC_SET_ARG1(call->data, etype);
2867 svoboda 294
    IPC_SET_ARG2(call->data, id);
295
    IPC_SET_ARG3(call->data, rc);
2913 svoboda 296
    //klog_printf("udebug_syscall_event/ipc_answer");
2805 svoboda 297
 
3018 svoboda 298
    THREAD->udebug.syscall_args[0] = a1;
299
    THREAD->udebug.syscall_args[1] = a2;
300
    THREAD->udebug.syscall_args[2] = a3;
301
    THREAD->udebug.syscall_args[3] = a4;
302
    THREAD->udebug.syscall_args[4] = a5;
303
    THREAD->udebug.syscall_args[5] = a6;
2866 svoboda 304
 
2867 svoboda 305
    /*
3018 svoboda 306
     * Make sure udebug.stop is true when going to sleep
2867 svoboda 307
     * in case we get woken up by DEBUG_END. (At which
308
     * point it must be back to the initial true value).
309
     */
3018 svoboda 310
    THREAD->udebug.stop = true;
2825 svoboda 311
 
3018 svoboda 312
    THREAD->udebug.cur_event = etype;
3026 svoboda 313
    mutex_unlock(&THREAD->udebug.lock);
2867 svoboda 314
 
3016 svoboda 315
    ipc_answer(&TASK->answerbox, call);
316
 
317
    mutex_unlock(&TASK->udebug.lock);
318
 
3018 svoboda 319
    udebug_wait_for_go(&THREAD->udebug.go_wq);
3026 svoboda 320
 
321
    udebug_int_unlock();
2867 svoboda 322
}
323
 
2903 svoboda 324
void udebug_thread_b_event(struct thread *t)
2867 svoboda 325
{
326
    call_t *call;
327
 
3026 svoboda 328
    udebug_int_lock();
329
 
3016 svoboda 330
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 331
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 332
 
2903 svoboda 333
    klog_printf("udebug_thread_b_event");
2867 svoboda 334
    klog_printf("- check state");
335
 
336
    /* Must only generate events when in debugging session */
3018 svoboda 337
    if (THREAD->udebug.debug_active != true) {
338
        klog_printf("- debug_active: %s, udebug.stop: %s",
339
            THREAD->udebug.debug_active ? "yes(+)" : "no(-)",
340
            THREAD->udebug.stop ? "yes(-)" : "no(+)");
3026 svoboda 341
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 342
        mutex_unlock(&TASK->udebug.lock);
2867 svoboda 343
        return;
2801 svoboda 344
    }
2867 svoboda 345
 
346
    klog_printf("- trigger event");
347
 
3018 svoboda 348
    call = THREAD->udebug.go_call;
349
    THREAD->udebug.go_call = NULL;
2867 svoboda 350
    IPC_SET_RETVAL(call->data, 0);
2903 svoboda 351
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B);
2867 svoboda 352
    IPC_SET_ARG2(call->data, (unative_t)t);
353
 
354
    /*
3018 svoboda 355
     * Make sure udebug.stop is true when going to sleep
2867 svoboda 356
     * in case we get woken up by DEBUG_END. (At which
357
     * point it must be back to the initial true value).
358
     */
3018 svoboda 359
    THREAD->udebug.stop = true;
2867 svoboda 360
 
3018 svoboda 361
    THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B;
3026 svoboda 362
    mutex_unlock(&THREAD->udebug.lock);
2867 svoboda 363
 
3016 svoboda 364
    ipc_answer(&TASK->answerbox, call);
2867 svoboda 365
 
3016 svoboda 366
    mutex_unlock(&TASK->udebug.lock);
367
 
2867 svoboda 368
    klog_printf("- sleep");
3018 svoboda 369
    udebug_wait_for_go(&THREAD->udebug.go_wq);
3026 svoboda 370
 
371
    udebug_int_unlock();
2801 svoboda 372
}
373
 
2903 svoboda 374
void udebug_thread_e_event(void)
375
{
376
    call_t *call;
377
 
3026 svoboda 378
    udebug_int_lock();
379
 
3016 svoboda 380
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 381
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 382
 
2903 svoboda 383
    klog_printf("udebug_thread_e_event");
384
    klog_printf("- check state");
385
 
386
    /* Must only generate events when in debugging session */
3018 svoboda 387
    if (THREAD->udebug.debug_active != true) {
388
        klog_printf("- debug_active: %s, udebug.stop: %s",
389
            THREAD->udebug.debug_active ? "yes(+)" : "no(-)",
390
            THREAD->udebug.stop ? "yes(-)" : "no(+)");
3026 svoboda 391
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 392
        mutex_unlock(&TASK->udebug.lock);
2903 svoboda 393
        return;
394
    }
395
 
396
    klog_printf("- trigger event");
397
 
3018 svoboda 398
    call = THREAD->udebug.go_call;
399
    THREAD->udebug.go_call = NULL;
2903 svoboda 400
    IPC_SET_RETVAL(call->data, 0);
401
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E);
402
 
2908 svoboda 403
    /* Prevent any further debug activity in thread */
3018 svoboda 404
    THREAD->udebug.debug_active = false;
405
    THREAD->udebug.cur_event = 0;       /* none */
406
    THREAD->udebug.stop = true; /* set to initial value */
3016 svoboda 407
 
3026 svoboda 408
    mutex_unlock(&THREAD->udebug.lock);
2903 svoboda 409
 
3016 svoboda 410
    ipc_answer(&TASK->answerbox, call);
2903 svoboda 411
 
3016 svoboda 412
    mutex_unlock(&TASK->udebug.lock);
2903 svoboda 413
 
3026 svoboda 414
    /* Leave int_lock enabled */
2908 svoboda 415
    /* This event does not sleep - debugging has finished in this thread */
2903 svoboda 416
}
417
 
2921 svoboda 418
static void breakpoint_trap_event(uintptr_t addr, udebug_event_t etype)
2918 svoboda 419
{
420
    call_t *call;
2903 svoboda 421
 
3026 svoboda 422
    udebug_int_lock();
423
 
3016 svoboda 424
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 425
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 426
 
2918 svoboda 427
    /* Must only generate events when in debugging session and have go */
3018 svoboda 428
    if (THREAD->udebug.debug_active != true ||
429
        THREAD->udebug.stop == true ||
3014 svoboda 430
        (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) {
3026 svoboda 431
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 432
        mutex_unlock(&TASK->udebug.lock);
2918 svoboda 433
        return;
434
    }
435
 
2921 svoboda 436
    klog_printf("udebug_breakpoint/trap_event");
3018 svoboda 437
    call = THREAD->udebug.go_call;
438
    THREAD->udebug.go_call = NULL;
3016 svoboda 439
 
2918 svoboda 440
    IPC_SET_RETVAL(call->data, 0);
441
    IPC_SET_ARG1(call->data, etype);
442
    IPC_SET_ARG2(call->data, addr);
443
 
444
    /*
3018 svoboda 445
     * Make sure udebug.stop is true when going to sleep
2918 svoboda 446
     * in case we get woken up by DEBUG_END. (At which
447
     * point it must be back to the initial true value).
448
     */
3018 svoboda 449
    THREAD->udebug.stop = true;
2918 svoboda 450
 
3018 svoboda 451
    THREAD->udebug.cur_event = etype;
3026 svoboda 452
    mutex_unlock(&THREAD->udebug.lock);
453
 
2918 svoboda 454
    klog_printf("- send answer");
455
 
3016 svoboda 456
    ipc_answer(&TASK->answerbox, call);
457
    mutex_unlock(&TASK->udebug.lock);
2918 svoboda 458
 
3018 svoboda 459
    udebug_wait_for_go(&THREAD->udebug.go_wq);
3026 svoboda 460
 
461
    udebug_int_unlock();
2918 svoboda 462
}
463
 
2921 svoboda 464
void udebug_breakpoint_event(uintptr_t addr)
465
{
466
    breakpoint_trap_event(addr, UDEBUG_EVENT_BREAKPOINT);
467
}
2918 svoboda 468
 
2921 svoboda 469
void udebug_trap_event(uintptr_t addr)
470
{
471
    breakpoint_trap_event(addr, UDEBUG_EVENT_TRAP);
472
}
473
 
2870 svoboda 474
/**
475
 * Terminate task debugging session.
476
 *
3016 svoboda 477
 * \param ta->udebug.lock must be already locked.
2870 svoboda 478
 * \return Zero on success or negative error code.
479
 */
480
int udebug_task_cleanup(struct task *ta)
481
{
482
    thread_t *t;
483
    link_t *cur;
484
    int flags;
3016 svoboda 485
    ipl_t ipl;
2867 svoboda 486
 
2870 svoboda 487
    klog_printf("udebug_task_cleanup()");
488
    klog_printf("task %llu", ta->taskid);
489
 
3026 svoboda 490
    udebug_int_lock();
491
 
3014 svoboda 492
    if (ta->udebug.dt_state == UDEBUG_TS_BEGINNING &&
493
        ta->udebug.dt_state != UDEBUG_TS_ACTIVE) {
2870 svoboda 494
        klog_printf("udebug_task_cleanup(): task not being debugged");
495
        return EINVAL;
496
    }
497
 
498
    /* Finish debugging of all userspace threads */
499
    for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
500
        t = list_get_instance(cur, thread_t, th_link);
501
 
3026 svoboda 502
        mutex_lock(&t->udebug.lock);
503
 
3016 svoboda 504
        ipl = interrupts_disable();
2870 svoboda 505
        spinlock_lock(&t->lock);
506
 
507
        flags = t->flags;
508
 
509
        spinlock_unlock(&t->lock);
3026 svoboda 510
        interrupts_restore(ipl);
2870 svoboda 511
 
512
        /* Only process userspace threads */
513
        if ((flags & THREAD_FLAG_USPACE) != 0) {
514
            /* Prevent any further debug activity in thread */
3018 svoboda 515
            t->udebug.debug_active = false;
516
            t->udebug.cur_event = 0;    /* none */
2870 svoboda 517
 
518
            /* Still has go? */
3018 svoboda 519
            if (t->udebug.stop == false) {
2870 svoboda 520
                /*
521
                * Yes, so clear go. As debug_active == false,
522
                 * this doesn't affect anything.
523
                 */
3018 svoboda 524
                t->udebug.stop = true; 
2870 svoboda 525
 
526
                /* Answer GO call */
527
                klog_printf("answer GO call with EVENT_FINISHED");
3018 svoboda 528
                IPC_SET_RETVAL(t->udebug.go_call->data, 0);
529
                IPC_SET_ARG1(t->udebug.go_call->data, UDEBUG_EVENT_FINISHED);
3026 svoboda 530
 
3018 svoboda 531
                ipc_answer(&ta->answerbox, t->udebug.go_call);
532
                t->udebug.go_call = NULL;
2870 svoboda 533
            } else {
534
                /*
535
                 * Debug_stop is already at initial value.
536
                 * Yet this means the thread needs waking up.
537
                 */
538
 
539
                /*
540
                 * t's lock must not be held when calling
541
                 * waitq_wakeup.
542
                 */
3018 svoboda 543
                waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST);
2870 svoboda 544
            }
545
        }
3026 svoboda 546
        mutex_unlock(&t->udebug.lock);
2870 svoboda 547
    }
548
 
3014 svoboda 549
    ta->udebug.dt_state = UDEBUG_TS_INACTIVE;
550
    ta->udebug.debugger = NULL;
2870 svoboda 551
 
3026 svoboda 552
    udebug_int_unlock();
553
 
2870 svoboda 554
    return 0;
555
}
556
 
557
 
2801 svoboda 558
/** @}
559
 */