~helenos-nicf/helenos/nicf

« back to all changes in this revision

Viewing changes to uspace/app/trace/trace.c

  • Committer: Radim Vansa
  • Date: 2011-09-20 21:55:59 UTC
  • mfrom: (697.1.517 HelenOS.mainline)
  • Revision ID: radim.vansa@matfyz.cz-20110920215559-7fjpai6wt5ieurcq
Merge with mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include <fibril_synch.h>
50
50
#include <sys/types.h>
51
51
#include <sys/typefmt.h>
 
52
#include <vfs/vfs.h>
52
53
 
53
54
#include <libc.h>
54
55
 
71
72
 
72
73
ipc_call_t thread_ipc_req[THBUF_SIZE];
73
74
 
74
 
int phoneid;
 
75
async_sess_t *sess;
75
76
bool abort_trace;
76
77
 
77
78
uintptr_t thash;
80
81
static fibril_mutex_t state_lock;
81
82
 
82
83
static bool cev_valid;
83
 
static console_event_t cev;
 
84
static kbd_event_t cev;
84
85
 
85
86
void thread_trace_start(uintptr_t thread_hash);
86
87
 
145
146
 
146
147
static int connect_task(task_id_t task_id)
147
148
{
148
 
        int rc;
149
 
 
150
 
        rc = async_connect_kbox(task_id);
151
 
 
152
 
        if (rc == ENOTSUP) {
153
 
                printf("You do not have userspace debugging support "
154
 
                    "compiled in the kernel.\n");
155
 
                printf("Compile kernel with 'Support for userspace debuggers' "
156
 
                    "(CONFIG_UDEBUG) enabled.\n");
157
 
                return rc;
158
 
        }
159
 
 
160
 
        if (rc < 0) {
 
149
        async_sess_t *ksess = async_connect_kbox(task_id);
 
150
        
 
151
        if (!ksess) {
 
152
                if (errno == ENOTSUP) {
 
153
                        printf("You do not have userspace debugging support "
 
154
                            "compiled in the kernel.\n");
 
155
                        printf("Compile kernel with 'Support for userspace debuggers' "
 
156
                            "(CONFIG_UDEBUG) enabled.\n");
 
157
                        return errno;
 
158
                }
 
159
                
161
160
                printf("Error connecting\n");
162
 
                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc);
163
 
                return rc;
 
161
                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno);
 
162
                return errno;
164
163
        }
165
 
 
166
 
        phoneid = rc;
167
 
 
168
 
        rc = udebug_begin(phoneid);
 
164
        
 
165
        int rc = udebug_begin(ksess);
169
166
        if (rc < 0) {
170
167
                printf("udebug_begin() -> %d\n", rc);
171
168
                return rc;
172
169
        }
173
 
 
174
 
        rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL);
 
170
        
 
171
        rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL);
175
172
        if (rc < 0) {
176
173
                printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
177
174
                return rc;
178
175
        }
179
 
 
 
176
        
 
177
        sess = ksess;
180
178
        return 0;
181
179
}
182
180
 
187
185
        size_t tb_needed;
188
186
        int i;
189
187
 
