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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 bestMatch = nextMatch; | 164 bestMatch = nextMatch; |
165 } else { | 165 } else { |
166 bestMatch = nextMatch - offset < offset - prevMatch ? nextMatch : prevMatch; | 166 bestMatch = nextMatch - offset < offset - prevMatch ? nextMatch : prevMatch; |
167 } | 167 } |
168 bestMatch += searchRegionOffset; | 168 bestMatch += searchRegionOffset; |
169 v8::debug::Location hintPosition = script.location(bestMatch); | 169 v8::debug::Location hintPosition = script.location(bestMatch); |
170 if (hintPosition.IsEmpty()) return; | 170 if (hintPosition.IsEmpty()) return; |
171 breakpoint->line_number = hintPosition.GetLineNumber(); | 171 breakpoint->line_number = hintPosition.GetLineNumber(); |
172 breakpoint->column_number = hintPosition.GetColumnNumber(); | 172 breakpoint->column_number = hintPosition.GetColumnNumber(); |
173 } | 173 } |
| 174 |
| 175 String16 breakLocationType(v8::debug::BreakLocationType type) { |
| 176 switch (type) { |
| 177 case v8::debug::kCallBreakLocation: |
| 178 return protocol::Debugger::BreakLocation::TypeEnum::Call; |
| 179 case v8::debug::kReturnBreakLocation: |
| 180 return protocol::Debugger::BreakLocation::TypeEnum::Return; |
| 181 case v8::debug::kDebuggerStatementBreakLocation: |
| 182 return protocol::Debugger::BreakLocation::TypeEnum::DebuggerStatement; |
| 183 case v8::debug::kCommonBreakLocation: |
| 184 return String16(); |
| 185 } |
| 186 return String16(); |
| 187 } |
| 188 |
174 } // namespace | 189 } // namespace |
175 | 190 |
176 V8DebuggerAgentImpl::V8DebuggerAgentImpl( | 191 V8DebuggerAgentImpl::V8DebuggerAgentImpl( |
177 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, | 192 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, |
178 protocol::DictionaryValue* state) | 193 protocol::DictionaryValue* state) |
179 : m_inspector(session->inspector()), | 194 : m_inspector(session->inspector()), |
180 m_debugger(m_inspector->debugger()), | 195 m_debugger(m_inspector->debugger()), |
181 m_session(session), | 196 m_session(session), |
182 m_enabled(false), | 197 m_enabled(false), |
183 m_state(state), | 198 m_state(state), |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 428 |
414 m_debugger->removeBreakpoint(debuggerBreakpointId); | 429 m_debugger->removeBreakpoint(debuggerBreakpointId); |
415 m_serverBreakpoints.erase(debuggerBreakpointId); | 430 m_serverBreakpoints.erase(debuggerBreakpointId); |
416 } | 431 } |
417 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId); | 432 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId); |
418 } | 433 } |
419 | 434 |
420 Response V8DebuggerAgentImpl::getPossibleBreakpoints( | 435 Response V8DebuggerAgentImpl::getPossibleBreakpoints( |
421 std::unique_ptr<protocol::Debugger::Location> start, | 436 std::unique_ptr<protocol::Debugger::Location> start, |
422 Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction, | 437 Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction, |
423 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations) { | 438 std::unique_ptr<protocol::Array<protocol::Debugger::BreakLocation>>* |
| 439 locations) { |
424 String16 scriptId = start->getScriptId(); | 440 String16 scriptId = start->getScriptId(); |
425 | 441 |
426 if (start->getLineNumber() < 0 || start->getColumnNumber(0) < 0) | 442 if (start->getLineNumber() < 0 || start->getColumnNumber(0) < 0) |
427 return Response::Error( | 443 return Response::Error( |
428 "start.lineNumber and start.columnNumber should be >= 0"); | 444 "start.lineNumber and start.columnNumber should be >= 0"); |
429 | 445 |
430 v8::debug::Location v8Start(start->getLineNumber(), | 446 v8::debug::Location v8Start(start->getLineNumber(), |
431 start->getColumnNumber(0)); | 447 start->getColumnNumber(0)); |
432 v8::debug::Location v8End; | 448 v8::debug::Location v8End; |
433 if (end.isJust()) { | 449 if (end.isJust()) { |
434 if (end.fromJust()->getScriptId() != scriptId) | 450 if (end.fromJust()->getScriptId() != scriptId) |
435 return Response::Error("Locations should contain the same scriptId"); | 451 return Response::Error("Locations should contain the same scriptId"); |
436 int line = end.fromJust()->getLineNumber(); | 452 int line = end.fromJust()->getLineNumber(); |
437 int column = end.fromJust()->getColumnNumber(0); | 453 int column = end.fromJust()->getColumnNumber(0); |
438 if (line < 0 || column < 0) | 454 if (line < 0 || column < 0) |
439 return Response::Error( | 455 return Response::Error( |
440 "end.lineNumber and end.columnNumber should be >= 0"); | 456 "end.lineNumber and end.columnNumber should be >= 0"); |
441 v8End = v8::debug::Location(line, column); | 457 v8End = v8::debug::Location(line, column); |
442 } | 458 } |
443 auto it = m_scripts.find(scriptId); | 459 auto it = m_scripts.find(scriptId); |
444 if (it == m_scripts.end()) return Response::Error("Script not found"); | 460 if (it == m_scripts.end()) return Response::Error("Script not found"); |
445 | 461 |
446 std::vector<v8::debug::Location> v8Locations; | 462 std::vector<v8::debug::BreakLocation> v8Locations; |
447 if (!it->second->getPossibleBreakpoints( | 463 if (!it->second->getPossibleBreakpoints( |
448 v8Start, v8End, restrictToFunction.fromMaybe(false), &v8Locations)) | 464 v8Start, v8End, restrictToFunction.fromMaybe(false), &v8Locations)) { |
449 return Response::InternalError(); | 465 return Response::InternalError(); |
| 466 } |
450 | 467 |
451 *locations = protocol::Array<protocol::Debugger::Location>::create(); | 468 *locations = protocol::Array<protocol::Debugger::BreakLocation>::create(); |
452 for (size_t i = 0; i < v8Locations.size(); ++i) { | 469 for (size_t i = 0; i < v8Locations.size(); ++i) { |
453 (*locations) | 470 std::unique_ptr<protocol::Debugger::BreakLocation> breakLocation = |
454 ->addItem(protocol::Debugger::Location::create() | 471 protocol::Debugger::BreakLocation::create() |
455 .setScriptId(scriptId) | 472 .setScriptId(scriptId) |
456 .setLineNumber(v8Locations[i].GetLineNumber()) | 473 .setLineNumber(v8Locations[i].GetLineNumber()) |
457 .setColumnNumber(v8Locations[i].GetColumnNumber()) | 474 .setColumnNumber(v8Locations[i].GetColumnNumber()) |
458 .build()); | 475 .build(); |
| 476 if (v8Locations[i].type() != v8::debug::kCommonBreakLocation) { |
| 477 breakLocation->setType(breakLocationType(v8Locations[i].type())); |
| 478 } |
| 479 (*locations)->addItem(std::move(breakLocation)); |
459 } | 480 } |
460 return Response::OK(); | 481 return Response::OK(); |
461 } | 482 } |
462 | 483 |
463 Response V8DebuggerAgentImpl::continueToLocation( | 484 Response V8DebuggerAgentImpl::continueToLocation( |
464 std::unique_ptr<protocol::Debugger::Location> location) { | 485 std::unique_ptr<protocol::Debugger::Location> location) { |
465 if (!enabled()) return Response::Error(kDebuggerNotEnabled); | 486 if (!enabled()) return Response::Error(kDebuggerNotEnabled); |
466 if (!m_continueToLocationBreakpointId.isEmpty()) { | 487 if (!m_continueToLocationBreakpointId.isEmpty()) { |
467 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); | 488 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); |
468 m_continueToLocationBreakpointId = ""; | 489 m_continueToLocationBreakpointId = ""; |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 void V8DebuggerAgentImpl::reset() { | 1339 void V8DebuggerAgentImpl::reset() { |
1319 if (!enabled()) return; | 1340 if (!enabled()) return; |
1320 m_scheduledDebuggerStep = NoStep; | 1341 m_scheduledDebuggerStep = NoStep; |
1321 m_blackboxedPositions.clear(); | 1342 m_blackboxedPositions.clear(); |
1322 resetBlackboxedStateCache(); | 1343 resetBlackboxedStateCache(); |
1323 m_scripts.clear(); | 1344 m_scripts.clear(); |
1324 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1345 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1325 } | 1346 } |
1326 | 1347 |
1327 } // namespace v8_inspector | 1348 } // namespace v8_inspector |
OLD | NEW |