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