Subversion Repositories HelenOS

Rev

Rev 3684 | 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
3471 svoboda 35
 * @brief   Udebug hooks and data structure management.
3031 svoboda 36
 *
3471 svoboda 37
 * Udebug is an interface that makes userspace debuggers possible.
2801 svoboda 38
 */
39
 
40
#include <synch/waitq.h>
3471 svoboda 41
#include <debug.h>
2813 svoboda 42
#include <udebug/udebug.h>
2870 svoboda 43
#include <errno.h>
4377 svoboda 44
#include <print.h>
2801 svoboda 45
#include <arch.h>
46
 
3026 svoboda 47
 
3471 svoboda 48
/** Initialize udebug part of task structure.
49
 *
50
 * Called as part of task structure initialization.
51
 * @param ut    Pointer to the structure to initialize.
52
 */
3014 svoboda 53
void udebug_task_init(udebug_task_t *ut)
54
{
3426 svoboda 55
    mutex_initialize(&ut->lock, MUTEX_PASSIVE);
3014 svoboda 56
    ut->dt_state = UDEBUG_TS_INACTIVE;
57
    ut->begin_call = NULL;
58
    ut->not_stoppable_count = 0;
59
    ut->evmask = 0;
60
}
61
 
3471 svoboda 62
/** Initialize udebug part of thread structure.
63
 *
64
 * Called as part of thread structure initialization.
65
 * @param ut    Pointer to the structure to initialize.
66
 */
3018 svoboda 67
void udebug_thread_initialize(udebug_thread_t *ut)
68
{
3426 svoboda 69
    mutex_initialize(&ut->lock, MUTEX_PASSIVE);
3018 svoboda 70
    waitq_initialize(&ut->go_wq);
3026 svoboda 71
 
3018 svoboda 72
    ut->go_call = NULL;
73
    ut->uspace_state = NULL;
3606 svoboda 74
    ut->go = false;
3018 svoboda 75
    ut->stoppable = true;
3684 svoboda 76
    ut->active = false;
3018 svoboda 77
    ut->cur_event = 0; /* none */
78
}
79
 
3471 svoboda 80
/** Wait for a GO message.
81
 *
82
 * When a debugging event occurs in a thread or the thread is stopped,
83
 * this function is called to block the thread until a GO message
84
 * is received.
85
 *
86
 * @param wq    The wait queue used by the thread to wait for GO messages.
87
 */
2917 svoboda 88
static void udebug_wait_for_go(waitq_t *wq)
89
{
90
    int rc;
91
    ipl_t ipl;
92
 
93
    ipl = waitq_sleep_prepare(wq);
94
 
95
    wq->missed_wakeups = 0; /* Enforce blocking. */
96
    rc = waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
97
 
98
    waitq_sleep_finish(wq, rc, ipl);
99
}
100
 
3030 svoboda 101
/** Do a preliminary check that a debugging session is in progress.
102
 *
3471 svoboda 103
 * This only requires the THREAD->udebug.lock mutex (and not TASK->udebug.lock
104
 * mutex). For an undebugged task, this will never block (while there could be
105
 * collisions by different threads on the TASK mutex), thus improving SMP
106
 * perormance for undebugged tasks.
107
 *
108
 * @return  True if the thread was in a debugging session when the function
109
 *      checked, false otherwise.
3030 svoboda 110
 */
111
static bool udebug_thread_precheck(void)
112
{
113
    bool res;
114
 
115
    mutex_lock(&THREAD->udebug.lock);
3684 svoboda 116
    res = THREAD->udebug.active;
3030 svoboda 117
    mutex_unlock(&THREAD->udebug.lock);
118
 
119
    return res;
120
}
121
 
3471 svoboda 122
/** Start of stoppable section.
123
 *
124
 * A stoppable section is a section of code where if the thread can be stoped. In other words,
125
 * if a STOP operation is issued, the thread is guaranteed not to execute
126
 * any userspace instructions until the thread is resumed.
127
 *
128
 * Having stoppable sections is better than having stopping points, since
129
 * a thread can be stopped even when it is blocked indefinitely in a system
130
 * call (whereas it would not reach any stopping point).
131
 */
