Rev 3455 | Rev 3485 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3455 | Rev 3470 | ||
---|---|---|---|
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 | #include <task.h> |
44 | #include <task.h> |
- | 45 | #include <loader/loader.h> |
|
45 | 46 | ||
46 | // Temporary: service and method names |
47 | // Temporary: service and method names |
47 | #include "proto.h" |
48 | #include "proto.h" |
48 | #include <ipc/services.h> |
49 | #include <ipc/services.h> |
49 | #include "../../srv/vfs/vfs.h" |
50 | #include "../../srv/vfs/vfs.h" |
50 | #include "../../srv/console/console.h" |
51 | #include "../../srv/console/console.h" |
51 | 52 | ||
52 | #include "syscalls.h" |
53 | #include "syscalls.h" |
53 | #include "ipcp.h" |
54 | #include "ipcp.h" |
54 | #include "errors.h" |
55 | #include "errors.h" |
55 | #include "trace.h" |
56 | #include "trace.h" |
56 | 57 | ||
57 | #define THBUF_SIZE 64 |
58 | #define THBUF_SIZE 64 |
58 | uintptr_t thread_hash_buf[THBUF_SIZE]; |
59 | uintptr_t thread_hash_buf[THBUF_SIZE]; |
59 | int n_threads; |
60 | int n_threads; |
60 | 61 | ||
61 | int next_thread_id; |
62 | int next_thread_id; |
62 | 63 | ||
63 | int phoneid; |
64 | int phoneid; |
64 | int abort_trace; |
65 | int abort_trace; |
65 | 66 | ||
66 | uintptr_t thash; |
67 | uintptr_t thash; |
67 | volatile int paused; |
68 | volatile int paused; |
68 | 69 | ||
69 | void thread_trace_start(uintptr_t thread_hash); |
70 | void thread_trace_start(uintptr_t thread_hash); |
70 | 71 | ||
71 | static proto_t *proto_console; |
72 | static proto_t *proto_console; |
72 | static task_id_t task_id; |
73 | static task_id_t task_id; |
- | 74 | static loader_t *task_ldr; |
|
73 | 75 | ||
74 | /** Combination of events/data to print. */ |
76 | /** Combination of events/data to print. */ |
75 | display_mask_t display_mask; |
77 | display_mask_t display_mask; |
76 | 78 | ||
- | 79 | static int program_run_fibril(void *arg); |
|
- | 80 | ||
- | 81 | static void program_run(void) |
|
- | 82 | { |
|
- | 83 | fid_t fid; |
|
- | 84 | ||
- | 85 | fid = fibril_create(program_run_fibril, NULL); |
|
- | 86 | if (fid == 0) { |
|
- | 87 | printf("Error creating fibril\n"); |
|
- | 88 | exit(1); |
|
- | 89 | } |
|
- | 90 | ||
- | 91 | fibril_add_ready(fid); |
|
- | 92 | } |
|
- | 93 | ||
- | 94 | static int program_run_fibril(void *arg) |
|
- | 95 | { |
|
- | 96 | int rc; |
|
- | 97 | ||
- | 98 | /* |
|
- | 99 | * This must be done in background as it will block until |
|
- | 100 | * we let the task reply to this call. |
|
- | 101 | */ |
|
- | 102 | rc = loader_run(task_ldr); |
|
- | 103 | if (rc != 0) { |
|
- | 104 | printf("Error running program\n"); |
|
- | 105 | exit(1); |
|
- | 106 | } |
|
- | 107 | ||
- | 108 | free(task_ldr); |
|
- | 109 | task_ldr = NULL; |
|
- | 110 | ||
- | 111 | printf("program_run_fibril exiting\n"); |
|
- | 112 | return 0; |
|
- | 113 | } |
|
- | 114 | ||
- | 115 | ||
77 | static int task_connect(task_id_t task_id) |
116 | static int connect_task(task_id_t task_id) |
78 | { |
117 | { |
79 | int rc; |
118 | int rc; |
80 | 119 | ||
81 | rc = ipc_connect_kbox(task_id); |
120 | rc = ipc_connect_kbox(task_id); |
82 | 121 | ||
83 | if (rc == ENOTSUP) { |
122 | if (rc == ENOTSUP) { |
84 | printf("You do not have userspace debugging support " |
123 | printf("You do not have userspace debugging support " |
85 | "compiled in the kernel.\n"); |
124 | "compiled in the kernel.\n"); |
86 | printf("Compile kernel with 'Support for userspace debuggers' " |
125 | printf("Compile kernel with 'Support for userspace debuggers' " |
87 | "(CONFIG_UDEBUG) enabled.\n"); |
126 | "(CONFIG_UDEBUG) enabled.\n"); |
88 | return rc; |
127 | return rc; |
89 | } |
128 | } |
90 | 129 | ||
91 | if (rc < 0) { |
130 | if (rc < 0) { |
92 | printf("Error connecting\n"); |
131 | printf("Error connecting\n"); |
93 | printf("ipc_connect_task(%lld) -> %d ", task_id, rc); |
132 | printf("ipc_connect_task(%lld) -> %d ", task_id, rc); |
94 | return rc; |
133 | return rc; |
95 | } |
134 | } |
96 | 135 | ||
97 | phoneid = rc; |
136 | phoneid = rc; |
98 | 137 | ||
99 | rc = udebug_begin(phoneid); |
138 | rc = udebug_begin(phoneid); |
100 | if (rc < 0) { |
139 | if (rc < 0) { |
101 | printf("udebug_begin() -> %d\n", rc); |
140 | printf("udebug_begin() -> %d\n", rc); |
102 | return rc; |
141 | return rc; |
103 | } |
142 | } |
104 | 143 | ||
105 | rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL); |
144 | rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL); |
106 | if (rc < 0) { |
145 | if (rc < 0) { |
107 | printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc); |
146 | printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc); |
108 | return rc; |
147 | return rc; |
109 | } |
148 | } |
110 | 149 | ||
111 | return 0; |
150 | return 0; |
112 | } |
151 | } |
113 | 152 | ||
114 | static int get_thread_list(void) |
153 | static int get_thread_list(void) |
115 | { |
154 | { |
116 | int rc; |
155 | int rc; |
117 | size_t tb_copied; |
156 | size_t tb_copied; |
118 | size_t tb_needed; |
157 | size_t tb_needed; |
119 | int i; |
158 | int i; |
120 | 159 | ||
121 | rc = udebug_thread_read(phoneid, thread_hash_buf, |
160 | rc = udebug_thread_read(phoneid, thread_hash_buf, |
122 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
161 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
123 | if (rc < 0) { |
162 | if (rc < 0) { |
124 | printf("udebug_thread_read() -> %d\n", rc); |
163 | printf("udebug_thread_read() -> %d\n", rc); |
125 | return rc; |
164 | return rc; |
126 | } |
165 | } |
127 | 166 | ||
128 | n_threads = tb_copied / sizeof(uintptr_t); |
167 | n_threads = tb_copied / sizeof(uintptr_t); |
129 | 168 | ||
130 | printf("Threads:"); |
169 | printf("Threads:"); |
131 | for (i = 0; i < n_threads; i++) { |
170 | for (i = 0; i < n_threads; i++) { |
132 | printf(" [%d] (hash 0x%lx)", 1+i, thread_hash_buf[i]); |
171 | printf(" [%d] (hash 0x%lx)", 1+i, thread_hash_buf[i]); |
133 | } |
172 | } |
134 | printf("\ntotal of %u threads\n", tb_needed / sizeof(uintptr_t)); |
173 | printf("\ntotal of %u threads\n", tb_needed / sizeof(uintptr_t)); |
135 | 174 | ||
136 | return 0; |
175 | return 0; |
137 | } |
176 | } |
138 | 177 | ||
139 | void val_print(sysarg_t val, val_type_t v_type) |
178 | void val_print(sysarg_t val, val_type_t v_type) |
140 | { |
179 | { |
141 | switch (v_type) { |
180 | switch (v_type) { |
142 | case V_VOID: |
181 | case V_VOID: |
143 | printf("<void>"); |
182 | printf("<void>"); |
144 | break; |
183 | break; |
145 | 184 | ||
146 | case V_INTEGER: |
185 | case V_INTEGER: |
147 | printf("%ld", val); |
186 | printf("%ld", val); |
148 | break; |
187 | break; |
149 | 188 | ||
150 | case V_HASH: |
189 | case V_HASH: |
- | 190 | case V_PTR: |
|
151 | printf("0x%08lx", val); |
191 | printf("0x%08lx", val); |
152 | break; |
192 | break; |
153 | 193 | ||
154 | case V_ERRNO: |
194 | case V_ERRNO: |
155 | if (val >= -15 && val <= 0) { |
195 | if (val >= -15 && val <= 0) { |
156 | printf("%ld %s (%s)", val, |
196 | printf("%ld %s (%s)", val, |
157 | err_desc[-val].name, |
197 | err_desc[-val].name, |
158 | err_desc[-val].desc); |
198 | err_desc[-val].desc); |
159 | } else { |
199 | } else { |
160 | printf("%ld", val); |
200 | printf("%ld", val); |
161 | } |
201 | } |
162 | break; |
202 | break; |
163 | case V_INT_ERRNO: |
203 | case V_INT_ERRNO: |
164 | if (val >= -15 && val < 0) { |
204 | if (val >= -15 && val < 0) { |
165 | printf("%ld %s (%s)", val, |
205 | printf("%ld %s (%s)", val, |
166 | err_desc[-val].name, |
206 | err_desc[-val].name, |
167 | err_desc[-val].desc); |
207 | err_desc[-val].desc); |
168 | } else { |
208 | } else { |
169 | printf("%ld", val); |
209 | printf("%ld", val); |
170 | } |
210 | } |
171 | break; |
211 | break; |
172 | 212 | ||
173 | case V_CHAR: |
213 | case V_CHAR: |
174 | if (val >= 0x20 && val < 0x7f) { |
214 | if (val >= 0x20 && val < 0x7f) { |
175 | printf("'%c'", val); |
215 | printf("'%c'", val); |
176 | } else { |
216 | } else { |
177 | switch (val) { |
217 | switch (val) { |
178 | case '\a': printf("'\\a'"); break; |
218 | case '\a': printf("'\\a'"); break; |
179 | case '\b': printf("'\\b'"); break; |
219 | case '\b': printf("'\\b'"); break; |
180 | case '\n': printf("'\\n'"); break; |
220 | case '\n': printf("'\\n'"); break; |
181 | case '\r': printf("'\\r'"); break; |
221 | case '\r': printf("'\\r'"); break; |
182 | case '\t': printf("'\\t'"); break; |
222 | case '\t': printf("'\\t'"); break; |
183 | case '\\': printf("'\\\\'"); break; |
223 | case '\\': printf("'\\\\'"); break; |
184 | default: printf("'\\x%02lX'", val); break; |
224 | default: printf("'\\x%02lX'", val); break; |
185 | } |
225 | } |
186 | } |
226 | } |
187 | break; |
227 | break; |
188 | } |
228 | } |
189 | } |
229 | } |
190 | 230 | ||
191 | 231 | ||
192 | static void print_sc_retval(sysarg_t retval, val_type_t val_type) |
232 | static void print_sc_retval(sysarg_t retval, val_type_t val_type) |
193 | { |
233 | { |
194 | printf(" -> "); |
234 | printf(" -> "); |
195 | val_print(retval, val_type); |
235 | val_print(retval, val_type); |
196 | putchar('\n'); |
236 | putchar('\n'); |
197 | } |
237 | } |
198 | 238 | ||
199 | static void print_sc_args(sysarg_t *sc_args, int n) |
239 | static void print_sc_args(sysarg_t *sc_args, int n) |
200 | { |
240 | { |
201 | int i; |
241 | int i; |
202 | 242 | ||
203 | putchar('('); |
243 | putchar('('); |
204 | if (n > 0) printf("%ld", sc_args[0]); |
244 | if (n > 0) printf("%ld", sc_args[0]); |
205 | for (i = 1; i < n; i++) { |
245 | for (i = 1; i < n; i++) { |
206 | printf(", %ld", sc_args[i]); |
246 | printf(", %ld", sc_args[i]); |
207 | } |
247 | } |
208 | putchar(')'); |
248 | putchar(')'); |
209 | } |
249 | } |
210 | 250 | ||
211 | static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc) |
251 | static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc) |
212 | { |
252 | { |
213 | ipc_call_t call; |
253 | ipc_call_t call; |
214 | ipcarg_t phoneid; |
254 | ipcarg_t phoneid; |
215 | 255 | ||
216 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
256 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
217 | return; |
257 | return; |
218 | 258 | ||
219 | phoneid = sc_args[0]; |
259 | phoneid = sc_args[0]; |
220 | 260 | ||
221 | IPC_SET_METHOD(call, sc_args[1]); |
261 | IPC_SET_METHOD(call, sc_args[1]); |
222 | IPC_SET_ARG1(call, sc_args[2]); |
262 | IPC_SET_ARG1(call, sc_args[2]); |
223 | IPC_SET_ARG2(call, sc_args[3]); |
263 | IPC_SET_ARG2(call, sc_args[3]); |
224 | IPC_SET_ARG3(call, sc_args[4]); |
264 | IPC_SET_ARG3(call, sc_args[4]); |
225 | IPC_SET_ARG4(call, sc_args[5]); |
265 | IPC_SET_ARG4(call, sc_args[5]); |
226 | IPC_SET_ARG5(call, 0); |
266 | IPC_SET_ARG5(call, 0); |
227 | 267 | ||
228 | ipcp_call_out(phoneid, &call, sc_rc); |
268 | ipcp_call_out(phoneid, &call, sc_rc); |
229 | } |
269 | } |
230 | 270 | ||
231 | static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc) |
271 | static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc) |
232 | { |
272 | { |
233 | ipc_call_t call; |
273 | ipc_call_t call; |
234 | int rc; |
274 | int rc; |
235 | 275 | ||
236 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
276 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
237 | return; |
277 | return; |
238 | 278 | ||
239 | memset(&call, 0, sizeof(call)); |
279 | memset(&call, 0, sizeof(call)); |
240 | rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
280 | rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
241 | 281 | ||
242 | if (rc >= 0) { |
282 | if (rc >= 0) { |
243 | ipcp_call_out(sc_args[0], &call, sc_rc); |
283 | ipcp_call_out(sc_args[0], &call, sc_rc); |
244 | } |
284 | } |
245 | } |
285 | } |
246 | 286 | ||
247 | static void sc_ipc_call_sync_fast(sysarg_t *sc_args) |
287 | static void sc_ipc_call_sync_fast(sysarg_t *sc_args) |
248 | { |
288 | { |
249 | ipc_call_t question, reply; |
289 | ipc_call_t question, reply; |
250 | int rc; |
290 | int rc; |
251 | int phoneidx; |
291 | int phoneidx; |
252 | 292 | ||
253 | // printf("sc_ipc_call_sync_fast()\n"); |
293 | // printf("sc_ipc_call_sync_fast()\n"); |
254 | phoneidx = sc_args[0]; |
294 | phoneidx = sc_args[0]; |
255 | 295 | ||
256 | IPC_SET_METHOD(question, sc_args[1]); |
296 | IPC_SET_METHOD(question, sc_args[1]); |
257 | IPC_SET_ARG1(question, sc_args[2]); |
297 | IPC_SET_ARG1(question, sc_args[2]); |
258 | IPC_SET_ARG2(question, sc_args[3]); |
298 | IPC_SET_ARG2(question, sc_args[3]); |
259 | IPC_SET_ARG3(question, sc_args[4]); |
299 | IPC_SET_ARG3(question, sc_args[4]); |
260 | IPC_SET_ARG4(question, 0); |
300 | IPC_SET_ARG4(question, 0); |
261 | IPC_SET_ARG5(question, 0); |
301 | IPC_SET_ARG5(question, 0); |
262 | 302 | ||
263 | // printf("memset\n"); |
303 | // printf("memset\n"); |
264 | memset(&reply, 0, sizeof(reply)); |
304 | memset(&reply, 0, sizeof(reply)); |
265 | // printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", |
305 | // printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", |
266 | // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
306 | // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
267 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
307 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); |
268 | // printf("dmr->%d\n", rc); |
308 | // printf("dmr->%d\n", rc); |
269 | if (rc < 0) return; |
309 | if (rc < 0) return; |
270 | 310 | ||
271 | // printf("call ipc_call_sync\n"); |
311 | // printf("call ipc_call_sync\n"); |
272 | ipcp_call_sync(phoneidx, &question, &reply); |
312 | ipcp_call_sync(phoneidx, &question, &reply); |
273 | } |
313 | } |
274 | 314 | ||
275 | static void sc_ipc_call_sync_slow(sysarg_t *sc_args) |
315 | static void sc_ipc_call_sync_slow(sysarg_t *sc_args) |
276 | { |
316 | { |
277 | ipc_call_t question, reply; |
317 | ipc_call_t question, reply; |
278 | int rc; |
318 | int rc; |
279 | 319 | ||
280 | memset(&question, 0, sizeof(question)); |
320 | memset(&question, 0, sizeof(question)); |
281 | rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
321 | rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
282 | printf("dmr->%d\n", rc); |
322 | printf("dmr->%d\n", rc); |
283 | if (rc < 0) return; |
323 | if (rc < 0) return; |
284 | 324 | ||
285 | memset(&reply, 0, sizeof(reply)); |
325 | memset(&reply, 0, sizeof(reply)); |
286 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
326 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
287 | printf("dmr->%d\n", rc); |
327 | printf("dmr->%d\n", rc); |
288 | if (rc < 0) return; |
328 | if (rc < 0) return; |
289 | 329 | ||
290 | ipcp_call_sync(sc_args[0], &question, &reply); |
330 | ipcp_call_sync(sc_args[0], &question, &reply); |
291 | } |
331 | } |
292 | 332 | ||
293 | static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc) |
333 | static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc) |
294 | { |
334 | { |
295 | ipc_call_t call; |
335 | ipc_call_t call; |
296 | int rc; |
336 | int rc; |
297 | 337 | ||
298 | if (sc_rc == 0) return; |
338 | if (sc_rc == 0) return; |
299 | 339 | ||
300 | memset(&call, 0, sizeof(call)); |
340 | memset(&call, 0, sizeof(call)); |
301 | rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); |
341 | rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); |
302 | // printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", |
342 | // printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", |
303 | // phoneid, (int)&call, sc_args[0], sizeof(call), rc); |
343 | // phoneid, (int)&call, sc_args[0], sizeof(call), rc); |
304 | 344 | ||
305 | if (rc >= 0) { |
345 | if (rc >= 0) { |
306 | ipcp_call_in(&call, sc_rc); |
346 | ipcp_call_in(&call, sc_rc); |
307 | } |
347 | } |
308 | } |
348 | } |
309 | 349 | ||
310 | static void event_syscall_b(unsigned thread_id, uintptr_t thread_hash, |
350 | static void event_syscall_b(unsigned thread_id, uintptr_t thread_hash, |
311 | unsigned sc_id, sysarg_t sc_rc) |
351 | unsigned sc_id, sysarg_t sc_rc) |
312 | { |
352 | { |
313 | sysarg_t sc_args[6]; |
353 | sysarg_t sc_args[6]; |
314 | int rc; |
354 | int rc; |
315 | 355 | ||
316 | /* Read syscall arguments */ |
356 | /* Read syscall arguments */ |
317 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
357 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
318 | 358 | ||
319 | async_serialize_start(); |
359 | async_serialize_start(); |
320 | 360 | ||
321 | // printf("[%d] ", thread_id); |
361 | // printf("[%d] ", thread_id); |
322 | 362 | ||
323 | if (rc < 0) { |
363 | if (rc < 0) { |
324 | printf("error\n"); |
364 | printf("error\n"); |
325 | async_serialize_end(); |
365 | async_serialize_end(); |
326 | return; |
366 | return; |
327 | } |
367 | } |
328 | 368 | ||
329 | if ((display_mask & DM_SYSCALL) != 0) { |
369 | if ((display_mask & DM_SYSCALL) != 0) { |
330 | /* Print syscall name and arguments */ |
370 | /* Print syscall name and arguments */ |
331 | printf("%s", syscall_desc[sc_id].name); |
371 | printf("%s", syscall_desc[sc_id].name); |
332 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
372 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
333 | } |
373 | } |
334 | 374 | ||
335 | async_serialize_end(); |
375 | async_serialize_end(); |
336 | } |
376 | } |
337 | 377 | ||
338 | static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash, |
378 | static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash, |
339 | unsigned sc_id, sysarg_t sc_rc) |
379 | unsigned sc_id, sysarg_t sc_rc) |
340 | { |
380 | { |
341 | sysarg_t sc_args[6]; |
381 | sysarg_t sc_args[6]; |
342 | int rv_type; |
382 | int rv_type; |
343 | int rc; |
383 | int rc; |
344 | 384 | ||
345 | /* Read syscall arguments */ |
385 | /* Read syscall arguments */ |
346 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
386 | rc = udebug_args_read(phoneid, thread_hash, sc_args); |
347 | 387 | ||
348 | async_serialize_start(); |
388 | async_serialize_start(); |
349 | 389 | ||
350 | // printf("[%d] ", thread_id); |
390 | // printf("[%d] ", thread_id); |
351 | 391 | ||
352 | if (rc < 0) { |
392 | if (rc < 0) { |
353 | printf("error\n"); |
393 | printf("error\n"); |
354 | async_serialize_end(); |
394 | async_serialize_end(); |
355 | return; |
395 | return; |
356 | } |
396 | } |
357 | 397 | ||
358 | if ((display_mask & DM_SYSCALL) != 0) { |
398 | if ((display_mask & DM_SYSCALL) != 0) { |
359 | /* Print syscall return value */ |
399 | /* Print syscall return value */ |
360 | rv_type = syscall_desc[sc_id].rv_type; |
400 | rv_type = syscall_desc[sc_id].rv_type; |
361 | print_sc_retval(sc_rc, rv_type); |
401 | print_sc_retval(sc_rc, rv_type); |
362 | } |
402 | } |
363 | 403 | ||
364 | switch (sc_id) { |
404 | switch (sc_id) { |
365 | case SYS_IPC_CALL_ASYNC_FAST: |
405 | case SYS_IPC_CALL_ASYNC_FAST: |
366 | sc_ipc_call_async_fast(sc_args, sc_rc); |
406 | sc_ipc_call_async_fast(sc_args, sc_rc); |
367 | break; |
407 | break; |
368 | case SYS_IPC_CALL_ASYNC_SLOW: |
408 | case SYS_IPC_CALL_ASYNC_SLOW: |
369 | sc_ipc_call_async_slow(sc_args, sc_rc); |
409 | sc_ipc_call_async_slow(sc_args, sc_rc); |
370 | break; |
410 | break; |
371 | case SYS_IPC_CALL_SYNC_FAST: |
411 | case SYS_IPC_CALL_SYNC_FAST: |
372 | sc_ipc_call_sync_fast(sc_args); |
412 | sc_ipc_call_sync_fast(sc_args); |
373 | break; |
413 | break; |
374 | case SYS_IPC_CALL_SYNC_SLOW: |
414 | case SYS_IPC_CALL_SYNC_SLOW: |
375 | sc_ipc_call_sync_slow(sc_args); |
415 | sc_ipc_call_sync_slow(sc_args); |
376 | break; |
416 | break; |
377 | case SYS_IPC_WAIT: |
417 | case SYS_IPC_WAIT: |
378 | sc_ipc_wait(sc_args, sc_rc); |
418 | sc_ipc_wait(sc_args, sc_rc); |
379 | break; |
419 | break; |
380 | default: |
420 | default: |
381 | break; |
421 | break; |
382 | } |
422 | } |
383 | 423 | ||
384 | async_serialize_end(); |
424 | async_serialize_end(); |
385 | } |
425 | } |
386 | 426 | ||
387 | static void event_thread_b(uintptr_t hash) |
427 | static void event_thread_b(uintptr_t hash) |
388 | { |
428 | { |
389 | async_serialize_start(); |
429 | async_serialize_start(); |
390 | printf("New thread, hash 0x%lx\n", hash); |
430 | printf("New thread, hash 0x%lx\n", hash); |
391 | async_serialize_end(); |
431 | async_serialize_end(); |
392 | 432 | ||
393 | thread_trace_start(hash); |
433 | thread_trace_start(hash); |
394 | } |
434 | } |
395 | 435 | ||
396 | static int trace_loop(void *thread_hash_arg) |
436 | static int trace_loop(void *thread_hash_arg) |
397 | { |
437 | { |
398 | int rc; |
438 | int rc; |
399 | unsigned ev_type; |
439 | unsigned ev_type; |
400 | uintptr_t thread_hash; |
440 | uintptr_t thread_hash; |
401 | unsigned thread_id; |
441 | unsigned thread_id; |
402 | sysarg_t val0, val1; |
442 | sysarg_t val0, val1; |
403 | 443 | ||
404 | thread_hash = (uintptr_t)thread_hash_arg; |
444 | thread_hash = (uintptr_t)thread_hash_arg; |
405 | thread_id = next_thread_id++; |
445 | thread_id = next_thread_id++; |
406 | 446 | ||
407 | printf("Start tracing thread [%d] (hash 0x%lx)\n", thread_id, thread_hash); |
447 | printf("Start tracing thread [%d] (hash 0x%lx)\n", thread_id, thread_hash); |
408 | 448 | ||
409 | while (!abort_trace) { |
449 | while (!abort_trace) { |
410 | 450 | ||
411 | /* Run thread until an event occurs */ |
451 | /* Run thread until an event occurs */ |
412 | rc = udebug_go(phoneid, thread_hash, |
452 | rc = udebug_go(phoneid, thread_hash, |
413 | &ev_type, &val0, &val1); |
453 | &ev_type, &val0, &val1); |
414 | 454 | ||
415 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
455 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
416 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
456 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
417 | /* Done tracing this thread */ |
457 | /* Done tracing this thread */ |
418 | break; |
458 | break; |
419 | } |
459 | } |
420 | 460 | ||
421 | if (rc >= 0) { |
461 | if (rc >= 0) { |
422 | switch (ev_type) { |
462 | switch (ev_type) { |
423 | case UDEBUG_EVENT_SYSCALL_B: |
463 | case UDEBUG_EVENT_SYSCALL_B: |
424 | event_syscall_b(thread_id, thread_hash, val0, (int)val1); |
464 | event_syscall_b(thread_id, thread_hash, val0, (int)val1); |
425 | break; |
465 | break; |
426 | case UDEBUG_EVENT_SYSCALL_E: |
466 | case UDEBUG_EVENT_SYSCALL_E: |
427 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
467 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
428 | break; |
468 | break; |
429 | case UDEBUG_EVENT_STOP: |
469 | case UDEBUG_EVENT_STOP: |
430 | printf("Stop event\n"); |
470 | printf("Stop event\n"); |
431 | printf("Waiting for resume\n"); |
471 | printf("Waiting for resume\n"); |
432 | while (paused) { |
472 | while (paused) { |
433 | usleep(1000000); |
473 | usleep(1000000); |
434 | fibril_yield(); |
474 | fibril_yield(); |
435 | printf("."); |
475 | printf("."); |
436 | } |
476 | } |
437 | printf("Resumed\n"); |
477 | printf("Resumed\n"); |
438 | break; |
478 | break; |
439 | case UDEBUG_EVENT_THREAD_B: |
479 | case UDEBUG_EVENT_THREAD_B: |
440 | event_thread_b(val0); |
480 | event_thread_b(val0); |
441 | break; |
481 | break; |
442 | case UDEBUG_EVENT_THREAD_E: |
482 | case UDEBUG_EVENT_THREAD_E: |
443 | printf("Thread 0x%lx exited\n", val0); |
483 | printf("Thread 0x%lx exited\n", val0); |
444 | abort_trace = 1; |
484 | abort_trace = 1; |
445 | break; |
485 | break; |
446 | default: |
486 | default: |
447 | printf("Unknown event type %d\n", ev_type); |
487 | printf("Unknown event type %d\n", ev_type); |
448 | break; |
488 | break; |
449 | } |
489 | } |
450 | } |
490 | } |
451 | 491 | ||
452 | } |
492 | } |
453 | 493 | ||
454 | printf("Finished tracing thread [%d]\n", thread_id); |
494 | printf("Finished tracing thread [%d]\n", thread_id); |
455 | return 0; |
495 | return 0; |
456 | } |
496 | } |
457 | 497 | ||
458 | void thread_trace_start(uintptr_t thread_hash) |
498 | void thread_trace_start(uintptr_t thread_hash) |
459 | { |
499 | { |
460 | fid_t fid; |
500 | fid_t fid; |
461 | 501 | ||
462 | thash = thread_hash; |
502 | thash = thread_hash; |
463 | 503 | ||
464 | fid = fibril_create(trace_loop, (void *)thread_hash); |
504 | fid = fibril_create(trace_loop, (void *)thread_hash); |
465 | if (fid == 0) { |
505 | if (fid == 0) { |
466 | printf("Warning: Failed creating fibril\n"); |
506 | printf("Warning: Failed creating fibril\n"); |
467 | } |
507 | } |
468 | fibril_add_ready(fid); |
508 | fibril_add_ready(fid); |
469 | } |
509 | } |
470 | 510 | ||
- | 511 | static loader_t *preload_task(const char *path, char *const argv[], |
|
471 | static void trace_active_task(task_id_t task_id) |
512 | task_id_t *task_id) |
472 | { |
513 | { |
473 | int i; |
514 | loader_t *ldr; |
474 | int rc; |
515 | int rc; |
475 | int c; |
- | |
476 | 516 | ||
- | 517 | /* Spawn a program loader */ |
|
- | 518 | ldr = loader_spawn(); |
|
- | 519 | if (ldr == NULL) |
|
- | 520 | return 0; |
|
- | 521 | ||
- | 522 | /* Get task ID. */ |
|
477 | rc = task_connect(task_id); |
523 | rc = loader_get_task_id(ldr, task_id); |
478 | if (rc < 0) { |
524 | if (rc != EOK) |
- | 525 | goto error; |
|
- | 526 | ||
- | 527 | /* Send program pathname */ |
|
479 | printf("Failed to connect to task %lld\n", task_id); |
528 | rc = loader_set_pathname(ldr, path); |
- | 529 | if (rc != EOK) |
|
- | 530 | goto error; |
|
- | 531 | ||
- | 532 | /* Send arguments */ |
|
- | 533 | rc = loader_set_args(ldr, argv); |
|
- | 534 | if (rc != EOK) |
|
- | 535 | goto error; |
|
- | 536 | ||
- | 537 | /* Load the program. */ |
|
- | 538 | rc = loader_load_program(ldr); |
|
- | 539 | if (rc != EOK) |
|
- | 540 | goto error; |
|
- | 541 | ||
- | 542 | /* Success */ |
|
480 | return; |
543 | return ldr; |
- | 544 | ||
- | 545 | /* Error exit */ |
|
- | 546 | error: |
|
- | 547 | loader_abort(ldr); |
|
- | 548 | free(ldr); |
|
- | 549 | return NULL; |
|
481 | } |
550 | } |
482 | 551 | ||
483 | printf("Connected to task %lld\n", task_id); |
552 | static void trace_task(task_id_t task_id) |
- | 553 | { |
|
- | 554 | int i; |
|
- | 555 | int rc; |
|
- | 556 | int c; |
|
484 | 557 | ||
485 | ipcp_init(); |
558 | ipcp_init(); |
486 | 559 | ||
487 | /* |
560 | /* |
488 | * User apps now typically have console on phone 3. |
561 | * User apps now typically have console on phone 3. |
489 | * (Phones 1 and 2 are used by the loader). |
562 | * (Phones 1 and 2 are used by the loader). |
490 | */ |
563 | */ |
491 | ipcp_connection_set(3, 0, proto_console); |
564 | ipcp_connection_set(3, 0, proto_console); |
492 | 565 | ||
493 | rc = get_thread_list(); |
566 | rc = get_thread_list(); |
494 | if (rc < 0) { |
567 | if (rc < 0) { |
495 | printf("Failed to get thread list (error %d)\n", rc); |
568 | printf("Failed to get thread list (error %d)\n", rc); |
496 | return; |
569 | return; |
497 | } |
570 | } |
498 | 571 | ||
499 | abort_trace = 0; |
572 | abort_trace = 0; |
500 | 573 | ||
501 | for (i = 0; i < n_threads; i++) { |
574 | for (i = 0; i < n_threads; i++) { |
502 | thread_trace_start(thread_hash_buf[i]); |
575 | thread_trace_start(thread_hash_buf[i]); |
503 | } |
576 | } |
504 | 577 | ||
505 | while(1) { |
578 | while(1) { |
506 | c = getchar(); |
579 | c = getchar(); |
507 | if (c == 'q') break; |
580 | if (c == 'q') break; |
508 | if (c == 'p') { |
581 | if (c == 'p') { |
509 | paused = 1; |
582 | paused = 1; |
510 | rc = udebug_stop(phoneid, thash); |
583 | rc = udebug_stop(phoneid, thash); |
511 | printf("stop -> %d\n", rc); |
584 | printf("stop -> %d\n", rc); |
512 | } |
585 | } |
513 | if (c == 'r') { |
586 | if (c == 'r') { |
514 | paused = 0; |
587 | paused = 0; |
515 | } |
588 | } |
516 | } |
589 | } |
517 | 590 | ||
518 | printf("\nTerminate debugging session...\n"); |
591 | printf("\nTerminate debugging session...\n"); |
519 | abort_trace = 1; |
592 | abort_trace = 1; |
520 | udebug_end(phoneid); |
593 | udebug_end(phoneid); |
521 | ipc_hangup(phoneid); |
594 | ipc_hangup(phoneid); |
522 | 595 | ||
523 | ipcp_cleanup(); |
596 | ipcp_cleanup(); |
524 | 597 | ||
525 | printf("Done\n"); |
598 | printf("Done\n"); |
526 | return; |
599 | return; |
527 | } |
600 | } |
528 | 601 | ||
529 | static void main_init(void) |
602 | static void main_init(void) |
530 | { |
603 | { |
531 | proto_t *p; |
604 | proto_t *p; |
532 | oper_t *o; |
605 | oper_t *o; |
533 | 606 | ||
534 | val_type_t arg_def[OPER_MAX_ARGS] = { |
607 | val_type_t arg_def[OPER_MAX_ARGS] = { |
535 | V_INTEGER, |
608 | V_INTEGER, |
536 | V_INTEGER, |
609 | V_INTEGER, |
537 | V_INTEGER, |
610 | V_INTEGER, |
538 | V_INTEGER, |
611 | V_INTEGER, |
539 | V_INTEGER |
612 | V_INTEGER |
540 | }; |
613 | }; |
541 | 614 | ||
542 | val_type_t resp_def[OPER_MAX_ARGS] = { |
615 | val_type_t resp_def[OPER_MAX_ARGS] = { |
543 | V_INTEGER, |
616 | V_INTEGER, |
544 | V_INTEGER, |
617 | V_INTEGER, |
545 | V_INTEGER, |
618 | V_INTEGER, |
546 | V_INTEGER, |
619 | V_INTEGER, |
547 | V_INTEGER |
620 | V_INTEGER |
548 | }; |
621 | }; |
549 | 622 | ||
550 | next_thread_id = 1; |
623 | next_thread_id = 1; |
551 | paused = 0; |
624 | paused = 0; |
552 | 625 | ||
553 | proto_init(); |
626 | proto_init(); |
554 | 627 | ||
555 | p = proto_new("vfs"); |
628 | p = proto_new("vfs"); |
556 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
629 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
557 | proto_add_oper(p, VFS_READ, o); |
630 | proto_add_oper(p, VFS_READ, o); |
558 | o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
631 | o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
559 | proto_add_oper(p, VFS_WRITE, o); |
632 | proto_add_oper(p, VFS_WRITE, o); |
560 | o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); |
633 | o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); |
561 | proto_add_oper(p, VFS_TRUNCATE, o); |
634 | proto_add_oper(p, VFS_TRUNCATE, o); |
562 | o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def); |
635 | o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def); |
563 | proto_add_oper(p, VFS_MOUNT, o); |
636 | proto_add_oper(p, VFS_MOUNT, o); |
564 | /* o = oper_new("unmount", 0, arg_def); |
637 | /* o = oper_new("unmount", 0, arg_def); |
565 | proto_add_oper(p, VFS_UNMOUNT, o);*/ |
638 | proto_add_oper(p, VFS_UNMOUNT, o);*/ |
566 | 639 | ||
567 | proto_register(SERVICE_VFS, p); |
640 | proto_register(SERVICE_VFS, p); |
568 | 641 | ||
569 | p = proto_new("console"); |
642 | p = proto_new("console"); |
570 | resp_def[0] = V_CHAR; |
643 | resp_def[0] = V_CHAR; |
571 | o = oper_new("getchar", 0, arg_def, V_INTEGER, 2, resp_def); |
644 | o = oper_new("getchar", 0, arg_def, V_INTEGER, 2, resp_def); |
572 | proto_add_oper(p, CONSOLE_GETCHAR, o); |
645 | proto_add_oper(p, CONSOLE_GETCHAR, o); |
573 | 646 | ||
574 | arg_def[0] = V_CHAR; |
647 | arg_def[0] = V_CHAR; |
575 | o = oper_new("putchar", 1, arg_def, V_VOID, 0, resp_def); |
648 | o = oper_new("putchar", 1, arg_def, V_VOID, 0, resp_def); |
576 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
649 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
577 | o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def); |
650 | o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def); |
578 | proto_add_oper(p, CONSOLE_CLEAR, o); |
651 | proto_add_oper(p, CONSOLE_CLEAR, o); |
579 | 652 | ||
580 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; |
653 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; |
581 | o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def); |
654 | o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def); |
582 | proto_add_oper(p, CONSOLE_GOTO, o); |
655 | proto_add_oper(p, CONSOLE_GOTO, o); |
583 | 656 | ||
584 | resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
657 | resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
585 | o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def); |
658 | o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def); |
586 | proto_add_oper(p, CONSOLE_GETSIZE, o); |
659 | proto_add_oper(p, CONSOLE_GETSIZE, o); |
587 | o = oper_new("flush", 0, arg_def, V_VOID, 0, resp_def); |
660 | o = oper_new("flush", 0, arg_def, V_VOID, 0, resp_def); |
588 | proto_add_oper(p, CONSOLE_FLUSH, o); |
661 | proto_add_oper(p, CONSOLE_FLUSH, o); |
589 | 662 | ||
590 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; |
663 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; |
591 | o = oper_new("set_style", 2, arg_def, V_INTEGER, 0, resp_def); |
664 | o = oper_new("set_style", 2, arg_def, V_INTEGER, 0, resp_def); |
592 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
665 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
593 | o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def); |
666 | o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def); |
594 | proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o); |
667 | proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o); |
595 | 668 | ||
596 | proto_console = p; |
669 | proto_console = p; |
597 | proto_register(SERVICE_CONSOLE, p); |
670 | proto_register(SERVICE_CONSOLE, p); |
598 | } |
671 | } |
599 | 672 | ||
600 | static void print_syntax() |
673 | static void print_syntax() |
601 | { |
674 | { |
602 | printf("Syntax:\n"); |
675 | printf("Syntax:\n"); |
603 | printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n"); |
676 | printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n"); |
604 | printf("or\ttrace [+<events>] -t <task_id>\n"); |
677 | printf("or\ttrace [+<events>] -t <task_id>\n"); |
605 | printf("Events: (default is +tp)\n"); |
678 | printf("Events: (default is +tp)\n"); |
606 | printf("\n"); |
679 | printf("\n"); |
607 | printf("\tt ... Thread creation and termination\n"); |
680 | printf("\tt ... Thread creation and termination\n"); |
608 | printf("\ts ... System calls\n"); |
681 | printf("\ts ... System calls\n"); |
609 | printf("\ti ... Low-level IPC\n"); |
682 | printf("\ti ... Low-level IPC\n"); |
610 | printf("\tp ... Protocol level\n"); |
683 | printf("\tp ... Protocol level\n"); |
611 | printf("\n"); |
684 | printf("\n"); |
612 | printf("Examples:\n"); |
685 | printf("Examples:\n"); |
613 | printf("\ttrace +s /app/tetris\n"); |
686 | printf("\ttrace +s /app/tetris\n"); |
614 | printf("\ttrace +tsip -t 12\n"); |
687 | printf("\ttrace +tsip -t 12\n"); |
615 | } |
688 | } |
616 | 689 | ||
617 | static display_mask_t parse_display_mask(char *text) |
690 | static display_mask_t parse_display_mask(char *text) |
618 | { |
691 | { |
619 | display_mask_t dm; |
692 | display_mask_t dm; |
620 | char *c; |
693 | char *c; |
621 | 694 | ||
622 | c = text; |
695 | c = text; |
623 | 696 | ||
624 | while (*c) { |
697 | while (*c) { |
625 | switch (*c) { |
698 | switch (*c) { |
626 | case 't': dm = dm | DM_THREAD; break; |
699 | case 't': dm = dm | DM_THREAD; break; |
627 | case 's': dm = dm | DM_SYSCALL; break; |
700 | case 's': dm = dm | DM_SYSCALL; break; |
628 | case 'i': dm = dm | DM_IPC; break; |
701 | case 'i': dm = dm | DM_IPC; break; |
629 | case 'p': dm = dm | DM_SYSTEM | DM_USER; break; |
702 | case 'p': dm = dm | DM_SYSTEM | DM_USER; break; |
630 | default: |
703 | default: |
631 | printf("Unexpected event type '%c'\n", *c); |
704 | printf("Unexpected event type '%c'\n", *c); |
632 | exit(1); |
705 | exit(1); |
633 | } |
706 | } |
634 | 707 | ||
635 | ++c; |
708 | ++c; |
636 | } |
709 | } |
637 | 710 | ||
638 | return dm; |
711 | return dm; |
639 | } |
712 | } |
640 | 713 | ||
641 | static int parse_args(int argc, char *argv[]) |
714 | static int parse_args(int argc, char *argv[]) |
642 | { |
715 | { |
643 | char *arg; |
716 | char *arg; |
644 | char *err_p; |
717 | char *err_p; |
645 | 718 | ||
646 | task_id = 0; |
719 | task_id = 0; |
647 | 720 | ||
648 | --argc; ++argv; |
721 | --argc; ++argv; |
649 | 722 | ||
650 | while (argc > 0) { |
723 | while (argc > 0) { |
651 | arg = *argv; |
724 | arg = *argv; |
652 | if (arg[0] == '+') { |
725 | if (arg[0] == '+') { |
653 | display_mask = parse_display_mask(&arg[1]); |
726 | display_mask = parse_display_mask(&arg[1]); |
654 | } else if (arg[0] == '-') { |
727 | } else if (arg[0] == '-') { |
655 | if (arg[1] == 't') { |
728 | if (arg[1] == 't') { |
656 | /* Trace an already running task */ |
729 | /* Trace an already running task */ |
657 | --argc; ++argv; |
730 | --argc; ++argv; |
658 | task_id = strtol(*argv, &err_p, 10); |
731 | task_id = strtol(*argv, &err_p, 10); |
- | 732 | task_ldr = NULL; |
|
659 | if (*err_p) { |
733 | if (*err_p) { |
660 | printf("Task ID syntax error\n"); |
734 | printf("Task ID syntax error\n"); |
661 | print_syntax(); |
735 | print_syntax(); |
662 | return -1; |
736 | return -1; |
663 | } |
737 | } |
664 | } else { |
738 | } else { |
665 | printf("Uknown option '%s'\n", arg[0]); |
739 | printf("Uknown option '%s'\n", arg[0]); |
666 | print_syntax(); |
740 | print_syntax(); |
667 | return -1; |
741 | return -1; |
668 | } |
742 | } |
669 | } else { |
743 | } else { |
670 | break; |
744 | break; |
671 | } |
745 | } |
672 | 746 | ||
673 | --argc; ++argv; |
747 | --argc; ++argv; |
674 | } |
748 | } |
675 | 749 | ||
676 | if (task_id != 0) { |
750 | if (task_id != 0) { |
677 | if (argc == 0) return 0; |
751 | if (argc == 0) return 0; |
678 | printf("Extra arguments\n"); |
752 | printf("Extra arguments\n"); |
679 | print_syntax(); |
753 | print_syntax(); |
680 | return -1; |
754 | return -1; |
681 | } |
755 | } |
682 | 756 | ||
683 | if (argc < 1) { |
757 | if (argc < 1) { |
684 | printf("Missing argument\n"); |
758 | printf("Missing argument\n"); |
685 | print_syntax(); |
759 | print_syntax(); |
686 | return -1; |
760 | return -1; |
687 | } |
761 | } |
688 | 762 | ||
689 | /* Execute the specified command and trace the new task. */ |
763 | /* Preload the specified program file. */ |
690 | printf("Spawning '%s' with arguments:\n", *argv); |
764 | printf("Spawning '%s' with arguments:\n", *argv); |
691 | { |
765 | { |
692 | char **cp = argv; |
766 | char **cp = argv; |
693 | while (*cp) printf("'%s'\n", *cp++); |
767 | while (*cp) printf("'%s'\n", *cp++); |
694 | } |
768 | } |
695 | task_id = task_spawn(*argv, argv); |
769 | task_ldr = preload_task(*argv, argv, &task_id); |
696 | 770 | ||
697 | return 0; |
771 | return 0; |
698 | } |
772 | } |
699 | 773 | ||
700 | int main(int argc, char *argv[]) |
774 | int main(int argc, char *argv[]) |
701 | { |
775 | { |
- | 776 | int rc; |
|
- | 777 | ||
702 | printf("System Call / IPC Tracer\n"); |
778 | printf("System Call / IPC Tracer\n"); |
703 | 779 | ||
704 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
780 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
705 | 781 | ||
706 | if (parse_args(argc, argv) < 0) |
782 | if (parse_args(argc, argv) < 0) |
707 | return 1; |
783 | return 1; |
708 | 784 | ||
709 | main_init(); |
785 | main_init(); |
- | 786 | ||
- | 787 | rc = connect_task(task_id); |
|
- | 788 | if (rc < 0) { |
|
- | 789 | printf("Failed connecting to task %lld\n", task_id); |
|
- | 790 | return 1; |
|
- | 791 | } |
|
- | 792 | ||
- | 793 | printf("Connected to task %lld\n", task_id); |
|
- | 794 | ||
- | 795 | if (task_ldr != NULL) { |
|
- | 796 | program_run(); |
|
- | 797 | } |
|
- | 798 | ||
710 | trace_active_task(task_id); |
799 | trace_task(task_id); |
711 | 800 | ||
712 | return 0; |
801 | return 0; |
713 | } |
802 | } |
714 | 803 | ||
715 | /** @} |
804 | /** @} |
716 | */ |
805 | */ |
717 | 806 |