Rev 2882 | Rev 2894 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2882 | Rev 2883 | ||
---|---|---|---|
1 | /** @addtogroup sctrace |
1 | /** @addtogroup sctrace |
2 | * @{ |
2 | * @{ |
3 | */ |
3 | */ |
4 | /** @file |
4 | /** @file |
5 | */ |
5 | */ |
6 | 6 | ||
7 | #include <stdio.h> |
7 | #include <stdio.h> |
8 | #include <stdlib.h> |
8 | #include <stdlib.h> |
9 | #include <unistd.h> |
9 | #include <unistd.h> |
10 | #include <syscall.h> |
10 | #include <syscall.h> |
11 | #include <ipc/ipc.h> |
11 | #include <ipc/ipc.h> |
12 | #include <fibril.h> |
12 | #include <fibril.h> |
13 | #include <errno.h> |
13 | #include <errno.h> |
14 | #include <udebug.h> |
14 | #include <udebug.h> |
15 | #include <async.h> |
15 | #include <async.h> |
16 | 16 | ||
17 | // Temporary: service and method names |
17 | // Temporary: service and method names |
18 | #include "proto.h" |
18 | #include "proto.h" |
19 | #include <ipc/services.h> |
19 | #include <ipc/services.h> |
20 | #include "../../srv/vfs/vfs.h" |
20 | #include "../../srv/vfs/vfs.h" |
21 | #include "../../srv/console/console.h" |
21 | #include "../../srv/console/console.h" |
22 | 22 | ||
23 | #include "syscalls.h" |
23 | #include "syscalls.h" |
24 | #include "ipcp.h" |
24 | #include "ipcp.h" |
25 | #include "errors.h" |
25 | #include "errors.h" |
26 | #include "debug_api.h" |
26 | #include "debug_api.h" |
27 | 27 | ||
28 | #define THBUF_SIZE 64 |
28 | #define THBUF_SIZE 64 |
29 | unsigned thread_hash_buf[THBUF_SIZE]; |
29 | unsigned thread_hash_buf[THBUF_SIZE]; |
30 | unsigned n_threads; |
30 | unsigned n_threads; |
31 | 31 | ||
32 | int next_thread_id; |
32 | int next_thread_id; |
33 | 33 | ||
34 | int phoneid; |
34 | int phoneid; |
35 | int abort_trace; |
35 | int abort_trace; |
36 | 36 | ||
37 | void thread_trace_start(unsigned thread_hash); |
37 | void thread_trace_start(unsigned thread_hash); |
38 | 38 | ||
39 | static proto_t *proto_console; |
39 | static proto_t *proto_console; |
40 | 40 | ||
41 | int task_connect(int taskid) |
41 | int task_connect(int taskid) |
42 | { |
42 | { |
43 | int rc; |
43 | int rc; |
44 | 44 | ||
45 | printf("ipc_connect_task(%d)...\n", taskid); |
45 | printf("ipc_connect_task(%d)...\n", taskid); |
46 | rc = ipc_connect_kbox(taskid); |
46 | rc = ipc_connect_kbox(taskid); |
47 | printf("-> %d\n", rc); |
47 | printf("-> %d\n", rc); |
48 | phoneid = rc; |
48 | phoneid = rc; |
49 | if (rc < 0) return rc; |
49 | if (rc < 0) return rc; |
50 | 50 | ||
51 | printf("debug_begin()\n"); |
51 | printf("debug_begin()\n"); |
52 | rc = debug_begin(phoneid); |
52 | rc = debug_begin(phoneid); |
53 | printf("-> %d\n", rc); |
53 | printf("-> %d\n", rc); |
54 | if (rc < 0) return rc; |
54 | if (rc < 0) return rc; |
55 | 55 | ||
56 | return 0; |
56 | return 0; |
57 | } |
57 | } |
58 | 58 | ||
59 | int get_thread_list(void) |
59 | int get_thread_list(void) |
60 | { |
60 | { |
61 | int rc; |
61 | int rc; |
62 | int tb_copied; |
62 | int tb_copied; |
63 | int tb_needed; |
63 | int tb_needed; |
64 | int i; |
64 | int i; |
65 | 65 | ||
66 | 66 | ||
67 | printf("send IPC_M_DEBUG_THREAD_READ message\n"); |
67 | printf("send IPC_M_DEBUG_THREAD_READ message\n"); |
68 | rc = debug_thread_read(phoneid, (unsigned)thread_hash_buf, |
68 | rc = debug_thread_read(phoneid, (unsigned)thread_hash_buf, |
69 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
69 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
70 | printf("-> %d\n", rc); |
70 | printf("-> %d\n", rc); |
71 | if (rc < 0) return rc; |
71 | if (rc < 0) return rc; |
72 | 72 | ||
73 | n_threads = tb_copied / sizeof(unsigned); |
73 | n_threads = tb_copied / sizeof(unsigned); |
74 | 74 | ||
75 | printf("thread IDs:"); |
75 | printf("thread IDs:"); |
76 | for (i=0; i<n_threads; i++) { |
76 | for (i=0; i<n_threads; i++) { |
77 | printf(" %u", thread_hash_buf[i]); |
77 | printf(" %u", thread_hash_buf[i]); |
78 | } |
78 | } |
79 | printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned)); |
79 | printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned)); |
80 | 80 | ||
81 | return 0; |
81 | return 0; |
82 | } |
82 | } |
83 | 83 | ||
84 | void print_sc_retval(int retval, rv_type_t rv_type) |
84 | void print_sc_retval(int retval, rv_type_t rv_type) |
85 | { |
85 | { |
86 | printf (" -> "); |
86 | printf (" -> "); |
87 | if (rv_type == RV_INTEGER) { |
87 | if (rv_type == RV_INTEGER) { |
88 | printf("%d", retval); |
88 | printf("%d", retval); |
89 | } else if (rv_type == RV_HASH) { |
89 | } else if (rv_type == RV_HASH) { |
90 | printf("0x%08x", retval); |
90 | printf("0x%08x", retval); |
91 | } else if (rv_type == RV_ERRNO) { |
91 | } else if (rv_type == RV_ERRNO) { |
92 | if (retval >= -15 && retval <= 0) { |
92 | if (retval >= -15 && retval <= 0) { |
93 | printf("%d %s (%s)", retval, |
93 | printf("%d %s (%s)", retval, |
94 | err_desc[retval].name, |
94 | err_desc[retval].name, |
95 | err_desc[retval].desc); |
95 | err_desc[retval].desc); |
96 | } else { |
96 | } else { |
97 | printf("%d", retval); |
97 | printf("%d", retval); |
98 | } |
98 | } |
99 | } else if (rv_type == RV_INT_ERRNO) { |
99 | } else if (rv_type == RV_INT_ERRNO) { |
100 | if (retval >= -15 && retval < 0) { |
100 | if (retval >= -15 && retval < 0) { |
101 | printf("%d %s (%s)", retval, |
101 | printf("%d %s (%s)", retval, |
102 | err_desc[retval].name, |
102 | err_desc[retval].name, |
103 | err_desc[retval].desc); |
103 | err_desc[retval].desc); |
104 | } else { |
104 | } else { |
105 | printf("%d", retval); |
105 | printf("%d", retval); |
106 | } |
106 | } |
107 | } |
107 | } |
108 | putchar('\n'); |
108 | putchar('\n'); |
109 | } |
109 | } |
110 | 110 | ||
111 | void print_sc_args(unsigned *sc_args, int n) |
111 | void print_sc_args(unsigned *sc_args, int n) |
112 | { |
112 | { |
113 | int i; |
113 | int i; |
114 | 114 | ||
115 | putchar('('); |
115 | putchar('('); |
116 | if (n > 0) printf("%d", sc_args[0]); |
116 | if (n > 0) printf("%d", sc_args[0]); |
117 | for (i=1; i<n; i++) { |
117 | for (i=1; i<n; i++) { |
118 | printf(", %d", sc_args[i]); |
118 | printf(", %d", sc_args[i]); |
119 | } |
119 | } |
120 | putchar(')'); |
120 | putchar(')'); |
121 | } |
121 | } |
122 | 122 | ||
123 | void sc_ipc_call_async_fast(unsigned *sc_args, int sc_rc) |
123 | void sc_ipc_call_async_fast(unsigned *sc_args, int sc_rc) |
124 | { |
124 | { |
125 | ipc_call_t call; |
125 | ipc_call_t call; |
126 | int phoneid; |
126 | int phoneid; |
127 | 127 | ||
128 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
128 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
129 | return; |
129 | return; |
130 | 130 | ||
131 | phoneid = sc_args[0]; |
131 | phoneid = sc_args[0]; |
132 | 132 | ||
133 | IPC_SET_METHOD(call, sc_args[1]); |
133 | IPC_SET_METHOD(call, sc_args[1]); |
134 | IPC_SET_ARG1(call, sc_args[2]); |
134 | IPC_SET_ARG1(call, sc_args[2]); |
135 | IPC_SET_ARG2(call, sc_args[3]); |
135 | IPC_SET_ARG2(call, sc_args[3]); |
136 | IPC_SET_ARG3(call, sc_args[4]); |
136 | IPC_SET_ARG3(call, sc_args[4]); |
137 | IPC_SET_ARG4(call, sc_args[5]); |
137 | IPC_SET_ARG4(call, sc_args[5]); |
138 | IPC_SET_ARG5(call, 0); |
138 | IPC_SET_ARG5(call, 0); |
139 | 139 | ||
140 | ipcp_call_out(phoneid, &call, sc_rc); |
140 | ipcp_call_out(phoneid, &call, sc_rc); |
141 | } |
141 | } |
142 | 142 | ||
143 | void sc_ipc_call_async_slow(unsigned *sc_args, int sc_rc) |
143 | void sc_ipc_call_async_slow(unsigned *sc_args, int sc_rc) |
144 | { |
144 | { |
145 | ipc_call_t call; |
145 | ipc_call_t call; |
146 | int rc; |
146 | int rc; |
147 | 147 | ||
148 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
148 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
149 | return; |
149 | return; |
150 | 150 | ||
151 | memset(&call, 0, sizeof(call)); |
151 | memset(&call, 0, sizeof(call)); |
152 | rc = debug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
152 | rc = debug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
153 | 153 | ||
154 | if (rc >= 0) { |
154 | if (rc >= 0) { |
155 | ipcp_call_out(sc_args[0], &call, sc_rc); |
155 | ipcp_call_out(sc_args[0], &call, sc_rc); |
156 | } |
156 | } |
157 | } |
157 | } |
158 | 158 | ||
159 | void sc_ipc_call_sync_fast(unsigned *sc_args) |
159 | void sc_ipc_call_sync_fast(unsigned *sc_args) |
160 | { |
160 | { |
161 | ipc_call_t question, reply; |
161 | ipc_call_t question, reply; |
162 | int rc; |
162 | int rc; |
163 | int phoneidx; |
163 | int phoneidx; |
164 | 164 | ||
165 | // printf("sc_ipc_call_sync_fast()\n"); |
165 | // printf("sc_ipc_call_sync_fast()\n"); |
166 | phoneidx = sc_args[0]; |
166 | phoneidx = sc_args[0]; |
167 | 167 | ||
168 | IPC_SET_METHOD(question, sc_args[1]); |
168 | IPC_SET_METHOD(question, sc_args[1]); |
169 | IPC_SET_ARG1(question, sc_args[2]); |
169 | IPC_SET_ARG1(question, sc_args[2]); |
170 | IPC_SET_ARG2(question, sc_args[3]); |
170 | IPC_SET_ARG2(question, sc_args[3]); |
171 | IPC_SET_ARG3(question, sc_args[4]); |
171 | IPC_SET_ARG3(question, sc_args[4]); |
172 | IPC_SET_ARG4(question, 0); |
172 | IPC_SET_ARG4(question, 0); |
173 | IPC_SET_ARG5(question, 0); |
173 | IPC_SET_ARG5(question, 0); |
174 | 174 | ||
175 | // printf("memset\n"); |
175 | // printf("memset\n"); |
176 | memset(&reply, 0, sizeof(reply)); |
176 | memset(&reply, 0, sizeof(reply)); |
177 | // printf("debug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", |
177 | // printf("debug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", |
178 | // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
178 | // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
179 | rc = debug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
179 | rc = debug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
180 | // printf("dmr->%d\n", rc); |
180 | // printf("dmr->%d\n", rc); |
181 | if (rc < 0) return; |
181 | if (rc < 0) return; |
182 | 182 | ||
183 | // printf("call ipc_call_sync\n"); |
183 | // printf("call ipc_call_sync\n"); |
184 | ipcp_call_sync(phoneidx, &question, &reply); |
184 | ipcp_call_sync(phoneidx, &question, &reply); |
185 | } |
185 | } |
186 | 186 | ||
187 | void sc_ipc_call_sync_slow(unsigned *sc_args) |
187 | void sc_ipc_call_sync_slow(unsigned *sc_args) |
188 | { |
188 | { |
189 | ipc_call_t question, reply; |
189 | ipc_call_t question, reply; |
190 | int rc; |
190 | int rc; |
191 | 191 | ||
192 | memset(&question, 0, sizeof(question)); |
192 | memset(&question, 0, sizeof(question)); |
193 | rc = debug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
193 | rc = debug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
194 | printf("dmr->%d\n", rc); |
194 | printf("dmr->%d\n", rc); |
195 | if (rc < 0) return; |
195 | if (rc < 0) return; |
196 | 196 | ||
197 | memset(&reply, 0, sizeof(reply)); |
197 | memset(&reply, 0, sizeof(reply)); |
198 | rc = debug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
198 | rc = debug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
199 | printf("dmr->%d\n", rc); |
199 | printf("dmr->%d\n", rc); |
200 | if (rc < 0) return; |
200 | if (rc < 0) return; |
201 | 201 | ||
202 | ipcp_call_sync(sc_args[0], &question, &reply); |
202 | ipcp_call_sync(sc_args[0], &question, &reply); |
203 | } |
203 | } |
204 | 204 | ||
205 | void sc_ipc_wait(unsigned *sc_args, int sc_rc) |
205 | void sc_ipc_wait(unsigned *sc_args, int sc_rc) |
206 | { |
206 | { |
207 | ipc_call_t call; |
207 | ipc_call_t call; |
208 | int rc; |
208 | int rc; |
209 | 209 | ||
210 | if (sc_rc == 0) return 0; |
210 | if (sc_rc == 0) return 0; |
211 | 211 | ||
212 | memset(&call, 0, sizeof(call)); |
212 | memset(&call, 0, sizeof(call)); |
213 | rc = debug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); |
213 | rc = debug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); |
214 | // printf("debug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", |
214 | // printf("debug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", |
215 | // phoneid, (int)&call, sc_args[0], sizeof(call), rc); |
215 | // phoneid, (int)&call, sc_args[0], sizeof(call), rc); |
216 | 216 | ||
217 | if (rc >= 0) { |
217 | if (rc >= 0) { |
218 | ipcp_call_in(&call, sc_rc); |
218 | ipcp_call_in(&call, sc_rc); |
219 | } |
219 | } |
220 | } |
220 | } |
221 | 221 | ||
222 | void event_syscall(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
222 | void event_syscall(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
223 | { |
223 | { |
224 | unsigned sc_args[6]; |
224 | unsigned sc_args[6]; |
225 | int rv_type; |
225 | int rv_type; |
226 | int rc; |
226 | int rc; |
227 | 227 | ||
228 | /* Read syscall arguments */ |
228 | /* Read syscall arguments */ |
229 | rc = debug_args_read(phoneid, thread_hash, sc_args); |
229 | rc = debug_args_read(phoneid, thread_hash, sc_args); |
230 | 230 | ||
231 | async_serialize_start(); |
231 | async_serialize_start(); |
232 | 232 | ||
233 | // printf("[%d] ", thread_id); |
233 | // printf("[%d] ", thread_id); |
234 | 234 | ||
235 | if (rc < 0) { |
235 | if (rc < 0) { |
236 | printf("error\n"); |
236 | printf("error\n"); |
237 | async_serialize_end(); |
237 | async_serialize_end(); |
238 | return; |
238 | return; |
239 | } |
239 | } |
240 | 240 | ||
241 | /* Print syscall name, id and arguments */ |
241 | /* Print syscall name, id and arguments */ |
242 | printf("%s", syscall_desc[sc_id].name); |
242 | printf("%s", syscall_desc[sc_id].name); |
243 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
243 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
244 | rv_type = syscall_desc[sc_id].rv_type; |
244 | rv_type = syscall_desc[sc_id].rv_type; |
245 | print_sc_retval(sc_rc, rv_type); |
245 | print_sc_retval(sc_rc, rv_type); |
246 | 246 | ||
247 | switch (sc_id) { |
247 | switch (sc_id) { |
248 | case SYS_IPC_CALL_ASYNC_FAST: |
248 | case SYS_IPC_CALL_ASYNC_FAST: |
249 | sc_ipc_call_async_fast(sc_args, sc_rc); |
249 | sc_ipc_call_async_fast(sc_args, sc_rc); |
250 | break; |
250 | break; |
251 | case SYS_IPC_CALL_ASYNC_SLOW: |
251 | case SYS_IPC_CALL_ASYNC_SLOW: |
252 | sc_ipc_call_async_slow(sc_args, sc_rc); |
252 | sc_ipc_call_async_slow(sc_args, sc_rc); |
253 | break; |
253 | break; |
254 | case SYS_IPC_CALL_SYNC_FAST: |
254 | case SYS_IPC_CALL_SYNC_FAST: |
255 | sc_ipc_call_sync_fast(sc_args); |
255 | sc_ipc_call_sync_fast(sc_args); |
256 | break; |
256 | break; |
257 | case SYS_IPC_CALL_SYNC_SLOW: |
257 | case SYS_IPC_CALL_SYNC_SLOW: |
258 | sc_ipc_call_sync_slow(sc_args); |
258 | sc_ipc_call_sync_slow(sc_args); |
259 | break; |
259 | break; |
260 | case SYS_IPC_WAIT: |
260 | case SYS_IPC_WAIT: |
261 | sc_ipc_wait(sc_args, sc_rc); |
261 | sc_ipc_wait(sc_args, sc_rc); |
262 | break; |
262 | break; |
263 | default: |
263 | default: |
264 | break; |
264 | break; |
265 | } |
265 | } |
266 | 266 | ||
267 | async_serialize_end(); |
267 | async_serialize_end(); |
268 | } |
268 | } |
269 | 269 | ||
270 | void event_new_thread(unsigned hash) |
270 | void event_new_thread(unsigned hash) |
271 | { |
271 | { |
272 | async_serialize_start(); |
272 | async_serialize_start(); |
273 | printf("new thread, hash 0x%x\n", hash); |
273 | printf("new thread, hash 0x%x\n", hash); |
274 | async_serialize_end(); |
274 | async_serialize_end(); |
275 | 275 | ||
276 | thread_trace_start(hash); |
276 | thread_trace_start(hash); |
277 | } |
277 | } |
278 | 278 | ||
279 | void trace_loop(void *thread_hash_arg) |
279 | void trace_loop(void *thread_hash_arg) |
280 | { |
280 | { |
281 | int rc; |
281 | int rc; |
282 | unsigned ev_type; |
282 | unsigned ev_type; |
283 | unsigned thread_hash; |
283 | unsigned thread_hash; |
284 | unsigned thread_id; |
284 | unsigned thread_id; |
285 | unsigned val0, val1; |
285 | unsigned val0, val1; |
286 | 286 | ||
287 | thread_hash = (unsigned)thread_hash_arg; |
287 | thread_hash = (unsigned)thread_hash_arg; |
288 | thread_id = next_thread_id++; |
288 | thread_id = next_thread_id++; |
289 | 289 | ||
290 | printf("trace_loop(%d)\n", thread_id); |
290 | printf("trace_loop(%d)\n", thread_id); |
291 | 291 | ||
292 | while (!abort_trace) { |
292 | while (!abort_trace) { |
293 | 293 | ||
294 | /* Run thread until an event occurs */ |
294 | /* Run thread until an event occurs */ |
295 | rc = debug_go(phoneid, thread_hash, |
295 | rc = debug_go(phoneid, thread_hash, |
296 | &ev_type, &val0, &val1); |
296 | &ev_type, &val0, &val1); |
297 | 297 | ||
298 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
298 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
299 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
299 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
300 | printf("thread %u debugging finished\n", thread_id); |
300 | printf("thread %u debugging finished\n", thread_id); |
301 | break; |
301 | break; |
302 | } |
302 | } |
303 | 303 | ||
304 | if (rc >= 0) { |
304 | if (rc >= 0) { |
305 | switch (ev_type) { |
305 | switch (ev_type) { |
306 | case UDEBUG_EVENT_SYSCALL: |
306 | case UDEBUG_EVENT_SYSCALL: |
307 | event_syscall(thread_id, thread_hash, val0, (int)val1); |
307 | event_syscall(thread_id, thread_hash, val0, (int)val1); |
308 | break; |
308 | break; |
309 | case UDEBUG_EVENT_NEW_THREAD: |
309 | case UDEBUG_EVENT_NEW_THREAD: |
310 | event_new_thread(val0); |
310 | event_new_thread(val0); |
311 | break; |
311 | break; |
312 | default: |
312 | default: |
313 | printf("unknown event type %d\n", ev_type); |
313 | printf("unknown event type %d\n", ev_type); |
314 | break; |
314 | break; |
315 | } |
315 | } |
316 | } |
316 | } |
317 | 317 | ||
318 | } |
318 | } |
319 | 319 | ||
320 | printf("trace_loop(%d) exiting\n", thread_id); |
320 | printf("trace_loop(%d) exiting\n", thread_id); |
321 | } |
321 | } |
322 | 322 | ||
323 | void thread_trace_start(unsigned thread_hash) |
323 | void thread_trace_start(unsigned thread_hash) |
324 | { |
324 | { |
325 | fid_t fid; |
325 | fid_t fid; |
326 | 326 | ||
327 | fid = fibril_create(trace_loop, (void *)thread_hash); |
327 | fid = fibril_create(trace_loop, (void *)thread_hash); |
328 | if (fid == 0) { |
328 | if (fid == 0) { |
329 | printf("Warning: Failed creating fibril\n"); |
329 | printf("Warning: Failed creating fibril\n"); |
330 | } |
330 | } |
331 | fibril_add_ready(fid); |
331 | fibril_add_ready(fid); |
332 | } |
332 | } |
333 | 333 | ||
334 | void trace_active_task(void) |
334 | void trace_active_task(void) |
335 | { |
335 | { |
336 | int taskid; |
336 | int taskid; |
337 | int i; |
337 | int i; |
338 | int rc; |
338 | int rc; |
339 | 339 | ||
340 | printf("Syscall Tracer\n"); |
340 | printf("Syscall Tracer\n"); |
341 | printf("Press 'c' to connect\n"); |
341 | printf("Press 'c' to connect\n"); |
342 | while ((i = getchar()) != 'c') |
342 | while ((i = getchar()) != 'c') |
343 | putchar(i); |
343 | putchar(i); |
344 | 344 | ||
345 | taskid = 14; |
345 | taskid = 14; |
346 | rc = task_connect(taskid); |
346 | rc = task_connect(taskid); |
347 | if (rc < 0) { |
347 | if (rc < 0) { |
348 | printf("Failed to connect to task %d\n", taskid); |
348 | printf("Failed to connect to task %d\n", taskid); |
349 | return; |
349 | return; |
350 | } |
350 | } |
351 | 351 | ||
352 | printf("Connected to task %d\n", taskid); |
352 | printf("Connected to task %d\n", taskid); |
353 | 353 | ||
354 | ipcp_init(); |
354 | ipcp_init(); |
355 | ipcp_connection_set(1, 0, proto_console); |
355 | ipcp_connection_set(1, 0, proto_console); |
356 | 356 | ||
357 | rc = get_thread_list(); |
357 | rc = get_thread_list(); |
358 | if (rc < 0) { |
358 | if (rc < 0) { |
359 | printf("Failed to get thread list (error %d)\n", rc); |
359 | printf("Failed to get thread list (error %d)\n", rc); |
360 | return; |
360 | return; |
361 | } |
361 | } |
362 | 362 | ||
363 | abort_trace = 0; |
363 | abort_trace = 0; |
364 | 364 | ||
365 | for (i = 0; i < n_threads; i++) { |
365 | for (i = 0; i < n_threads; i++) { |
366 | thread_trace_start(thread_hash_buf[i]); |
366 | thread_trace_start(thread_hash_buf[i]); |
367 | } |
367 | } |
368 | 368 | ||
369 | getchar(); |
369 | getchar(); |
370 | 370 | ||
371 | printf("terminate debugging session...\n"); |
371 | printf("terminate debugging session...\n"); |
372 | abort_trace = 1; |
372 | abort_trace = 1; |
373 | debug_end(phoneid); |
373 | debug_end(phoneid); |
374 | ipc_hangup(phoneid); |
374 | ipc_hangup(phoneid); |
375 | 375 | ||
376 | ipcp_cleanup(); |
376 | ipcp_cleanup(); |
377 | 377 | ||
378 | printf("done\n"); |
378 | printf("done\n"); |
379 | return; |
379 | return; |
380 | } |
380 | } |
381 | 381 | ||
382 | static void main_init(void) |
382 | static void main_init(void) |
383 | { |
383 | { |
384 | proto_t *p; |
384 | proto_t *p; |
385 | oper_t *o; |
385 | oper_t *o; |
386 | 386 | ||
387 | next_thread_id = 1; |
387 | next_thread_id = 1; |
388 | 388 | ||
389 | proto_init(); |
389 | proto_init(); |
390 | 390 | ||
391 | o = malloc(sizeof(oper_t)); |
- | |
392 | o->name = "mount"; |
- | |
393 | - | ||
394 | p = proto_new("vfs"); |
391 | p = proto_new("vfs"); |
- | 392 | o = oper_new("read"); |
|
- | 393 | proto_add_oper(p, VFS_READ, o); |
|
- | 394 | o = oper_new("write"); |
|
- | 395 | proto_add_oper(p, VFS_WRITE, o); |
|
- | 396 | o = oper_new("truncate"); |
|
- | 397 | proto_add_oper(p, VFS_TRUNCATE, o); |
|
- | 398 | o = oper_new("mount"); |
|
395 | proto_add_oper(p, VFS_MOUNT, o); |
399 | proto_add_oper(p, VFS_MOUNT, o); |
- | 400 | o = oper_new("unmount"); |
|
- | 401 | proto_add_oper(p, VFS_UNMOUNT, o); |
|
396 | 402 | ||
397 | proto_register(SERVICE_VFS, p); |
403 | proto_register(SERVICE_VFS, p); |
398 | 404 | ||
399 | p = proto_new("console"); |
405 | p = proto_new("console"); |
400 | o = malloc(sizeof(oper_t)); |
406 | o = oper_new("getchar"); |
- | 407 | proto_add_oper(p, CONSOLE_GETCHAR, o); |
|
401 | o->name = "putchar"; |
408 | o = oper_new("putchar"); |
402 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
409 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
- | 410 | o = oper_new("clear"); |
|
- | 411 | proto_add_oper(p, CONSOLE_CLEAR, o); |
|
- | 412 | o = oper_new("goto"); |
|
- | 413 | proto_add_oper(p, CONSOLE_GOTO, o); |
|
- | 414 | o = oper_new("getsize"); |
|
- | 415 | proto_add_oper(p, CONSOLE_GETSIZE, o); |
|
- | 416 | o = oper_new("flush"); |
|
- | 417 | proto_add_oper(p, CONSOLE_FLUSH, o); |
|
- | 418 | o = oper_new("set_style"); |
|
- | 419 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
|
- | 420 | o = oper_new("flush"); |
|
- | 421 | proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o); |
|
- | 422 | o = oper_new("cursor_visibility"); |
|
- | 423 | proto_add_oper(p, CONSOLE_FLUSH, o); |
|
403 | 424 | ||
404 | proto_console = p; |
425 | proto_console = p; |
405 | proto_register(SERVICE_CONSOLE, p); |
426 | proto_register(SERVICE_CONSOLE, p); |
406 | } |
427 | } |
407 | 428 | ||
408 | int main(void) |
429 | int main(void) |
409 | { |
430 | { |
410 | main_init(); |
431 | main_init(); |
411 | 432 | ||
412 | while (1) { |
433 | while (1) { |
413 | trace_active_task(); |
434 | trace_active_task(); |
414 | } |
435 | } |
415 | } |
436 | } |
416 | 437 | ||
417 | /** @} |
438 | /** @} |
418 | */ |
439 | */ |
419 | 440 |