Subversion Repositories HelenOS

Rev

Rev 4581 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4581 Rev 4718
Line 41... Line 41...
41
#include <udebug.h>
41
#include <udebug.h>
42
#include <async.h>
42
#include <async.h>
43
#include <task.h>
43
#include <task.h>
44
#include <mem.h>
44
#include <mem.h>
45
#include <string.h>
45
#include <string.h>
-
 
46
#include <bool.h>
46
#include <loader/loader.h>
47
#include <loader/loader.h>
-
 
48
#include <io/console.h>
-
 
49
#include <io/keycode.h>
-
 
50
#include <fibril_sync.h>
47
 
51
 
48
#include <libc.h>
52
#include <libc.h>
49
 
53
 
50
// Temporary: service and method names
54
// Temporary: service and method names
51
#include "proto.h"
55
#include "proto.h"
Line 62... Line 66...
62
uintptr_t thread_hash_buf[THBUF_SIZE];
66
uintptr_t thread_hash_buf[THBUF_SIZE];
63
int n_threads;
67
int n_threads;
64
 
68
 
65
int next_thread_id;
69
int next_thread_id;
66
 
70
 
-
 
71
ipc_call_t thread_ipc_req[THBUF_SIZE];
-
 
72
 
67
int phoneid;
73
int phoneid;
68
int abort_trace;
74
bool abort_trace;
69
 
75
 
70
uintptr_t thash;
76
uintptr_t thash;
71
volatile int paused;
77
static bool paused;
-
 
78
static fibril_condvar_t state_cv;
-
 
79
static fibril_mutex_t state_lock;
-
 
80
 
-
 
81
static bool cev_valid;
-
 
82
static console_event_t cev;
72
 
83
 
73
void thread_trace_start(uintptr_t thread_hash);
84
void thread_trace_start(uintptr_t thread_hash);
74
 
85
 
75
static proto_t *proto_console;
86
static proto_t *proto_console;
76
static task_id_t task_id;
87
static task_id_t task_id;
77
static loader_t *task_ldr;
88
static loader_t *task_ldr;
-
 
89
static bool task_wait_for;
78
 
90
 
79
/** Combination of events/data to print. */
91
/** Combination of events/data to print. */
80
display_mask_t display_mask;
92
display_mask_t display_mask;
81
 
93
 
82
static int program_run_fibril(void *arg);
94
static int program_run_fibril(void *arg);
-
 
95
static int cev_fibril(void *arg);
83
 
96
 
84
static void program_run(void)
97
static void program_run(void)
85
{
98
{
86
    fid_t fid;
99
    fid_t fid;
87
 
100
 
Line 92... Line 105...
92
    }
105
    }
93
 
106
 
94
    fibril_add_ready(fid);
107
    fibril_add_ready(fid);
95
}
108
}
96
 
109
 
-
 
110
static void cev_fibril_start(void)
-
 
111
{
-
 
112
    fid_t fid;
-
 
113
 
-
 
114
    fid = fibril_create(cev_fibril, NULL);
-
 
115
    if (fid == 0) {
-
 
116
        printf("Error creating fibril\n");
-
 
117
        exit(1);
-
 
118
    }
-
 
119
 
-
 
120
    fibril_add_ready(fid);
-
 
121
}
-
 
122
 
