Rev 3455 | Rev 3485 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3455 | Rev 3470 | ||
---|---|---|---|
Line 40... | Line 40... | ||
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 | 46 | ||
46 | // Temporary: service and method names |
47 | // Temporary: service and method names |
47 | #include "proto.h" |
48 | #include "proto.h" |
48 | #include <ipc/services.h> |
49 | #include <ipc/services.h> |
49 | #include "../../srv/vfs/vfs.h" |
50 | #include "../../srv/vfs/vfs.h" |
Line 68... | Line 69... | ||
68 | 69 | ||
69 | void thread_trace_start(uintptr_t thread_hash); |
70 | void thread_trace_start(uintptr_t thread_hash); |
70 | 71 | ||
71 | static proto_t *proto_console; |
72 | static proto_t *proto_console; |
72 | static task_id_t task_id; |
73 | static task_id_t task_id; |
- | 74 | static loader_t *task_ldr; |
|
73 | 75 | ||
74 | /** Combination of events/data to print. */ |
76 | /** Combination of events/data to print. */ |
75 | display_mask_t display_mask; |
77 | display_mask_t display_mask; |
76 | 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 | ||
77 | static int task_connect(task_id_t task_id) |
116 | static int connect_task(task_id_t task_id) |
78 | { |
117 | { |
79 | int rc; |
118 | int rc; |
80 | 119 | ||
81 | rc = ipc_connect_kbox(task_id); |
120 | rc = ipc_connect_kbox(task_id); |
82 | 121 | ||
Line 146... | Line 185... | ||
146 | case V_INTEGER: |
185 | case V_INTEGER: |
147 | printf("%ld", val); |
186 | printf("%ld", val); |
148 | break; |
187 | break; |
149 | 188 | ||
150 | case V_HASH: |
189 | case V_HASH: |
- | 190 | case V_PTR: |
|
151 | printf("0x%08lx", val); |
191 | printf("0x%08lx", val); |
152 | break; |
192 | break; |
153 | 193 | ||
154 | case V_ERRNO: |
194 | case V_ERRNO: |
155 | if (val >= -15 && val <= 0) { |
195 | if (val >= -15 && val <= 0) { |
Line 466... | Line 506... | ||
466 | printf("Warning: Failed creating fibril\n"); |
506 | printf("Warning: Failed creating fibril\n"); |
467 | } |
507 | } |
468 | fibril_add_ready(fid); |
508 | fibril_add_ready(fid); |
469 | } |
509 | } |
470 | 510 | ||
- | 511 | static loader_t *preload_task(const char *path, char *const argv[], |
|
471 | static void trace_active_task(task_id_t task_id) |
512 | task_id_t *task_id) |
472 | { |
513 | { |
473 | int i; |
514 | loader_t *ldr; |
474 | int rc; |
515 | int rc; |
475 | int c; |
- | |
476 | 516 | ||
- | 517 | /* Spawn a program loader */ |
|
- | 518 | ldr = loader_spawn(); |
|
- | 519 | if (ldr == NULL) |
|
- | 520 | return 0; |
|
- | 521 | ||
- | 522 | /* Get task ID. */ |
|
477 | rc = task_connect(task_id); |
523 | rc = loader_get_task_id(ldr, task_id); |
478 | if (rc < 0) { |
524 | if (rc != EOK) |
- | 525 | goto error; |
|
- | 526 | ||
- | 527 | /* Send program pathname */ |
|
479 | 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 */ |
|
480 | return; |
543 | return ldr; |
- | 544 | ||
- | 545 | /* Error exit */ |
|
- | 546 | error: |
|
- | 547 | loader_abort(ldr); |
|
- | 548 | free(ldr); |
|
- | 549 | return NULL; |
|
481 | } |
550 | } |
482 | 551 | ||
483 | 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; |
|
484 | 557 | ||
485 | ipcp_init(); |
558 | ipcp_init(); |
486 | 559 | ||
487 | /* |
560 | /* |
488 | * User apps now typically have console on phone 3. |
561 | * User apps now typically have console on phone 3. |
Line 654... | Line 727... | ||
654 | } else if (arg[0] == '-') { |
727 | } else if (arg[0] == '-') { |
655 | if (arg[1] == 't') { |
728 | if (arg[1] == 't') { |
656 | /* Trace an already running task */ |
729 | /* Trace an already running task */ |
657 | --argc; ++argv; |
730 | --argc; ++argv; |
658 | task_id = strtol(*argv, &err_p, 10); |
731 | task_id = strtol(*argv, &err_p, 10); |
- | 732 | task_ldr = NULL; |
|
659 | if (*err_p) { |
733 | if (*err_p) { |
660 | printf("Task ID syntax error\n"); |
734 | printf("Task ID syntax error\n"); |
661 | print_syntax(); |
735 | print_syntax(); |
662 | return -1; |
736 | return -1; |
663 | } |
737 | } |
Line 684... | Line 758... | ||
684 | printf("Missing argument\n"); |
758 | printf("Missing argument\n"); |
685 | print_syntax(); |
759 | print_syntax(); |
686 | return -1; |
760 | return -1; |
687 | } |
761 | } |
688 | 762 | ||
689 | /* Execute the specified command and trace the new task. */ |
763 | /* Preload the specified program file. */ |
690 | printf("Spawning '%s' with arguments:\n", *argv); |
764 | printf("Spawning '%s' with arguments:\n", *argv); |
691 | { |
765 | { |
692 | char **cp = argv; |
766 | char **cp = argv; |
693 | while (*cp) printf("'%s'\n", *cp++); |
767 | while (*cp) printf("'%s'\n", *cp++); |
694 | } |
768 | } |
695 | task_id = task_spawn(*argv, argv); |
769 | task_ldr = preload_task(*argv, argv, &task_id); |
696 | 770 | ||
697 | return 0; |
771 | return 0; |
698 | } |
772 | } |
699 | 773 | ||
700 | int main(int argc, char *argv[]) |
774 | int main(int argc, char *argv[]) |
701 | { |
775 | { |
- | 776 | int rc; |
|
- | 777 | ||
702 | printf("System Call / IPC Tracer\n"); |
778 | printf("System Call / IPC Tracer\n"); |
703 | 779 | ||
704 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
780 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
705 | 781 | ||
706 | if (parse_args(argc, argv) < 0) |
782 | if (parse_args(argc, argv) < 0) |
707 | return 1; |
783 | return 1; |
708 | 784 | ||
709 | 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 | ||
710 | trace_active_task(task_id); |
799 | trace_task(task_id); |
711 | 800 | ||
712 | return 0; |
801 | return 0; |
713 | } |
802 | } |
714 | 803 | ||
715 | /** @} |
804 | /** @} |