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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 const std::vector<String16>& ids = debuggerBreakpointIdsIterator->second; | 373 const std::vector<String16>& ids = debuggerBreakpointIdsIterator->second; |
374 for (size_t i = 0; i < ids.size(); ++i) { | 374 for (size_t i = 0; i < ids.size(); ++i) { |
375 const String16& debuggerBreakpointId = ids[i]; | 375 const String16& debuggerBreakpointId = ids[i]; |
376 | 376 |
377 m_debugger->removeBreakpoint(debuggerBreakpointId); | 377 m_debugger->removeBreakpoint(debuggerBreakpointId); |
378 m_serverBreakpoints.erase(debuggerBreakpointId); | 378 m_serverBreakpoints.erase(debuggerBreakpointId); |
379 } | 379 } |
380 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId); | 380 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId); |
381 } | 381 } |
382 | 382 |
| 383 void V8DebuggerAgentImpl::getPossibleBreakpoints( |
| 384 ErrorString* errorString, |
| 385 std::unique_ptr<protocol::Debugger::Location> start, |
| 386 const Maybe<protocol::Debugger::Location>& end, |
| 387 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations) { |
| 388 String16 scriptId = start->getScriptId(); |
| 389 |
| 390 if (start->getLineNumber() < 0 || start->getColumnNumber(0) < 0) { |
| 391 *errorString = "start.lineNumber and start.columnNumber should be >= 0"; |
| 392 return; |
| 393 } |
| 394 |
| 395 v8::DebugInterface::Location v8Start(start->getLineNumber(), |
| 396 start->getColumnNumber(0)); |
| 397 v8::DebugInterface::Location v8End; |
| 398 if (end.isJust()) { |
| 399 if (end.fromJust()->getScriptId() != scriptId) { |
| 400 *errorString = "Locations should contain the same scriptId"; |
| 401 return; |
| 402 } |
| 403 int line = end.fromJust()->getLineNumber(); |
| 404 int column = end.fromJust()->getColumnNumber(0); |
| 405 if (line < 0 || column < 0) { |
| 406 *errorString = "end.lineNumber and end.columnNumber should be >= 0"; |
| 407 return; |
| 408 } |
| 409 v8End = v8::DebugInterface::Location(line, column); |
| 410 } |
| 411 auto it = m_scripts.find(scriptId); |
| 412 if (it == m_scripts.end()) { |
| 413 *errorString = "Script not found"; |
| 414 return; |
| 415 } |
| 416 |
| 417 std::vector<v8::DebugInterface::Location> v8Locations; |
| 418 if (!it->second->getPossibleBreakpoints(v8Start, v8End, &v8Locations)) { |
| 419 *errorString = "Internal error"; |
| 420 return; |
| 421 } |
| 422 |
| 423 *locations = protocol::Array<protocol::Debugger::Location>::create(); |
| 424 for (size_t i = 0; i < v8Locations.size(); ++i) { |
| 425 (*locations) |
| 426 ->addItem(protocol::Debugger::Location::create() |
| 427 .setScriptId(scriptId) |
| 428 .setLineNumber(v8Locations[i].GetLineNumber()) |
| 429 .setColumnNumber(v8Locations[i].GetColumnNumber()) |
| 430 .build()); |
| 431 } |
| 432 } |
| 433 |
383 void V8DebuggerAgentImpl::continueToLocation( | 434 void V8DebuggerAgentImpl::continueToLocation( |
384 ErrorString* errorString, | 435 ErrorString* errorString, |
385 std::unique_ptr<protocol::Debugger::Location> location) { | 436 std::unique_ptr<protocol::Debugger::Location> location) { |
386 if (!checkEnabled(errorString)) return; | 437 if (!checkEnabled(errorString)) return; |
387 if (!m_continueToLocationBreakpointId.isEmpty()) { | 438 if (!m_continueToLocationBreakpointId.isEmpty()) { |
388 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); | 439 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); |
389 m_continueToLocationBreakpointId = ""; | 440 m_continueToLocationBreakpointId = ""; |
390 } | 441 } |
391 | 442 |
392 String16 scriptId; | 443 String16 scriptId; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 if (!checkEnabled(errorString)) return; | 591 if (!checkEnabled(errorString)) return; |
541 | 592 |
542 v8::HandleScope handles(m_isolate); | 593 v8::HandleScope handles(m_isolate); |
543 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent); | 594 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent); |
544 if (!m_debugger->setScriptSource(scriptId, newSource, dryRun.fromMaybe(false), | 595 if (!m_debugger->setScriptSource(scriptId, newSource, dryRun.fromMaybe(false), |
545 errorString, optOutCompileError, | 596 errorString, optOutCompileError, |
546 &m_pausedCallFrames, stackChanged)) | 597 &m_pausedCallFrames, stackChanged)) |
547 return; | 598 return; |
548 | 599 |
549 ScriptsMap::iterator it = m_scripts.find(scriptId); | 600 ScriptsMap::iterator it = m_scripts.find(scriptId); |
550 if (it != m_scripts.end()) it->second->setSource(m_isolate, newSource); | 601 if (it != m_scripts.end()) it->second->setSource(newSource); |
551 | 602 |
552 std::unique_ptr<Array<CallFrame>> callFrames = currentCallFrames(errorString); | 603 std::unique_ptr<Array<CallFrame>> callFrames = currentCallFrames(errorString); |
553 if (!callFrames) return; | 604 if (!callFrames) return; |
554 *newCallFrames = std::move(callFrames); | 605 *newCallFrames = std::move(callFrames); |
555 *asyncStackTrace = currentAsyncStackTrace(); | 606 *asyncStackTrace = currentAsyncStackTrace(); |
556 } | 607 } |
557 | 608 |
558 void V8DebuggerAgentImpl::restartFrame( | 609 void V8DebuggerAgentImpl::restartFrame( |
559 ErrorString* errorString, const String16& callFrameId, | 610 ErrorString* errorString, const String16& callFrameId, |
560 std::unique_ptr<Array<CallFrame>>* newCallFrames, | 611 std::unique_ptr<Array<CallFrame>>* newCallFrames, |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 | 1293 |
1243 void V8DebuggerAgentImpl::reset() { | 1294 void V8DebuggerAgentImpl::reset() { |
1244 if (!enabled()) return; | 1295 if (!enabled()) return; |
1245 m_scheduledDebuggerStep = NoStep; | 1296 m_scheduledDebuggerStep = NoStep; |
1246 m_scripts.clear(); | 1297 m_scripts.clear(); |
1247 m_blackboxedPositions.clear(); | 1298 m_blackboxedPositions.clear(); |
1248 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1299 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1249 } | 1300 } |
1250 | 1301 |
1251 } // namespace v8_inspector | 1302 } // namespace v8_inspector |
OLD | NEW |