Subversion Repositories HelenOS

Rev

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