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