Rev 3428 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3428 | Rev 3435 | ||
---|---|---|---|
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 trace |
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 | 54 | ||
55 | #define THBUF_SIZE 64 |
55 | #define THBUF_SIZE 64 |
56 | unsigned thread_hash_buf[THBUF_SIZE]; |
56 | unsigned thread_hash_buf[THBUF_SIZE]; |
57 | unsigned n_threads; |
57 | unsigned n_threads; |
58 | 58 | ||
59 | int next_thread_id; |
59 | int next_thread_id; |
60 | 60 | ||
61 | int phoneid; |
61 | int phoneid; |
62 | int abort_trace; |
62 | int abort_trace; |
63 | 63 | ||
64 | unsigned thash; |
64 | unsigned thash; |
65 | volatile int paused; |
65 | volatile int paused; |
66 | 66 | ||
67 | void thread_trace_start(unsigned thread_hash); |
67 | void thread_trace_start(unsigned thread_hash); |
68 | 68 | ||
69 | static proto_t *proto_console; |
69 | static proto_t *proto_console; |
70 | 70 | ||
71 | static int task_connect(task_id_t task_id) |
71 | static int task_connect(task_id_t task_id) |
72 | { |
72 | { |
73 | int rc; |
73 | int rc; |
74 | 74 | ||
75 | printf("ipc_connect_task(%lld)... ", task_id); |
75 | printf("ipc_connect_task(%lld)... ", task_id); |
76 | rc = ipc_connect_kbox(task_id); |
76 | rc = ipc_connect_kbox(task_id); |
77 | printf("-> %d\n", rc); |
77 | printf("-> %d\n", rc); |
78 | phoneid = rc; |
78 | phoneid = rc; |
79 | if (rc < 0) return rc; |
79 | if (rc < 0) return rc; |
80 | 80 | ||
81 | printf("udebug_begin()... "); |
81 | printf("udebug_begin()... "); |
82 | rc = udebug_begin(phoneid); |
82 | rc = udebug_begin(phoneid); |
83 | printf("-> %d\n", rc); |
83 | printf("-> %d\n", rc); |
84 | if (rc < 0) return rc; |
84 | if (rc < 0) return rc; |
85 | 85 | ||
86 | printf("udebug_set_evmask(0x%x)... ", UDEBUG_EM_ALL); |
86 | printf("udebug_set_evmask(0x%x)... ", UDEBUG_EM_ALL); |
87 | rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL); |
87 | rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL); |
88 | printf("-> %d\n", rc); |
88 | printf("-> %d\n", rc); |
89 | if (rc < 0) return rc; |
89 | if (rc < 0) return rc; |
90 | 90 | ||
91 | return 0; |
91 | return 0; |
92 | } |
92 | } |
93 | 93 | ||
94 | static int get_thread_list(void) |
94 | static int get_thread_list(void) |
95 | { |
95 | { |
96 | int rc; |
96 | int rc; |
97 | size_t tb_copied; |
97 | size_t tb_copied; |
98 | size_t tb_needed; |
98 | size_t tb_needed; |
99 | int i; |
99 | int i; |
100 | 100 | ||
101 | printf("send IPC_M_DEBUG_THREAD_READ message\n"); |
101 | printf("send IPC_M_DEBUG_THREAD_READ message\n"); |
102 | rc = udebug_thread_read(phoneid, thread_hash_buf, |
102 | rc = udebug_thread_read(phoneid, thread_hash_buf, |
103 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
103 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
104 | printf("-> %d\n", rc); |
104 | printf("-> %d\n", rc); |
105 | if (rc < 0) return rc; |
105 | if (rc < 0) return rc; |
106 | 106 | ||
107 | n_threads = tb_copied / sizeof(unsigned); |
107 | n_threads = tb_copied / sizeof(unsigned); |
108 | 108 | ||
109 | printf("thread IDs:"); |
109 | printf("thread IDs:"); |
110 | for (i=0; i<n_threads; i++) { |
110 | for (i=0; i<n_threads; i++) { |
111 | printf(" %u", thread_hash_buf[i]); |
111 | printf(" %u", thread_hash_buf[i]); |
112 | } |
112 | } |
113 | printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned)); |
113 | printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned)); |
114 | 114 | ||
115 | return 0; |
115 | return 0; |
116 | } |
116 | } |
117 | 117 | ||
118 | static void print_sc_retval(int retval, rv_type_t rv_type) |
118 | static void print_sc_retval(int retval, rv_type_t rv_type) |
119 | { |
119 | { |
120 | printf (" -> "); |
120 | printf (" -> "); |
121 | if (rv_type == RV_INTEGER) { |
121 | if (rv_type == RV_INTEGER) { |
122 | printf("%d", retval); |
122 | printf("%d", retval); |
123 | } else if (rv_type == RV_HASH) { |
123 | } else if (rv_type == RV_HASH) { |
124 | printf("0x%08x", retval); |
124 | printf("0x%08x", retval); |
125 | } else if (rv_type == RV_ERRNO) { |
125 | } else if (rv_type == RV_ERRNO) { |
126 | if (retval >= -15 && retval <= 0) { |
126 | if (retval >= -15 && retval <= 0) { |
127 | printf("%d %s (%s)", retval, |
127 | printf("%d %s (%s)", retval, |
128 | err_desc[retval].name, |
128 | err_desc[retval].name, |
129 | err_desc[retval].desc); |
129 | err_desc[retval].desc); |
130 | } else { |
130 | } else { |
131 | printf("%d", retval); |
131 | printf("%d", retval); |
132 | } |
132 | } |
133 | } else if (rv_type == RV_INT_ERRNO) { |
133 | } else if (rv_type == RV_INT_ERRNO) { |
134 | if (retval >= -15 && retval < 0) { |
134 | if (retval >= -15 && retval < 0) { |
135 | printf("%d %s (%s)", retval, |
135 | printf("%d %s (%s)", retval, |
136 | err_desc[retval].name, |
136 | err_desc[retval].name, |
137 | err_desc[retval].desc); |
137 | err_desc[retval].desc); |
138 | } else { |
138 | } else { |
139 | printf("%d", retval); |
139 | printf("%d", retval); |
140 | } |
140 | } |
141 | } |
141 | } |
142 | putchar('\n'); |
142 | putchar('\n'); |
143 | } |
143 | } |
144 | 144 | ||
145 | static void print_sc_args(unsigned *sc_args, int n) |
145 | static void print_sc_args(unsigned *sc_args, int n) |
146 | { |
146 | { |
147 | int i; |
147 | int i; |
148 | 148 | ||
149 | putchar('('); |
149 | putchar('('); |
150 | if (n > 0) printf("%d", sc_args[0]); |
150 | if (n > 0) printf("%d", sc_args[0]); |
151 | for (i=1; i<n; i++) { |
151 | for (i=1; i<n; i++) { |
152 | printf(", %d", sc_args[i]); |
152 | printf(", %d", sc_args[i]); |
153 | } |
153 | } |
154 | putchar(')'); |
154 | putchar(')'); |
155 | } |
155 | } |
156 | 156 | ||
157 | static void sc_ipc_call_async_fast(unsigned *sc_args, int sc_rc) |
157 | static void sc_ipc_call_async_fast(unsigned *sc_args, int sc_rc) |
158 | { |
158 | { |
159 | ipc_call_t call; |
159 | ipc_call_t call; |
160 | int phoneid; |
160 | int phoneid; |
161 | 161 | ||
162 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
162 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
163 | return; |
163 | return; |
164 | 164 | ||
165 | phoneid = sc_args[0]; |
165 | phoneid = sc_args[0]; |
166 | 166 | ||
167 | IPC_SET_METHOD(call, sc_args[1]); |
167 | IPC_SET_METHOD(call, sc_args[1]); |
168 | IPC_SET_ARG1(call, sc_args[2]); |
168 | IPC_SET_ARG1(call, sc_args[2]); |
169 | IPC_SET_ARG2(call, sc_args[3]); |
169 | IPC_SET_ARG2(call, sc_args[3]); |
170 | IPC_SET_ARG3(call, sc_args[4]); |
170 | IPC_SET_ARG3(call, sc_args[4]); |
171 | IPC_SET_ARG4(call, sc_args[5]); |
171 | IPC_SET_ARG4(call, sc_args[5]); |
172 | IPC_SET_ARG5(call, 0); |
172 | IPC_SET_ARG5(call, 0); |
173 | 173 | ||
174 | ipcp_call_out(phoneid, &call, sc_rc); |
174 | ipcp_call_out(phoneid, &call, sc_rc); |
175 | } |
175 | } |
176 | 176 | ||
177 | static void sc_ipc_call_async_slow(unsigned *sc_args, int sc_rc) |
177 | static void sc_ipc_call_async_slow(unsigned *sc_args, int sc_rc) |
178 | { |
178 | { |
179 | ipc_call_t call; |
179 | ipc_call_t call; |
180 | int rc; |
180 | int rc; |
181 | 181 | ||
182 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
182 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
183 | return; |
183 | return; |
184 | 184 | ||
185 | memset(&call, 0, sizeof(call)); |
185 | memset(&call, 0, sizeof(call)); |
186 | rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
186 | rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
187 | 187 | ||
188 | if (rc >= 0) { |
188 | if (rc >= 0) { |
189 | ipcp_call_out(sc_args[0], &call, sc_rc); |
189 | ipcp_call_out(sc_args[0], &call, sc_rc); |
190 | } |
190 | } |
191 | } |
191 | } |
192 | 192 | ||
193 | static void sc_ipc_call_sync_fast(unsigned *sc_args) |
193 | static void sc_ipc_call_sync_fast(unsigned *sc_args) |
194 | { |
194 | { |
195 | ipc_call_t question, reply; |
195 | ipc_call_t question, reply; |
196 | int rc; |
196 | int rc; |
197 | int phoneidx; |
197 | int phoneidx; |
198 | 198 | ||
199 | // printf("sc_ipc_call_sync_fast()\n"); |
199 | // printf("sc_ipc_call_sync_fast()\n"); |
200 | phoneidx = sc_args[0]; |
200 | phoneidx = sc_args[0]; |
201 | 201 | ||
202 | IPC_SET_METHOD(question, sc_args[1]); |
202 | IPC_SET_METHOD(question, sc_args[1]); |
203 | IPC_SET_ARG1(question, sc_args[2]); |
203 | IPC_SET_ARG1(question, sc_args[2]); |
204 | IPC_SET_ARG2(question, sc_args[3]); |
204 | IPC_SET_ARG2(question, sc_args[3]); |
205 | IPC_SET_ARG3(question, sc_args[4]); |
205 | IPC_SET_ARG3(question, sc_args[4]); |
206 | IPC_SET_ARG4(question, 0); |
206 | IPC_SET_ARG4(question, 0); |
207 | IPC_SET_ARG5(question, 0); |
207 | IPC_SET_ARG5(question, 0); |
208 | 208 | ||
209 | // printf("memset\n"); |
209 | // printf("memset\n"); |
210 | memset(&reply, 0, sizeof(reply)); |
210 | memset(&reply, 0, sizeof(reply)); |
211 | // printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", |
211 | // printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", |
212 | // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
212 | // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
213 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
213 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
214 | // printf("dmr->%d\n", rc); |
214 | // printf("dmr->%d\n", rc); |
215 | if (rc < 0) return; |
215 | if (rc < 0) return; |
216 | 216 | ||
217 | // printf("call ipc_call_sync\n"); |
217 | // printf("call ipc_call_sync\n"); |
218 | ipcp_call_sync(phoneidx, &question, &reply); |
218 | ipcp_call_sync(phoneidx, &question, &reply); |
219 | } |
219 | } |
220 | 220 | ||
221 | static void sc_ipc_call_sync_slow(unsigned *sc_args) |
221 | static void sc_ipc_call_sync_slow(unsigned *sc_args) |
222 | { |
222 | { |
223 | ipc_call_t question, reply; |
223 | ipc_call_t question, reply; |
224 | int rc; |
224 | int rc; |
225 | 225 | ||
226 | memset(&question, 0, sizeof(question)); |
226 | memset(&question, 0, sizeof(question)); |
227 | rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
227 | rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
228 | printf("dmr->%d\n", rc); |
228 | printf("dmr->%d\n", rc); |
229 | if (rc < 0) return; |
229 | if (rc < 0) return; |
230 | 230 | ||
231 | memset(&reply, 0, sizeof(reply)); |
231 | memset(&reply, 0, sizeof(reply)); |
232 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
232 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
233 | printf("dmr->%d\n", rc); |
233 | printf("dmr->%d\n", rc); |
234 | if (rc < 0) return; |
234 | if (rc < 0) return; |
235 | 235 | ||
236 | ipcp_call_sync(sc_args[0], &question, &reply); |
236 | ipcp_call_sync(sc_args[0], &question, &reply); |
237 | } |
237 | } |
238 | 238 | ||
239 | static void sc_ipc_wait(unsigned *sc_args, int sc_rc) |
239 | static void sc_ipc_wait(unsigned *sc_args, int sc_rc) |
240 | { |
240 | { |
241 | ipc_call_t call; |
241 | ipc_call_t call; |
242 | int rc; |
242 | int rc; |
243 | 243 | ||
244 | if (sc_rc == 0) return; |
244 | if (sc_rc == 0) return; |
245 | 245 | ||
246 | memset(&call, 0, sizeof(call)); |
246 | memset(&call, 0, sizeof(call)); |
247 | rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); |
247 | rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); |
248 | // printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", |
248 | // printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", |
249 | // phoneid, (int)&call, sc_args[0], sizeof(call), rc); |
249 | // phoneid, (int)&call, sc_args[0], sizeof(call), rc); |
250 | 250 | ||
251 | if (rc >= 0) { |
251 | if (rc >= 0) { |
252 | ipcp_call_in(&call, sc_rc); |
252 | ipcp_call_in(&call, sc_rc); |
253 | } |
253 | } |
254 | } |
254 | } |
255 | 255 | ||
256 | static void event_syscall_b(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
256 | static void event_syscall_b(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
257 | { |
257 | { |
258 | unsigned sc_args[6]; |
258 | unsigned sc_args[6]; |
259 | int rc; |
259 | int rc; |
260 | 260 | ||
261 | /* Read syscall arguments */ |
261 | /* Read syscall arguments */ |
262 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
262 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
263 | 263 | ||
264 | async_serialize_start(); |
264 | async_serialize_start(); |
265 | 265 | ||
266 | // printf("[%d] ", thread_id); |
266 | // printf("[%d] ", thread_id); |
267 | 267 | ||
268 | if (rc < 0) { |
268 | if (rc < 0) { |
269 | printf("error\n"); |
269 | printf("error\n"); |
270 | async_serialize_end(); |
270 | async_serialize_end(); |
271 | return; |
271 | return; |
272 | } |
272 | } |
273 | 273 | ||
274 | /* Print syscall name, id and arguments */ |
274 | /* Print syscall name, id and arguments */ |
275 | printf("%s", syscall_desc[sc_id].name); |
275 | printf("%s", syscall_desc[sc_id].name); |
276 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
276 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
277 | 277 | ||
278 | async_serialize_end(); |
278 | async_serialize_end(); |
279 | } |
279 | } |
280 | 280 | ||
281 | static void event_syscall_e(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
281 | static void event_syscall_e(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
282 | { |
282 | { |
283 | unsigned sc_args[6]; |
283 | unsigned sc_args[6]; |
284 | int rv_type; |
284 | int rv_type; |
285 | int rc; |
285 | int rc; |
286 | 286 | ||
287 | /* Read syscall arguments */ |
287 | /* Read syscall arguments */ |
288 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
288 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
289 | 289 | ||
290 | async_serialize_start(); |
290 | async_serialize_start(); |
291 | 291 | ||
292 | // printf("[%d] ", thread_id); |
292 | // printf("[%d] ", thread_id); |
293 | 293 | ||
294 | if (rc < 0) { |
294 | if (rc < 0) { |
295 | printf("error\n"); |
295 | printf("error\n"); |
296 | async_serialize_end(); |
296 | async_serialize_end(); |
297 | return; |
297 | return; |
298 | } |
298 | } |
299 | 299 | ||
300 | rv_type = syscall_desc[sc_id].rv_type; |
300 | rv_type = syscall_desc[sc_id].rv_type; |
301 | print_sc_retval(sc_rc, rv_type); |
301 | print_sc_retval(sc_rc, rv_type); |
302 | 302 | ||
303 | switch (sc_id) { |
303 | switch (sc_id) { |
304 | case SYS_IPC_CALL_ASYNC_FAST: |
304 | case SYS_IPC_CALL_ASYNC_FAST: |
305 | sc_ipc_call_async_fast(sc_args, sc_rc); |
305 | sc_ipc_call_async_fast(sc_args, sc_rc); |
306 | break; |
306 | break; |
307 | case SYS_IPC_CALL_ASYNC_SLOW: |
307 | case SYS_IPC_CALL_ASYNC_SLOW: |
308 | sc_ipc_call_async_slow(sc_args, sc_rc); |
308 | sc_ipc_call_async_slow(sc_args, sc_rc); |
309 | break; |
309 | break; |
310 | case SYS_IPC_CALL_SYNC_FAST: |
310 | case SYS_IPC_CALL_SYNC_FAST: |
311 | sc_ipc_call_sync_fast(sc_args); |
311 | sc_ipc_call_sync_fast(sc_args); |
312 | break; |
312 | break; |
313 | case SYS_IPC_CALL_SYNC_SLOW: |
313 | case SYS_IPC_CALL_SYNC_SLOW: |
314 | sc_ipc_call_sync_slow(sc_args); |
314 | sc_ipc_call_sync_slow(sc_args); |
315 | break; |
315 | break; |
316 | case SYS_IPC_WAIT: |
316 | case SYS_IPC_WAIT: |
317 | sc_ipc_wait(sc_args, sc_rc); |
317 | sc_ipc_wait(sc_args, sc_rc); |
318 | break; |
318 | break; |
319 | default: |
319 | default: |
320 | break; |
320 | break; |
321 | } |
321 | } |
322 | 322 | ||
323 | async_serialize_end(); |
323 | async_serialize_end(); |
324 | } |
324 | } |
325 | 325 | ||
326 | static void event_thread_b(unsigned hash) |
326 | static void event_thread_b(unsigned hash) |
327 | { |
327 | { |
328 | async_serialize_start(); |
328 | async_serialize_start(); |
329 | printf("new thread, hash 0x%x\n", hash); |
329 | printf("new thread, hash 0x%x\n", hash); |
330 | async_serialize_end(); |
330 | async_serialize_end(); |
331 | 331 | ||
332 | thread_trace_start(hash); |
332 | thread_trace_start(hash); |
333 | } |
333 | } |
334 | 334 | ||
335 | static int trace_loop(void *thread_hash_arg) |
335 | static int trace_loop(void *thread_hash_arg) |
336 | { |
336 | { |
337 | int rc; |
337 | int rc; |
338 | unsigned ev_type; |
338 | unsigned ev_type; |
339 | unsigned thread_hash; |
339 | unsigned thread_hash; |
340 | unsigned thread_id; |
340 | unsigned thread_id; |
341 | unsigned val0, val1; |
341 | unsigned val0, val1; |
342 | 342 | ||
343 | thread_hash = (unsigned)thread_hash_arg; |
343 | thread_hash = (unsigned)thread_hash_arg; |
344 | thread_id = next_thread_id++; |
344 | thread_id = next_thread_id++; |
345 | 345 | ||
346 | printf("trace_loop(%d)\n", thread_id); |
346 | printf("trace_loop(%d)\n", thread_id); |
347 | 347 | ||
348 | while (!abort_trace) { |
348 | while (!abort_trace) { |
349 | 349 | ||
350 | /* Run thread until an event occurs */ |
350 | /* Run thread until an event occurs */ |
351 | rc = udebug_go(phoneid, thread_hash, |
351 | rc = udebug_go(phoneid, thread_hash, |
352 | &ev_type, &val0, &val1); |
352 | &ev_type, &val0, &val1); |
353 | 353 | ||
354 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
354 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
355 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
355 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
356 | printf("thread %u debugging finished\n", thread_id); |
356 | printf("thread %u debugging finished\n", thread_id); |
357 | break; |
357 | break; |
358 | } |
358 | } |
359 | 359 | ||
360 | if (rc >= 0) { |
360 | if (rc >= 0) { |
361 | switch (ev_type) { |
361 | switch (ev_type) { |
362 | case UDEBUG_EVENT_SYSCALL_B: |
362 | case UDEBUG_EVENT_SYSCALL_B: |
363 | event_syscall_b(thread_id, thread_hash, val0, (int)val1); |
363 | event_syscall_b(thread_id, thread_hash, val0, (int)val1); |
364 | break; |
364 | break; |
365 | case UDEBUG_EVENT_SYSCALL_E: |
365 | case UDEBUG_EVENT_SYSCALL_E: |
366 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
366 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
367 | break; |
367 | break; |
368 | case UDEBUG_EVENT_STOP: |
368 | case UDEBUG_EVENT_STOP: |
369 | printf("stop event\n"); |
369 | printf("stop event\n"); |
370 | printf("waiting for resume\n"); |
370 | printf("waiting for resume\n"); |
371 | while (paused) { |
371 | while (paused) { |
372 | usleep(1000000); |
372 | usleep(1000000); |
373 | fibril_yield(); |
373 | fibril_yield(); |
374 | printf("."); |
374 | printf("."); |
375 | } |
375 | } |
376 | printf("resumed\n"); |
376 | printf("resumed\n"); |
377 | break; |
377 | break; |
378 | case UDEBUG_EVENT_THREAD_B: |
378 | case UDEBUG_EVENT_THREAD_B: |
379 | event_thread_b(val0); |
379 | event_thread_b(val0); |
380 | break; |
380 | break; |
381 | case UDEBUG_EVENT_THREAD_E: |
381 | case UDEBUG_EVENT_THREAD_E: |
382 | printf("thread 0x%x exited\n", val0); |
382 | printf("thread 0x%x exited\n", val0); |
383 | abort_trace = 1; |
383 | abort_trace = 1; |
384 | break; |
384 | break; |
385 | default: |
385 | default: |
386 | printf("unknown event type %d\n", ev_type); |
386 | printf("unknown event type %d\n", ev_type); |
387 | break; |
387 | break; |
388 | } |
388 | } |
389 | } |
389 | } |
390 | 390 | ||
391 | } |
391 | } |
392 | 392 | ||
393 | printf("trace_loop(%d) exiting\n", thread_id); |
393 | printf("trace_loop(%d) exiting\n", thread_id); |
394 | return 0; |
394 | return 0; |
395 | } |
395 | } |
396 | 396 | ||
397 | void thread_trace_start(unsigned thread_hash) |
397 | void thread_trace_start(unsigned thread_hash) |
398 | { |
398 | { |
399 | fid_t fid; |
399 | fid_t fid; |
400 | 400 | ||
401 | thash = thread_hash; |
401 | thash = thread_hash; |
402 | 402 | ||
403 | fid = fibril_create(trace_loop, (void *)thread_hash); |
403 | fid = fibril_create(trace_loop, (void *)thread_hash); |
404 | if (fid == 0) { |
404 | if (fid == 0) { |
405 | printf("Warning: Failed creating fibril\n"); |
405 | printf("Warning: Failed creating fibril\n"); |
406 | } |
406 | } |
407 | fibril_add_ready(fid); |
407 | fibril_add_ready(fid); |
408 | } |
408 | } |
409 | 409 | ||
410 | static void trace_active_task(task_id_t task_id) |
410 | static void trace_active_task(task_id_t task_id) |
411 | { |
411 | { |
412 | int i; |
412 | int i; |
413 | int rc; |
413 | int rc; |
414 | int c; |
414 | int c; |
415 | 415 | ||
416 | printf("Syscall Tracer\n"); |
416 | printf("Syscall Tracer\n"); |
417 | 417 | ||
418 | rc = task_connect(task_id); |
418 | rc = task_connect(task_id); |
419 | if (rc < 0) { |
419 | if (rc < 0) { |
420 | printf("Failed to connect to task %lld\n", task_id); |
420 | printf("Failed to connect to task %lld\n", task_id); |
421 | return; |
421 | return; |
422 | } |
422 | } |
423 | 423 | ||
424 | printf("Connected to task %lld\n", task_id); |
424 | printf("Connected to task %lld\n", task_id); |
425 | 425 | ||
426 | ipcp_init(); |
426 | ipcp_init(); |
427 | ipcp_connection_set(1, 0, proto_console); |
427 | ipcp_connection_set(1, 0, proto_console); |
428 | 428 | ||
429 | rc = get_thread_list(); |
429 | rc = get_thread_list(); |
430 | if (rc < 0) { |
430 | if (rc < 0) { |
431 | printf("Failed to get thread list (error %d)\n", rc); |
431 | printf("Failed to get thread list (error %d)\n", rc); |
432 | return; |
432 | return; |
433 | } |
433 | } |
434 | 434 | ||
435 | abort_trace = 0; |
435 | abort_trace = 0; |
436 | 436 | ||
437 | for (i = 0; i < n_threads; i++) { |
437 | for (i = 0; i < n_threads; i++) { |
438 | thread_trace_start(thread_hash_buf[i]); |
438 | thread_trace_start(thread_hash_buf[i]); |
439 | } |
439 | } |
440 | 440 | ||
441 | while(1) { |
441 | while(1) { |
442 | c = getchar(); |
442 | c = getchar(); |
443 | if (c == 'q') break; |
443 | if (c == 'q') break; |
444 | if (c == 'p') { |
444 | if (c == 'p') { |
445 | paused = 1; |
445 | paused = 1; |
446 | rc = udebug_stop(phoneid, thash); |
446 | rc = udebug_stop(phoneid, thash); |
447 | printf("stop -> %d\n", rc); |
447 | printf("stop -> %d\n", rc); |
448 | } |
448 | } |
449 | if (c == 'r') { |
449 | if (c == 'r') { |
450 | paused = 0; |
450 | paused = 0; |
451 | } |
451 | } |
452 | } |
452 | } |
453 | 453 | ||
454 | printf("terminate debugging session...\n"); |
454 | printf("terminate debugging session...\n"); |
455 | abort_trace = 1; |
455 | abort_trace = 1; |
456 | udebug_end(phoneid); |
456 | udebug_end(phoneid); |
457 | ipc_hangup(phoneid); |
457 | ipc_hangup(phoneid); |
458 | 458 | ||
459 | ipcp_cleanup(); |
459 | ipcp_cleanup(); |
460 | 460 | ||
461 | printf("done\n"); |
461 | printf("done\n"); |
462 | return; |
462 | return; |
463 | } |
463 | } |
464 | 464 | ||
465 | static void main_init(void) |
465 | static void main_init(void) |
466 | { |
466 | { |
467 | proto_t *p; |
467 | proto_t *p; |
468 | oper_t *o; |
468 | oper_t *o; |
469 | 469 | ||
470 | next_thread_id = 1; |
470 | next_thread_id = 1; |
471 | paused = 0; |
471 | paused = 0; |
472 | 472 | ||
473 | proto_init(); |
473 | proto_init(); |
474 | 474 | ||
475 | p = proto_new("vfs"); |
475 | p = proto_new("vfs"); |
476 | o = oper_new("read"); |
476 | o = oper_new("read"); |
477 | proto_add_oper(p, VFS_READ, o); |
477 | proto_add_oper(p, VFS_READ, o); |
478 | o = oper_new("write"); |
478 | o = oper_new("write"); |
479 | proto_add_oper(p, VFS_WRITE, o); |
479 | proto_add_oper(p, VFS_WRITE, o); |
480 | o = oper_new("truncate"); |
480 | o = oper_new("truncate"); |
481 | proto_add_oper(p, VFS_TRUNCATE, o); |
481 | proto_add_oper(p, VFS_TRUNCATE, o); |
482 | o = oper_new("mount"); |
482 | o = oper_new("mount"); |
483 | proto_add_oper(p, VFS_MOUNT, o); |
483 | proto_add_oper(p, VFS_MOUNT, o); |
484 | o = oper_new("unmount"); |
484 | o = oper_new("unmount"); |
485 | proto_add_oper(p, VFS_UNMOUNT, o); |
485 | proto_add_oper(p, VFS_UNMOUNT, o); |
486 | 486 | ||
487 | proto_register(SERVICE_VFS, p); |
487 | proto_register(SERVICE_VFS, p); |
488 | 488 | ||
489 | p = proto_new("console"); |
489 | p = proto_new("console"); |
490 | o = oper_new("getchar"); |
490 | o = oper_new("getchar"); |
491 | proto_add_oper(p, CONSOLE_GETCHAR, o); |
491 | proto_add_oper(p, CONSOLE_GETCHAR, o); |
492 | o = oper_new("putchar"); |
492 | o = oper_new("putchar"); |
493 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
493 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
494 | o = oper_new("clear"); |
494 | o = oper_new("clear"); |
495 | proto_add_oper(p, CONSOLE_CLEAR, o); |
495 | proto_add_oper(p, CONSOLE_CLEAR, o); |
496 | o = oper_new("goto"); |
496 | o = oper_new("goto"); |
497 | proto_add_oper(p, CONSOLE_GOTO, o); |
497 | proto_add_oper(p, CONSOLE_GOTO, o); |
498 | o = oper_new("getsize"); |
498 | o = oper_new("getsize"); |
499 | proto_add_oper(p, CONSOLE_GETSIZE, o); |
499 | proto_add_oper(p, CONSOLE_GETSIZE, o); |
500 | o = oper_new("flush"); |
500 | o = oper_new("flush"); |
501 | proto_add_oper(p, CONSOLE_FLUSH, o); |
501 | proto_add_oper(p, CONSOLE_FLUSH, o); |
502 | o = oper_new("set_style"); |
502 | o = oper_new("set_style"); |
503 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
503 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
504 | o = oper_new("cursor_visibility"); |
504 | o = oper_new("cursor_visibility"); |
505 | proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o); |
505 | proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o); |
506 | o = oper_new("flush"); |
506 | o = oper_new("flush"); |
507 | proto_add_oper(p, CONSOLE_FLUSH, o); |
507 | proto_add_oper(p, CONSOLE_FLUSH, o); |
508 | 508 | ||
509 | proto_console = p; |
509 | proto_console = p; |
510 | proto_register(SERVICE_CONSOLE, p); |
510 | proto_register(SERVICE_CONSOLE, p); |
511 | } |
511 | } |
512 | 512 | ||
513 | static void print_syntax() |
513 | static void print_syntax() |
514 | { |
514 | { |
515 | printf("syntax: sctrace <task_id>\n"); |
515 | printf("syntax: trace <task_id>\n"); |
516 | } |
516 | } |
517 | 517 | ||
518 | int main(int argc, char *argv[]) |
518 | int main(int argc, char *argv[]) |
519 | { |
519 | { |
520 | task_id_t task_id; |
520 | task_id_t task_id; |
521 | char *err_p; |
521 | char *err_p; |
522 | 522 | ||
523 | if (argc != 2) { |
523 | if (argc != 2) { |
524 | printf("Mising argument\n"); |
524 | printf("Mising argument\n"); |
525 | print_syntax(); |
525 | print_syntax(); |
526 | return 1; |
526 | return 1; |
527 | } |
527 | } |
528 | 528 | ||
529 | task_id = strtol(argv[1], &err_p, 10); |
529 | task_id = strtol(argv[1], &err_p, 10); |
530 | 530 | ||
531 | if (*err_p) { |
531 | if (*err_p) { |
532 | printf("Task ID syntax error\n"); |
532 | printf("Task ID syntax error\n"); |
533 | print_syntax(); |
533 | print_syntax(); |
534 | return 1; |
534 | return 1; |
535 | } |
535 | } |
536 | 536 | ||
537 | main_init(); |
537 | main_init(); |
538 | trace_active_task(task_id); |
538 | trace_active_task(task_id); |
539 | } |
539 | } |
540 | 540 | ||
541 | /** @} |
541 | /** @} |
542 | */ |
542 | */ |
543 | 543 |