2804 svoboda 132
void udebug_stoppable_begin(void)
2801 svoboda 133
{
2804 svoboda 134
    int nsc;
2898 svoboda 135
    call_t *db_call, *go_call;
2804 svoboda 136
 
2902 svoboda 137
    ASSERT(THREAD);
138
    ASSERT(TASK);
139
 
3030 svoboda 140
    /* Early check for undebugged tasks */
141
    if (!udebug_thread_precheck()) {
142
        return;
143
    }
144
 
3016 svoboda 145
    mutex_lock(&TASK->udebug.lock);
2804 svoboda 146
 
3014 svoboda 147
    nsc = --TASK->udebug.not_stoppable_count;
2804 svoboda 148
 
3032 svoboda 149
    /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */
150
    mutex_lock(&THREAD->udebug.lock);
151
    ASSERT(THREAD->udebug.stoppable == false);
152
    THREAD->udebug.stoppable = true;
2804 svoboda 153
 
3014 svoboda 154
    if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING && nsc == 0) {
2898 svoboda 155
        /*
156
         * This was the last non-stoppable thread. Reply to
157
         * DEBUG_BEGIN call.
158
         */
159
 
3014 svoboda 160
        db_call = TASK->udebug.begin_call;
2902 svoboda 161
        ASSERT(db_call);
162
 
3014 svoboda 163
        TASK->udebug.dt_state = UDEBUG_TS_ACTIVE;
164
        TASK->udebug.begin_call = NULL;
2804 svoboda 165
 
166
        IPC_SET_RETVAL(db_call->data, 0);
167
        ipc_answer(&TASK->answerbox, db_call);     
2898 svoboda 168
 
3014 svoboda 169
    } else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) {
2898 svoboda 170
        /*
171
         * Active debugging session
172
         */
173
 
3684 svoboda 174
        if (THREAD->udebug.active == true &&
3606 svoboda 175
            THREAD->udebug.go == false) {
2898 svoboda 176
            /*
177
             * Thread was requested to stop - answer go call
178
             */
179
 
180
            /* Make sure nobody takes this call away from us */
3018 svoboda 181
            go_call = THREAD->udebug.go_call;
182
            THREAD->udebug.go_call = NULL;
2902 svoboda 183
            ASSERT(go_call);
2898 svoboda 184
 
185
            IPC_SET_RETVAL(go_call->data, 0);
186
            IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP);
187
 
3018 svoboda 188
            THREAD->udebug.cur_event = UDEBUG_EVENT_STOP;
2898 svoboda 189
 
190
                ipc_answer(&TASK->answerbox, go_call);
191
        }
3032 svoboda 192
    }
2898 svoboda 193
 
3032 svoboda 194
    mutex_unlock(&THREAD->udebug.lock);
195
        mutex_unlock(&TASK->udebug.lock);
2804 svoboda 196
}
197
 
3471 svoboda 198
/** End of a stoppable section.
199
 *
200
 * This is the point where the thread will block if it is stopped.
201
 * (As, by definition, a stopped thread must not leave its stoppable section).
202
 */
2804 svoboda 203
void udebug_stoppable_end(void)
204
{
3030 svoboda 205
    /* Early check for undebugged tasks */
206
    if (!udebug_thread_precheck()) {
207
        return;
208
    }
209
 
2804 svoboda 210
restart:
3016 svoboda 211
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 212
    mutex_lock(&THREAD->udebug.lock);
2898 svoboda 213
 
3684 svoboda 214
    if (THREAD->udebug.active && THREAD->udebug.go == false) {
3014 svoboda 215
        TASK->udebug.begin_call = NULL;
3026 svoboda 216
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 217
        mutex_unlock(&TASK->udebug.lock);
2823 svoboda 218
 
3018 svoboda 219
        udebug_wait_for_go(&THREAD->udebug.go_wq);
2917 svoboda 220
 
2804 svoboda 221
        goto restart;
3606 svoboda 222
        /* Must try again - have to lose stoppability atomically. */
2804 svoboda 223
    } else {
3014 svoboda 224
        ++TASK->udebug.not_stoppable_count;
3026 svoboda 225
        ASSERT(THREAD->udebug.stoppable == true);
3018 svoboda 226
        THREAD->udebug.stoppable = false;
2898 svoboda 227
 
3026 svoboda 228
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 229
        mutex_unlock(&TASK->udebug.lock);
2801 svoboda 230
    }
231
}
232
 
3015 svoboda 233
/** Upon being scheduled to run, check if the current thread should stop.
234
 *
3611 svoboda 235
 * This function is called from clock().
3015 svoboda 236
 */
237
void udebug_before_thread_runs(void)
238
{
3611 svoboda 239
    /* Check if we are supposed to stop. */
3015 svoboda 240
    udebug_stoppable_begin();
241
    udebug_stoppable_end();
242
}
243
 
3471 svoboda 244
/** Syscall event hook.
245
 *
246
 * Must be called before and after servicing a system call. This generates
247
 * a SYSCALL_B or SYSCALL_E event, depending on the value of @a end_variant.
248
 */
