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