Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
2801 svoboda 1
/** @addtogroup generic
2
 * @{
3
 */
4
 
5
/**
6
 * @file
7
 * @brief   Tdebug.
8
 */
9
 
10
#include <synch/waitq.h>
11
#include <console/klog.h>
12
#include <udebug.h>
13
#include <arch.h>
14
 
2804 svoboda 15
void udebug_stoppable_begin(void)
2801 svoboda 16
{
2804 svoboda 17
    int nsc;
18
    call_t *db_call;
19
 
20
    spinlock_lock(&TASK->lock);
21
 
22
    nsc = --TASK->not_stoppable_count;
23
    db_call = TASK->debug_begin_call;
24
 
25
    if (TASK->stop_request == true) {
26
        klog_printf("udebug_stoppable_begin");
27
        klog_printf(" - nsc := %d", nsc);
28
    }
29
 
30
    if (TASK->stop_request == true && nsc == 0) {
2801 svoboda 31
        TASK->stop_request = false;
32
        TASK->debug_begin_call = NULL;
2804 svoboda 33
        spinlock_unlock(&TASK->lock);
34
 
35
        IPC_SET_RETVAL(db_call->data, 0);
36
        klog_printf("udebug_stoppable_begin/ipc_answer");
37
        ipc_answer(&TASK->answerbox, db_call);     
38
    } else {
39
            spinlock_unlock(&TASK->lock);
40
    }
41
}
42
 
43
void udebug_stoppable_end(void)
44
{
45
restart:
46
    spinlock_lock(&TASK->lock);
47
 
48
    if (TASK->stop_request) {
49
        TASK->debug_begin_call = NULL;
50
        spinlock_unlock(&TASK->lock);
51
        klog_printf("udebug_stoppable_end: waitq_sleep");
2801 svoboda 52
        waitq_sleep(&THREAD->go_wq);
2804 svoboda 53
        goto restart;
54
        /* must try again - have to lose stoppability atomically */
55
    } else {
56
        ++TASK->not_stoppable_count;
57
        spinlock_unlock(&TASK->lock);
2801 svoboda 58
    }
59
}
60
 
61
void udebug_syscall_event(void)
62
{
2804 svoboda 63
    spinlock_lock(&TASK->lock);
2801 svoboda 64
    /* being debugged + have go */
65
    if (TASK->being_debugged && !TASK->stop_request) { /* locking! */
66
        klog_printf("udebug_syscall_event");
67
        IPC_SET_RETVAL(TASK->debug_go_call->data, 0);
2804 svoboda 68
        klog_printf("udebug_syscall_event/ipc_answer");
69
 
2801 svoboda 70
        ipc_answer(&TASK->answerbox, TASK->debug_go_call);
2804 svoboda 71
        spinlock_unlock(&TASK->lock);
2801 svoboda 72
        waitq_sleep(&THREAD->go_wq);
2804 svoboda 73
    } else {
74
        spinlock_unlock(&TASK->lock);
2801 svoboda 75
    }
76
}
77
 
78
/** @}
79
 */