2805 svoboda 249
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
2901 svoboda 250
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
251
    bool end_variant)
2801 svoboda 252
{
2805 svoboda 253
    call_t *call;
2901 svoboda 254
    udebug_event_t etype;
2805 svoboda 255
 
2901 svoboda 256
    etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B;
257
 
3030 svoboda 258
    /* Early check for undebugged tasks */
259
    if (!udebug_thread_precheck()) {
260
        return;
261
    }
262
 
3016 svoboda 263
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 264
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 265
 
3606 svoboda 266
    /* Must only generate events when in debugging session and is go. */
3684 svoboda 267
    if (THREAD->udebug.active != true || THREAD->udebug.go == false ||
3014 svoboda 268
        (TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) {
3026 svoboda 269
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 270
        mutex_unlock(&TASK->udebug.lock);
2867 svoboda 271
        return;
272
    }
2804 svoboda 273
 
3424 svoboda 274
    //printf("udebug_syscall_event\n");
3018 svoboda 275
    call = THREAD->udebug.go_call;
276
    THREAD->udebug.go_call = NULL;
3016 svoboda 277
 
2867 svoboda 278
    IPC_SET_RETVAL(call->data, 0);
2901 svoboda 279
    IPC_SET_ARG1(call->data, etype);
2867 svoboda 280
    IPC_SET_ARG2(call->data, id);
281
    IPC_SET_ARG3(call->data, rc);
3424 svoboda 282
    //printf("udebug_syscall_event/ipc_answer\n");
2805 svoboda 283
 
3018 svoboda 284
    THREAD->udebug.syscall_args[0] = a1;
285
    THREAD->udebug.syscall_args[1] = a2;
286
    THREAD->udebug.syscall_args[2] = a3;
287
    THREAD->udebug.syscall_args[3] = a4;
288
    THREAD->udebug.syscall_args[4] = a5;
289
    THREAD->udebug.syscall_args[5] = a6;
2866 svoboda 290
 
2867 svoboda 291
    /*
3606 svoboda 292
     * Make sure udebug.go is false when going to sleep
2867 svoboda 293
     * in case we get woken up by DEBUG_END. (At which
294
     * point it must be back to the initial true value).
295
     */
3606 svoboda 296
    THREAD->udebug.go = false;
3018 svoboda 297
    THREAD->udebug.cur_event = etype;
2867 svoboda 298
 
3016 svoboda 299
    ipc_answer(&TASK->answerbox, call);
300
 
3032 svoboda 301
    mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 302
    mutex_unlock(&TASK->udebug.lock);
303
 
3018 svoboda 304
    udebug_wait_for_go(&THREAD->udebug.go_wq);
2867 svoboda 305
}
306
 
3623 svoboda 307
/** Thread-creation event hook combined with attaching the thread.
3471 svoboda 308
 *
309
 * Must be called when a new userspace thread is created in the debugged
3623 svoboda 310
 * task. Generates a THREAD_B event. Also attaches the thread @a t
311
 * to the task @a ta.
3471 svoboda 312
 *
3623 svoboda 313
 * This is necessary to avoid a race condition where the BEGIN and THREAD_READ
314
 * requests would be handled inbetween attaching the thread and checking it
315
 * for being in a debugging session to send the THREAD_B event. We could then
316
 * either miss threads or get some threads both in the thread list
317
 * and get a THREAD_B event for them.
318
 *
3471 svoboda 319
 * @param t Structure of the thread being created. Not locked, as the
320
 *      thread is not executing yet.
3623 svoboda 321
 * @param ta    Task to which the thread should be attached.
3471 svoboda 322
 */
3623 svoboda 323
void udebug_thread_b_event_attach(struct thread *t, struct task *ta)
2867 svoboda 324
{
325
    call_t *call;
326
 
3016 svoboda 327
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 328
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 329
 
3623 svoboda 330
    thread_attach(t, ta);
331
 
3471 svoboda 332
    LOG("udebug_thread_b_event\n");
333
    LOG("- check state\n");
2867 svoboda 334
 
335
    /* Must only generate events when in debugging session */
3684 svoboda 336
    if (THREAD->udebug.active != true) {
337
        LOG("- udebug.active: %s, udebug.go: %s\n",
338
            THREAD->udebug.active ? "yes(+)" : "no(-)",
3606 svoboda 339
            THREAD->udebug.go ? "yes(-)" : "no(+)");
3026 svoboda 340
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 341
        mutex_unlock(&TASK->udebug.lock);
2867 svoboda 342
        return;
2801 svoboda 343
    }
2867 svoboda 344
 
3471 svoboda 345
    LOG("- trigger event\n");
2867 svoboda 346
 
3018 svoboda 347
    call = THREAD->udebug.go_call;
348
    THREAD->udebug.go_call = NULL;
2867 svoboda 349
    IPC_SET_RETVAL(call->data, 0);
2903 svoboda 350
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B);
2867 svoboda 351
    IPC_SET_ARG2(call->data, (unative_t)t);
352
 
353
    /*
3606 svoboda 354
     * Make sure udebug.go is false when going to sleep
2867 svoboda 355
     * in case we get woken up by DEBUG_END. (At which
356
     * point it must be back to the initial true value).
357
     */
3606 svoboda 358
    THREAD->udebug.go = false;
3018 svoboda 359
    THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B;
2867 svoboda 360
 
3016 svoboda 361
    ipc_answer(&TASK->answerbox, call);
2867 svoboda 362
 
3032 svoboda 363
    mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 364
    mutex_unlock(&TASK->udebug.lock);
365
 
3471 svoboda 366
    LOG("- sleep\n");
3018 svoboda 367
    udebug_wait_for_go(&THREAD->udebug.go_wq);
2801 svoboda 368
}
369
 
