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