Rev 4655 | Rev 4657 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4655 | Rev 4656 | ||
|---|---|---|---|
| Line 70... | Line 70... | ||
| 70 | int phoneid; |
70 | int phoneid; |
| 71 | int abort_trace; |
71 | int abort_trace; |
| 72 | 72 | ||
| 73 | uintptr_t thash; |
73 | uintptr_t thash; |
| 74 | volatile int paused; |
74 | volatile int paused; |
| 75 | fibril_condvar_t paused_cv; |
75 | fibril_condvar_t state_cv; |
| 76 | fibril_mutex_t paused_lock; |
76 | fibril_mutex_t state_lock; |
| - | 77 | ||
| - | 78 | int cev_valid; |
|
| - | 79 | console_event_t cev; |
|
| 77 | 80 | ||
| 78 | void thread_trace_start(uintptr_t thread_hash); |
81 | void thread_trace_start(uintptr_t thread_hash); |
| 79 | 82 | ||
| 80 | static proto_t *proto_console; |
83 | static proto_t *proto_console; |
| 81 | static task_id_t task_id; |
84 | static task_id_t task_id; |
| Line 83... | Line 86... | ||
| 83 | 86 | ||
| 84 | /** Combination of events/data to print. */ |
87 | /** Combination of events/data to print. */ |
| 85 | display_mask_t display_mask; |
88 | display_mask_t display_mask; |
| 86 | 89 | ||
| 87 | static int program_run_fibril(void *arg); |
90 | static int program_run_fibril(void *arg); |
| - | 91 | static int cev_fibril(void *arg); |
|
| 88 | 92 | ||
| 89 | static void program_run(void) |
93 | static void program_run(void) |
| 90 | { |
94 | { |
| 91 | fid_t fid; |
95 | fid_t fid; |
| 92 | 96 | ||
| Line 97... | Line 101... | ||
| 97 | } |
101 | } |
| 98 | 102 | ||
| 99 | fibril_add_ready(fid); |
103 | fibril_add_ready(fid); |
| 100 | } |
104 | } |
| 101 | 105 | ||
| - | 106 | static void cev_fibril_start(void) |
|
| - | 107 | { |
|
| - | 108 | fid_t fid; |
|
| - | 109 | ||
| - | 110 | fid = fibril_create(cev_fibril, NULL); |
|
| - | 111 | if (fid == 0) { |
|
| - | 112 | printf("Error creating fibril\n"); |
|
| - | 113 | exit(1); |
|
| - | 114 | } |
|
| - | 115 | ||
| - | 116 | fibril_add_ready(fid); |
|
| - | 117 | } |
|
| - | 118 | ||
| 102 | static int program_run_fibril(void *arg) |
119 | static int program_run_fibril(void *arg) |
| 103 | { |
120 | { |
| 104 | int rc; |
121 | int rc; |
| 105 | 122 | ||
| 106 | /* |
123 | /* |
| Line 454... | Line 471... | ||
| 454 | 471 | ||
| 455 | printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash); |
472 | printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash); |
| 456 | 473 | ||
| 457 | while (!abort_trace) { |
474 | while (!abort_trace) { |
| 458 | 475 | ||
| 459 | fibril_mutex_lock(&paused_lock); |
476 | fibril_mutex_lock(&state_lock); |
| 460 | if (paused) { |
477 | if (paused) { |
| 461 | printf("Thread [%d] paused. Press R to resume.\n", |
478 | printf("Thread [%d] paused. Press R to resume.\n", |
| 462 | thread_id); |
479 | thread_id); |
| 463 | 480 | ||
| 464 | while (paused) |
481 | while (paused) |
| 465 | fibril_condvar_wait(&paused_cv, &paused_lock); |
482 | fibril_condvar_wait(&state_cv, &state_lock); |
| 466 | 483 | ||
| 467 | printf("Thread [%d] resumed.\n", thread_id); |
484 | printf("Thread [%d] resumed.\n", thread_id); |
| 468 | } |
485 | } |
| 469 | fibril_mutex_unlock(&paused_lock); |
486 | fibril_mutex_unlock(&state_lock); |
| 470 | 487 | ||
| 471 | /* Run thread until an event occurs */ |
488 | /* Run thread until an event occurs */ |
| 472 | rc = udebug_go(phoneid, thread_hash, |
489 | rc = udebug_go(phoneid, thread_hash, |
| 473 | &ev_type, &val0, &val1); |
490 | &ev_type, &val0, &val1); |
| 474 | 491 | ||
| Line 486... | Line 503... | ||
| 486 | case UDEBUG_EVENT_SYSCALL_E: |
503 | case UDEBUG_EVENT_SYSCALL_E: |
| 487 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
504 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
| 488 | break; |
505 | break; |
| 489 | case UDEBUG_EVENT_STOP: |
506 | case UDEBUG_EVENT_STOP: |
| 490 | printf("Stop event\n"); |
507 | printf("Stop event\n"); |
| 491 | fibril_mutex_lock(&paused_lock); |
508 | fibril_mutex_lock(&state_lock); |
| 492 | paused = 1; |
509 | paused = 1; |
| 493 | fibril_mutex_unlock(&paused_lock); |
510 | fibril_mutex_unlock(&state_lock); |
| 494 | break; |
511 | break; |
| 495 | case UDEBUG_EVENT_THREAD_B: |
512 | case UDEBUG_EVENT_THREAD_B: |
| 496 | event_thread_b(val0); |
513 | event_thread_b(val0); |
| 497 | break; |
514 | break; |
| 498 | case UDEBUG_EVENT_THREAD_E: |
515 | case UDEBUG_EVENT_THREAD_E: |
| 499 | printf("Thread 0x%lx exited.\n", val0); |
516 | printf("Thread 0x%lx exited.\n", val0); |
| - | 517 | fibril_mutex_lock(&state_lock); |
|
| 500 | abort_trace = 1; |
518 | abort_trace = 1; |
| - | 519 | fibril_condvar_broadcast(&state_cv); |
|
| - | 520 | fibril_mutex_unlock(&state_lock); |
|
| 501 | break; |
521 | break; |
| 502 | default: |
522 | default: |
| 503 | printf("Unknown event type %d.\n", ev_type); |
523 | printf("Unknown event type %d.\n", ev_type); |
| 504 | break; |
524 | break; |
| 505 | } |
525 | } |
| Line 590... | Line 610... | ||
| 590 | loader_abort(ldr); |
610 | loader_abort(ldr); |
| 591 | free(ldr); |
611 | free(ldr); |
| 592 | return NULL; |
612 | return NULL; |
| 593 | } |
613 | } |
| 594 | 614 | ||
| - | 615 | static int cev_fibril(void *arg) |
|
| - | 616 | { |
|
| - | 617 | (void) arg; |
|
| - | 618 | ||
| - | 619 | printf("cev_fibril()\n"); |
|
| - | 620 | while (true) { |
|
| - | 621 | printf("cev_fibril: wait for cev_valid == 0\n"); |
|
| - | 622 | fibril_mutex_lock(&state_lock); |
|
| - | 623 | while (cev_valid) |
|
| - | 624 | fibril_condvar_wait(&state_cv, &state_lock); |
|
| - | 625 | fibril_mutex_unlock(&state_lock); |
|
| - | 626 | ||
| - | 627 | printf("cev_fibril: wait for key\n"); |
|
| - | 628 | ||
| - | 629 | if (!console_get_event(fphone(stdin), &cev)) |
|
| - | 630 | return -1; |
|
| - | 631 | ||
| - | 632 | printf("cev_fibril: broadcast cev_valid = 1\n"); |
|
| - | 633 | ||
| - | 634 | fibril_mutex_lock(&state_lock); |
|
| - | 635 | cev_valid = 1; |
|
| - | 636 | fibril_condvar_broadcast(&state_cv); |
|
| - | 637 | fibril_mutex_unlock(&state_lock); |
|
| - | 638 | } |
|
| - | 639 | } |
|
| - | 640 | ||
| 595 | static void trace_task(task_id_t task_id) |
641 | static void trace_task(task_id_t task_id) |
| 596 | { |
642 | { |
| 597 | console_event_t ev; |
643 | console_event_t ev; |
| 598 | bool done; |
644 | bool done; |
| 599 | int i; |
645 | int i; |
| Line 620... | Line 666... | ||
| 620 | } |
666 | } |
| 621 | 667 | ||
| 622 | done = false; |
668 | done = false; |
| 623 | 669 | ||
| 624 | while (!done) { |
670 | while (!done) { |
| - | 671 | printf("trace_task: wait for cev_valid || abort_trace\n"); |
|
| - | 672 | fibril_mutex_lock(&state_lock); |
|
| - | 673 | while (!cev_valid && !abort_trace) |
|
| 625 | if (!console_get_event(fphone(stdin), &ev)) |
674 | fibril_condvar_wait(&state_cv, &state_lock); |
| - | 675 | fibril_mutex_unlock(&state_lock); |
|
| - | 676 | ||
| - | 677 | printf("trace_task: got something\n"); |
|
| - | 678 | ||
| - | 679 | ev = cev; |
|
| - | 680 | ||
| - | 681 | fibril_mutex_lock(&state_lock); |
|
| - | 682 | cev_valid = false; |
|
| - | 683 | fibril_condvar_broadcast(&state_cv); |
|
| - | 684 | fibril_mutex_unlock(&state_lock); |
|
| - | 685 | ||
| - | 686 | if (abort_trace) |
|
| 626 | return; |
687 | break; |
| 627 | 688 | ||
| 628 | if (ev.type != KEY_PRESS) |
689 | if (ev.type != KEY_PRESS) |
| 629 | continue; |
690 | continue; |
| 630 | 691 | ||
| 631 | switch (ev.key) { |
692 | switch (ev.key) { |
| Line 637... | Line 698... | ||
| 637 | rc = udebug_stop(phoneid, thash); |
698 | rc = udebug_stop(phoneid, thash); |
| 638 | if (rc != EOK) |
699 | if (rc != EOK) |
| 639 | printf("Error: stop -> %d\n", rc); |
700 | printf("Error: stop -> %d\n", rc); |
| 640 | break; |
701 | break; |
| 641 | case KC_R: |
702 | case KC_R: |
| 642 | fibril_mutex_lock(&paused_lock); |
703 | fibril_mutex_lock(&state_lock); |
| 643 | paused = 0; |
704 | paused = 0; |
| 644 | fibril_condvar_broadcast(&paused_cv); |
705 | fibril_condvar_broadcast(&state_cv); |
| 645 | fibril_mutex_unlock(&paused_lock); |
706 | fibril_mutex_unlock(&state_lock); |
| 646 | printf("Resume...\n"); |
707 | printf("Resume...\n"); |
| 647 | break; |
708 | break; |
| 648 | } |
709 | } |
| 649 | } |
710 | } |
| 650 | 711 | ||
| Line 680... | Line 741... | ||
| 680 | V_INTEGER |
741 | V_INTEGER |
| 681 | }; |
742 | }; |
| 682 | 743 | ||
| 683 | next_thread_id = 1; |
744 | next_thread_id = 1; |
| 684 | paused = 0; |
745 | paused = 0; |
| - | 746 | cev_valid = 0; |
|
| - | 747 | ||
| 685 | fibril_mutex_initialize(&paused_lock); |
748 | fibril_mutex_initialize(&state_lock); |
| 686 | fibril_condvar_initialize(&paused_cv); |
749 | fibril_condvar_initialize(&state_cv); |
| 687 | 750 | ||
| 688 | proto_init(); |
751 | proto_init(); |
| 689 | 752 | ||
| 690 | p = proto_new("vfs"); |
753 | p = proto_new("vfs"); |
| 691 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
754 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
| Line 871... | Line 934... | ||
| 871 | 934 | ||
| 872 | if (task_ldr != NULL) { |
935 | if (task_ldr != NULL) { |
| 873 | program_run(); |
936 | program_run(); |
| 874 | } |
937 | } |
| 875 | 938 | ||
| - | 939 | cev_fibril_start(); |
|
| 876 | trace_task(task_id); |
940 | trace_task(task_id); |
| 877 | 941 | ||
| 878 | return 0; |
942 | return 0; |
| 879 | } |
943 | } |
| 880 | 944 | ||