OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 Smi::FromInt(StackFrame::INTERNAL); | 626 Smi::FromInt(StackFrame::INTERNAL); |
627 | 627 |
628 return reinterpret_cast<Object**>(&Memory::Object_at( | 628 return reinterpret_cast<Object**>(&Memory::Object_at( |
629 fp + StandardFrameConstants::kContextOffset)); | 629 fp + StandardFrameConstants::kContextOffset)); |
630 } | 630 } |
631 | 631 |
632 const int Debug::kFrameDropperFrameSize = 4; | 632 const int Debug::kFrameDropperFrameSize = 4; |
633 | 633 |
634 | 634 |
635 void ScriptCache::Add(Handle<Script> script) { | 635 void ScriptCache::Add(Handle<Script> script) { |
636 Isolate* isolate = Isolate::Current(); | 636 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
637 // Create an entry in the hash map for the script. | 637 // Create an entry in the hash map for the script. |
638 int id = Smi::cast(script->id())->value(); | 638 int id = Smi::cast(script->id())->value(); |
639 HashMap::Entry* entry = | 639 HashMap::Entry* entry = |
640 HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true); | 640 HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true); |
641 if (entry->value != NULL) { | 641 if (entry->value != NULL) { |
642 ASSERT(*script == *reinterpret_cast<Script**>(entry->value)); | 642 ASSERT(*script == *reinterpret_cast<Script**>(entry->value)); |
643 return; | 643 return; |
644 } | 644 } |
645 | 645 |
646 // Globalize the script object, make it weak and use the location of the | 646 // Globalize the script object, make it weak and use the location of the |
647 // global handle as the value in the hash map. | 647 // global handle as the value in the hash map. |
648 Handle<Script> script_ = | 648 Handle<Script> script_ = |
649 Handle<Script>::cast( | 649 Handle<Script>::cast( |
650 (isolate->global_handles()->Create(*script))); | 650 (global_handles->Create(*script))); |
651 isolate->global_handles()->MakeWeak( | 651 global_handles->MakeWeak( |
652 reinterpret_cast<Object**>(script_.location()), | 652 reinterpret_cast<Object**>(script_.location()), |
653 this, | 653 this, |
654 ScriptCache::HandleWeakScript); | 654 ScriptCache::HandleWeakScript); |
655 entry->value = script_.location(); | 655 entry->value = script_.location(); |
656 } | 656 } |
657 | 657 |
658 | 658 |
659 Handle<FixedArray> ScriptCache::GetScripts() { | 659 Handle<FixedArray> ScriptCache::GetScripts() { |
660 Handle<FixedArray> instances = FACTORY->NewFixedArray(occupancy()); | 660 Handle<FixedArray> instances = FACTORY->NewFixedArray(occupancy()); |
661 int count = 0; | 661 int count = 0; |
662 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { | 662 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { |
663 ASSERT(entry->value != NULL); | 663 ASSERT(entry->value != NULL); |
664 if (entry->value != NULL) { | 664 if (entry->value != NULL) { |
665 instances->set(count, *reinterpret_cast<Script**>(entry->value)); | 665 instances->set(count, *reinterpret_cast<Script**>(entry->value)); |
666 count++; | 666 count++; |
667 } | 667 } |
668 } | 668 } |
669 return instances; | 669 return instances; |
670 } | 670 } |
671 | 671 |
672 | 672 |
673 void ScriptCache::ProcessCollectedScripts() { | 673 void ScriptCache::ProcessCollectedScripts() { |
674 Isolate* isolate = Isolate::Current(); | 674 Debugger* debugger = Isolate::Current()->debugger(); |
675 for (int i = 0; i < collected_scripts_.length(); i++) { | 675 for (int i = 0; i < collected_scripts_.length(); i++) { |
676 isolate->debugger()->OnScriptCollected(collected_scripts_[i]); | 676 debugger->OnScriptCollected(collected_scripts_[i]); |
677 } | 677 } |
678 collected_scripts_.Clear(); | 678 collected_scripts_.Clear(); |
679 } | 679 } |
680 | 680 |
681 | 681 |
682 void ScriptCache::Clear() { | 682 void ScriptCache::Clear() { |
683 Isolate* isolate = Isolate::Current(); | 683 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
684 // Iterate the script cache to get rid of all the weak handles. | 684 // Iterate the script cache to get rid of all the weak handles. |
685 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { | 685 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { |
686 ASSERT(entry != NULL); | 686 ASSERT(entry != NULL); |
687 Object** location = reinterpret_cast<Object**>(entry->value); | 687 Object** location = reinterpret_cast<Object**>(entry->value); |
688 ASSERT((*location)->IsScript()); | 688 ASSERT((*location)->IsScript()); |
689 isolate->global_handles()->ClearWeakness(location); | 689 global_handles->ClearWeakness(location); |
690 isolate->global_handles()->Destroy(location); | 690 global_handles->Destroy(location); |
691 } | 691 } |
692 // Clear the content of the hash map. | 692 // Clear the content of the hash map. |
693 HashMap::Clear(); | 693 HashMap::Clear(); |
694 } | 694 } |
695 | 695 |
696 | 696 |
697 void ScriptCache::HandleWeakScript(v8::Persistent<v8::Value> obj, void* data) { | 697 void ScriptCache::HandleWeakScript(v8::Persistent<v8::Value> obj, void* data) { |
698 ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data); | 698 ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data); |
699 // Find the location of the global handle. | 699 // Find the location of the global handle. |
700 Script** location = | 700 Script** location = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 node = debug->debug_info_list_; | 741 node = debug->debug_info_list_; |
742 while (node != NULL) { | 742 while (node != NULL) { |
743 ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data)); | 743 ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data)); |
744 node = node->next(); | 744 node = node->next(); |
745 } | 745 } |
746 #endif | 746 #endif |
747 } | 747 } |
748 | 748 |
749 | 749 |
750 DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { | 750 DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { |
751 Isolate* isolate = Isolate::Current(); | 751 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
752 // Globalize the request debug info object and make it weak. | 752 // Globalize the request debug info object and make it weak. |
753 debug_info_ = Handle<DebugInfo>::cast( | 753 debug_info_ = Handle<DebugInfo>::cast( |
754 (isolate->global_handles()->Create(debug_info))); | 754 (global_handles->Create(debug_info))); |
755 isolate->global_handles()->MakeWeak( | 755 global_handles->MakeWeak( |
756 reinterpret_cast<Object**>(debug_info_.location()), | 756 reinterpret_cast<Object**>(debug_info_.location()), |
757 this, | 757 this, |
758 Debug::HandleWeakDebugInfo); | 758 Debug::HandleWeakDebugInfo); |
759 } | 759 } |
760 | 760 |
761 | 761 |
762 DebugInfoListNode::~DebugInfoListNode() { | 762 DebugInfoListNode::~DebugInfoListNode() { |
763 Isolate::Current()->global_handles()->Destroy( | 763 Isolate::Current()->global_handles()->Destroy( |
764 reinterpret_cast<Object**>(debug_info_.location())); | 764 reinterpret_cast<Object**>(debug_info_.location())); |
765 } | 765 } |
766 | 766 |
767 | 767 |
768 bool Debug::CompileDebuggerScript(int index) { | 768 bool Debug::CompileDebuggerScript(int index) { |
769 HandleScope scope; | 769 Isolate* isolate = Isolate::Current(); |
770 Factory* factory = isolate->factory(); | |
771 HandleScope scope(isolate); | |
770 | 772 |
771 // Bail out if the index is invalid. | 773 // Bail out if the index is invalid. |
772 if (index == -1) { | 774 if (index == -1) { |
773 return false; | 775 return false; |
774 } | 776 } |
775 | 777 |
776 // Find source and name for the requested script. | 778 // Find source and name for the requested script. |
777 Handle<String> source_code = | 779 Handle<String> source_code = |
778 Isolate::Current()->bootstrapper()->NativesSourceLookup(index); | 780 isolate->bootstrapper()->NativesSourceLookup(index); |
779 Vector<const char> name = Natives::GetScriptName(index); | 781 Vector<const char> name = Natives::GetScriptName(index); |
780 Handle<String> script_name = FACTORY->NewStringFromAscii(name); | 782 Handle<String> script_name = factory->NewStringFromAscii(name); |
781 | 783 |
782 // Compile the script. | 784 // Compile the script. |
783 Handle<SharedFunctionInfo> function_info; | 785 Handle<SharedFunctionInfo> function_info; |
784 function_info = Compiler::Compile(source_code, | 786 function_info = Compiler::Compile(source_code, |
785 script_name, | 787 script_name, |
786 0, 0, NULL, NULL, | 788 0, 0, NULL, NULL, |
787 Handle<String>::null(), | 789 Handle<String>::null(), |
788 NATIVES_CODE); | 790 NATIVES_CODE); |
789 | 791 |
790 // Silently ignore stack overflows during compilation. | 792 // Silently ignore stack overflows during compilation. |
791 if (function_info.is_null()) { | 793 if (function_info.is_null()) { |
792 ASSERT(Isolate::Current()->has_pending_exception()); | 794 ASSERT(isolate->has_pending_exception()); |
793 Isolate::Current()->clear_pending_exception(); | 795 isolate->clear_pending_exception(); |
794 return false; | 796 return false; |
795 } | 797 } |
796 | 798 |
797 // Execute the shared function in the debugger context. | 799 // Execute the shared function in the debugger context. |
798 Handle<Context> context = Isolate::Current()->global_context(); | 800 Handle<Context> context = isolate->global_context(); |
799 bool caught_exception = false; | 801 bool caught_exception = false; |
800 Handle<JSFunction> function = | 802 Handle<JSFunction> function = |
801 FACTORY->NewFunctionFromSharedFunctionInfo(function_info, context); | 803 factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
802 Handle<Object> result = | 804 Handle<Object> result = |
803 Execution::TryCall(function, Handle<Object>(context->global()), | 805 Execution::TryCall(function, Handle<Object>(context->global()), |
804 0, NULL, &caught_exception); | 806 0, NULL, &caught_exception); |
805 | 807 |
806 // Check for caught exceptions. | 808 // Check for caught exceptions. |
807 if (caught_exception) { | 809 if (caught_exception) { |
808 Handle<Object> message = MessageHandler::MakeMessageObject( | 810 Handle<Object> message = MessageHandler::MakeMessageObject( |
809 "error_loading_debugger", NULL, Vector<Handle<Object> >::empty(), | 811 "error_loading_debugger", NULL, Vector<Handle<Object> >::empty(), |
810 Handle<String>(), Handle<JSArray>()); | 812 Handle<String>(), Handle<JSArray>()); |
811 MessageHandler::ReportMessage(NULL, message); | 813 MessageHandler::ReportMessage(NULL, message); |
812 return false; | 814 return false; |
813 } | 815 } |
814 | 816 |
815 // Mark this script as native and return successfully. | 817 // Mark this script as native and return successfully. |
816 Handle<Script> script(Script::cast(function->shared()->script())); | 818 Handle<Script> script(Script::cast(function->shared()->script())); |
817 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 819 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
818 return true; | 820 return true; |
819 } | 821 } |
820 | 822 |
821 | 823 |
822 bool Debug::Load() { | 824 bool Debug::Load() { |
823 // Return if debugger is already loaded. | 825 // Return if debugger is already loaded. |
824 if (IsLoaded()) return true; | 826 if (IsLoaded()) return true; |
825 | 827 |
826 Isolate* isolate = Isolate::Current(); | 828 ASSERT(Isolate::Current() == isolate_); |
829 Debugger* debugger = isolate_->debugger(); | |
827 | 830 |
828 // Bail out if we're already in the process of compiling the native | 831 // Bail out if we're already in the process of compiling the native |
829 // JavaScript source code for the debugger. | 832 // JavaScript source code for the debugger. |
830 if (isolate->debugger()->compiling_natives() || | 833 if (debugger->compiling_natives() || |
831 isolate->debugger()->is_loading_debugger()) | 834 debugger->is_loading_debugger()) |
832 return false; | 835 return false; |
833 isolate->debugger()->set_loading_debugger(true); | 836 debugger->set_loading_debugger(true); |
834 | 837 |
835 // Disable breakpoints and interrupts while compiling and running the | 838 // Disable breakpoints and interrupts while compiling and running the |
836 // debugger scripts including the context creation code. | 839 // debugger scripts including the context creation code. |
837 DisableBreak disable(true); | 840 DisableBreak disable(true); |
838 PostponeInterruptsScope postpone(isolate); | 841 PostponeInterruptsScope postpone(isolate_); |
839 | 842 |
840 // Create the debugger context. | 843 // Create the debugger context. |
841 HandleScope scope; | 844 HandleScope scope(isolate_); |
842 Handle<Context> context = | 845 Handle<Context> context = |
843 isolate->bootstrapper()->CreateEnvironment( | 846 isolate_->bootstrapper()->CreateEnvironment( |
844 Handle<Object>::null(), | 847 Handle<Object>::null(), |
845 v8::Handle<ObjectTemplate>(), | 848 v8::Handle<ObjectTemplate>(), |
846 NULL); | 849 NULL); |
847 | 850 |
848 // Use the debugger context. | 851 // Use the debugger context. |
849 SaveContext save(isolate); | 852 SaveContext save(isolate_); |
850 isolate->set_context(*context); | 853 isolate_->set_context(*context); |
851 | 854 |
852 // Expose the builtins object in the debugger context. | 855 // Expose the builtins object in the debugger context. |
853 Handle<String> key = FACTORY->LookupAsciiSymbol("builtins"); | 856 Handle<String> key = isolate_->factory()->LookupAsciiSymbol("builtins"); |
854 Handle<GlobalObject> global = Handle<GlobalObject>(context->global()); | 857 Handle<GlobalObject> global = Handle<GlobalObject>(context->global()); |
855 RETURN_IF_EMPTY_HANDLE_VALUE( | 858 RETURN_IF_EMPTY_HANDLE_VALUE( |
856 isolate, | 859 isolate_, |
857 SetProperty(global, key, Handle<Object>(global->builtins()), | 860 SetProperty(global, key, Handle<Object>(global->builtins()), |
858 NONE, kNonStrictMode), | 861 NONE, kNonStrictMode), |
859 false); | 862 false); |
860 | 863 |
861 // Compile the JavaScript for the debugger in the debugger context. | 864 // Compile the JavaScript for the debugger in the debugger context. |
862 isolate->debugger()->set_compiling_natives(true); | 865 debugger->set_compiling_natives(true); |
863 bool caught_exception = | 866 bool caught_exception = |
864 !CompileDebuggerScript(Natives::GetIndex("mirror")) || | 867 !CompileDebuggerScript(Natives::GetIndex("mirror")) || |
865 !CompileDebuggerScript(Natives::GetIndex("debug")); | 868 !CompileDebuggerScript(Natives::GetIndex("debug")); |
866 | 869 |
867 if (FLAG_enable_liveedit) { | 870 if (FLAG_enable_liveedit) { |
868 caught_exception = caught_exception || | 871 caught_exception = caught_exception || |
869 !CompileDebuggerScript(Natives::GetIndex("liveedit")); | 872 !CompileDebuggerScript(Natives::GetIndex("liveedit")); |
870 } | 873 } |
871 | 874 |
872 isolate->debugger()->set_compiling_natives(false); | 875 debugger->set_compiling_natives(false); |
873 | 876 |
874 // Make sure we mark the debugger as not loading before we might | 877 // Make sure we mark the debugger as not loading before we might |
875 // return. | 878 // return. |
876 isolate->debugger()->set_loading_debugger(false); | 879 debugger->set_loading_debugger(false); |
877 | 880 |
878 // Check for caught exceptions. | 881 // Check for caught exceptions. |
879 if (caught_exception) return false; | 882 if (caught_exception) return false; |
880 | 883 |
881 // Debugger loaded. | 884 // Debugger loaded. |
882 debug_context_ = context; | 885 debug_context_ = context; |
883 | 886 |
884 return true; | 887 return true; |
885 } | 888 } |
886 | 889 |
(...skipping 26 matching lines...) Expand all Loading... | |
913 v->VisitPointer(BitCast<Object**>(&(debug_break_slot_))); | 916 v->VisitPointer(BitCast<Object**>(&(debug_break_slot_))); |
914 } | 917 } |
915 | 918 |
916 | 919 |
917 // This remains a static method so that generated code can call it. | 920 // This remains a static method so that generated code can call it. |
918 Object* Debug::Break(RUNTIME_CALLING_CONVENTION) { | 921 Object* Debug::Break(RUNTIME_CALLING_CONVENTION) { |
919 RUNTIME_GET_ISOLATE; | 922 RUNTIME_GET_ISOLATE; |
920 | 923 |
921 Debug* debug = isolate->debug(); | 924 Debug* debug = isolate->debug(); |
922 Heap* heap = isolate->heap(); | 925 Heap* heap = isolate->heap(); |
923 HandleScope scope; | 926 HandleScope scope(isolate); |
924 ASSERT(args.length() == 0); | 927 ASSERT(args.length() == 0); |
925 | 928 |
926 debug->thread_local_.frame_drop_mode_ = FRAMES_UNTOUCHED; | 929 debug->thread_local_.frame_drop_mode_ = FRAMES_UNTOUCHED; |
927 | 930 |
928 // Get the top-most JavaScript frame. | 931 // Get the top-most JavaScript frame. |
929 JavaScriptFrameIterator it; | 932 JavaScriptFrameIterator it; |
930 JavaScriptFrame* frame = it.frame(); | 933 JavaScriptFrame* frame = it.frame(); |
931 | 934 |
932 // Just continue if breaks are disabled or debugger cannot be loaded. | 935 // Just continue if breaks are disabled or debugger cannot be loaded. |
933 if (debug->disable_break() || !debug->Load()) { | 936 if (debug->disable_break() || !debug->Load()) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1025 } | 1028 } |
1026 | 1029 |
1027 return heap->undefined_value(); | 1030 return heap->undefined_value(); |
1028 } | 1031 } |
1029 | 1032 |
1030 | 1033 |
1031 // Check the break point objects for whether one or more are actually | 1034 // Check the break point objects for whether one or more are actually |
1032 // triggered. This function returns a JSArray with the break point objects | 1035 // triggered. This function returns a JSArray with the break point objects |
1033 // which is triggered. | 1036 // which is triggered. |
1034 Handle<Object> Debug::CheckBreakPoints(Handle<Object> break_point_objects) { | 1037 Handle<Object> Debug::CheckBreakPoints(Handle<Object> break_point_objects) { |
1038 Factory* factory = Isolate::Current()->factory(); | |
Mads Ager (chromium)
2011/03/29 13:57:16
Use isolate_ here as well.
| |
1039 | |
1035 // Count the number of break points hit. If there are multiple break points | 1040 // Count the number of break points hit. If there are multiple break points |
1036 // they are in a FixedArray. | 1041 // they are in a FixedArray. |
1037 Handle<FixedArray> break_points_hit; | 1042 Handle<FixedArray> break_points_hit; |
1038 int break_points_hit_count = 0; | 1043 int break_points_hit_count = 0; |
1039 ASSERT(!break_point_objects->IsUndefined()); | 1044 ASSERT(!break_point_objects->IsUndefined()); |
1040 if (break_point_objects->IsFixedArray()) { | 1045 if (break_point_objects->IsFixedArray()) { |
1041 Handle<FixedArray> array(FixedArray::cast(*break_point_objects)); | 1046 Handle<FixedArray> array(FixedArray::cast(*break_point_objects)); |
1042 break_points_hit = FACTORY->NewFixedArray(array->length()); | 1047 break_points_hit = factory->NewFixedArray(array->length()); |
1043 for (int i = 0; i < array->length(); i++) { | 1048 for (int i = 0; i < array->length(); i++) { |
1044 Handle<Object> o(array->get(i)); | 1049 Handle<Object> o(array->get(i)); |
1045 if (CheckBreakPoint(o)) { | 1050 if (CheckBreakPoint(o)) { |
1046 break_points_hit->set(break_points_hit_count++, *o); | 1051 break_points_hit->set(break_points_hit_count++, *o); |
1047 } | 1052 } |
1048 } | 1053 } |
1049 } else { | 1054 } else { |
1050 break_points_hit = FACTORY->NewFixedArray(1); | 1055 break_points_hit = factory->NewFixedArray(1); |
1051 if (CheckBreakPoint(break_point_objects)) { | 1056 if (CheckBreakPoint(break_point_objects)) { |
1052 break_points_hit->set(break_points_hit_count++, *break_point_objects); | 1057 break_points_hit->set(break_points_hit_count++, *break_point_objects); |
1053 } | 1058 } |
1054 } | 1059 } |
1055 | 1060 |
1056 // Return undefined if no break points were triggered. | 1061 // Return undefined if no break points were triggered. |
1057 if (break_points_hit_count == 0) { | 1062 if (break_points_hit_count == 0) { |
1058 return FACTORY->undefined_value(); | 1063 return factory->undefined_value(); |
1059 } | 1064 } |
1060 // Return break points hit as a JSArray. | 1065 // Return break points hit as a JSArray. |
1061 Handle<JSArray> result = FACTORY->NewJSArrayWithElements(break_points_hit); | 1066 Handle<JSArray> result = factory->NewJSArrayWithElements(break_points_hit); |
1062 result->set_length(Smi::FromInt(break_points_hit_count)); | 1067 result->set_length(Smi::FromInt(break_points_hit_count)); |
1063 return result; | 1068 return result; |
1064 } | 1069 } |
1065 | 1070 |
1066 | 1071 |
1067 // Check whether a single break point object is triggered. | 1072 // Check whether a single break point object is triggered. |
1068 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { | 1073 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { |
1069 HandleScope scope; | 1074 ASSERT(Isolate::Current() == isolate_); |
1075 Factory* factory = isolate_->factory(); | |
1076 HandleScope scope(isolate_); | |
1070 | 1077 |
1071 // Ignore check if break point object is not a JSObject. | 1078 // Ignore check if break point object is not a JSObject. |
1072 if (!break_point_object->IsJSObject()) return true; | 1079 if (!break_point_object->IsJSObject()) return true; |
1073 | 1080 |
1074 // Get the function IsBreakPointTriggered (defined in debug-debugger.js). | 1081 // Get the function IsBreakPointTriggered (defined in debug-debugger.js). |
1075 Handle<String> is_break_point_triggered_symbol = | 1082 Handle<String> is_break_point_triggered_symbol = |
1076 FACTORY->LookupAsciiSymbol("IsBreakPointTriggered"); | 1083 factory->LookupAsciiSymbol("IsBreakPointTriggered"); |
1077 Handle<JSFunction> check_break_point = | 1084 Handle<JSFunction> check_break_point = |
1078 Handle<JSFunction>(JSFunction::cast( | 1085 Handle<JSFunction>(JSFunction::cast( |
1079 debug_context()->global()->GetPropertyNoExceptionThrown( | 1086 debug_context()->global()->GetPropertyNoExceptionThrown( |
1080 *is_break_point_triggered_symbol))); | 1087 *is_break_point_triggered_symbol))); |
1081 | 1088 |
1082 // Get the break id as an object. | 1089 // Get the break id as an object. |
1083 Handle<Object> break_id = FACTORY->NewNumberFromInt(Debug::break_id()); | 1090 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); |
1084 | 1091 |
1085 // Call HandleBreakPointx. | 1092 // Call HandleBreakPointx. |
1086 bool caught_exception = false; | 1093 bool caught_exception = false; |
1087 const int argc = 2; | 1094 const int argc = 2; |
1088 Object** argv[argc] = { | 1095 Object** argv[argc] = { |
1089 break_id.location(), | 1096 break_id.location(), |
1090 reinterpret_cast<Object**>(break_point_object.location()) | 1097 reinterpret_cast<Object**>(break_point_object.location()) |
1091 }; | 1098 }; |
1092 Handle<Object> result = Execution::TryCall(check_break_point, | 1099 Handle<Object> result = Execution::TryCall(check_break_point, |
1093 Isolate::Current()->js_builtins_object(), argc, argv, &caught_exception); | 1100 isolate_->js_builtins_object(), argc, argv, &caught_exception); |
1094 | 1101 |
1095 // If exception or non boolean result handle as not triggered | 1102 // If exception or non boolean result handle as not triggered |
1096 if (caught_exception || !result->IsBoolean()) { | 1103 if (caught_exception || !result->IsBoolean()) { |
1097 return false; | 1104 return false; |
1098 } | 1105 } |
1099 | 1106 |
1100 // Return whether the break point is triggered. | 1107 // Return whether the break point is triggered. |
1101 ASSERT(!result.is_null()); | 1108 ASSERT(!result.is_null()); |
1102 return (*result)->IsTrue(); | 1109 return (*result)->IsTrue(); |
1103 } | 1110 } |
1104 | 1111 |
1105 | 1112 |
1106 // Check whether the function has debug information. | 1113 // Check whether the function has debug information. |
1107 bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) { | 1114 bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) { |
1108 return !shared->debug_info()->IsUndefined(); | 1115 return !shared->debug_info()->IsUndefined(); |
1109 } | 1116 } |
1110 | 1117 |
1111 | 1118 |
1112 // Return the debug info for this function. EnsureDebugInfo must be called | 1119 // Return the debug info for this function. EnsureDebugInfo must be called |
1113 // prior to ensure the debug info has been generated for shared. | 1120 // prior to ensure the debug info has been generated for shared. |
1114 Handle<DebugInfo> Debug::GetDebugInfo(Handle<SharedFunctionInfo> shared) { | 1121 Handle<DebugInfo> Debug::GetDebugInfo(Handle<SharedFunctionInfo> shared) { |
1115 ASSERT(HasDebugInfo(shared)); | 1122 ASSERT(HasDebugInfo(shared)); |
1116 return Handle<DebugInfo>(DebugInfo::cast(shared->debug_info())); | 1123 return Handle<DebugInfo>(DebugInfo::cast(shared->debug_info())); |
1117 } | 1124 } |
1118 | 1125 |
1119 | 1126 |
1120 void Debug::SetBreakPoint(Handle<SharedFunctionInfo> shared, | 1127 void Debug::SetBreakPoint(Handle<SharedFunctionInfo> shared, |
1121 Handle<Object> break_point_object, | 1128 Handle<Object> break_point_object, |
1122 int* source_position) { | 1129 int* source_position) { |
1123 HandleScope scope; | 1130 HandleScope scope(isolate_); |
1124 | 1131 |
1125 if (!EnsureDebugInfo(shared)) { | 1132 if (!EnsureDebugInfo(shared)) { |
1126 // Return if retrieving debug info failed. | 1133 // Return if retrieving debug info failed. |
1127 return; | 1134 return; |
1128 } | 1135 } |
1129 | 1136 |
1130 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1137 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1131 // Source positions starts with zero. | 1138 // Source positions starts with zero. |
1132 ASSERT(source_position >= 0); | 1139 ASSERT(source_position >= 0); |
1133 | 1140 |
1134 // Find the break point and change it. | 1141 // Find the break point and change it. |
1135 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); | 1142 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
1136 it.FindBreakLocationFromPosition(*source_position); | 1143 it.FindBreakLocationFromPosition(*source_position); |
1137 it.SetBreakPoint(break_point_object); | 1144 it.SetBreakPoint(break_point_object); |
1138 | 1145 |
1139 *source_position = it.position(); | 1146 *source_position = it.position(); |
1140 | 1147 |
1141 // At least one active break point now. | 1148 // At least one active break point now. |
1142 ASSERT(debug_info->GetBreakPointCount() > 0); | 1149 ASSERT(debug_info->GetBreakPointCount() > 0); |
1143 } | 1150 } |
1144 | 1151 |
1145 | 1152 |
1146 void Debug::ClearBreakPoint(Handle<Object> break_point_object) { | 1153 void Debug::ClearBreakPoint(Handle<Object> break_point_object) { |
1147 HandleScope scope; | 1154 HandleScope scope(isolate_); |
1148 | 1155 |
1149 DebugInfoListNode* node = debug_info_list_; | 1156 DebugInfoListNode* node = debug_info_list_; |
1150 while (node != NULL) { | 1157 while (node != NULL) { |
1151 Object* result = DebugInfo::FindBreakPointInfo(node->debug_info(), | 1158 Object* result = DebugInfo::FindBreakPointInfo(node->debug_info(), |
1152 break_point_object); | 1159 break_point_object); |
1153 if (!result->IsUndefined()) { | 1160 if (!result->IsUndefined()) { |
1154 // Get information in the break point. | 1161 // Get information in the break point. |
1155 BreakPointInfo* break_point_info = BreakPointInfo::cast(result); | 1162 BreakPointInfo* break_point_info = BreakPointInfo::cast(result); |
1156 Handle<DebugInfo> debug_info = node->debug_info(); | 1163 Handle<DebugInfo> debug_info = node->debug_info(); |
1157 Handle<SharedFunctionInfo> shared(debug_info->shared()); | 1164 Handle<SharedFunctionInfo> shared(debug_info->shared()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 bool Debug::IsBreakOnException(ExceptionBreakType type) { | 1250 bool Debug::IsBreakOnException(ExceptionBreakType type) { |
1244 if (type == BreakUncaughtException) { | 1251 if (type == BreakUncaughtException) { |
1245 return break_on_uncaught_exception_; | 1252 return break_on_uncaught_exception_; |
1246 } else { | 1253 } else { |
1247 return break_on_exception_; | 1254 return break_on_exception_; |
1248 } | 1255 } |
1249 } | 1256 } |
1250 | 1257 |
1251 | 1258 |
1252 void Debug::PrepareStep(StepAction step_action, int step_count) { | 1259 void Debug::PrepareStep(StepAction step_action, int step_count) { |
1253 HandleScope scope; | 1260 ASSERT(Isolate::Current() == isolate_); |
1261 HandleScope scope(isolate_); | |
1254 ASSERT(Debug::InDebugger()); | 1262 ASSERT(Debug::InDebugger()); |
1255 | 1263 |
1256 // Remember this step action and count. | 1264 // Remember this step action and count. |
1257 thread_local_.last_step_action_ = step_action; | 1265 thread_local_.last_step_action_ = step_action; |
1258 if (step_action == StepOut) { | 1266 if (step_action == StepOut) { |
1259 // For step out target frame will be found on the stack so there is no need | 1267 // For step out target frame will be found on the stack so there is no need |
1260 // to set step counter for it. It's expected to always be 0 for StepOut. | 1268 // to set step counter for it. It's expected to always be 0 for StepOut. |
1261 thread_local_.step_count_ = 0; | 1269 thread_local_.step_count_ = 0; |
1262 } else { | 1270 } else { |
1263 thread_local_.step_count_ = step_count; | 1271 thread_local_.step_count_ = step_count; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1391 restarted_function->shared()); | 1399 restarted_function->shared()); |
1392 FloodWithOneShot(restarted_shared); | 1400 FloodWithOneShot(restarted_shared); |
1393 } else if (!call_function_stub.is_null()) { | 1401 } else if (!call_function_stub.is_null()) { |
1394 // If it's CallFunction stub ensure target function is compiled and flood | 1402 // If it's CallFunction stub ensure target function is compiled and flood |
1395 // it with one shot breakpoints. | 1403 // it with one shot breakpoints. |
1396 | 1404 |
1397 // Find out number of arguments from the stub minor key. | 1405 // Find out number of arguments from the stub minor key. |
1398 // Reverse lookup required as the minor key cannot be retrieved | 1406 // Reverse lookup required as the minor key cannot be retrieved |
1399 // from the code object. | 1407 // from the code object. |
1400 Handle<Object> obj( | 1408 Handle<Object> obj( |
1401 HEAP->code_stubs()->SlowReverseLookup(*call_function_stub)); | 1409 isolate_->heap()->code_stubs()->SlowReverseLookup( |
1410 *call_function_stub)); | |
1402 ASSERT(!obj.is_null()); | 1411 ASSERT(!obj.is_null()); |
1403 ASSERT(!(*obj)->IsUndefined()); | 1412 ASSERT(!(*obj)->IsUndefined()); |
1404 ASSERT(obj->IsSmi()); | 1413 ASSERT(obj->IsSmi()); |
1405 // Get the STUB key and extract major and minor key. | 1414 // Get the STUB key and extract major and minor key. |
1406 uint32_t key = Smi::cast(*obj)->value(); | 1415 uint32_t key = Smi::cast(*obj)->value(); |
1407 // Argc in the stub is the number of arguments passed - not the | 1416 // Argc in the stub is the number of arguments passed - not the |
1408 // expected arguments of the called function. | 1417 // expected arguments of the called function. |
1409 int call_function_arg_count = | 1418 int call_function_arg_count = |
1410 CallFunctionStub::ExtractArgcFromMinorKey( | 1419 CallFunctionStub::ExtractArgcFromMinorKey( |
1411 CodeStub::MinorKeyFromKey(key)); | 1420 CodeStub::MinorKeyFromKey(key)); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1546 } | 1555 } |
1547 | 1556 |
1548 UNREACHABLE(); | 1557 UNREACHABLE(); |
1549 return Handle<Code>::null(); | 1558 return Handle<Code>::null(); |
1550 } | 1559 } |
1551 | 1560 |
1552 | 1561 |
1553 // Simple function for returning the source positions for active break points. | 1562 // Simple function for returning the source positions for active break points. |
1554 Handle<Object> Debug::GetSourceBreakLocations( | 1563 Handle<Object> Debug::GetSourceBreakLocations( |
1555 Handle<SharedFunctionInfo> shared) { | 1564 Handle<SharedFunctionInfo> shared) { |
1556 if (!HasDebugInfo(shared)) return Handle<Object>(HEAP->undefined_value()); | 1565 Isolate* isolate = Isolate::Current(); |
1566 Heap* heap = isolate->heap(); | |
1567 if (!HasDebugInfo(shared)) return Handle<Object>(heap->undefined_value()); | |
1557 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1568 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1558 if (debug_info->GetBreakPointCount() == 0) { | 1569 if (debug_info->GetBreakPointCount() == 0) { |
1559 return Handle<Object>(HEAP->undefined_value()); | 1570 return Handle<Object>(heap->undefined_value()); |
1560 } | 1571 } |
1561 Handle<FixedArray> locations = | 1572 Handle<FixedArray> locations = |
1562 FACTORY->NewFixedArray(debug_info->GetBreakPointCount()); | 1573 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); |
1563 int count = 0; | 1574 int count = 0; |
1564 for (int i = 0; i < debug_info->break_points()->length(); i++) { | 1575 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
1565 if (!debug_info->break_points()->get(i)->IsUndefined()) { | 1576 if (!debug_info->break_points()->get(i)->IsUndefined()) { |
1566 BreakPointInfo* break_point_info = | 1577 BreakPointInfo* break_point_info = |
1567 BreakPointInfo::cast(debug_info->break_points()->get(i)); | 1578 BreakPointInfo::cast(debug_info->break_points()->get(i)); |
1568 if (break_point_info->GetBreakPointCount() > 0) { | 1579 if (break_point_info->GetBreakPointCount() > 0) { |
1569 locations->set(count++, break_point_info->statement_position()); | 1580 locations->set(count++, break_point_info->statement_position()); |
1570 } | 1581 } |
1571 } | 1582 } |
1572 } | 1583 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1725 DebugInfoListNode* prev = NULL; | 1736 DebugInfoListNode* prev = NULL; |
1726 DebugInfoListNode* current = debug_info_list_; | 1737 DebugInfoListNode* current = debug_info_list_; |
1727 while (current != NULL) { | 1738 while (current != NULL) { |
1728 if (*current->debug_info() == *debug_info) { | 1739 if (*current->debug_info() == *debug_info) { |
1729 // Unlink from list. If prev is NULL we are looking at the first element. | 1740 // Unlink from list. If prev is NULL we are looking at the first element. |
1730 if (prev == NULL) { | 1741 if (prev == NULL) { |
1731 debug_info_list_ = current->next(); | 1742 debug_info_list_ = current->next(); |
1732 } else { | 1743 } else { |
1733 prev->set_next(current->next()); | 1744 prev->set_next(current->next()); |
1734 } | 1745 } |
1735 current->debug_info()->shared()->set_debug_info(HEAP->undefined_value()); | 1746 current->debug_info()->shared()->set_debug_info( |
1747 isolate_->heap()->undefined_value()); | |
1736 delete current; | 1748 delete current; |
1737 | 1749 |
1738 // If there are no more debug info objects there are not more break | 1750 // If there are no more debug info objects there are not more break |
1739 // points. | 1751 // points. |
1740 has_break_points_ = debug_info_list_ != NULL; | 1752 has_break_points_ = debug_info_list_ != NULL; |
1741 | 1753 |
1742 return; | 1754 return; |
1743 } | 1755 } |
1744 // Move to next in list. | 1756 // Move to next in list. |
1745 prev = current; | 1757 prev = current; |
1746 current = current->next(); | 1758 current = current->next(); |
1747 } | 1759 } |
1748 UNREACHABLE(); | 1760 UNREACHABLE(); |
1749 } | 1761 } |
1750 | 1762 |
1751 | 1763 |
1752 void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { | 1764 void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { |
1753 HandleScope scope; | 1765 ASSERT(Isolate::Current() == isolate_); |
1766 HandleScope scope(isolate_); | |
1754 | 1767 |
1755 // Get the executing function in which the debug break occurred. | 1768 // Get the executing function in which the debug break occurred. |
1756 Handle<SharedFunctionInfo> shared = | 1769 Handle<SharedFunctionInfo> shared = |
1757 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); | 1770 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
1758 if (!EnsureDebugInfo(shared)) { | 1771 if (!EnsureDebugInfo(shared)) { |
1759 // Return if we failed to retrieve the debug info. | 1772 // Return if we failed to retrieve the debug info. |
1760 return; | 1773 return; |
1761 } | 1774 } |
1762 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1775 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1763 Handle<Code> code(debug_info->code()); | 1776 Handle<Code> code(debug_info->code()); |
1764 Handle<Code> original_code(debug_info->original_code()); | 1777 Handle<Code> original_code(debug_info->original_code()); |
1765 #ifdef DEBUG | 1778 #ifdef DEBUG |
1766 // Get the code which is actually executing. | 1779 // Get the code which is actually executing. |
1767 Handle<Code> frame_code(frame->LookupCode(Isolate::Current())); | 1780 Handle<Code> frame_code(frame->LookupCode(isolate_)); |
1768 ASSERT(frame_code.is_identical_to(code)); | 1781 ASSERT(frame_code.is_identical_to(code)); |
1769 #endif | 1782 #endif |
1770 | 1783 |
1771 // Find the call address in the running code. This address holds the call to | 1784 // Find the call address in the running code. This address holds the call to |
1772 // either a DebugBreakXXX or to the debug break return entry code if the | 1785 // either a DebugBreakXXX or to the debug break return entry code if the |
1773 // break point is still active after processing the break point. | 1786 // break point is still active after processing the break point. |
1774 Address addr = frame->pc() - Assembler::kCallTargetAddressOffset; | 1787 Address addr = frame->pc() - Assembler::kCallTargetAddressOffset; |
1775 | 1788 |
1776 // Check if the location is at JS exit or debug break slot. | 1789 // Check if the location is at JS exit or debug break slot. |
1777 bool at_js_return = false; | 1790 bool at_js_return = false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1826 // There is no longer a break point present. Don't try to look in the | 1839 // There is no longer a break point present. Don't try to look in the |
1827 // original code as the running code will have the right address. This takes | 1840 // original code as the running code will have the right address. This takes |
1828 // care of the case where the last break point is removed from the function | 1841 // care of the case where the last break point is removed from the function |
1829 // and therefore no "original code" is available. | 1842 // and therefore no "original code" is available. |
1830 thread_local_.after_break_target_ = Assembler::target_address_at(addr); | 1843 thread_local_.after_break_target_ = Assembler::target_address_at(addr); |
1831 } | 1844 } |
1832 } | 1845 } |
1833 | 1846 |
1834 | 1847 |
1835 bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { | 1848 bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { |
1836 HandleScope scope; | 1849 HandleScope scope(isolate_); |
1837 | 1850 |
1838 // Get the executing function in which the debug break occurred. | 1851 // Get the executing function in which the debug break occurred. |
1839 Handle<SharedFunctionInfo> shared = | 1852 Handle<SharedFunctionInfo> shared = |
1840 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); | 1853 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
1841 if (!EnsureDebugInfo(shared)) { | 1854 if (!EnsureDebugInfo(shared)) { |
1842 // Return if we failed to retrieve the debug info. | 1855 // Return if we failed to retrieve the debug info. |
1843 return false; | 1856 return false; |
1844 } | 1857 } |
1845 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1858 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1846 Handle<Code> code(debug_info->code()); | 1859 Handle<Code> code(debug_info->code()); |
(...skipping 28 matching lines...) Expand all Loading... | |
1875 restarter_frame_function_pointer; | 1888 restarter_frame_function_pointer; |
1876 } | 1889 } |
1877 | 1890 |
1878 | 1891 |
1879 bool Debug::IsDebugGlobal(GlobalObject* global) { | 1892 bool Debug::IsDebugGlobal(GlobalObject* global) { |
1880 return IsLoaded() && global == debug_context()->global(); | 1893 return IsLoaded() && global == debug_context()->global(); |
1881 } | 1894 } |
1882 | 1895 |
1883 | 1896 |
1884 void Debug::ClearMirrorCache() { | 1897 void Debug::ClearMirrorCache() { |
1898 ASSERT(Isolate::Current() == isolate_); | |
1885 PostponeInterruptsScope postpone(isolate_); | 1899 PostponeInterruptsScope postpone(isolate_); |
1886 HandleScope scope; | 1900 HandleScope scope(isolate_); |
1887 ASSERT(Isolate::Current()->context() == *Debug::debug_context()); | 1901 ASSERT(isolate_->context() == *Debug::debug_context()); |
1888 | 1902 |
1889 // Clear the mirror cache. | 1903 // Clear the mirror cache. |
1890 Handle<String> function_name = | 1904 Handle<String> function_name = |
1891 FACTORY->LookupSymbol(CStrVector("ClearMirrorCache")); | 1905 isolate_->factory()->LookupSymbol(CStrVector("ClearMirrorCache")); |
1892 Handle<Object> fun(Isolate::Current()->global()->GetPropertyNoExceptionThrown( | 1906 Handle<Object> fun(Isolate::Current()->global()->GetPropertyNoExceptionThrown( |
1893 *function_name)); | 1907 *function_name)); |
1894 ASSERT(fun->IsJSFunction()); | 1908 ASSERT(fun->IsJSFunction()); |
1895 bool caught_exception; | 1909 bool caught_exception; |
1896 Handle<Object> js_object = Execution::TryCall( | 1910 Handle<Object> js_object = Execution::TryCall( |
1897 Handle<JSFunction>::cast(fun), | 1911 Handle<JSFunction>::cast(fun), |
1898 Handle<JSObject>(Debug::debug_context()->global()), | 1912 Handle<JSObject>(Debug::debug_context()->global()), |
1899 0, NULL, &caught_exception); | 1913 0, NULL, &caught_exception); |
1900 } | 1914 } |
1901 | 1915 |
1902 | 1916 |
1903 void Debug::CreateScriptCache() { | 1917 void Debug::CreateScriptCache() { |
1904 HandleScope scope; | 1918 ASSERT(Isolate::Current() == isolate_); |
1919 Heap* heap = isolate_->heap(); | |
1920 HandleScope scope(isolate_); | |
1905 | 1921 |
1906 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | 1922 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
1907 // rid of all the cached script wrappers and the second gets rid of the | 1923 // rid of all the cached script wrappers and the second gets rid of the |
1908 // scripts which are no longer referenced. | 1924 // scripts which are no longer referenced. |
1909 HEAP->CollectAllGarbage(false); | 1925 heap->CollectAllGarbage(false); |
1910 HEAP->CollectAllGarbage(false); | 1926 heap->CollectAllGarbage(false); |
1911 | 1927 |
1912 ASSERT(script_cache_ == NULL); | 1928 ASSERT(script_cache_ == NULL); |
1913 script_cache_ = new ScriptCache(); | 1929 script_cache_ = new ScriptCache(); |
1914 | 1930 |
1915 // Scan heap for Script objects. | 1931 // Scan heap for Script objects. |
1916 int count = 0; | 1932 int count = 0; |
1917 HeapIterator iterator; | 1933 HeapIterator iterator; |
1918 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 1934 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
1919 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { | 1935 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { |
1920 script_cache_->Add(Handle<Script>(Script::cast(obj))); | 1936 script_cache_->Add(Handle<Script>(Script::cast(obj))); |
(...skipping 13 matching lines...) Expand all Loading... | |
1934 | 1950 |
1935 | 1951 |
1936 void Debug::AddScriptToScriptCache(Handle<Script> script) { | 1952 void Debug::AddScriptToScriptCache(Handle<Script> script) { |
1937 if (script_cache_ != NULL) { | 1953 if (script_cache_ != NULL) { |
1938 script_cache_->Add(script); | 1954 script_cache_->Add(script); |
1939 } | 1955 } |
1940 } | 1956 } |
1941 | 1957 |
1942 | 1958 |
1943 Handle<FixedArray> Debug::GetLoadedScripts() { | 1959 Handle<FixedArray> Debug::GetLoadedScripts() { |
1960 ASSERT(Isolate::Current() == isolate_); | |
1944 // Create and fill the script cache when the loaded scripts is requested for | 1961 // Create and fill the script cache when the loaded scripts is requested for |
1945 // the first time. | 1962 // the first time. |
1946 if (script_cache_ == NULL) { | 1963 if (script_cache_ == NULL) { |
1947 CreateScriptCache(); | 1964 CreateScriptCache(); |
1948 } | 1965 } |
1949 | 1966 |
1950 // If the script cache is not active just return an empty array. | 1967 // If the script cache is not active just return an empty array. |
1951 ASSERT(script_cache_ != NULL); | 1968 ASSERT(script_cache_ != NULL); |
1952 if (script_cache_ == NULL) { | 1969 if (script_cache_ == NULL) { |
1953 FACTORY->NewFixedArray(0); | 1970 isolate_->factory()->NewFixedArray(0); |
1954 } | 1971 } |
1955 | 1972 |
1956 // Perform GC to get unreferenced scripts evicted from the cache before | 1973 // Perform GC to get unreferenced scripts evicted from the cache before |
1957 // returning the content. | 1974 // returning the content. |
1958 HEAP->CollectAllGarbage(false); | 1975 isolate_->heap()->CollectAllGarbage(false); |
1959 | 1976 |
1960 // Get the scripts from the cache. | 1977 // Get the scripts from the cache. |
1961 return script_cache_->GetScripts(); | 1978 return script_cache_->GetScripts(); |
1962 } | 1979 } |
1963 | 1980 |
1964 | 1981 |
1965 void Debug::AfterGarbageCollection() { | 1982 void Debug::AfterGarbageCollection() { |
1966 // Generate events for collected scripts. | 1983 // Generate events for collected scripts. |
1967 if (script_cache_ != NULL) { | 1984 if (script_cache_ != NULL) { |
1968 script_cache_->ProcessCollectedScripts(); | 1985 script_cache_->ProcessCollectedScripts(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2001 } | 2018 } |
2002 | 2019 |
2003 | 2020 |
2004 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 2021 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
2005 int argc, Object*** argv, | 2022 int argc, Object*** argv, |
2006 bool* caught_exception) { | 2023 bool* caught_exception) { |
2007 ASSERT(Isolate::Current() == isolate_); | 2024 ASSERT(Isolate::Current() == isolate_); |
2008 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2025 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
2009 | 2026 |
2010 // Create the execution state object. | 2027 // Create the execution state object. |
2011 Handle<String> constructor_str = FACTORY->LookupSymbol(constructor_name); | 2028 Handle<String> constructor_str = |
2029 isolate_->factory()->LookupSymbol(constructor_name); | |
2012 Handle<Object> constructor( | 2030 Handle<Object> constructor( |
2013 isolate_->global()->GetPropertyNoExceptionThrown(*constructor_str)); | 2031 isolate_->global()->GetPropertyNoExceptionThrown(*constructor_str)); |
2014 ASSERT(constructor->IsJSFunction()); | 2032 ASSERT(constructor->IsJSFunction()); |
2015 if (!constructor->IsJSFunction()) { | 2033 if (!constructor->IsJSFunction()) { |
2016 *caught_exception = true; | 2034 *caught_exception = true; |
2017 return FACTORY->undefined_value(); | 2035 return isolate_->factory()->undefined_value(); |
2018 } | 2036 } |
2019 Handle<Object> js_object = Execution::TryCall( | 2037 Handle<Object> js_object = Execution::TryCall( |
2020 Handle<JSFunction>::cast(constructor), | 2038 Handle<JSFunction>::cast(constructor), |
2021 Handle<JSObject>(isolate_->debug()->debug_context()->global()), | 2039 Handle<JSObject>(isolate_->debug()->debug_context()->global()), |
2022 argc, argv, caught_exception); | 2040 argc, argv, caught_exception); |
2023 return js_object; | 2041 return js_object; |
2024 } | 2042 } |
2025 | 2043 |
2026 | 2044 |
2027 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { | 2045 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { |
2028 ASSERT(Isolate::Current() == isolate_); | 2046 ASSERT(Isolate::Current() == isolate_); |
2029 // Create the execution state object. | 2047 // Create the execution state object. |
2030 Handle<Object> break_id = FACTORY->NewNumberFromInt( | 2048 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( |
2031 isolate_->debug()->break_id()); | 2049 isolate_->debug()->break_id()); |
2032 const int argc = 1; | 2050 const int argc = 1; |
2033 Object** argv[argc] = { break_id.location() }; | 2051 Object** argv[argc] = { break_id.location() }; |
2034 return MakeJSObject(CStrVector("MakeExecutionState"), | 2052 return MakeJSObject(CStrVector("MakeExecutionState"), |
2035 argc, argv, caught_exception); | 2053 argc, argv, caught_exception); |
2036 } | 2054 } |
2037 | 2055 |
2038 | 2056 |
2039 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, | 2057 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, |
2040 Handle<Object> break_points_hit, | 2058 Handle<Object> break_points_hit, |
2041 bool* caught_exception) { | 2059 bool* caught_exception) { |
2042 ASSERT(Isolate::Current() == isolate_); | 2060 ASSERT(Isolate::Current() == isolate_); |
2043 // Create the new break event object. | 2061 // Create the new break event object. |
2044 const int argc = 2; | 2062 const int argc = 2; |
2045 Object** argv[argc] = { exec_state.location(), | 2063 Object** argv[argc] = { exec_state.location(), |
2046 break_points_hit.location() }; | 2064 break_points_hit.location() }; |
2047 return MakeJSObject(CStrVector("MakeBreakEvent"), | 2065 return MakeJSObject(CStrVector("MakeBreakEvent"), |
2048 argc, | 2066 argc, |
2049 argv, | 2067 argv, |
2050 caught_exception); | 2068 caught_exception); |
2051 } | 2069 } |
2052 | 2070 |
2053 | 2071 |
2054 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, | 2072 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, |
2055 Handle<Object> exception, | 2073 Handle<Object> exception, |
2056 bool uncaught, | 2074 bool uncaught, |
2057 bool* caught_exception) { | 2075 bool* caught_exception) { |
2058 ASSERT(Isolate::Current() == isolate_); | 2076 ASSERT(Isolate::Current() == isolate_); |
2077 Factory* factory = isolate_->factory(); | |
2059 // Create the new exception event object. | 2078 // Create the new exception event object. |
2060 const int argc = 3; | 2079 const int argc = 3; |
2061 Object** argv[argc] = { exec_state.location(), | 2080 Object** argv[argc] = { exec_state.location(), |
2062 exception.location(), | 2081 exception.location(), |
2063 uncaught ? FACTORY->true_value().location() : | 2082 uncaught ? factory->true_value().location() : |
2064 FACTORY->false_value().location()}; | 2083 factory->false_value().location()}; |
2065 return MakeJSObject(CStrVector("MakeExceptionEvent"), | 2084 return MakeJSObject(CStrVector("MakeExceptionEvent"), |
2066 argc, argv, caught_exception); | 2085 argc, argv, caught_exception); |
2067 } | 2086 } |
2068 | 2087 |
2069 | 2088 |
2070 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, | 2089 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, |
2071 bool* caught_exception) { | 2090 bool* caught_exception) { |
2072 ASSERT(Isolate::Current() == isolate_); | 2091 ASSERT(Isolate::Current() == isolate_); |
2073 // Create the new function event object. | 2092 // Create the new function event object. |
2074 const int argc = 1; | 2093 const int argc = 1; |
2075 Object** argv[argc] = { function.location() }; | 2094 Object** argv[argc] = { function.location() }; |
2076 return MakeJSObject(CStrVector("MakeNewFunctionEvent"), | 2095 return MakeJSObject(CStrVector("MakeNewFunctionEvent"), |
2077 argc, argv, caught_exception); | 2096 argc, argv, caught_exception); |
2078 } | 2097 } |
2079 | 2098 |
2080 | 2099 |
2081 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, | 2100 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, |
2082 bool before, | 2101 bool before, |
2083 bool* caught_exception) { | 2102 bool* caught_exception) { |
2084 ASSERT(Isolate::Current() == isolate_); | 2103 ASSERT(Isolate::Current() == isolate_); |
2104 Factory* factory = isolate_->factory(); | |
2085 // Create the compile event object. | 2105 // Create the compile event object. |
2086 Handle<Object> exec_state = MakeExecutionState(caught_exception); | 2106 Handle<Object> exec_state = MakeExecutionState(caught_exception); |
2087 Handle<Object> script_wrapper = GetScriptWrapper(script); | 2107 Handle<Object> script_wrapper = GetScriptWrapper(script); |
2088 const int argc = 3; | 2108 const int argc = 3; |
2089 Object** argv[argc] = { exec_state.location(), | 2109 Object** argv[argc] = { exec_state.location(), |
2090 script_wrapper.location(), | 2110 script_wrapper.location(), |
2091 before ? FACTORY->true_value().location() : | 2111 before ? factory->true_value().location() : |
2092 FACTORY->false_value().location() }; | 2112 factory->false_value().location() }; |
2093 | 2113 |
2094 return MakeJSObject(CStrVector("MakeCompileEvent"), | 2114 return MakeJSObject(CStrVector("MakeCompileEvent"), |
2095 argc, | 2115 argc, |
2096 argv, | 2116 argv, |
2097 caught_exception); | 2117 caught_exception); |
2098 } | 2118 } |
2099 | 2119 |
2100 | 2120 |
2101 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, | 2121 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, |
2102 bool* caught_exception) { | 2122 bool* caught_exception) { |
2103 ASSERT(Isolate::Current() == isolate_); | 2123 ASSERT(Isolate::Current() == isolate_); |
2104 // Create the script collected event object. | 2124 // Create the script collected event object. |
2105 Handle<Object> exec_state = MakeExecutionState(caught_exception); | 2125 Handle<Object> exec_state = MakeExecutionState(caught_exception); |
2106 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id)); | 2126 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id)); |
2107 const int argc = 2; | 2127 const int argc = 2; |
2108 Object** argv[argc] = { exec_state.location(), id_object.location() }; | 2128 Object** argv[argc] = { exec_state.location(), id_object.location() }; |
2109 | 2129 |
2110 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), | 2130 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), |
2111 argc, | 2131 argc, |
2112 argv, | 2132 argv, |
2113 caught_exception); | 2133 caught_exception); |
2114 } | 2134 } |
2115 | 2135 |
2116 | 2136 |
2117 void Debugger::OnException(Handle<Object> exception, bool uncaught) { | 2137 void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
2118 ASSERT(Isolate::Current() == isolate_); | 2138 ASSERT(Isolate::Current() == isolate_); |
2119 HandleScope scope; | 2139 HandleScope scope(isolate_); |
2140 Debug* debug = isolate_->debug(); | |
2120 | 2141 |
2121 // Bail out based on state or if there is no listener for this event | 2142 // Bail out based on state or if there is no listener for this event |
2122 if (isolate_->debug()->InDebugger()) return; | 2143 if (debug->InDebugger()) return; |
2123 if (!Debugger::EventActive(v8::Exception)) return; | 2144 if (!Debugger::EventActive(v8::Exception)) return; |
2124 | 2145 |
2125 // Bail out if exception breaks are not active | 2146 // Bail out if exception breaks are not active |
2126 if (uncaught) { | 2147 if (uncaught) { |
2127 // Uncaught exceptions are reported by either flags. | 2148 // Uncaught exceptions are reported by either flags. |
2128 if (!(isolate_->debug()->break_on_uncaught_exception() || | 2149 if (!(debug->break_on_uncaught_exception() || |
2129 isolate_->debug()->break_on_exception())) return; | 2150 debug->break_on_exception())) return; |
2130 } else { | 2151 } else { |
2131 // Caught exceptions are reported is activated. | 2152 // Caught exceptions are reported is activated. |
2132 if (!isolate_->debug()->break_on_exception()) return; | 2153 if (!debug->break_on_exception()) return; |
2133 } | 2154 } |
2134 | 2155 |
2135 // Enter the debugger. | 2156 // Enter the debugger. |
2136 EnterDebugger debugger; | 2157 EnterDebugger debugger; |
2137 if (debugger.FailedToEnter()) return; | 2158 if (debugger.FailedToEnter()) return; |
2138 | 2159 |
2139 // Clear all current stepping setup. | 2160 // Clear all current stepping setup. |
2140 isolate_->debug()->ClearStepping(); | 2161 debug->ClearStepping(); |
2141 // Create the event data object. | 2162 // Create the event data object. |
2142 bool caught_exception = false; | 2163 bool caught_exception = false; |
2143 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 2164 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
2144 Handle<Object> event_data; | 2165 Handle<Object> event_data; |
2145 if (!caught_exception) { | 2166 if (!caught_exception) { |
2146 event_data = MakeExceptionEvent(exec_state, exception, uncaught, | 2167 event_data = MakeExceptionEvent(exec_state, exception, uncaught, |
2147 &caught_exception); | 2168 &caught_exception); |
2148 } | 2169 } |
2149 // Bail out and don't call debugger if exception. | 2170 // Bail out and don't call debugger if exception. |
2150 if (caught_exception) { | 2171 if (caught_exception) { |
2151 return; | 2172 return; |
2152 } | 2173 } |
2153 | 2174 |
2154 // Process debug event. | 2175 // Process debug event. |
2155 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); | 2176 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
2156 // Return to continue execution from where the exception was thrown. | 2177 // Return to continue execution from where the exception was thrown. |
2157 } | 2178 } |
2158 | 2179 |
2159 | 2180 |
2160 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, | 2181 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, |
2161 bool auto_continue) { | 2182 bool auto_continue) { |
2162 ASSERT(Isolate::Current() == isolate_); | 2183 ASSERT(Isolate::Current() == isolate_); |
2163 HandleScope scope; | 2184 HandleScope scope(isolate_); |
2164 | 2185 |
2165 // Debugger has already been entered by caller. | 2186 // Debugger has already been entered by caller. |
2166 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2187 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
2167 | 2188 |
2168 // Bail out if there is no listener for this event | 2189 // Bail out if there is no listener for this event |
2169 if (!Debugger::EventActive(v8::Break)) return; | 2190 if (!Debugger::EventActive(v8::Break)) return; |
2170 | 2191 |
2171 // Debugger must be entered in advance. | 2192 // Debugger must be entered in advance. |
2172 ASSERT(Isolate::Current()->context() == *isolate_->debug()->debug_context()); | 2193 ASSERT(Isolate::Current()->context() == *isolate_->debug()->debug_context()); |
2173 | 2194 |
(...skipping 12 matching lines...) Expand all Loading... | |
2186 | 2207 |
2187 // Process debug event. | 2208 // Process debug event. |
2188 ProcessDebugEvent(v8::Break, | 2209 ProcessDebugEvent(v8::Break, |
2189 Handle<JSObject>::cast(event_data), | 2210 Handle<JSObject>::cast(event_data), |
2190 auto_continue); | 2211 auto_continue); |
2191 } | 2212 } |
2192 | 2213 |
2193 | 2214 |
2194 void Debugger::OnBeforeCompile(Handle<Script> script) { | 2215 void Debugger::OnBeforeCompile(Handle<Script> script) { |
2195 ASSERT(Isolate::Current() == isolate_); | 2216 ASSERT(Isolate::Current() == isolate_); |
2196 HandleScope scope; | 2217 HandleScope scope(isolate_); |
2197 | 2218 |
2198 // Bail out based on state or if there is no listener for this event | 2219 // Bail out based on state or if there is no listener for this event |
2199 if (isolate_->debug()->InDebugger()) return; | 2220 if (isolate_->debug()->InDebugger()) return; |
2200 if (compiling_natives()) return; | 2221 if (compiling_natives()) return; |
2201 if (!EventActive(v8::BeforeCompile)) return; | 2222 if (!EventActive(v8::BeforeCompile)) return; |
2202 | 2223 |
2203 // Enter the debugger. | 2224 // Enter the debugger. |
2204 EnterDebugger debugger; | 2225 EnterDebugger debugger; |
2205 if (debugger.FailedToEnter()) return; | 2226 if (debugger.FailedToEnter()) return; |
2206 | 2227 |
2207 // Create the event data object. | 2228 // Create the event data object. |
2208 bool caught_exception = false; | 2229 bool caught_exception = false; |
2209 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); | 2230 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); |
2210 // Bail out and don't call debugger if exception. | 2231 // Bail out and don't call debugger if exception. |
2211 if (caught_exception) { | 2232 if (caught_exception) { |
2212 return; | 2233 return; |
2213 } | 2234 } |
2214 | 2235 |
2215 // Process debug event. | 2236 // Process debug event. |
2216 ProcessDebugEvent(v8::BeforeCompile, | 2237 ProcessDebugEvent(v8::BeforeCompile, |
2217 Handle<JSObject>::cast(event_data), | 2238 Handle<JSObject>::cast(event_data), |
2218 true); | 2239 true); |
2219 } | 2240 } |
2220 | 2241 |
2221 | 2242 |
2222 // Handle debugger actions when a new script is compiled. | 2243 // Handle debugger actions when a new script is compiled. |
2223 void Debugger::OnAfterCompile(Handle<Script> script, | 2244 void Debugger::OnAfterCompile(Handle<Script> script, |
2224 AfterCompileFlags after_compile_flags) { | 2245 AfterCompileFlags after_compile_flags) { |
2225 ASSERT(Isolate::Current() == isolate_); | 2246 ASSERT(Isolate::Current() == isolate_); |
2226 HandleScope scope; | 2247 HandleScope scope(isolate_); |
2248 Debug* debug = isolate_->debug(); | |
2227 | 2249 |
2228 // Add the newly compiled script to the script cache. | 2250 // Add the newly compiled script to the script cache. |
2229 isolate_->debug()->AddScriptToScriptCache(script); | 2251 debug->AddScriptToScriptCache(script); |
2230 | 2252 |
2231 // No more to do if not debugging. | 2253 // No more to do if not debugging. |
2232 if (!IsDebuggerActive()) return; | 2254 if (!IsDebuggerActive()) return; |
2233 | 2255 |
2234 // No compile events while compiling natives. | 2256 // No compile events while compiling natives. |
2235 if (compiling_natives()) return; | 2257 if (compiling_natives()) return; |
2236 | 2258 |
2237 // Store whether in debugger before entering debugger. | 2259 // Store whether in debugger before entering debugger. |
2238 bool in_debugger = isolate_->debug()->InDebugger(); | 2260 bool in_debugger = debug->InDebugger(); |
2239 | 2261 |
2240 // Enter the debugger. | 2262 // Enter the debugger. |
2241 EnterDebugger debugger; | 2263 EnterDebugger debugger; |
2242 if (debugger.FailedToEnter()) return; | 2264 if (debugger.FailedToEnter()) return; |
2243 | 2265 |
2244 // If debugging there might be script break points registered for this | 2266 // If debugging there might be script break points registered for this |
2245 // script. Make sure that these break points are set. | 2267 // script. Make sure that these break points are set. |
2246 | 2268 |
2247 // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). | 2269 // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). |
2248 Handle<String> update_script_break_points_symbol = | 2270 Handle<String> update_script_break_points_symbol = |
2249 FACTORY->LookupAsciiSymbol("UpdateScriptBreakPoints"); | 2271 isolate_->factory()->LookupAsciiSymbol("UpdateScriptBreakPoints"); |
2250 Handle<Object> update_script_break_points = | 2272 Handle<Object> update_script_break_points = |
2251 Handle<Object>(isolate_->debug()->debug_context()->global()-> | 2273 Handle<Object>(debug->debug_context()->global()-> |
2252 GetPropertyNoExceptionThrown(*update_script_break_points_symbol)); | 2274 GetPropertyNoExceptionThrown(*update_script_break_points_symbol)); |
2253 if (!update_script_break_points->IsJSFunction()) { | 2275 if (!update_script_break_points->IsJSFunction()) { |
2254 return; | 2276 return; |
2255 } | 2277 } |
2256 ASSERT(update_script_break_points->IsJSFunction()); | 2278 ASSERT(update_script_break_points->IsJSFunction()); |
2257 | 2279 |
2258 // Wrap the script object in a proper JS object before passing it | 2280 // Wrap the script object in a proper JS object before passing it |
2259 // to JavaScript. | 2281 // to JavaScript. |
2260 Handle<JSValue> wrapper = GetScriptWrapper(script); | 2282 Handle<JSValue> wrapper = GetScriptWrapper(script); |
2261 | 2283 |
(...skipping 22 matching lines...) Expand all Loading... | |
2284 } | 2306 } |
2285 // Process debug event. | 2307 // Process debug event. |
2286 ProcessDebugEvent(v8::AfterCompile, | 2308 ProcessDebugEvent(v8::AfterCompile, |
2287 Handle<JSObject>::cast(event_data), | 2309 Handle<JSObject>::cast(event_data), |
2288 true); | 2310 true); |
2289 } | 2311 } |
2290 | 2312 |
2291 | 2313 |
2292 void Debugger::OnScriptCollected(int id) { | 2314 void Debugger::OnScriptCollected(int id) { |
2293 ASSERT(Isolate::Current() == isolate_); | 2315 ASSERT(Isolate::Current() == isolate_); |
2294 HandleScope scope; | 2316 HandleScope scope(isolate_); |
2295 | 2317 |
2296 // No more to do if not debugging. | 2318 // No more to do if not debugging. |
2297 if (!IsDebuggerActive()) return; | 2319 if (!IsDebuggerActive()) return; |
2298 if (!Debugger::EventActive(v8::ScriptCollected)) return; | 2320 if (!Debugger::EventActive(v8::ScriptCollected)) return; |
2299 | 2321 |
2300 // Enter the debugger. | 2322 // Enter the debugger. |
2301 EnterDebugger debugger; | 2323 EnterDebugger debugger; |
2302 if (debugger.FailedToEnter()) return; | 2324 if (debugger.FailedToEnter()) return; |
2303 | 2325 |
2304 // Create the script collected state object. | 2326 // Create the script collected state object. |
2305 bool caught_exception = false; | 2327 bool caught_exception = false; |
2306 Handle<Object> event_data = MakeScriptCollectedEvent(id, | 2328 Handle<Object> event_data = MakeScriptCollectedEvent(id, |
2307 &caught_exception); | 2329 &caught_exception); |
2308 // Bail out and don't call debugger if exception. | 2330 // Bail out and don't call debugger if exception. |
2309 if (caught_exception) { | 2331 if (caught_exception) { |
2310 return; | 2332 return; |
2311 } | 2333 } |
2312 | 2334 |
2313 // Process debug event. | 2335 // Process debug event. |
2314 ProcessDebugEvent(v8::ScriptCollected, | 2336 ProcessDebugEvent(v8::ScriptCollected, |
2315 Handle<JSObject>::cast(event_data), | 2337 Handle<JSObject>::cast(event_data), |
2316 true); | 2338 true); |
2317 } | 2339 } |
2318 | 2340 |
2319 | 2341 |
2320 void Debugger::ProcessDebugEvent(v8::DebugEvent event, | 2342 void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
2321 Handle<JSObject> event_data, | 2343 Handle<JSObject> event_data, |
2322 bool auto_continue) { | 2344 bool auto_continue) { |
2323 ASSERT(Isolate::Current() == isolate_); | 2345 ASSERT(Isolate::Current() == isolate_); |
2324 HandleScope scope; | 2346 HandleScope scope(isolate_); |
2325 | 2347 |
2326 // Clear any pending debug break if this is a real break. | 2348 // Clear any pending debug break if this is a real break. |
2327 if (!auto_continue) { | 2349 if (!auto_continue) { |
2328 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); | 2350 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); |
2329 } | 2351 } |
2330 | 2352 |
2331 // Create the execution state. | 2353 // Create the execution state. |
2332 bool caught_exception = false; | 2354 bool caught_exception = false; |
2333 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 2355 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
2334 if (caught_exception) { | 2356 if (caught_exception) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2414 Handle<Context> Debugger::GetDebugContext() { | 2436 Handle<Context> Debugger::GetDebugContext() { |
2415 ASSERT(Isolate::Current() == isolate_); | 2437 ASSERT(Isolate::Current() == isolate_); |
2416 never_unload_debugger_ = true; | 2438 never_unload_debugger_ = true; |
2417 EnterDebugger debugger; | 2439 EnterDebugger debugger; |
2418 return isolate_->debug()->debug_context(); | 2440 return isolate_->debug()->debug_context(); |
2419 } | 2441 } |
2420 | 2442 |
2421 | 2443 |
2422 void Debugger::UnloadDebugger() { | 2444 void Debugger::UnloadDebugger() { |
2423 ASSERT(Isolate::Current() == isolate_); | 2445 ASSERT(Isolate::Current() == isolate_); |
2446 Debug* debug = isolate_->debug(); | |
2424 | 2447 |
2425 // Make sure that there are no breakpoints left. | 2448 // Make sure that there are no breakpoints left. |
2426 isolate_->debug()->ClearAllBreakPoints(); | 2449 debug->ClearAllBreakPoints(); |
2427 | 2450 |
2428 // Unload the debugger if feasible. | 2451 // Unload the debugger if feasible. |
2429 if (!never_unload_debugger_) { | 2452 if (!never_unload_debugger_) { |
2430 isolate_->debug()->Unload(); | 2453 debug->Unload(); |
2431 } | 2454 } |
2432 | 2455 |
2433 // Clear the flag indicating that the debugger should be unloaded. | 2456 // Clear the flag indicating that the debugger should be unloaded. |
2434 debugger_unload_pending_ = false; | 2457 debugger_unload_pending_ = false; |
2435 } | 2458 } |
2436 | 2459 |
2437 | 2460 |
2438 void Debugger::NotifyMessageHandler(v8::DebugEvent event, | 2461 void Debugger::NotifyMessageHandler(v8::DebugEvent event, |
2439 Handle<JSObject> exec_state, | 2462 Handle<JSObject> exec_state, |
2440 Handle<JSObject> event_data, | 2463 Handle<JSObject> event_data, |
2441 bool auto_continue) { | 2464 bool auto_continue) { |
2442 ASSERT(Isolate::Current() == isolate_); | 2465 ASSERT(Isolate::Current() == isolate_); |
2443 HandleScope scope; | 2466 HandleScope scope(isolate_); |
2444 | 2467 |
2445 if (!isolate_->debug()->Load()) return; | 2468 if (!isolate_->debug()->Load()) return; |
2446 | 2469 |
2447 // Process the individual events. | 2470 // Process the individual events. |
2448 bool sendEventMessage = false; | 2471 bool sendEventMessage = false; |
2449 switch (event) { | 2472 switch (event) { |
2450 case v8::Break: | 2473 case v8::Break: |
2451 case v8::BreakForCommand: | 2474 case v8::BreakForCommand: |
2452 sendEventMessage = !auto_continue; | 2475 sendEventMessage = !auto_continue; |
2453 break; | 2476 break; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2603 if (running && !HasCommands()) { | 2626 if (running && !HasCommands()) { |
2604 return; | 2627 return; |
2605 } | 2628 } |
2606 } | 2629 } |
2607 } | 2630 } |
2608 | 2631 |
2609 | 2632 |
2610 void Debugger::SetEventListener(Handle<Object> callback, | 2633 void Debugger::SetEventListener(Handle<Object> callback, |
2611 Handle<Object> data) { | 2634 Handle<Object> data) { |
2612 ASSERT(Isolate::Current() == isolate_); | 2635 ASSERT(Isolate::Current() == isolate_); |
2613 HandleScope scope; | 2636 HandleScope scope(isolate_); |
2637 GlobalHandles* global_handles = isolate_->global_handles(); | |
2614 | 2638 |
2615 // Clear the global handles for the event listener and the event listener data | 2639 // Clear the global handles for the event listener and the event listener data |
2616 // object. | 2640 // object. |
2617 if (!event_listener_.is_null()) { | 2641 if (!event_listener_.is_null()) { |
2618 isolate_->global_handles()->Destroy( | 2642 global_handles->Destroy( |
2619 reinterpret_cast<Object**>(event_listener_.location())); | 2643 reinterpret_cast<Object**>(event_listener_.location())); |
2620 event_listener_ = Handle<Object>(); | 2644 event_listener_ = Handle<Object>(); |
2621 } | 2645 } |
2622 if (!event_listener_data_.is_null()) { | 2646 if (!event_listener_data_.is_null()) { |
2623 isolate_->global_handles()->Destroy( | 2647 global_handles->Destroy( |
2624 reinterpret_cast<Object**>(event_listener_data_.location())); | 2648 reinterpret_cast<Object**>(event_listener_data_.location())); |
2625 event_listener_data_ = Handle<Object>(); | 2649 event_listener_data_ = Handle<Object>(); |
2626 } | 2650 } |
2627 | 2651 |
2628 // If there is a new debug event listener register it together with its data | 2652 // If there is a new debug event listener register it together with its data |
2629 // object. | 2653 // object. |
2630 if (!callback->IsUndefined() && !callback->IsNull()) { | 2654 if (!callback->IsUndefined() && !callback->IsNull()) { |
2631 event_listener_ = Handle<Object>::cast( | 2655 event_listener_ = Handle<Object>::cast( |
2632 isolate_->global_handles()->Create(*callback)); | 2656 global_handles->Create(*callback)); |
2633 if (data.is_null()) { | 2657 if (data.is_null()) { |
2634 data = FACTORY->undefined_value(); | 2658 data = isolate_->factory()->undefined_value(); |
2635 } | 2659 } |
2636 event_listener_data_ = Handle<Object>::cast( | 2660 event_listener_data_ = Handle<Object>::cast( |
2637 isolate_->global_handles()->Create(*data)); | 2661 global_handles->Create(*data)); |
2638 } | 2662 } |
2639 | 2663 |
2640 ListenersChanged(); | 2664 ListenersChanged(); |
2641 } | 2665 } |
2642 | 2666 |
2643 | 2667 |
2644 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { | 2668 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { |
2645 ASSERT(Isolate::Current() == isolate_); | 2669 ASSERT(Isolate::Current() == isolate_); |
2646 ScopedLock with(debugger_access_); | 2670 ScopedLock with(debugger_access_); |
2647 | 2671 |
2648 message_handler_ = handler; | 2672 message_handler_ = handler; |
2649 ListenersChanged(); | 2673 ListenersChanged(); |
2650 if (handler == NULL) { | 2674 if (handler == NULL) { |
2651 // Send an empty command to the debugger if in a break to make JavaScript | 2675 // Send an empty command to the debugger if in a break to make JavaScript |
2652 // run again if the debugger is closed. | 2676 // run again if the debugger is closed. |
2653 if (isolate_->debug()->InDebugger()) { | 2677 if (isolate_->debug()->InDebugger()) { |
2654 ProcessCommand(Vector<const uint16_t>::empty()); | 2678 ProcessCommand(Vector<const uint16_t>::empty()); |
2655 } | 2679 } |
2656 } | 2680 } |
2657 } | 2681 } |
2658 | 2682 |
2659 | 2683 |
2660 void Debugger::ListenersChanged() { | 2684 void Debugger::ListenersChanged() { |
2661 Isolate* isolate = Isolate::Current(); | 2685 ASSERT(Isolate::Current() == isolate_); |
2662 if (IsDebuggerActive()) { | 2686 if (IsDebuggerActive()) { |
2663 // Disable the compilation cache when the debugger is active. | 2687 // Disable the compilation cache when the debugger is active. |
2664 isolate->compilation_cache()->Disable(); | 2688 isolate_->compilation_cache()->Disable(); |
2665 debugger_unload_pending_ = false; | 2689 debugger_unload_pending_ = false; |
2666 } else { | 2690 } else { |
2667 isolate->compilation_cache()->Enable(); | 2691 isolate_->compilation_cache()->Enable(); |
2668 // Unload the debugger if event listener and message handler cleared. | 2692 // Unload the debugger if event listener and message handler cleared. |
2669 // Schedule this for later, because we may be in non-V8 thread. | 2693 // Schedule this for later, because we may be in non-V8 thread. |
2670 debugger_unload_pending_ = true; | 2694 debugger_unload_pending_ = true; |
2671 } | 2695 } |
2672 } | 2696 } |
2673 | 2697 |
2674 | 2698 |
2675 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 2699 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
2676 int period) { | 2700 int period) { |
2677 ASSERT(Isolate::Current() == isolate_); | 2701 ASSERT(Isolate::Current() == isolate_); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2769 Handle<Object> Debugger::Call(Handle<JSFunction> fun, | 2793 Handle<Object> Debugger::Call(Handle<JSFunction> fun, |
2770 Handle<Object> data, | 2794 Handle<Object> data, |
2771 bool* pending_exception) { | 2795 bool* pending_exception) { |
2772 ASSERT(Isolate::Current() == isolate_); | 2796 ASSERT(Isolate::Current() == isolate_); |
2773 // When calling functions in the debugger prevent it from beeing unloaded. | 2797 // When calling functions in the debugger prevent it from beeing unloaded. |
2774 Debugger::never_unload_debugger_ = true; | 2798 Debugger::never_unload_debugger_ = true; |
2775 | 2799 |
2776 // Enter the debugger. | 2800 // Enter the debugger. |
2777 EnterDebugger debugger; | 2801 EnterDebugger debugger; |
2778 if (debugger.FailedToEnter()) { | 2802 if (debugger.FailedToEnter()) { |
2779 return FACTORY->undefined_value(); | 2803 return isolate_->factory()->undefined_value(); |
2780 } | 2804 } |
2781 | 2805 |
2782 // Create the execution state. | 2806 // Create the execution state. |
2783 bool caught_exception = false; | 2807 bool caught_exception = false; |
2784 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 2808 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
2785 if (caught_exception) { | 2809 if (caught_exception) { |
2786 return FACTORY->undefined_value(); | 2810 return isolate_->factory()->undefined_value(); |
2787 } | 2811 } |
2788 | 2812 |
2789 static const int kArgc = 2; | 2813 static const int kArgc = 2; |
2790 Object** argv[kArgc] = { exec_state.location(), data.location() }; | 2814 Object** argv[kArgc] = { exec_state.location(), data.location() }; |
2791 Handle<Object> result = Execution::Call( | 2815 Handle<Object> result = Execution::Call( |
2792 fun, | 2816 fun, |
2793 Handle<Object>(isolate_->debug()->debug_context_->global_proxy()), | 2817 Handle<Object>(isolate_->debug()->debug_context_->global_proxy()), |
2794 kArgc, | 2818 kArgc, |
2795 argv, | 2819 argv, |
2796 pending_exception); | 2820 pending_exception); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3155 { | 3179 { |
3156 Locker locker; | 3180 Locker locker; |
3157 Isolate::Current()->debugger()->CallMessageDispatchHandler(); | 3181 Isolate::Current()->debugger()->CallMessageDispatchHandler(); |
3158 } | 3182 } |
3159 } | 3183 } |
3160 } | 3184 } |
3161 | 3185 |
3162 #endif // ENABLE_DEBUGGER_SUPPORT | 3186 #endif // ENABLE_DEBUGGER_SUPPORT |
3163 | 3187 |
3164 } } // namespace v8::internal | 3188 } } // namespace v8::internal |
OLD | NEW |