/branches/snapshot/kernel/generic/include/udebug/udebug.h |
---|
105,6 → 105,18 |
*/ |
UDEBUG_M_MEM_READ, |
UDEBUG_M_TASK_MEM_AREAS_READ, |
UDEBUG_M_THREAD_COPY_KSTACK, |
UDEBUG_M_THREAD_GET_THREAD_STRUCT, |
UDEBUG_M_MEM_WRITE, |
UDEBUG_M_THREAD_RESTORE_THREAD_STRUCT, |
UDEBUG_M_RESTORE_KSTACK, |
} udebug_method_t; |
/branches/snapshot/kernel/generic/include/udebug/udebug_ops.h |
---|
49,6 → 49,14 |
int udebug_mem_read(unative_t uspace_addr, size_t n, void **buffer); |
/* CHECKPOINTING */ |
int udebug_task_get_memory_areas(void **buffer, size_t buf_size, size_t *n); |
int udebug_mem_write(void *buffer, void *start, size_t n); |
int udebug_copy_kstack(void *kstack, void **buffer, size_t n); |
int udebug_thread_get_thread_struct(thread_t *t, void **buffer); |
int udebug_restore_thread_struct(void *buffer, thread_t *t_old); |
int udebug_restore_kstack(void *buffer, size_t size, thread_t *t); |
#endif |
/** @} |
/branches/snapshot/kernel/generic/src/udebug/udebug_ipc.c |
---|
285,6 → 285,159 |
ipc_answer(&TASK->kb.box, call); |
} |
/**************************/ |
/*** CHECKPOINTING ***/ |
/**************************/ |
static void udebug_receive_thread_get_thread_struct(call_t *call) |
{ |
unative_t to_copy; |
unative_t total_bytes; |
thread_t *t = (thread_t *)IPC_GET_ARG3(call->data); |
void *buffer; |
unative_t uspace_addr = IPC_GET_ARG2(call->data); |
size_t buf_size = IPC_GET_ARG4(call->data); |
if (buf_size < sizeof(thread_t)) |
{ |
to_copy = 0; |
total_bytes = sizeof(thread_t); |
} |
else |
{ |
udebug_thread_get_thread_struct(t, &buffer); |
to_copy = sizeof(thread_t); |
total_bytes = sizeof(thread_t); |
} |
IPC_SET_RETVAL(call->data, 0); |
IPC_SET_ARG1(call->data, uspace_addr); |
IPC_SET_ARG2(call->data, to_copy); |
IPC_SET_ARG3(call->data, total_bytes); |
if (to_copy > 0) |
call->buffer = buffer; |
else |
call->buffer = NULL; |
ipc_answer(&TASK->kb.box, call); |
} |
static void udebug_receive_thread_copy_kstack(call_t *call) |
{ |
void *buffer; |
unative_t uspace_addr = IPC_GET_ARG2(call->data); |
size_t buf_size = IPC_GET_ARG3(call->data); |
thread_t *t = (thread_t *)IPC_GET_ARG4(call->data); |
size_t copied; |
size_t kstack_size = PAGE_SIZE;//(uintptr_t)t->saved_context.sp - (uintptr_t)t->kstack; |
if (buf_size >= kstack_size) |
{ |
udebug_copy_kstack(t->kstack, &buffer, buf_size); |
copied = kstack_size; |
} |
else |
copied = 0; |
IPC_SET_RETVAL(call->data, 0); |
IPC_SET_ARG1(call->data, uspace_addr); |
IPC_SET_ARG2(call->data, copied); |
IPC_SET_ARG3(call->data, kstack_size); // needed |
if (copied > 0) |
call->buffer = (void *)buffer; |
else |
call->buffer = NULL; |
ipc_answer(&TASK->kb.box, call); |
} |
static void udebug_receive_task_mem_areas_read(call_t *call) |
{ |
unative_t uspace_addr; |
unative_t to_copy; |
unsigned total_bytes; |
unsigned buf_size; |
void *buffer; |
size_t n; |
int rc; |
uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ |
buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ |
rc = udebug_task_get_memory_areas(&buffer, buf_size, &n); |
if (rc < 0) { |
IPC_SET_RETVAL(call->data, rc); |
ipc_answer(&TASK->kb.box, call); |
return; |
} |
total_bytes = n; |
/* Copy MAX(buf_size, total_bytes) bytes */ |
if (buf_size > total_bytes) |
to_copy = total_bytes; |
else |
to_copy = buf_size; |
/* |
* Make use of call->buffer to transfer data to caller's userspace |
*/ |
IPC_SET_RETVAL(call->data, 0); |
/* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
same code in process_answer() can be used |
(no way to distinguish method in answer) */ |
IPC_SET_ARG1(call->data, uspace_addr); |
IPC_SET_ARG2(call->data, to_copy); |
IPC_SET_ARG3(call->data, total_bytes); |
call->buffer = buffer; |
ipc_answer(&TASK->kb.box, call); |
} |
static void udebug_receive_mem_write(call_t *call) |
{ |
size_t size = (size_t)IPC_GET_ARG3(call->data); |
void *start = (void *)IPC_GET_ARG4(call->data); |
udebug_mem_write(call->buffer, start, size); |
IPC_SET_RETVAL(call->data, 0); |
ipc_answer(&TASK->kb.box, call); |
} |
static void udebug_receive_thread_restore_struct(call_t *call) |
{ |
thread_t *t = (thread_t *)IPC_GET_ARG3(call->data); |
udebug_restore_thread_struct(call->buffer, t); |
IPC_SET_RETVAL(call->data, 0); |
ipc_answer(&TASK->kb.box, call); |
} |
static void udebug_receive_restore_kstack(call_t *call) |
{ |
size_t size = (size_t)IPC_GET_ARG3(call->data); |
thread_t *t = (thread_t *)IPC_GET_ARG4(call->data); |
udebug_restore_kstack(call->buffer, size, t); |
IPC_SET_RETVAL(call->data, 0); |
ipc_answer(&TASK->kb.box, call); |
} |
/** Handle a debug call received on the kernel answerbox. |
* |
* This is called by the kbox servicing thread. Verifies that the sender |
336,6 → 489,26 |
case UDEBUG_M_MEM_READ: |
udebug_receive_mem_read(call); |
break; |
/* CHECKPOINTING */ |
case UDEBUG_M_TASK_MEM_AREAS_READ: |
udebug_receive_task_mem_areas_read(call); |
break; |
case UDEBUG_M_MEM_WRITE: |
udebug_receive_mem_write(call); |
break; |
case UDEBUG_M_THREAD_COPY_KSTACK: |
udebug_receive_thread_copy_kstack(call); |
break; |
case UDEBUG_M_RESTORE_KSTACK: |
udebug_receive_restore_kstack(call); |
break; |
case UDEBUG_M_THREAD_GET_THREAD_STRUCT: |
udebug_receive_thread_get_thread_struct(call); |
break; |
case UDEBUG_M_THREAD_RESTORE_THREAD_STRUCT: |
udebug_receive_thread_restore_struct(call); |
break; |
} |
} |
/branches/snapshot/kernel/generic/src/udebug/udebug_ops.c |
---|
503,5 → 503,155 |
return 0; |
} |
int udebug_thread_get_thread_struct(thread_t *t, void **buffer) |
{ |
ipl_t ipl = interrupts_disable(); |
void *data_buffer = (void *)malloc(sizeof(thread_t), 0); |
memcpy(data_buffer, (void *)t, sizeof(thread_t)); |
*buffer = data_buffer; |
interrupts_restore(ipl); |
return (0); |
} |
int udebug_task_get_memory_areas(void **buffer, size_t buf_size, size_t *n) |
{ |
link_t *cur; |
ipl_t ipl; |
unative_t *areas_buffer; |
size_t max_index; |
as_print(TASK->as); |
areas_buffer = malloc(buf_size, 0); |
mutex_lock(&TASK->udebug.lock); |
/* Verify task state */ |
if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) { |
mutex_unlock(&TASK->udebug.lock); |
return EINVAL; |
} |
ipl = interrupts_disable(); |
spinlock_lock(&TASK->lock); |
max_index = buf_size / sizeof(unative_t); |
as_t *as = TASK->as; |
mutex_lock(&as->lock); |
/* print out info about address space areas */ |
unsigned int index = 0; |
for (cur = as->as_area_btree.leaf_head.next; |
cur != &as->as_area_btree.leaf_head; cur = cur->next) { |
btree_node_t *node; |
node = list_get_instance(cur, btree_node_t, leaf_link); |
unsigned int i; |
for (i = 0; i < node->keys; i++) { |
if (index >= max_index) |
break; |
as_area_t *area = node->value[i]; |
mutex_lock(&area->lock); |
areas_buffer[index++] = area->base; |
areas_buffer[index++] = area->base + FRAMES2SIZE(area->pages); |
mutex_unlock(&area->lock); |
} |
} |
mutex_unlock(&as->lock); |
spinlock_unlock(&TASK->lock); |
interrupts_restore(ipl); |
mutex_unlock(&TASK->udebug.lock); |
*buffer = areas_buffer; |
*n = (index) * sizeof(unative_t); |
return 0; |
} |
int udebug_copy_kstack(void *kstack, void **buffer, size_t n) |
{ |
ipl_t ipl = interrupts_disable(); |
void *data_buffer = malloc(n, 0); |
memcpy(data_buffer, (void *)kstack, n); |
*buffer = data_buffer; |
interrupts_restore(ipl); |
return 0; |
} |
int udebug_restore_thread_struct(void *buffer, thread_t *t_old) |
{ |
ipl_t ipl = interrupts_disable(); |
thread_t *t_new = (thread_t *)buffer; |
t_old->thread_code = t_new->thread_code; |
printf("old sp: %p, new sp: %p\n", t_old->saved_context.sp, t_new->saved_context.sp); |
printf("old kstack: %p, new kstack: %p\n", t_old->kstack, t_new->kstack); |
t_old->saved_context = t_new->saved_context; |
t_old->saved_context.sp = (uintptr_t)t_old->kstack + ((uintptr_t)t_new->saved_context.sp - (uintptr_t)t_new->kstack); |
t_old->sleep_timeout_context = t_new->sleep_timeout_context; |
t_old->sleep_timeout = t_new->sleep_timeout; |
t_old->timeout_pending = t_new->timeout_pending; |
t_old->in_copy_from_uspace = t_new->in_copy_from_uspace; |
t_old->in_copy_to_uspace = t_new->in_copy_to_uspace; |
t_old->interrupted = t_new->interrupted; |
t_old->call_me = t_new->call_me; |
t_old->call_me_with = t_new->call_me_with; |
t_old->udebug.go_call = t_new->udebug.go_call; |
interrupts_restore(ipl); |
return (0); |
} |
int udebug_mem_write(void *buffer, void *start, size_t n) |
{ |
ipl_t ipl = interrupts_disable(); |
if (((unsigned) start & 0x80000000) == 0) |
copy_to_uspace(start, buffer, n); |
interrupts_restore(ipl); |
return (0); |
} |
int udebug_restore_kstack(void *buffer, size_t size, thread_t *t) |
{ |
ipl_t ipl = interrupts_disable(); |
memcpy(t->kstack + sizeof(the_t), buffer + sizeof(the_t), size - sizeof(the_t)); |
interrupts_restore(ipl); |
return (0); |
} |
/** @} |
*/ |