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

Side by Side Diff: src/debug.cc

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

Powered by Google App Engine
This is Rietveld 408576698