Subversion Repositories HelenOS

Rev

Rev 3447 | Rev 3455 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2008 Jiri Svoboda
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup trace
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <syscall.h>
  39. #include <ipc/ipc.h>
  40. #include <fibril.h>
  41. #include <errno.h>
  42. #include <udebug.h>
  43. #include <async.h>
  44. #include <task.h>
  45.  
  46. // Temporary: service and method names
  47. #include "proto.h"
  48. #include <ipc/services.h>
  49. #include "../../srv/vfs/vfs.h"
  50. #include "../../srv/console/console.h"
  51.  
  52. #include "syscalls.h"
  53. #include "ipcp.h"
  54. #include "errors.h"
  55. #include "trace.h"
  56.  
  57. #define THBUF_SIZE 64
  58. unsigned thread_hash_buf[THBUF_SIZE];
  59. unsigned n_threads;
  60.  
  61. int next_thread_id;
  62.  
  63. int phoneid;
  64. int abort_trace;
  65.  
  66. unsigned thash;
  67. volatile int paused;
  68.  
  69. void thread_trace_start(unsigned thread_hash);
  70.  
  71. static proto_t *proto_console;
  72. static task_id_t task_id;
  73.  
  74. /** Combination of events/data to print. */
  75. display_mask_t display_mask;
  76.  
  77. static int task_connect(task_id_t task_id)
  78. {
  79.     int rc;
  80.  
  81.     rc = ipc_connect_kbox(task_id);
  82.  
  83.     if (rc == ENOTSUP) {
  84.         printf("You do not have userspace debugging support "
  85.             "compiled in the kernel.\n");
  86.         printf("Compile kernel with 'Support for userspace debuggers' "
  87.             "(CONFIG_UDEBUG) enabled.\n");
  88.         return rc;
  89.     }
  90.  
  91.     if (rc < 0) {
  92.         printf("Error connecting\n");
  93.         printf("ipc_connect_task(%lld) -> %d ", task_id, rc);
  94.         return rc;
  95.     }
  96.  
  97.     phoneid = rc;
  98.  
  99.     rc = udebug_begin(phoneid);
  100.     if (rc < 0) {
  101.         printf("udebug_begin() -> %d\n", rc);
  102.         return rc;
  103.     }
  104.  
  105.     rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL);
  106.     if (rc < 0) {
  107.         printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
  108.         return rc;
  109.     }
  110.  
  111.     return 0;
  112. }
  113.  
  114. static int get_thread_list(void)
  115. {
  116.     int rc;
  117.     size_t tb_copied;
  118.     size_t tb_needed;
  119.     int i;
  120.  
  121.     rc = udebug_thread_read(phoneid, thread_hash_buf,
  122.         THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
  123.     if (rc < 0) {
  124.         printf("udebug_thread_read() -> %d\n", rc);
  125.         return rc;
  126.     }
  127.  
  128.     n_threads = tb_copied / sizeof(unsigned);
  129.  
  130.     printf("Threads:");
  131.     for (i = 0; i < n_threads; i++) {
  132.         printf(" [%d] (hash 0x%x)", 1+i, thread_hash_buf[i]);
  133.     }
  134.     printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
  135.  
  136.     return 0;
  137. }
  138.  
  139. void val_print(int val, val_type_t v_type)
  140. {
  141.     switch (v_type) {
  142.     case V_VOID:
  143.         printf("<void>");
  144.         break;
  145.  
  146.     case V_INTEGER:
  147.         printf("%d", val);
  148.         break;
  149.  
  150.     case V_HASH:
  151.         printf("0x%08x", val);
  152.         break;
  153.  
  154.     case V_ERRNO:
  155.         if (val >= -15 && val <= 0) {
  156.             printf("%d %s (%s)", val,
  157.                 err_desc[-val].name,
  158.                 err_desc[-val].desc);
  159.         } else {
  160.             printf("%d", val);
  161.         }
  162.         break;
  163.     case V_INT_ERRNO:
  164.         if (val >= -15 && val < 0) {
  165.             printf("%d %s (%s)", val,
  166.                 err_desc[-val].name,
  167.                 err_desc[-val].desc);
  168.         } else {
  169.             printf("%d", val);
  170.         }
  171.         break;
  172.  
  173.     case V_CHAR:
  174.         if (val >= 0x20 && val < 0x7f) {
  175.             printf("'%c'", val);
  176.         } else {
  177.             switch (val) {
  178.             case '\a': printf("'\\a'"); break;
  179.             case '\b': printf("'\\b'"); break;
  180.             case '\n': printf("'\\n'"); break;
  181.             case '\r': printf("'\\r'"); break;
  182.             case '\t': printf("'\\t'"); break;
  183.             case '\\': printf("'\\\\'"); break;
  184.             default: printf("'\\x%X'"); break;
  185.             }
  186.         }
  187.         break;
  188.     }
  189. }
  190.  
  191.  
  192. static void print_sc_retval(int retval, val_type_t val_type)
  193. {
  194.     printf(" -> ");
  195.     val_print(retval, val_type);
  196.     putchar('\n');
  197. }
  198.  
  199. static void print_sc_args(unsigned *sc_args, int n)
  200. {
  201.     int i;
  202.  
  203.     putchar('(');
  204.     if (n > 0) printf("%d", sc_args[0]);
  205.     for (i = 1; i < n; i++) {
  206.         printf(", %d", sc_args[i]);
  207.     }
  208.     putchar(')');
  209. }
  210.  
  211. static void sc_ipc_call_async_fast(unsigned *sc_args, int sc_rc)
  212. {
  213.     ipc_call_t call;
  214.     int phoneid;
  215.    
  216.     if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
  217.         return;
  218.  
  219.     phoneid = sc_args[0];
  220.  
  221.     IPC_SET_METHOD(call, sc_args[1]);
  222.     IPC_SET_ARG1(call, sc_args[2]);
  223.     IPC_SET_ARG2(call, sc_args[3]);
  224.     IPC_SET_ARG3(call, sc_args[4]);
  225.     IPC_SET_ARG4(call, sc_args[5]);
  226.     IPC_SET_ARG5(call, 0);
  227.  
  228.     ipcp_call_out(phoneid, &call, sc_rc);
  229. }
  230.  
  231. static void sc_ipc_call_async_slow(unsigned *sc_args, int sc_rc)
  232. {
  233.     ipc_call_t call;
  234.     int rc;
  235.  
  236.     if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
  237.         return;
  238.  
  239.     memset(&call, 0, sizeof(call));
  240.     rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
  241.  
  242.     if (rc >= 0) {
  243.         ipcp_call_out(sc_args[0], &call, sc_rc);
  244.     }
  245. }
  246.  
  247. static void sc_ipc_call_sync_fast(unsigned *sc_args)
  248. {
  249.     ipc_call_t question, reply;
  250.     int rc;
  251.     int phoneidx;
  252.  
  253. //  printf("sc_ipc_call_sync_fast()\n");
  254.     phoneidx = sc_args[0];
  255.  
  256.     IPC_SET_METHOD(question, sc_args[1]);
  257.     IPC_SET_ARG1(question, sc_args[2]);
  258.     IPC_SET_ARG2(question, sc_args[3]);
  259.     IPC_SET_ARG3(question, sc_args[4]);
  260.     IPC_SET_ARG4(question, 0);
  261.     IPC_SET_ARG5(question, 0);
  262.  
  263. //  printf("memset\n");
  264.     memset(&reply, 0, sizeof(reply));
  265. //  printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n",
  266. //      phoneid, &reply.args, sc_args[5], sizeof(reply.args));
  267.     rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args));
  268. //  printf("dmr->%d\n", rc);
  269.     if (rc < 0) return;
  270.  
  271. //  printf("call ipc_call_sync\n");
  272.     ipcp_call_sync(phoneidx, &question, &reply);
  273. }
  274.  
  275. static void sc_ipc_call_sync_slow(unsigned *sc_args)
  276. {
  277.     ipc_call_t question, reply;
  278.     int rc;
  279.  
  280.     memset(&question, 0, sizeof(question));
  281.     rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args));
  282.     printf("dmr->%d\n", rc);
  283.     if (rc < 0) return;
  284.  
  285.     memset(&reply, 0, sizeof(reply));
  286.     rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args));
  287.     printf("dmr->%d\n", rc);
  288.     if (rc < 0) return;
  289.  
  290.     ipcp_call_sync(sc_args[0], &question, &reply);
  291. }
  292.  
  293. static void sc_ipc_wait(unsigned *sc_args, int sc_rc)
  294. {
  295.     ipc_call_t call;
  296.     int rc;
  297.  
  298.     if (sc_rc == 0) return;
  299.  
  300.     memset(&call, 0, sizeof(call));
  301.     rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call));
  302. //  printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n",
  303. //      phoneid, (int)&call, sc_args[0], sizeof(call), rc);
  304.  
  305.     if (rc >= 0) {
  306.         ipcp_call_in(&call, sc_rc);
  307.     }
  308. }
  309.  
  310. static void event_syscall_b(unsigned thread_id, unsigned thread_hash,  unsigned sc_id, int sc_rc)
  311. {
  312.     unsigned sc_args[6];
  313.     int rc;
  314.  
  315.     /* Read syscall arguments */
  316.     rc = udebug_args_read(phoneid, thread_hash, sc_args);
  317.  
  318.     async_serialize_start();
  319.  
  320. //  printf("[%d] ", thread_id);
  321.  
  322.     if (rc < 0) {
  323.         printf("error\n");
  324.         async_serialize_end();
  325.         return;
  326.     }
  327.  
  328.     if ((display_mask & DM_SYSCALL) != 0) {
  329.         /* Print syscall name and arguments */
  330.         printf("%s", syscall_desc[sc_id].name);
  331.         print_sc_args(sc_args, syscall_desc[sc_id].n_args);
  332.     }
  333.  
  334.     async_serialize_end();
  335. }
  336.  
  337. static void event_syscall_e(unsigned thread_id, unsigned thread_hash,  unsigned sc_id, int sc_rc)
  338. {
  339.     unsigned sc_args[6];
  340.     int rv_type;
  341.     int rc;
  342.  
  343.     /* Read syscall arguments */
  344.     rc = udebug_args_read(phoneid, thread_hash, sc_args);
  345.  
  346.     async_serialize_start();
  347.  
  348. //  printf("[%d] ", thread_id);
  349.  
  350.     if (rc < 0) {
  351.         printf("error\n");
  352.         async_serialize_end();
  353.         return;
  354.     }
  355.  
  356.     if ((display_mask & DM_SYSCALL) != 0) {
  357.         /* Print syscall return value */
  358.         rv_type = syscall_desc[sc_id].rv_type;
  359.         print_sc_retval(sc_rc, rv_type);
  360.     }
  361.  
  362.     switch (sc_id) {
  363.     case SYS_IPC_CALL_ASYNC_FAST:
  364.         sc_ipc_call_async_fast(sc_args, sc_rc);
  365.         break;
  366.     case SYS_IPC_CALL_ASYNC_SLOW:
  367.         sc_ipc_call_async_slow(sc_args, sc_rc);
  368.         break;
  369.     case SYS_IPC_CALL_SYNC_FAST:
  370.         sc_ipc_call_sync_fast(sc_args);
  371.         break;
  372.     case SYS_IPC_CALL_SYNC_SLOW:
  373.         sc_ipc_call_sync_slow(sc_args);
  374.         break;
  375.     case SYS_IPC_WAIT:
  376.         sc_ipc_wait(sc_args, sc_rc);
  377.         break;
  378.     default:
  379.         break;
  380.     }
  381.  
  382.     async_serialize_end();
  383. }
  384.  
  385. static void event_thread_b(unsigned hash)
  386. {
  387.     async_serialize_start();
  388.     printf("New thread, hash 0x%x\n", hash);
  389.     async_serialize_end();
  390.  
  391.     thread_trace_start(hash);
  392. }
  393.  
  394. static int trace_loop(void *thread_hash_arg)
  395. {
  396.     int rc;
  397.     unsigned ev_type;
  398.     unsigned thread_hash;
  399.     unsigned thread_id;
  400.     unsigned val0, val1;
  401.  
  402.     thread_hash = (unsigned)thread_hash_arg;
  403.     thread_id = next_thread_id++;
  404.  
  405.     printf("Start tracing thread [%d] (hash 0x%x)\n", thread_id, thread_hash);
  406.  
  407.     while (!abort_trace) {
  408.  
  409.         /* Run thread until an event occurs */
  410.         rc = udebug_go(phoneid, thread_hash,
  411.             &ev_type, &val0, &val1);
  412.  
  413. //      printf("rc = %d, ev_type=%d\n", rc, ev_type);
  414.         if (ev_type == UDEBUG_EVENT_FINISHED) {
  415.             /* Done tracing this thread */
  416.             break;
  417.         }
  418.  
  419.         if (rc >= 0) {
  420.             switch (ev_type) {
  421.             case UDEBUG_EVENT_SYSCALL_B:
  422.                 event_syscall_b(thread_id, thread_hash, val0, (int)val1);
  423.                 break;
  424.             case UDEBUG_EVENT_SYSCALL_E:
  425.                 event_syscall_e(thread_id, thread_hash, val0, (int)val1);
  426.                 break;
  427.             case UDEBUG_EVENT_STOP:
  428.                 printf("Stop event\n");
  429.                 printf("Waiting for resume\n");
  430.                 while (paused) {
  431.                     usleep(1000000);
  432.                     fibril_yield();
  433.                     printf(".");
  434.                 }
  435.                 printf("Resumed\n");
  436.                 break;
  437.             case UDEBUG_EVENT_THREAD_B:
  438.                 event_thread_b(val0);
  439.                 break;
  440.             case UDEBUG_EVENT_THREAD_E:
  441.                 printf("Thread 0x%x exited\n", val0);
  442.                 abort_trace = 1;
  443.                 break;
  444.             default:
  445.                 printf("Unknown event type %d\n", ev_type);
  446.                 break;
  447.             }
  448.         }
  449.  
  450.     }
  451.  
  452.     printf("Finished tracing thread [%d]\n", thread_id);
  453.     return 0;
  454. }
  455.  
  456. void thread_trace_start(unsigned thread_hash)
  457. {
  458.     fid_t fid;
  459.  
  460.     thash = thread_hash;
  461.  
  462.     fid = fibril_create(trace_loop, (void *)thread_hash);
  463.     if (fid == 0) {
  464.         printf("Warning: Failed creating fibril\n");
  465.     }
  466.     fibril_add_ready(fid);
  467. }
  468.  
  469. static void trace_active_task(task_id_t task_id)
  470. {
  471.     int i;
  472.     int rc;
  473.     int c;
  474.  
  475.     rc = task_connect(task_id);
  476.     if (rc < 0) {
  477.         printf("Failed to connect to task %lld\n", task_id);
  478.         return;
  479.     }
  480.  
  481.     printf("Connected to task %lld\n", task_id);
  482.  
  483.     ipcp_init();
  484.  
  485.     /*
  486.      * User apps now typically have console on phone 3.
  487.      * (Phones 1 and 2 are used by the loader).
  488.      */
  489.     ipcp_connection_set(3, 0, proto_console);
  490.  
  491.     rc = get_thread_list();
  492.     if (rc < 0) {
  493.         printf("Failed to get thread list (error %d)\n", rc);
  494.         return;
  495.     }
  496.  
  497.     abort_trace = 0;
  498.  
  499.     for (i = 0; i < n_threads; i++) {
  500.         thread_trace_start(thread_hash_buf[i]);
  501.     }
  502.  
  503.     while(1) {
  504.         c = getchar();
  505.         if (c == 'q') break;
  506.         if (c == 'p') {
  507.             paused = 1;
  508.             rc = udebug_stop(phoneid, thash);
  509.             printf("stop -> %d\n", rc);
  510.         }
  511.         if (c == 'r') {
  512.             paused = 0;
  513.         }
  514.     }
  515.  
  516.     printf("\nTerminate debugging session...\n");
  517.     abort_trace = 1;
  518.     udebug_end(phoneid);
  519.     ipc_hangup(phoneid);
  520.  
  521.     ipcp_cleanup();
  522.  
  523.     printf("Done\n");
  524.     return;
  525. }
  526.  
  527. static void main_init(void)
  528. {
  529.     proto_t *p;
  530.     oper_t *o;
  531.  
  532.     val_type_t arg_def[OPER_MAX_ARGS] = {
  533.         V_INTEGER,
  534.         V_INTEGER,
  535.         V_INTEGER,
  536.         V_INTEGER,
  537.         V_INTEGER      
  538.     };
  539.  
  540.     val_type_t resp_def[OPER_MAX_ARGS] = {
  541.         V_INTEGER,
  542.         V_INTEGER,
  543.         V_INTEGER,
  544.         V_INTEGER,
  545.         V_INTEGER      
  546.     };
  547.  
  548.     next_thread_id = 1;
  549.     paused = 0;
  550.  
  551.     proto_init();
  552.  
  553.     p = proto_new("vfs");
  554.     o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
  555.     proto_add_oper(p, VFS_READ, o);
  556.     o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
  557.     proto_add_oper(p, VFS_WRITE, o);
  558.     o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
  559.     proto_add_oper(p, VFS_TRUNCATE, o);
  560.     o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
  561.     proto_add_oper(p, VFS_MOUNT, o);
  562. /*  o = oper_new("unmount", 0, arg_def);
  563.     proto_add_oper(p, VFS_UNMOUNT, o);*/
  564.  
  565.     proto_register(SERVICE_VFS, p);
  566.  
  567.     p = proto_new("console");
  568.     resp_def[0] = V_CHAR;
  569.     o = oper_new("getchar", 0, arg_def, V_INTEGER, 2, resp_def);
  570.     proto_add_oper(p, CONSOLE_GETCHAR, o);
  571.  
  572.     arg_def[0] = V_CHAR;
  573.     o = oper_new("putchar", 1, arg_def, V_VOID, 0, resp_def);
  574.     proto_add_oper(p, CONSOLE_PUTCHAR, o);
  575.     o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def);
  576.     proto_add_oper(p, CONSOLE_CLEAR, o);
  577.  
  578.     arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
  579.     o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def);
  580.     proto_add_oper(p, CONSOLE_GOTO, o);
  581.  
  582.     resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
  583.     o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def);
  584.     proto_add_oper(p, CONSOLE_GETSIZE, o);
  585.     o = oper_new("flush", 0, arg_def, V_VOID, 0, resp_def);
  586.     proto_add_oper(p, CONSOLE_FLUSH, o);
  587.  
  588.     arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
  589.     o = oper_new("set_style", 2, arg_def, V_INTEGER, 0, resp_def);
  590.     proto_add_oper(p, CONSOLE_SET_STYLE, o);
  591.     o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def);
  592.     proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o);
  593.  
  594.     proto_console = p;
  595.     proto_register(SERVICE_CONSOLE, p);
  596. }
  597.  
  598. static void print_syntax()
  599. {
  600.     printf("Syntax:\n");
  601.     printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
  602.     printf("or\ttrace [+<events>] -t <task_id>\n");
  603.     printf("Events: (default is +tp)\n");
  604.     printf("\n");
  605.     printf("\tt ... Thread creation and termination\n");
  606.     printf("\ts ... System calls\n");
  607.     printf("\ti ... Low-level IPC\n");
  608.     printf("\tp ... Protocol level\n");
  609.     printf("\n");
  610.     printf("Examples:\n");
  611.     printf("\ttrace +s /app/tetris\n");
  612.     printf("\ttrace +tsip -t 12\n");
  613. }
  614.  
  615. static display_mask_t parse_display_mask(char *text)
  616. {
  617.     display_mask_t dm;
  618.     char *c;
  619.  
  620.     c = text;
  621.  
  622.     while (*c) {
  623.         switch (*c) {
  624.         case 't': dm = dm | DM_THREAD; break;
  625.         case 's': dm = dm | DM_SYSCALL; break;
  626.         case 'i': dm = dm | DM_IPC; break;
  627.         case 'p': dm = dm | DM_SYSTEM | DM_USER; break;
  628.         default:
  629.             printf("Unexpected event type '%c'\n", *c);
  630.             exit(1);
  631.         }
  632.  
  633.         ++c;
  634.     }
  635.  
  636.     return dm;
  637. }
  638.  
  639. static int parse_args(int argc, char *argv[])
  640. {
  641.     char *arg;
  642.     char *err_p;
  643.  
  644.     task_id = 0;
  645.  
  646.     --argc; ++argv;
  647.  
  648.     while (argc > 0) {
  649.         arg = *argv;
  650.         if (arg[0] == '+') {
  651.             display_mask = parse_display_mask(&arg[1]);
  652.         } else if (arg[0] == '-') {
  653.             if (arg[1] == 't') {
  654.                 /* Trace an already running task */
  655.                 --argc; ++argv;
  656.                 task_id = strtol(*argv, &err_p, 10);
  657.                 if (*err_p) {
  658.                     printf("Task ID syntax error\n");
  659.                     print_syntax();
  660.                     return -1;
  661.                 }
  662.             } else {
  663.                 printf("Uknown option '%s'\n", arg[0]);
  664.                 print_syntax();
  665.                 return -1;
  666.             }
  667.         } else {
  668.             break;
  669.         }
  670.  
  671.         --argc; ++argv;
  672.     }
  673.  
  674.     if (task_id != 0) {
  675.         if (argc == 0) return;
  676.         printf("Extra arguments\n");
  677.         print_syntax();
  678.         return -1;
  679.     }
  680.  
  681.     if (argc < 1) {
  682.         printf("Missing argument\n");
  683.         print_syntax();
  684.         return -1;
  685.     }
  686.  
  687.     /* Execute the specified command and trace the new task. */
  688.     printf("Spawning '%s' with arguments:\n", *argv);
  689.     {
  690.         char **cp = argv;
  691.         while (*cp) printf("'%s'\n", *cp++);
  692.     }
  693.     task_id = task_spawn(*argv, argv);
  694.  
  695.     return 0;
  696. }
  697.  
  698. int main(int argc, char *argv[])
  699. {
  700.     printf("System Call / IPC Tracer\n");
  701.  
  702.     display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
  703.  
  704.     if (parse_args(argc, argv) < 0)
  705.         return 1;
  706.  
  707.     main_init();
  708.     trace_active_task(task_id);
  709.  
  710.     return 0;
  711. }
  712.  
  713. /** @}
  714.  */
  715.