| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 "platform/v8_inspector/V8DebuggerAgentImpl.h" | 5 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/inspector_protocol/Values.h" | 8 #include "platform/inspector_protocol/Values.h" |
| 9 #include "platform/v8_inspector/IgnoreExceptionsScope.h" | 9 #include "platform/v8_inspector/IgnoreExceptionsScope.h" |
| 10 #include "platform/v8_inspector/InjectedScript.h" | 10 #include "platform/v8_inspector/InjectedScript.h" |
| 11 #include "platform/v8_inspector/InjectedScriptHost.h" | 11 #include "platform/v8_inspector/InjectedScriptHost.h" |
| 12 #include "platform/v8_inspector/InjectedScriptManager.h" | 12 #include "platform/v8_inspector/InjectedScriptManager.h" |
| 13 #include "platform/v8_inspector/JavaScriptCallFrame.h" | 13 #include "platform/v8_inspector/JavaScriptCallFrame.h" |
| 14 #include "platform/v8_inspector/PromiseTracker.h" | |
| 15 #include "platform/v8_inspector/RemoteObjectId.h" | 14 #include "platform/v8_inspector/RemoteObjectId.h" |
| 16 #include "platform/v8_inspector/ScriptBreakpoint.h" | 15 #include "platform/v8_inspector/ScriptBreakpoint.h" |
| 17 #include "platform/v8_inspector/V8AsyncCallTracker.h" | 16 #include "platform/v8_inspector/V8AsyncCallTracker.h" |
| 18 #include "platform/v8_inspector/V8Regex.h" | 17 #include "platform/v8_inspector/V8Regex.h" |
| 19 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 18 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
| 20 #include "platform/v8_inspector/V8StackTraceImpl.h" | 19 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 21 #include "platform/v8_inspector/V8StringUtil.h" | 20 #include "platform/v8_inspector/V8StringUtil.h" |
| 22 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" | 21 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" |
| 23 #include "platform/v8_inspector/public/V8Debugger.h" | 22 #include "platform/v8_inspector/public/V8Debugger.h" |
| 24 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 23 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 25 #include "platform/v8_inspector/public/V8ToProtocolValue.h" | 24 #include "platform/v8_inspector/public/V8ToProtocolValue.h" |
| 26 | 25 |
| 27 using blink::protocol::Array; | 26 using blink::protocol::Array; |
| 28 using blink::protocol::Maybe; | 27 using blink::protocol::Maybe; |
| 29 using blink::protocol::Debugger::AsyncOperation; | 28 using blink::protocol::Debugger::AsyncOperation; |
| 30 using blink::protocol::Debugger::BreakpointId; | 29 using blink::protocol::Debugger::BreakpointId; |
| 31 using blink::protocol::Debugger::CallFrame; | 30 using blink::protocol::Debugger::CallFrame; |
| 32 using blink::protocol::Debugger::CollectionEntry; | 31 using blink::protocol::Debugger::CollectionEntry; |
| 33 using blink::protocol::Runtime::ExceptionDetails; | 32 using blink::protocol::Runtime::ExceptionDetails; |
| 34 using blink::protocol::Debugger::FunctionDetails; | 33 using blink::protocol::Debugger::FunctionDetails; |
| 35 using blink::protocol::Debugger::GeneratorObjectDetails; | 34 using blink::protocol::Debugger::GeneratorObjectDetails; |
| 36 using blink::protocol::Debugger::PromiseDetails; | |
| 37 using blink::protocol::Runtime::ScriptId; | 35 using blink::protocol::Runtime::ScriptId; |
| 38 using blink::protocol::Runtime::StackTrace; | 36 using blink::protocol::Runtime::StackTrace; |
| 39 using blink::protocol::Runtime::RemoteObject; | 37 using blink::protocol::Runtime::RemoteObject; |
| 40 | 38 |
| 41 namespace blink { | 39 namespace blink { |
| 42 | 40 |
| 43 namespace DebuggerAgentState { | 41 namespace DebuggerAgentState { |
| 44 static const char javaScriptBreakpoints[] = "javaScriptBreakopints"; | 42 static const char javaScriptBreakpoints[] = "javaScriptBreakopints"; |
| 45 static const char pauseOnExceptionsState[] = "pauseOnExceptionsState"; | 43 static const char pauseOnExceptionsState[] = "pauseOnExceptionsState"; |
| 46 static const char asyncCallStackDepth[] = "asyncCallStackDepth"; | 44 static const char asyncCallStackDepth[] = "asyncCallStackDepth"; |
| 47 static const char promiseTrackerEnabled[] = "promiseTrackerEnabled"; | |
| 48 static const char promiseTrackerCaptureStacks[] = "promiseTrackerCaptureStacks"; | |
| 49 | 45 |
| 50 // Breakpoint properties. | 46 // Breakpoint properties. |
| 51 static const char url[] = "url"; | 47 static const char url[] = "url"; |
| 52 static const char isRegex[] = "isRegex"; | 48 static const char isRegex[] = "isRegex"; |
| 53 static const char lineNumber[] = "lineNumber"; | 49 static const char lineNumber[] = "lineNumber"; |
| 54 static const char columnNumber[] = "columnNumber"; | 50 static const char columnNumber[] = "columnNumber"; |
| 55 static const char condition[] = "condition"; | 51 static const char condition[] = "condition"; |
| 56 static const char skipAllPauses[] = "skipAllPauses"; | 52 static const char skipAllPauses[] = "skipAllPauses"; |
| 57 | 53 |
| 58 } // namespace DebuggerAgentState; | 54 } // namespace DebuggerAgentState; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 , m_nestedAsyncCallCount(0) | 185 , m_nestedAsyncCallCount(0) |
| 190 , m_currentAsyncOperationId(unknownAsyncOperationId) | 186 , m_currentAsyncOperationId(unknownAsyncOperationId) |
| 191 , m_pendingTraceAsyncOperationCompleted(false) | 187 , m_pendingTraceAsyncOperationCompleted(false) |
| 192 , m_startingStepIntoAsync(false) | 188 , m_startingStepIntoAsync(false) |
| 193 { | 189 { |
| 194 ASSERT(contextGroupId); | 190 ASSERT(contextGroupId); |
| 195 m_injectedScriptManager->injectedScriptHost()->setDebuggerAgent(this); | 191 m_injectedScriptManager->injectedScriptHost()->setDebuggerAgent(this); |
| 196 | 192 |
| 197 // FIXME: remove once InjectedScriptManager moves to v8. | 193 // FIXME: remove once InjectedScriptManager moves to v8. |
| 198 m_v8AsyncCallTracker = V8AsyncCallTracker::create(this); | 194 m_v8AsyncCallTracker = V8AsyncCallTracker::create(this); |
| 199 m_promiseTracker = PromiseTracker::create(this, m_isolate); | |
| 200 clearBreakDetails(); | 195 clearBreakDetails(); |
| 201 } | 196 } |
| 202 | 197 |
| 203 V8DebuggerAgentImpl::~V8DebuggerAgentImpl() | 198 V8DebuggerAgentImpl::~V8DebuggerAgentImpl() |
| 204 { | 199 { |
| 205 } | 200 } |
| 206 | 201 |
| 207 bool V8DebuggerAgentImpl::checkEnabled(ErrorString* errorString) | 202 bool V8DebuggerAgentImpl::checkEnabled(ErrorString* errorString) |
| 208 { | 203 { |
| 209 if (enabled()) | 204 if (enabled()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 238 } | 233 } |
| 239 | 234 |
| 240 void V8DebuggerAgentImpl::disable(ErrorString*) | 235 void V8DebuggerAgentImpl::disable(ErrorString*) |
| 241 { | 236 { |
| 242 if (!enabled()) | 237 if (!enabled()) |
| 243 return; | 238 return; |
| 244 | 239 |
| 245 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict
ionaryValue::create()); | 240 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict
ionaryValue::create()); |
| 246 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp
l::DontPauseOnExceptions); | 241 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp
l::DontPauseOnExceptions); |
| 247 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0); | 242 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0); |
| 248 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, false); | |
| 249 m_state->setBoolean(DebuggerAgentState::promiseTrackerCaptureStacks, false); | |
| 250 | 243 |
| 251 debugger().removeDebuggerAgent(m_contextGroupId); | 244 debugger().removeDebuggerAgent(m_contextGroupId); |
| 252 m_pausedContext.Reset(); | 245 m_pausedContext.Reset(); |
| 253 m_currentCallStack.clear(); | 246 m_currentCallStack.clear(); |
| 254 m_scripts.clear(); | 247 m_scripts.clear(); |
| 255 m_blackboxedPositions.clear(); | 248 m_blackboxedPositions.clear(); |
| 256 m_breakpointIdToDebuggerBreakpointIds.clear(); | 249 m_breakpointIdToDebuggerBreakpointIds.clear(); |
| 257 internalSetAsyncCallStackDepth(0); | 250 internalSetAsyncCallStackDepth(0); |
| 258 m_promiseTracker->setEnabled(false, false); | |
| 259 m_continueToLocationBreakpointId = String16(); | 251 m_continueToLocationBreakpointId = String16(); |
| 260 clearBreakDetails(); | 252 clearBreakDetails(); |
| 261 m_scheduledDebuggerStep = NoStep; | 253 m_scheduledDebuggerStep = NoStep; |
| 262 m_skipNextDebuggerStepOut = false; | 254 m_skipNextDebuggerStepOut = false; |
| 263 m_javaScriptPauseScheduled = false; | 255 m_javaScriptPauseScheduled = false; |
| 264 m_steppingFromFramework = false; | 256 m_steppingFromFramework = false; |
| 265 m_pausingOnNativeEvent = false; | 257 m_pausingOnNativeEvent = false; |
| 266 m_skippedStepFrameCount = 0; | 258 m_skippedStepFrameCount = 0; |
| 267 m_recursionLevelForStepFrame = 0; | 259 m_recursionLevelForStepFrame = 0; |
| 268 m_asyncOperationNotifications.clear(); | 260 m_asyncOperationNotifications.clear(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 295 |
| 304 int pauseState = V8DebuggerImpl::DontPauseOnExceptions; | 296 int pauseState = V8DebuggerImpl::DontPauseOnExceptions; |
| 305 m_state->getNumber(DebuggerAgentState::pauseOnExceptionsState, &pauseState); | 297 m_state->getNumber(DebuggerAgentState::pauseOnExceptionsState, &pauseState); |
| 306 setPauseOnExceptionsImpl(&error, pauseState); | 298 setPauseOnExceptionsImpl(&error, pauseState); |
| 307 | 299 |
| 308 m_skipAllPauses = m_state->booleanProperty(DebuggerAgentState::skipAllPauses
, false); | 300 m_skipAllPauses = m_state->booleanProperty(DebuggerAgentState::skipAllPauses
, false); |
| 309 | 301 |
| 310 int asyncCallStackDepth = 0; | 302 int asyncCallStackDepth = 0; |
| 311 m_state->getNumber(DebuggerAgentState::asyncCallStackDepth, &asyncCallStackD
epth); | 303 m_state->getNumber(DebuggerAgentState::asyncCallStackDepth, &asyncCallStackD
epth); |
| 312 internalSetAsyncCallStackDepth(asyncCallStackDepth); | 304 internalSetAsyncCallStackDepth(asyncCallStackDepth); |
| 313 | |
| 314 m_promiseTracker->setEnabled(m_state->booleanProperty(DebuggerAgentState::pr
omiseTrackerEnabled, false), m_state->booleanProperty(DebuggerAgentState::promis
eTrackerCaptureStacks, false)); | |
| 315 } | 305 } |
| 316 | 306 |
| 317 void V8DebuggerAgentImpl::setBreakpointsActive(ErrorString* errorString, bool ac
tive) | 307 void V8DebuggerAgentImpl::setBreakpointsActive(ErrorString* errorString, bool ac
tive) |
| 318 { | 308 { |
| 319 if (!checkEnabled(errorString)) | 309 if (!checkEnabled(errorString)) |
| 320 return; | 310 return; |
| 321 debugger().setBreakpointsActivated(active); | 311 debugger().setBreakpointsActivated(active); |
| 322 } | 312 } |
| 323 | 313 |
| 324 void V8DebuggerAgentImpl::setSkipAllPauses(ErrorString*, bool skipped) | 314 void V8DebuggerAgentImpl::setSkipAllPauses(ErrorString*, bool skipped) |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 { | 855 { |
| 866 return trackingAsyncCalls(); | 856 return trackingAsyncCalls(); |
| 867 } | 857 } |
| 868 | 858 |
| 869 void V8DebuggerAgentImpl::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> cont
ext, const String16& eventType, const String16& eventName, int id) | 859 void V8DebuggerAgentImpl::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> cont
ext, const String16& eventType, const String16& eventName, int id) |
| 870 { | 860 { |
| 871 ASSERT(trackingAsyncCalls()); | 861 ASSERT(trackingAsyncCalls()); |
| 872 m_v8AsyncCallTracker->didReceiveV8AsyncTaskEvent(context, eventType, eventNa
me, id); | 862 m_v8AsyncCallTracker->didReceiveV8AsyncTaskEvent(context, eventType, eventNa
me, id); |
| 873 } | 863 } |
| 874 | 864 |
| 875 bool V8DebuggerAgentImpl::v8PromiseEventsEnabled() const | |
| 876 { | |
| 877 return m_promiseTracker->isEnabled(); | |
| 878 } | |
| 879 | |
| 880 void V8DebuggerAgentImpl::didReceiveV8PromiseEvent(v8::Local<v8::Context> contex
t, v8::Local<v8::Object> promise, v8::Local<v8::Value> parentPromise, int status
) | |
| 881 { | |
| 882 ASSERT(m_promiseTracker->isEnabled()); | |
| 883 m_promiseTracker->didReceiveV8PromiseEvent(context, promise, parentPromise,
status); | |
| 884 } | |
| 885 | |
| 886 void V8DebuggerAgentImpl::pause(ErrorString* errorString) | 865 void V8DebuggerAgentImpl::pause(ErrorString* errorString) |
| 887 { | 866 { |
| 888 if (!checkEnabled(errorString)) | 867 if (!checkEnabled(errorString)) |
| 889 return; | 868 return; |
| 890 if (m_javaScriptPauseScheduled || isPaused()) | 869 if (m_javaScriptPauseScheduled || isPaused()) |
| 891 return; | 870 return; |
| 892 clearBreakDetails(); | 871 clearBreakDetails(); |
| 893 clearStepIntoAsync(); | 872 clearStepIntoAsync(); |
| 894 m_javaScriptPauseScheduled = true; | 873 m_javaScriptPauseScheduled = true; |
| 895 m_scheduledDebuggerStep = NoStep; | 874 m_scheduledDebuggerStep = NoStep; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 } | 1066 } |
| 1088 | 1067 |
| 1089 void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d
epth) | 1068 void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d
epth) |
| 1090 { | 1069 { |
| 1091 if (!checkEnabled(errorString)) | 1070 if (!checkEnabled(errorString)) |
| 1092 return; | 1071 return; |
| 1093 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, depth); | 1072 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, depth); |
| 1094 internalSetAsyncCallStackDepth(depth); | 1073 internalSetAsyncCallStackDepth(depth); |
| 1095 } | 1074 } |
| 1096 | 1075 |
| 1097 void V8DebuggerAgentImpl::enablePromiseTracker(ErrorString* errorString, | |
| 1098 const Maybe<bool>& captureStacks) | |
| 1099 { | |
| 1100 if (!checkEnabled(errorString)) | |
| 1101 return; | |
| 1102 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, true); | |
| 1103 m_state->setBoolean(DebuggerAgentState::promiseTrackerCaptureStacks, capture
Stacks.fromMaybe(false)); | |
| 1104 m_promiseTracker->setEnabled(true, captureStacks.fromMaybe(false)); | |
| 1105 } | |
| 1106 | |
| 1107 void V8DebuggerAgentImpl::disablePromiseTracker(ErrorString* errorString) | |
| 1108 { | |
| 1109 if (!checkEnabled(errorString)) | |
| 1110 return; | |
| 1111 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, false); | |
| 1112 m_promiseTracker->setEnabled(false, false); | |
| 1113 } | |
| 1114 | |
| 1115 void V8DebuggerAgentImpl::getPromiseById(ErrorString* errorString, int promiseId
, const Maybe<String16>& objectGroup, OwnPtr<RemoteObject>* promise) | |
| 1116 { | |
| 1117 if (!checkEnabled(errorString)) | |
| 1118 return; | |
| 1119 if (!m_promiseTracker->isEnabled()) { | |
| 1120 *errorString = "Promise tracking is disabled"; | |
| 1121 return; | |
| 1122 } | |
| 1123 v8::HandleScope handles(m_isolate); | |
| 1124 v8::Local<v8::Object> value = m_promiseTracker->promiseById(promiseId); | |
| 1125 if (value.IsEmpty()) { | |
| 1126 *errorString = "Promise with specified ID not found."; | |
| 1127 return; | |
| 1128 } | |
| 1129 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor(
value->CreationContext()); | |
| 1130 *promise = injectedScript->wrapObject(errorString, value, objectGroup.fromMa
ybe("")); | |
| 1131 } | |
| 1132 | |
| 1133 void V8DebuggerAgentImpl::didUpdatePromise(const String16& eventType, PassOwnPtr
<protocol::Debugger::PromiseDetails> promise) | |
| 1134 { | |
| 1135 if (m_frontend) | |
| 1136 m_frontend->promiseUpdated(eventType, promise); | |
| 1137 } | |
| 1138 | |
| 1139 int V8DebuggerAgentImpl::traceAsyncOperationStarting(const String16& description
) | 1076 int V8DebuggerAgentImpl::traceAsyncOperationStarting(const String16& description
) |
| 1140 { | 1077 { |
| 1141 v8::HandleScope scope(m_isolate); | 1078 v8::HandleScope scope(m_isolate); |
| 1142 OwnPtr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, V8StackTrac
e::maxCallStackSizeToCapture, description); | 1079 OwnPtr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, V8StackTrac
e::maxCallStackSizeToCapture, description); |
| 1143 | 1080 |
| 1144 do { | 1081 do { |
| 1145 ++m_lastAsyncOperationId; | 1082 ++m_lastAsyncOperationId; |
| 1146 if (m_lastAsyncOperationId <= 0) | 1083 if (m_lastAsyncOperationId <= 0) |
| 1147 m_lastAsyncOperationId = 1; | 1084 m_lastAsyncOperationId = 1; |
| 1148 } while (m_asyncOperations.contains(m_lastAsyncOperationId)); | 1085 } while (m_asyncOperations.contains(m_lastAsyncOperationId)); |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 | 1632 |
| 1696 void V8DebuggerAgentImpl::reset() | 1633 void V8DebuggerAgentImpl::reset() |
| 1697 { | 1634 { |
| 1698 if (!enabled()) | 1635 if (!enabled()) |
| 1699 return; | 1636 return; |
| 1700 m_scheduledDebuggerStep = NoStep; | 1637 m_scheduledDebuggerStep = NoStep; |
| 1701 m_scripts.clear(); | 1638 m_scripts.clear(); |
| 1702 m_blackboxedPositions.clear(); | 1639 m_blackboxedPositions.clear(); |
| 1703 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1640 m_breakpointIdToDebuggerBreakpointIds.clear(); |
| 1704 resetAsyncCallTracker(); | 1641 resetAsyncCallTracker(); |
| 1705 m_promiseTracker->clear(); | |
| 1706 } | 1642 } |
| 1707 | 1643 |
| 1708 } // namespace blink | 1644 } // namespace blink |
| OLD | NEW |