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