3471 svoboda 370
/** Thread-termination event hook.
371
 *
372
 * Must be called when the current thread is terminating.
373
 * Generates a THREAD_E event.
374
 */
2903 svoboda 375
void udebug_thread_e_event(void)
376
{
377
    call_t *call;
378
 
3016 svoboda 379
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 380
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 381
 
3471 svoboda 382
    LOG("udebug_thread_e_event\n");
383
    LOG("- check state\n");
2903 svoboda 384
 
3606 svoboda 385
    /* Must only generate events when in debugging session. */
3684 svoboda 386
    if (THREAD->udebug.active != true) {
387
/*      printf("- udebug.active: %s, udebug.go: %s\n",
388
            THREAD->udebug.active ? "yes(+)" : "no(-)",
3606 svoboda 389
            THREAD->udebug.go ? "yes(-)" : "no(+)");*/
3026 svoboda 390
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 391
        mutex_unlock(&TASK->udebug.lock);
2903 svoboda 392
        return;
393
    }
394
 
3471 svoboda 395
    LOG("- trigger event\n");
2903 svoboda 396
 
3018 svoboda 397
    call = THREAD->udebug.go_call;
398
    THREAD->udebug.go_call = NULL;
2903 svoboda 399
    IPC_SET_RETVAL(call->data, 0);
400
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E);
401
 
3606 svoboda 402
    /* Prevent any further debug activity in thread. */
3684 svoboda 403
    THREAD->udebug.active = false;
3018 svoboda 404
    THREAD->udebug.cur_event = 0;       /* none */
3606 svoboda 405
    THREAD->udebug.go = false;  /* set to initial value */
3016 svoboda 406
 
407
    ipc_answer(&TASK->answerbox, call);
2903 svoboda 408
 
3032 svoboda 409
    mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 410
    mutex_unlock(&TASK->udebug.lock);
2903 svoboda 411
 
3606 svoboda 412
    /*
413
     * This event does not sleep - debugging has finished
414
     * in this thread.
415
     */
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
 
3016 svoboda 422
    mutex_lock(&TASK->udebug.lock);
3026 svoboda 423
    mutex_lock(&THREAD->udebug.lock);
3016 svoboda 424
 
3606 svoboda 425
    /* Must only generate events when in debugging session and have go. */
3684 svoboda 426
    if (THREAD->udebug.active != true || THREAD->udebug.go == false) {
3026 svoboda 427
        mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 428
        mutex_unlock(&TASK->udebug.lock);
2918 svoboda 429
        return;
430
    }
431
 
3030 svoboda 432
    /* Verify that the event is enabled */