97
static int program_run_fibril(void *arg)
123
static int program_run_fibril(void *arg)
98
{
124
{
99
    int rc;
125
    int rc;
100
 
126
 
101
    /*
127
    /*
Line 178... Line 204...
178
    return 0;
204
    return 0;
179
}
205
}
180
 
206
 
181
void val_print(sysarg_t val, val_type_t v_type)
207
void val_print(sysarg_t val, val_type_t v_type)
182
{
208
{
-
 
209
    long sval;
-
 
210
 
-
 
211
    sval = (long) val;
-
 
212
 
183
    switch (v_type) {
213
    switch (v_type) {
184
    case V_VOID:
214
    case V_VOID:
185
        printf("<void>");
215
        printf("<void>");
186
        break;
216
        break;
187
 
217
 
188
    case V_INTEGER:
218
    case V_INTEGER:
189
        printf("%ld", val);
219
        printf("%ld", sval);
190
        break;
220
        break;
191
 
221
 
192
    case V_HASH:
222
    case V_HASH:
193
    case V_PTR:
223
    case V_PTR:
194
        printf("0x%08lx", val);
224
        printf("0x%08lx", val);
195
        break;
225
        break;
196
 
226
 
197
    case V_ERRNO:
227
    case V_ERRNO:
198
        if (val >= -15 && val <= 0) {
228
        if (sval >= -15 && sval <= 0) {
199
            printf("%ld %s (%s)", val,
229
            printf("%ld %s (%s)", sval,
200
                err_desc[-val].name,
230
                err_desc[-sval].name,
201
                err_desc[-val].desc);
231
                err_desc[-sval].desc);
202
        } else {
232
        } else {
203
            printf("%ld", val);
233
            printf("%ld", sval);
204
        }
234
        }
205
        break;
235
        break;
206
    case V_INT_ERRNO:
236
    case V_INT_ERRNO:
207
        if (val >= -15 && val < 0) {
237
        if (sval >= -15 && sval < 0) {
208
            printf("%ld %s (%s)", val,
238
            printf("%ld %s (%s)", sval,
209
                err_desc[-val].name,
239
                err_desc[-sval].name,
210
                err_desc[-val].desc);
240
                err_desc[-sval].desc);
211
        } else {
241
        } else {
212
            printf("%ld", val);
242
            printf("%ld", sval);
213
        }
243
        }
214
        break;
244
        break;
215
 
245
 
216
    case V_CHAR:
246
    case V_CHAR:
217
        if (val >= 0x20 && val < 0x7f) {
247
        if (sval >= 0x20 && sval < 0x7f) {
218
            printf("'%c'", val);
248
            printf("'%c'", sval);
219
        } else {
249
        } else {
220
            switch (val) {
250
            switch (sval) {
221
            case '\a': printf("'\\a'"); break;
251
            case '\a': printf("'\\a'"); break;
222
            case '\b': printf("'\\b'"); break;
252
            case '\b': printf("'\\b'"); break;
223
            case '\n': printf("'\\n'"); break;
253
            case '\n': printf("'\\n'"); break;
224
            case '\r': printf("'\\r'"); break;
254
            case '\r': printf("'\\r'"); break;
225
            case '\t': printf("'\\t'"); break;
255
            case '\t': printf("'\\t'"); break;
Line 254... Line 284...
254
static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc)
284
static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc)
255
{
285
{
256
    ipc_call_t call;
286
    ipc_call_t call;
257
    ipcarg_t phoneid;
287
    ipcarg_t phoneid;
258
   
288
   
-
 
289
    if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
259
    if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
290
        sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY)
260
        return;
291
        return;
261
 
292
 
262
    phoneid = sc_args[0];
293
    phoneid = sc_args[0];
263
 
294
 
264
    IPC_SET_METHOD(call, sc_args[1]);
295
    IPC_SET_METHOD(call, sc_args[1]);
Line 274... Line 305...
274
static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc)
305
static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc)
275
{
306
{
276
    ipc_call_t call;
307
    ipc_call_t call;
277
    int rc;
308
    int rc;
278
 
309
 
-
 
310
    if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
279
    if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
311
        sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY)
280
        return;
312
        return;
281
 
313
 
282
    memset(&call, 0, sizeof(call));
314
    memset(&call, 0, sizeof(call));
283
    rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
315
    rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
284
 
316
 
Line 313... Line 345...
313
 
345
 
314
//  printf("call ipc_call_sync\n");
346
//  printf("call ipc_call_sync\n");
315
    ipcp_call_sync(phoneidx, &question, &reply);
347
    ipcp_call_sync(phoneidx, &question, &reply);
316
}
348
}
317
 
349
 
318
static void sc_ipc_call_sync_slow(sysarg_t *sc_args)
350
static void sc_ipc_call_sync_slow_b(unsigned thread_id, sysarg_t *sc_args)
319
{
351
{
320
    ipc_call_t question, reply;
352
    ipc_call_t question;
321
    int rc;
353
    int rc;
322
 
354
 
323
    memset(&question, 0, sizeof(question));
355
    memset(&question, 0, sizeof(question));
324
    rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args));
356
    rc = udebug_mem_read(phoneid, &question.args, sc_args[1],
-
 
357
        sizeof(question.args));
-
 
358
 
-
 
359
    if (rc < 0) {
325
    printf("dmr->%d\n", rc);
360
        printf("Error: mem_read->%d\n", rc);
-
 
361
        return;
-
 
362
    }
-
 
363
 
-
 
364
    thread_ipc_req[thread_id] = question;
-
 
365
}
-
 
366
 
-
 
367
static void sc_ipc_call_sync_slow_e(unsigned thread_id, sysarg_t *sc_args)
-
 
368
{
326
    if (rc < 0) return;
369
    ipc_call_t reply;
-
 
370
    int rc;
327
 
371
 
328
    memset(&reply, 0, sizeof(reply));
372
    memset(&reply, 0, sizeof(reply));
329
    rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args));
373
    rc = udebug_mem_read(phoneid, &reply.args, sc_args[2],
-
 
374
        sizeof(reply.args));
-
 
375
 
-
 
376
    if (rc < 0) {
330
    printf("dmr->%d\n", rc);
377
        printf("Error: mem_read->%d\n", rc);
331
    if (rc < 0) return;
378
        return;
-
 
379
    }
332
 
380
 
333
    ipcp_call_sync(sc_args[0], &question, &reply);
381
    ipcp_call_sync(sc_args[0], &thread_ipc_req[thread_id], &reply);
334
}
382
}
335
 
383
 
336
static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
384
static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
337
{
385
{
338
    ipc_call_t call;
386
    ipc_call_t call;
Line 373... Line 421...
373
        /* Print syscall name and arguments */
421
        /* Print syscall name and arguments */
374
        printf("%s", syscall_desc[sc_id].name);
422
        printf("%s", syscall_desc[sc_id].name);
375
        print_sc_args(sc_args, syscall_desc[sc_id].n_args);
423
        print_sc_args(sc_args, syscall_desc[sc_id].n_args);
376
    }
424
    }
