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