Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2787 | decky | 1 | #include <stdio.h> |
2 | #include <unistd.h> |
||
3 | #include <task.h> |
||
4 | #include <tdebug.h> |
||
5 | #include <async.h> |
||
6 | #include <sys/types.h> |
||
7 | #include <time.h> |
||
8 | |||
9 | #include "../tester.h" |
||
10 | |||
11 | static char *syscall_name[] = { |
||
12 | "sys_io", |
||
13 | "sys_tls_set", |
||
14 | "sys_thread_create", |
||
15 | "sys_thread_exit", |
||
16 | "sys_thread_get_id", |
||
17 | "sys_task_get_id", |
||
18 | "sys_futex_sleep_timeout", |
||
19 | "sys_futex_wakeup", |
||
20 | "sys_as_area_create", |
||
21 | "sys_as_area_resize", |
||
22 | "sys_as_area_destroy", |
||
23 | "sys_ipc_call_sync_fast", |
||
24 | "sys_ipc_call_sync_slow", |
||
25 | "sys_ipc_call_async_fast", |
||
26 | "sys_ipc_call_async_slow", |
||
27 | "sys_ipc_answer_fast", |
||
28 | "sys_ipc_answer_slow", |
||
29 | "sys_ipc_forward_fast", |
||
30 | "sys_ipc_wait_for_call", |
||
31 | "sys_ipc_hangup", |
||
32 | "sys_ipc_register_irq", |
||
33 | "sys_ipc_unregister_irq", |
||
34 | "sys_cap_grant", |
||
35 | "sys_cap_revoke", |
||
36 | "sys_physmem_map", |
||
37 | "sys_iospace_enable", |
||
38 | "sys_preempt_control", |
||
39 | "sys_sysinfo_valid", |
||
40 | "sys_sysinfo_value", |
||
41 | "sys_debug_enable_console", |
||
42 | "sys_tdebug_attach_task", |
||
43 | "sys_tdebug_continue_thread", |
||
44 | "sys_tdebug_get_syscall_args" |
||
45 | "sys_tdebug_set_event_mask", |
||
46 | "sys_tdebug_stop_thread", |
||
47 | "sys_tdebug_stop_task" |
||
48 | }; |
||
49 | |||
50 | static void event_syscall(thread_id_t tid, sysarg_t syscall_id, sysarg_t rc) |
||
51 | { |
||
52 | sysarg_t sc_args[6]; |
||
53 | size_t buf_len; |
||
54 | int res; |
||
55 | |||
56 | buf_len = 6; |
||
57 | |||
58 | res = tdebug_get_syscall_args(tid, sc_args, &buf_len); |
||
59 | if (res != 0) { |
||
60 | printf("tdebug_get_syscall_args() -> %d\n", res); |
||
61 | } |
||
62 | |||
63 | printf("%s(", syscall_name[syscall_id]); |
||
64 | |||
65 | switch (syscall_id) { |
||
66 | case SYS_TLS_SET: printf("0x%08x", sc_args[0]); break; |
||
67 | case SYS_IPC_WAIT: printf("0x%08x, %u, %d", sc_args[0], sc_args[1], sc_args[2]); break; |
||
68 | default: |
||
69 | printf("%u, %u, %u, %u, %u, %u", |
||
70 | sc_args[0], sc_args[1], sc_args[2], |
||
71 | sc_args[3], sc_args[4], sc_args[5]); |
||
72 | break; |
||
73 | } |
||
74 | |||
75 | printf(") -> %d\n", rc); |
||
76 | } |
||
77 | |||
78 | static void event_exception(sysarg_t exc_no) |
||
79 | { |
||
80 | printf("exception %u\n", exc_no); |
||
81 | } |
||
82 | |||
83 | |||
84 | static void notif_handler(ipc_callid_t iid, ipc_call_t *call) |
||
85 | { |
||
86 | thread_id_t tid; |
||
87 | sysarg_t method; |
||
88 | sysarg_t tid_lo, tid_hi, ev_type, syscall_id, rc; |
||
89 | sysarg_t exc_no; |
||
90 | int res; |
||
91 | |||
92 | (void)iid; |
||
93 | |||
94 | method = IPC_GET_METHOD(*call); |
||
95 | tid_lo = IPC_GET_ARG1(*call); |
||
96 | tid_hi = IPC_GET_ARG2(*call); |
||
97 | ev_type = IPC_GET_ARG3(*call); |
||
98 | |||
99 | tid = (thread_id_t)tid_lo | ((thread_id_t)tid_hi << 32); |
||
100 | |||
101 | switch (ev_type) { |
||
102 | case TDEBUG_EV_SYSCALL: |
||
103 | syscall_id = IPC_GET_ARG4(*call); |
||
104 | rc = IPC_GET_ARG5(*call); |
||
105 | event_syscall(tid, syscall_id, rc); |
||
106 | break; |
||
107 | case TDEBUG_EV_EXCEPTION: |
||
108 | exc_no = IPC_GET_ARG4(*call); |
||
109 | event_exception(exc_no); |
||
110 | break; |
||
111 | default: |
||
112 | printf("unknown tdebug event notification %u\n", ev_type); |
||
113 | break; |
||
114 | } |
||
115 | |||
116 | res = tdebug_continue_thread(tid); |
||
117 | if (res != 0) { |
||
118 | printf("tdebug_continue_thread() -> %d\n", res); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | char *test_tdebug1(bool quiet) |
||
123 | { |
||
124 | task_id_t taskid; |
||
125 | int result; |
||
126 | |||
127 | async_set_interrupt_received(notif_handler); |
||
128 | |||
129 | printf("test_tdebug1()\n"); |
||
130 | taskid = 12; |
||
131 | // tid = task_get_id(); |
||
132 | // printf("this task id is %d\n", tid); |
||
133 | printf("attaching...\n"); |
||
134 | result = tdebug_attach_task(taskid, 368); |
||
135 | printf("result is %d\n", result); |
||
136 | getchar(); |
||
137 | /* printf("setting event mask...\n"); |
||
138 | result = tdebug_set_event_mask(taskid, TDEBUG_EVMASK_IAFTER); |
||
139 | printf("result is %d\n", result); |
||
140 | getchar(); |
||
141 | */ |
||
142 | printf("detaching...\n"); |
||
143 | result = tdebug_detach_task(taskid); |
||
144 | printf("result is %d\n", result); |
||
145 | |||
146 | return NULL; |
||
147 | } |