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