Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2834 → Rev 2835

/branches/tracing/kernel/generic/src/udebug/udebug_ipc.c
132,49 → 132,44
ta = get_lock_callee_task(phone);
klog_printf("task %llu", ta->taskid);
 
//TODO: UDEBUG_TS_BEGINNING
if (ta->dt_state != UDEBUG_TS_ACTIVE) {
if (ta->dt_state == UDEBUG_TS_BEGINNING &&
ta->dt_state != UDEBUG_TS_ACTIVE) {
spinlock_unlock(&ta->lock);
interrupts_restore(ipl);
klog_printf("udebug_rp_begin(): task not in TS_BEGINNING");
klog_printf("udebug_rp_begin(): task not being debugged");
return EINVAL;
}
 
/* Clear debug_active from all of the task's userspace threads */
 
/* Finish debugging of all userspace threads */
for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
t = list_get_instance(cur, thread_t, th_link);
 
spinlock_lock(&t->lock);
if ((t->flags & THREAD_FLAG_USPACE) != 0)
t->debug_active = true;
spinlock_unlock(&t->lock);
}
 
/* Now respond to unanswered GO calls and reset thread states */
for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
t = list_get_instance(cur, thread_t, th_link);
/* Only process userspace threads */
if ((t->flags & THREAD_FLAG_USPACE) != 0) {
/* Prevent any further debug activity in thread */
t->debug_active = false;
 
spinlock_lock(&t->lock);
/* Still has go? */
if (t->debug_stop == false) {
/*
* Yes, so clear go. As debug_active == false,
* this doesn't affect anything.
*/
t->debug_stop = true;
 
/* Still has go? */
if ((t->flags & THREAD_FLAG_USPACE) != 0 &&
t->debug_stop == false) {
/*
* Yes, so clear go. As debug_active == false,
* this doesn't affect anything.
*/
t->debug_stop = true;
/* Answer GO call */
ipc_answer(&ta->answerbox, t->debug_go_call);
} else {
/*
* Debug_stop is already at initial value.
* Yet this means the thread needs waking up.
*/
waitq_wakeup(&t->go_wq, WAKEUP_FIRST);
}
}
 
/* Answer GO call */
ipc_answer(&ta->answerbox, t->debug_go_call);
} else {
/*
* Debug_stop is already at initial value.
* Yet this means the thread needs waking up.
*/
waitq_wakeup(&t->go_wq, WAKEUP_FIRST);
}
spinlock_unlock(&t->lock);
}
 
/branches/tracing/uspace/app/sctrace/debug_api.c
7,6 → 7,7
#include <stdio.h>
#include <syscall.h>
#include <ipc/ipc.h>
#include <async.h>
#include <udebug.h>
 
#include "debug_api.h"
13,26 → 14,31
 
int debug_begin(unsigned phoneid)
{
return ipc_call_sync_1_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_BEGIN);
return async_req_1_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_BEGIN);
}
 
int debug_end(unsigned phoneid)
{
return async_req_1_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_END);
}
 
int debug_thread_read(unsigned phoneid, void *buffer, unsigned n,
unsigned *copied, unsigned *needed)
{
printf("send IPC_M_DEBUG_THREAD_READ message\n");
return ipc_call_sync_3_2(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_THREAD_READ,
return async_req_3_2(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_THREAD_READ,
(sysarg_t)buffer, n, copied, needed);
}
 
int debug_mem_read(unsigned phoneid, void *buffer, unsigned addr, unsigned n)
{
return ipc_call_sync_4_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_MEM_READ,
return async_req_4_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_MEM_READ,
(sysarg_t)buffer, addr, n);
}
 
int debug_args_read(unsigned phoneid, unsigned tid, unsigned *buffer)
{
return ipc_call_sync_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_ARGS_READ,
return async_req_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_ARGS_READ,
tid, (sysarg_t)buffer);
}
 
40,7 → 46,7
unsigned *sc_id, unsigned *sc_rc)
{
/* Run thread until a syscall is executed */
return ipc_call_sync_2_3(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_GO,
return async_req_2_3(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_GO,
tid, (sysarg_t)ev_type, (sysarg_t)sc_id, (sysarg_t)sc_rc);
}
 
/branches/tracing/uspace/app/sctrace/debug_api.h
8,6 → 8,7
#define DEBUG_API_H_
 
int debug_begin(unsigned phoneid);
int debug_end(unsigned phoneid);
int debug_thread_read(unsigned phoneid, void *buffer, unsigned n,
unsigned *copied, unsigned *needed);
int debug_mem_read(unsigned phoneid, void *buffer, unsigned addr, unsigned n);
/branches/tracing/uspace/app/sctrace/sctrace.c
8,7 → 8,8
#include <unistd.h>
#include <syscall.h>
#include <ipc/ipc.h>
#include <udebug.h>
#include <fibril.h>
#include <errno.h>
 
#include "syscalls.h"
#include "errors.h"
18,6 → 19,7
unsigned threadid_buf[TIDBUF_SIZE];
 
int phoneid;
int abort_trace;
 
int task_connect(int taskid)
{
114,6 → 116,22
}
}
 
int keyboard_fibril(void *arg)
{
(void)arg;
 
printf("keyboard fibril started\n");
 
getchar();
printf("keyboard fibril setting abort_trace\n");
abort_trace = 1;
printf("keyboard fibril sending debug_end()\n");
debug_end(phoneid);
printf("keyboard fibril exitting\n");
 
return EOK;
}
 
void trace_loop(void)
{
int rc;
123,8 → 141,18
unsigned sc_id;
int sc_rc;
int rv_type;
fid_t kb_fid;
 
while (1) {
abort_trace = 0;
kb_fid = fibril_create(keyboard_fibril, NULL);
if (kb_fid == 0) {
printf("Failed creating keyboard fibril\n");
return;
}
fibril_add_ready(kb_fid);
 
while (!abort_trace) {
 
/* Run thread until a syscall is executed */
rc = debug_go(phoneid, threadid_buf[0],
&ev_type, &sc_id, &sc_rc);
151,6 → 179,8
break;
}
}
 
printf("trace_loop() exiting\n");
}
 
 
181,7 → 211,14
}
 
trace_loop();
/*
printf("press 'd' to disconnect\n");
while ((i = getchar()) != 'd')
putchar(i);
 
printf("call debug_end()\n");
debug_end(phoneid);
*/
printf("done\n");
return;
}
188,7 → 225,9
 
int main(void)
{
trace_active_task();
while (1) {
trace_active_task();
}
}
 
/** @}