#include <stdio.h>
#include <unistd.h>
#include <task.h>
#include <tdebug.h>
#include <async.h>
#include <sys/types.h>
#include <time.h>
#include "../tester.h"
static char *syscall_name[] = {
"sys_io",
"sys_tls_set",
"sys_thread_create",
"sys_thread_exit",
"sys_thread_get_id",
"sys_task_get_id",
"sys_futex_sleep_timeout",
"sys_futex_wakeup",
"sys_as_area_create",
"sys_as_area_resize",
"sys_as_area_destroy",
"sys_ipc_call_sync_fast",
"sys_ipc_call_sync_slow",
"sys_ipc_call_async_fast",
"sys_ipc_call_async_slow",
"sys_ipc_answer_fast",
"sys_ipc_answer_slow",
"sys_ipc_forward_fast",
"sys_ipc_wait_for_call",
"sys_ipc_hangup",
"sys_ipc_register_irq",
"sys_ipc_unregister_irq",
"sys_cap_grant",
"sys_cap_revoke",
"sys_physmem_map",
"sys_iospace_enable",
"sys_preempt_control",
"sys_sysinfo_valid",
"sys_sysinfo_value",
"sys_debug_enable_console",
"sys_tdebug_attach_task",
"sys_tdebug_continue_thread",
"sys_tdebug_get_syscall_args"
"sys_tdebug_set_event_mask",
"sys_tdebug_stop_thread",
"sys_tdebug_stop_task"
};
static void event_syscall(thread_id_t tid, sysarg_t syscall_id, sysarg_t rc)
{
sysarg_t sc_args[6];
size_t buf_len;
int res;
buf_len = 6;
res = tdebug_get_syscall_args(tid, sc_args, &buf_len);
if (res != 0) {
printf("tdebug_get_syscall_args() -> %d\n", res
);
}
printf("%s(", syscall_name
[syscall_id
]);
switch (syscall_id) {
case SYS_TLS_SET
: printf("0x%08x", sc_args
[0]); break;
case SYS_IPC_WAIT
: printf("0x%08x, %u, %d", sc_args
[0], sc_args
[1], sc_args
[2]); break;
default:
printf("%u, %u, %u, %u, %u, %u",
sc_args[0], sc_args[1], sc_args[2],
sc_args[3], sc_args[4], sc_args[5]);
break;
}
}
static void event_exception(sysarg_t exc_no)
{
printf("exception %u\n", exc_no
);
}
static void notif_handler(ipc_callid_t iid, ipc_call_t *call)
{
thread_id_t tid;
sysarg_t method;
sysarg_t tid_lo, tid_hi, ev_type, syscall_id, rc;
sysarg_t exc_no;
int res;
(void)iid;
method = IPC_GET_METHOD(*call);
tid_lo = IPC_GET_ARG1(*call);
tid_hi = IPC_GET_ARG2(*call);
ev_type = IPC_GET_ARG3(*call);
tid = (thread_id_t)tid_lo | ((thread_id_t)tid_hi << 32);
switch (ev_type) {
case TDEBUG_EV_SYSCALL:
syscall_id = IPC_GET_ARG4(*call);
rc = IPC_GET_ARG5(*call);
event_syscall(tid, syscall_id, rc);
break;
case TDEBUG_EV_EXCEPTION:
exc_no = IPC_GET_ARG4(*call);
event_exception(exc_no);
break;
default:
printf("unknown tdebug event notification %u\n", ev_type
);
break;
}
res = tdebug_continue_thread(tid);
if (res != 0) {
printf("tdebug_continue_thread() -> %d\n", res
);
}
}
char *test_tdebug1(bool quiet)
{
task_id_t taskid;
int result;
async_set_interrupt_received(notif_handler);
taskid = 12;
// tid = task_get_id();
// printf("this task id is %d\n", tid);
result = tdebug_attach_task(taskid, 368);
printf("result is %d\n", result
);
/* printf("setting event mask...\n");
result = tdebug_set_event_mask(taskid, TDEBUG_EVMASK_IAFTER);
printf("result is %d\n", result);
getchar();
*/
result = tdebug_detach_task(taskid);
printf("result is %d\n", result
);
return NULL;
}