OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/inspector/v8-debugger-agent-impl.h" | 5 #include "src/inspector/v8-debugger-agent-impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/debug/debug-interface.h" | 9 #include "src/debug/debug-interface.h" |
10 #include "src/inspector/injected-script.h" | 10 #include "src/inspector/injected-script.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 if (isPaused()) m_debugger->continueProgram(m_session->contextGroupId()); | 240 if (isPaused()) m_debugger->continueProgram(m_session->contextGroupId()); |
241 m_debugger->disable(); | 241 m_debugger->disable(); |
242 JavaScriptCallFrames emptyCallFrames; | 242 JavaScriptCallFrames emptyCallFrames; |
243 m_pausedCallFrames.swap(emptyCallFrames); | 243 m_pausedCallFrames.swap(emptyCallFrames); |
244 m_blackboxedPositions.clear(); | 244 m_blackboxedPositions.clear(); |
245 m_blackboxPattern.reset(); | 245 m_blackboxPattern.reset(); |
246 resetBlackboxedStateCache(); | 246 resetBlackboxedStateCache(); |
247 m_scripts.clear(); | 247 m_scripts.clear(); |
248 m_breakpointIdToDebuggerBreakpointIds.clear(); | 248 m_breakpointIdToDebuggerBreakpointIds.clear(); |
249 m_debugger->setAsyncCallStackDepth(this, 0); | 249 m_debugger->setAsyncCallStackDepth(this, 0); |
250 m_continueToLocationBreakpointId = String16(); | 250 clearContinueToLocation(); |
251 clearBreakDetails(); | 251 clearBreakDetails(); |
252 m_skipAllPauses = false; | 252 m_skipAllPauses = false; |
253 m_state->setBoolean(DebuggerAgentState::skipAllPauses, false); | 253 m_state->setBoolean(DebuggerAgentState::skipAllPauses, false); |
254 m_state->remove(DebuggerAgentState::blackboxPattern); | 254 m_state->remove(DebuggerAgentState::blackboxPattern); |
255 m_enabled = false; | 255 m_enabled = false; |
256 m_state->setBoolean(DebuggerAgentState::debuggerEnabled, false); | 256 m_state->setBoolean(DebuggerAgentState::debuggerEnabled, false); |
257 return Response::OK(); | 257 return Response::OK(); |
258 } | 258 } |
259 | 259 |
260 void V8DebuggerAgentImpl::restore() { | 260 void V8DebuggerAgentImpl::restore() { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 .build(); | 477 .build(); |
478 if (v8Locations[i].type() != v8::debug::kCommonBreakLocation) { | 478 if (v8Locations[i].type() != v8::debug::kCommonBreakLocation) { |
479 breakLocation->setType(breakLocationType(v8Locations[i].type())); | 479 breakLocation->setType(breakLocationType(v8Locations[i].type())); |
480 } | 480 } |
481 (*locations)->addItem(std::move(breakLocation)); | 481 (*locations)->addItem(std::move(breakLocation)); |
482 } | 482 } |
483 return Response::OK(); | 483 return Response::OK(); |
484 } | 484 } |
485 | 485 |
486 Response V8DebuggerAgentImpl::continueToLocation( | 486 Response V8DebuggerAgentImpl::continueToLocation( |
487 std::unique_ptr<protocol::Debugger::Location> location) { | 487 std::unique_ptr<protocol::Debugger::Location> location, |
| 488 Maybe<String16> strategy) { |
488 if (!enabled()) return Response::Error(kDebuggerNotEnabled); | 489 if (!enabled()) return Response::Error(kDebuggerNotEnabled); |
489 if (!m_continueToLocationBreakpointId.isEmpty()) { | 490 if (!isPaused()) return Response::Error(kDebuggerNotPaused); |
490 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); | 491 clearContinueToLocation(); |
491 m_continueToLocationBreakpointId = ""; | |
492 } | |
493 | 492 |
494 ScriptBreakpoint breakpoint(location->getScriptId(), | 493 ScriptBreakpoint breakpoint(location->getScriptId(), |
495 location->getLineNumber(), | 494 location->getLineNumber(), |
496 location->getColumnNumber(0), String16()); | 495 location->getColumnNumber(0), String16()); |
497 | 496 |
498 m_continueToLocationBreakpointId = m_debugger->setBreakpoint( | 497 m_continueToLocationBreakpointId = m_debugger->setBreakpoint( |
499 breakpoint, &breakpoint.line_number, &breakpoint.column_number); | 498 breakpoint, &breakpoint.line_number, &breakpoint.column_number); |
| 499 if (m_continueToLocationBreakpointId.isEmpty()) { |
| 500 return Response::Error("Location can't be resolved"); |
| 501 } |
| 502 m_continueToLocationStrategy = strategy.fromMaybe( |
| 503 protocol::Debugger::ContinueToLocation::StrategyEnum::Default); |
| 504 if (m_continueToLocationStrategy != |
| 505 protocol::Debugger::ContinueToLocation::StrategyEnum::Default) { |
| 506 m_continueToLocationStack = m_debugger->captureStackTrace(true); |
| 507 if (m_continueToLocationStack) { |
| 508 m_continueToLocationStrategy = |
| 509 protocol::Debugger::ContinueToLocation::StrategyEnum::Default; |
| 510 } |
| 511 } |
500 // TODO(kozyatinskiy): Return actual line and column number. | 512 // TODO(kozyatinskiy): Return actual line and column number. |
501 return resume(); | 513 return resume(); |
502 } | 514 } |
503 | 515 |
| 516 void V8DebuggerAgentImpl::clearContinueToLocation() { |
| 517 if (m_continueToLocationBreakpointId.isEmpty()) return; |
| 518 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); |
| 519 m_continueToLocationBreakpointId = String16(); |
| 520 m_continueToLocationStrategy = String16(); |
| 521 m_continueToLocationStack.reset(); |
| 522 } |
| 523 |
504 bool V8DebuggerAgentImpl::isFunctionBlackboxed(const String16& scriptId, | 524 bool V8DebuggerAgentImpl::isFunctionBlackboxed(const String16& scriptId, |
505 const v8::debug::Location& start, | 525 const v8::debug::Location& start, |
506 const v8::debug::Location& end) { | 526 const v8::debug::Location& end) { |
507 ScriptsMap::iterator it = m_scripts.find(scriptId); | 527 ScriptsMap::iterator it = m_scripts.find(scriptId); |
508 if (it == m_scripts.end()) { | 528 if (it == m_scripts.end()) { |
509 // Unknown scripts are blackboxed. | 529 // Unknown scripts are blackboxed. |
510 return true; | 530 return true; |
511 } | 531 } |
512 if (m_blackboxPattern) { | 532 if (m_blackboxPattern) { |
513 const String16& scriptSourceURL = it->second->sourceURL(); | 533 const String16& scriptSourceURL = it->second->sourceURL(); |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 if (!hasHint) { | 1157 if (!hasHint) { |
1138 hint = breakpointHint(*scriptRef, breakpoint); | 1158 hint = breakpointHint(*scriptRef, breakpoint); |
1139 if (!hint.isEmpty()) | 1159 if (!hint.isEmpty()) |
1140 breakpointObject->setString(DebuggerAgentState::hint, hint); | 1160 breakpointObject->setString(DebuggerAgentState::hint, hint); |
1141 } | 1161 } |
1142 if (location) | 1162 if (location) |
1143 m_frontend.breakpointResolved(cookie.first, std::move(location)); | 1163 m_frontend.breakpointResolved(cookie.first, std::move(location)); |
1144 } | 1164 } |
1145 } | 1165 } |
1146 | 1166 |
| 1167 bool V8DebuggerAgentImpl::shouldIgnoreContinueToLocation( |
| 1168 const String16& breakpointId) { |
| 1169 if (breakpointId != m_continueToLocationBreakpointId) return false; |
| 1170 if (m_continueToLocationStrategy == |
| 1171 protocol::Debugger::ContinueToLocation::StrategyEnum::Default) { |
| 1172 return false; |
| 1173 } |
| 1174 std::unique_ptr<V8StackTraceImpl> currentStack = |
| 1175 m_debugger->captureStackTrace(true); |
| 1176 if (m_continueToLocationStrategy == |
| 1177 protocol::Debugger::ContinueToLocation::StrategyEnum::InCurrentFrame) { |
| 1178 return !m_continueToLocationStack->isEqualIgnoringTopFrame( |
| 1179 currentStack.get()); |
| 1180 } |
| 1181 return false; |
| 1182 } |
| 1183 |
1147 void V8DebuggerAgentImpl::didPause(int contextId, | 1184 void V8DebuggerAgentImpl::didPause(int contextId, |
1148 v8::Local<v8::Value> exception, | 1185 v8::Local<v8::Value> exception, |
1149 const std::vector<String16>& hitBreakpoints, | 1186 const std::vector<String16>& hitBreakpoints, |
1150 bool isPromiseRejection, bool isUncaught, | 1187 bool isPromiseRejection, bool isUncaught, |
1151 bool isOOMBreak) { | 1188 bool isOOMBreak) { |
1152 JavaScriptCallFrames frames = m_debugger->currentCallFrames(); | 1189 JavaScriptCallFrames frames = m_debugger->currentCallFrames(); |
1153 m_pausedCallFrames.swap(frames); | 1190 m_pausedCallFrames.swap(frames); |
1154 v8::HandleScope handles(m_isolate); | 1191 v8::HandleScope handles(m_isolate); |
1155 | 1192 |
1156 std::vector<BreakReason> hitReasons; | 1193 std::vector<BreakReason> hitReasons; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 breakAuxData->setArray("reasons", std::move(reasons)); | 1264 breakAuxData->setArray("reasons", std::move(reasons)); |
1228 } | 1265 } |
1229 | 1266 |
1230 std::unique_ptr<Array<CallFrame>> protocolCallFrames; | 1267 std::unique_ptr<Array<CallFrame>> protocolCallFrames; |
1231 Response response = currentCallFrames(&protocolCallFrames); | 1268 Response response = currentCallFrames(&protocolCallFrames); |
1232 if (!response.isSuccess()) protocolCallFrames = Array<CallFrame>::create(); | 1269 if (!response.isSuccess()) protocolCallFrames = Array<CallFrame>::create(); |
1233 m_frontend.paused(std::move(protocolCallFrames), breakReason, | 1270 m_frontend.paused(std::move(protocolCallFrames), breakReason, |
1234 std::move(breakAuxData), std::move(hitBreakpointIds), | 1271 std::move(breakAuxData), std::move(hitBreakpointIds), |
1235 currentAsyncStackTrace()); | 1272 currentAsyncStackTrace()); |
1236 | 1273 |
1237 if (!m_continueToLocationBreakpointId.isEmpty()) { | 1274 clearContinueToLocation(); |
1238 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); | |
1239 m_continueToLocationBreakpointId = ""; | |
1240 } | |
1241 } | 1275 } |
1242 | 1276 |
1243 void V8DebuggerAgentImpl::didContinue() { | 1277 void V8DebuggerAgentImpl::didContinue() { |
1244 JavaScriptCallFrames emptyCallFrames; | 1278 JavaScriptCallFrames emptyCallFrames; |
1245 m_pausedCallFrames.swap(emptyCallFrames); | 1279 m_pausedCallFrames.swap(emptyCallFrames); |
1246 clearBreakDetails(); | 1280 clearBreakDetails(); |
1247 m_frontend.resumed(); | 1281 m_frontend.resumed(); |
1248 } | 1282 } |
1249 | 1283 |
1250 void V8DebuggerAgentImpl::breakProgram( | 1284 void V8DebuggerAgentImpl::breakProgram( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 | 1324 |
1291 void V8DebuggerAgentImpl::reset() { | 1325 void V8DebuggerAgentImpl::reset() { |
1292 if (!enabled()) return; | 1326 if (!enabled()) return; |
1293 m_blackboxedPositions.clear(); | 1327 m_blackboxedPositions.clear(); |
1294 resetBlackboxedStateCache(); | 1328 resetBlackboxedStateCache(); |
1295 m_scripts.clear(); | 1329 m_scripts.clear(); |
1296 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1330 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1297 } | 1331 } |
1298 | 1332 |
1299 } // namespace v8_inspector | 1333 } // namespace v8_inspector |
OLD | NEW |