Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/debug.cc

Issue 6880010: Merge (7265, 7271] from bleeding_edge to experimental/gc branch.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.h ('k') | src/debug-agent.h » ('j') | src/heap.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "natives.h" 44 #include "natives.h"
45 #include "stub-cache.h" 45 #include "stub-cache.h"
46 #include "log.h" 46 #include "log.h"
47 47
48 #include "../include/v8-debug.h" 48 #include "../include/v8-debug.h"
49 49
50 namespace v8 { 50 namespace v8 {
51 namespace internal { 51 namespace internal {
52 52
53 #ifdef ENABLE_DEBUGGER_SUPPORT 53 #ifdef ENABLE_DEBUGGER_SUPPORT
54
55
56 Debug::Debug(Isolate* isolate)
57 : has_break_points_(false),
58 script_cache_(NULL),
59 debug_info_list_(NULL),
60 disable_break_(false),
61 break_on_exception_(false),
62 break_on_uncaught_exception_(false),
63 debug_break_return_(NULL),
64 debug_break_slot_(NULL),
65 isolate_(isolate) {
66 memset(registers_, 0, sizeof(JSCallerSavedBuffer));
67 }
68
69
70 Debug::~Debug() {
71 }
72
73
54 static void PrintLn(v8::Local<v8::Value> value) { 74 static void PrintLn(v8::Local<v8::Value> value) {
55 v8::Local<v8::String> s = value->ToString(); 75 v8::Local<v8::String> s = value->ToString();
56 ScopedVector<char> data(s->Length() + 1); 76 ScopedVector<char> data(s->Length() + 1);
57 if (data.start() == NULL) { 77 if (data.start() == NULL) {
58 V8::FatalProcessOutOfMemory("PrintLn"); 78 V8::FatalProcessOutOfMemory("PrintLn");
59 return; 79 return;
60 } 80 }
61 s->WriteAscii(data.start()); 81 s->WriteAscii(data.start());
62 PrintF("%s\n", data.start()); 82 PrintF("%s\n", data.start());
63 } 83 }
64 84
65 85
66 static Handle<Code> ComputeCallDebugBreak(int argc, Code::Kind kind) { 86 static Handle<Code> ComputeCallDebugBreak(int argc, Code::Kind kind) {
67 CALL_HEAP_FUNCTION(StubCache::ComputeCallDebugBreak(argc, kind), Code); 87 Isolate* isolate = Isolate::Current();
88 CALL_HEAP_FUNCTION(
89 isolate,
90 isolate->stub_cache()->ComputeCallDebugBreak(argc, kind),
91 Code);
68 } 92 }
69 93
70 94
71 static Handle<Code> ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind) { 95 static Handle<Code> ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind) {
96 Isolate* isolate = Isolate::Current();
72 CALL_HEAP_FUNCTION( 97 CALL_HEAP_FUNCTION(
73 StubCache::ComputeCallDebugPrepareStepIn(argc, kind), Code); 98 isolate,
99 isolate->stub_cache()->ComputeCallDebugPrepareStepIn(argc, kind),
100 Code);
74 } 101 }
75 102
76 103
77 static v8::Handle<v8::Context> GetDebugEventContext() { 104 static v8::Handle<v8::Context> GetDebugEventContext(Isolate* isolate) {
78 Handle<Context> context = Debug::debugger_entry()->GetContext(); 105 Handle<Context> context = isolate->debug()->debugger_entry()->GetContext();
79 // Top::context() may have been NULL when "script collected" event occured. 106 // Isolate::context() may have been NULL when "script collected" event
80 if (*context == NULL) { 107 // occured.
81 return v8::Local<v8::Context>(); 108 if (context.is_null()) return v8::Local<v8::Context>();
82 }
83 Handle<Context> global_context(context->global_context()); 109 Handle<Context> global_context(context->global_context());
84 return v8::Utils::ToLocal(global_context); 110 return v8::Utils::ToLocal(global_context);
85 } 111 }
86 112
87 113
88 BreakLocationIterator::BreakLocationIterator(Handle<DebugInfo> debug_info, 114 BreakLocationIterator::BreakLocationIterator(Handle<DebugInfo> debug_info,
89 BreakLocatorType type) { 115 BreakLocatorType type) {
90 debug_info_ = debug_info; 116 debug_info_ = debug_info;
91 type_ = type; 117 type_ = type;
92 reloc_iterator_ = NULL; 118 reloc_iterator_ = NULL;
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 reloc_iterator_original_->next(); 555 reloc_iterator_original_->next();
530 #ifdef DEBUG 556 #ifdef DEBUG
531 ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done()); 557 ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done());
532 if (!reloc_iterator_->done()) { 558 if (!reloc_iterator_->done()) {
533 ASSERT(rmode() == original_rmode()); 559 ASSERT(rmode() == original_rmode());
534 } 560 }
535 #endif 561 #endif
536 } 562 }
537 563
538 564
539 bool Debug::has_break_points_ = false;
540 ScriptCache* Debug::script_cache_ = NULL;
541 DebugInfoListNode* Debug::debug_info_list_ = NULL;
542
543
544 // Threading support. 565 // Threading support.
545 void Debug::ThreadInit() { 566 void Debug::ThreadInit() {
546 thread_local_.break_count_ = 0; 567 thread_local_.break_count_ = 0;
547 thread_local_.break_id_ = 0; 568 thread_local_.break_id_ = 0;
548 thread_local_.break_frame_id_ = StackFrame::NO_ID; 569 thread_local_.break_frame_id_ = StackFrame::NO_ID;
549 thread_local_.last_step_action_ = StepNone; 570 thread_local_.last_step_action_ = StepNone;
550 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; 571 thread_local_.last_statement_position_ = RelocInfo::kNoPosition;
551 thread_local_.step_count_ = 0; 572 thread_local_.step_count_ = 0;
552 thread_local_.last_fp_ = 0; 573 thread_local_.last_fp_ = 0;
553 thread_local_.step_into_fp_ = 0; 574 thread_local_.step_into_fp_ = 0;
554 thread_local_.step_out_fp_ = 0; 575 thread_local_.step_out_fp_ = 0;
555 thread_local_.after_break_target_ = 0; 576 thread_local_.after_break_target_ = 0;
577 // TODO(isolates): frames_are_dropped_?
556 thread_local_.debugger_entry_ = NULL; 578 thread_local_.debugger_entry_ = NULL;
557 thread_local_.pending_interrupts_ = 0; 579 thread_local_.pending_interrupts_ = 0;
558 thread_local_.restarter_frame_function_pointer_ = NULL; 580 thread_local_.restarter_frame_function_pointer_ = NULL;
559 } 581 }
560 582
561 583
562 JSCallerSavedBuffer Debug::registers_;
563 Debug::ThreadLocal Debug::thread_local_;
564
565
566 char* Debug::ArchiveDebug(char* storage) { 584 char* Debug::ArchiveDebug(char* storage) {
567 char* to = storage; 585 char* to = storage;
568 memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); 586 memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal));
569 to += sizeof(ThreadLocal); 587 to += sizeof(ThreadLocal);
570 memcpy(to, reinterpret_cast<char*>(&registers_), sizeof(registers_)); 588 memcpy(to, reinterpret_cast<char*>(&registers_), sizeof(registers_));
571 ThreadInit(); 589 ThreadInit();
572 ASSERT(to <= storage + ArchiveSpacePerThread()); 590 ASSERT(to <= storage + ArchiveSpacePerThread());
573 return storage + ArchiveSpacePerThread(); 591 return storage + ArchiveSpacePerThread();
574 } 592 }
575 593
576 594
577 char* Debug::RestoreDebug(char* storage) { 595 char* Debug::RestoreDebug(char* storage) {
578 char* from = storage; 596 char* from = storage;
579 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); 597 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal));
580 from += sizeof(ThreadLocal); 598 from += sizeof(ThreadLocal);
581 memcpy(reinterpret_cast<char*>(&registers_), from, sizeof(registers_)); 599 memcpy(reinterpret_cast<char*>(&registers_), from, sizeof(registers_));
582 ASSERT(from <= storage + ArchiveSpacePerThread()); 600 ASSERT(from <= storage + ArchiveSpacePerThread());
583 return storage + ArchiveSpacePerThread(); 601 return storage + ArchiveSpacePerThread();
584 } 602 }
585 603
586 604
587 int Debug::ArchiveSpacePerThread() { 605 int Debug::ArchiveSpacePerThread() {
588 return sizeof(ThreadLocal) + sizeof(registers_); 606 return sizeof(ThreadLocal) + sizeof(JSCallerSavedBuffer);
589 } 607 }
590 608
591 609
592 // Frame structure (conforms InternalFrame structure): 610 // Frame structure (conforms InternalFrame structure):
593 // -- code 611 // -- code
594 // -- SMI maker 612 // -- SMI maker
595 // -- function (slot is called "context") 613 // -- function (slot is called "context")
596 // -- frame base 614 // -- frame base
597 Object** Debug::SetUpFrameDropperFrame(StackFrame* bottom_js_frame, 615 Object** Debug::SetUpFrameDropperFrame(StackFrame* bottom_js_frame,
598 Handle<Code> code) { 616 Handle<Code> code) {
599 ASSERT(bottom_js_frame->is_java_script()); 617 ASSERT(bottom_js_frame->is_java_script());
600 618
601 Address fp = bottom_js_frame->fp(); 619 Address fp = bottom_js_frame->fp();
602 620
603 // Move function pointer into "context" slot. 621 // Move function pointer into "context" slot.
604 Memory::Object_at(fp + StandardFrameConstants::kContextOffset) = 622 Memory::Object_at(fp + StandardFrameConstants::kContextOffset) =
605 Memory::Object_at(fp + JavaScriptFrameConstants::kFunctionOffset); 623 Memory::Object_at(fp + JavaScriptFrameConstants::kFunctionOffset);
606 624
607 Memory::Object_at(fp + InternalFrameConstants::kCodeOffset) = *code; 625 Memory::Object_at(fp + InternalFrameConstants::kCodeOffset) = *code;
608 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset) = 626 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset) =
609 Smi::FromInt(StackFrame::INTERNAL); 627 Smi::FromInt(StackFrame::INTERNAL);
610 628
611 return reinterpret_cast<Object**>(&Memory::Object_at( 629 return reinterpret_cast<Object**>(&Memory::Object_at(
612 fp + StandardFrameConstants::kContextOffset)); 630 fp + StandardFrameConstants::kContextOffset));
613 } 631 }
614 632
615 const int Debug::kFrameDropperFrameSize = 4; 633 const int Debug::kFrameDropperFrameSize = 4;
616 634
617 635
618
619
620
621 // Default break enabled.
622 bool Debug::disable_break_ = false;
623
624 // Default call debugger on uncaught exception.
625 bool Debug::break_on_exception_ = false;
626 bool Debug::break_on_uncaught_exception_ = false;
627
628 Handle<Context> Debug::debug_context_ = Handle<Context>();
629 Code* Debug::debug_break_return_ = NULL;
630 Code* Debug::debug_break_slot_ = NULL;
631
632
633 void ScriptCache::Add(Handle<Script> script) { 636 void ScriptCache::Add(Handle<Script> script) {
637 Isolate* isolate = Isolate::Current();
634 // Create an entry in the hash map for the script. 638 // Create an entry in the hash map for the script.
635 int id = Smi::cast(script->id())->value(); 639 int id = Smi::cast(script->id())->value();
636 HashMap::Entry* entry = 640 HashMap::Entry* entry =
637 HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true); 641 HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
638 if (entry->value != NULL) { 642 if (entry->value != NULL) {
639 ASSERT(*script == *reinterpret_cast<Script**>(entry->value)); 643 ASSERT(*script == *reinterpret_cast<Script**>(entry->value));
640 return; 644 return;
641 } 645 }
642 646
643 // Globalize the script object, make it weak and use the location of the 647 // Globalize the script object, make it weak and use the location of the
644 // global handle as the value in the hash map. 648 // global handle as the value in the hash map.
645 Handle<Script> script_ = 649 Handle<Script> script_ =
646 Handle<Script>::cast((GlobalHandles::Create(*script))); 650 Handle<Script>::cast(
647 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()), 651 (isolate->global_handles()->Create(*script)));
648 this, ScriptCache::HandleWeakScript); 652 isolate->global_handles()->MakeWeak(
653 reinterpret_cast<Object**>(script_.location()),
654 this,
655 ScriptCache::HandleWeakScript);
649 entry->value = script_.location(); 656 entry->value = script_.location();
650 } 657 }
651 658
652 659
653 Handle<FixedArray> ScriptCache::GetScripts() { 660 Handle<FixedArray> ScriptCache::GetScripts() {
654 Handle<FixedArray> instances = Factory::NewFixedArray(occupancy()); 661 Handle<FixedArray> instances = FACTORY->NewFixedArray(occupancy());
655 int count = 0; 662 int count = 0;
656 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { 663 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
657 ASSERT(entry->value != NULL); 664 ASSERT(entry->value != NULL);
658 if (entry->value != NULL) { 665 if (entry->value != NULL) {
659 instances->set(count, *reinterpret_cast<Script**>(entry->value)); 666 instances->set(count, *reinterpret_cast<Script**>(entry->value));
660 count++; 667 count++;
661 } 668 }
662 } 669 }
663 return instances; 670 return instances;
664 } 671 }
665 672
666 673
667 void ScriptCache::ProcessCollectedScripts() { 674 void ScriptCache::ProcessCollectedScripts() {
675 Isolate* isolate = Isolate::Current();
668 for (int i = 0; i < collected_scripts_.length(); i++) { 676 for (int i = 0; i < collected_scripts_.length(); i++) {
669 Debugger::OnScriptCollected(collected_scripts_[i]); 677 isolate->debugger()->OnScriptCollected(collected_scripts_[i]);
670 } 678 }
671 collected_scripts_.Clear(); 679 collected_scripts_.Clear();
672 } 680 }
673 681
674 682
675 void ScriptCache::Clear() { 683 void ScriptCache::Clear() {
684 Isolate* isolate = Isolate::Current();
676 // Iterate the script cache to get rid of all the weak handles. 685 // Iterate the script cache to get rid of all the weak handles.
677 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { 686 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
678 ASSERT(entry != NULL); 687 ASSERT(entry != NULL);
679 Object** location = reinterpret_cast<Object**>(entry->value); 688 Object** location = reinterpret_cast<Object**>(entry->value);
680 ASSERT((*location)->IsScript()); 689 ASSERT((*location)->IsScript());
681 GlobalHandles::ClearWeakness(location); 690 isolate->global_handles()->ClearWeakness(location);
682 GlobalHandles::Destroy(location); 691 isolate->global_handles()->Destroy(location);
683 } 692 }
684 // Clear the content of the hash map. 693 // Clear the content of the hash map.
685 HashMap::Clear(); 694 HashMap::Clear();
686 } 695 }
687 696
688 697
689 void ScriptCache::HandleWeakScript(v8::Persistent<v8::Value> obj, void* data) { 698 void ScriptCache::HandleWeakScript(v8::Persistent<v8::Value> obj, void* data) {
690 ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data); 699 ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data);
691 // Find the location of the global handle. 700 // Find the location of the global handle.
692 Script** location = 701 Script** location =
693 reinterpret_cast<Script**>(Utils::OpenHandle(*obj).location()); 702 reinterpret_cast<Script**>(Utils::OpenHandle(*obj).location());
694 ASSERT((*location)->IsScript()); 703 ASSERT((*location)->IsScript());
695 704
696 // Remove the entry from the cache. 705 // Remove the entry from the cache.
697 int id = Smi::cast((*location)->id())->value(); 706 int id = Smi::cast((*location)->id())->value();
698 script_cache->Remove(reinterpret_cast<void*>(id), Hash(id)); 707 script_cache->Remove(reinterpret_cast<void*>(id), Hash(id));
699 script_cache->collected_scripts_.Add(id); 708 script_cache->collected_scripts_.Add(id);
700 709
701 // Clear the weak handle. 710 // Clear the weak handle.
702 obj.Dispose(); 711 obj.Dispose();
703 obj.Clear(); 712 obj.Clear();
704 } 713 }
705 714
706 715
707 void Debug::Setup(bool create_heap_objects) { 716 void Debug::Setup(bool create_heap_objects) {
708 ThreadInit(); 717 ThreadInit();
709 if (create_heap_objects) { 718 if (create_heap_objects) {
710 // Get code to handle debug break on return. 719 // Get code to handle debug break on return.
711 debug_break_return_ = 720 debug_break_return_ =
712 Builtins::builtin(Builtins::Return_DebugBreak); 721 Isolate::Current()->builtins()->builtin(Builtins::Return_DebugBreak);
713 ASSERT(debug_break_return_->IsCode()); 722 ASSERT(debug_break_return_->IsCode());
714 // Get code to handle debug break in debug break slots. 723 // Get code to handle debug break in debug break slots.
715 debug_break_slot_ = 724 debug_break_slot_ =
716 Builtins::builtin(Builtins::Slot_DebugBreak); 725 Isolate::Current()->builtins()->builtin(Builtins::Slot_DebugBreak);
717 ASSERT(debug_break_slot_->IsCode()); 726 ASSERT(debug_break_slot_->IsCode());
718 } 727 }
719 } 728 }
720 729
721 730
722 void Debug::HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data) { 731 void Debug::HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data) {
732 Debug* debug = Isolate::Current()->debug();
723 DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data); 733 DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data);
724 // We need to clear all breakpoints associated with the function to restore 734 // We need to clear all breakpoints associated with the function to restore
725 // original code and avoid patching the code twice later because 735 // original code and avoid patching the code twice later because
726 // the function will live in the heap until next gc, and can be found by 736 // the function will live in the heap until next gc, and can be found by
727 // Runtime::FindSharedFunctionInfoInScript. 737 // Runtime::FindSharedFunctionInfoInScript.
728 BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS); 738 BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS);
729 it.ClearAllDebugBreak(); 739 it.ClearAllDebugBreak();
730 RemoveDebugInfo(node->debug_info()); 740 debug->RemoveDebugInfo(node->debug_info());
731 #ifdef DEBUG 741 #ifdef DEBUG
732 node = Debug::debug_info_list_; 742 node = debug->debug_info_list_;
733 while (node != NULL) { 743 while (node != NULL) {
734 ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data)); 744 ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data));
735 node = node->next(); 745 node = node->next();
736 } 746 }
737 #endif 747 #endif
738 } 748 }
739 749
740 750
741 DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { 751 DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) {
752 Isolate* isolate = Isolate::Current();
742 // Globalize the request debug info object and make it weak. 753 // Globalize the request debug info object and make it weak.
743 debug_info_ = Handle<DebugInfo>::cast((GlobalHandles::Create(debug_info))); 754 debug_info_ = Handle<DebugInfo>::cast(
744 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()), 755 (isolate->global_handles()->Create(debug_info)));
745 this, Debug::HandleWeakDebugInfo); 756 isolate->global_handles()->MakeWeak(
757 reinterpret_cast<Object**>(debug_info_.location()),
758 this,
759 Debug::HandleWeakDebugInfo);
746 } 760 }
747 761
748 762
749 DebugInfoListNode::~DebugInfoListNode() { 763 DebugInfoListNode::~DebugInfoListNode() {
750 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location())); 764 Isolate::Current()->global_handles()->Destroy(
765 reinterpret_cast<Object**>(debug_info_.location()));
751 } 766 }
752 767
753 768
754 bool Debug::CompileDebuggerScript(int index) { 769 bool Debug::CompileDebuggerScript(int index) {
755 HandleScope scope; 770 HandleScope scope;
756 771
757 // Bail out if the index is invalid. 772 // Bail out if the index is invalid.
758 if (index == -1) { 773 if (index == -1) {
759 return false; 774 return false;
760 } 775 }
761 776
762 // Find source and name for the requested script. 777 // Find source and name for the requested script.
763 Handle<String> source_code = Bootstrapper::NativesSourceLookup(index); 778 Handle<String> source_code =
779 Isolate::Current()->bootstrapper()->NativesSourceLookup(index);
764 Vector<const char> name = Natives::GetScriptName(index); 780 Vector<const char> name = Natives::GetScriptName(index);
765 Handle<String> script_name = Factory::NewStringFromAscii(name); 781 Handle<String> script_name = FACTORY->NewStringFromAscii(name);
766 782
767 // Compile the script. 783 // Compile the script.
768 Handle<SharedFunctionInfo> function_info; 784 Handle<SharedFunctionInfo> function_info;
769 function_info = Compiler::Compile(source_code, 785 function_info = Compiler::Compile(source_code,
770 script_name, 786 script_name,
771 0, 0, NULL, NULL, 787 0, 0, NULL, NULL,
772 Handle<String>::null(), 788 Handle<String>::null(),
773 NATIVES_CODE); 789 NATIVES_CODE);
774 790
775 // Silently ignore stack overflows during compilation. 791 // Silently ignore stack overflows during compilation.
776 if (function_info.is_null()) { 792 if (function_info.is_null()) {
777 ASSERT(Top::has_pending_exception()); 793 ASSERT(Isolate::Current()->has_pending_exception());
778 Top::clear_pending_exception(); 794 Isolate::Current()->clear_pending_exception();
779 return false; 795 return false;
780 } 796 }
781 797
782 // Execute the shared function in the debugger context. 798 // Execute the shared function in the debugger context.
783 Handle<Context> context = Top::global_context(); 799 Handle<Context> context = Isolate::Current()->global_context();
784 bool caught_exception = false; 800 bool caught_exception = false;
785 Handle<JSFunction> function = 801 Handle<JSFunction> function =
786 Factory::NewFunctionFromSharedFunctionInfo(function_info, context); 802 FACTORY->NewFunctionFromSharedFunctionInfo(function_info, context);
787 Handle<Object> result = 803 Handle<Object> result =
788 Execution::TryCall(function, Handle<Object>(context->global()), 804 Execution::TryCall(function, Handle<Object>(context->global()),
789 0, NULL, &caught_exception); 805 0, NULL, &caught_exception);
790 806
791 // Check for caught exceptions. 807 // Check for caught exceptions.
792 if (caught_exception) { 808 if (caught_exception) {
793 Handle<Object> message = MessageHandler::MakeMessageObject( 809 Handle<Object> message = MessageHandler::MakeMessageObject(
794 "error_loading_debugger", NULL, Vector<Handle<Object> >::empty(), 810 "error_loading_debugger", NULL, Vector<Handle<Object> >::empty(),
795 Handle<String>(), Handle<JSArray>()); 811 Handle<String>(), Handle<JSArray>());
796 MessageHandler::ReportMessage(NULL, message); 812 MessageHandler::ReportMessage(NULL, message);
797 return false; 813 return false;
798 } 814 }
799 815
800 // Mark this script as native and return successfully. 816 // Mark this script as native and return successfully.
801 Handle<Script> script(Script::cast(function->shared()->script())); 817 Handle<Script> script(Script::cast(function->shared()->script()));
802 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 818 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
803 return true; 819 return true;
804 } 820 }
805 821
806 822
807 bool Debug::Load() { 823 bool Debug::Load() {
808 // Return if debugger is already loaded. 824 // Return if debugger is already loaded.
809 if (IsLoaded()) return true; 825 if (IsLoaded()) return true;
810 826
827 Isolate* isolate = Isolate::Current();
828
811 // Bail out if we're already in the process of compiling the native 829 // Bail out if we're already in the process of compiling the native
812 // JavaScript source code for the debugger. 830 // JavaScript source code for the debugger.
813 if (Debugger::compiling_natives() || Debugger::is_loading_debugger()) 831 if (isolate->debugger()->compiling_natives() ||
832 isolate->debugger()->is_loading_debugger())
814 return false; 833 return false;
815 Debugger::set_loading_debugger(true); 834 isolate->debugger()->set_loading_debugger(true);
816 835
817 // Disable breakpoints and interrupts while compiling and running the 836 // Disable breakpoints and interrupts while compiling and running the
818 // debugger scripts including the context creation code. 837 // debugger scripts including the context creation code.
819 DisableBreak disable(true); 838 DisableBreak disable(true);
820 PostponeInterruptsScope postpone; 839 PostponeInterruptsScope postpone(isolate);
821 840
822 // Create the debugger context. 841 // Create the debugger context.
823 HandleScope scope; 842 HandleScope scope;
824 Handle<Context> context = 843 Handle<Context> context =
825 Bootstrapper::CreateEnvironment(Handle<Object>::null(), 844 isolate->bootstrapper()->CreateEnvironment(
826 v8::Handle<ObjectTemplate>(), 845 Handle<Object>::null(),
827 NULL); 846 v8::Handle<ObjectTemplate>(),
847 NULL);
828 848
829 // Use the debugger context. 849 // Use the debugger context.
830 SaveContext save; 850 SaveContext save(isolate);
831 Top::set_context(*context); 851 isolate->set_context(*context);
832 852
833 // Expose the builtins object in the debugger context. 853 // Expose the builtins object in the debugger context.
834 Handle<String> key = Factory::LookupAsciiSymbol("builtins"); 854 Handle<String> key = FACTORY->LookupAsciiSymbol("builtins");
835 Handle<GlobalObject> global = Handle<GlobalObject>(context->global()); 855 Handle<GlobalObject> global = Handle<GlobalObject>(context->global());
836 RETURN_IF_EMPTY_HANDLE_VALUE( 856 RETURN_IF_EMPTY_HANDLE_VALUE(
857 isolate,
837 SetProperty(global, key, Handle<Object>(global->builtins()), 858 SetProperty(global, key, Handle<Object>(global->builtins()),
838 NONE, kNonStrictMode), 859 NONE, kNonStrictMode),
839 false); 860 false);
840 861
841 // Compile the JavaScript for the debugger in the debugger context. 862 // Compile the JavaScript for the debugger in the debugger context.
842 Debugger::set_compiling_natives(true); 863 isolate->debugger()->set_compiling_natives(true);
843 bool caught_exception = 864 bool caught_exception =
844 !CompileDebuggerScript(Natives::GetIndex("mirror")) || 865 !CompileDebuggerScript(Natives::GetIndex("mirror")) ||
845 !CompileDebuggerScript(Natives::GetIndex("debug")); 866 !CompileDebuggerScript(Natives::GetIndex("debug"));
846 867
847 if (FLAG_enable_liveedit) { 868 if (FLAG_enable_liveedit) {
848 caught_exception = caught_exception || 869 caught_exception = caught_exception ||
849 !CompileDebuggerScript(Natives::GetIndex("liveedit")); 870 !CompileDebuggerScript(Natives::GetIndex("liveedit"));
850 } 871 }
851 872
852 Debugger::set_compiling_natives(false); 873 isolate->debugger()->set_compiling_natives(false);
853 874
854 // Make sure we mark the debugger as not loading before we might 875 // Make sure we mark the debugger as not loading before we might
855 // return. 876 // return.
856 Debugger::set_loading_debugger(false); 877 isolate->debugger()->set_loading_debugger(false);
857 878
858 // Check for caught exceptions. 879 // Check for caught exceptions.
859 if (caught_exception) return false; 880 if (caught_exception) return false;
860 881
861 // Debugger loaded. 882 // Debugger loaded.
862 debug_context_ = context; 883 debug_context_ = context;
863 884
864 return true; 885 return true;
865 } 886 }
866 887
867 888
868 void Debug::Unload() { 889 void Debug::Unload() {
869 // Return debugger is not loaded. 890 // Return debugger is not loaded.
870 if (!IsLoaded()) { 891 if (!IsLoaded()) {
871 return; 892 return;
872 } 893 }
873 894
874 // Clear the script cache. 895 // Clear the script cache.
875 DestroyScriptCache(); 896 DestroyScriptCache();
876 897
877 // Clear debugger context global handle. 898 // Clear debugger context global handle.
878 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location())); 899 Isolate::Current()->global_handles()->Destroy(
900 reinterpret_cast<Object**>(debug_context_.location()));
879 debug_context_ = Handle<Context>(); 901 debug_context_ = Handle<Context>();
880 } 902 }
881 903
882 904
883 // Set the flag indicating that preemption happened during debugging. 905 // Set the flag indicating that preemption happened during debugging.
884 void Debug::PreemptionWhileInDebugger() { 906 void Debug::PreemptionWhileInDebugger() {
885 ASSERT(InDebugger()); 907 ASSERT(InDebugger());
886 Debug::set_interrupts_pending(PREEMPT); 908 Debug::set_interrupts_pending(PREEMPT);
887 } 909 }
888 910
889 911
890 void Debug::Iterate(ObjectVisitor* v) { 912 void Debug::Iterate(ObjectVisitor* v) {
891 v->VisitPointer(BitCast<Object**>(&(debug_break_return_))); 913 v->VisitPointer(BitCast<Object**>(&(debug_break_return_)));
892 v->VisitPointer(BitCast<Object**>(&(debug_break_slot_))); 914 v->VisitPointer(BitCast<Object**>(&(debug_break_slot_)));
893 } 915 }
894 916
895 917
896 Object* Debug::Break(Arguments args) { 918 // This remains a static method so that generated code can call it.
919 Object* Debug::Break(RUNTIME_CALLING_CONVENTION) {
920 RUNTIME_GET_ISOLATE;
921
922 Debug* debug = isolate->debug();
923 Heap* heap = isolate->heap();
897 HandleScope scope; 924 HandleScope scope;
898 ASSERT(args.length() == 0); 925 ASSERT(args.length() == 0);
899 926
900 thread_local_.frame_drop_mode_ = FRAMES_UNTOUCHED; 927 debug->thread_local_.frame_drop_mode_ = FRAMES_UNTOUCHED;
901 928
902 // Get the top-most JavaScript frame. 929 // Get the top-most JavaScript frame.
903 JavaScriptFrameIterator it; 930 JavaScriptFrameIterator it;
904 JavaScriptFrame* frame = it.frame(); 931 JavaScriptFrame* frame = it.frame();
905 932
906 // Just continue if breaks are disabled or debugger cannot be loaded. 933 // Just continue if breaks are disabled or debugger cannot be loaded.
907 if (disable_break() || !Load()) { 934 if (debug->disable_break() || !debug->Load()) {
908 SetAfterBreakTarget(frame); 935 debug->SetAfterBreakTarget(frame);
909 return Heap::undefined_value(); 936 return heap->undefined_value();
910 } 937 }
911 938
912 // Enter the debugger. 939 // Enter the debugger.
913 EnterDebugger debugger; 940 EnterDebugger debugger;
914 if (debugger.FailedToEnter()) { 941 if (debugger.FailedToEnter()) {
915 return Heap::undefined_value(); 942 return heap->undefined_value();
916 } 943 }
917 944
918 // Postpone interrupt during breakpoint processing. 945 // Postpone interrupt during breakpoint processing.
919 PostponeInterruptsScope postpone; 946 PostponeInterruptsScope postpone(isolate);
920 947
921 // Get the debug info (create it if it does not exist). 948 // Get the debug info (create it if it does not exist).
922 Handle<SharedFunctionInfo> shared = 949 Handle<SharedFunctionInfo> shared =
923 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); 950 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
924 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 951 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
925 952
926 // Find the break point where execution has stopped. 953 // Find the break point where execution has stopped.
927 BreakLocationIterator break_location_iterator(debug_info, 954 BreakLocationIterator break_location_iterator(debug_info,
928 ALL_BREAK_LOCATIONS); 955 ALL_BREAK_LOCATIONS);
929 break_location_iterator.FindBreakLocationFromAddress(frame->pc()); 956 break_location_iterator.FindBreakLocationFromAddress(frame->pc());
930 957
931 // Check whether step next reached a new statement. 958 // Check whether step next reached a new statement.
932 if (!StepNextContinue(&break_location_iterator, frame)) { 959 if (!debug->StepNextContinue(&break_location_iterator, frame)) {
933 // Decrease steps left if performing multiple steps. 960 // Decrease steps left if performing multiple steps.
934 if (thread_local_.step_count_ > 0) { 961 if (debug->thread_local_.step_count_ > 0) {
935 thread_local_.step_count_--; 962 debug->thread_local_.step_count_--;
936 } 963 }
937 } 964 }
938 965
939 // If there is one or more real break points check whether any of these are 966 // If there is one or more real break points check whether any of these are
940 // triggered. 967 // triggered.
941 Handle<Object> break_points_hit(Heap::undefined_value()); 968 Handle<Object> break_points_hit(heap->undefined_value());
942 if (break_location_iterator.HasBreakPoint()) { 969 if (break_location_iterator.HasBreakPoint()) {
943 Handle<Object> break_point_objects = 970 Handle<Object> break_point_objects =
944 Handle<Object>(break_location_iterator.BreakPointObjects()); 971 Handle<Object>(break_location_iterator.BreakPointObjects());
945 break_points_hit = CheckBreakPoints(break_point_objects); 972 break_points_hit = debug->CheckBreakPoints(break_point_objects);
946 } 973 }
947 974
948 // If step out is active skip everything until the frame where we need to step 975 // If step out is active skip everything until the frame where we need to step
949 // out to is reached, unless real breakpoint is hit. 976 // out to is reached, unless real breakpoint is hit.
950 if (Debug::StepOutActive() && frame->fp() != Debug::step_out_fp() && 977 if (debug->StepOutActive() && frame->fp() != debug->step_out_fp() &&
951 break_points_hit->IsUndefined() ) { 978 break_points_hit->IsUndefined() ) {
952 // Step count should always be 0 for StepOut. 979 // Step count should always be 0 for StepOut.
953 ASSERT(thread_local_.step_count_ == 0); 980 ASSERT(debug->thread_local_.step_count_ == 0);
954 } else if (!break_points_hit->IsUndefined() || 981 } else if (!break_points_hit->IsUndefined() ||
955 (thread_local_.last_step_action_ != StepNone && 982 (debug->thread_local_.last_step_action_ != StepNone &&
956 thread_local_.step_count_ == 0)) { 983 debug->thread_local_.step_count_ == 0)) {
957 // Notify debugger if a real break point is triggered or if performing 984 // Notify debugger if a real break point is triggered or if performing
958 // single stepping with no more steps to perform. Otherwise do another step. 985 // single stepping with no more steps to perform. Otherwise do another step.
959 986
960 // Clear all current stepping setup. 987 // Clear all current stepping setup.
961 ClearStepping(); 988 debug->ClearStepping();
962 989
963 // Notify the debug event listeners. 990 // Notify the debug event listeners.
964 Debugger::OnDebugBreak(break_points_hit, false); 991 isolate->debugger()->OnDebugBreak(break_points_hit, false);
965 } else if (thread_local_.last_step_action_ != StepNone) { 992 } else if (debug->thread_local_.last_step_action_ != StepNone) {
966 // Hold on to last step action as it is cleared by the call to 993 // Hold on to last step action as it is cleared by the call to
967 // ClearStepping. 994 // ClearStepping.
968 StepAction step_action = thread_local_.last_step_action_; 995 StepAction step_action = debug->thread_local_.last_step_action_;
969 int step_count = thread_local_.step_count_; 996 int step_count = debug->thread_local_.step_count_;
970 997
971 // Clear all current stepping setup. 998 // Clear all current stepping setup.
972 ClearStepping(); 999 debug->ClearStepping();
973 1000
974 // Set up for the remaining steps. 1001 // Set up for the remaining steps.
975 PrepareStep(step_action, step_count); 1002 debug->PrepareStep(step_action, step_count);
976 } 1003 }
977 1004
978 if (thread_local_.frame_drop_mode_ == FRAMES_UNTOUCHED) { 1005 if (debug->thread_local_.frame_drop_mode_ == FRAMES_UNTOUCHED) {
979 SetAfterBreakTarget(frame); 1006 debug->SetAfterBreakTarget(frame);
980 } else if (thread_local_.frame_drop_mode_ == FRAME_DROPPED_IN_IC_CALL) { 1007 } else if (debug->thread_local_.frame_drop_mode_ ==
1008 FRAME_DROPPED_IN_IC_CALL) {
981 // We must have been calling IC stub. Do not go there anymore. 1009 // We must have been calling IC stub. Do not go there anymore.
982 Code* plain_return = Builtins::builtin(Builtins::PlainReturn_LiveEdit); 1010 Code* plain_return =
983 thread_local_.after_break_target_ = plain_return->entry(); 1011 Isolate::Current()->builtins()->builtin(Builtins::PlainReturn_LiveEdit);
984 } else if (thread_local_.frame_drop_mode_ == 1012 debug->thread_local_.after_break_target_ = plain_return->entry();
1013 } else if (debug->thread_local_.frame_drop_mode_ ==
985 FRAME_DROPPED_IN_DEBUG_SLOT_CALL) { 1014 FRAME_DROPPED_IN_DEBUG_SLOT_CALL) {
986 // Debug break slot stub does not return normally, instead it manually 1015 // Debug break slot stub does not return normally, instead it manually
987 // cleans the stack and jumps. We should patch the jump address. 1016 // cleans the stack and jumps. We should patch the jump address.
988 Code* plain_return = Builtins::builtin(Builtins::FrameDropper_LiveEdit); 1017 Code* plain_return = Isolate::Current()->builtins()->builtin(
989 thread_local_.after_break_target_ = plain_return->entry(); 1018 Builtins::FrameDropper_LiveEdit);
990 } else if (thread_local_.frame_drop_mode_ == FRAME_DROPPED_IN_DIRECT_CALL) { 1019 debug->thread_local_.after_break_target_ = plain_return->entry();
1020 } else if (debug->thread_local_.frame_drop_mode_ ==
1021 FRAME_DROPPED_IN_DIRECT_CALL) {
991 // Nothing to do, after_break_target is not used here. 1022 // Nothing to do, after_break_target is not used here.
992 } else { 1023 } else {
993 UNREACHABLE(); 1024 UNREACHABLE();
994 } 1025 }
995 1026
996 return Heap::undefined_value(); 1027 return heap->undefined_value();
997 } 1028 }
998 1029
999 1030
1000 // Check the break point objects for whether one or more are actually 1031 // Check the break point objects for whether one or more are actually
1001 // triggered. This function returns a JSArray with the break point objects 1032 // triggered. This function returns a JSArray with the break point objects
1002 // which is triggered. 1033 // which is triggered.
1003 Handle<Object> Debug::CheckBreakPoints(Handle<Object> break_point_objects) { 1034 Handle<Object> Debug::CheckBreakPoints(Handle<Object> break_point_objects) {
1004 // Count the number of break points hit. If there are multiple break points 1035 // Count the number of break points hit. If there are multiple break points
1005 // they are in a FixedArray. 1036 // they are in a FixedArray.
1006 Handle<FixedArray> break_points_hit; 1037 Handle<FixedArray> break_points_hit;
1007 int break_points_hit_count = 0; 1038 int break_points_hit_count = 0;
1008 ASSERT(!break_point_objects->IsUndefined()); 1039 ASSERT(!break_point_objects->IsUndefined());
1009 if (break_point_objects->IsFixedArray()) { 1040 if (break_point_objects->IsFixedArray()) {
1010 Handle<FixedArray> array(FixedArray::cast(*break_point_objects)); 1041 Handle<FixedArray> array(FixedArray::cast(*break_point_objects));
1011 break_points_hit = Factory::NewFixedArray(array->length()); 1042 break_points_hit = FACTORY->NewFixedArray(array->length());
1012 for (int i = 0; i < array->length(); i++) { 1043 for (int i = 0; i < array->length(); i++) {
1013 Handle<Object> o(array->get(i)); 1044 Handle<Object> o(array->get(i));
1014 if (CheckBreakPoint(o)) { 1045 if (CheckBreakPoint(o)) {
1015 break_points_hit->set(break_points_hit_count++, *o); 1046 break_points_hit->set(break_points_hit_count++, *o);
1016 } 1047 }
1017 } 1048 }
1018 } else { 1049 } else {
1019 break_points_hit = Factory::NewFixedArray(1); 1050 break_points_hit = FACTORY->NewFixedArray(1);
1020 if (CheckBreakPoint(break_point_objects)) { 1051 if (CheckBreakPoint(break_point_objects)) {
1021 break_points_hit->set(break_points_hit_count++, *break_point_objects); 1052 break_points_hit->set(break_points_hit_count++, *break_point_objects);
1022 } 1053 }
1023 } 1054 }
1024 1055
1025 // Return undefined if no break points were triggered. 1056 // Return undefined if no break points were triggered.
1026 if (break_points_hit_count == 0) { 1057 if (break_points_hit_count == 0) {
1027 return Factory::undefined_value(); 1058 return FACTORY->undefined_value();
1028 } 1059 }
1029 // Return break points hit as a JSArray. 1060 // Return break points hit as a JSArray.
1030 Handle<JSArray> result = Factory::NewJSArrayWithElements(break_points_hit); 1061 Handle<JSArray> result = FACTORY->NewJSArrayWithElements(break_points_hit);
1031 result->set_length(Smi::FromInt(break_points_hit_count)); 1062 result->set_length(Smi::FromInt(break_points_hit_count));
1032 return result; 1063 return result;
1033 } 1064 }
1034 1065
1035 1066
1036 // Check whether a single break point object is triggered. 1067 // Check whether a single break point object is triggered.
1037 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { 1068 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) {
1038 HandleScope scope; 1069 HandleScope scope;
1039 1070
1040 // Ignore check if break point object is not a JSObject. 1071 // Ignore check if break point object is not a JSObject.
1041 if (!break_point_object->IsJSObject()) return true; 1072 if (!break_point_object->IsJSObject()) return true;
1042 1073
1043 // Get the function IsBreakPointTriggered (defined in debug-debugger.js). 1074 // Get the function IsBreakPointTriggered (defined in debug-debugger.js).
1044 Handle<String> is_break_point_triggered_symbol = 1075 Handle<String> is_break_point_triggered_symbol =
1045 Factory::LookupAsciiSymbol("IsBreakPointTriggered"); 1076 FACTORY->LookupAsciiSymbol("IsBreakPointTriggered");
1046 Handle<JSFunction> check_break_point = 1077 Handle<JSFunction> check_break_point =
1047 Handle<JSFunction>(JSFunction::cast( 1078 Handle<JSFunction>(JSFunction::cast(
1048 debug_context()->global()->GetPropertyNoExceptionThrown( 1079 debug_context()->global()->GetPropertyNoExceptionThrown(
1049 *is_break_point_triggered_symbol))); 1080 *is_break_point_triggered_symbol)));
1050 1081
1051 // Get the break id as an object. 1082 // Get the break id as an object.
1052 Handle<Object> break_id = Factory::NewNumberFromInt(Debug::break_id()); 1083 Handle<Object> break_id = FACTORY->NewNumberFromInt(Debug::break_id());
1053 1084
1054 // Call HandleBreakPointx. 1085 // Call HandleBreakPointx.
1055 bool caught_exception = false; 1086 bool caught_exception = false;
1056 const int argc = 2; 1087 const int argc = 2;
1057 Object** argv[argc] = { 1088 Object** argv[argc] = {
1058 break_id.location(), 1089 break_id.location(),
1059 reinterpret_cast<Object**>(break_point_object.location()) 1090 reinterpret_cast<Object**>(break_point_object.location())
1060 }; 1091 };
1061 Handle<Object> result = Execution::TryCall(check_break_point, 1092 Handle<Object> result = Execution::TryCall(check_break_point,
1062 Top::builtins(), argc, argv, 1093 Isolate::Current()->js_builtins_object(), argc, argv, &caught_exception);
1063 &caught_exception);
1064 1094
1065 // If exception or non boolean result handle as not triggered 1095 // If exception or non boolean result handle as not triggered
1066 if (caught_exception || !result->IsBoolean()) { 1096 if (caught_exception || !result->IsBoolean()) {
1067 return false; 1097 return false;
1068 } 1098 }
1069 1099
1070 // Return whether the break point is triggered. 1100 // Return whether the break point is triggered.
1071 return *result == Heap::true_value(); 1101 ASSERT(!result.is_null());
1102 return (*result)->IsTrue();
1072 } 1103 }
1073 1104
1074 1105
1075 // Check whether the function has debug information. 1106 // Check whether the function has debug information.
1076 bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) { 1107 bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) {
1077 return !shared->debug_info()->IsUndefined(); 1108 return !shared->debug_info()->IsUndefined();
1078 } 1109 }
1079 1110
1080 1111
1081 // Return the debug info for this function. EnsureDebugInfo must be called 1112 // Return the debug info for this function. EnsureDebugInfo must be called
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 restarted_function->shared()); 1391 restarted_function->shared());
1361 FloodWithOneShot(restarted_shared); 1392 FloodWithOneShot(restarted_shared);
1362 } else if (!call_function_stub.is_null()) { 1393 } else if (!call_function_stub.is_null()) {
1363 // If it's CallFunction stub ensure target function is compiled and flood 1394 // If it's CallFunction stub ensure target function is compiled and flood
1364 // it with one shot breakpoints. 1395 // it with one shot breakpoints.
1365 1396
1366 // Find out number of arguments from the stub minor key. 1397 // Find out number of arguments from the stub minor key.
1367 // Reverse lookup required as the minor key cannot be retrieved 1398 // Reverse lookup required as the minor key cannot be retrieved
1368 // from the code object. 1399 // from the code object.
1369 Handle<Object> obj( 1400 Handle<Object> obj(
1370 Heap::code_stubs()->SlowReverseLookup(*call_function_stub)); 1401 HEAP->code_stubs()->SlowReverseLookup(*call_function_stub));
1371 ASSERT(*obj != Heap::undefined_value()); 1402 ASSERT(!obj.is_null());
1403 ASSERT(!(*obj)->IsUndefined());
1372 ASSERT(obj->IsSmi()); 1404 ASSERT(obj->IsSmi());
1373 // Get the STUB key and extract major and minor key. 1405 // Get the STUB key and extract major and minor key.
1374 uint32_t key = Smi::cast(*obj)->value(); 1406 uint32_t key = Smi::cast(*obj)->value();
1375 // Argc in the stub is the number of arguments passed - not the 1407 // Argc in the stub is the number of arguments passed - not the
1376 // expected arguments of the called function. 1408 // expected arguments of the called function.
1377 int call_function_arg_count = 1409 int call_function_arg_count =
1378 CallFunctionStub::ExtractArgcFromMinorKey( 1410 CallFunctionStub::ExtractArgcFromMinorKey(
1379 CodeStub::MinorKeyFromKey(key)); 1411 CodeStub::MinorKeyFromKey(key));
1380 ASSERT(call_function_stub->major_key() == 1412 ASSERT(call_function_stub->major_key() ==
1381 CodeStub::MajorKeyFromKey(key)); 1413 CodeStub::MajorKeyFromKey(key));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 Handle<Code> Debug::FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode) { 1511 Handle<Code> Debug::FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode) {
1480 // Find the builtin debug break function matching the calling convention 1512 // Find the builtin debug break function matching the calling convention
1481 // used by the call site. 1513 // used by the call site.
1482 if (code->is_inline_cache_stub()) { 1514 if (code->is_inline_cache_stub()) {
1483 switch (code->kind()) { 1515 switch (code->kind()) {
1484 case Code::CALL_IC: 1516 case Code::CALL_IC:
1485 case Code::KEYED_CALL_IC: 1517 case Code::KEYED_CALL_IC:
1486 return ComputeCallDebugBreak(code->arguments_count(), code->kind()); 1518 return ComputeCallDebugBreak(code->arguments_count(), code->kind());
1487 1519
1488 case Code::LOAD_IC: 1520 case Code::LOAD_IC:
1489 return Handle<Code>(Builtins::builtin(Builtins::LoadIC_DebugBreak)); 1521 return Handle<Code>(Isolate::Current()->builtins()->builtin(
1522 Builtins::LoadIC_DebugBreak));
1490 1523
1491 case Code::STORE_IC: 1524 case Code::STORE_IC:
1492 return Handle<Code>(Builtins::builtin(Builtins::StoreIC_DebugBreak)); 1525 return Handle<Code>(Isolate::Current()->builtins()->builtin(
1526 Builtins::StoreIC_DebugBreak));
1493 1527
1494 case Code::KEYED_LOAD_IC: 1528 case Code::KEYED_LOAD_IC:
1495 return Handle<Code>( 1529 return Handle<Code>(
1496 Builtins::builtin(Builtins::KeyedLoadIC_DebugBreak)); 1530 Isolate::Current()->builtins()->builtin(
1531 Builtins::KeyedLoadIC_DebugBreak));
1497 1532
1498 case Code::KEYED_STORE_IC: 1533 case Code::KEYED_STORE_IC:
1499 return Handle<Code>( 1534 return Handle<Code>(
1500 Builtins::builtin(Builtins::KeyedStoreIC_DebugBreak)); 1535 Isolate::Current()->builtins()->builtin(
1536 Builtins::KeyedStoreIC_DebugBreak));
1501 1537
1502 default: 1538 default:
1503 UNREACHABLE(); 1539 UNREACHABLE();
1504 } 1540 }
1505 } 1541 }
1506 if (RelocInfo::IsConstructCall(mode)) { 1542 if (RelocInfo::IsConstructCall(mode)) {
1507 Handle<Code> result = 1543 Handle<Code> result =
1508 Handle<Code>(Builtins::builtin(Builtins::ConstructCall_DebugBreak)); 1544 Handle<Code>(Isolate::Current()->builtins()->builtin(
1545 Builtins::ConstructCall_DebugBreak));
1509 return result; 1546 return result;
1510 } 1547 }
1511 if (code->kind() == Code::STUB) { 1548 if (code->kind() == Code::STUB) {
1512 ASSERT(code->major_key() == CodeStub::CallFunction); 1549 ASSERT(code->major_key() == CodeStub::CallFunction);
1513 Handle<Code> result = 1550 Handle<Code> result =
1514 Handle<Code>(Builtins::builtin(Builtins::StubNoRegisters_DebugBreak)); 1551 Handle<Code>(Isolate::Current()->builtins()->builtin(
1552 Builtins::StubNoRegisters_DebugBreak));
1515 return result; 1553 return result;
1516 } 1554 }
1517 1555
1518 UNREACHABLE(); 1556 UNREACHABLE();
1519 return Handle<Code>::null(); 1557 return Handle<Code>::null();
1520 } 1558 }
1521 1559
1522 1560
1523 // Simple function for returning the source positions for active break points. 1561 // Simple function for returning the source positions for active break points.
1524 Handle<Object> Debug::GetSourceBreakLocations( 1562 Handle<Object> Debug::GetSourceBreakLocations(
1525 Handle<SharedFunctionInfo> shared) { 1563 Handle<SharedFunctionInfo> shared) {
1526 if (!HasDebugInfo(shared)) return Handle<Object>(Heap::undefined_value()); 1564 if (!HasDebugInfo(shared)) return Handle<Object>(HEAP->undefined_value());
1527 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 1565 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
1528 if (debug_info->GetBreakPointCount() == 0) { 1566 if (debug_info->GetBreakPointCount() == 0) {
1529 return Handle<Object>(Heap::undefined_value()); 1567 return Handle<Object>(HEAP->undefined_value());
1530 } 1568 }
1531 Handle<FixedArray> locations = 1569 Handle<FixedArray> locations =
1532 Factory::NewFixedArray(debug_info->GetBreakPointCount()); 1570 FACTORY->NewFixedArray(debug_info->GetBreakPointCount());
1533 int count = 0; 1571 int count = 0;
1534 for (int i = 0; i < debug_info->break_points()->length(); i++) { 1572 for (int i = 0; i < debug_info->break_points()->length(); i++) {
1535 if (!debug_info->break_points()->get(i)->IsUndefined()) { 1573 if (!debug_info->break_points()->get(i)->IsUndefined()) {
1536 BreakPointInfo* break_point_info = 1574 BreakPointInfo* break_point_info =
1537 BreakPointInfo::cast(debug_info->break_points()->get(i)); 1575 BreakPointInfo::cast(debug_info->break_points()->get(i));
1538 if (break_point_info->GetBreakPointCount() > 0) { 1576 if (break_point_info->GetBreakPointCount() > 0) {
1539 locations->set(count++, break_point_info->statement_position()); 1577 locations->set(count++, break_point_info->statement_position());
1540 } 1578 }
1541 } 1579 }
1542 } 1580 }
(...skipping 25 matching lines...) Expand all
1568 // For constructor functions skip another frame. 1606 // For constructor functions skip another frame.
1569 if (is_constructor) { 1607 if (is_constructor) {
1570 ASSERT(it.frame()->is_construct()); 1608 ASSERT(it.frame()->is_construct());
1571 it.Advance(); 1609 it.Advance();
1572 } 1610 }
1573 fp = it.frame()->fp(); 1611 fp = it.frame()->fp();
1574 } 1612 }
1575 1613
1576 // Flood the function with one-shot break points if it is called from where 1614 // Flood the function with one-shot break points if it is called from where
1577 // step into was requested. 1615 // step into was requested.
1578 if (fp == Debug::step_in_fp()) { 1616 if (fp == step_in_fp()) {
1579 // Don't allow step into functions in the native context. 1617 // Don't allow step into functions in the native context.
1580 if (!function->IsBuiltin()) { 1618 if (!function->IsBuiltin()) {
1581 if (function->shared()->code() == 1619 if (function->shared()->code() ==
1582 Builtins::builtin(Builtins::FunctionApply) || 1620 Isolate::Current()->builtins()->builtin(Builtins::FunctionApply) ||
1583 function->shared()->code() == 1621 function->shared()->code() ==
1584 Builtins::builtin(Builtins::FunctionCall)) { 1622 Isolate::Current()->builtins()->builtin(Builtins::FunctionCall)) {
1585 // Handle function.apply and function.call separately to flood the 1623 // Handle function.apply and function.call separately to flood the
1586 // function to be called and not the code for Builtins::FunctionApply or 1624 // function to be called and not the code for Builtins::FunctionApply or
1587 // Builtins::FunctionCall. The receiver of call/apply is the target 1625 // Builtins::FunctionCall. The receiver of call/apply is the target
1588 // function. 1626 // function.
1589 if (!holder.is_null() && holder->IsJSFunction() && 1627 if (!holder.is_null() && holder->IsJSFunction() &&
1590 !JSFunction::cast(*holder)->IsBuiltin()) { 1628 !JSFunction::cast(*holder)->IsBuiltin()) {
1591 Handle<SharedFunctionInfo> shared_info( 1629 Handle<SharedFunctionInfo> shared_info(
1592 JSFunction::cast(*holder)->shared()); 1630 JSFunction::cast(*holder)->shared());
1593 Debug::FloodWithOneShot(shared_info); 1631 Debug::FloodWithOneShot(shared_info);
1594 } 1632 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 // Ensure shared in compiled. Return false if this failed. 1706 // Ensure shared in compiled. Return false if this failed.
1669 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false; 1707 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false;
1670 1708
1671 // If preparing for the first break point make sure to deoptimize all 1709 // If preparing for the first break point make sure to deoptimize all
1672 // functions as debugging does not work with optimized code. 1710 // functions as debugging does not work with optimized code.
1673 if (!has_break_points_) { 1711 if (!has_break_points_) {
1674 Deoptimizer::DeoptimizeAll(); 1712 Deoptimizer::DeoptimizeAll();
1675 } 1713 }
1676 1714
1677 // Create the debug info object. 1715 // Create the debug info object.
1678 Handle<DebugInfo> debug_info = Factory::NewDebugInfo(shared); 1716 Handle<DebugInfo> debug_info = FACTORY->NewDebugInfo(shared);
1679 1717
1680 // Add debug info to the list. 1718 // Add debug info to the list.
1681 DebugInfoListNode* node = new DebugInfoListNode(*debug_info); 1719 DebugInfoListNode* node = new DebugInfoListNode(*debug_info);
1682 node->set_next(debug_info_list_); 1720 node->set_next(debug_info_list_);
1683 debug_info_list_ = node; 1721 debug_info_list_ = node;
1684 1722
1685 // Now there is at least one break point. 1723 // Now there is at least one break point.
1686 has_break_points_ = true; 1724 has_break_points_ = true;
1687 1725
1688 return true; 1726 return true;
1689 } 1727 }
1690 1728
1691 1729
1692 void Debug::RemoveDebugInfo(Handle<DebugInfo> debug_info) { 1730 void Debug::RemoveDebugInfo(Handle<DebugInfo> debug_info) {
1693 ASSERT(debug_info_list_ != NULL); 1731 ASSERT(debug_info_list_ != NULL);
1694 // Run through the debug info objects to find this one and remove it. 1732 // Run through the debug info objects to find this one and remove it.
1695 DebugInfoListNode* prev = NULL; 1733 DebugInfoListNode* prev = NULL;
1696 DebugInfoListNode* current = debug_info_list_; 1734 DebugInfoListNode* current = debug_info_list_;
1697 while (current != NULL) { 1735 while (current != NULL) {
1698 if (*current->debug_info() == *debug_info) { 1736 if (*current->debug_info() == *debug_info) {
1699 // Unlink from list. If prev is NULL we are looking at the first element. 1737 // Unlink from list. If prev is NULL we are looking at the first element.
1700 if (prev == NULL) { 1738 if (prev == NULL) {
1701 debug_info_list_ = current->next(); 1739 debug_info_list_ = current->next();
1702 } else { 1740 } else {
1703 prev->set_next(current->next()); 1741 prev->set_next(current->next());
1704 } 1742 }
1705 current->debug_info()->shared()->set_debug_info(Heap::undefined_value()); 1743 current->debug_info()->shared()->set_debug_info(HEAP->undefined_value());
1706 delete current; 1744 delete current;
1707 1745
1708 // If there are no more debug info objects there are not more break 1746 // If there are no more debug info objects there are not more break
1709 // points. 1747 // points.
1710 has_break_points_ = debug_info_list_ != NULL; 1748 has_break_points_ = debug_info_list_ != NULL;
1711 1749
1712 return; 1750 return;
1713 } 1751 }
1714 // Move to next in list. 1752 // Move to next in list.
1715 prev = current; 1753 prev = current;
(...skipping 11 matching lines...) Expand all
1727 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); 1765 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
1728 if (!EnsureDebugInfo(shared)) { 1766 if (!EnsureDebugInfo(shared)) {
1729 // Return if we failed to retrieve the debug info. 1767 // Return if we failed to retrieve the debug info.
1730 return; 1768 return;
1731 } 1769 }
1732 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 1770 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
1733 Handle<Code> code(debug_info->code()); 1771 Handle<Code> code(debug_info->code());
1734 Handle<Code> original_code(debug_info->original_code()); 1772 Handle<Code> original_code(debug_info->original_code());
1735 #ifdef DEBUG 1773 #ifdef DEBUG
1736 // Get the code which is actually executing. 1774 // Get the code which is actually executing.
1737 Handle<Code> frame_code(frame->code()); 1775 Handle<Code> frame_code(frame->LookupCode(Isolate::Current()));
1738 ASSERT(frame_code.is_identical_to(code)); 1776 ASSERT(frame_code.is_identical_to(code));
1739 #endif 1777 #endif
1740 1778
1741 // Find the call address in the running code. This address holds the call to 1779 // Find the call address in the running code. This address holds the call to
1742 // either a DebugBreakXXX or to the debug break return entry code if the 1780 // either a DebugBreakXXX or to the debug break return entry code if the
1743 // break point is still active after processing the break point. 1781 // break point is still active after processing the break point.
1744 Address addr = frame->pc() - Assembler::kCallTargetAddressOffset; 1782 Address addr = frame->pc() - Assembler::kCallTargetAddressOffset;
1745 1783
1746 // Check if the location is at JS exit or debug break slot. 1784 // Check if the location is at JS exit or debug break slot.
1747 bool at_js_return = false; 1785 bool at_js_return = false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 Handle<SharedFunctionInfo> shared = 1847 Handle<SharedFunctionInfo> shared =
1810 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); 1848 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
1811 if (!EnsureDebugInfo(shared)) { 1849 if (!EnsureDebugInfo(shared)) {
1812 // Return if we failed to retrieve the debug info. 1850 // Return if we failed to retrieve the debug info.
1813 return false; 1851 return false;
1814 } 1852 }
1815 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 1853 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
1816 Handle<Code> code(debug_info->code()); 1854 Handle<Code> code(debug_info->code());
1817 #ifdef DEBUG 1855 #ifdef DEBUG
1818 // Get the code which is actually executing. 1856 // Get the code which is actually executing.
1819 Handle<Code> frame_code(frame->code()); 1857 Handle<Code> frame_code(frame->LookupCode(Isolate::Current()));
1820 ASSERT(frame_code.is_identical_to(code)); 1858 ASSERT(frame_code.is_identical_to(code));
1821 #endif 1859 #endif
1822 1860
1823 // Find the call address in the running code. 1861 // Find the call address in the running code.
1824 Address addr = frame->pc() - Assembler::kCallTargetAddressOffset; 1862 Address addr = frame->pc() - Assembler::kCallTargetAddressOffset;
1825 1863
1826 // Check if the location is at JS return. 1864 // Check if the location is at JS return.
1827 RelocIterator it(debug_info->code()); 1865 RelocIterator it(debug_info->code());
1828 while (!it.done()) { 1866 while (!it.done()) {
1829 if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) { 1867 if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) {
(...skipping 10 matching lines...) Expand all
1840 FrameDropMode mode, 1878 FrameDropMode mode,
1841 Object** restarter_frame_function_pointer) { 1879 Object** restarter_frame_function_pointer) {
1842 thread_local_.frame_drop_mode_ = mode; 1880 thread_local_.frame_drop_mode_ = mode;
1843 thread_local_.break_frame_id_ = new_break_frame_id; 1881 thread_local_.break_frame_id_ = new_break_frame_id;
1844 thread_local_.restarter_frame_function_pointer_ = 1882 thread_local_.restarter_frame_function_pointer_ =
1845 restarter_frame_function_pointer; 1883 restarter_frame_function_pointer;
1846 } 1884 }
1847 1885
1848 1886
1849 bool Debug::IsDebugGlobal(GlobalObject* global) { 1887 bool Debug::IsDebugGlobal(GlobalObject* global) {
1850 return IsLoaded() && global == Debug::debug_context()->global(); 1888 return IsLoaded() && global == debug_context()->global();
1851 } 1889 }
1852 1890
1853 1891
1854 void Debug::ClearMirrorCache() { 1892 void Debug::ClearMirrorCache() {
1855 PostponeInterruptsScope postpone; 1893 PostponeInterruptsScope postpone(isolate_);
1856 HandleScope scope; 1894 HandleScope scope;
1857 ASSERT(Top::context() == *Debug::debug_context()); 1895 ASSERT(Isolate::Current()->context() == *Debug::debug_context());
1858 1896
1859 // Clear the mirror cache. 1897 // Clear the mirror cache.
1860 Handle<String> function_name = 1898 Handle<String> function_name =
1861 Factory::LookupSymbol(CStrVector("ClearMirrorCache")); 1899 FACTORY->LookupSymbol(CStrVector("ClearMirrorCache"));
1862 Handle<Object> fun(Top::global()->GetPropertyNoExceptionThrown( 1900 Handle<Object> fun(Isolate::Current()->global()->GetPropertyNoExceptionThrown(
1863 *function_name)); 1901 *function_name));
1864 ASSERT(fun->IsJSFunction()); 1902 ASSERT(fun->IsJSFunction());
1865 bool caught_exception; 1903 bool caught_exception;
1866 Handle<Object> js_object = Execution::TryCall( 1904 Handle<Object> js_object = Execution::TryCall(
1867 Handle<JSFunction>::cast(fun), 1905 Handle<JSFunction>::cast(fun),
1868 Handle<JSObject>(Debug::debug_context()->global()), 1906 Handle<JSObject>(Debug::debug_context()->global()),
1869 0, NULL, &caught_exception); 1907 0, NULL, &caught_exception);
1870 } 1908 }
1871 1909
1872 1910
1873 void Debug::CreateScriptCache() { 1911 void Debug::CreateScriptCache() {
1874 HandleScope scope; 1912 HandleScope scope;
1875 1913
1876 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets 1914 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets
1877 // rid of all the cached script wrappers and the second gets rid of the 1915 // rid of all the cached script wrappers and the second gets rid of the
1878 // scripts which are no longer referenced. The second also sweeps precisely, 1916 // scripts which are no longer referenced. The second also sweeps precisely,
1879 // which saves us doing yet another GC to make the heap iterable. 1917 // which saves us doing yet another GC to make the heap iterable.
1880 Heap::CollectAllGarbage(Heap::kNoGCFlags); 1918 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1881 Heap::CollectAllGarbage(Heap::kMakeHeapIterableMask); 1919 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask);
1882 1920
1883 ASSERT(script_cache_ == NULL); 1921 ASSERT(script_cache_ == NULL);
1884 script_cache_ = new ScriptCache(); 1922 script_cache_ = new ScriptCache();
1885 1923
1886 // Scan heap for Script objects. 1924 // Scan heap for Script objects.
1887 int count = 0; 1925 int count = 0;
1888 HeapIterator iterator; 1926 HeapIterator iterator;
1889 AssertNoAllocation no_allocation; 1927 AssertNoAllocation no_allocation;
1890 1928
1891 for (HeapObject* obj = iterator.Next(); obj != NULL; obj = iterator.Next()) { 1929 for (HeapObject* obj = iterator.Next(); obj != NULL; obj = iterator.Next()) {
(...skipping 24 matching lines...) Expand all
1916 Handle<FixedArray> Debug::GetLoadedScripts() { 1954 Handle<FixedArray> Debug::GetLoadedScripts() {
1917 // Create and fill the script cache when the loaded scripts is requested for 1955 // Create and fill the script cache when the loaded scripts is requested for
1918 // the first time. 1956 // the first time.
1919 if (script_cache_ == NULL) { 1957 if (script_cache_ == NULL) {
1920 CreateScriptCache(); 1958 CreateScriptCache();
1921 } 1959 }
1922 1960
1923 // If the script cache is not active just return an empty array. 1961 // If the script cache is not active just return an empty array.
1924 ASSERT(script_cache_ != NULL); 1962 ASSERT(script_cache_ != NULL);
1925 if (script_cache_ == NULL) { 1963 if (script_cache_ == NULL) {
1926 Factory::NewFixedArray(0); 1964 FACTORY->NewFixedArray(0);
1927 } 1965 }
1928 1966
1929 // Perform GC to get unreferenced scripts evicted from the cache before 1967 // Perform GC to get unreferenced scripts evicted from the cache before
1930 // returning the content. 1968 // returning the content.
1931 Heap::CollectAllGarbage(Heap::kNoGCFlags); 1969 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1932 1970
1933 // Get the scripts from the cache. 1971 // Get the scripts from the cache.
1934 return script_cache_->GetScripts(); 1972 return script_cache_->GetScripts();
1935 } 1973 }
1936 1974
1937 1975
1938 void Debug::AfterGarbageCollection() { 1976 void Debug::AfterGarbageCollection() {
1939 // Generate events for collected scripts. 1977 // Generate events for collected scripts.
1940 if (script_cache_ != NULL) { 1978 if (script_cache_ != NULL) {
1941 script_cache_->ProcessCollectedScripts(); 1979 script_cache_->ProcessCollectedScripts();
1942 } 1980 }
1943 } 1981 }
1944 1982
1945 1983
1946 Mutex* Debugger::debugger_access_ = OS::CreateMutex(); 1984 Debugger::Debugger()
1947 Handle<Object> Debugger::event_listener_ = Handle<Object>(); 1985 : debugger_access_(OS::CreateMutex()),
1948 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); 1986 event_listener_(Handle<Object>()),
1949 bool Debugger::compiling_natives_ = false; 1987 event_listener_data_(Handle<Object>()),
1950 bool Debugger::is_loading_debugger_ = false; 1988 compiling_natives_(false),
1951 bool Debugger::never_unload_debugger_ = false; 1989 is_loading_debugger_(false),
1952 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL; 1990 never_unload_debugger_(false),
1953 bool Debugger::debugger_unload_pending_ = false; 1991 message_handler_(NULL),
1954 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL; 1992 debugger_unload_pending_(false),
1955 Mutex* Debugger::dispatch_handler_access_ = OS::CreateMutex(); 1993 host_dispatch_handler_(NULL),
1956 v8::Debug::DebugMessageDispatchHandler 1994 dispatch_handler_access_(OS::CreateMutex()),
1957 Debugger::debug_message_dispatch_handler_ = NULL; 1995 debug_message_dispatch_handler_(NULL),
1958 MessageDispatchHelperThread* Debugger::message_dispatch_helper_thread_ = NULL; 1996 message_dispatch_helper_thread_(NULL),
1959 int Debugger::host_dispatch_micros_ = 100 * 1000; 1997 host_dispatch_micros_(100 * 1000),
1960 DebuggerAgent* Debugger::agent_ = NULL; 1998 agent_(NULL),
1961 LockingCommandMessageQueue Debugger::command_queue_(kQueueInitialSize); 1999 command_queue_(kQueueInitialSize),
1962 Semaphore* Debugger::command_received_ = OS::CreateSemaphore(0); 2000 command_received_(OS::CreateSemaphore(0)),
1963 LockingCommandMessageQueue Debugger::event_command_queue_(kQueueInitialSize); 2001 event_command_queue_(kQueueInitialSize) {
2002 }
2003
2004
2005 Debugger::~Debugger() {
2006 delete debugger_access_;
2007 debugger_access_ = 0;
2008 delete dispatch_handler_access_;
2009 dispatch_handler_access_ = 0;
2010 delete command_received_;
2011 command_received_ = 0;
2012 }
1964 2013
1965 2014
1966 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, 2015 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name,
1967 int argc, Object*** argv, 2016 int argc, Object*** argv,
1968 bool* caught_exception) { 2017 bool* caught_exception) {
1969 ASSERT(Top::context() == *Debug::debug_context()); 2018 ASSERT(Isolate::Current() == isolate_);
2019 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
1970 2020
1971 // Create the execution state object. 2021 // Create the execution state object.
1972 Handle<String> constructor_str = Factory::LookupSymbol(constructor_name); 2022 Handle<String> constructor_str = FACTORY->LookupSymbol(constructor_name);
1973 Handle<Object> constructor(Top::global()->GetPropertyNoExceptionThrown( 2023 Handle<Object> constructor(
1974 *constructor_str)); 2024 isolate_->global()->GetPropertyNoExceptionThrown(*constructor_str));
1975 ASSERT(constructor->IsJSFunction()); 2025 ASSERT(constructor->IsJSFunction());
1976 if (!constructor->IsJSFunction()) { 2026 if (!constructor->IsJSFunction()) {
1977 *caught_exception = true; 2027 *caught_exception = true;
1978 return Factory::undefined_value(); 2028 return FACTORY->undefined_value();
1979 } 2029 }
1980 Handle<Object> js_object = Execution::TryCall( 2030 Handle<Object> js_object = Execution::TryCall(
1981 Handle<JSFunction>::cast(constructor), 2031 Handle<JSFunction>::cast(constructor),
1982 Handle<JSObject>(Debug::debug_context()->global()), argc, argv, 2032 Handle<JSObject>(isolate_->debug()->debug_context()->global()),
1983 caught_exception); 2033 argc, argv, caught_exception);
1984 return js_object; 2034 return js_object;
1985 } 2035 }
1986 2036
1987 2037
1988 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { 2038 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) {
2039 ASSERT(Isolate::Current() == isolate_);
1989 // Create the execution state object. 2040 // Create the execution state object.
1990 Handle<Object> break_id = Factory::NewNumberFromInt(Debug::break_id()); 2041 Handle<Object> break_id = FACTORY->NewNumberFromInt(
2042 isolate_->debug()->break_id());
1991 const int argc = 1; 2043 const int argc = 1;
1992 Object** argv[argc] = { break_id.location() }; 2044 Object** argv[argc] = { break_id.location() };
1993 return MakeJSObject(CStrVector("MakeExecutionState"), 2045 return MakeJSObject(CStrVector("MakeExecutionState"),
1994 argc, argv, caught_exception); 2046 argc, argv, caught_exception);
1995 } 2047 }
1996 2048
1997 2049
1998 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, 2050 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state,
1999 Handle<Object> break_points_hit, 2051 Handle<Object> break_points_hit,
2000 bool* caught_exception) { 2052 bool* caught_exception) {
2053 ASSERT(Isolate::Current() == isolate_);
2001 // Create the new break event object. 2054 // Create the new break event object.
2002 const int argc = 2; 2055 const int argc = 2;
2003 Object** argv[argc] = { exec_state.location(), 2056 Object** argv[argc] = { exec_state.location(),
2004 break_points_hit.location() }; 2057 break_points_hit.location() };
2005 return MakeJSObject(CStrVector("MakeBreakEvent"), 2058 return MakeJSObject(CStrVector("MakeBreakEvent"),
2006 argc, 2059 argc,
2007 argv, 2060 argv,
2008 caught_exception); 2061 caught_exception);
2009 } 2062 }
2010 2063
2011 2064
2012 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, 2065 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state,
2013 Handle<Object> exception, 2066 Handle<Object> exception,
2014 bool uncaught, 2067 bool uncaught,
2015 bool* caught_exception) { 2068 bool* caught_exception) {
2069 ASSERT(Isolate::Current() == isolate_);
2016 // Create the new exception event object. 2070 // Create the new exception event object.
2017 const int argc = 3; 2071 const int argc = 3;
2018 Object** argv[argc] = { exec_state.location(), 2072 Object** argv[argc] = { exec_state.location(),
2019 exception.location(), 2073 exception.location(),
2020 uncaught ? Factory::true_value().location() : 2074 uncaught ? FACTORY->true_value().location() :
2021 Factory::false_value().location()}; 2075 FACTORY->false_value().location()};
2022 return MakeJSObject(CStrVector("MakeExceptionEvent"), 2076 return MakeJSObject(CStrVector("MakeExceptionEvent"),
2023 argc, argv, caught_exception); 2077 argc, argv, caught_exception);
2024 } 2078 }
2025 2079
2026 2080
2027 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, 2081 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function,
2028 bool* caught_exception) { 2082 bool* caught_exception) {
2083 ASSERT(Isolate::Current() == isolate_);
2029 // Create the new function event object. 2084 // Create the new function event object.
2030 const int argc = 1; 2085 const int argc = 1;
2031 Object** argv[argc] = { function.location() }; 2086 Object** argv[argc] = { function.location() };
2032 return MakeJSObject(CStrVector("MakeNewFunctionEvent"), 2087 return MakeJSObject(CStrVector("MakeNewFunctionEvent"),
2033 argc, argv, caught_exception); 2088 argc, argv, caught_exception);
2034 } 2089 }
2035 2090
2036 2091
2037 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, 2092 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script,
2038 bool before, 2093 bool before,
2039 bool* caught_exception) { 2094 bool* caught_exception) {
2095 ASSERT(Isolate::Current() == isolate_);
2040 // Create the compile event object. 2096 // Create the compile event object.
2041 Handle<Object> exec_state = MakeExecutionState(caught_exception); 2097 Handle<Object> exec_state = MakeExecutionState(caught_exception);
2042 Handle<Object> script_wrapper = GetScriptWrapper(script); 2098 Handle<Object> script_wrapper = GetScriptWrapper(script);
2043 const int argc = 3; 2099 const int argc = 3;
2044 Object** argv[argc] = { exec_state.location(), 2100 Object** argv[argc] = { exec_state.location(),
2045 script_wrapper.location(), 2101 script_wrapper.location(),
2046 before ? Factory::true_value().location() : 2102 before ? FACTORY->true_value().location() :
2047 Factory::false_value().location() }; 2103 FACTORY->false_value().location() };
2048 2104
2049 return MakeJSObject(CStrVector("MakeCompileEvent"), 2105 return MakeJSObject(CStrVector("MakeCompileEvent"),
2050 argc, 2106 argc,
2051 argv, 2107 argv,
2052 caught_exception); 2108 caught_exception);
2053 } 2109 }
2054 2110
2055 2111
2056 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, 2112 Handle<Object> Debugger::MakeScriptCollectedEvent(int id,
2057 bool* caught_exception) { 2113 bool* caught_exception) {
2114 ASSERT(Isolate::Current() == isolate_);
2058 // Create the script collected event object. 2115 // Create the script collected event object.
2059 Handle<Object> exec_state = MakeExecutionState(caught_exception); 2116 Handle<Object> exec_state = MakeExecutionState(caught_exception);
2060 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id)); 2117 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id));
2061 const int argc = 2; 2118 const int argc = 2;
2062 Object** argv[argc] = { exec_state.location(), id_object.location() }; 2119 Object** argv[argc] = { exec_state.location(), id_object.location() };
2063 2120
2064 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), 2121 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"),
2065 argc, 2122 argc,
2066 argv, 2123 argv,
2067 caught_exception); 2124 caught_exception);
2068 } 2125 }
2069 2126
2070 2127
2071 void Debugger::OnException(Handle<Object> exception, bool uncaught) { 2128 void Debugger::OnException(Handle<Object> exception, bool uncaught) {
2129 ASSERT(Isolate::Current() == isolate_);
2072 HandleScope scope; 2130 HandleScope scope;
2073 2131
2074 // Bail out based on state or if there is no listener for this event 2132 // Bail out based on state or if there is no listener for this event
2075 if (Debug::InDebugger()) return; 2133 if (isolate_->debug()->InDebugger()) return;
2076 if (!Debugger::EventActive(v8::Exception)) return; 2134 if (!Debugger::EventActive(v8::Exception)) return;
2077 2135
2078 // Bail out if exception breaks are not active 2136 // Bail out if exception breaks are not active
2079 if (uncaught) { 2137 if (uncaught) {
2080 // Uncaught exceptions are reported by either flags. 2138 // Uncaught exceptions are reported by either flags.
2081 if (!(Debug::break_on_uncaught_exception() || 2139 if (!(isolate_->debug()->break_on_uncaught_exception() ||
2082 Debug::break_on_exception())) return; 2140 isolate_->debug()->break_on_exception())) return;
2083 } else { 2141 } else {
2084 // Caught exceptions are reported is activated. 2142 // Caught exceptions are reported is activated.
2085 if (!Debug::break_on_exception()) return; 2143 if (!isolate_->debug()->break_on_exception()) return;
2086 } 2144 }
2087 2145
2088 // Enter the debugger. 2146 // Enter the debugger.
2089 EnterDebugger debugger; 2147 EnterDebugger debugger;
2090 if (debugger.FailedToEnter()) return; 2148 if (debugger.FailedToEnter()) return;
2091 2149
2092 // Clear all current stepping setup. 2150 // Clear all current stepping setup.
2093 Debug::ClearStepping(); 2151 isolate_->debug()->ClearStepping();
2094 // Create the event data object. 2152 // Create the event data object.
2095 bool caught_exception = false; 2153 bool caught_exception = false;
2096 Handle<Object> exec_state = MakeExecutionState(&caught_exception); 2154 Handle<Object> exec_state = MakeExecutionState(&caught_exception);
2097 Handle<Object> event_data; 2155 Handle<Object> event_data;
2098 if (!caught_exception) { 2156 if (!caught_exception) {
2099 event_data = MakeExceptionEvent(exec_state, exception, uncaught, 2157 event_data = MakeExceptionEvent(exec_state, exception, uncaught,
2100 &caught_exception); 2158 &caught_exception);
2101 } 2159 }
2102 // Bail out and don't call debugger if exception. 2160 // Bail out and don't call debugger if exception.
2103 if (caught_exception) { 2161 if (caught_exception) {
2104 return; 2162 return;
2105 } 2163 }
2106 2164
2107 // Process debug event. 2165 // Process debug event.
2108 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); 2166 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false);
2109 // Return to continue execution from where the exception was thrown. 2167 // Return to continue execution from where the exception was thrown.
2110 } 2168 }
2111 2169
2112 2170
2113 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, 2171 void Debugger::OnDebugBreak(Handle<Object> break_points_hit,
2114 bool auto_continue) { 2172 bool auto_continue) {
2173 ASSERT(Isolate::Current() == isolate_);
2115 HandleScope scope; 2174 HandleScope scope;
2116 2175
2117 // Debugger has already been entered by caller. 2176 // Debugger has already been entered by caller.
2118 ASSERT(Top::context() == *Debug::debug_context()); 2177 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
2119 2178
2120 // Bail out if there is no listener for this event 2179 // Bail out if there is no listener for this event
2121 if (!Debugger::EventActive(v8::Break)) return; 2180 if (!Debugger::EventActive(v8::Break)) return;
2122 2181
2123 // Debugger must be entered in advance. 2182 // Debugger must be entered in advance.
2124 ASSERT(Top::context() == *Debug::debug_context()); 2183 ASSERT(Isolate::Current()->context() == *isolate_->debug()->debug_context());
2125 2184
2126 // Create the event data object. 2185 // Create the event data object.
2127 bool caught_exception = false; 2186 bool caught_exception = false;
2128 Handle<Object> exec_state = MakeExecutionState(&caught_exception); 2187 Handle<Object> exec_state = MakeExecutionState(&caught_exception);
2129 Handle<Object> event_data; 2188 Handle<Object> event_data;
2130 if (!caught_exception) { 2189 if (!caught_exception) {
2131 event_data = MakeBreakEvent(exec_state, break_points_hit, 2190 event_data = MakeBreakEvent(exec_state, break_points_hit,
2132 &caught_exception); 2191 &caught_exception);
2133 } 2192 }
2134 // Bail out and don't call debugger if exception. 2193 // Bail out and don't call debugger if exception.
2135 if (caught_exception) { 2194 if (caught_exception) {
2136 return; 2195 return;
2137 } 2196 }
2138 2197
2139 // Process debug event. 2198 // Process debug event.
2140 ProcessDebugEvent(v8::Break, 2199 ProcessDebugEvent(v8::Break,
2141 Handle<JSObject>::cast(event_data), 2200 Handle<JSObject>::cast(event_data),
2142 auto_continue); 2201 auto_continue);
2143 } 2202 }
2144 2203
2145 2204
2146 void Debugger::OnBeforeCompile(Handle<Script> script) { 2205 void Debugger::OnBeforeCompile(Handle<Script> script) {
2206 ASSERT(Isolate::Current() == isolate_);
2147 HandleScope scope; 2207 HandleScope scope;
2148 2208
2149 // Bail out based on state or if there is no listener for this event 2209 // Bail out based on state or if there is no listener for this event
2150 if (Debug::InDebugger()) return; 2210 if (isolate_->debug()->InDebugger()) return;
2151 if (compiling_natives()) return; 2211 if (compiling_natives()) return;
2152 if (!EventActive(v8::BeforeCompile)) return; 2212 if (!EventActive(v8::BeforeCompile)) return;
2153 2213
2154 // Enter the debugger. 2214 // Enter the debugger.
2155 EnterDebugger debugger; 2215 EnterDebugger debugger;
2156 if (debugger.FailedToEnter()) return; 2216 if (debugger.FailedToEnter()) return;
2157 2217
2158 // Create the event data object. 2218 // Create the event data object.
2159 bool caught_exception = false; 2219 bool caught_exception = false;
2160 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); 2220 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception);
2161 // Bail out and don't call debugger if exception. 2221 // Bail out and don't call debugger if exception.
2162 if (caught_exception) { 2222 if (caught_exception) {
2163 return; 2223 return;
2164 } 2224 }
2165 2225
2166 // Process debug event. 2226 // Process debug event.
2167 ProcessDebugEvent(v8::BeforeCompile, 2227 ProcessDebugEvent(v8::BeforeCompile,
2168 Handle<JSObject>::cast(event_data), 2228 Handle<JSObject>::cast(event_data),
2169 true); 2229 true);
2170 } 2230 }
2171 2231
2172 2232
2173 // Handle debugger actions when a new script is compiled. 2233 // Handle debugger actions when a new script is compiled.
2174 void Debugger::OnAfterCompile(Handle<Script> script, 2234 void Debugger::OnAfterCompile(Handle<Script> script,
2175 AfterCompileFlags after_compile_flags) { 2235 AfterCompileFlags after_compile_flags) {
2236 ASSERT(Isolate::Current() == isolate_);
2176 HandleScope scope; 2237 HandleScope scope;
2177 2238
2178 // Add the newly compiled script to the script cache. 2239 // Add the newly compiled script to the script cache.
2179 Debug::AddScriptToScriptCache(script); 2240 isolate_->debug()->AddScriptToScriptCache(script);
2180 2241
2181 // No more to do if not debugging. 2242 // No more to do if not debugging.
2182 if (!IsDebuggerActive()) return; 2243 if (!IsDebuggerActive()) return;
2183 2244
2184 // No compile events while compiling natives. 2245 // No compile events while compiling natives.
2185 if (compiling_natives()) return; 2246 if (compiling_natives()) return;
2186 2247
2187 // Store whether in debugger before entering debugger. 2248 // Store whether in debugger before entering debugger.
2188 bool in_debugger = Debug::InDebugger(); 2249 bool in_debugger = isolate_->debug()->InDebugger();
2189 2250
2190 // Enter the debugger. 2251 // Enter the debugger.
2191 EnterDebugger debugger; 2252 EnterDebugger debugger;
2192 if (debugger.FailedToEnter()) return; 2253 if (debugger.FailedToEnter()) return;
2193 2254
2194 // If debugging there might be script break points registered for this 2255 // If debugging there might be script break points registered for this
2195 // script. Make sure that these break points are set. 2256 // script. Make sure that these break points are set.
2196 2257
2197 // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). 2258 // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js).
2198 Handle<String> update_script_break_points_symbol = 2259 Handle<String> update_script_break_points_symbol =
2199 Factory::LookupAsciiSymbol("UpdateScriptBreakPoints"); 2260 FACTORY->LookupAsciiSymbol("UpdateScriptBreakPoints");
2200 Handle<Object> update_script_break_points = 2261 Handle<Object> update_script_break_points =
2201 Handle<Object>(Debug::debug_context()->global()-> 2262 Handle<Object>(isolate_->debug()->debug_context()->global()->
2202 GetPropertyNoExceptionThrown(*update_script_break_points_symbol)); 2263 GetPropertyNoExceptionThrown(*update_script_break_points_symbol));
2203 if (!update_script_break_points->IsJSFunction()) { 2264 if (!update_script_break_points->IsJSFunction()) {
2204 return; 2265 return;
2205 } 2266 }
2206 ASSERT(update_script_break_points->IsJSFunction()); 2267 ASSERT(update_script_break_points->IsJSFunction());
2207 2268
2208 // Wrap the script object in a proper JS object before passing it 2269 // Wrap the script object in a proper JS object before passing it
2209 // to JavaScript. 2270 // to JavaScript.
2210 Handle<JSValue> wrapper = GetScriptWrapper(script); 2271 Handle<JSValue> wrapper = GetScriptWrapper(script);
2211 2272
2212 // Call UpdateScriptBreakPoints expect no exceptions. 2273 // Call UpdateScriptBreakPoints expect no exceptions.
2213 bool caught_exception = false; 2274 bool caught_exception = false;
2214 const int argc = 1; 2275 const int argc = 1;
2215 Object** argv[argc] = { reinterpret_cast<Object**>(wrapper.location()) }; 2276 Object** argv[argc] = { reinterpret_cast<Object**>(wrapper.location()) };
2216 Handle<Object> result = Execution::TryCall( 2277 Handle<Object> result = Execution::TryCall(
2217 Handle<JSFunction>::cast(update_script_break_points), 2278 Handle<JSFunction>::cast(update_script_break_points),
2218 Top::builtins(), argc, argv, 2279 Isolate::Current()->js_builtins_object(), argc, argv,
2219 &caught_exception); 2280 &caught_exception);
2220 if (caught_exception) { 2281 if (caught_exception) {
2221 return; 2282 return;
2222 } 2283 }
2223 // Bail out based on state or if there is no listener for this event 2284 // Bail out based on state or if there is no listener for this event
2224 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return; 2285 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return;
2225 if (!Debugger::EventActive(v8::AfterCompile)) return; 2286 if (!Debugger::EventActive(v8::AfterCompile)) return;
2226 2287
2227 // Create the compile state object. 2288 // Create the compile state object.
2228 Handle<Object> event_data = MakeCompileEvent(script, 2289 Handle<Object> event_data = MakeCompileEvent(script,
2229 false, 2290 false,
2230 &caught_exception); 2291 &caught_exception);
2231 // Bail out and don't call debugger if exception. 2292 // Bail out and don't call debugger if exception.
2232 if (caught_exception) { 2293 if (caught_exception) {
2233 return; 2294 return;
2234 } 2295 }
2235 // Process debug event. 2296 // Process debug event.
2236 ProcessDebugEvent(v8::AfterCompile, 2297 ProcessDebugEvent(v8::AfterCompile,
2237 Handle<JSObject>::cast(event_data), 2298 Handle<JSObject>::cast(event_data),
2238 true); 2299 true);
2239 } 2300 }
2240 2301
2241 2302
2242 void Debugger::OnScriptCollected(int id) { 2303 void Debugger::OnScriptCollected(int id) {
2304 ASSERT(Isolate::Current() == isolate_);
2243 HandleScope scope; 2305 HandleScope scope;
2244 2306
2245 // No more to do if not debugging. 2307 // No more to do if not debugging.
2246 if (!IsDebuggerActive()) return; 2308 if (!IsDebuggerActive()) return;
2247 if (!Debugger::EventActive(v8::ScriptCollected)) return; 2309 if (!Debugger::EventActive(v8::ScriptCollected)) return;
2248 2310
2249 // Enter the debugger. 2311 // Enter the debugger.
2250 EnterDebugger debugger; 2312 EnterDebugger debugger;
2251 if (debugger.FailedToEnter()) return; 2313 if (debugger.FailedToEnter()) return;
2252 2314
2253 // Create the script collected state object. 2315 // Create the script collected state object.
2254 bool caught_exception = false; 2316 bool caught_exception = false;
2255 Handle<Object> event_data = MakeScriptCollectedEvent(id, 2317 Handle<Object> event_data = MakeScriptCollectedEvent(id,
2256 &caught_exception); 2318 &caught_exception);
2257 // Bail out and don't call debugger if exception. 2319 // Bail out and don't call debugger if exception.
2258 if (caught_exception) { 2320 if (caught_exception) {
2259 return; 2321 return;
2260 } 2322 }
2261 2323
2262 // Process debug event. 2324 // Process debug event.
2263 ProcessDebugEvent(v8::ScriptCollected, 2325 ProcessDebugEvent(v8::ScriptCollected,
2264 Handle<JSObject>::cast(event_data), 2326 Handle<JSObject>::cast(event_data),
2265 true); 2327 true);
2266 } 2328 }
2267 2329
2268 2330
2269 void Debugger::ProcessDebugEvent(v8::DebugEvent event, 2331 void Debugger::ProcessDebugEvent(v8::DebugEvent event,
2270 Handle<JSObject> event_data, 2332 Handle<JSObject> event_data,
2271 bool auto_continue) { 2333 bool auto_continue) {
2334 ASSERT(Isolate::Current() == isolate_);
2272 HandleScope scope; 2335 HandleScope scope;
2273 2336
2274 // Clear any pending debug break if this is a real break. 2337 // Clear any pending debug break if this is a real break.
2275 if (!auto_continue) { 2338 if (!auto_continue) {
2276 Debug::clear_interrupt_pending(DEBUGBREAK); 2339 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK);
2277 } 2340 }
2278 2341
2279 // Create the execution state. 2342 // Create the execution state.
2280 bool caught_exception = false; 2343 bool caught_exception = false;
2281 Handle<Object> exec_state = MakeExecutionState(&caught_exception); 2344 Handle<Object> exec_state = MakeExecutionState(&caught_exception);
2282 if (caught_exception) { 2345 if (caught_exception) {
2283 return; 2346 return;
2284 } 2347 }
2285 // First notify the message handler if any. 2348 // First notify the message handler if any.
2286 if (message_handler_ != NULL) { 2349 if (message_handler_ != NULL) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2337 event_listener_data_, 2400 event_listener_data_,
2338 client_data); 2401 client_data);
2339 callback(event_details); 2402 callback(event_details);
2340 } 2403 }
2341 2404
2342 2405
2343 void Debugger::CallJSEventCallback(v8::DebugEvent event, 2406 void Debugger::CallJSEventCallback(v8::DebugEvent event,
2344 Handle<Object> exec_state, 2407 Handle<Object> exec_state,
2345 Handle<Object> event_data) { 2408 Handle<Object> event_data) {
2346 ASSERT(event_listener_->IsJSFunction()); 2409 ASSERT(event_listener_->IsJSFunction());
2410 ASSERT(Isolate::Current() == isolate_);
2347 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); 2411 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_));
2348 2412
2349 // Invoke the JavaScript debug event listener. 2413 // Invoke the JavaScript debug event listener.
2350 const int argc = 4; 2414 const int argc = 4;
2351 Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(), 2415 Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(),
2352 exec_state.location(), 2416 exec_state.location(),
2353 Handle<Object>::cast(event_data).location(), 2417 Handle<Object>::cast(event_data).location(),
2354 event_listener_data_.location() }; 2418 event_listener_data_.location() };
2355 bool caught_exception = false; 2419 bool caught_exception = false;
2356 Execution::TryCall(fun, Top::global(), argc, argv, &caught_exception); 2420 Execution::TryCall(fun, isolate_->global(), argc, argv, &caught_exception);
2357 // Silently ignore exceptions from debug event listeners. 2421 // Silently ignore exceptions from debug event listeners.
2358 } 2422 }
2359 2423
2360 2424
2361 Handle<Context> Debugger::GetDebugContext() { 2425 Handle<Context> Debugger::GetDebugContext() {
2362 never_unload_debugger_ = true; 2426 ASSERT(Isolate::Current() == isolate_);
2363 EnterDebugger debugger; 2427 never_unload_debugger_ = true;
2364 return Debug::debug_context(); 2428 EnterDebugger debugger;
2429 return isolate_->debug()->debug_context();
2365 } 2430 }
2366 2431
2367 2432
2368 void Debugger::UnloadDebugger() { 2433 void Debugger::UnloadDebugger() {
2434 ASSERT(Isolate::Current() == isolate_);
2435
2369 // Make sure that there are no breakpoints left. 2436 // Make sure that there are no breakpoints left.
2370 Debug::ClearAllBreakPoints(); 2437 isolate_->debug()->ClearAllBreakPoints();
2371 2438
2372 // Unload the debugger if feasible. 2439 // Unload the debugger if feasible.
2373 if (!never_unload_debugger_) { 2440 if (!never_unload_debugger_) {
2374 Debug::Unload(); 2441 isolate_->debug()->Unload();
2375 } 2442 }
2376 2443
2377 // Clear the flag indicating that the debugger should be unloaded. 2444 // Clear the flag indicating that the debugger should be unloaded.
2378 debugger_unload_pending_ = false; 2445 debugger_unload_pending_ = false;
2379 } 2446 }
2380 2447
2381 2448
2382 void Debugger::NotifyMessageHandler(v8::DebugEvent event, 2449 void Debugger::NotifyMessageHandler(v8::DebugEvent event,
2383 Handle<JSObject> exec_state, 2450 Handle<JSObject> exec_state,
2384 Handle<JSObject> event_data, 2451 Handle<JSObject> event_data,
2385 bool auto_continue) { 2452 bool auto_continue) {
2453 ASSERT(Isolate::Current() == isolate_);
2386 HandleScope scope; 2454 HandleScope scope;
2387 2455
2388 if (!Debug::Load()) return; 2456 if (!isolate_->debug()->Load()) return;
2389 2457
2390 // Process the individual events. 2458 // Process the individual events.
2391 bool sendEventMessage = false; 2459 bool sendEventMessage = false;
2392 switch (event) { 2460 switch (event) {
2393 case v8::Break: 2461 case v8::Break:
2394 case v8::BreakForCommand: 2462 case v8::BreakForCommand:
2395 sendEventMessage = !auto_continue; 2463 sendEventMessage = !auto_continue;
2396 break; 2464 break;
2397 case v8::Exception: 2465 case v8::Exception:
2398 sendEventMessage = true; 2466 sendEventMessage = true;
2399 break; 2467 break;
2400 case v8::BeforeCompile: 2468 case v8::BeforeCompile:
2401 break; 2469 break;
2402 case v8::AfterCompile: 2470 case v8::AfterCompile:
2403 sendEventMessage = true; 2471 sendEventMessage = true;
2404 break; 2472 break;
2405 case v8::ScriptCollected: 2473 case v8::ScriptCollected:
2406 sendEventMessage = true; 2474 sendEventMessage = true;
2407 break; 2475 break;
2408 case v8::NewFunction: 2476 case v8::NewFunction:
2409 break; 2477 break;
2410 default: 2478 default:
2411 UNREACHABLE(); 2479 UNREACHABLE();
2412 } 2480 }
2413 2481
2414 // The debug command interrupt flag might have been set when the command was 2482 // The debug command interrupt flag might have been set when the command was
2415 // added. It should be enough to clear the flag only once while we are in the 2483 // added. It should be enough to clear the flag only once while we are in the
2416 // debugger. 2484 // debugger.
2417 ASSERT(Debug::InDebugger()); 2485 ASSERT(isolate_->debug()->InDebugger());
2418 StackGuard::Continue(DEBUGCOMMAND); 2486 isolate_->stack_guard()->Continue(DEBUGCOMMAND);
2419 2487
2420 // Notify the debugger that a debug event has occurred unless auto continue is 2488 // Notify the debugger that a debug event has occurred unless auto continue is
2421 // active in which case no event is send. 2489 // active in which case no event is send.
2422 if (sendEventMessage) { 2490 if (sendEventMessage) {
2423 MessageImpl message = MessageImpl::NewEvent( 2491 MessageImpl message = MessageImpl::NewEvent(
2424 event, 2492 event,
2425 auto_continue, 2493 auto_continue,
2426 Handle<JSObject>::cast(exec_state), 2494 Handle<JSObject>::cast(exec_state),
2427 Handle<JSObject>::cast(event_data)); 2495 Handle<JSObject>::cast(event_data));
2428 InvokeMessageHandler(message); 2496 InvokeMessageHandler(message);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 Debugger::host_dispatch_handler_(); 2539 Debugger::host_dispatch_handler_();
2472 continue; 2540 continue;
2473 } 2541 }
2474 } else { 2542 } else {
2475 // In case there is no host dispatch - just wait. 2543 // In case there is no host dispatch - just wait.
2476 command_received_->Wait(); 2544 command_received_->Wait();
2477 } 2545 }
2478 2546
2479 // Get the command from the queue. 2547 // Get the command from the queue.
2480 CommandMessage command = command_queue_.Get(); 2548 CommandMessage command = command_queue_.Get();
2481 Logger::DebugTag("Got request from command queue, in interactive loop."); 2549 LOGGER->DebugTag("Got request from command queue, in interactive loop.");
2482 if (!Debugger::IsDebuggerActive()) { 2550 if (!Debugger::IsDebuggerActive()) {
2483 // Delete command text and user data. 2551 // Delete command text and user data.
2484 command.Dispose(); 2552 command.Dispose();
2485 return; 2553 return;
2486 } 2554 }
2487 2555
2488 // Invoke JavaScript to process the debug request. 2556 // Invoke JavaScript to process the debug request.
2489 v8::Local<v8::String> fun_name; 2557 v8::Local<v8::String> fun_name;
2490 v8::Local<v8::Function> fun; 2558 v8::Local<v8::Function> fun;
2491 v8::Local<v8::Value> request; 2559 v8::Local<v8::Value> request;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 // and there are no more commands queued. 2613 // and there are no more commands queued.
2546 if (running && !HasCommands()) { 2614 if (running && !HasCommands()) {
2547 return; 2615 return;
2548 } 2616 }
2549 } 2617 }
2550 } 2618 }
2551 2619
2552 2620
2553 void Debugger::SetEventListener(Handle<Object> callback, 2621 void Debugger::SetEventListener(Handle<Object> callback,
2554 Handle<Object> data) { 2622 Handle<Object> data) {
2623 ASSERT(Isolate::Current() == isolate_);
2555 HandleScope scope; 2624 HandleScope scope;
2556 2625
2557 // Clear the global handles for the event listener and the event listener data 2626 // Clear the global handles for the event listener and the event listener data
2558 // object. 2627 // object.
2559 if (!event_listener_.is_null()) { 2628 if (!event_listener_.is_null()) {
2560 GlobalHandles::Destroy( 2629 isolate_->global_handles()->Destroy(
2561 reinterpret_cast<Object**>(event_listener_.location())); 2630 reinterpret_cast<Object**>(event_listener_.location()));
2562 event_listener_ = Handle<Object>(); 2631 event_listener_ = Handle<Object>();
2563 } 2632 }
2564 if (!event_listener_data_.is_null()) { 2633 if (!event_listener_data_.is_null()) {
2565 GlobalHandles::Destroy( 2634 isolate_->global_handles()->Destroy(
2566 reinterpret_cast<Object**>(event_listener_data_.location())); 2635 reinterpret_cast<Object**>(event_listener_data_.location()));
2567 event_listener_data_ = Handle<Object>(); 2636 event_listener_data_ = Handle<Object>();
2568 } 2637 }
2569 2638
2570 // If there is a new debug event listener register it together with its data 2639 // If there is a new debug event listener register it together with its data
2571 // object. 2640 // object.
2572 if (!callback->IsUndefined() && !callback->IsNull()) { 2641 if (!callback->IsUndefined() && !callback->IsNull()) {
2573 event_listener_ = Handle<Object>::cast(GlobalHandles::Create(*callback)); 2642 event_listener_ = Handle<Object>::cast(
2643 isolate_->global_handles()->Create(*callback));
2574 if (data.is_null()) { 2644 if (data.is_null()) {
2575 data = Factory::undefined_value(); 2645 data = FACTORY->undefined_value();
2576 } 2646 }
2577 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); 2647 event_listener_data_ = Handle<Object>::cast(
2648 isolate_->global_handles()->Create(*data));
2578 } 2649 }
2579 2650
2580 ListenersChanged(); 2651 ListenersChanged();
2581 } 2652 }
2582 2653
2583 2654
2584 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { 2655 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
2656 ASSERT(Isolate::Current() == isolate_);
2585 ScopedLock with(debugger_access_); 2657 ScopedLock with(debugger_access_);
2586 2658
2587 message_handler_ = handler; 2659 message_handler_ = handler;
2588 ListenersChanged(); 2660 ListenersChanged();
2589 if (handler == NULL) { 2661 if (handler == NULL) {
2590 // Send an empty command to the debugger if in a break to make JavaScript 2662 // Send an empty command to the debugger if in a break to make JavaScript
2591 // run again if the debugger is closed. 2663 // run again if the debugger is closed.
2592 if (Debug::InDebugger()) { 2664 if (isolate_->debug()->InDebugger()) {
2593 ProcessCommand(Vector<const uint16_t>::empty()); 2665 ProcessCommand(Vector<const uint16_t>::empty());
2594 } 2666 }
2595 } 2667 }
2596 } 2668 }
2597 2669
2598 2670
2599 void Debugger::ListenersChanged() { 2671 void Debugger::ListenersChanged() {
2672 Isolate* isolate = Isolate::Current();
2600 if (IsDebuggerActive()) { 2673 if (IsDebuggerActive()) {
2601 // Disable the compilation cache when the debugger is active. 2674 // Disable the compilation cache when the debugger is active.
2602 CompilationCache::Disable(); 2675 isolate->compilation_cache()->Disable();
2603 debugger_unload_pending_ = false; 2676 debugger_unload_pending_ = false;
2604 } else { 2677 } else {
2605 CompilationCache::Enable(); 2678 isolate->compilation_cache()->Enable();
2606 // Unload the debugger if event listener and message handler cleared. 2679 // Unload the debugger if event listener and message handler cleared.
2607 // Schedule this for later, because we may be in non-V8 thread. 2680 // Schedule this for later, because we may be in non-V8 thread.
2608 debugger_unload_pending_ = true; 2681 debugger_unload_pending_ = true;
2609 } 2682 }
2610 } 2683 }
2611 2684
2612 2685
2613 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, 2686 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
2614 int period) { 2687 int period) {
2688 ASSERT(Isolate::Current() == isolate_);
2615 host_dispatch_handler_ = handler; 2689 host_dispatch_handler_ = handler;
2616 host_dispatch_micros_ = period * 1000; 2690 host_dispatch_micros_ = period * 1000;
2617 } 2691 }
2618 2692
2619 2693
2620 void Debugger::SetDebugMessageDispatchHandler( 2694 void Debugger::SetDebugMessageDispatchHandler(
2621 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { 2695 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) {
2696 ASSERT(Isolate::Current() == isolate_);
2622 ScopedLock with(dispatch_handler_access_); 2697 ScopedLock with(dispatch_handler_access_);
2623 debug_message_dispatch_handler_ = handler; 2698 debug_message_dispatch_handler_ = handler;
2624 2699
2625 if (provide_locker && message_dispatch_helper_thread_ == NULL) { 2700 if (provide_locker && message_dispatch_helper_thread_ == NULL) {
2626 message_dispatch_helper_thread_ = new MessageDispatchHelperThread; 2701 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_);
2627 message_dispatch_helper_thread_->Start(); 2702 message_dispatch_helper_thread_->Start();
2628 } 2703 }
2629 } 2704 }
2630 2705
2631 2706
2632 // Calls the registered debug message handler. This callback is part of the 2707 // Calls the registered debug message handler. This callback is part of the
2633 // public API. 2708 // public API.
2634 void Debugger::InvokeMessageHandler(MessageImpl message) { 2709 void Debugger::InvokeMessageHandler(MessageImpl message) {
2710 ASSERT(Isolate::Current() == isolate_);
2635 ScopedLock with(debugger_access_); 2711 ScopedLock with(debugger_access_);
2636 2712
2637 if (message_handler_ != NULL) { 2713 if (message_handler_ != NULL) {
2638 message_handler_(message); 2714 message_handler_(message);
2639 } 2715 }
2640 } 2716 }
2641 2717
2642 2718
2643 // Puts a command coming from the public API on the queue. Creates 2719 // Puts a command coming from the public API on the queue. Creates
2644 // a copy of the command string managed by the debugger. Up to this 2720 // a copy of the command string managed by the debugger. Up to this
2645 // point, the command data was managed by the API client. Called 2721 // point, the command data was managed by the API client. Called
2646 // by the API client thread. 2722 // by the API client thread.
2647 void Debugger::ProcessCommand(Vector<const uint16_t> command, 2723 void Debugger::ProcessCommand(Vector<const uint16_t> command,
2648 v8::Debug::ClientData* client_data) { 2724 v8::Debug::ClientData* client_data) {
2725 ASSERT(Isolate::Current() == isolate_);
2649 // Need to cast away const. 2726 // Need to cast away const.
2650 CommandMessage message = CommandMessage::New( 2727 CommandMessage message = CommandMessage::New(
2651 Vector<uint16_t>(const_cast<uint16_t*>(command.start()), 2728 Vector<uint16_t>(const_cast<uint16_t*>(command.start()),
2652 command.length()), 2729 command.length()),
2653 client_data); 2730 client_data);
2654 Logger::DebugTag("Put command on command_queue."); 2731 LOGGER->DebugTag("Put command on command_queue.");
2655 command_queue_.Put(message); 2732 command_queue_.Put(message);
2656 command_received_->Signal(); 2733 command_received_->Signal();
2657 2734
2658 // Set the debug command break flag to have the command processed. 2735 // Set the debug command break flag to have the command processed.
2659 if (!Debug::InDebugger()) { 2736 if (!isolate_->debug()->InDebugger()) {
2660 StackGuard::DebugCommand(); 2737 isolate_->stack_guard()->DebugCommand();
2661 } 2738 }
2662 2739
2663 MessageDispatchHelperThread* dispatch_thread; 2740 MessageDispatchHelperThread* dispatch_thread;
2664 { 2741 {
2665 ScopedLock with(dispatch_handler_access_); 2742 ScopedLock with(dispatch_handler_access_);
2666 dispatch_thread = message_dispatch_helper_thread_; 2743 dispatch_thread = message_dispatch_helper_thread_;
2667 } 2744 }
2668 2745
2669 if (dispatch_thread == NULL) { 2746 if (dispatch_thread == NULL) {
2670 CallMessageDispatchHandler(); 2747 CallMessageDispatchHandler();
2671 } else { 2748 } else {
2672 dispatch_thread->Schedule(); 2749 dispatch_thread->Schedule();
2673 } 2750 }
2674 } 2751 }
2675 2752
2676 2753
2677 bool Debugger::HasCommands() { 2754 bool Debugger::HasCommands() {
2755 ASSERT(Isolate::Current() == isolate_);
2678 return !command_queue_.IsEmpty(); 2756 return !command_queue_.IsEmpty();
2679 } 2757 }
2680 2758
2681 2759
2682 void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { 2760 void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) {
2761 ASSERT(Isolate::Current() == isolate_);
2683 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); 2762 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data);
2684 event_command_queue_.Put(message); 2763 event_command_queue_.Put(message);
2685 2764
2686 // Set the debug command break flag to have the command processed. 2765 // Set the debug command break flag to have the command processed.
2687 if (!Debug::InDebugger()) { 2766 if (!isolate_->debug()->InDebugger()) {
2688 StackGuard::DebugCommand(); 2767 isolate_->stack_guard()->DebugCommand();
2689 } 2768 }
2690 } 2769 }
2691 2770
2692 2771
2693 bool Debugger::IsDebuggerActive() { 2772 bool Debugger::IsDebuggerActive() {
2773 ASSERT(Isolate::Current() == isolate_);
2694 ScopedLock with(debugger_access_); 2774 ScopedLock with(debugger_access_);
2695 2775
2696 return message_handler_ != NULL || !event_listener_.is_null(); 2776 return message_handler_ != NULL || !event_listener_.is_null();
2697 } 2777 }
2698 2778
2699 2779
2700 Handle<Object> Debugger::Call(Handle<JSFunction> fun, 2780 Handle<Object> Debugger::Call(Handle<JSFunction> fun,
2701 Handle<Object> data, 2781 Handle<Object> data,
2702 bool* pending_exception) { 2782 bool* pending_exception) {
2783 ASSERT(Isolate::Current() == isolate_);
2703 // When calling functions in the debugger prevent it from beeing unloaded. 2784 // When calling functions in the debugger prevent it from beeing unloaded.
2704 Debugger::never_unload_debugger_ = true; 2785 Debugger::never_unload_debugger_ = true;
2705 2786
2706 // Enter the debugger. 2787 // Enter the debugger.
2707 EnterDebugger debugger; 2788 EnterDebugger debugger;
2708 if (debugger.FailedToEnter()) { 2789 if (debugger.FailedToEnter()) {
2709 return Factory::undefined_value(); 2790 return FACTORY->undefined_value();
2710 } 2791 }
2711 2792
2712 // Create the execution state. 2793 // Create the execution state.
2713 bool caught_exception = false; 2794 bool caught_exception = false;
2714 Handle<Object> exec_state = MakeExecutionState(&caught_exception); 2795 Handle<Object> exec_state = MakeExecutionState(&caught_exception);
2715 if (caught_exception) { 2796 if (caught_exception) {
2716 return Factory::undefined_value(); 2797 return FACTORY->undefined_value();
2717 } 2798 }
2718 2799
2719 static const int kArgc = 2; 2800 static const int kArgc = 2;
2720 Object** argv[kArgc] = { exec_state.location(), data.location() }; 2801 Object** argv[kArgc] = { exec_state.location(), data.location() };
2721 Handle<Object> result = Execution::Call( 2802 Handle<Object> result = Execution::Call(
2722 fun, 2803 fun,
2723 Handle<Object>(Debug::debug_context_->global_proxy()), 2804 Handle<Object>(isolate_->debug()->debug_context_->global_proxy()),
2724 kArgc, 2805 kArgc,
2725 argv, 2806 argv,
2726 pending_exception); 2807 pending_exception);
2727 return result; 2808 return result;
2728 } 2809 }
2729 2810
2730 2811
2731 static void StubMessageHandler2(const v8::Debug::Message& message) { 2812 static void StubMessageHandler2(const v8::Debug::Message& message) {
2732 // Simply ignore message. 2813 // Simply ignore message.
2733 } 2814 }
2734 2815
2735 2816
2736 bool Debugger::StartAgent(const char* name, int port, 2817 bool Debugger::StartAgent(const char* name, int port,
2737 bool wait_for_connection) { 2818 bool wait_for_connection) {
2819 ASSERT(Isolate::Current() == isolate_);
2738 if (wait_for_connection) { 2820 if (wait_for_connection) {
2739 // Suspend V8 if it is already running or set V8 to suspend whenever 2821 // Suspend V8 if it is already running or set V8 to suspend whenever
2740 // it starts. 2822 // it starts.
2741 // Provide stub message handler; V8 auto-continues each suspend 2823 // Provide stub message handler; V8 auto-continues each suspend
2742 // when there is no message handler; we doesn't need it. 2824 // when there is no message handler; we doesn't need it.
2743 // Once become suspended, V8 will stay so indefinitely long, until remote 2825 // Once become suspended, V8 will stay so indefinitely long, until remote
2744 // debugger connects and issues "continue" command. 2826 // debugger connects and issues "continue" command.
2745 Debugger::message_handler_ = StubMessageHandler2; 2827 Debugger::message_handler_ = StubMessageHandler2;
2746 v8::Debug::DebugBreak(); 2828 v8::Debug::DebugBreak();
2747 } 2829 }
2748 2830
2749 if (Socket::Setup()) { 2831 if (Socket::Setup()) {
2750 if (agent_ == NULL) { 2832 if (agent_ == NULL) {
2751 agent_ = new DebuggerAgent(name, port); 2833 agent_ = new DebuggerAgent(isolate_, name, port);
2752 agent_->Start(); 2834 agent_->Start();
2753 } 2835 }
2754 return true; 2836 return true;
2755 } 2837 }
2756 2838
2757 return false; 2839 return false;
2758 } 2840 }
2759 2841
2760 2842
2761 void Debugger::StopAgent() { 2843 void Debugger::StopAgent() {
2844 ASSERT(Isolate::Current() == isolate_);
2762 if (agent_ != NULL) { 2845 if (agent_ != NULL) {
2763 agent_->Shutdown(); 2846 agent_->Shutdown();
2764 agent_->Join(); 2847 agent_->Join();
2765 delete agent_; 2848 delete agent_;
2766 agent_ = NULL; 2849 agent_ = NULL;
2767 } 2850 }
2768 } 2851 }
2769 2852
2770 2853
2771 void Debugger::WaitForAgent() { 2854 void Debugger::WaitForAgent() {
2855 ASSERT(Isolate::Current() == isolate_);
2772 if (agent_ != NULL) 2856 if (agent_ != NULL)
2773 agent_->WaitUntilListening(); 2857 agent_->WaitUntilListening();
2774 } 2858 }
2775 2859
2776 2860
2777 void Debugger::CallMessageDispatchHandler() { 2861 void Debugger::CallMessageDispatchHandler() {
2862 ASSERT(Isolate::Current() == isolate_);
2778 v8::Debug::DebugMessageDispatchHandler handler; 2863 v8::Debug::DebugMessageDispatchHandler handler;
2779 { 2864 {
2780 ScopedLock with(dispatch_handler_access_); 2865 ScopedLock with(dispatch_handler_access_);
2781 handler = Debugger::debug_message_dispatch_handler_; 2866 handler = Debugger::debug_message_dispatch_handler_;
2782 } 2867 }
2783 if (handler != NULL) { 2868 if (handler != NULL) {
2784 handler(); 2869 handler();
2785 } 2870 }
2786 } 2871 }
2787 2872
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2871 return v8::Handle<v8::String>(); 2956 return v8::Handle<v8::String>();
2872 } 2957 }
2873 return scope.Close(v8::Utils::ToLocal(Handle<String>::cast(json))); 2958 return scope.Close(v8::Utils::ToLocal(Handle<String>::cast(json)));
2874 } else { 2959 } else {
2875 return v8::Utils::ToLocal(response_json_); 2960 return v8::Utils::ToLocal(response_json_);
2876 } 2961 }
2877 } 2962 }
2878 2963
2879 2964
2880 v8::Handle<v8::Context> MessageImpl::GetEventContext() const { 2965 v8::Handle<v8::Context> MessageImpl::GetEventContext() const {
2881 v8::Handle<v8::Context> context = GetDebugEventContext(); 2966 Isolate* isolate = Isolate::Current();
2882 // Top::context() may be NULL when "script collected" event occures. 2967 v8::Handle<v8::Context> context = GetDebugEventContext(isolate);
2968 // Isolate::context() may be NULL when "script collected" event occures.
2883 ASSERT(!context.IsEmpty() || event_ == v8::ScriptCollected); 2969 ASSERT(!context.IsEmpty() || event_ == v8::ScriptCollected);
2884 return GetDebugEventContext(); 2970 return GetDebugEventContext(isolate);
2885 } 2971 }
2886 2972
2887 2973
2888 v8::Debug::ClientData* MessageImpl::GetClientData() const { 2974 v8::Debug::ClientData* MessageImpl::GetClientData() const {
2889 return client_data_; 2975 return client_data_;
2890 } 2976 }
2891 2977
2892 2978
2893 EventDetailsImpl::EventDetailsImpl(DebugEvent event, 2979 EventDetailsImpl::EventDetailsImpl(DebugEvent event,
2894 Handle<JSObject> exec_state, 2980 Handle<JSObject> exec_state,
(...skipping 16 matching lines...) Expand all
2911 return v8::Utils::ToLocal(exec_state_); 2997 return v8::Utils::ToLocal(exec_state_);
2912 } 2998 }
2913 2999
2914 3000
2915 v8::Handle<v8::Object> EventDetailsImpl::GetEventData() const { 3001 v8::Handle<v8::Object> EventDetailsImpl::GetEventData() const {
2916 return v8::Utils::ToLocal(event_data_); 3002 return v8::Utils::ToLocal(event_data_);
2917 } 3003 }
2918 3004
2919 3005
2920 v8::Handle<v8::Context> EventDetailsImpl::GetEventContext() const { 3006 v8::Handle<v8::Context> EventDetailsImpl::GetEventContext() const {
2921 return GetDebugEventContext(); 3007 return GetDebugEventContext(Isolate::Current());
2922 } 3008 }
2923 3009
2924 3010
2925 v8::Handle<v8::Value> EventDetailsImpl::GetCallbackData() const { 3011 v8::Handle<v8::Value> EventDetailsImpl::GetCallbackData() const {
2926 return v8::Utils::ToLocal(callback_data_); 3012 return v8::Utils::ToLocal(callback_data_);
2927 } 3013 }
2928 3014
2929 3015
2930 v8::Debug::ClientData* EventDetailsImpl::GetClientData() const { 3016 v8::Debug::ClientData* EventDetailsImpl::GetClientData() const {
2931 return client_data_; 3017 return client_data_;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 3106
3021 bool LockingCommandMessageQueue::IsEmpty() const { 3107 bool LockingCommandMessageQueue::IsEmpty() const {
3022 ScopedLock sl(lock_); 3108 ScopedLock sl(lock_);
3023 return queue_.IsEmpty(); 3109 return queue_.IsEmpty();
3024 } 3110 }
3025 3111
3026 3112
3027 CommandMessage LockingCommandMessageQueue::Get() { 3113 CommandMessage LockingCommandMessageQueue::Get() {
3028 ScopedLock sl(lock_); 3114 ScopedLock sl(lock_);
3029 CommandMessage result = queue_.Get(); 3115 CommandMessage result = queue_.Get();
3030 Logger::DebugEvent("Get", result.text()); 3116 LOGGER->DebugEvent("Get", result.text());
3031 return result; 3117 return result;
3032 } 3118 }
3033 3119
3034 3120
3035 void LockingCommandMessageQueue::Put(const CommandMessage& message) { 3121 void LockingCommandMessageQueue::Put(const CommandMessage& message) {
3036 ScopedLock sl(lock_); 3122 ScopedLock sl(lock_);
3037 queue_.Put(message); 3123 queue_.Put(message);
3038 Logger::DebugEvent("Put", message.text()); 3124 LOGGER->DebugEvent("Put", message.text());
3039 } 3125 }
3040 3126
3041 3127
3042 void LockingCommandMessageQueue::Clear() { 3128 void LockingCommandMessageQueue::Clear() {
3043 ScopedLock sl(lock_); 3129 ScopedLock sl(lock_);
3044 queue_.Clear(); 3130 queue_.Clear();
3045 } 3131 }
3046 3132
3047 3133
3048 MessageDispatchHelperThread::MessageDispatchHelperThread() 3134 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate)
3049 : Thread("v8:MsgDispHelpr"), 3135 : Thread(isolate, "v8:MsgDispHelpr"),
3050 sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()), 3136 sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()),
3051 already_signalled_(false) { 3137 already_signalled_(false) {
3052 } 3138 }
3053 3139
3054 3140
3055 MessageDispatchHelperThread::~MessageDispatchHelperThread() { 3141 MessageDispatchHelperThread::~MessageDispatchHelperThread() {
3056 delete mutex_; 3142 delete mutex_;
3057 delete sem_; 3143 delete sem_;
3058 } 3144 }
3059 3145
(...skipping 12 matching lines...) Expand all
3072 3158
3073 void MessageDispatchHelperThread::Run() { 3159 void MessageDispatchHelperThread::Run() {
3074 while (true) { 3160 while (true) {
3075 sem_->Wait(); 3161 sem_->Wait();
3076 { 3162 {
3077 ScopedLock lock(mutex_); 3163 ScopedLock lock(mutex_);
3078 already_signalled_ = false; 3164 already_signalled_ = false;
3079 } 3165 }
3080 { 3166 {
3081 Locker locker; 3167 Locker locker;
3082 Debugger::CallMessageDispatchHandler(); 3168 Isolate::Current()->debugger()->CallMessageDispatchHandler();
3083 } 3169 }
3084 } 3170 }
3085 } 3171 }
3086 3172
3087 #endif // ENABLE_DEBUGGER_SUPPORT 3173 #endif // ENABLE_DEBUGGER_SUPPORT
3088 3174
3089 } } // namespace v8::internal 3175 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.h ('k') | src/debug-agent.h » ('j') | src/heap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698