190
 
        rc = udebug_thread_read(phoneid, thread_hash_buf,
 
188
        rc = udebug_thread_read(sess, thread_hash_buf,
191
189
                THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
192
190
        if (rc < 0) {
193
191
                printf("udebug_thread_read() -> %d\n", rc);
313
311
                return;
314
312
 
315
313
        memset(&call, 0, sizeof(call));
316
 
        rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
 
314
        rc = udebug_mem_read(sess, &call.args, sc_args[1], sizeof(call.args));
317
315
 
318
316
        if (rc >= 0) {
319
317
                ipcp_call_out(sc_args[0], &call, sc_rc);
324
322
{
325
323
        ipc_call_t question, reply;
326
324
        int rc;
327
 
        int phoneidx;
 
325
        int phoneid;
328
326
 
329
 
//      printf("sc_ipc_call_sync_fast()\n");
330
 
        phoneidx = sc_args[0];
 
327
        phoneid = sc_args[0];
331
328
 
332
329
        IPC_SET_IMETHOD(question, sc_args[1]);
333
330
        IPC_SET_ARG1(question, sc_args[2]);
336
333
        IPC_SET_ARG4(question, 0);
337
334
        IPC_SET_ARG5(question, 0);
338
335
 
339
 
//      printf("memset\n");
340
336
        memset(&reply, 0, sizeof(reply));
341
 
//      printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n",
342
 
//              phoneid, &reply.args, sc_args[5], sizeof(reply.args));
343
 
        rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args));
344
 
//      printf("dmr->%d\n", rc);
345
 
        if (rc < 0) return;
346
 
 
347
 
//      printf("call ipc_call_sync\n");
348
 
        ipcp_call_sync(phoneidx, &question, &reply);
 
337
        rc = udebug_mem_read(sess, &reply.args, sc_args[5], sizeof(reply.args));
 
338
        if (rc < 0)
 
339
                return;
 
340
        
 
341
        ipcp_call_sync(phoneid, &question, &reply);
349
342
}
350
343
 
351
344
static void sc_ipc_call_sync_slow_b(unsigned thread_id, sysarg_t *sc_args)
354
347
        int rc;
355
348
 
356
349
        memset(&question, 0, sizeof(question));
357
 
        rc = udebug_mem_read(phoneid, &question.args, sc_args[1],
 
350
        rc = udebug_mem_read(sess, &question.args, sc_args[1],
358
351
            sizeof(question.args));
359
352
 
360
353
        if (rc < 0) {
371
364
        int rc;
372
365
 
373
366
        memset(&reply, 0, sizeof(reply));
374
 
        rc = udebug_mem_read(phoneid, &reply.args, sc_args[2],
 
367
        rc = udebug_mem_read(sess, &reply.args, sc_args[2],
375
368
            sizeof(reply.args));
376
369
 
377
370
        if (rc < 0) {
390
383
        if (sc_rc == 0) return;
391
384
 
392
385
        memset(&call, 0, sizeof(call));
393
 
        rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call));
394
 
//      printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n",
395
 
//              phoneid, (int)&call, sc_args[0], sizeof(call), rc);
396
 
 
397
 
        if (rc >= 0) {
 
386
        rc = udebug_mem_read(sess, &call, sc_args[0], sizeof(call));
 
387
        
 
388
        if (rc >= 0)
398
389
                ipcp_call_in(&call, sc_rc);
399
 
        }
400
390
}
401
391
 
402
392
static void event_syscall_b(unsigned thread_id, uintptr_t thread_hash,
406
396
        int rc;
407
397
 
408
398
        /* Read syscall arguments */
409
 
        rc = udebug_args_read(phoneid, thread_hash, sc_args);
410
 
 
411
 
        async_serialize_start();
412
 
 
413
 
//      printf("[%d] ", thread_id);
 
399
        rc = udebug_args_read(sess, thread_hash, sc_args);
414
400
 
415
401
        if (rc < 0) {
416
402
                printf("error\n");
417
 
                async_serialize_end();
418
403
                return;
419
404
        }
420
405
 
431
416
        default:
432
417
                break;
433
418
        }
434
 
 
435
 
        async_serialize_end();
436
419
}
437
420
 
438
421
static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash,
443
426
        int rc;
444
427
 
445
428
        /* Read syscall arguments */
446
 
        rc = udebug_args_read(phoneid, thread_hash, sc_args);
447
 
 
448
 
        async_serialize_start();
 
429
        rc = udebug_args_read(sess, thread_hash, sc_args);
449
430
 
450
431
//      printf("[%d] ", thread_id);
451
432
 
452
433
        if (rc < 0) {
453
434
                printf("error\n");
454
 
                async_serialize_end();
455
435
                return;
456
436
        }
457
437
 
480
460
        default:
481
461
                break;
482
462
        }
483
 
 
484
 
        async_serialize_end();
485
463
}
486
464
 
487
465
static void event_thread_b(uintptr_t hash)
488
466
{
489
 
        async_serialize_start();
490
467
        printf("New thread, hash %p\n", (void *) hash);
491
 
        async_serialize_end();
492
 
 
493
468
        thread_trace_start(hash);
494
469
}
495
470
 
