Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3015 → Rev 3016

/branches/tracing/kernel/generic/include/udebug/udebug.h
175,6 → 175,8
 
#ifdef KERNEL
 
#include <synch/mutex.h>
 
typedef enum {
/** Task is not being debugged */
UDEBUG_TS_INACTIVE,
189,6 → 191,9
/** Debugging part of task_t structure.
*/
typedef struct {
/** Synchronize debug ops on this task / access to this structure */
mutex_t lock;
 
udebug_task_state_t dt_state;
call_t *begin_call;
int not_stoppable_count;
/branches/tracing/kernel/generic/src/udebug/udebug.c
43,6 → 43,7
 
void udebug_task_init(udebug_task_t *ut)
{
mutex_initialize(&ut->lock);
ut->dt_state = UDEBUG_TS_INACTIVE;
ut->begin_call = NULL;
ut->not_stoppable_count = 0;
71,8 → 72,7
ASSERT(THREAD);
ASSERT(TASK);
 
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
mutex_lock(&TASK->udebug.lock);
 
nsc = --TASK->udebug.not_stoppable_count;
 
90,15 → 90,16
db_call = TASK->udebug.begin_call;
ASSERT(db_call);
 
/* Lock order OK, THREAD->debug_lock is after TASK->lock */
/* Lock order OK, THREAD->debug_lock is after TASK->udebug.lock */
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
THREAD->debug_stoppable = true;
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
 
TASK->udebug.dt_state = UDEBUG_TS_ACTIVE;
TASK->udebug.begin_call = NULL;
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
 
IPC_SET_RETVAL(db_call->data, 0);
//klog_printf("udebug_stoppable_begin/ipc_answer");
109,7 → 110,8
* Active debugging session
*/
 
/* Lock order OK, THREAD->debug_lock is after TASK->lock */
/* Lock order OK, THREAD->debug_lock is after TASK->udebug.lock */
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
THREAD->debug_stoppable = true;
 
128,18 → 130,18
 
THREAD->cur_event = UDEBUG_EVENT_STOP;
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
 
ipc_answer(&TASK->answerbox, go_call);
 
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
} else {
/*
* No stop request - nothing happens.
*/
spinlock_unlock(&THREAD->debug_lock);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
}
} else {
/*
146,13 → 148,14
* All other cases - nothing special happens.
*/
 
/* Lock order OK, THREAD->debug_lock is after TASK->lock */
/* Lock order OK, THREAD->debug_lock is after TASK->udebug.lock */
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
THREAD->debug_stoppable = true;
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
 
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
}
}
 
161,10 → 164,10
ipl_t ipl;
 
restart:
mutex_lock(&TASK->udebug.lock);
 
/* Lock order OK, THREAD->debug_lock is after TASK->udebug.lock */
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
 
/* Lock order OK, THREAD->debug_lock is after TASK->lock */
spinlock_lock(&THREAD->debug_lock);
 
if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) {
176,8 → 179,8
THREAD->debug_stop == true) {
TASK->udebug.begin_call = NULL;
spinlock_unlock(&THREAD->debug_lock);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
 
udebug_wait_for_go(&THREAD->go_wq);
 
188,8 → 191,8
THREAD->debug_stoppable = false;
 
spinlock_unlock(&THREAD->debug_lock);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
}
}
 
211,7 → 214,7
THREAD->debug_in_before_thread_runs = true;
ipl = interrupts_enable();
 
/* Now we're free to do whatever we need (lock mutexes, etc.) */
/* Now we're free to do whatever we need (lock mutexes, sleep, etc.) */
 
/* Check if we're supposed to stop */
udebug_stoppable_begin();
231,6 → 234,8
 
etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B;
 
mutex_lock(&TASK->udebug.lock);
 
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
 
240,11 → 245,14
(TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) {
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
return;
}
 
//klog_printf("udebug_syscall_event");
call = THREAD->debug_go_call;
THREAD->debug_go_call = NULL;
 
IPC_SET_RETVAL(call->data, 0);
IPC_SET_ARG1(call->data, etype);
IPC_SET_ARG2(call->data, id);
267,12 → 275,12
 
THREAD->cur_event = etype;
spinlock_unlock(&THREAD->debug_lock);
 
spinlock_lock(&TASK->lock);
ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
 
ipc_answer(&TASK->answerbox, call);
 
mutex_unlock(&TASK->udebug.lock);
 
udebug_wait_for_go(&THREAD->go_wq);
}
 