377
 
425
 
-
 
426
    switch (sc_id) {
-
 
427
    case SYS_IPC_CALL_SYNC_SLOW:
-
 
428
        sc_ipc_call_sync_slow_b(thread_id, sc_args);
-
 
429
        break;
-
 
430
    default:
-
 
431
        break;
-
 
432
    }
-
 
433
 
378
    async_serialize_end();
434
    async_serialize_end();
379
}
435
}
380
 
436
 
381
static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash,
437
static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash,
382
    unsigned sc_id, sysarg_t sc_rc)
438
    unsigned sc_id, sysarg_t sc_rc)
Line 413... Line 469...
413
        break;
469
        break;
414
    case SYS_IPC_CALL_SYNC_FAST:
470
    case SYS_IPC_CALL_SYNC_FAST:
415
        sc_ipc_call_sync_fast(sc_args);
471
        sc_ipc_call_sync_fast(sc_args);
416
        break;
472
        break;
417
    case SYS_IPC_CALL_SYNC_SLOW:
473
    case SYS_IPC_CALL_SYNC_SLOW:
418
        sc_ipc_call_sync_slow(sc_args);
474
        sc_ipc_call_sync_slow_e(thread_id, sc_args);
419
        break;
475
        break;
420
    case SYS_IPC_WAIT:
476
    case SYS_IPC_WAIT:
421
        sc_ipc_wait(sc_args, sc_rc);
477
        sc_ipc_wait(sc_args, sc_rc);
422
        break;
478
        break;
423
    default:
479
    default:
Line 444... Line 500...
444
    unsigned thread_id;
500
    unsigned thread_id;
445
    sysarg_t val0, val1;
501
    sysarg_t val0, val1;
446
 
502
 
447
    thread_hash = (uintptr_t)thread_hash_arg;
503
    thread_hash = (uintptr_t)thread_hash_arg;
448
    thread_id = next_thread_id++;
504
    thread_id = next_thread_id++;
