OLD | NEW |
---|---|
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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1867 async_task_listener_ = listener; | 1867 async_task_listener_ = listener; |
1868 async_task_listener_data_ = data; | 1868 async_task_listener_data_ = data; |
1869 UpdateState(); | 1869 UpdateState(); |
1870 } | 1870 } |
1871 | 1871 |
1872 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) { | 1872 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) { |
1873 if (in_debug_scope() || ignore_events()) return; | 1873 if (in_debug_scope() || ignore_events()) return; |
1874 | 1874 |
1875 if (async_task_listener_) { | 1875 if (async_task_listener_) { |
1876 async_task_listener_(type, id, async_task_listener_data_); | 1876 async_task_listener_(type, id, async_task_listener_data_); |
1877 // There are three types of event listeners: C++ message_handler, | 1877 if (!non_inspector_listener_exists()) return; |
1878 // JavaScript event listener and C++ event listener. | |
1879 // Currently inspector still uses C++ event listener and installs | |
1880 // more specific event listeners for part of events. Calling of | |
1881 // C++ event listener is redundant when more specific event listener | |
1882 // is presented. Other clients can install JavaScript event listener | |
1883 // (e.g. some of NodeJS module). | |
1884 bool non_inspector_listener_exists = | |
1885 message_handler_ != nullptr || | |
1886 (event_listener_.is_null() && !event_listener_->IsForeign()); | |
1887 if (!non_inspector_listener_exists) return; | |
1888 } | 1878 } |
1889 | 1879 |
1890 HandleScope scope(isolate_); | 1880 HandleScope scope(isolate_); |
1891 DebugScope debug_scope(this); | 1881 DebugScope debug_scope(this); |
1892 if (debug_scope.failed()) return; | 1882 if (debug_scope.failed()) return; |
1893 | 1883 |
1894 // Create the script collected state object. | 1884 // Create the script collected state object. |
1895 Handle<Object> event_data; | 1885 Handle<Object> event_data; |
1896 // Bail out and don't call debugger if exception. | 1886 // Bail out and don't call debugger if exception. |
1897 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), | 1887 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1956 event_listener_data_ }; | 1946 event_listener_data_ }; |
1957 Handle<JSReceiver> global = isolate_->global_proxy(); | 1947 Handle<JSReceiver> global = isolate_->global_proxy(); |
1958 MaybeHandle<Object> result = | 1948 MaybeHandle<Object> result = |
1959 Execution::Call(isolate_, Handle<JSFunction>::cast(event_listener_), | 1949 Execution::Call(isolate_, Handle<JSFunction>::cast(event_listener_), |
1960 global, arraysize(argv), argv); | 1950 global, arraysize(argv), argv); |
1961 CHECK(!result.is_null()); // Listeners must not throw. | 1951 CHECK(!result.is_null()); // Listeners must not throw. |
1962 } | 1952 } |
1963 in_debug_event_listener_ = previous; | 1953 in_debug_event_listener_ = previous; |
1964 } | 1954 } |
1965 | 1955 |
1956 void Debug::SetCompileEventListener(debug::CompileEventListener listener, | |
1957 void* data) { | |
1958 compile_event_listener_ = listener; | |
1959 compile_event_listener_data_ = data; | |
1960 UpdateState(); | |
1961 } | |
1966 | 1962 |
1967 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { | 1963 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { |
1968 if (ignore_events()) return; | 1964 if (ignore_events()) return; |
1969 if (script->type() != i::Script::TYPE_NORMAL && | 1965 if (script->type() != i::Script::TYPE_NORMAL && |
1970 script->type() != i::Script::TYPE_WASM) { | 1966 script->type() != i::Script::TYPE_WASM) { |
1971 return; | 1967 return; |
1972 } | 1968 } |
1973 SuppressDebug while_processing(this); | 1969 SuppressDebug while_processing(this); |
kozy
2017/01/17 17:14:09
test/debug relies on this (e.g. debug-step-stub-ca
jgruber
2017/01/18 10:25:34
Good point, the current solution in test-api.js is
| |
1974 | 1970 |
1971 if (compile_event_listener_) { | |
1972 compile_event_listener_(ToApiHandle<debug::Script>(script), | |
1973 event != v8::AfterCompile, | |
1974 compile_event_listener_data_); | |
1975 if (!non_inspector_listener_exists()) return; | |
1976 } | |
1977 | |
1975 bool in_nested_debug_scope = in_debug_scope(); | 1978 bool in_nested_debug_scope = in_debug_scope(); |
1976 HandleScope scope(isolate_); | 1979 HandleScope scope(isolate_); |
1977 DebugScope debug_scope(this); | 1980 DebugScope debug_scope(this); |
Yang
2017/01/18 11:41:08
I think we need to move the DebugScope above the c
kozy
2017/01/18 20:00:02
Done.
| |
1978 if (debug_scope.failed()) return; | 1981 if (debug_scope.failed()) return; |
1979 | 1982 |
1980 // Create the compile state object. | 1983 // Create the compile state object. |
1981 Handle<Object> event_data; | 1984 Handle<Object> event_data; |
1982 // Bail out and don't call debugger if exception. | 1985 // Bail out and don't call debugger if exception. |
1983 if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return; | 1986 if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return; |
1984 | 1987 |
1985 // Don't call NotifyMessageHandler if already in debug scope to avoid running | 1988 // Don't call NotifyMessageHandler if already in debug scope to avoid running |
1986 // nested command loop. | 1989 // nested command loop. |
1987 if (in_nested_debug_scope) { | 1990 if (in_nested_debug_scope) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2163 UpdateState(); | 2166 UpdateState(); |
2164 if (handler == NULL && in_debug_scope()) { | 2167 if (handler == NULL && in_debug_scope()) { |
2165 // Send an empty command to the debugger if in a break to make JavaScript | 2168 // Send an empty command to the debugger if in a break to make JavaScript |
2166 // run again if the debugger is closed. | 2169 // run again if the debugger is closed. |
2167 EnqueueCommandMessage(Vector<const uint16_t>::empty()); | 2170 EnqueueCommandMessage(Vector<const uint16_t>::empty()); |
2168 } | 2171 } |
2169 } | 2172 } |
2170 | 2173 |
2171 void Debug::UpdateState() { | 2174 void Debug::UpdateState() { |
2172 bool is_active = message_handler_ != nullptr || !event_listener_.is_null() || | 2175 bool is_active = message_handler_ != nullptr || !event_listener_.is_null() || |
2173 async_task_listener_ != nullptr; | 2176 async_task_listener_ != nullptr || |
2177 compile_event_listener_ != nullptr; | |
2174 if (is_active || in_debug_scope()) { | 2178 if (is_active || in_debug_scope()) { |
2175 // Note that the debug context could have already been loaded to | 2179 // Note that the debug context could have already been loaded to |
2176 // bootstrap test cases. | 2180 // bootstrap test cases. |
2177 isolate_->compilation_cache()->Disable(); | 2181 isolate_->compilation_cache()->Disable(); |
2178 is_active = Load(); | 2182 is_active = Load(); |
2179 } else if (is_loaded()) { | 2183 } else if (is_loaded()) { |
2180 isolate_->compilation_cache()->Enable(); | 2184 isolate_->compilation_cache()->Enable(); |
2181 Unload(); | 2185 Unload(); |
2182 } | 2186 } |
2183 is_active_ = is_active; | 2187 is_active_ = is_active; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2653 logger_->DebugEvent("Put", message.text()); | 2657 logger_->DebugEvent("Put", message.text()); |
2654 } | 2658 } |
2655 | 2659 |
2656 void LockingCommandMessageQueue::Clear() { | 2660 void LockingCommandMessageQueue::Clear() { |
2657 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2661 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2658 queue_.Clear(); | 2662 queue_.Clear(); |
2659 } | 2663 } |
2660 | 2664 |
2661 } // namespace internal | 2665 } // namespace internal |
2662 } // namespace v8 | 2666 } // namespace v8 |
OLD | NEW |