526
501
                fibril_mutex_unlock(&state_lock);
527
502
 
528
503
                /* Run thread until an event occurs */
529
 
                rc = udebug_go(phoneid, thread_hash,
 
504
                rc = udebug_go(sess, thread_hash,
530
505
                    &ev_type, &val0, &val1);
531
506
 
532
507
//              printf("rc = %d, ev_type=%d\n", rc, ev_type);
611
586
                goto error;
612
587
 
613
588
        /* Send default files */
614
 
        fdi_node_t *files[4];
615
 
        fdi_node_t stdin_node;
616
 
        fdi_node_t stdout_node;
617
 
        fdi_node_t stderr_node;
 
589
        int *files[4];
 
590
        int fd_stdin;
 
591
        int fd_stdout;
 
592
        int fd_stderr;
618
593
        
619
 
        if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
620
 
                files[0] = &stdin_node;
 
594
        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
 
595
                files[0] = &fd_stdin;
621
596
        else
622
597
                files[0] = NULL;
623
598
        
624
 
        if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
625
 
                files[1] = &stdout_node;
 
599
        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
 
600
                files[1] = &fd_stdout;
626
601
        else
627
602
                files[1] = NULL;
628
603
        
629
 
        if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
630
 
                files[2] = &stderr_node;
 
604
        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
 
605
                files[2] = &fd_stderr;
631
606
        else
632
607
                files[2] = NULL;
633
608
        
655
630
static int cev_fibril(void *arg)
656
631
{
657
632
        (void) arg;
658
 
 
 
633
        
 
634
        console_ctrl_t *console = console_init(stdin, stdout);
 
635
        
659
636
        while (true) {
660
637
                fibril_mutex_lock(&state_lock);
661
638
                while (cev_valid)
662
639
                        fibril_condvar_wait(&state_cv, &state_lock);
663
640
                fibril_mutex_unlock(&state_lock);
664
 
 
665
 
                if (!console_get_event(fphone(stdin), &cev))
 
641
                
 
642
                if (!console_get_kbd_event(console, &cev))
666
643
                        return -1;
667
 
 
 
644
                
668
645
                fibril_mutex_lock(&state_lock);
669
646
                cev_valid = true;
670
647
                fibril_condvar_broadcast(&state_cv);
671
 
                fibril_mutex_unlock(&state_lock);               
 
648
                fibril_mutex_unlock(&state_lock);
672
649
        }
673
650
}
674
651
 
675
652
static void trace_task(task_id_t task_id)
676
653
{
677
 
        console_event_t ev;
 
654
        kbd_event_t ev;
678
655
        bool done;
679
656
        int i;
680
657
        int rc;
726
703
                        break;
727
704
                case KC_P:
728
705
                        printf("Pause...\n");
729
 
                        rc = udebug_stop(phoneid, thash);
 
706
                        rc = udebug_stop(sess, thash);
730
707
                        if (rc != EOK)
731
708
                                printf("Error: stop -> %d\n", rc);
732
709
                        break;
742
719
 
743
720
        printf("\nTerminate debugging session...\n");
744
721
        abort_trace = true;
745
 
        udebug_end(phoneid);
746
 
        async_hangup(phoneid);
 
722
        udebug_end(sess);
 
723
        async_hangup(sess);
747
724
 
748
725
        ipcp_cleanup();
749
726
 
784
761
        p = proto_new("vfs");
785
762
        o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
786
763
        proto_add_oper(p, VFS_IN_OPEN, o);
787
 
        o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def);
788
 
        proto_add_oper(p, VFS_IN_OPEN_NODE, o);
789
764
        o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
790
765
        proto_add_oper(p, VFS_IN_READ, o);
791
766
        o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
815
790
 
816
791
        proto_register(SERVICE_VFS, p);
817
792
 
 
793
#if 0
818
794
        p = proto_new("console");
819
795
 
820
796
        o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
850
826
 
851
827
        proto_console = p;
852
828
        proto_register(SERVICE_CONSOLE, p);
 
829
#endif
853
830
}
854
831
 
855
832
static void print_syntax()