281,6 → 289,8
call_t *call;
ipl_t ipl;
 
mutex_lock(&TASK->udebug.lock);
 
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
 
294,6 → 304,7
THREAD->debug_stop ? "yes(-)" : "no(+)");
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
return;
}
 
300,6 → 311,7
klog_printf("- trigger event");
 
call = THREAD->debug_go_call;
THREAD->debug_go_call = NULL;
IPC_SET_RETVAL(call->data, 0);
IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B);
IPC_SET_ARG2(call->data, (unative_t)t);
313,12 → 325,12
 
THREAD->cur_event = UDEBUG_EVENT_THREAD_B;
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
 
spinlock_lock(&TASK->lock);
ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
spinlock_unlock(&TASK->lock);
ipc_answer(&TASK->answerbox, call);
 
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
 
klog_printf("- sleep");
udebug_wait_for_go(&THREAD->go_wq);
}
328,6 → 340,8
call_t *call;
ipl_t ipl;
 
mutex_lock(&TASK->udebug.lock);
 
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
 
341,6 → 355,7
THREAD->debug_stop ? "yes(-)" : "no(+)");
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
return;
}
 
347,6 → 362,7
klog_printf("- trigger event");
 
call = THREAD->debug_go_call;
THREAD->debug_go_call = NULL;
IPC_SET_RETVAL(call->data, 0);
IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E);
 
354,13 → 370,13
THREAD->debug_active = false;
THREAD->cur_event = 0; /* none */
THREAD->debug_stop = true; /* set to initial value */
 
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
 
spinlock_lock(&TASK->lock);
ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
spinlock_unlock(&TASK->lock);
ipc_answer(&TASK->answerbox, call);
 
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
 
/* This event does not sleep - debugging has finished in this thread */
}
370,6 → 386,8
call_t *call;
ipl_t ipl;
 
mutex_lock(&TASK->udebug.lock);
 
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
 
379,11 → 397,14
(TASK->udebug.evmask & UDEBUG_EVMASK(etype)) == 0) {
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
return;
}
 
klog_printf("udebug_breakpoint/trap_event");
call = THREAD->debug_go_call;
THREAD->debug_go_call = NULL;
 
IPC_SET_RETVAL(call->data, 0);
IPC_SET_ARG1(call->data, etype);
IPC_SET_ARG2(call->data, addr);
397,12 → 418,11
 
THREAD->cur_event = etype;
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
klog_printf("- send answer");
 
spinlock_lock(&TASK->lock);
ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
ipc_answer(&TASK->answerbox, call);
mutex_unlock(&TASK->udebug.lock);
 
udebug_wait_for_go(&THREAD->go_wq);
}
420,7 → 440,7
/**
* Terminate task debugging session.
*
* \param ta Must be already locked and interrupts must be disabled.
* \param ta->udebug.lock must be already locked.
* \return Zero on success or negative error code.
*/
int udebug_task_cleanup(struct task *ta)
428,6 → 448,7
thread_t *t;
link_t *cur;
int flags;
ipl_t ipl;
 
klog_printf("udebug_task_cleanup()");
klog_printf("task %llu", ta->taskid);
442,6 → 463,7
for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
t = list_get_instance(cur, thread_t, th_link);
 
ipl = interrupts_disable();
spinlock_lock(&t->debug_lock);
spinlock_lock(&t->lock);
 
