| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 Handle<Script> script(Script::cast(function->shared()->script())); | 790 Handle<Script> script(Script::cast(function->shared()->script())); |
| 791 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 791 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 792 return true; | 792 return true; |
| 793 } | 793 } |
| 794 | 794 |
| 795 | 795 |
| 796 bool Debug::Load() { | 796 bool Debug::Load() { |
| 797 // Return if debugger is already loaded. | 797 // Return if debugger is already loaded. |
| 798 if (IsLoaded()) return true; | 798 if (IsLoaded()) return true; |
| 799 | 799 |
| 800 ASSERT(Isolate::Current() == isolate_); | |
| 801 Debugger* debugger = isolate_->debugger(); | 800 Debugger* debugger = isolate_->debugger(); |
| 802 | 801 |
| 803 // Bail out if we're already in the process of compiling the native | 802 // Bail out if we're already in the process of compiling the native |
| 804 // JavaScript source code for the debugger. | 803 // JavaScript source code for the debugger. |
| 805 if (debugger->compiling_natives() || | 804 if (debugger->compiling_natives() || |
| 806 debugger->is_loading_debugger()) | 805 debugger->is_loading_debugger()) |
| 807 return false; | 806 return false; |
| 808 debugger->set_loading_debugger(true); | 807 debugger->set_loading_debugger(true); |
| 809 | 808 |
| 810 // Disable breakpoints and interrupts while compiling and running the | 809 // Disable breakpoints and interrupts while compiling and running the |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 } | 1041 } |
| 1043 // Return break points hit as a JSArray. | 1042 // Return break points hit as a JSArray. |
| 1044 Handle<JSArray> result = factory->NewJSArrayWithElements(break_points_hit); | 1043 Handle<JSArray> result = factory->NewJSArrayWithElements(break_points_hit); |
| 1045 result->set_length(Smi::FromInt(break_points_hit_count)); | 1044 result->set_length(Smi::FromInt(break_points_hit_count)); |
| 1046 return result; | 1045 return result; |
| 1047 } | 1046 } |
| 1048 | 1047 |
| 1049 | 1048 |
| 1050 // Check whether a single break point object is triggered. | 1049 // Check whether a single break point object is triggered. |
| 1051 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { | 1050 bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { |
| 1052 ASSERT(Isolate::Current() == isolate_); | |
| 1053 Factory* factory = isolate_->factory(); | 1051 Factory* factory = isolate_->factory(); |
| 1054 HandleScope scope(isolate_); | 1052 HandleScope scope(isolate_); |
| 1055 | 1053 |
| 1056 // Ignore check if break point object is not a JSObject. | 1054 // Ignore check if break point object is not a JSObject. |
| 1057 if (!break_point_object->IsJSObject()) return true; | 1055 if (!break_point_object->IsJSObject()) return true; |
| 1058 | 1056 |
| 1059 // Get the function IsBreakPointTriggered (defined in debug-debugger.js). | 1057 // Get the function IsBreakPointTriggered (defined in debug-debugger.js). |
| 1060 Handle<String> is_break_point_triggered_symbol = | 1058 Handle<String> is_break_point_triggered_symbol = |
| 1061 factory->LookupAsciiSymbol("IsBreakPointTriggered"); | 1059 factory->LookupAsciiSymbol("IsBreakPointTriggered"); |
| 1062 Handle<JSFunction> check_break_point = | 1060 Handle<JSFunction> check_break_point = |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 bool Debug::IsBreakOnException(ExceptionBreakType type) { | 1226 bool Debug::IsBreakOnException(ExceptionBreakType type) { |
| 1229 if (type == BreakUncaughtException) { | 1227 if (type == BreakUncaughtException) { |
| 1230 return break_on_uncaught_exception_; | 1228 return break_on_uncaught_exception_; |
| 1231 } else { | 1229 } else { |
| 1232 return break_on_exception_; | 1230 return break_on_exception_; |
| 1233 } | 1231 } |
| 1234 } | 1232 } |
| 1235 | 1233 |
| 1236 | 1234 |
| 1237 void Debug::PrepareStep(StepAction step_action, int step_count) { | 1235 void Debug::PrepareStep(StepAction step_action, int step_count) { |
| 1238 ASSERT(Isolate::Current() == isolate_); | |
| 1239 HandleScope scope(isolate_); | 1236 HandleScope scope(isolate_); |
| 1240 ASSERT(Debug::InDebugger()); | 1237 ASSERT(Debug::InDebugger()); |
| 1241 | 1238 |
| 1242 // Remember this step action and count. | 1239 // Remember this step action and count. |
| 1243 thread_local_.last_step_action_ = step_action; | 1240 thread_local_.last_step_action_ = step_action; |
| 1244 if (step_action == StepOut) { | 1241 if (step_action == StepOut) { |
| 1245 // For step out target frame will be found on the stack so there is no need | 1242 // For step out target frame will be found on the stack so there is no need |
| 1246 // to set step counter for it. It's expected to always be 0 for StepOut. | 1243 // to set step counter for it. It's expected to always be 0 for StepOut. |
| 1247 thread_local_.step_count_ = 0; | 1244 thread_local_.step_count_ = 0; |
| 1248 } else { | 1245 } else { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 } | 1730 } |
| 1734 // Move to next in list. | 1731 // Move to next in list. |
| 1735 prev = current; | 1732 prev = current; |
| 1736 current = current->next(); | 1733 current = current->next(); |
| 1737 } | 1734 } |
| 1738 UNREACHABLE(); | 1735 UNREACHABLE(); |
| 1739 } | 1736 } |
| 1740 | 1737 |
| 1741 | 1738 |
| 1742 void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { | 1739 void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { |
| 1743 ASSERT(Isolate::Current() == isolate_); | |
| 1744 HandleScope scope(isolate_); | 1740 HandleScope scope(isolate_); |
| 1745 | 1741 |
| 1746 // Get the executing function in which the debug break occurred. | 1742 // Get the executing function in which the debug break occurred. |
| 1747 Handle<SharedFunctionInfo> shared = | 1743 Handle<SharedFunctionInfo> shared = |
| 1748 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); | 1744 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
| 1749 if (!EnsureDebugInfo(shared)) { | 1745 if (!EnsureDebugInfo(shared)) { |
| 1750 // Return if we failed to retrieve the debug info. | 1746 // Return if we failed to retrieve the debug info. |
| 1751 return; | 1747 return; |
| 1752 } | 1748 } |
| 1753 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1749 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 // care of the case where the last break point is removed from the function | 1815 // care of the case where the last break point is removed from the function |
| 1820 // and therefore no "original code" is available. | 1816 // and therefore no "original code" is available. |
| 1821 thread_local_.after_break_target_ = Assembler::target_address_at(addr); | 1817 thread_local_.after_break_target_ = Assembler::target_address_at(addr); |
| 1822 } | 1818 } |
| 1823 } | 1819 } |
| 1824 | 1820 |
| 1825 | 1821 |
| 1826 bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { | 1822 bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { |
| 1827 HandleScope scope(isolate_); | 1823 HandleScope scope(isolate_); |
| 1828 | 1824 |
| 1825 // If there are no break points this cannot be break at return, as |
| 1826 // the debugger statement and stack guard bebug break cannot be at |
| 1827 // return. |
| 1828 if (!has_break_points_) { |
| 1829 return false; |
| 1830 } |
| 1831 |
| 1829 // Get the executing function in which the debug break occurred. | 1832 // Get the executing function in which the debug break occurred. |
| 1830 Handle<SharedFunctionInfo> shared = | 1833 Handle<SharedFunctionInfo> shared = |
| 1831 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); | 1834 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
| 1832 if (!EnsureDebugInfo(shared)) { | 1835 if (!EnsureDebugInfo(shared)) { |
| 1833 // Return if we failed to retrieve the debug info. | 1836 // Return if we failed to retrieve the debug info. |
| 1834 return false; | 1837 return false; |
| 1835 } | 1838 } |
| 1836 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1839 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 1837 Handle<Code> code(debug_info->code()); | 1840 Handle<Code> code(debug_info->code()); |
| 1838 #ifdef DEBUG | 1841 #ifdef DEBUG |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1866 restarter_frame_function_pointer; | 1869 restarter_frame_function_pointer; |
| 1867 } | 1870 } |
| 1868 | 1871 |
| 1869 | 1872 |
| 1870 bool Debug::IsDebugGlobal(GlobalObject* global) { | 1873 bool Debug::IsDebugGlobal(GlobalObject* global) { |
| 1871 return IsLoaded() && global == debug_context()->global(); | 1874 return IsLoaded() && global == debug_context()->global(); |
| 1872 } | 1875 } |
| 1873 | 1876 |
| 1874 | 1877 |
| 1875 void Debug::ClearMirrorCache() { | 1878 void Debug::ClearMirrorCache() { |
| 1876 ASSERT(Isolate::Current() == isolate_); | |
| 1877 PostponeInterruptsScope postpone(isolate_); | 1879 PostponeInterruptsScope postpone(isolate_); |
| 1878 HandleScope scope(isolate_); | 1880 HandleScope scope(isolate_); |
| 1879 ASSERT(isolate_->context() == *Debug::debug_context()); | 1881 ASSERT(isolate_->context() == *Debug::debug_context()); |
| 1880 | 1882 |
| 1881 // Clear the mirror cache. | 1883 // Clear the mirror cache. |
| 1882 Handle<String> function_name = | 1884 Handle<String> function_name = |
| 1883 isolate_->factory()->LookupSymbol(CStrVector("ClearMirrorCache")); | 1885 isolate_->factory()->LookupSymbol(CStrVector("ClearMirrorCache")); |
| 1884 Handle<Object> fun(Isolate::Current()->global()->GetPropertyNoExceptionThrown( | 1886 Handle<Object> fun(Isolate::Current()->global()->GetPropertyNoExceptionThrown( |
| 1885 *function_name)); | 1887 *function_name)); |
| 1886 ASSERT(fun->IsJSFunction()); | 1888 ASSERT(fun->IsJSFunction()); |
| 1887 bool caught_exception; | 1889 bool caught_exception; |
| 1888 Handle<Object> js_object = Execution::TryCall( | 1890 Handle<Object> js_object = Execution::TryCall( |
| 1889 Handle<JSFunction>::cast(fun), | 1891 Handle<JSFunction>::cast(fun), |
| 1890 Handle<JSObject>(Debug::debug_context()->global()), | 1892 Handle<JSObject>(Debug::debug_context()->global()), |
| 1891 0, NULL, &caught_exception); | 1893 0, NULL, &caught_exception); |
| 1892 } | 1894 } |
| 1893 | 1895 |
| 1894 | 1896 |
| 1895 void Debug::CreateScriptCache() { | 1897 void Debug::CreateScriptCache() { |
| 1896 ASSERT(Isolate::Current() == isolate_); | |
| 1897 Heap* heap = isolate_->heap(); | 1898 Heap* heap = isolate_->heap(); |
| 1898 HandleScope scope(isolate_); | 1899 HandleScope scope(isolate_); |
| 1899 | 1900 |
| 1900 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | 1901 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
| 1901 // rid of all the cached script wrappers and the second gets rid of the | 1902 // rid of all the cached script wrappers and the second gets rid of the |
| 1902 // scripts which are no longer referenced. The second also sweeps precisely, | 1903 // scripts which are no longer referenced. The second also sweeps precisely, |
| 1903 // which saves us doing yet another GC to make the heap iterable. | 1904 // which saves us doing yet another GC to make the heap iterable. |
| 1904 heap->CollectAllGarbage(Heap::kNoGCFlags); | 1905 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 1905 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask); | 1906 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask); |
| 1906 | 1907 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1931 | 1932 |
| 1932 | 1933 |
| 1933 void Debug::AddScriptToScriptCache(Handle<Script> script) { | 1934 void Debug::AddScriptToScriptCache(Handle<Script> script) { |
| 1934 if (script_cache_ != NULL) { | 1935 if (script_cache_ != NULL) { |
| 1935 script_cache_->Add(script); | 1936 script_cache_->Add(script); |
| 1936 } | 1937 } |
| 1937 } | 1938 } |
| 1938 | 1939 |
| 1939 | 1940 |
| 1940 Handle<FixedArray> Debug::GetLoadedScripts() { | 1941 Handle<FixedArray> Debug::GetLoadedScripts() { |
| 1941 ASSERT(Isolate::Current() == isolate_); | |
| 1942 // Create and fill the script cache when the loaded scripts is requested for | 1942 // Create and fill the script cache when the loaded scripts is requested for |
| 1943 // the first time. | 1943 // the first time. |
| 1944 if (script_cache_ == NULL) { | 1944 if (script_cache_ == NULL) { |
| 1945 CreateScriptCache(); | 1945 CreateScriptCache(); |
| 1946 } | 1946 } |
| 1947 | 1947 |
| 1948 // If the script cache is not active just return an empty array. | 1948 // If the script cache is not active just return an empty array. |
| 1949 ASSERT(script_cache_ != NULL); | 1949 ASSERT(script_cache_ != NULL); |
| 1950 if (script_cache_ == NULL) { | 1950 if (script_cache_ == NULL) { |
| 1951 isolate_->factory()->NewFixedArray(0); | 1951 isolate_->factory()->NewFixedArray(0); |
| 1952 } | 1952 } |
| 1953 | 1953 |
| 1954 // Perform GC to get unreferenced scripts evicted from the cache before | 1954 // Perform GC to get unreferenced scripts evicted from the cache before |
| 1955 // returning the content. | 1955 // returning the content. |
| 1956 isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1956 isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1957 | 1957 |
| 1958 // Get the scripts from the cache. | 1958 // Get the scripts from the cache. |
| 1959 return script_cache_->GetScripts(); | 1959 return script_cache_->GetScripts(); |
| 1960 } | 1960 } |
| 1961 | 1961 |
| 1962 | 1962 |
| 1963 void Debug::AfterGarbageCollection() { | 1963 void Debug::AfterGarbageCollection() { |
| 1964 // Generate events for collected scripts. | 1964 // Generate events for collected scripts. |
| 1965 if (script_cache_ != NULL) { | 1965 if (script_cache_ != NULL) { |
| 1966 script_cache_->ProcessCollectedScripts(); | 1966 script_cache_->ProcessCollectedScripts(); |
| 1967 } | 1967 } |
| 1968 } | 1968 } |
| 1969 | 1969 |
| 1970 | 1970 |
| 1971 Debugger::Debugger() | 1971 Debugger::Debugger(Isolate* isolate) |
| 1972 : debugger_access_(OS::CreateMutex()), | 1972 : debugger_access_(OS::CreateMutex()), |
| 1973 event_listener_(Handle<Object>()), | 1973 event_listener_(Handle<Object>()), |
| 1974 event_listener_data_(Handle<Object>()), | 1974 event_listener_data_(Handle<Object>()), |
| 1975 compiling_natives_(false), | 1975 compiling_natives_(false), |
| 1976 is_loading_debugger_(false), | 1976 is_loading_debugger_(false), |
| 1977 never_unload_debugger_(false), | 1977 never_unload_debugger_(false), |
| 1978 message_handler_(NULL), | 1978 message_handler_(NULL), |
| 1979 debugger_unload_pending_(false), | 1979 debugger_unload_pending_(false), |
| 1980 host_dispatch_handler_(NULL), | 1980 host_dispatch_handler_(NULL), |
| 1981 dispatch_handler_access_(OS::CreateMutex()), | 1981 dispatch_handler_access_(OS::CreateMutex()), |
| 1982 debug_message_dispatch_handler_(NULL), | 1982 debug_message_dispatch_handler_(NULL), |
| 1983 message_dispatch_helper_thread_(NULL), | 1983 message_dispatch_helper_thread_(NULL), |
| 1984 host_dispatch_micros_(100 * 1000), | 1984 host_dispatch_micros_(100 * 1000), |
| 1985 agent_(NULL), | 1985 agent_(NULL), |
| 1986 command_queue_(kQueueInitialSize), | 1986 command_queue_(isolate->logger(), kQueueInitialSize), |
| 1987 command_received_(OS::CreateSemaphore(0)), | 1987 command_received_(OS::CreateSemaphore(0)), |
| 1988 event_command_queue_(kQueueInitialSize) { | 1988 event_command_queue_(isolate->logger(), kQueueInitialSize), |
| 1989 isolate_(isolate) { |
| 1989 } | 1990 } |
| 1990 | 1991 |
| 1991 | 1992 |
| 1992 Debugger::~Debugger() { | 1993 Debugger::~Debugger() { |
| 1993 delete debugger_access_; | 1994 delete debugger_access_; |
| 1994 debugger_access_ = 0; | 1995 debugger_access_ = 0; |
| 1995 delete dispatch_handler_access_; | 1996 delete dispatch_handler_access_; |
| 1996 dispatch_handler_access_ = 0; | 1997 dispatch_handler_access_ = 0; |
| 1997 delete command_received_; | 1998 delete command_received_; |
| 1998 command_received_ = 0; | 1999 command_received_ = 0; |
| 1999 } | 2000 } |
| 2000 | 2001 |
| 2001 | 2002 |
| 2002 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 2003 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
| 2003 int argc, Object*** argv, | 2004 int argc, Object*** argv, |
| 2004 bool* caught_exception) { | 2005 bool* caught_exception) { |
| 2005 ASSERT(Isolate::Current() == isolate_); | |
| 2006 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2006 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
| 2007 | 2007 |
| 2008 // Create the execution state object. | 2008 // Create the execution state object. |
| 2009 Handle<String> constructor_str = | 2009 Handle<String> constructor_str = |
| 2010 isolate_->factory()->LookupSymbol(constructor_name); | 2010 isolate_->factory()->LookupSymbol(constructor_name); |
| 2011 Handle<Object> constructor( | 2011 Handle<Object> constructor( |
| 2012 isolate_->global()->GetPropertyNoExceptionThrown(*constructor_str)); | 2012 isolate_->global()->GetPropertyNoExceptionThrown(*constructor_str)); |
| 2013 ASSERT(constructor->IsJSFunction()); | 2013 ASSERT(constructor->IsJSFunction()); |
| 2014 if (!constructor->IsJSFunction()) { | 2014 if (!constructor->IsJSFunction()) { |
| 2015 *caught_exception = true; | 2015 *caught_exception = true; |
| 2016 return isolate_->factory()->undefined_value(); | 2016 return isolate_->factory()->undefined_value(); |
| 2017 } | 2017 } |
| 2018 Handle<Object> js_object = Execution::TryCall( | 2018 Handle<Object> js_object = Execution::TryCall( |
| 2019 Handle<JSFunction>::cast(constructor), | 2019 Handle<JSFunction>::cast(constructor), |
| 2020 Handle<JSObject>(isolate_->debug()->debug_context()->global()), | 2020 Handle<JSObject>(isolate_->debug()->debug_context()->global()), |
| 2021 argc, argv, caught_exception); | 2021 argc, argv, caught_exception); |
| 2022 return js_object; | 2022 return js_object; |
| 2023 } | 2023 } |
| 2024 | 2024 |
| 2025 | 2025 |
| 2026 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { | 2026 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { |
| 2027 ASSERT(Isolate::Current() == isolate_); | |
| 2028 // Create the execution state object. | 2027 // Create the execution state object. |
| 2029 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( | 2028 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( |
| 2030 isolate_->debug()->break_id()); | 2029 isolate_->debug()->break_id()); |
| 2031 const int argc = 1; | 2030 const int argc = 1; |
| 2032 Object** argv[argc] = { break_id.location() }; | 2031 Object** argv[argc] = { break_id.location() }; |
| 2033 return MakeJSObject(CStrVector("MakeExecutionState"), | 2032 return MakeJSObject(CStrVector("MakeExecutionState"), |
| 2034 argc, argv, caught_exception); | 2033 argc, argv, caught_exception); |
| 2035 } | 2034 } |
| 2036 | 2035 |
| 2037 | 2036 |
| 2038 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, | 2037 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, |
| 2039 Handle<Object> break_points_hit, | 2038 Handle<Object> break_points_hit, |
| 2040 bool* caught_exception) { | 2039 bool* caught_exception) { |
| 2041 ASSERT(Isolate::Current() == isolate_); | |
| 2042 // Create the new break event object. | 2040 // Create the new break event object. |
| 2043 const int argc = 2; | 2041 const int argc = 2; |
| 2044 Object** argv[argc] = { exec_state.location(), | 2042 Object** argv[argc] = { exec_state.location(), |
| 2045 break_points_hit.location() }; | 2043 break_points_hit.location() }; |
| 2046 return MakeJSObject(CStrVector("MakeBreakEvent"), | 2044 return MakeJSObject(CStrVector("MakeBreakEvent"), |
| 2047 argc, | 2045 argc, |
| 2048 argv, | 2046 argv, |
| 2049 caught_exception); | 2047 caught_exception); |
| 2050 } | 2048 } |
| 2051 | 2049 |
| 2052 | 2050 |
| 2053 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, | 2051 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, |
| 2054 Handle<Object> exception, | 2052 Handle<Object> exception, |
| 2055 bool uncaught, | 2053 bool uncaught, |
| 2056 bool* caught_exception) { | 2054 bool* caught_exception) { |
| 2057 ASSERT(Isolate::Current() == isolate_); | |
| 2058 Factory* factory = isolate_->factory(); | 2055 Factory* factory = isolate_->factory(); |
| 2059 // Create the new exception event object. | 2056 // Create the new exception event object. |
| 2060 const int argc = 3; | 2057 const int argc = 3; |
| 2061 Object** argv[argc] = { exec_state.location(), | 2058 Object** argv[argc] = { exec_state.location(), |
| 2062 exception.location(), | 2059 exception.location(), |
| 2063 uncaught ? factory->true_value().location() : | 2060 uncaught ? factory->true_value().location() : |
| 2064 factory->false_value().location()}; | 2061 factory->false_value().location()}; |
| 2065 return MakeJSObject(CStrVector("MakeExceptionEvent"), | 2062 return MakeJSObject(CStrVector("MakeExceptionEvent"), |
| 2066 argc, argv, caught_exception); | 2063 argc, argv, caught_exception); |
| 2067 } | 2064 } |
| 2068 | 2065 |
| 2069 | 2066 |
| 2070 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, | 2067 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, |
| 2071 bool* caught_exception) { | 2068 bool* caught_exception) { |
| 2072 ASSERT(Isolate::Current() == isolate_); | |
| 2073 // Create the new function event object. | 2069 // Create the new function event object. |
| 2074 const int argc = 1; | 2070 const int argc = 1; |
| 2075 Object** argv[argc] = { function.location() }; | 2071 Object** argv[argc] = { function.location() }; |
| 2076 return MakeJSObject(CStrVector("MakeNewFunctionEvent"), | 2072 return MakeJSObject(CStrVector("MakeNewFunctionEvent"), |
| 2077 argc, argv, caught_exception); | 2073 argc, argv, caught_exception); |
| 2078 } | 2074 } |
| 2079 | 2075 |
| 2080 | 2076 |
| 2081 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, | 2077 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, |
| 2082 bool before, | 2078 bool before, |
| 2083 bool* caught_exception) { | 2079 bool* caught_exception) { |
| 2084 ASSERT(Isolate::Current() == isolate_); | |
| 2085 Factory* factory = isolate_->factory(); | 2080 Factory* factory = isolate_->factory(); |
| 2086 // Create the compile event object. | 2081 // Create the compile event object. |
| 2087 Handle<Object> exec_state = MakeExecutionState(caught_exception); | 2082 Handle<Object> exec_state = MakeExecutionState(caught_exception); |
| 2088 Handle<Object> script_wrapper = GetScriptWrapper(script); | 2083 Handle<Object> script_wrapper = GetScriptWrapper(script); |
| 2089 const int argc = 3; | 2084 const int argc = 3; |
| 2090 Object** argv[argc] = { exec_state.location(), | 2085 Object** argv[argc] = { exec_state.location(), |
| 2091 script_wrapper.location(), | 2086 script_wrapper.location(), |
| 2092 before ? factory->true_value().location() : | 2087 before ? factory->true_value().location() : |
| 2093 factory->false_value().location() }; | 2088 factory->false_value().location() }; |
| 2094 | 2089 |
| 2095 return MakeJSObject(CStrVector("MakeCompileEvent"), | 2090 return MakeJSObject(CStrVector("MakeCompileEvent"), |
| 2096 argc, | 2091 argc, |
| 2097 argv, | 2092 argv, |
| 2098 caught_exception); | 2093 caught_exception); |
| 2099 } | 2094 } |
| 2100 | 2095 |
| 2101 | 2096 |
| 2102 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, | 2097 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, |
| 2103 bool* caught_exception) { | 2098 bool* caught_exception) { |
| 2104 ASSERT(Isolate::Current() == isolate_); | |
| 2105 // Create the script collected event object. | 2099 // Create the script collected event object. |
| 2106 Handle<Object> exec_state = MakeExecutionState(caught_exception); | 2100 Handle<Object> exec_state = MakeExecutionState(caught_exception); |
| 2107 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id)); | 2101 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id)); |
| 2108 const int argc = 2; | 2102 const int argc = 2; |
| 2109 Object** argv[argc] = { exec_state.location(), id_object.location() }; | 2103 Object** argv[argc] = { exec_state.location(), id_object.location() }; |
| 2110 | 2104 |
| 2111 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), | 2105 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), |
| 2112 argc, | 2106 argc, |
| 2113 argv, | 2107 argv, |
| 2114 caught_exception); | 2108 caught_exception); |
| 2115 } | 2109 } |
| 2116 | 2110 |
| 2117 | 2111 |
| 2118 void Debugger::OnException(Handle<Object> exception, bool uncaught) { | 2112 void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
| 2119 ASSERT(Isolate::Current() == isolate_); | |
| 2120 HandleScope scope(isolate_); | 2113 HandleScope scope(isolate_); |
| 2121 Debug* debug = isolate_->debug(); | 2114 Debug* debug = isolate_->debug(); |
| 2122 | 2115 |
| 2123 // Bail out based on state or if there is no listener for this event | 2116 // Bail out based on state or if there is no listener for this event |
| 2124 if (debug->InDebugger()) return; | 2117 if (debug->InDebugger()) return; |
| 2125 if (!Debugger::EventActive(v8::Exception)) return; | 2118 if (!Debugger::EventActive(v8::Exception)) return; |
| 2126 | 2119 |
| 2127 // Bail out if exception breaks are not active | 2120 // Bail out if exception breaks are not active |
| 2128 if (uncaught) { | 2121 if (uncaught) { |
| 2129 // Uncaught exceptions are reported by either flags. | 2122 // Uncaught exceptions are reported by either flags. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2154 } | 2147 } |
| 2155 | 2148 |
| 2156 // Process debug event. | 2149 // Process debug event. |
| 2157 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); | 2150 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
| 2158 // Return to continue execution from where the exception was thrown. | 2151 // Return to continue execution from where the exception was thrown. |
| 2159 } | 2152 } |
| 2160 | 2153 |
| 2161 | 2154 |
| 2162 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, | 2155 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, |
| 2163 bool auto_continue) { | 2156 bool auto_continue) { |
| 2164 ASSERT(Isolate::Current() == isolate_); | |
| 2165 HandleScope scope(isolate_); | 2157 HandleScope scope(isolate_); |
| 2166 | 2158 |
| 2167 // Debugger has already been entered by caller. | 2159 // Debugger has already been entered by caller. |
| 2168 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2160 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
| 2169 | 2161 |
| 2170 // Bail out if there is no listener for this event | 2162 // Bail out if there is no listener for this event |
| 2171 if (!Debugger::EventActive(v8::Break)) return; | 2163 if (!Debugger::EventActive(v8::Break)) return; |
| 2172 | 2164 |
| 2173 // Debugger must be entered in advance. | 2165 // Debugger must be entered in advance. |
| 2174 ASSERT(Isolate::Current()->context() == *isolate_->debug()->debug_context()); | 2166 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
| 2175 | 2167 |
| 2176 // Create the event data object. | 2168 // Create the event data object. |
| 2177 bool caught_exception = false; | 2169 bool caught_exception = false; |
| 2178 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 2170 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 2179 Handle<Object> event_data; | 2171 Handle<Object> event_data; |
| 2180 if (!caught_exception) { | 2172 if (!caught_exception) { |
| 2181 event_data = MakeBreakEvent(exec_state, break_points_hit, | 2173 event_data = MakeBreakEvent(exec_state, break_points_hit, |
| 2182 &caught_exception); | 2174 &caught_exception); |
| 2183 } | 2175 } |
| 2184 // Bail out and don't call debugger if exception. | 2176 // Bail out and don't call debugger if exception. |
| 2185 if (caught_exception) { | 2177 if (caught_exception) { |
| 2186 return; | 2178 return; |
| 2187 } | 2179 } |
| 2188 | 2180 |
| 2189 // Process debug event. | 2181 // Process debug event. |
| 2190 ProcessDebugEvent(v8::Break, | 2182 ProcessDebugEvent(v8::Break, |
| 2191 Handle<JSObject>::cast(event_data), | 2183 Handle<JSObject>::cast(event_data), |
| 2192 auto_continue); | 2184 auto_continue); |
| 2193 } | 2185 } |
| 2194 | 2186 |
| 2195 | 2187 |
| 2196 void Debugger::OnBeforeCompile(Handle<Script> script) { | 2188 void Debugger::OnBeforeCompile(Handle<Script> script) { |
| 2197 ASSERT(Isolate::Current() == isolate_); | |
| 2198 HandleScope scope(isolate_); | 2189 HandleScope scope(isolate_); |
| 2199 | 2190 |
| 2200 // Bail out based on state or if there is no listener for this event | 2191 // Bail out based on state or if there is no listener for this event |
| 2201 if (isolate_->debug()->InDebugger()) return; | 2192 if (isolate_->debug()->InDebugger()) return; |
| 2202 if (compiling_natives()) return; | 2193 if (compiling_natives()) return; |
| 2203 if (!EventActive(v8::BeforeCompile)) return; | 2194 if (!EventActive(v8::BeforeCompile)) return; |
| 2204 | 2195 |
| 2205 // Enter the debugger. | 2196 // Enter the debugger. |
| 2206 EnterDebugger debugger; | 2197 EnterDebugger debugger; |
| 2207 if (debugger.FailedToEnter()) return; | 2198 if (debugger.FailedToEnter()) return; |
| 2208 | 2199 |
| 2209 // Create the event data object. | 2200 // Create the event data object. |
| 2210 bool caught_exception = false; | 2201 bool caught_exception = false; |
| 2211 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); | 2202 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); |
| 2212 // Bail out and don't call debugger if exception. | 2203 // Bail out and don't call debugger if exception. |
| 2213 if (caught_exception) { | 2204 if (caught_exception) { |
| 2214 return; | 2205 return; |
| 2215 } | 2206 } |
| 2216 | 2207 |
| 2217 // Process debug event. | 2208 // Process debug event. |
| 2218 ProcessDebugEvent(v8::BeforeCompile, | 2209 ProcessDebugEvent(v8::BeforeCompile, |
| 2219 Handle<JSObject>::cast(event_data), | 2210 Handle<JSObject>::cast(event_data), |
| 2220 true); | 2211 true); |
| 2221 } | 2212 } |
| 2222 | 2213 |
| 2223 | 2214 |
| 2224 // Handle debugger actions when a new script is compiled. | 2215 // Handle debugger actions when a new script is compiled. |
| 2225 void Debugger::OnAfterCompile(Handle<Script> script, | 2216 void Debugger::OnAfterCompile(Handle<Script> script, |
| 2226 AfterCompileFlags after_compile_flags) { | 2217 AfterCompileFlags after_compile_flags) { |
| 2227 ASSERT(Isolate::Current() == isolate_); | |
| 2228 HandleScope scope(isolate_); | 2218 HandleScope scope(isolate_); |
| 2229 Debug* debug = isolate_->debug(); | 2219 Debug* debug = isolate_->debug(); |
| 2230 | 2220 |
| 2231 // Add the newly compiled script to the script cache. | 2221 // Add the newly compiled script to the script cache. |
| 2232 debug->AddScriptToScriptCache(script); | 2222 debug->AddScriptToScriptCache(script); |
| 2233 | 2223 |
| 2234 // No more to do if not debugging. | 2224 // No more to do if not debugging. |
| 2235 if (!IsDebuggerActive()) return; | 2225 if (!IsDebuggerActive()) return; |
| 2236 | 2226 |
| 2237 // No compile events while compiling natives. | 2227 // No compile events while compiling natives. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2286 return; | 2276 return; |
| 2287 } | 2277 } |
| 2288 // Process debug event. | 2278 // Process debug event. |
| 2289 ProcessDebugEvent(v8::AfterCompile, | 2279 ProcessDebugEvent(v8::AfterCompile, |
| 2290 Handle<JSObject>::cast(event_data), | 2280 Handle<JSObject>::cast(event_data), |
| 2291 true); | 2281 true); |
| 2292 } | 2282 } |
| 2293 | 2283 |
| 2294 | 2284 |
| 2295 void Debugger::OnScriptCollected(int id) { | 2285 void Debugger::OnScriptCollected(int id) { |
| 2296 ASSERT(Isolate::Current() == isolate_); | |
| 2297 HandleScope scope(isolate_); | 2286 HandleScope scope(isolate_); |
| 2298 | 2287 |
| 2299 // No more to do if not debugging. | 2288 // No more to do if not debugging. |
| 2300 if (!IsDebuggerActive()) return; | 2289 if (!IsDebuggerActive()) return; |
| 2301 if (!Debugger::EventActive(v8::ScriptCollected)) return; | 2290 if (!Debugger::EventActive(v8::ScriptCollected)) return; |
| 2302 | 2291 |
| 2303 // Enter the debugger. | 2292 // Enter the debugger. |
| 2304 EnterDebugger debugger; | 2293 EnterDebugger debugger; |
| 2305 if (debugger.FailedToEnter()) return; | 2294 if (debugger.FailedToEnter()) return; |
| 2306 | 2295 |
| 2307 // Create the script collected state object. | 2296 // Create the script collected state object. |
| 2308 bool caught_exception = false; | 2297 bool caught_exception = false; |
| 2309 Handle<Object> event_data = MakeScriptCollectedEvent(id, | 2298 Handle<Object> event_data = MakeScriptCollectedEvent(id, |
| 2310 &caught_exception); | 2299 &caught_exception); |
| 2311 // Bail out and don't call debugger if exception. | 2300 // Bail out and don't call debugger if exception. |
| 2312 if (caught_exception) { | 2301 if (caught_exception) { |
| 2313 return; | 2302 return; |
| 2314 } | 2303 } |
| 2315 | 2304 |
| 2316 // Process debug event. | 2305 // Process debug event. |
| 2317 ProcessDebugEvent(v8::ScriptCollected, | 2306 ProcessDebugEvent(v8::ScriptCollected, |
| 2318 Handle<JSObject>::cast(event_data), | 2307 Handle<JSObject>::cast(event_data), |
| 2319 true); | 2308 true); |
| 2320 } | 2309 } |
| 2321 | 2310 |
| 2322 | 2311 |
| 2323 void Debugger::ProcessDebugEvent(v8::DebugEvent event, | 2312 void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
| 2324 Handle<JSObject> event_data, | 2313 Handle<JSObject> event_data, |
| 2325 bool auto_continue) { | 2314 bool auto_continue) { |
| 2326 ASSERT(Isolate::Current() == isolate_); | |
| 2327 HandleScope scope(isolate_); | 2315 HandleScope scope(isolate_); |
| 2328 | 2316 |
| 2329 // Clear any pending debug break if this is a real break. | 2317 // Clear any pending debug break if this is a real break. |
| 2330 if (!auto_continue) { | 2318 if (!auto_continue) { |
| 2331 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); | 2319 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); |
| 2332 } | 2320 } |
| 2333 | 2321 |
| 2334 // Create the execution state. | 2322 // Create the execution state. |
| 2335 bool caught_exception = false; | 2323 bool caught_exception = false; |
| 2336 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 2324 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 event_listener_data_, | 2380 event_listener_data_, |
| 2393 client_data); | 2381 client_data); |
| 2394 callback(event_details); | 2382 callback(event_details); |
| 2395 } | 2383 } |
| 2396 | 2384 |
| 2397 | 2385 |
| 2398 void Debugger::CallJSEventCallback(v8::DebugEvent event, | 2386 void Debugger::CallJSEventCallback(v8::DebugEvent event, |
| 2399 Handle<Object> exec_state, | 2387 Handle<Object> exec_state, |
| 2400 Handle<Object> event_data) { | 2388 Handle<Object> event_data) { |
| 2401 ASSERT(event_listener_->IsJSFunction()); | 2389 ASSERT(event_listener_->IsJSFunction()); |
| 2402 ASSERT(Isolate::Current() == isolate_); | |
| 2403 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); | 2390 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); |
| 2404 | 2391 |
| 2405 // Invoke the JavaScript debug event listener. | 2392 // Invoke the JavaScript debug event listener. |
| 2406 const int argc = 4; | 2393 const int argc = 4; |
| 2407 Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(), | 2394 Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(), |
| 2408 exec_state.location(), | 2395 exec_state.location(), |
| 2409 Handle<Object>::cast(event_data).location(), | 2396 Handle<Object>::cast(event_data).location(), |
| 2410 event_listener_data_.location() }; | 2397 event_listener_data_.location() }; |
| 2411 bool caught_exception = false; | 2398 bool caught_exception = false; |
| 2412 Execution::TryCall(fun, isolate_->global(), argc, argv, &caught_exception); | 2399 Execution::TryCall(fun, isolate_->global(), argc, argv, &caught_exception); |
| 2413 // Silently ignore exceptions from debug event listeners. | 2400 // Silently ignore exceptions from debug event listeners. |
| 2414 } | 2401 } |
| 2415 | 2402 |
| 2416 | 2403 |
| 2417 Handle<Context> Debugger::GetDebugContext() { | 2404 Handle<Context> Debugger::GetDebugContext() { |
| 2418 ASSERT(Isolate::Current() == isolate_); | |
| 2419 never_unload_debugger_ = true; | 2405 never_unload_debugger_ = true; |
| 2420 EnterDebugger debugger; | 2406 EnterDebugger debugger; |
| 2421 return isolate_->debug()->debug_context(); | 2407 return isolate_->debug()->debug_context(); |
| 2422 } | 2408 } |
| 2423 | 2409 |
| 2424 | 2410 |
| 2425 void Debugger::UnloadDebugger() { | 2411 void Debugger::UnloadDebugger() { |
| 2426 ASSERT(Isolate::Current() == isolate_); | |
| 2427 Debug* debug = isolate_->debug(); | 2412 Debug* debug = isolate_->debug(); |
| 2428 | 2413 |
| 2429 // Make sure that there are no breakpoints left. | 2414 // Make sure that there are no breakpoints left. |
| 2430 debug->ClearAllBreakPoints(); | 2415 debug->ClearAllBreakPoints(); |
| 2431 | 2416 |
| 2432 // Unload the debugger if feasible. | 2417 // Unload the debugger if feasible. |
| 2433 if (!never_unload_debugger_) { | 2418 if (!never_unload_debugger_) { |
| 2434 debug->Unload(); | 2419 debug->Unload(); |
| 2435 } | 2420 } |
| 2436 | 2421 |
| 2437 // Clear the flag indicating that the debugger should be unloaded. | 2422 // Clear the flag indicating that the debugger should be unloaded. |
| 2438 debugger_unload_pending_ = false; | 2423 debugger_unload_pending_ = false; |
| 2439 } | 2424 } |
| 2440 | 2425 |
| 2441 | 2426 |
| 2442 void Debugger::NotifyMessageHandler(v8::DebugEvent event, | 2427 void Debugger::NotifyMessageHandler(v8::DebugEvent event, |
| 2443 Handle<JSObject> exec_state, | 2428 Handle<JSObject> exec_state, |
| 2444 Handle<JSObject> event_data, | 2429 Handle<JSObject> event_data, |
| 2445 bool auto_continue) { | 2430 bool auto_continue) { |
| 2446 ASSERT(Isolate::Current() == isolate_); | |
| 2447 HandleScope scope(isolate_); | 2431 HandleScope scope(isolate_); |
| 2448 | 2432 |
| 2449 if (!isolate_->debug()->Load()) return; | 2433 if (!isolate_->debug()->Load()) return; |
| 2450 | 2434 |
| 2451 // Process the individual events. | 2435 // Process the individual events. |
| 2452 bool sendEventMessage = false; | 2436 bool sendEventMessage = false; |
| 2453 switch (event) { | 2437 switch (event) { |
| 2454 case v8::Break: | 2438 case v8::Break: |
| 2455 case v8::BreakForCommand: | 2439 case v8::BreakForCommand: |
| 2456 sendEventMessage = !auto_continue; | 2440 sendEventMessage = !auto_continue; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2532 Debugger::host_dispatch_handler_(); | 2516 Debugger::host_dispatch_handler_(); |
| 2533 continue; | 2517 continue; |
| 2534 } | 2518 } |
| 2535 } else { | 2519 } else { |
| 2536 // In case there is no host dispatch - just wait. | 2520 // In case there is no host dispatch - just wait. |
| 2537 command_received_->Wait(); | 2521 command_received_->Wait(); |
| 2538 } | 2522 } |
| 2539 | 2523 |
| 2540 // Get the command from the queue. | 2524 // Get the command from the queue. |
| 2541 CommandMessage command = command_queue_.Get(); | 2525 CommandMessage command = command_queue_.Get(); |
| 2542 LOGGER->DebugTag("Got request from command queue, in interactive loop."); | 2526 isolate_->logger()->DebugTag( |
| 2527 "Got request from command queue, in interactive loop."); |
| 2543 if (!Debugger::IsDebuggerActive()) { | 2528 if (!Debugger::IsDebuggerActive()) { |
| 2544 // Delete command text and user data. | 2529 // Delete command text and user data. |
| 2545 command.Dispose(); | 2530 command.Dispose(); |
| 2546 return; | 2531 return; |
| 2547 } | 2532 } |
| 2548 | 2533 |
| 2549 // Invoke JavaScript to process the debug request. | 2534 // Invoke JavaScript to process the debug request. |
| 2550 v8::Local<v8::String> fun_name; | 2535 v8::Local<v8::String> fun_name; |
| 2551 v8::Local<v8::Function> fun; | 2536 v8::Local<v8::Function> fun; |
| 2552 v8::Local<v8::Value> request; | 2537 v8::Local<v8::Value> request; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 // and there are no more commands queued. | 2591 // and there are no more commands queued. |
| 2607 if (running && !HasCommands()) { | 2592 if (running && !HasCommands()) { |
| 2608 return; | 2593 return; |
| 2609 } | 2594 } |
| 2610 } | 2595 } |
| 2611 } | 2596 } |
| 2612 | 2597 |
| 2613 | 2598 |
| 2614 void Debugger::SetEventListener(Handle<Object> callback, | 2599 void Debugger::SetEventListener(Handle<Object> callback, |
| 2615 Handle<Object> data) { | 2600 Handle<Object> data) { |
| 2616 ASSERT(Isolate::Current() == isolate_); | |
| 2617 HandleScope scope(isolate_); | 2601 HandleScope scope(isolate_); |
| 2618 GlobalHandles* global_handles = isolate_->global_handles(); | 2602 GlobalHandles* global_handles = isolate_->global_handles(); |
| 2619 | 2603 |
| 2620 // Clear the global handles for the event listener and the event listener data | 2604 // Clear the global handles for the event listener and the event listener data |
| 2621 // object. | 2605 // object. |
| 2622 if (!event_listener_.is_null()) { | 2606 if (!event_listener_.is_null()) { |
| 2623 global_handles->Destroy( | 2607 global_handles->Destroy( |
| 2624 reinterpret_cast<Object**>(event_listener_.location())); | 2608 reinterpret_cast<Object**>(event_listener_.location())); |
| 2625 event_listener_ = Handle<Object>(); | 2609 event_listener_ = Handle<Object>(); |
| 2626 } | 2610 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2640 } | 2624 } |
| 2641 event_listener_data_ = Handle<Object>::cast( | 2625 event_listener_data_ = Handle<Object>::cast( |
| 2642 global_handles->Create(*data)); | 2626 global_handles->Create(*data)); |
| 2643 } | 2627 } |
| 2644 | 2628 |
| 2645 ListenersChanged(); | 2629 ListenersChanged(); |
| 2646 } | 2630 } |
| 2647 | 2631 |
| 2648 | 2632 |
| 2649 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { | 2633 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { |
| 2650 ASSERT(Isolate::Current() == isolate_); | |
| 2651 ScopedLock with(debugger_access_); | 2634 ScopedLock with(debugger_access_); |
| 2652 | 2635 |
| 2653 message_handler_ = handler; | 2636 message_handler_ = handler; |
| 2654 ListenersChanged(); | 2637 ListenersChanged(); |
| 2655 if (handler == NULL) { | 2638 if (handler == NULL) { |
| 2656 // Send an empty command to the debugger if in a break to make JavaScript | 2639 // Send an empty command to the debugger if in a break to make JavaScript |
| 2657 // run again if the debugger is closed. | 2640 // run again if the debugger is closed. |
| 2658 if (isolate_->debug()->InDebugger()) { | 2641 if (isolate_->debug()->InDebugger()) { |
| 2659 ProcessCommand(Vector<const uint16_t>::empty()); | 2642 ProcessCommand(Vector<const uint16_t>::empty()); |
| 2660 } | 2643 } |
| 2661 } | 2644 } |
| 2662 } | 2645 } |
| 2663 | 2646 |
| 2664 | 2647 |
| 2665 void Debugger::ListenersChanged() { | 2648 void Debugger::ListenersChanged() { |
| 2666 ASSERT(Isolate::Current() == isolate_); | |
| 2667 if (IsDebuggerActive()) { | 2649 if (IsDebuggerActive()) { |
| 2668 // Disable the compilation cache when the debugger is active. | 2650 // Disable the compilation cache when the debugger is active. |
| 2669 isolate_->compilation_cache()->Disable(); | 2651 isolate_->compilation_cache()->Disable(); |
| 2670 debugger_unload_pending_ = false; | 2652 debugger_unload_pending_ = false; |
| 2671 } else { | 2653 } else { |
| 2672 isolate_->compilation_cache()->Enable(); | 2654 isolate_->compilation_cache()->Enable(); |
| 2673 // Unload the debugger if event listener and message handler cleared. | 2655 // Unload the debugger if event listener and message handler cleared. |
| 2674 // Schedule this for later, because we may be in non-V8 thread. | 2656 // Schedule this for later, because we may be in non-V8 thread. |
| 2675 debugger_unload_pending_ = true; | 2657 debugger_unload_pending_ = true; |
| 2676 } | 2658 } |
| 2677 } | 2659 } |
| 2678 | 2660 |
| 2679 | 2661 |
| 2680 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 2662 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
| 2681 int period) { | 2663 int period) { |
| 2682 ASSERT(Isolate::Current() == isolate_); | |
| 2683 host_dispatch_handler_ = handler; | 2664 host_dispatch_handler_ = handler; |
| 2684 host_dispatch_micros_ = period * 1000; | 2665 host_dispatch_micros_ = period * 1000; |
| 2685 } | 2666 } |
| 2686 | 2667 |
| 2687 | 2668 |
| 2688 void Debugger::SetDebugMessageDispatchHandler( | 2669 void Debugger::SetDebugMessageDispatchHandler( |
| 2689 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { | 2670 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { |
| 2690 ASSERT(Isolate::Current() == isolate_); | |
| 2691 ScopedLock with(dispatch_handler_access_); | 2671 ScopedLock with(dispatch_handler_access_); |
| 2692 debug_message_dispatch_handler_ = handler; | 2672 debug_message_dispatch_handler_ = handler; |
| 2693 | 2673 |
| 2694 if (provide_locker && message_dispatch_helper_thread_ == NULL) { | 2674 if (provide_locker && message_dispatch_helper_thread_ == NULL) { |
| 2695 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); | 2675 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); |
| 2696 message_dispatch_helper_thread_->Start(); | 2676 message_dispatch_helper_thread_->Start(); |
| 2697 } | 2677 } |
| 2698 } | 2678 } |
| 2699 | 2679 |
| 2700 | 2680 |
| 2701 // Calls the registered debug message handler. This callback is part of the | 2681 // Calls the registered debug message handler. This callback is part of the |
| 2702 // public API. | 2682 // public API. |
| 2703 void Debugger::InvokeMessageHandler(MessageImpl message) { | 2683 void Debugger::InvokeMessageHandler(MessageImpl message) { |
| 2704 ASSERT(Isolate::Current() == isolate_); | |
| 2705 ScopedLock with(debugger_access_); | 2684 ScopedLock with(debugger_access_); |
| 2706 | 2685 |
| 2707 if (message_handler_ != NULL) { | 2686 if (message_handler_ != NULL) { |
| 2708 message_handler_(message); | 2687 message_handler_(message); |
| 2709 } | 2688 } |
| 2710 } | 2689 } |
| 2711 | 2690 |
| 2712 | 2691 |
| 2713 // Puts a command coming from the public API on the queue. Creates | 2692 // Puts a command coming from the public API on the queue. Creates |
| 2714 // a copy of the command string managed by the debugger. Up to this | 2693 // a copy of the command string managed by the debugger. Up to this |
| 2715 // point, the command data was managed by the API client. Called | 2694 // point, the command data was managed by the API client. Called |
| 2716 // by the API client thread. | 2695 // by the API client thread. |
| 2717 void Debugger::ProcessCommand(Vector<const uint16_t> command, | 2696 void Debugger::ProcessCommand(Vector<const uint16_t> command, |
| 2718 v8::Debug::ClientData* client_data) { | 2697 v8::Debug::ClientData* client_data) { |
| 2719 ASSERT(Isolate::Current() == isolate_); | |
| 2720 // Need to cast away const. | 2698 // Need to cast away const. |
| 2721 CommandMessage message = CommandMessage::New( | 2699 CommandMessage message = CommandMessage::New( |
| 2722 Vector<uint16_t>(const_cast<uint16_t*>(command.start()), | 2700 Vector<uint16_t>(const_cast<uint16_t*>(command.start()), |
| 2723 command.length()), | 2701 command.length()), |
| 2724 client_data); | 2702 client_data); |
| 2725 LOGGER->DebugTag("Put command on command_queue."); | 2703 isolate_->logger()->DebugTag("Put command on command_queue."); |
| 2726 command_queue_.Put(message); | 2704 command_queue_.Put(message); |
| 2727 command_received_->Signal(); | 2705 command_received_->Signal(); |
| 2728 | 2706 |
| 2729 // Set the debug command break flag to have the command processed. | 2707 // Set the debug command break flag to have the command processed. |
| 2730 if (!isolate_->debug()->InDebugger()) { | 2708 if (!isolate_->debug()->InDebugger()) { |
| 2731 isolate_->stack_guard()->DebugCommand(); | 2709 isolate_->stack_guard()->DebugCommand(); |
| 2732 } | 2710 } |
| 2733 | 2711 |
| 2734 MessageDispatchHelperThread* dispatch_thread; | 2712 MessageDispatchHelperThread* dispatch_thread; |
| 2735 { | 2713 { |
| 2736 ScopedLock with(dispatch_handler_access_); | 2714 ScopedLock with(dispatch_handler_access_); |
| 2737 dispatch_thread = message_dispatch_helper_thread_; | 2715 dispatch_thread = message_dispatch_helper_thread_; |
| 2738 } | 2716 } |
| 2739 | 2717 |
| 2740 if (dispatch_thread == NULL) { | 2718 if (dispatch_thread == NULL) { |
| 2741 CallMessageDispatchHandler(); | 2719 CallMessageDispatchHandler(); |
| 2742 } else { | 2720 } else { |
| 2743 dispatch_thread->Schedule(); | 2721 dispatch_thread->Schedule(); |
| 2744 } | 2722 } |
| 2745 } | 2723 } |
| 2746 | 2724 |
| 2747 | 2725 |
| 2748 bool Debugger::HasCommands() { | 2726 bool Debugger::HasCommands() { |
| 2749 ASSERT(Isolate::Current() == isolate_); | |
| 2750 return !command_queue_.IsEmpty(); | 2727 return !command_queue_.IsEmpty(); |
| 2751 } | 2728 } |
| 2752 | 2729 |
| 2753 | 2730 |
| 2754 void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { | 2731 void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { |
| 2755 ASSERT(Isolate::Current() == isolate_); | |
| 2756 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); | 2732 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); |
| 2757 event_command_queue_.Put(message); | 2733 event_command_queue_.Put(message); |
| 2758 | 2734 |
| 2759 // Set the debug command break flag to have the command processed. | 2735 // Set the debug command break flag to have the command processed. |
| 2760 if (!isolate_->debug()->InDebugger()) { | 2736 if (!isolate_->debug()->InDebugger()) { |
| 2761 isolate_->stack_guard()->DebugCommand(); | 2737 isolate_->stack_guard()->DebugCommand(); |
| 2762 } | 2738 } |
| 2763 } | 2739 } |
| 2764 | 2740 |
| 2765 | 2741 |
| 2766 bool Debugger::IsDebuggerActive() { | 2742 bool Debugger::IsDebuggerActive() { |
| 2767 ASSERT(Isolate::Current() == isolate_); | |
| 2768 ScopedLock with(debugger_access_); | 2743 ScopedLock with(debugger_access_); |
| 2769 | 2744 |
| 2770 return message_handler_ != NULL || !event_listener_.is_null(); | 2745 return message_handler_ != NULL || !event_listener_.is_null(); |
| 2771 } | 2746 } |
| 2772 | 2747 |
| 2773 | 2748 |
| 2774 Handle<Object> Debugger::Call(Handle<JSFunction> fun, | 2749 Handle<Object> Debugger::Call(Handle<JSFunction> fun, |
| 2775 Handle<Object> data, | 2750 Handle<Object> data, |
| 2776 bool* pending_exception) { | 2751 bool* pending_exception) { |
| 2777 ASSERT(Isolate::Current() == isolate_); | |
| 2778 // When calling functions in the debugger prevent it from beeing unloaded. | 2752 // When calling functions in the debugger prevent it from beeing unloaded. |
| 2779 Debugger::never_unload_debugger_ = true; | 2753 Debugger::never_unload_debugger_ = true; |
| 2780 | 2754 |
| 2781 // Enter the debugger. | 2755 // Enter the debugger. |
| 2782 EnterDebugger debugger; | 2756 EnterDebugger debugger; |
| 2783 if (debugger.FailedToEnter()) { | 2757 if (debugger.FailedToEnter()) { |
| 2784 return isolate_->factory()->undefined_value(); | 2758 return isolate_->factory()->undefined_value(); |
| 2785 } | 2759 } |
| 2786 | 2760 |
| 2787 // Create the execution state. | 2761 // Create the execution state. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2817 // Provide stub message handler; V8 auto-continues each suspend | 2791 // Provide stub message handler; V8 auto-continues each suspend |
| 2818 // when there is no message handler; we doesn't need it. | 2792 // when there is no message handler; we doesn't need it. |
| 2819 // Once become suspended, V8 will stay so indefinitely long, until remote | 2793 // Once become suspended, V8 will stay so indefinitely long, until remote |
| 2820 // debugger connects and issues "continue" command. | 2794 // debugger connects and issues "continue" command. |
| 2821 Debugger::message_handler_ = StubMessageHandler2; | 2795 Debugger::message_handler_ = StubMessageHandler2; |
| 2822 v8::Debug::DebugBreak(); | 2796 v8::Debug::DebugBreak(); |
| 2823 } | 2797 } |
| 2824 | 2798 |
| 2825 if (Socket::Setup()) { | 2799 if (Socket::Setup()) { |
| 2826 if (agent_ == NULL) { | 2800 if (agent_ == NULL) { |
| 2827 agent_ = new DebuggerAgent(isolate_, name, port); | 2801 agent_ = new DebuggerAgent(name, port); |
| 2828 agent_->Start(); | 2802 agent_->Start(); |
| 2829 } | 2803 } |
| 2830 return true; | 2804 return true; |
| 2831 } | 2805 } |
| 2832 | 2806 |
| 2833 return false; | 2807 return false; |
| 2834 } | 2808 } |
| 2835 | 2809 |
| 2836 | 2810 |
| 2837 void Debugger::StopAgent() { | 2811 void Debugger::StopAgent() { |
| 2838 ASSERT(Isolate::Current() == isolate_); | 2812 ASSERT(Isolate::Current() == isolate_); |
| 2839 if (agent_ != NULL) { | 2813 if (agent_ != NULL) { |
| 2840 agent_->Shutdown(); | 2814 agent_->Shutdown(); |
| 2841 agent_->Join(); | 2815 agent_->Join(); |
| 2842 delete agent_; | 2816 delete agent_; |
| 2843 agent_ = NULL; | 2817 agent_ = NULL; |
| 2844 } | 2818 } |
| 2845 } | 2819 } |
| 2846 | 2820 |
| 2847 | 2821 |
| 2848 void Debugger::WaitForAgent() { | 2822 void Debugger::WaitForAgent() { |
| 2849 ASSERT(Isolate::Current() == isolate_); | 2823 ASSERT(Isolate::Current() == isolate_); |
| 2850 if (agent_ != NULL) | 2824 if (agent_ != NULL) |
| 2851 agent_->WaitUntilListening(); | 2825 agent_->WaitUntilListening(); |
| 2852 } | 2826 } |
| 2853 | 2827 |
| 2854 | 2828 |
| 2855 void Debugger::CallMessageDispatchHandler() { | 2829 void Debugger::CallMessageDispatchHandler() { |
| 2856 ASSERT(Isolate::Current() == isolate_); | |
| 2857 v8::Debug::DebugMessageDispatchHandler handler; | 2830 v8::Debug::DebugMessageDispatchHandler handler; |
| 2858 { | 2831 { |
| 2859 ScopedLock with(dispatch_handler_access_); | 2832 ScopedLock with(dispatch_handler_access_); |
| 2860 handler = Debugger::debug_message_dispatch_handler_; | 2833 handler = Debugger::debug_message_dispatch_handler_; |
| 2861 } | 2834 } |
| 2862 if (handler != NULL) { | 2835 if (handler != NULL) { |
| 2863 handler(); | 2836 handler(); |
| 2864 } | 2837 } |
| 2865 } | 2838 } |
| 2866 | 2839 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3080 } | 3053 } |
| 3081 CommandMessage* array_to_free = messages_; | 3054 CommandMessage* array_to_free = messages_; |
| 3082 *this = new_queue; | 3055 *this = new_queue; |
| 3083 new_queue.messages_ = array_to_free; | 3056 new_queue.messages_ = array_to_free; |
| 3084 // Make the new_queue empty so that it doesn't call Dispose on any messages. | 3057 // Make the new_queue empty so that it doesn't call Dispose on any messages. |
| 3085 new_queue.start_ = new_queue.end_; | 3058 new_queue.start_ = new_queue.end_; |
| 3086 // Automatic destructor called on new_queue, freeing array_to_free. | 3059 // Automatic destructor called on new_queue, freeing array_to_free. |
| 3087 } | 3060 } |
| 3088 | 3061 |
| 3089 | 3062 |
| 3090 LockingCommandMessageQueue::LockingCommandMessageQueue(int size) | 3063 LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size) |
| 3091 : queue_(size) { | 3064 : logger_(logger), queue_(size) { |
| 3092 lock_ = OS::CreateMutex(); | 3065 lock_ = OS::CreateMutex(); |
| 3093 } | 3066 } |
| 3094 | 3067 |
| 3095 | 3068 |
| 3096 LockingCommandMessageQueue::~LockingCommandMessageQueue() { | 3069 LockingCommandMessageQueue::~LockingCommandMessageQueue() { |
| 3097 delete lock_; | 3070 delete lock_; |
| 3098 } | 3071 } |
| 3099 | 3072 |
| 3100 | 3073 |
| 3101 bool LockingCommandMessageQueue::IsEmpty() const { | 3074 bool LockingCommandMessageQueue::IsEmpty() const { |
| 3102 ScopedLock sl(lock_); | 3075 ScopedLock sl(lock_); |
| 3103 return queue_.IsEmpty(); | 3076 return queue_.IsEmpty(); |
| 3104 } | 3077 } |
| 3105 | 3078 |
| 3106 | 3079 |
| 3107 CommandMessage LockingCommandMessageQueue::Get() { | 3080 CommandMessage LockingCommandMessageQueue::Get() { |
| 3108 ScopedLock sl(lock_); | 3081 ScopedLock sl(lock_); |
| 3109 CommandMessage result = queue_.Get(); | 3082 CommandMessage result = queue_.Get(); |
| 3110 LOGGER->DebugEvent("Get", result.text()); | 3083 logger_->DebugEvent("Get", result.text()); |
| 3111 return result; | 3084 return result; |
| 3112 } | 3085 } |
| 3113 | 3086 |
| 3114 | 3087 |
| 3115 void LockingCommandMessageQueue::Put(const CommandMessage& message) { | 3088 void LockingCommandMessageQueue::Put(const CommandMessage& message) { |
| 3116 ScopedLock sl(lock_); | 3089 ScopedLock sl(lock_); |
| 3117 queue_.Put(message); | 3090 queue_.Put(message); |
| 3118 LOGGER->DebugEvent("Put", message.text()); | 3091 logger_->DebugEvent("Put", message.text()); |
| 3119 } | 3092 } |
| 3120 | 3093 |
| 3121 | 3094 |
| 3122 void LockingCommandMessageQueue::Clear() { | 3095 void LockingCommandMessageQueue::Clear() { |
| 3123 ScopedLock sl(lock_); | 3096 ScopedLock sl(lock_); |
| 3124 queue_.Clear(); | 3097 queue_.Clear(); |
| 3125 } | 3098 } |
| 3126 | 3099 |
| 3127 | 3100 |
| 3128 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) | 3101 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) |
| 3129 : Thread(isolate, "v8:MsgDispHelpr"), | 3102 : Thread("v8:MsgDispHelpr"), |
| 3130 sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()), | 3103 sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()), |
| 3131 already_signalled_(false) { | 3104 already_signalled_(false) { |
| 3132 } | 3105 } |
| 3133 | 3106 |
| 3134 | 3107 |
| 3135 MessageDispatchHelperThread::~MessageDispatchHelperThread() { | 3108 MessageDispatchHelperThread::~MessageDispatchHelperThread() { |
| 3136 delete mutex_; | 3109 delete mutex_; |
| 3137 delete sem_; | 3110 delete sem_; |
| 3138 } | 3111 } |
| 3139 | 3112 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3160 { | 3133 { |
| 3161 Locker locker; | 3134 Locker locker; |
| 3162 Isolate::Current()->debugger()->CallMessageDispatchHandler(); | 3135 Isolate::Current()->debugger()->CallMessageDispatchHandler(); |
| 3163 } | 3136 } |
| 3164 } | 3137 } |
| 3165 } | 3138 } |
| 3166 | 3139 |
| 3167 #endif // ENABLE_DEBUGGER_SUPPORT | 3140 #endif // ENABLE_DEBUGGER_SUPPORT |
| 3168 | 3141 |
| 3169 } } // namespace v8::internal | 3142 } } // namespace v8::internal |
| OLD | NEW |