-
 
505
    if (thread_id >= THBUF_SIZE) {
-
 
506
        printf("Too many threads.\n");
-
 
507
        return ELIMIT;
-
 
508
    }
449
 
509
 
450
    printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash);
510
    printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash);
451
 
511
 
452
    while (!abort_trace) {
512
    while (!abort_trace) {
453
 
513
 
-
 
514
        fibril_mutex_lock(&state_lock);
454
        if (paused) {
515
        if (paused) {
455
            printf("Press R to resume (and be patient).\n");
516
            printf("Thread [%d] paused. Press R to resume.\n",
456
            while (paused) {
517
                thread_id);
-
 
518
 
457
                usleep(1000000);
519
            while (paused)
458
                fibril_yield();
520
                fibril_condvar_wait(&state_cv, &state_lock);
459
                printf(".");
-
 
460
            }
521
 
461
            printf("Resumed\n");
522
            printf("Thread [%d] resumed.\n", thread_id);
462
        }
523
        }
-
 
524
        fibril_mutex_unlock(&state_lock);
463
 
525
 
464
        /* Run thread until an event occurs */
526
        /* Run thread until an event occurs */
465
        rc = udebug_go(phoneid, thread_hash,
527
        rc = udebug_go(phoneid, thread_hash,
466
            &ev_type, &val0, &val1);
528
            &ev_type, &val0, &val1);
467
 
529
 
Line 479... Line 541...
479
            case UDEBUG_EVENT_SYSCALL_E:
541
            case UDEBUG_EVENT_SYSCALL_E:
480
                event_syscall_e(thread_id, thread_hash, val0, (int)val1);
542
                event_syscall_e(thread_id, thread_hash, val0, (int)val1);
481
                break;
543
                break;
482
            case UDEBUG_EVENT_STOP:
544
            case UDEBUG_EVENT_STOP:
483
                printf("Stop event\n");
545
                printf("Stop event\n");
-
 
546
                fibril_mutex_lock(&state_lock);
-
 
547
                paused = true;
-
 
548
                fibril_mutex_unlock(&state_lock);
484
                break;
549
                break;
485
            case UDEBUG_EVENT_THREAD_B:
550
            case UDEBUG_EVENT_THREAD_B:
486
                event_thread_b(val0);
551
                event_thread_b(val0);
487
                break;
552
                break;
488
            case UDEBUG_EVENT_THREAD_E:
553
            case UDEBUG_EVENT_THREAD_E:
489
                printf("Thread 0x%lx exited.\n", val0);
554
                printf("Thread 0x%lx exited.\n", val0);
-
 
555
                fibril_mutex_lock(&state_lock);
490
                abort_trace = 1;
556
                abort_trace = true;
-
 
557
                fibril_condvar_broadcast(&state_cv);
-
 
558
                fibril_mutex_unlock(&state_lock);
491
                break;
559
                break;
492
            default:
560
            default:
493
                printf("Unknown event type %d.\n", ev_type);
561
                printf("Unknown event type %d.\n", ev_type);
494
                break;
562
                break;
495
            }
563
            }
Line 538... Line 606...
538
    /* Send arguments */
606
    /* Send arguments */
539
    rc = loader_set_args(ldr, argv);
607
    rc = loader_set_args(ldr, argv);
540
    if (rc != EOK)
608
    if (rc != EOK)
541
        goto error;
609
        goto error;
542
 
610
 
-
 
611
    /* Send default files */
-
 
612
    fdi_node_t *files[4];
-
 
613
    fdi_node_t stdin_node;
-
 
614
    fdi_node_t stdout_node;
-
 
615
    fdi_node_t stderr_node;
-
 
616
   
-
 
617
    if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
-
 
618
        files[0] = &stdin_node;
-
 
619
    else
-
 
620
        files[0] = NULL;
-
 
621
   
-
 
622
    if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
-
 
623
        files[1] = &stdout_node;
-
 
624
    else
-
 
625
        files[1] = NULL;
-
 
626
   
-
 
627
    if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
-
 
628
        files[2] = &stderr_node;
-
 
629
    else
-
 
