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