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

Side by Side Diff: src/debug/debug.cc

Issue 1292533003: Debugger: simplify calling into Javascript. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « src/debug/debug.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/debug/debug.h" 5 #include "src/debug/debug.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 if (break_points_hit_count == 0) { 625 if (break_points_hit_count == 0) {
626 return factory->undefined_value(); 626 return factory->undefined_value();
627 } 627 }
628 // Return break points hit as a JSArray. 628 // Return break points hit as a JSArray.
629 Handle<JSArray> result = factory->NewJSArrayWithElements(break_points_hit); 629 Handle<JSArray> result = factory->NewJSArrayWithElements(break_points_hit);
630 result->set_length(Smi::FromInt(break_points_hit_count)); 630 result->set_length(Smi::FromInt(break_points_hit_count));
631 return result; 631 return result;
632 } 632 }
633 633
634 634
635 MaybeHandle<Object> Debug::CallFunction(const char* name, int argc,
636 Handle<Object> args[]) {
637 PostponeInterruptsScope no_interrupts(isolate_);
638 AssertDebugContext();
639 Handle<Object> holder = isolate_->natives_utils_object();
640 Handle<JSFunction> fun = Handle<JSFunction>::cast(
641 Object::GetProperty(isolate_, holder, name, STRICT).ToHandleChecked());
642 Handle<Object> undefined = isolate_->factory()->undefined_value();
643 return Execution::TryCall(fun, undefined, argc, args);
644 }
645
646
635 // Check whether a single break point object is triggered. 647 // Check whether a single break point object is triggered.
636 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { 648 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) {
637 Factory* factory = isolate_->factory(); 649 Factory* factory = isolate_->factory();
638 HandleScope scope(isolate_); 650 HandleScope scope(isolate_);
639 651
640 // Ignore check if break point object is not a JSObject. 652 // Ignore check if break point object is not a JSObject.
641 if (!break_point_object->IsJSObject()) return true; 653 if (!break_point_object->IsJSObject()) return true;
642 654
643 // Get the function IsBreakPointTriggered (defined in debug.js).
644 Handle<String> is_break_point_triggered_string =
645 factory->InternalizeOneByteString(
646 STATIC_CHAR_VECTOR("IsBreakPointTriggered"));
647 Handle<GlobalObject> debug_global(debug_context()->global_object());
648 Handle<JSFunction> check_break_point = Handle<JSFunction>::cast(
649 Object::GetProperty(debug_utils(), is_break_point_triggered_string)
650 .ToHandleChecked());
651
652 // Get the break id as an object. 655 // Get the break id as an object.
653 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); 656 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id());
654 657
655 // Call HandleBreakPointx. 658 // Call IsBreakPointTriggered.
656 Handle<Object> argv[] = { break_id, break_point_object }; 659 Handle<Object> argv[] = { break_id, break_point_object };
657 Handle<Object> result; 660 Handle<Object> result;
658 if (!Execution::TryCall(check_break_point, 661 if (!CallFunction("IsBreakPointTriggered", arraysize(argv), argv)
659 isolate_->js_builtins_object(), 662 .ToHandle(&result)) {
660 arraysize(argv),
661 argv).ToHandle(&result)) {
662 return false; 663 return false;
663 } 664 }
664 665
665 // Return whether the break point is triggered. 666 // Return whether the break point is triggered.
666 return result->IsTrue(); 667 return result->IsTrue();
667 } 668 }
668 669
669 670
670 bool Debug::SetBreakPoint(Handle<JSFunction> function, 671 bool Debug::SetBreakPoint(Handle<JSFunction> function,
671 Handle<Object> break_point_object, 672 Handle<Object> break_point_object,
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 1663
1663 1664
1664 bool Debug::IsDebugGlobal(GlobalObject* global) { 1665 bool Debug::IsDebugGlobal(GlobalObject* global) {
1665 return is_loaded() && global == debug_context()->global_object(); 1666 return is_loaded() && global == debug_context()->global_object();
1666 } 1667 }
1667 1668
1668 1669
1669 void Debug::ClearMirrorCache() { 1670 void Debug::ClearMirrorCache() {
1670 PostponeInterruptsScope postpone(isolate_); 1671 PostponeInterruptsScope postpone(isolate_);
1671 HandleScope scope(isolate_); 1672 HandleScope scope(isolate_);
1672 AssertDebugContext(); 1673 CallFunction("ClearMirrorCache", 0, NULL);
1673
1674 Handle<Object> fun =
1675 Object::GetProperty(isolate_, debug_utils(), "ClearMirrorCache")
1676 .ToHandleChecked();
1677 Handle<Object> undefined = isolate_->factory()->undefined_value();
1678 Execution::TryCall(Handle<JSFunction>::cast(fun), undefined, 0, NULL);
1679 } 1674 }
1680 1675
1681 1676
1682 Handle<FixedArray> Debug::GetLoadedScripts() { 1677 Handle<FixedArray> Debug::GetLoadedScripts() {
1683 // Create and fill the script cache when the loaded scripts is requested for 1678 // Create and fill the script cache when the loaded scripts is requested for
1684 // the first time. 1679 // the first time.
1685 if (script_cache_ == NULL) script_cache_ = new ScriptCache(isolate_); 1680 if (script_cache_ == NULL) script_cache_ = new ScriptCache(isolate_);
1686 1681
1687 // Perform GC to get unreferenced scripts evicted from the cache before 1682 // Perform GC to get unreferenced scripts evicted from the cache before
1688 // returning the content. 1683 // returning the content.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 if (!it.done()) { 1735 if (!it.done()) {
1741 script->set_eval_from_shared(it.frame()->function()->shared()); 1736 script->set_eval_from_shared(it.frame()->function()->shared());
1742 Code* code = it.frame()->LookupCode(); 1737 Code* code = it.frame()->LookupCode();
1743 int offset = static_cast<int>( 1738 int offset = static_cast<int>(
1744 it.frame()->pc() - code->instruction_start()); 1739 it.frame()->pc() - code->instruction_start());
1745 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); 1740 script->set_eval_from_instructions_offset(Smi::FromInt(offset));
1746 } 1741 }
1747 } 1742 }
1748 1743
1749 1744
1750 MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name,
1751 int argc,
1752 Handle<Object> argv[]) {
1753 AssertDebugContext();
1754 // Create the execution state object.
1755 Handle<Object> constructor =
1756 Object::GetProperty(isolate_, debug_utils(), constructor_name)
1757 .ToHandleChecked();
1758 DCHECK(constructor->IsJSFunction());
1759 if (!constructor->IsJSFunction()) return MaybeHandle<Object>();
1760 // We do not handle interrupts here. In particular, termination interrupts.
1761 PostponeInterruptsScope no_interrupts(isolate_);
1762 return Execution::TryCall(Handle<JSFunction>::cast(constructor),
1763 handle(debug_context()->global_proxy()),
1764 argc,
1765 argv);
1766 }
1767
1768
1769 MaybeHandle<Object> Debug::MakeExecutionState() { 1745 MaybeHandle<Object> Debug::MakeExecutionState() {
1770 // Create the execution state object. 1746 // Create the execution state object.
1771 Handle<Object> argv[] = { isolate_->factory()->NewNumberFromInt(break_id()) }; 1747 Handle<Object> argv[] = { isolate_->factory()->NewNumberFromInt(break_id()) };
1772 return MakeJSObject("MakeExecutionState", arraysize(argv), argv); 1748 return CallFunction("MakeExecutionState", arraysize(argv), argv);
1773 } 1749 }
1774 1750
1775 1751
1776 MaybeHandle<Object> Debug::MakeBreakEvent(Handle<Object> break_points_hit) { 1752 MaybeHandle<Object> Debug::MakeBreakEvent(Handle<Object> break_points_hit) {
1777 // Create the new break event object. 1753 // Create the new break event object.
1778 Handle<Object> argv[] = { isolate_->factory()->NewNumberFromInt(break_id()), 1754 Handle<Object> argv[] = { isolate_->factory()->NewNumberFromInt(break_id()),
1779 break_points_hit }; 1755 break_points_hit };
1780 return MakeJSObject("MakeBreakEvent", arraysize(argv), argv); 1756 return CallFunction("MakeBreakEvent", arraysize(argv), argv);
1781 } 1757 }
1782 1758
1783 1759
1784 MaybeHandle<Object> Debug::MakeExceptionEvent(Handle<Object> exception, 1760 MaybeHandle<Object> Debug::MakeExceptionEvent(Handle<Object> exception,
1785 bool uncaught, 1761 bool uncaught,
1786 Handle<Object> promise) { 1762 Handle<Object> promise) {
1787 // Create the new exception event object. 1763 // Create the new exception event object.
1788 Handle<Object> argv[] = { isolate_->factory()->NewNumberFromInt(break_id()), 1764 Handle<Object> argv[] = { isolate_->factory()->NewNumberFromInt(break_id()),
1789 exception, 1765 exception,
1790 isolate_->factory()->ToBoolean(uncaught), 1766 isolate_->factory()->ToBoolean(uncaught),
1791 promise }; 1767 promise };
1792 return MakeJSObject("MakeExceptionEvent", arraysize(argv), argv); 1768 return CallFunction("MakeExceptionEvent", arraysize(argv), argv);
1793 } 1769 }
1794 1770
1795 1771
1796 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script, 1772 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script,
1797 v8::DebugEvent type) { 1773 v8::DebugEvent type) {
1798 // Create the compile event object. 1774 // Create the compile event object.
1799 Handle<Object> script_wrapper = Script::GetWrapper(script); 1775 Handle<Object> script_wrapper = Script::GetWrapper(script);
1800 Handle<Object> argv[] = { script_wrapper, 1776 Handle<Object> argv[] = { script_wrapper,
1801 isolate_->factory()->NewNumberFromInt(type) }; 1777 isolate_->factory()->NewNumberFromInt(type) };
1802 return MakeJSObject("MakeCompileEvent", arraysize(argv), argv); 1778 return CallFunction("MakeCompileEvent", arraysize(argv), argv);
1803 } 1779 }
1804 1780
1805 1781
1806 MaybeHandle<Object> Debug::MakePromiseEvent(Handle<JSObject> event_data) { 1782 MaybeHandle<Object> Debug::MakePromiseEvent(Handle<JSObject> event_data) {
1807 // Create the promise event object. 1783 // Create the promise event object.
1808 Handle<Object> argv[] = { event_data }; 1784 Handle<Object> argv[] = { event_data };
1809 return MakeJSObject("MakePromiseEvent", arraysize(argv), argv); 1785 return CallFunction("MakePromiseEvent", arraysize(argv), argv);
1810 } 1786 }
1811 1787
1812 1788
1813 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<JSObject> task_event) { 1789 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<JSObject> task_event) {
1814 // Create the async task event object. 1790 // Create the async task event object.
1815 Handle<Object> argv[] = { task_event }; 1791 Handle<Object> argv[] = { task_event };
1816 return MakeJSObject("MakeAsyncTaskEvent", arraysize(argv), argv); 1792 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv);
1817 } 1793 }
1818 1794
1819 1795
1820 void Debug::OnThrow(Handle<Object> exception) { 1796 void Debug::OnThrow(Handle<Object> exception) {
1821 if (in_debug_scope() || ignore_events()) return; 1797 if (in_debug_scope() || ignore_events()) return;
1822 // Temporarily clear any scheduled_exception to allow evaluating 1798 // Temporarily clear any scheduled_exception to allow evaluating
1823 // JavaScript from the debug event handler. 1799 // JavaScript from the debug event handler.
1824 HandleScope scope(isolate_); 1800 HandleScope scope(isolate_);
1825 Handle<Object> scheduled_exception; 1801 Handle<Object> scheduled_exception;
1826 if (isolate_->has_scheduled_exception()) { 1802 if (isolate_->has_scheduled_exception()) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 ProcessCompileEventInDebugScope(v8::AfterCompile, script); 1949 ProcessCompileEventInDebugScope(v8::AfterCompile, script);
1974 return; 1950 return;
1975 } 1951 }
1976 1952
1977 HandleScope scope(isolate_); 1953 HandleScope scope(isolate_);
1978 DebugScope debug_scope(this); 1954 DebugScope debug_scope(this);
1979 if (debug_scope.failed()) return; 1955 if (debug_scope.failed()) return;
1980 1956
1981 // If debugging there might be script break points registered for this 1957 // If debugging there might be script break points registered for this
1982 // script. Make sure that these break points are set. 1958 // script. Make sure that these break points are set.
1983 1959 Handle<Object> argv[] = {Script::GetWrapper(script)};
Jakob Kummerow 2015/08/13 14:57:36 nit: we like spaces inside {}
1984 // Get the function UpdateScriptBreakPoints (defined in debug.js). 1960 if (CallFunction("UpdateScriptBreakPoints", arraysize(argv), argv)
1985 Handle<Object> update_script_break_points = 1961 .is_null()) {
1986 Object::GetProperty(isolate_, debug_utils(), "UpdateScriptBreakPoints")
1987 .ToHandleChecked();
1988 if (!update_script_break_points->IsJSFunction()) {
1989 return;
1990 }
1991 DCHECK(update_script_break_points->IsJSFunction());
1992
1993 // Wrap the script object in a proper JS object before passing it
1994 // to JavaScript.
1995 Handle<Object> wrapper = Script::GetWrapper(script);
1996
1997 // Call UpdateScriptBreakPoints expect no exceptions.
1998 Handle<Object> argv[] = { wrapper };
1999 if (Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points),
2000 isolate_->js_builtins_object(),
2001 arraysize(argv),
2002 argv).is_null()) {
2003 return; 1962 return;
2004 } 1963 }
2005 1964
2006 // Create the compile state object. 1965 // Create the compile state object.
2007 Handle<Object> event_data; 1966 Handle<Object> event_data;
2008 // Bail out and don't call debugger if exception. 1967 // Bail out and don't call debugger if exception.
2009 if (!MakeCompileEvent(script, v8::AfterCompile).ToHandle(&event_data)) return; 1968 if (!MakeCompileEvent(script, v8::AfterCompile).ToHandle(&event_data)) return;
2010 1969
2011 // Process debug event. 1970 // Process debug event.
2012 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true); 1971 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true);
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 } 2679 }
2721 2680
2722 2681
2723 void LockingCommandMessageQueue::Clear() { 2682 void LockingCommandMessageQueue::Clear() {
2724 base::LockGuard<base::Mutex> lock_guard(&mutex_); 2683 base::LockGuard<base::Mutex> lock_guard(&mutex_);
2725 queue_.Clear(); 2684 queue_.Clear();
2726 } 2685 }
2727 2686
2728 } // namespace internal 2687 } // namespace internal
2729 } // namespace v8 2688 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698