630
        files[2] = NULL;
-
 
631
   
-
 
632
    files[3] = NULL;
-
 
633
   
-
 
634
    rc = loader_set_files(ldr, files);
-
 
635
    if (rc != EOK)
-
 
636
        goto error;
-
 
637
 
543
    /* Load the program. */
638
    /* Load the program. */
544
    rc = loader_load_program(ldr);
639
    rc = loader_load_program(ldr);
545
    if (rc != EOK)
640
    if (rc != EOK)
546
        goto error;
641
        goto error;
547
 
642
 
Line 553... Line 648...
553
    loader_abort(ldr);
648
    loader_abort(ldr);
554
    free(ldr);
649
    free(ldr);
555
    return NULL;
650
    return NULL;
556
}
651
}
557
 
652
 
-
 
653
static int cev_fibril(void *arg)
-
 
654
{
-
 
655
    (void) arg;
-
 
656
 
-
 
657
    while (true) {
-
 
658
        fibril_mutex_lock(&state_lock);
-
 
659
        while (cev_valid)
-
 
660
            fibril_condvar_wait(&state_cv, &state_lock);
-
 
661
        fibril_mutex_unlock(&state_lock);
-
 
662
 
-
 
663
        if (!console_get_event(fphone(stdin), &cev))
-
 
664
            return -1;
-
 
665
 
-
 
666
        fibril_mutex_lock(&state_lock);
-
 
667
        cev_valid = true;
-
 
668
        fibril_condvar_broadcast(&state_cv);
-
 
669
        fibril_mutex_unlock(&state_lock);      
-
 
670
    }
-
 
671
}
-
 
672
 
