Subversion Repositories HelenOS

Rev

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