Changeset 4470e26 in mainline for uspace/app/trace/trace.c


Ignore:
Timestamp:
2008-09-24T10:57:21Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0993087
Parents:
45454e9b
Message:

Separate load and run commands for loader. Update tracer - no events get missed on startup anymore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/trace/trace.c

    r45454e9b r4470e26  
    4343#include <async.h>
    4444#include <task.h>
     45#include <loader/loader.h>
    4546
    4647// Temporary: service and method names
     
    7172static proto_t *proto_console;
    7273static task_id_t task_id;
     74static loader_t *task_ldr;
    7375
    7476/** Combination of events/data to print. */
    7577display_mask_t display_mask;
    7678
    77 static int task_connect(task_id_t task_id)
     79static int program_run_fibril(void *arg);
     80
     81static 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
     94static 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
     116static int connect_task(task_id_t task_id)
    78117{
    79118        int rc;
     
    149188
    150189        case V_HASH:
     190        case V_PTR:
    151191                printf("0x%08lx", val);
    152192                break;
     
    469509}
    470510
    471 static void trace_active_task(task_id_t task_id)
     511static 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 */
     546error:
     547        loader_abort(ldr);
     548        free(ldr);
     549        return NULL;
     550}
     551
     552static void trace_task(task_id_t task_id)
    472553{
    473554        int i;
    474555        int rc;
    475556        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);
    484557
    485558        ipcp_init();
     
    657730                                --argc; ++argv;
    658731                                task_id = strtol(*argv, &err_p, 10);
     732                                task_ldr = NULL;
    659733                                if (*err_p) {
    660734                                        printf("Task ID syntax error\n");
     
    687761        }
    688762
    689         /* Execute the specified command and trace the new task. */
     763        /* Preload the specified program file. */
    690764        printf("Spawning '%s' with arguments:\n", *argv);
    691765        {
     
    693767                while (*cp) printf("'%s'\n", *cp++);
    694768        }
    695         task_id = task_spawn(*argv, argv);
     769        task_ldr = preload_task(*argv, argv, &task_id);
    696770
    697771        return 0;
     
    700774int main(int argc, char *argv[])
    701775{
     776        int rc;
     777
    702778        printf("System Call / IPC Tracer\n");
    703779
     
    708784
    709785        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);
    711800
    712801        return 0;
Note: See TracChangeset for help on using the changeset viewer.