558
static void trace_task(task_id_t task_id)
673
static void trace_task(task_id_t task_id)
559
{
674
{
-
 
675
    console_event_t ev;
-
 
676
    bool done;
560
    int i;
677
    int i;
561
    int rc;
678
    int rc;
562
    int c;
-
 
563
 
679
 
564
    ipcp_init();
680
    ipcp_init();
565
 
681
 
566
    /*
682
    /*
567
     * User apps now typically have console on phone 3.
683
     * User apps now typically have console on phone 3.
Line 573... Line 689...
573
    if (rc < 0) {
689
    if (rc < 0) {
574
        printf("Failed to get thread list (error %d)\n", rc);
690
        printf("Failed to get thread list (error %d)\n", rc);
575
        return;
691
        return;
576
    }
692
    }
577
 
693
 
578
    abort_trace = 0;
694
    abort_trace = false;
579
 
695
 
580
    for (i = 0; i < n_threads; i++) {
696
    for (i = 0; i < n_threads; i++) {
581
        thread_trace_start(thread_hash_buf[i]);
697
        thread_trace_start(thread_hash_buf[i]);
582
    }
698
    }
583
 
699
 
-
 
700
    done = false;
-
 
701
 
584
    while(1) {
702
    while (!done) {
-
 
703
        fibril_mutex_lock(&state_lock);
-
 
704
        while (!cev_valid && !abort_trace)
-
 
705
            fibril_condvar_wait(&state_cv, &state_lock);
-
 
706
        fibril_mutex_unlock(&state_lock);
-
 
707
 
585
        c = getchar();
708
        ev = cev;
-
 
709
 
-
 
710
        fibril_mutex_lock(&state_lock);
-
 
711
        cev_valid = false;
-
 
712
        fibril_condvar_broadcast(&state_cv);
-
 
713
        fibril_mutex_unlock(&state_lock);
-
 
714
 
586
        if (c == 'q') break;
715
        if (abort_trace)
-
 
716
            break;
-
 
717
 
-
 
718
        if (ev.type != KEY_PRESS)
-
 
719
            continue;
-
 
720
 
587
        if (c == 'p') {
721
        switch (ev.key) {
-
 
722
        case KC_Q:
-
 
723
            done = true;
-
 
724
            break;
-
 
725
        case KC_P:
588
            printf("Pause...\n");
726
            printf("Pause...\n");
589
            paused = 1;
-
 
590
            rc = udebug_stop(phoneid, thash);
727
            rc = udebug_stop(phoneid, thash);
-
 
728
            if (rc != EOK)
591
            printf("stop -> %d\n", rc);
729
                printf("Error: stop -> %d\n", rc);
592
        }
730
            break;
593
        if (c == 'r') {
731
        case KC_R:
-
 
732
            fibril_mutex_lock(&state_lock);
594
            paused = 0;
733
            paused = false;
-
 
734
            fibril_condvar_broadcast(&state_cv);
-
 
735
            fibril_mutex_unlock(&state_lock);
595
            printf("Resume...\n");
736
            printf("Resume...\n");
-
 
737
            break;
596
        }
738
        }
597
    }
739
    }
598
 
740
 
599
    printf("\nTerminate debugging session...\n");
741
    printf("\nTerminate debugging session...\n");
600
    abort_trace = 1;
742
    abort_trace = true;
601
    udebug_end(phoneid);
743
    udebug_end(phoneid);
602
    ipc_hangup(phoneid);
744
    ipc_hangup(phoneid);
603
 
745
 
604
    ipcp_cleanup();
746
    ipcp_cleanup();
605
 
747
 
Line 627... Line 769...
627
        V_INTEGER,
769
        V_INTEGER,
628
        V_INTEGER
770
        V_INTEGER
629
    };
771
    };
630
 
772
 
631
    next_thread_id = 1;
773
    next_thread_id = 1;
632
    paused = 0;
774
    paused = false;
-
 
775
    cev_valid = false;
-
 
776
 
-
 
777
    fibril_mutex_initialize(&state_lock);
-
 
778
    fibril_condvar_initialize(&state_cv);
633
 
779
 
634
    proto_init();
780
    proto_init();
635
 
781
 
636
    p = proto_new("vfs");
782
    p = proto_new("vfs");
-
 
783
    o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
-
 
784
    proto_add_oper(p, VFS_IN_OPEN, o);
-
 
785
    o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def);
-
 
786
    proto_add_oper(p, VFS_IN_OPEN_NODE, o);
637
    o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
787
    o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
638
    proto_add_oper(p, VFS_READ, o);
788
    proto_add_oper(p, VFS_IN_READ, o);
639
    o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
789
    o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
640
    proto_add_oper(p, VFS_WRITE, o);
790
    proto_add_oper(p, VFS_IN_WRITE, o);
-
 
791
    o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);
-
 
792
    proto_add_oper(p, VFS_IN_SEEK, o);
641
    o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
793
    o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
642
    proto_add_oper(p, VFS_TRUNCATE, o);
794
    proto_add_oper(p, VFS_IN_TRUNCATE, o);
-
 
795
    o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def);
-
 
796
    proto_add_oper(p, VFS_IN_FSTAT, o);
-
 
797
    o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def);
-
 
798
    proto_add_oper(p, VFS_IN_CLOSE, o);
643
    o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
799
    o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
644
    proto_add_oper(p, VFS_MOUNT, o);
800
    proto_add_oper(p, VFS_IN_MOUNT, o);
645
/*  o = oper_new("unmount", 0, arg_def);
801
/*  o = oper_new("unmount", 0, arg_def);
646
    proto_add_oper(p, VFS_UNMOUNT, o);*/
802
    proto_add_oper(p, VFS_IN_UNMOUNT, o);*/
647
    o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
-
 
648
    proto_add_oper(p, VFS_OPEN, o);
-
 
649
    o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def);
-
 
650
    proto_add_oper(p, VFS_CLOSE, o);
-
 
651
    o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);
803
    o = oper_new("sync", 1, arg_def, V_ERRNO, 0, resp_def);
652
    proto_add_oper(p, VFS_SEEK, o);
804
    proto_add_oper(p, VFS_IN_SYNC, o);
653
    o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def);
805
    o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def);
654
    proto_add_oper(p, VFS_MKDIR, o);
806
    proto_add_oper(p, VFS_IN_MKDIR, o);
655
    o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def);
807
    o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def);
656
    proto_add_oper(p, VFS_UNLINK, o);
808
    proto_add_oper(p, VFS_IN_UNLINK, o);
