OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // Global variable to store the last function hit - used by some tests. | 504 // Global variable to store the last function hit - used by some tests. |
505 char last_function_hit[80]; | 505 char last_function_hit[80]; |
506 | 506 |
507 // Debug event handler which counts the break points which have been hit. | 507 // Debug event handler which counts the break points which have been hit. |
508 int break_point_hit_count = 0; | 508 int break_point_hit_count = 0; |
509 static void DebugEventBreakPointHitCount(v8::DebugEvent event, | 509 static void DebugEventBreakPointHitCount(v8::DebugEvent event, |
510 v8::Handle<v8::Object> exec_state, | 510 v8::Handle<v8::Object> exec_state, |
511 v8::Handle<v8::Object> event_data, | 511 v8::Handle<v8::Object> event_data, |
512 v8::Handle<v8::Value> data) { | 512 v8::Handle<v8::Value> data) { |
513 // When hitting a debug event listener there must be a break set. | 513 // When hitting a debug event listener there must be a break set. |
514 CHECK(v8::internal::Top::is_break()); | 514 CHECK(v8::internal::Debug::break_id() != 0); |
515 | 515 |
516 // Count the number of breaks. | 516 // Count the number of breaks. |
517 if (event == v8::Break) { | 517 if (event == v8::Break) { |
518 break_point_hit_count++; | 518 break_point_hit_count++; |
519 if (!frame_function_name.IsEmpty()) { | 519 if (!frame_function_name.IsEmpty()) { |
520 // Get the name of the function. | 520 // Get the name of the function. |
521 const int argc = 1; | 521 const int argc = 1; |
522 v8::Handle<v8::Value> argv[argc] = { exec_state }; | 522 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
523 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, | 523 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, |
524 argc, argv); | 524 argc, argv); |
(...skipping 19 matching lines...) Expand all Loading... |
544 break_point_hit_count = 0; | 544 break_point_hit_count = 0; |
545 exception_hit_count = 0; | 545 exception_hit_count = 0; |
546 uncaught_exception_hit_count = 0; | 546 uncaught_exception_hit_count = 0; |
547 } | 547 } |
548 | 548 |
549 static void DebugEventCounter(v8::DebugEvent event, | 549 static void DebugEventCounter(v8::DebugEvent event, |
550 v8::Handle<v8::Object> exec_state, | 550 v8::Handle<v8::Object> exec_state, |
551 v8::Handle<v8::Object> event_data, | 551 v8::Handle<v8::Object> event_data, |
552 v8::Handle<v8::Value> data) { | 552 v8::Handle<v8::Value> data) { |
553 // When hitting a debug event listener there must be a break set. | 553 // When hitting a debug event listener there must be a break set. |
554 CHECK(v8::internal::Top::is_break()); | 554 CHECK(v8::internal::Debug::break_id() != 0); |
555 | 555 |
556 // Count the number of breaks. | 556 // Count the number of breaks. |
557 if (event == v8::Break) { | 557 if (event == v8::Break) { |
558 break_point_hit_count++; | 558 break_point_hit_count++; |
559 } else if (event == v8::Exception) { | 559 } else if (event == v8::Exception) { |
560 exception_hit_count++; | 560 exception_hit_count++; |
561 | 561 |
562 // Check whether the exception was uncaught. | 562 // Check whether the exception was uncaught. |
563 v8::Local<v8::String> fun_name = v8::String::New("uncaught"); | 563 v8::Local<v8::String> fun_name = v8::String::New("uncaught"); |
564 v8::Local<v8::Function> fun = | 564 v8::Local<v8::Function> fun = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 " return exec_state.frame(0).evaluate(expr).value() === expected;" | 602 " return exec_state.frame(0).evaluate(expr).value() === expected;" |
603 "}"; | 603 "}"; |
604 v8::Local<v8::Function> evaluate_check_function; | 604 v8::Local<v8::Function> evaluate_check_function; |
605 | 605 |
606 // The actual debug event described by the longer comment above. | 606 // The actual debug event described by the longer comment above. |
607 static void DebugEventEvaluate(v8::DebugEvent event, | 607 static void DebugEventEvaluate(v8::DebugEvent event, |
608 v8::Handle<v8::Object> exec_state, | 608 v8::Handle<v8::Object> exec_state, |
609 v8::Handle<v8::Object> event_data, | 609 v8::Handle<v8::Object> event_data, |
610 v8::Handle<v8::Value> data) { | 610 v8::Handle<v8::Value> data) { |
611 // When hitting a debug event listener there must be a break set. | 611 // When hitting a debug event listener there must be a break set. |
612 CHECK(v8::internal::Top::is_break()); | 612 CHECK(v8::internal::Debug::break_id() != 0); |
613 | 613 |
614 if (event == v8::Break) { | 614 if (event == v8::Break) { |
615 for (int i = 0; checks[i].expr != NULL; i++) { | 615 for (int i = 0; checks[i].expr != NULL; i++) { |
616 const int argc = 3; | 616 const int argc = 3; |
617 v8::Handle<v8::Value> argv[argc] = { exec_state, | 617 v8::Handle<v8::Value> argv[argc] = { exec_state, |
618 v8::String::New(checks[i].expr), | 618 v8::String::New(checks[i].expr), |
619 checks[i].expected }; | 619 checks[i].expected }; |
620 v8::Handle<v8::Value> result = | 620 v8::Handle<v8::Value> result = |
621 evaluate_check_function->Call(exec_state, argc, argv); | 621 evaluate_check_function->Call(exec_state, argc, argv); |
622 if (!result->IsTrue()) { | 622 if (!result->IsTrue()) { |
623 v8::String::AsciiValue ascii(checks[i].expected->ToString()); | 623 v8::String::AsciiValue ascii(checks[i].expected->ToString()); |
624 V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *ascii); | 624 V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *ascii); |
625 } | 625 } |
626 } | 626 } |
627 } | 627 } |
628 } | 628 } |
629 | 629 |
630 | 630 |
631 // This debug event listener removes a breakpoint in a function | 631 // This debug event listener removes a breakpoint in a function |
632 int debug_event_remove_break_point = 0; | 632 int debug_event_remove_break_point = 0; |
633 static void DebugEventRemoveBreakPoint(v8::DebugEvent event, | 633 static void DebugEventRemoveBreakPoint(v8::DebugEvent event, |
634 v8::Handle<v8::Object> exec_state, | 634 v8::Handle<v8::Object> exec_state, |
635 v8::Handle<v8::Object> event_data, | 635 v8::Handle<v8::Object> event_data, |
636 v8::Handle<v8::Value> data) { | 636 v8::Handle<v8::Value> data) { |
637 // When hitting a debug event listener there must be a break set. | 637 // When hitting a debug event listener there must be a break set. |
638 CHECK(v8::internal::Top::is_break()); | 638 CHECK(v8::internal::Debug::break_id() != 0); |
639 | 639 |
640 if (event == v8::Break) { | 640 if (event == v8::Break) { |
641 break_point_hit_count++; | 641 break_point_hit_count++; |
642 v8::Handle<v8::Function> fun = v8::Handle<v8::Function>::Cast(data); | 642 v8::Handle<v8::Function> fun = v8::Handle<v8::Function>::Cast(data); |
643 ClearBreakPoint(debug_event_remove_break_point); | 643 ClearBreakPoint(debug_event_remove_break_point); |
644 } | 644 } |
645 } | 645 } |
646 | 646 |
647 | 647 |
648 // Debug event handler which counts break points hit and performs a step | 648 // Debug event handler which counts break points hit and performs a step |
649 // afterwards. | 649 // afterwards. |
650 StepAction step_action = StepIn; // Step action to perform when stepping. | 650 StepAction step_action = StepIn; // Step action to perform when stepping. |
651 static void DebugEventStep(v8::DebugEvent event, | 651 static void DebugEventStep(v8::DebugEvent event, |
652 v8::Handle<v8::Object> exec_state, | 652 v8::Handle<v8::Object> exec_state, |
653 v8::Handle<v8::Object> event_data, | 653 v8::Handle<v8::Object> event_data, |
654 v8::Handle<v8::Value> data) { | 654 v8::Handle<v8::Value> data) { |
655 // When hitting a debug event listener there must be a break set. | 655 // When hitting a debug event listener there must be a break set. |
656 CHECK(v8::internal::Top::is_break()); | 656 CHECK(v8::internal::Debug::break_id() != 0); |
657 | 657 |
658 if (event == v8::Break) { | 658 if (event == v8::Break) { |
659 break_point_hit_count++; | 659 break_point_hit_count++; |
660 PrepareStep(step_action); | 660 PrepareStep(step_action); |
661 } | 661 } |
662 } | 662 } |
663 | 663 |
664 | 664 |
665 // Debug event handler which counts break points hit and performs a step | 665 // Debug event handler which counts break points hit and performs a step |
666 // afterwards. For each call the expected function is checked. | 666 // afterwards. For each call the expected function is checked. |
667 // For this debug event handler to work the following two global varaibles | 667 // For this debug event handler to work the following two global varaibles |
668 // must be initialized. | 668 // must be initialized. |
669 // expected_step_sequence: An array of the expected function call sequence. | 669 // expected_step_sequence: An array of the expected function call sequence. |
670 // frame_function_name: A JavaScript function (see below). | 670 // frame_function_name: A JavaScript function (see below). |
671 | 671 |
672 // String containing the expected function call sequence. Note: this only works | 672 // String containing the expected function call sequence. Note: this only works |
673 // if functions have name length of one. | 673 // if functions have name length of one. |
674 const char* expected_step_sequence = NULL; | 674 const char* expected_step_sequence = NULL; |
675 | 675 |
676 // The actual debug event described by the longer comment above. | 676 // The actual debug event described by the longer comment above. |
677 static void DebugEventStepSequence(v8::DebugEvent event, | 677 static void DebugEventStepSequence(v8::DebugEvent event, |
678 v8::Handle<v8::Object> exec_state, | 678 v8::Handle<v8::Object> exec_state, |
679 v8::Handle<v8::Object> event_data, | 679 v8::Handle<v8::Object> event_data, |
680 v8::Handle<v8::Value> data) { | 680 v8::Handle<v8::Value> data) { |
681 // When hitting a debug event listener there must be a break set. | 681 // When hitting a debug event listener there must be a break set. |
682 CHECK(v8::internal::Top::is_break()); | 682 CHECK(v8::internal::Debug::break_id() != 0); |
683 | 683 |
684 if (event == v8::Break || event == v8::Exception) { | 684 if (event == v8::Break || event == v8::Exception) { |
685 // Check that the current function is the expected. | 685 // Check that the current function is the expected. |
686 CHECK(break_point_hit_count < | 686 CHECK(break_point_hit_count < |
687 static_cast<int>(strlen(expected_step_sequence))); | 687 static_cast<int>(strlen(expected_step_sequence))); |
688 const int argc = 1; | 688 const int argc = 1; |
689 v8::Handle<v8::Value> argv[argc] = { exec_state }; | 689 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
690 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, | 690 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, |
691 argc, argv); | 691 argc, argv); |
692 CHECK(result->IsString()); | 692 CHECK(result->IsString()); |
693 v8::String::AsciiValue function_name(result->ToString()); | 693 v8::String::AsciiValue function_name(result->ToString()); |
694 CHECK_EQ(1, strlen(*function_name)); | 694 CHECK_EQ(1, strlen(*function_name)); |
695 CHECK_EQ((*function_name)[0], | 695 CHECK_EQ((*function_name)[0], |
696 expected_step_sequence[break_point_hit_count]); | 696 expected_step_sequence[break_point_hit_count]); |
697 | 697 |
698 // Perform step. | 698 // Perform step. |
699 break_point_hit_count++; | 699 break_point_hit_count++; |
700 PrepareStep(step_action); | 700 PrepareStep(step_action); |
701 } | 701 } |
702 } | 702 } |
703 | 703 |
704 | 704 |
705 // Debug event handler which performs a garbage collection. | 705 // Debug event handler which performs a garbage collection. |
706 static void DebugEventBreakPointCollectGarbage( | 706 static void DebugEventBreakPointCollectGarbage( |
707 v8::DebugEvent event, | 707 v8::DebugEvent event, |
708 v8::Handle<v8::Object> exec_state, | 708 v8::Handle<v8::Object> exec_state, |
709 v8::Handle<v8::Object> event_data, | 709 v8::Handle<v8::Object> event_data, |
710 v8::Handle<v8::Value> data) { | 710 v8::Handle<v8::Value> data) { |
711 // When hitting a debug event listener there must be a break set. | 711 // When hitting a debug event listener there must be a break set. |
712 CHECK(v8::internal::Top::is_break()); | 712 CHECK(v8::internal::Debug::break_id() != 0); |
713 | 713 |
714 // Perform a garbage collection when break point is hit and continue. Based | 714 // Perform a garbage collection when break point is hit and continue. Based |
715 // on the number of break points hit either scavenge or mark compact | 715 // on the number of break points hit either scavenge or mark compact |
716 // collector is used. | 716 // collector is used. |
717 if (event == v8::Break) { | 717 if (event == v8::Break) { |
718 break_point_hit_count++; | 718 break_point_hit_count++; |
719 if (break_point_hit_count % 2 == 0) { | 719 if (break_point_hit_count % 2 == 0) { |
720 // Scavenge. | 720 // Scavenge. |
721 Heap::CollectGarbage(0, v8::internal::NEW_SPACE); | 721 Heap::CollectGarbage(0, v8::internal::NEW_SPACE); |
722 } else { | 722 } else { |
723 // Mark sweep (and perhaps compact). | 723 // Mark sweep (and perhaps compact). |
724 Heap::CollectAllGarbage(); | 724 Heap::CollectAllGarbage(); |
725 } | 725 } |
726 } | 726 } |
727 } | 727 } |
728 | 728 |
729 | 729 |
730 // Debug event handler which re-issues a debug break and calls the garbage | 730 // Debug event handler which re-issues a debug break and calls the garbage |
731 // collector to have the heap verified. | 731 // collector to have the heap verified. |
732 static void DebugEventBreak(v8::DebugEvent event, | 732 static void DebugEventBreak(v8::DebugEvent event, |
733 v8::Handle<v8::Object> exec_state, | 733 v8::Handle<v8::Object> exec_state, |
734 v8::Handle<v8::Object> event_data, | 734 v8::Handle<v8::Object> event_data, |
735 v8::Handle<v8::Value> data) { | 735 v8::Handle<v8::Value> data) { |
736 // When hitting a debug event listener there must be a break set. | 736 // When hitting a debug event listener there must be a break set. |
737 CHECK(v8::internal::Top::is_break()); | 737 CHECK(v8::internal::Debug::break_id() != 0); |
738 | 738 |
739 if (event == v8::Break) { | 739 if (event == v8::Break) { |
740 // Count the number of breaks. | 740 // Count the number of breaks. |
741 break_point_hit_count++; | 741 break_point_hit_count++; |
742 | 742 |
743 // Run the garbage collector to enforce heap verification if option | 743 // Run the garbage collector to enforce heap verification if option |
744 // --verify-heap is set. | 744 // --verify-heap is set. |
745 Heap::CollectGarbage(0, v8::internal::NEW_SPACE); | 745 Heap::CollectGarbage(0, v8::internal::NEW_SPACE); |
746 | 746 |
747 // Set the break flag again to come back here as soon as possible. | 747 // Set the break flag again to come back here as soon as possible. |
(...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3688 | 3688 |
3689 // Fill a host dispatch and a continue command on the command queue before | 3689 // Fill a host dispatch and a continue command on the command queue before |
3690 // generating a debug break. | 3690 // generating a debug break. |
3691 v8::Debug::SendHostDispatch(NULL); | 3691 v8::Debug::SendHostDispatch(NULL); |
3692 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); | 3692 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
3693 CompileRun("debugger"); | 3693 CompileRun("debugger"); |
3694 | 3694 |
3695 // The host dispatch callback should be called. | 3695 // The host dispatch callback should be called. |
3696 CHECK_EQ(1, host_dispatch_hit_count); | 3696 CHECK_EQ(1, host_dispatch_hit_count); |
3697 } | 3697 } |
3698 | |
OLD | NEW |