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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 const std::vector<String16>& ids = debuggerBreakpointIdsIterator->second; | 342 const std::vector<String16>& ids = debuggerBreakpointIdsIterator->second; |
343 for (size_t i = 0; i < ids.size(); ++i) { | 343 for (size_t i = 0; i < ids.size(); ++i) { |
344 const String16& debuggerBreakpointId = ids[i]; | 344 const String16& debuggerBreakpointId = ids[i]; |
345 | 345 |
346 m_debugger->removeBreakpoint(debuggerBreakpointId); | 346 m_debugger->removeBreakpoint(debuggerBreakpointId); |
347 m_serverBreakpoints.erase(debuggerBreakpointId); | 347 m_serverBreakpoints.erase(debuggerBreakpointId); |
348 } | 348 } |
349 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId); | 349 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId); |
350 } | 350 } |
351 | 351 |
| 352 Response V8DebuggerAgentImpl::getPossibleBreakpoints( |
| 353 std::unique_ptr<protocol::Debugger::Location> start, |
| 354 Maybe<protocol::Debugger::Location> end, |
| 355 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations) { |
| 356 String16 scriptId = start->getScriptId(); |
| 357 |
| 358 if (start->getLineNumber() < 0 || start->getColumnNumber(0) < 0) |
| 359 return Response::Error( |
| 360 "start.lineNumber and start.columnNumber should be >= 0"); |
| 361 |
| 362 v8::DebugInterface::Location v8Start(start->getLineNumber(), |
| 363 start->getColumnNumber(0)); |
| 364 v8::DebugInterface::Location v8End; |
| 365 if (end.isJust()) { |
| 366 if (end.fromJust()->getScriptId() != scriptId) |
| 367 return Response::Error("Locations should contain the same scriptId"); |
| 368 int line = end.fromJust()->getLineNumber(); |
| 369 int column = end.fromJust()->getColumnNumber(0); |
| 370 if (line < 0 || column < 0) |
| 371 return Response::Error( |
| 372 "end.lineNumber and end.columnNumber should be >= 0"); |
| 373 v8End = v8::DebugInterface::Location(line, column); |
| 374 } |
| 375 auto it = m_scripts.find(scriptId); |
| 376 if (it == m_scripts.end()) return Response::Error("Script not found"); |
| 377 |
| 378 std::vector<v8::DebugInterface::Location> v8Locations; |
| 379 if (!it->second->getPossibleBreakpoints(v8Start, v8End, &v8Locations)) |
| 380 return Response::InternalError(); |
| 381 |
| 382 *locations = protocol::Array<protocol::Debugger::Location>::create(); |
| 383 for (size_t i = 0; i < v8Locations.size(); ++i) { |
| 384 (*locations) |
| 385 ->addItem(protocol::Debugger::Location::create() |
| 386 .setScriptId(scriptId) |
| 387 .setLineNumber(v8Locations[i].GetLineNumber()) |
| 388 .setColumnNumber(v8Locations[i].GetColumnNumber()) |
| 389 .build()); |
| 390 } |
| 391 return Response::OK(); |
| 392 } |
| 393 |
352 Response V8DebuggerAgentImpl::continueToLocation( | 394 Response V8DebuggerAgentImpl::continueToLocation( |
353 std::unique_ptr<protocol::Debugger::Location> location) { | 395 std::unique_ptr<protocol::Debugger::Location> location) { |
354 if (!enabled()) return Response::Error(kDebuggerNotEnabled); | 396 if (!enabled()) return Response::Error(kDebuggerNotEnabled); |
355 if (!m_continueToLocationBreakpointId.isEmpty()) { | 397 if (!m_continueToLocationBreakpointId.isEmpty()) { |
356 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); | 398 m_debugger->removeBreakpoint(m_continueToLocationBreakpointId); |
357 m_continueToLocationBreakpointId = ""; | 399 m_continueToLocationBreakpointId = ""; |
358 } | 400 } |
359 | 401 |
360 String16 scriptId = location->getScriptId(); | 402 String16 scriptId = location->getScriptId(); |
361 int lineNumber = location->getLineNumber(); | 403 int lineNumber = location->getLineNumber(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 544 |
503 v8::HandleScope handles(m_isolate); | 545 v8::HandleScope handles(m_isolate); |
504 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent); | 546 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent); |
505 bool compileError = false; | 547 bool compileError = false; |
506 Response response = m_debugger->setScriptSource( | 548 Response response = m_debugger->setScriptSource( |
507 scriptId, newSource, dryRun.fromMaybe(false), optOutCompileError, | 549 scriptId, newSource, dryRun.fromMaybe(false), optOutCompileError, |
508 &m_pausedCallFrames, stackChanged, &compileError); | 550 &m_pausedCallFrames, stackChanged, &compileError); |
509 if (!response.isSuccess() || compileError) return response; | 551 if (!response.isSuccess() || compileError) return response; |
510 | 552 |
511 ScriptsMap::iterator it = m_scripts.find(scriptId); | 553 ScriptsMap::iterator it = m_scripts.find(scriptId); |
512 if (it != m_scripts.end()) it->second->setSource(m_isolate, newSource); | 554 if (it != m_scripts.end()) it->second->setSource(newSource); |
513 | 555 |
514 std::unique_ptr<Array<CallFrame>> callFrames; | 556 std::unique_ptr<Array<CallFrame>> callFrames; |
515 response = currentCallFrames(&callFrames); | 557 response = currentCallFrames(&callFrames); |
516 if (!response.isSuccess()) return response; | 558 if (!response.isSuccess()) return response; |
517 *newCallFrames = std::move(callFrames); | 559 *newCallFrames = std::move(callFrames); |
518 *asyncStackTrace = currentAsyncStackTrace(); | 560 *asyncStackTrace = currentAsyncStackTrace(); |
519 return Response::OK(); | 561 return Response::OK(); |
520 } | 562 } |
521 | 563 |
522 Response V8DebuggerAgentImpl::restartFrame( | 564 Response V8DebuggerAgentImpl::restartFrame( |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 | 1218 |
1177 void V8DebuggerAgentImpl::reset() { | 1219 void V8DebuggerAgentImpl::reset() { |
1178 if (!enabled()) return; | 1220 if (!enabled()) return; |
1179 m_scheduledDebuggerStep = NoStep; | 1221 m_scheduledDebuggerStep = NoStep; |
1180 m_scripts.clear(); | 1222 m_scripts.clear(); |
1181 m_blackboxedPositions.clear(); | 1223 m_blackboxedPositions.clear(); |
1182 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1224 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1183 } | 1225 } |
1184 | 1226 |
1185 } // namespace v8_inspector | 1227 } // namespace v8_inspector |
OLD | NEW |