305,6 → 305,19 |
return ta; |
} |
|
static thread_t *get_task_thread_by_id(task_t *ta, thread_id_t tid) |
{ |
thread_t *t; |
link_t *cur; |
|
for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
t = list_get_instance(cur, thread_t, th_link); |
if (tid == t->tid) return t; |
} |
|
return NULL; |
} |
|
#include <console/klog.h> |
|
static int debug_begin(call_t *call, phone_t *phone) |
340,10 → 353,9 |
return 0; |
} |
|
static void debug_go(call_t *call, phone_t *phone) |
static int debug_go(call_t *call, phone_t *phone) |
{ |
thread_t *t; |
link_t *l; |
task_t *ta; |
|
klog_printf("debug_go()"); |
350,21 → 362,23 |
ta = get_lock_callee_task(phone); |
|
ta->debug_go_call = call; |
|
l = ta->th_head.next; |
if (l != &TASK->th_head) { |
t = list_get_instance(l, thread_t, th_link); |
klog_printf("debug_go(): waitq_wakeup"); |
waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
t = get_task_thread_by_id(ta, IPC_GET_ARG1(call->data)); |
if (t == NULL) { |
spinlock_unlock(&ta->lock); |
return ENOENT; |
} |
|
klog_printf("debug_go(): waitq_wakeup"); |
waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
|
spinlock_unlock(&ta->lock); |
|
return 0; /* no backsend */ |
} |
|
static int debug_args_read(call_t *call, phone_t *phone) |
{ |
thread_t *t; |
link_t *l; |
task_t *ta; |
void *uspace_buffer; |
unative_t to_copy; |
375,29 → 389,87 |
|
ta = get_lock_callee_task(phone); |
klog_printf("task %llu", ta->taskid); |
t = get_task_thread_by_id(ta, IPC_GET_ARG1(call->data)); |
if (t == NULL) { |
spinlock_unlock(&ta->lock); |
return ENOENT; |
} |
|
l = ta->th_head.next; |
if (l != &TASK->th_head) { |
t = list_get_instance(l, thread_t, th_link); |
/* t = requested thread */ |
uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
to_copy = IPC_GET_ARG3(call->data); |
rc = copy_to_uspace(uspace_buffer, t->syscall_args, to_copy); |
if (rc != 0) { |
spinlock_unlock(&ta->lock); |
klog_printf("debug_args_read() - copy failed"); |
return rc; |
} |
IPC_SET_ARG1(call->data, to_copy); |
uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
to_copy = IPC_GET_ARG3(call->data); |
if (to_copy > 6) to_copy = 6; |
|
rc = copy_to_uspace(uspace_buffer, t->syscall_args, to_copy); |
if (rc != 0) { |
spinlock_unlock(&ta->lock); |
klog_printf("debug_args_read() - copy failed"); |
return rc; |
} |
|
spinlock_unlock(&ta->lock); |
|
IPC_SET_ARG1(call->data, to_copy); |
|
klog_printf("debug_args_read() done"); |
return 1; /* actually need becksend with retval 0 */ |
} |
|
static int debug_thread_read(call_t *call, phone_t *phone) |
{ |
thread_t *t; |
link_t *cur; |
task_t *ta; |
unative_t *uspace_buffer; |
unative_t to_copy; |
int rc; |
unsigned copied, total; |
unsigned buf_size; |
unative_t tid; |
|
klog_printf("debug_thread_read()"); |
// FIXME: verify task/thread state |
|
ta = get_lock_callee_task(phone); |
klog_printf("task %llu", ta->taskid); |
|
uspace_buffer = (void *)IPC_GET_ARG1(call->data); |
buf_size = IPC_GET_ARG2(call->data); |
|
copied = total = 0; |
for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
t = list_get_instance(cur, thread_t, th_link); |
|
//FIXME: id cropped!! |
tid = (unative_t) t->tid; |
|
to_copy = sizeof(unative_t); |
if (copied + to_copy >= buf_size) |
to_copy = buf_size - copied; |
|
if (to_copy > 0) { |
rc = copy_to_uspace(uspace_buffer, &tid, to_copy); |
if (rc != 0) { |
spinlock_unlock(&ta->lock); |
klog_printf("debug_thread_read() - copy failed"); |
return rc; |
} |
} |
|
++uspace_buffer; |
total += sizeof(unative_t); |
copied += to_copy; |
} |
|
spinlock_unlock(&ta->lock); |
|
IPC_SET_ARG1(call->data, copied); |
IPC_SET_ARG2(call->data, total); |
|
klog_printf("debug_thread_read() done"); |
return 1; /* actually need becksend with retval 0 */ |
} |
|
|
/** Called before the request is sent. |
* |
* @param call Call structure with the request. |
452,11 → 524,14 |
rc = debug_begin(call, phone); |
return rc; |
case IPC_M_DEBUG_GO: |
debug_go(call, phone); |
break; |
rc = debug_go(call, phone); |
return rc; |
case IPC_M_DEBUG_ARGS_READ: |
rc = debug_args_read(call, phone); |
return rc; |
case IPC_M_DEBUG_THREAD_READ: |
rc = debug_thread_read(call, phone); |
return rc; |
default: |
break; |
} |