Changeset 47e0a05b in mainline for uspace/app/trace/trace.c


Ignore:
Timestamp:
2008-09-18T09:05:31Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4e5aa02
Parents:
2c57ee14
Message:

Allow trace to run programs and trace them (no more task IDs)

File:
1 edited

Legend:

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

    r2c57ee14 r47e0a05b  
    4242#include <udebug.h>
    4343#include <async.h>
     44#include <task.h>
    4445
    4546// Temporary: service and method names
     
    129130        printf("Threads:");
    130131        for (i = 0; i < n_threads; i++) {
    131                 printf(" [%d] (hash 0x%u)", 1+i, thread_hash_buf[i]);
     132                printf(" [%d] (hash 0x%x)", 1+i, thread_hash_buf[i]);
    132133        }
    133134        printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
     
    541542static void print_syntax()
    542543{
    543         printf("Syntax: trace [+<events>] <task_id>\n");
     544        printf("Syntax:\n");
     545        printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
     546        printf("or\ttrace [+<events>] -t <task_id>\n");
    544547        printf("Events: (default is +tp)\n");
    545548        printf("\n");
     
    549552        printf("\tp ... Protocol level\n");
    550553        printf("\n");
    551         printf("Example: trace +tsip 12\n");
     554        printf("Examples:\n");
     555        printf("\ttrace +s /app/tetris\n");
     556        printf("\ttrace +tsip -t 12\n");
    552557}
    553558
     
    581586        char *err_p;
    582587
     588        task_id = 0;
     589
    583590        --argc; ++argv;
    584591
    585         while (argc > 1) {
     592        while (argc > 0) {
    586593                arg = *argv;
    587594                if (arg[0] == '+') {
    588595                        display_mask = parse_display_mask(&arg[1]);
     596                } else if (arg[0] == '-') {
     597                        if (arg[1] == 't') {
     598                                /* Trace an already running task */
     599                                --argc; ++argv;
     600                                task_id = strtol(*argv, &err_p, 10);
     601                                if (*err_p) {
     602                                        printf("Task ID syntax error\n");
     603                                        print_syntax();
     604                                        return -1;
     605                                }
     606                        } else {
     607                                printf("Uknown option '%s'\n", arg[0]);
     608                                print_syntax();
     609                                return -1;
     610                        }
    589611                } else {
    590                         printf("Unexpected argument '%s'\n", arg);
    591                         print_syntax();
    592                         return -1;
     612                        break;
    593613                }
    594614
     
    596616        }
    597617
    598         if (argc != 1) {
     618        if (task_id != 0) {
     619                if (argc == 0) return;
     620                printf("Extra arguments\n");
     621                print_syntax();
     622                return -1;
     623        }
     624
     625        if (argc < 1) {
    599626                printf("Missing argument\n");
    600627                print_syntax();
    601                 return 1;
    602         }
    603 
    604         task_id = strtol(*argv, &err_p, 10);
    605 
    606         if (*err_p) {
    607                 printf("Task ID syntax error\n");
    608                 print_syntax();
    609628                return -1;
    610629        }
     630
     631        /* Execute the specified command and trace the new task. */
     632        printf("Spawning '%s' with arguments:\n", *argv);
     633        {
     634                char **cp = argv;
     635                while (*cp) printf("'%s'\n", *cp++);
     636        }
     637        task_id = task_spawn(*argv, argv);
    611638
    612639        return 0;
Note: See TracChangeset for help on using the changeset viewer.