source: mainline/uspace/app/trace/trace.c@ 06b0211b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 06b0211b was a3b339b4, checked in by Martin Sucha <sucha14@…>, 12 years ago

Fix /app/trace

  • Property mode set to 100644
File size: 18.1 KB
Line 
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 <fibril.h>
39#include <errno.h>
40#include <udebug.h>
41#include <async.h>
42#include <task.h>
43#include <mem.h>
44#include <str.h>
45#include <stdbool.h>
46#include <loader/loader.h>
47#include <io/console.h>
48#include <io/keycode.h>
49#include <fibril_synch.h>
50#include <sys/types.h>
51#include <sys/typefmt.h>
52#include <vfs/vfs.h>
53
54#include <libc.h>
55
56/* Temporary: service and method names */
57#include "proto.h"
58#include <ipc/services.h>
59#include "../../srv/vfs/vfs.h"
60#include <ipc/console.h>
61
62#include "syscalls.h"
63#include "ipcp.h"
64#include "errors.h"
65#include "trace.h"
66
67#define THBUF_SIZE 64
68uintptr_t thread_hash_buf[THBUF_SIZE];
69int n_threads;
70
71int next_thread_id;
72
73ipc_call_t thread_ipc_req[THBUF_SIZE];
74
75async_sess_t *sess;
76bool abort_trace;
77
78uintptr_t thash;
79static bool paused;
80static fibril_condvar_t state_cv;
81static fibril_mutex_t state_lock;
82
83static bool cev_valid;
84static kbd_event_t cev;
85
86void thread_trace_start(uintptr_t thread_hash);
87
88static task_id_t task_id;
89static loader_t *task_ldr;
90static bool task_wait_for;
91
92/** Combination of events/data to print. */
93display_mask_t display_mask;
94
95static int program_run_fibril(void *arg);
96static int cev_fibril(void *arg);
97
98static void program_run(void)
99{
100 fid_t fid;
101
102 fid = fibril_create(program_run_fibril, NULL);
103 if (fid == 0) {
104 printf("Error creating fibril\n");
105 exit(1);
106 }
107
108 fibril_add_ready(fid);
109}
110
111static void cev_fibril_start(void)
112{
113 fid_t fid;
114
115 fid = fibril_create(cev_fibril, NULL);
116 if (fid == 0) {
117 printf("Error creating fibril\n");
118 exit(1);
119 }
120
121 fibril_add_ready(fid);
122}
123
124static int program_run_fibril(void *arg)
125{
126 int rc;
127
128 /*
129 * This must be done in background as it will block until
130 * we let the task reply to this call.
131 */
132 rc = loader_run(task_ldr);
133 if (rc != 0) {
134 printf("Error running program\n");
135 exit(1);
136 }
137
138 task_ldr = NULL;
139
140 printf("program_run_fibril exiting\n");
141 return 0;
142}
143
144
145static int connect_task(task_id_t task_id)
146{
147 async_sess_t *ksess = async_connect_kbox(task_id);
148
149 if (!ksess) {
150 if (errno == ENOTSUP) {
151 printf("You do not have userspace debugging support "
152 "compiled in the kernel.\n");
153 printf("Compile kernel with 'Support for userspace debuggers' "
154 "(CONFIG_UDEBUG) enabled.\n");
155 return errno;
156 }
157
158 printf("Error connecting\n");
159 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno);
160 return errno;
161 }
162
163 int rc = udebug_begin(ksess);
164 if (rc < 0) {
165 printf("udebug_begin() -> %d\n", rc);
166 return rc;
167 }
168
169 rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL);
170 if (rc < 0) {
171 printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
172 return rc;
173 }
174
175 sess = ksess;
176 return 0;
177}
178
179static int get_thread_list(void)
180{
181 int rc;
182 size_t tb_copied;
183 size_t tb_needed;
184 int i;
185
186 rc = udebug_thread_read(sess, thread_hash_buf,
187 THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
188 if (rc < 0) {
189 printf("udebug_thread_read() -> %d\n", rc);
190 return rc;
191 }
192
193 n_threads = tb_copied / sizeof(uintptr_t);
194
195 printf("Threads:");
196 for (i = 0; i < n_threads; i++) {
197 printf(" [%d] (hash %p)", 1 + i, (void *) thread_hash_buf[i]);
198 }
199 printf("\ntotal of %zu threads\n", tb_needed / sizeof(uintptr_t));
200
201 return 0;
202}
203
204void val_print(sysarg_t val, val_type_t v_type)
205{
206 long sval;
207
208 sval = (long) val;
209
210 switch (v_type) {
211 case V_VOID:
212 printf("<void>");
213 break;
214
215 case V_INTEGER:
216 printf("%ld", sval);
217 break;
218
219 case V_HASH:
220 case V_PTR:
221 printf("%p", (void *) val);
222 break;
223
224 case V_ERRNO:
225 if (sval >= -15 && sval <= 0) {
226 printf("%ld %s (%s)", sval,
227 err_desc[-sval].name,
228 err_desc[-sval].desc);
229 } else {
230 printf("%ld", sval);
231 }
232 break;
233 case V_INT_ERRNO:
234 if (sval >= -15 && sval < 0) {
235 printf("%ld %s (%s)", sval,
236 err_desc[-sval].name,
237 err_desc[-sval].desc);
238 } else {
239 printf("%ld", sval);
240 }
241 break;
242
243 case V_CHAR:
244 if (sval >= 0x20 && sval < 0x7f) {
245 printf("'%c'", (char) sval);
246 } else {
247 switch (sval) {
248 case '\a': printf("'\\a'"); break;
249 case '\b': printf("'\\b'"); break;
250 case '\n': printf("'\\n'"); break;
251 case '\r': printf("'\\r'"); break;
252 case '\t': printf("'\\t'"); break;
253 case '\\': printf("'\\\\'"); break;
254 default: printf("'\\x%02" PRIxn "'", val); break;
255 }
256 }
257 break;
258 }
259}
260
261
262static void print_sc_retval(sysarg_t retval, val_type_t val_type)
263{
264 printf(" -> ");
265 val_print(retval, val_type);
266 putchar('\n');
267}
268
269static void print_sc_args(sysarg_t *sc_args, int n)
270{
271 int i;
272
273 putchar('(');
274 if (n > 0) printf("%" PRIun, sc_args[0]);
275 for (i = 1; i < n; i++) {
276 printf(", %" PRIun, sc_args[i]);
277 }
278 putchar(')');
279}
280
281static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc)
282{
283 ipc_call_t call;
284 sysarg_t phoneid;
285
286 if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
287 sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY)
288 return;
289
290 phoneid = sc_args[0];
291
292 IPC_SET_IMETHOD(call, sc_args[1]);
293 IPC_SET_ARG1(call, sc_args[2]);
294 IPC_SET_ARG2(call, sc_args[3]);
295 IPC_SET_ARG3(call, sc_args[4]);
296 IPC_SET_ARG4(call, sc_args[5]);
297 IPC_SET_ARG5(call, 0);
298
299 ipcp_call_out(phoneid, &call, sc_rc);
300}
301
302static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc)
303{
304 ipc_call_t call;
305 int rc;
306
307 if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
308 sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY)
309 return;
310
311 memset(&call, 0, sizeof(call));
312 rc = udebug_mem_read(sess, &call.args, sc_args[1], sizeof(call.args));
313
314 if (rc >= 0) {
315 ipcp_call_out(sc_args[0], &call, sc_rc);
316 }
317}
318
319static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
320{
321 ipc_call_t call;
322 int rc;
323
324 if (sc_rc == 0) return;
325
326 memset(&call, 0, sizeof(call));
327 rc = udebug_mem_read(sess, &call, sc_args[0], sizeof(call));
328
329 if (rc >= 0)
330 ipcp_call_in(&call, sc_rc);
331}
332
333static void event_syscall_b(unsigned thread_id, uintptr_t thread_hash,
334 unsigned sc_id, sysarg_t sc_rc)
335{
336 sysarg_t sc_args[6];
337 int rc;
338
339 /* Read syscall arguments */
340 rc = udebug_args_read(sess, thread_hash, sc_args);
341
342 if (rc < 0) {
343 printf("error\n");
344 return;
345 }
346
347 if ((display_mask & DM_SYSCALL) != 0) {
348 /* Print syscall name and arguments */
349 if (syscall_desc_defined(sc_id)) {
350 printf("%s", syscall_desc[sc_id].name);
351 print_sc_args(sc_args, syscall_desc[sc_id].n_args);
352 }
353 else {
354 printf("unknown_syscall<%d>", sc_id);
355 print_sc_args(sc_args, 6);
356 }
357 }
358}
359
360static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash,
361 unsigned sc_id, sysarg_t sc_rc)
362{
363 sysarg_t sc_args[6];
364 int rv_type;
365 int rc;
366
367 /* Read syscall arguments */
368 rc = udebug_args_read(sess, thread_hash, sc_args);
369
370// printf("[%d] ", thread_id);
371
372 if (rc < 0) {
373 printf("error\n");
374 return;
375 }
376
377 if ((display_mask & DM_SYSCALL) != 0) {
378 /* Print syscall return value */
379 if (syscall_desc_defined(sc_id))
380 rv_type = syscall_desc[sc_id].rv_type;
381 else
382 rv_type = V_PTR;
383 print_sc_retval(sc_rc, rv_type);
384 }
385
386 switch (sc_id) {
387 case SYS_IPC_CALL_ASYNC_FAST:
388 sc_ipc_call_async_fast(sc_args, sc_rc);
389 break;
390 case SYS_IPC_CALL_ASYNC_SLOW:
391 sc_ipc_call_async_slow(sc_args, sc_rc);
392 break;
393 case SYS_IPC_WAIT:
394 sc_ipc_wait(sc_args, sc_rc);
395 break;
396 default:
397 break;
398 }
399}
400
401static void event_thread_b(uintptr_t hash)
402{
403 printf("New thread, hash %p\n", (void *) hash);
404 thread_trace_start(hash);
405}
406
407static int trace_loop(void *thread_hash_arg)
408{
409 int rc;
410 unsigned ev_type;
411 uintptr_t thread_hash;
412 unsigned thread_id;
413 sysarg_t val0, val1;
414
415 thread_hash = (uintptr_t)thread_hash_arg;
416 thread_id = next_thread_id++;
417 if (thread_id >= THBUF_SIZE) {
418 printf("Too many threads.\n");
419 return ELIMIT;
420 }
421
422 printf("Start tracing thread [%u] (hash %p).\n",
423 thread_id, (void *) thread_hash);
424
425 while (!abort_trace) {
426
427 fibril_mutex_lock(&state_lock);
428 if (paused) {
429 printf("Thread [%u] paused. Press R to resume.\n",
430 thread_id);
431
432 while (paused)
433 fibril_condvar_wait(&state_cv, &state_lock);
434
435 printf("Thread [%u] resumed.\n", thread_id);
436 }
437 fibril_mutex_unlock(&state_lock);
438
439 /* Run thread until an event occurs */
440 rc = udebug_go(sess, thread_hash,
441 &ev_type, &val0, &val1);
442
443// printf("rc = %d, ev_type=%d\n", rc, ev_type);
444 if (ev_type == UDEBUG_EVENT_FINISHED) {
445 /* Done tracing this thread */
446 break;
447 }
448
449 if (rc >= 0) {
450 switch (ev_type) {
451 case UDEBUG_EVENT_SYSCALL_B:
452 event_syscall_b(thread_id, thread_hash, val0, (int)val1);
453 break;
454 case UDEBUG_EVENT_SYSCALL_E:
455 event_syscall_e(thread_id, thread_hash, val0, (int)val1);
456 break;
457 case UDEBUG_EVENT_STOP:
458 printf("Stop event\n");
459 fibril_mutex_lock(&state_lock);
460 paused = true;
461 fibril_mutex_unlock(&state_lock);
462 break;
463 case UDEBUG_EVENT_THREAD_B:
464 event_thread_b(val0);
465 break;
466 case UDEBUG_EVENT_THREAD_E:
467 printf("Thread %" PRIun " exited.\n", val0);
468 fibril_mutex_lock(&state_lock);
469 abort_trace = true;
470 fibril_condvar_broadcast(&state_cv);
471 fibril_mutex_unlock(&state_lock);
472 break;
473 default:
474 printf("Unknown event type %d.\n", ev_type);
475 break;
476 }
477 }
478
479 }
480
481 printf("Finished tracing thread [%d].\n", thread_id);
482 return 0;
483}
484
485void thread_trace_start(uintptr_t thread_hash)
486{
487 fid_t fid;
488
489 thash = thread_hash;
490
491 fid = fibril_create(trace_loop, (void *)thread_hash);
492 if (fid == 0) {
493 printf("Warning: Failed creating fibril\n");
494 }
495 fibril_add_ready(fid);
496}
497
498static loader_t *preload_task(const char *path, char **argv,
499 task_id_t *task_id)
500{
501 loader_t *ldr;
502 int rc;
503
504 /* Spawn a program loader */
505 ldr = loader_connect();
506 if (ldr == NULL)
507 return NULL;
508
509 /* Get task ID. */
510 rc = loader_get_task_id(ldr, task_id);
511 if (rc != EOK)
512 goto error;
513
514 /* Send program pathname */
515 rc = loader_set_pathname(ldr, path);
516 if (rc != EOK)
517 goto error;
518
519 /* Send arguments */
520 rc = loader_set_args(ldr, (const char **) argv);
521 if (rc != EOK)
522 goto error;
523
524 /* Send default files */
525 int *files[4];
526 int fd_stdin;
527 int fd_stdout;
528 int fd_stderr;
529
530 if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
531 files[0] = &fd_stdin;
532 else
533 files[0] = NULL;
534
535 if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
536 files[1] = &fd_stdout;
537 else
538 files[1] = NULL;
539
540 if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
541 files[2] = &fd_stderr;
542 else
543 files[2] = NULL;
544
545 files[3] = NULL;
546
547 rc = loader_set_files(ldr, files);
548 if (rc != EOK)
549 goto error;
550
551 /* Load the program. */
552 rc = loader_load_program(ldr);
553 if (rc != EOK)
554 goto error;
555
556 /* Success */
557 return ldr;
558
559 /* Error exit */
560error:
561 loader_abort(ldr);
562 return NULL;
563}
564
565static int cev_fibril(void *arg)
566{
567 (void) arg;
568
569 console_ctrl_t *console = console_init(stdin, stdout);
570
571 while (true) {
572 fibril_mutex_lock(&state_lock);
573 while (cev_valid)
574 fibril_condvar_wait(&state_cv, &state_lock);
575 fibril_mutex_unlock(&state_lock);
576
577 if (!console_get_kbd_event(console, &cev))
578 return -1;
579
580 fibril_mutex_lock(&state_lock);
581 cev_valid = true;
582 fibril_condvar_broadcast(&state_cv);
583 fibril_mutex_unlock(&state_lock);
584 }
585}
586
587static void trace_task(task_id_t task_id)
588{
589 kbd_event_t ev;
590 bool done;
591 int i;
592 int rc;
593
594 ipcp_init();
595
596 rc = get_thread_list();
597 if (rc < 0) {
598 printf("Failed to get thread list (error %d)\n", rc);
599 return;
600 }
601
602 abort_trace = false;
603
604 for (i = 0; i < n_threads; i++) {
605 thread_trace_start(thread_hash_buf[i]);
606 }
607
608 done = false;
609
610 while (!done) {
611 fibril_mutex_lock(&state_lock);
612 while (!cev_valid && !abort_trace)
613 fibril_condvar_wait(&state_cv, &state_lock);
614 fibril_mutex_unlock(&state_lock);
615
616 ev = cev;
617
618 fibril_mutex_lock(&state_lock);
619 cev_valid = false;
620 fibril_condvar_broadcast(&state_cv);
621 fibril_mutex_unlock(&state_lock);
622
623 if (abort_trace)
624 break;
625
626 if (ev.type != KEY_PRESS)
627 continue;
628
629 switch (ev.key) {
630 case KC_Q:
631 done = true;
632 break;
633 case KC_P:
634 printf("Pause...\n");
635 rc = udebug_stop(sess, thash);
636 if (rc != EOK)
637 printf("Error: stop -> %d\n", rc);
638 break;
639 case KC_R:
640 fibril_mutex_lock(&state_lock);
641 paused = false;
642 fibril_condvar_broadcast(&state_cv);
643 fibril_mutex_unlock(&state_lock);
644 printf("Resume...\n");
645 break;
646 default:
647 break;
648 }
649 }
650
651 printf("\nTerminate debugging session...\n");
652 abort_trace = true;
653 udebug_end(sess);
654 async_hangup(sess);
655
656 ipcp_cleanup();
657
658 printf("Done\n");
659 return;
660}
661
662static void main_init(void)
663{
664 proto_t *p;
665 oper_t *o;
666
667 val_type_t arg_def[OPER_MAX_ARGS] = {
668 V_INTEGER,
669 V_INTEGER,
670 V_INTEGER,
671 V_INTEGER,
672 V_INTEGER
673 };
674
675 val_type_t resp_def[OPER_MAX_ARGS] = {
676 V_INTEGER,
677 V_INTEGER,
678 V_INTEGER,
679 V_INTEGER,
680 V_INTEGER
681 };
682
683 next_thread_id = 1;
684 paused = false;
685 cev_valid = false;
686
687 fibril_mutex_initialize(&state_lock);
688 fibril_condvar_initialize(&state_cv);
689
690 proto_init();
691
692 p = proto_new("vfs");
693 o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
694 proto_add_oper(p, VFS_IN_OPEN, o);
695 o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
696 proto_add_oper(p, VFS_IN_READ, o);
697 o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
698 proto_add_oper(p, VFS_IN_WRITE, o);
699 o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);
700 proto_add_oper(p, VFS_IN_SEEK, o);
701 o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
702 proto_add_oper(p, VFS_IN_TRUNCATE, o);
703 o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def);
704 proto_add_oper(p, VFS_IN_FSTAT, o);
705 o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def);
706 proto_add_oper(p, VFS_IN_CLOSE, o);
707 o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
708 proto_add_oper(p, VFS_IN_MOUNT, o);
709/* o = oper_new("unmount", 0, arg_def);
710 proto_add_oper(p, VFS_IN_UNMOUNT, o);*/
711 o = oper_new("sync", 1, arg_def, V_ERRNO, 0, resp_def);
712 proto_add_oper(p, VFS_IN_SYNC, o);
713 o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def);
714 proto_add_oper(p, VFS_IN_MKDIR, o);
715 o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def);
716 proto_add_oper(p, VFS_IN_UNLINK, o);
717 o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def);
718 proto_add_oper(p, VFS_IN_RENAME, o);
719 o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def);
720 proto_add_oper(p, VFS_IN_STAT, o);
721
722 proto_register(SERVICE_VFS, p);
723}
724
725static void print_syntax()
726{
727 printf("Syntax:\n");
728 printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
729 printf("or\ttrace [+<events>] -t <task_id>\n");
730 printf("Events: (default is +tp)\n");
731 printf("\n");
732 printf("\tt ... Thread creation and termination\n");
733 printf("\ts ... System calls\n");
734 printf("\ti ... Low-level IPC\n");
735 printf("\tp ... Protocol level\n");
736 printf("\n");
737 printf("Examples:\n");
738 printf("\ttrace +s /app/tetris\n");
739 printf("\ttrace +tsip -t 12\n");
740}
741
742static display_mask_t parse_display_mask(const char *text)
743{
744 display_mask_t dm = 0;
745 const char *c = text;
746
747 while (*c) {
748 switch (*c) {
749 case 't':
750 dm = dm | DM_THREAD;
751 break;
752 case 's':
753 dm = dm | DM_SYSCALL;
754 break;
755 case 'i':
756 dm = dm | DM_IPC;
757 break;
758 case 'p':
759 dm = dm | DM_SYSTEM | DM_USER;
760 break;
761 default:
762 printf("Unexpected event type '%c'.\n", *c);
763 exit(1);
764 }
765
766 ++c;
767 }
768
769 return dm;
770}
771
772static int parse_args(int argc, char *argv[])
773{
774 char *err_p;
775
776 task_id = 0;
777
778 --argc;
779 ++argv;
780
781 while (argc > 0) {
782 char *arg = *argv;
783 if (arg[0] == '+') {
784 display_mask = parse_display_mask(&arg[1]);
785 } else if (arg[0] == '-') {
786 if (arg[1] == 't') {
787 /* Trace an already running task */
788 --argc;
789 ++argv;
790 task_id = strtol(*argv, &err_p, 10);
791 task_ldr = NULL;
792 task_wait_for = false;
793 if (*err_p) {
794 printf("Task ID syntax error\n");
795 print_syntax();
796 return -1;
797 }
798 } else {
799 printf("Uknown option '%c'\n", arg[0]);
800 print_syntax();
801 return -1;
802 }
803 } else {
804 break;
805 }
806
807 --argc;
808 ++argv;
809 }
810
811 if (task_id != 0) {
812 if (argc == 0)
813 return 0;
814 printf("Extra arguments\n");
815 print_syntax();
816 return -1;
817 }
818
819 if (argc < 1) {
820 printf("Missing argument\n");
821 print_syntax();
822 return -1;
823 }
824
825 /* Preload the specified program file. */
826 printf("Spawning '%s' with arguments:\n", *argv);
827
828 char **cp = argv;
829 while (*cp)
830 printf("'%s'\n", *cp++);
831
832 task_ldr = preload_task(*argv, argv, &task_id);
833 task_wait_for = true;
834
835 return 0;
836}
837
838int main(int argc, char *argv[])
839{
840 int rc;
841 task_exit_t texit;
842 int retval;
843
844 printf("System Call / IPC Tracer\n");
845 printf("Controls: Q - Quit, P - Pause, R - Resume\n");
846
847 display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
848
849 if (parse_args(argc, argv) < 0)
850 return 1;
851
852 main_init();
853
854 rc = connect_task(task_id);
855 if (rc < 0) {
856 printf("Failed connecting to task %" PRIu64 ".\n", task_id);
857 return 1;
858 }
859
860 printf("Connected to task %" PRIu64 ".\n", task_id);
861
862 if (task_ldr != NULL)
863 program_run();
864
865 cev_fibril_start();
866 trace_task(task_id);
867
868 if (task_wait_for) {
869 printf("Waiting for task to exit.\n");
870
871 rc = task_wait(task_id, &texit, &retval);
872 if (rc != EOK) {
873 printf("Failed waiting for task.\n");
874 return -1;
875 }
876
877 if (texit == TASK_EXIT_NORMAL) {
878 printf("Task exited normally, return value %d.\n",
879 retval);
880 } else {
881 printf("Task exited unexpectedly.\n");
882 }
883 }
884
885 return 0;
886}
887
888/** @}
889 */
Note: See TracBrowser for help on using the repository browser.