Rev 3442 | Rev 3447 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3442 | Rev 3444 | ||
|---|---|---|---|
| Line 49... | Line 49... | ||
| 49 | #include "../../srv/console/console.h" |
49 | #include "../../srv/console/console.h" |
| 50 | 50 | ||
| 51 | #include "syscalls.h" |
51 | #include "syscalls.h" |
| 52 | #include "ipcp.h" |
52 | #include "ipcp.h" |
| 53 | #include "errors.h" |
53 | #include "errors.h" |
| - | 54 | #include "trace.h" |
|
| 54 | 55 | ||
| 55 | #define THBUF_SIZE 64 |
56 | #define THBUF_SIZE 64 |
| 56 | unsigned thread_hash_buf[THBUF_SIZE]; |
57 | unsigned thread_hash_buf[THBUF_SIZE]; |
| 57 | unsigned n_threads; |
58 | unsigned n_threads; |
| 58 | 59 | ||
| Line 65... | Line 66... | ||
| 65 | volatile int paused; |
66 | volatile int paused; |
| 66 | 67 | ||
| 67 | void thread_trace_start(unsigned thread_hash); |
68 | void thread_trace_start(unsigned thread_hash); |
| 68 | 69 | ||
| 69 | static proto_t *proto_console; |
70 | static proto_t *proto_console; |
| - | 71 | static task_id_t task_id; |
|
| - | 72 | ||
| - | 73 | /** Combination of events/data to print. */ |
|
| - | 74 | display_mask_t display_mask; |
|
| 70 | 75 | ||
| 71 | static int task_connect(task_id_t task_id) |
76 | static int task_connect(task_id_t task_id) |
| 72 | { |
77 | { |
| 73 | int rc; |
78 | int rc; |
| 74 | 79 | ||
| Line 284... | Line 289... | ||
| 284 | printf("error\n"); |
289 | printf("error\n"); |
| 285 | async_serialize_end(); |
290 | async_serialize_end(); |
| 286 | return; |
291 | return; |
| 287 | } |
292 | } |
| 288 | 293 | ||
| - | 294 | if ((display_mask & DM_SYSCALL) != 0) { |
|
| 289 | /* Print syscall name, id and arguments */ |
295 | /* Print syscall name and arguments */ |
| 290 | printf("%s", syscall_desc[sc_id].name); |
296 | printf("%s", syscall_desc[sc_id].name); |
| 291 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
297 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
| - | 298 | } |
|
| 292 | 299 | ||
| 293 | async_serialize_end(); |
300 | async_serialize_end(); |
| 294 | } |
301 | } |
| 295 | 302 | ||
| 296 | static void event_syscall_e(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
303 | static void event_syscall_e(unsigned thread_id, unsigned thread_hash, unsigned sc_id, int sc_rc) |
| Line 310... | Line 317... | ||
| 310 | printf("error\n"); |
317 | printf("error\n"); |
| 311 | async_serialize_end(); |
318 | async_serialize_end(); |
| 312 | return; |
319 | return; |
| 313 | } |
320 | } |
| 314 | 321 | ||
| - | 322 | if ((display_mask & DM_SYSCALL) != 0) { |
|
| - | 323 | /* Print syscall return value */ |
|
| 315 | rv_type = syscall_desc[sc_id].rv_type; |
324 | rv_type = syscall_desc[sc_id].rv_type; |
| 316 | print_sc_retval(sc_rc, rv_type); |
325 | print_sc_retval(sc_rc, rv_type); |
| - | 326 | } |
|
| 317 | 327 | ||
| 318 | switch (sc_id) { |
328 | switch (sc_id) { |
| 319 | case SYS_IPC_CALL_ASYNC_FAST: |
329 | case SYS_IPC_CALL_ASYNC_FAST: |
| 320 | sc_ipc_call_async_fast(sc_args, sc_rc); |
330 | sc_ipc_call_async_fast(sc_args, sc_rc); |
| 321 | break; |
331 | break; |
| Line 426... | Line 436... | ||
| 426 | { |
436 | { |
| 427 | int i; |
437 | int i; |
| 428 | int rc; |
438 | int rc; |
| 429 | int c; |
439 | int c; |
| 430 | 440 | ||
| 431 | printf("Syscall Tracer\n"); |
- | |
| 432 | - | ||
| 433 | rc = task_connect(task_id); |
441 | rc = task_connect(task_id); |
| 434 | if (rc < 0) { |
442 | if (rc < 0) { |
| 435 | printf("Failed to connect to task %lld\n", task_id); |
443 | printf("Failed to connect to task %lld\n", task_id); |
| 436 | return; |
444 | return; |
| 437 | } |
445 | } |
| Line 530... | Line 538... | ||
| 530 | proto_register(SERVICE_CONSOLE, p); |
538 | proto_register(SERVICE_CONSOLE, p); |
| 531 | } |
539 | } |
| 532 | 540 | ||
| 533 | static void print_syntax() |
541 | static void print_syntax() |
| 534 | { |
542 | { |
| 535 | printf("Syntax: trace <task_id>\n"); |
543 | printf("Syntax: trace [+<events>] <task_id>\n"); |
| - | 544 | printf("Events: (default is +tp)\n"); |
|
| - | 545 | printf("\n"); |
|
| - | 546 | printf("\tt ... Thread creation and termination\n"); |
|
| - | 547 | printf("\ts ... System calls\n"); |
|
| - | 548 | printf("\ti ... Low-level IPC\n"); |
|
| - | 549 | printf("\tp ... Protocol level\n"); |
|
| - | 550 | printf("\n"); |
|
| - | 551 | printf("Example: trace +tsip 12\n"); |
|
| - | 552 | } |
|
| - | 553 | ||
| - | 554 | static display_mask_t parse_display_mask(char *text) |
|
| - | 555 | { |
|
| - | 556 | display_mask_t dm; |
|
| - | 557 | char *c; |
|
| - | 558 | ||
| - | 559 | c = text; |
|
| - | 560 | ||
| - | 561 | while (*c) { |
|
| - | 562 | switch (*c) { |
|
| - | 563 | case 't': dm = dm | DM_THREAD; break; |
|
| - | 564 | case 's': dm = dm | DM_SYSCALL; break; |
|
| - | 565 | case 'i': dm = dm | DM_IPC; break; |
|
| - | 566 | case 'p': dm = dm | DM_SYSTEM | DM_USER; break; |
|
| - | 567 | default: |
|
| - | 568 | printf("Unexpected event type '%c'\n", *c); |
|
| - | 569 | exit(1); |
|
| - | 570 | } |
|
| - | 571 | ||
| - | 572 | ++c; |
|
| - | 573 | } |
|
| - | 574 | ||
| - | 575 | return dm; |
|
| 536 | } |
576 | } |
| 537 | 577 | ||
| 538 | int main(int argc, char *argv[]) |
578 | static int parse_args(int argc, char *argv[]) |
| 539 | { |
579 | { |
| 540 | task_id_t task_id; |
580 | char *arg; |
| 541 | char *err_p; |
581 | char *err_p; |
| 542 | 582 | ||
| - | 583 | --argc; ++argv; |
|
| - | 584 | ||
| - | 585 | while (argc > 1) { |
|
| - | 586 | arg = *argv; |
|
| - | 587 | if (arg[0] == '+') { |
|
| - | 588 | display_mask = parse_display_mask(&arg[1]); |
|
| - | 589 | } else { |
|
| - | 590 | printf("Unexpected argument '%s'\n", arg); |
|
| - | 591 | print_syntax(); |
|
| - | 592 | return -1; |
|
| - | 593 | } |
|
| - | 594 | ||
| - | 595 | --argc; ++argv; |
|
| - | 596 | } |
|
| - | 597 | ||
| 543 | if (argc != 2) { |
598 | if (argc != 1) { |
| 544 | printf("Mising argument\n"); |
599 | printf("Missing argument\n"); |
| 545 | print_syntax(); |
600 | print_syntax(); |
| 546 | return 1; |
601 | return 1; |
| 547 | } |
602 | } |
| 548 | 603 | ||
| 549 | task_id = strtol(argv[1], &err_p, 10); |
604 | task_id = strtol(*argv, &err_p, 10); |
| 550 | 605 | ||
| 551 | if (*err_p) { |
606 | if (*err_p) { |
| 552 | printf("Task ID syntax error\n"); |
607 | printf("Task ID syntax error\n"); |
| 553 | print_syntax(); |
608 | print_syntax(); |
| 554 | return 1; |
609 | return -1; |
| 555 | } |
610 | } |
| 556 | 611 | ||
| - | 612 | return 0; |
|
| - | 613 | } |
|
| - | 614 | ||
| - | 615 | int main(int argc, char *argv[]) |
|
| - | 616 | { |
|
| - | 617 | printf("System Call / IPC Tracer\n"); |
|
| - | 618 | ||
| - | 619 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
|
| - | 620 | ||
| - | 621 | if (parse_args(argc, argv) < 0) |
|
| - | 622 | return 1; |
|
| - | 623 | ||
| 557 | main_init(); |
624 | main_init(); |
| 558 | trace_active_task(task_id); |
625 | trace_active_task(task_id); |
| - | 626 | ||
| - | 627 | return 0; |
|
| 559 | } |
628 | } |
| 560 | 629 | ||
| 561 | /** @} |
630 | /** @} |
| 562 | */ |
631 | */ |