657
    o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def);
809
    o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def);
658
    proto_add_oper(p, VFS_RENAME, o);
810
    proto_add_oper(p, VFS_IN_RENAME, o);
-
 
811
    o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def);
-
 
812
    proto_add_oper(p, VFS_IN_STAT, o);
659
 
813
 
660
    proto_register(SERVICE_VFS, p);
814
    proto_register(SERVICE_VFS, p);
661
 
815
 
662
    p = proto_new("console");
816
    p = proto_new("console");
-
 
817
 
-
 
818
    o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
-
 
819
    proto_add_oper(p, VFS_IN_WRITE, o);
-
 
820
 
663
    resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
821
    resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
664
    resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR;
822
    resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR;
665
    o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def);
823
    o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def);
666
 
824
 
667
    arg_def[0] = V_CHAR;
825
    arg_def[0] = V_CHAR;
Line 750... Line 908...
750
            if (arg[1] == 't') {
908
            if (arg[1] == 't') {
751
                /* Trace an already running task */
909
                /* Trace an already running task */
752
                --argc; ++argv;
910
                --argc; ++argv;
753
                task_id = strtol(*argv, &err_p, 10);
911
                task_id = strtol(*argv, &err_p, 10);
754
                task_ldr = NULL;
912
                task_ldr = NULL;
-
 
913
                task_wait_for = false;
755
                if (*err_p) {
914
                if (*err_p) {
756
                    printf("Task ID syntax error\n");
915
                    printf("Task ID syntax error\n");
757
                    print_syntax();
916
                    print_syntax();
758
                    return -1;
917
                    return -1;
759
                }
918
                }
Line 787... Line 946...
787
    {
946
    {
788
        char **cp = argv;
947
        char **cp = argv;
789
        while (*cp) printf("'%s'\n", *cp++);
948
        while (*cp) printf("'%s'\n", *cp++);
790
    }
949
    }
791
    task_ldr = preload_task(*argv, argv, &task_id);
950
    task_ldr = preload_task(*argv, argv, &task_id);
-
 
951
    task_wait_for = true;
792
 
952
 
793
    return 0;
953
    return 0;
794
}
954
}
795
 
955
 
796
int main(int argc, char *argv[])
956
int main(int argc, char *argv[])
797
{
957
{
798
    int rc;
958
    int rc;
-
 
959
    task_exit_t texit;
-
 
960
    int retval;
799
 
961
 
800
    printf("System Call / IPC Tracer\n");
962
    printf("System Call / IPC Tracer\n");
801
    printf("Controls: Q - Quit, P - Pause, R - Resume\n");
963
    printf("Controls: Q - Quit, P - Pause, R - Resume\n");
802
 
964
 
803
    display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
965
    display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
Line 813... Line 975...
813
        return 1;
975
        return 1;
814
    }
976
    }
815
 
977
 
816
    printf("Connected to task %lld.\n", task_id);
978
    printf("Connected to task %lld.\n", task_id);
817
 
979
 
818
    if (task_ldr != NULL) {
980
    if (task_ldr != NULL)
819
        program_run();
981
        program_run();
820
    }
-
 
821
 
982
 
-
 
983
    cev_fibril_start();
822
    trace_task(task_id);
984
    trace_task(task_id);
823
 
985
 
-
 
986
    if (task_wait_for) {
-
 
987
        printf("Waiting for task to exit.\n");
-
 
988
 
-
 
989
        rc = task_wait(task_id, &texit, &retval);
-
 
990
        if (rc != EOK) {
-
 
991
            printf("Failed waiting for task.\n");
-
 
992
            return -1;
-
 
993
        }
-
 
994
 
-
 
995
        if (texit == TASK_EXIT_NORMAL) {
-
 
996
            printf("Task exited normally, return value %d.\n",
-
 
997
                retval);
-
 
998
        } else {
-
 
999
            printf("Task exited unexpectedly.\n");
-
 
1000
        }
-
 
1001
    }
-
 
1002
 
824
    return 0;
1003
    return 0;
825
}
1004
}
826
 
1005
 
827
/** @}
1006
/** @}
828
 */
1007
 */