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