Changeset 4470e26 in mainline for uspace/app/trace/trace.c
- Timestamp:
- 2008-09-24T10:57:21Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0993087
- Parents:
- 45454e9b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/trace/trace.c
r45454e9b r4470e26 43 43 #include <async.h> 44 44 #include <task.h> 45 #include <loader/loader.h> 45 46 46 47 // Temporary: service and method names … … 71 72 static proto_t *proto_console; 72 73 static task_id_t task_id; 74 static loader_t *task_ldr; 73 75 74 76 /** Combination of events/data to print. */ 75 77 display_mask_t display_mask; 76 78 77 static int task_connect(task_id_t task_id) 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 116 static int connect_task(task_id_t task_id) 78 117 { 79 118 int rc; … … 149 188 150 189 case V_HASH: 190 case V_PTR: 151 191 printf("0x%08lx", val); 152 192 break; … … 469 509 } 470 510 471 static void trace_active_task(task_id_t task_id) 511 static loader_t *preload_task(const char *path, char *const argv[], 512 task_id_t *task_id) 513 { 514 loader_t *ldr; 515 int rc; 516 517 /* Spawn a program loader */ 518 ldr = loader_spawn(); 519 if (ldr == NULL) 520 return 0; 521 522 /* Get task ID. */ 523 rc = loader_get_task_id(ldr, task_id); 524 if (rc != EOK) 525 goto error; 526 527 /* Send program pathname */ 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 */ 543 return ldr; 544 545 /* Error exit */ 546 error: 547 loader_abort(ldr); 548 free(ldr); 549 return NULL; 550 } 551 552 static void trace_task(task_id_t task_id) 472 553 { 473 554 int i; 474 555 int rc; 475 556 int c; 476 477 rc = task_connect(task_id);478 if (rc < 0) {479 printf("Failed to connect to task %lld\n", task_id);480 return;481 }482 483 printf("Connected to task %lld\n", task_id);484 557 485 558 ipcp_init(); … … 657 730 --argc; ++argv; 658 731 task_id = strtol(*argv, &err_p, 10); 732 task_ldr = NULL; 659 733 if (*err_p) { 660 734 printf("Task ID syntax error\n"); … … 687 761 } 688 762 689 /* Execute the specified command and trace the new task. */763 /* Preload the specified program file. */ 690 764 printf("Spawning '%s' with arguments:\n", *argv); 691 765 { … … 693 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 771 return 0; … … 700 774 int main(int argc, char *argv[]) 701 775 { 776 int rc; 777 702 778 printf("System Call / IPC Tracer\n"); 703 779 … … 708 784 709 785 main_init(); 710 trace_active_task(task_id); 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 799 trace_task(task_id); 711 800 712 801 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.