467,7 → 489,9
klog_printf("answer GO call with EVENT_FINISHED");
IPC_SET_RETVAL(t->debug_go_call->data, 0);
IPC_SET_ARG1(t->debug_go_call->data, UDEBUG_EVENT_FINISHED);
/* FIXME: must not call with interrupts disabled!!*/
ipc_answer(&ta->answerbox, t->debug_go_call);
t->debug_go_call = NULL;
} else {
/*
* Debug_stop is already at initial value.
482,6 → 506,7
}
}
spinlock_unlock(&t->debug_lock);
interrupts_restore(ipl);
}
 
ta->udebug.dt_state = UDEBUG_TS_INACTIVE;
/branches/tracing/kernel/generic/src/udebug/udebug_ops.c
137,14 → 137,11
 
klog_printf("udebug_begin()");
 
ipl = interrupts_disable();
mutex_lock(&TASK->udebug.lock);
klog_printf("debugging task %llu", TASK->taskid);
 
spinlock_lock(&TASK->lock);
 
if (TASK->udebug.dt_state != UDEBUG_TS_INACTIVE) {
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
klog_printf("udebug_begin(): busy error");
 
return EBUSY;
167,14 → 164,15
for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
t = list_get_instance(cur, thread_t, th_link);
 
ipl = interrupts_disable();
spinlock_lock(&t->debug_lock);
if ((t->flags & THREAD_FLAG_USPACE) != 0)
t->debug_active = true;
spinlock_unlock(&t->debug_lock);
interrupts_restore(ipl);
}
 
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
 
klog_printf("udebug_begin() done (%s)",
reply ? "reply" : "stoppability wait");
184,40 → 182,30
 
int udebug_end(void)
{
ipl_t ipl;
int rc;
 
klog_printf("udebug_end()");
 
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
mutex_lock(&TASK->udebug.lock);
klog_printf("task %llu", TASK->taskid);
 
rc = udebug_task_cleanup(TASK);
 
klog_printf("task %llu", TASK->taskid);
mutex_unlock(&TASK->udebug.lock);
 
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
 
if (rc < 0) return EINVAL;
 
return 0;
return rc;
}
 
int udebug_set_evmask(udebug_evmask_t mask)
{
ipl_t ipl;
 
klog_printf("udebug_set_mask()");
 
ipl = interrupts_disable();
klog_printf("debugging task %llu", TASK->taskid);
 
spinlock_lock(&TASK->lock);
mutex_lock(&TASK->udebug.lock);
 
if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
klog_printf("udebug_set_mask(): not active debuging session");
 
return EINVAL;
225,8 → 213,7
 
TASK->udebug.evmask = mask;
 
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
mutex_unlock(&TASK->udebug.lock);
 
return 0;
}
269,6 → 256,7
int rc;
 
klog_printf("udebug_stop()");
mutex_lock(&TASK->udebug.lock);
 
ipl = interrupts_disable();
 
306,13 → 294,13
klog_printf("udebug_stop/ipc_answer");
 
THREAD->cur_event = UDEBUG_EVENT_STOP;
 
_thread_op_end(t);
interrupts_restore(ipl);
 
spinlock_lock(&TASK->lock);
ipc_answer(&TASK->answerbox, call);
spinlock_unlock(&TASK->lock);
mutex_unlock(&TASK->udebug.lock);
 
interrupts_restore(ipl);
klog_printf("udebog_stop/done");
return 0;
}
333,17 → 321,16
/* Allocate a buffer to hold thread IDs */
id_buffer = malloc(buf_size, 0);
 
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
mutex_lock(&TASK->udebug.lock);
 
/* Verify task state */
if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
 
mutex_unlock(&TASK->udebug.lock);
return EINVAL;
}
 
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
/* Copy down the thread IDs */
 
max_ids = buf_size / sizeof(unative_t);
370,6 → 357,8
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
 
mutex_unlock(&TASK->udebug.lock);
 
*buffer = id_buffer;
*n = copied_ids * sizeof(unative_t);
 
492,17 → 481,25
void *data_buffer;
int rc;
 
klog_printf("udebug_mem_read()");
/* Verify task state */
mutex_lock(&TASK->udebug.lock);
 
if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
mutex_unlock(&TASK->udebug.lock);
return EBUSY;
}
 
data_buffer = malloc(n, 0);
 
klog_printf("udebug_mem_read: src=%u, size=%u", uspace_addr, n);
// klog_printf("udebug_mem_read: src=%u, size=%u", uspace_addr, n);
 
/* NOTE: this is not strictly from a syscall... but that shouldn't
* be a problem */
rc = copy_from_uspace(data_buffer, (void *)uspace_addr, n);
if (rc) return rc;
mutex_unlock(&TASK->udebug.lock);
 
if (rc != 0) return rc;
 
*buffer = data_buffer;
return 0;
}
510,17 → 507,16
int udebug_mem_write(unative_t uspace_addr, void *data, size_t n)
{
int rc;
udebug_task_state_t dts;
 
klog_printf("udebug_mem_write()");
 
/* Verify task state */
spinlock_lock(&TASK->lock);
dts = TASK->udebug.dt_state;
spinlock_unlock(&TASK->lock);
mutex_lock(&TASK->udebug.lock);
 
if (dts != UDEBUG_TS_ACTIVE)
if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
mutex_unlock(&TASK->udebug.lock);
return EBUSY;
}
klog_printf("dst=%u, size=%u", uspace_addr, n);
 
531,6 → 527,8
 
rc = as_debug_write(uspace_addr, data, n);
 
mutex_unlock(&TASK->udebug.lock);
 
return rc;
}