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