433
    if ((TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) {
434
        mutex_unlock(&THREAD->udebug.lock);
435
        mutex_unlock(&TASK->udebug.lock);
436
        return;
437
    }
438
 
3611 svoboda 439
    LOG("udebug_breakpoint/trap_event\n");
3018 svoboda 440
    call = THREAD->udebug.go_call;
441
    THREAD->udebug.go_call = NULL;
3016 svoboda 442
 
2918 svoboda 443
    IPC_SET_RETVAL(call->data, 0);
444
    IPC_SET_ARG1(call->data, etype);
445
    IPC_SET_ARG2(call->data, addr);
446
 
447
    /*
3606 svoboda 448
     * Make sure udebug.go is false when going to sleep
2918 svoboda 449
     * in case we get woken up by DEBUG_END. (At which
450
     * point it must be back to the initial true value).
451
     */
3606 svoboda 452
    THREAD->udebug.go = false;
3018 svoboda 453
    THREAD->udebug.cur_event = etype;
3026 svoboda 454
 
3611 svoboda 455
    LOG("- send answer\n");
3032 svoboda 456
    ipc_answer(&TASK->answerbox, call);
2918 svoboda 457
 
3032 svoboda 458
    mutex_unlock(&THREAD->udebug.lock);
3016 svoboda 459
    mutex_unlock(&TASK->udebug.lock);
2918 svoboda 460
 
3018 svoboda 461
    udebug_wait_for_go(&THREAD->udebug.go_wq);
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
 *
3471 svoboda 477
 * Gracefully terminates the debugging session for a task. If the debugger
478
 * is still waiting for events on some threads, it will receive a
479
 * FINISHED event for each of them.
480
 *
481
 * @param ta    Task structure. ta->udebug.lock must be already locked.
482
 * @return  Zero on success or negative error code.
2870 svoboda 483
 */
484
int udebug_task_cleanup(struct task *ta)
485
{
486
    thread_t *t;
487
    link_t *cur;
488
    int flags;
3016 svoboda 489
    ipl_t ipl;
2867 svoboda 490
 
3471 svoboda 491
    LOG("udebug_task_cleanup()\n");
492
    LOG("task %" PRIu64 "\n", ta->taskid);
2870 svoboda 493
 
3032 svoboda 494
    if (ta->udebug.dt_state != UDEBUG_TS_BEGINNING &&
3014 svoboda 495
        ta->udebug.dt_state != UDEBUG_TS_ACTIVE) {
3471 svoboda 496
        LOG("udebug_task_cleanup(): task not being debugged\n");
2870 svoboda 497
        return EINVAL;
498
    }
499
 
500
    /* Finish debugging of all userspace threads */
501
    for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
502
        t = list_get_instance(cur, thread_t, th_link);
503
 
3026 svoboda 504
        mutex_lock(&t->udebug.lock);
505
 
3016 svoboda 506
        ipl = interrupts_disable();
2870 svoboda 507
        spinlock_lock(&t->lock);
508
 
509
        flags = t->flags;
510
 
511
        spinlock_unlock(&t->lock);
3026 svoboda 512
        interrupts_restore(ipl);
2870 svoboda 513
 
3606 svoboda 514
        /* Only process userspace threads. */
2870 svoboda 515
        if ((flags & THREAD_FLAG_USPACE) != 0) {
3606 svoboda 516
            /* Prevent any further debug activity in thread. */
3684 svoboda 517
            t->udebug.active = false;
3018 svoboda 518
            t->udebug.cur_event = 0;    /* none */
2870 svoboda 519
 
3606 svoboda 520
            /* Is the thread still go? */
521
            if (t->udebug.go == true) {
2870 svoboda 522
                /*
3684 svoboda 523
                * Yes, so clear go. As active == false,
2870 svoboda 524
                 * this doesn't affect anything.
525
                 */
3606 svoboda 526
                t->udebug.go = false;  
2870 svoboda 527
 
528
                /* Answer GO call */
3471 svoboda 529
                LOG("answer GO call with EVENT_FINISHED\n");
3018 svoboda 530
                IPC_SET_RETVAL(t->udebug.go_call->data, 0);
3471 svoboda 531
                IPC_SET_ARG1(t->udebug.go_call->data,
532
                    UDEBUG_EVENT_FINISHED);
3026 svoboda 533
 
3018 svoboda 534
                ipc_answer(&ta->answerbox, t->udebug.go_call);
535
                t->udebug.go_call = NULL;
2870 svoboda 536
            } else {
537
                /*
538
                 * Debug_stop is already at initial value.
539
                 * Yet this means the thread needs waking up.
540
                 */
541
 
542
                /*
543
                 * t's lock must not be held when calling
544
                 * waitq_wakeup.
545
                 */
3018 svoboda 546
                waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST);
2870 svoboda 547
            }
548
        }
3026 svoboda 549
        mutex_unlock(&t->udebug.lock);
2870 svoboda 550
    }
551
 
3014 svoboda 552
    ta->udebug.dt_state = UDEBUG_TS_INACTIVE;
553
    ta->udebug.debugger = NULL;
2870 svoboda 554
 
555
    return 0;
556
}
557
 
558
 
2801 svoboda 559
/** @}
560
 */