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 25 matching lines...) Expand all Loading... | |
36 using protocol::Runtime::ScriptId; | 36 using protocol::Runtime::ScriptId; |
37 using protocol::Runtime::StackTrace; | 37 using protocol::Runtime::StackTrace; |
38 using protocol::Runtime::RemoteObject; | 38 using protocol::Runtime::RemoteObject; |
39 | 39 |
40 namespace DebuggerAgentState { | 40 namespace DebuggerAgentState { |
41 static const char javaScriptBreakpoints[] = "javaScriptBreakopints"; | 41 static const char javaScriptBreakpoints[] = "javaScriptBreakopints"; |
42 static const char pauseOnExceptionsState[] = "pauseOnExceptionsState"; | 42 static const char pauseOnExceptionsState[] = "pauseOnExceptionsState"; |
43 static const char asyncCallStackDepth[] = "asyncCallStackDepth"; | 43 static const char asyncCallStackDepth[] = "asyncCallStackDepth"; |
44 static const char blackboxPattern[] = "blackboxPattern"; | 44 static const char blackboxPattern[] = "blackboxPattern"; |
45 static const char debuggerEnabled[] = "debuggerEnabled"; | 45 static const char debuggerEnabled[] = "debuggerEnabled"; |
46 static const char skipAllPauses[] = "skipAllPauses"; | |
46 | 47 |
47 // Breakpoint properties. | 48 // Breakpoint properties. |
48 static const char url[] = "url"; | 49 static const char url[] = "url"; |
49 static const char isRegex[] = "isRegex"; | 50 static const char isRegex[] = "isRegex"; |
50 static const char lineNumber[] = "lineNumber"; | 51 static const char lineNumber[] = "lineNumber"; |
51 static const char columnNumber[] = "columnNumber"; | 52 static const char columnNumber[] = "columnNumber"; |
52 static const char condition[] = "condition"; | 53 static const char condition[] = "condition"; |
53 static const char skipAllPauses[] = "skipAllPauses"; | 54 static const char hint[] = "hint"; |
54 | 55 |
55 } // namespace DebuggerAgentState | 56 } // namespace DebuggerAgentState |
56 | 57 |
57 static const char kBacktraceObjectGroup[] = "backtrace"; | 58 static const char kBacktraceObjectGroup[] = "backtrace"; |
58 static const char kDebuggerNotEnabled[] = "Debugger agent is not enabled"; | 59 static const char kDebuggerNotEnabled[] = "Debugger agent is not enabled"; |
59 static const char kDebuggerNotPaused[] = | 60 static const char kDebuggerNotPaused[] = |
60 "Can only perform operation while paused."; | 61 "Can only perform operation while paused."; |
61 | 62 |
63 static const size_t kBreakpointHintMaxLength = 128; | |
64 static const intptr_t kBreakpointHintMaxSearchOffset = 80 * 10; | |
65 | |
62 namespace { | 66 namespace { |
63 | 67 |
64 void TranslateWasmStackTraceLocations(Array<CallFrame>* stackTrace, | 68 void TranslateWasmStackTraceLocations(Array<CallFrame>* stackTrace, |
65 WasmTranslation* wasmTranslation) { | 69 WasmTranslation* wasmTranslation) { |
66 for (size_t i = 0, e = stackTrace->length(); i != e; ++i) { | 70 for (size_t i = 0, e = stackTrace->length(); i != e; ++i) { |
67 protocol::Debugger::Location* location = stackTrace->get(i)->getLocation(); | 71 protocol::Debugger::Location* location = stackTrace->get(i)->getLocation(); |
68 String16 scriptId = location->getScriptId(); | 72 String16 scriptId = location->getScriptId(); |
69 int lineNumber = location->getLineNumber(); | 73 int lineNumber = location->getLineNumber(); |
70 int columnNumber = location->getColumnNumber(-1); | 74 int columnNumber = location->getColumnNumber(-1); |
71 | 75 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 | 116 |
113 std::unique_ptr<protocol::Debugger::Location> buildProtocolLocation( | 117 std::unique_ptr<protocol::Debugger::Location> buildProtocolLocation( |
114 const String16& scriptId, int lineNumber, int columnNumber) { | 118 const String16& scriptId, int lineNumber, int columnNumber) { |
115 return protocol::Debugger::Location::create() | 119 return protocol::Debugger::Location::create() |
116 .setScriptId(scriptId) | 120 .setScriptId(scriptId) |
117 .setLineNumber(lineNumber) | 121 .setLineNumber(lineNumber) |
118 .setColumnNumber(columnNumber) | 122 .setColumnNumber(columnNumber) |
119 .build(); | 123 .build(); |
120 } | 124 } |
121 | 125 |
126 String16 breakpointHint(const V8DebuggerScript& script, | |
127 const ScriptBreakpoint& breakpoint) { | |
128 int offset = script.offset(breakpoint.line_number, breakpoint.column_number); | |
129 if (offset == V8DebuggerScript::kNoOffset) return String16(); | |
130 const String16& source = script.source(); | |
131 String16 hint = | |
132 source.substring(offset, kBreakpointHintMaxLength).stripWhiteSpace(); | |
133 for (size_t i = 0; i < hint.length(); ++i) { | |
134 if (hint[i] == '\r' || hint[i] == '\n' || hint[i] == ';') { | |
alph
2017/02/28 00:47:26
nit: drop {}
kozy
2017/02/28 01:56:26
v8 code style force me to put this brackets here.
| |
135 return hint.substring(0, i); | |
136 } | |
137 } | |
138 return hint; | |
139 } | |
140 | |
141 void adjustBreakpointLocation(const V8DebuggerScript& script, | |
142 const String16& hint, | |
143 ScriptBreakpoint* breakpoint) { | |
144 if (hint.isEmpty()) return; | |
145 intptr_t sourceOffset = | |
146 script.offset(breakpoint->line_number, breakpoint->column_number); | |
147 if (sourceOffset == V8DebuggerScript::kNoOffset) return; | |
148 | |
149 intptr_t startSourceOffset = std::max( | |
alph
2017/02/28 00:47:26
nit: searchRegionOffset
kozy
2017/02/28 01:56:26
Done.
| |
150 sourceOffset - kBreakpointHintMaxSearchOffset, static_cast<intptr_t>(0)); | |
151 size_t offset = sourceOffset - startSourceOffset; | |
152 String16 searchArea = script.source().substring( | |
153 startSourceOffset, offset + kBreakpointHintMaxSearchOffset); | |
154 | |
155 size_t nextMatch = searchArea.find(hint, offset); | |
156 size_t prevMatch = searchArea.reverseFind(hint, offset); | |
157 if (nextMatch == String16::kNotFound && prevMatch == String16::kNotFound) { | |
alph
2017/02/28 00:47:26
no need for {}
kozy
2017/02/28 01:56:26
Acknowledged.
| |
158 return; | |
159 } | |
160 size_t bestMatch; | |
161 if (nextMatch == String16::kNotFound) { | |
162 bestMatch = prevMatch; | |
163 } else if (prevMatch == String16::kNotFound) { | |
164 bestMatch = nextMatch; | |
165 } else { | |
166 bestMatch = nextMatch - offset < offset - prevMatch ? nextMatch : prevMatch; | |
167 } | |
168 bestMatch += startSourceOffset; | |
169 v8::debug::Location hintPosition = script.location(bestMatch); | |
170 if (hintPosition.IsEmpty()) return; | |
171 breakpoint->line_number = hintPosition.GetLineNumber(); | |
172 breakpoint->column_number = hintPosition.GetColumnNumber(); | |
173 } | |
122 } // namespace | 174 } // namespace |
123 | 175 |
124 V8DebuggerAgentImpl::V8DebuggerAgentImpl( | 176 V8DebuggerAgentImpl::V8DebuggerAgentImpl( |
125 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, | 177 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, |
126 protocol::DictionaryValue* state) | 178 protocol::DictionaryValue* state) |
127 : m_inspector(session->inspector()), | 179 : m_inspector(session->inspector()), |
128 m_debugger(m_inspector->debugger()), | 180 m_debugger(m_inspector->debugger()), |
129 m_session(session), | 181 m_session(session), |
130 m_enabled(false), | 182 m_enabled(false), |
131 m_state(state), | 183 m_state(state), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 284 |
233 Response V8DebuggerAgentImpl::setSkipAllPauses(bool skip) { | 285 Response V8DebuggerAgentImpl::setSkipAllPauses(bool skip) { |
234 m_state->setBoolean(DebuggerAgentState::skipAllPauses, skip); | 286 m_state->setBoolean(DebuggerAgentState::skipAllPauses, skip); |
235 m_skipAllPauses = skip; | 287 m_skipAllPauses = skip; |
236 return Response::OK(); | 288 return Response::OK(); |
237 } | 289 } |
238 | 290 |
239 static std::unique_ptr<protocol::DictionaryValue> | 291 static std::unique_ptr<protocol::DictionaryValue> |
240 buildObjectForBreakpointCookie(const String16& url, int lineNumber, | 292 buildObjectForBreakpointCookie(const String16& url, int lineNumber, |
241 int columnNumber, const String16& condition, | 293 int columnNumber, const String16& condition, |
242 bool isRegex) { | 294 bool isRegex, const String16& hint) { |
243 std::unique_ptr<protocol::DictionaryValue> breakpointObject = | 295 std::unique_ptr<protocol::DictionaryValue> breakpointObject = |
244 protocol::DictionaryValue::create(); | 296 protocol::DictionaryValue::create(); |
245 breakpointObject->setString(DebuggerAgentState::url, url); | 297 breakpointObject->setString(DebuggerAgentState::url, url); |
246 breakpointObject->setInteger(DebuggerAgentState::lineNumber, lineNumber); | 298 breakpointObject->setInteger(DebuggerAgentState::lineNumber, lineNumber); |
247 breakpointObject->setInteger(DebuggerAgentState::columnNumber, columnNumber); | 299 breakpointObject->setInteger(DebuggerAgentState::columnNumber, columnNumber); |
248 breakpointObject->setString(DebuggerAgentState::condition, condition); | 300 breakpointObject->setString(DebuggerAgentState::condition, condition); |
249 breakpointObject->setBoolean(DebuggerAgentState::isRegex, isRegex); | 301 breakpointObject->setBoolean(DebuggerAgentState::isRegex, isRegex); |
302 if (!hint.isEmpty()) { | |
303 breakpointObject->setString(DebuggerAgentState::hint, hint); | |
304 } | |
250 return breakpointObject; | 305 return breakpointObject; |
251 } | 306 } |
252 | 307 |
253 static bool matches(V8InspectorImpl* inspector, const String16& url, | 308 static bool matches(V8InspectorImpl* inspector, const String16& url, |
254 const String16& pattern, bool isRegex) { | 309 const String16& pattern, bool isRegex) { |
255 if (isRegex) { | 310 if (isRegex) { |
256 V8Regex regex(inspector, pattern, true); | 311 V8Regex regex(inspector, pattern, true); |
257 return regex.match(url) != -1; | 312 return regex.match(url) != -1; |
258 } | 313 } |
259 return url == pattern; | 314 return url == pattern; |
(...skipping 26 matching lines...) Expand all Loading... | |
286 if (!breakpointsCookie) { | 341 if (!breakpointsCookie) { |
287 std::unique_ptr<protocol::DictionaryValue> newValue = | 342 std::unique_ptr<protocol::DictionaryValue> newValue = |
288 protocol::DictionaryValue::create(); | 343 protocol::DictionaryValue::create(); |
289 breakpointsCookie = newValue.get(); | 344 breakpointsCookie = newValue.get(); |
290 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, | 345 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, |
291 std::move(newValue)); | 346 std::move(newValue)); |
292 } | 347 } |
293 if (breakpointsCookie->get(breakpointId)) | 348 if (breakpointsCookie->get(breakpointId)) |
294 return Response::Error("Breakpoint at specified location already exists."); | 349 return Response::Error("Breakpoint at specified location already exists."); |
295 | 350 |
296 breakpointsCookie->setObject( | 351 String16 hint; |
297 breakpointId, buildObjectForBreakpointCookie( | |
298 url, lineNumber, columnNumber, condition, isRegex)); | |
299 | |
300 ScriptBreakpoint breakpoint(String16(), lineNumber, columnNumber, condition); | 352 ScriptBreakpoint breakpoint(String16(), lineNumber, columnNumber, condition); |
301 for (const auto& script : m_scripts) { | 353 for (const auto& script : m_scripts) { |
302 if (!matches(m_inspector, script.second->sourceURL(), url, isRegex)) | 354 if (!matches(m_inspector, script.second->sourceURL(), url, isRegex)) |
303 continue; | 355 continue; |
304 breakpoint.script_id = script.first; | 356 breakpoint.script_id = script.first; |
305 std::unique_ptr<protocol::Debugger::Location> location = | 357 std::unique_ptr<protocol::Debugger::Location> location = |
306 resolveBreakpoint(breakpointId, breakpoint, UserBreakpointSource); | 358 resolveBreakpoint(breakpointId, breakpoint, UserBreakpointSource, hint); |
359 if (!isRegex) hint = breakpointHint(*script.second, breakpoint); | |
307 if (location) (*locations)->addItem(std::move(location)); | 360 if (location) (*locations)->addItem(std::move(location)); |
308 } | 361 } |
309 | 362 |
363 breakpointsCookie->setObject( | |
364 breakpointId, | |
365 buildObjectForBreakpointCookie(url, lineNumber, columnNumber, condition, | |
366 isRegex, hint)); | |
367 | |
310 *outBreakpointId = breakpointId; | 368 *outBreakpointId = breakpointId; |
311 return Response::OK(); | 369 return Response::OK(); |
312 } | 370 } |
313 | 371 |
314 Response V8DebuggerAgentImpl::setBreakpoint( | 372 Response V8DebuggerAgentImpl::setBreakpoint( |
315 std::unique_ptr<protocol::Debugger::Location> location, | 373 std::unique_ptr<protocol::Debugger::Location> location, |
316 Maybe<String16> optionalCondition, String16* outBreakpointId, | 374 Maybe<String16> optionalCondition, String16* outBreakpointId, |
317 std::unique_ptr<protocol::Debugger::Location>* actualLocation) { | 375 std::unique_ptr<protocol::Debugger::Location>* actualLocation) { |
318 ScriptBreakpoint breakpoint( | 376 ScriptBreakpoint breakpoint( |
319 location->getScriptId(), location->getLineNumber(), | 377 location->getScriptId(), location->getLineNumber(), |
320 location->getColumnNumber(0), optionalCondition.fromMaybe(String16())); | 378 location->getColumnNumber(0), optionalCondition.fromMaybe(String16())); |
321 | 379 |
322 String16 breakpointId = | 380 String16 breakpointId = |
323 generateBreakpointId(breakpoint, UserBreakpointSource); | 381 generateBreakpointId(breakpoint, UserBreakpointSource); |
324 if (m_breakpointIdToDebuggerBreakpointIds.find(breakpointId) != | 382 if (m_breakpointIdToDebuggerBreakpointIds.find(breakpointId) != |
325 m_breakpointIdToDebuggerBreakpointIds.end()) { | 383 m_breakpointIdToDebuggerBreakpointIds.end()) { |
326 return Response::Error("Breakpoint at specified location already exists."); | 384 return Response::Error("Breakpoint at specified location already exists."); |
327 } | 385 } |
328 *actualLocation = | 386 *actualLocation = resolveBreakpoint( |
329 resolveBreakpoint(breakpointId, breakpoint, UserBreakpointSource); | 387 breakpointId, breakpoint, UserBreakpointSource, /* hint */ String16()); |
330 if (!*actualLocation) return Response::Error("Could not resolve breakpoint"); | 388 if (!*actualLocation) return Response::Error("Could not resolve breakpoint"); |
331 *outBreakpointId = breakpointId; | 389 *outBreakpointId = breakpointId; |
332 return Response::OK(); | 390 return Response::OK(); |
333 } | 391 } |
334 | 392 |
335 Response V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId) { | 393 Response V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId) { |
336 if (!enabled()) return Response::Error(kDebuggerNotEnabled); | 394 if (!enabled()) return Response::Error(kDebuggerNotEnabled); |
337 protocol::DictionaryValue* breakpointsCookie = | 395 protocol::DictionaryValue* breakpointsCookie = |
338 m_state->getObject(DebuggerAgentState::javaScriptBreakpoints); | 396 m_state->getObject(DebuggerAgentState::javaScriptBreakpoints); |
339 if (breakpointsCookie) breakpointsCookie->remove(breakpointId); | 397 if (breakpointsCookie) breakpointsCookie->remove(breakpointId); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 // Ranges array contains positions in script where blackbox state is changed. | 508 // Ranges array contains positions in script where blackbox state is changed. |
451 // [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is | 509 // [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is |
452 // blackboxed... | 510 // blackboxed... |
453 return itStartRange == itEndRange && | 511 return itStartRange == itEndRange && |
454 std::distance(ranges.begin(), itStartRange) % 2; | 512 std::distance(ranges.begin(), itStartRange) % 2; |
455 } | 513 } |
456 | 514 |
457 std::unique_ptr<protocol::Debugger::Location> | 515 std::unique_ptr<protocol::Debugger::Location> |
458 V8DebuggerAgentImpl::resolveBreakpoint(const String16& breakpointId, | 516 V8DebuggerAgentImpl::resolveBreakpoint(const String16& breakpointId, |
459 const ScriptBreakpoint& breakpoint, | 517 const ScriptBreakpoint& breakpoint, |
460 BreakpointSource source) { | 518 BreakpointSource source, |
519 const String16& hint) { | |
461 v8::HandleScope handles(m_isolate); | 520 v8::HandleScope handles(m_isolate); |
462 DCHECK(enabled()); | 521 DCHECK(enabled()); |
463 // FIXME: remove these checks once crbug.com/520702 is resolved. | 522 // FIXME: remove these checks once crbug.com/520702 is resolved. |
464 CHECK(!breakpointId.isEmpty()); | 523 CHECK(!breakpointId.isEmpty()); |
465 CHECK(!breakpoint.script_id.isEmpty()); | 524 CHECK(!breakpoint.script_id.isEmpty()); |
466 ScriptsMap::iterator scriptIterator = m_scripts.find(breakpoint.script_id); | 525 ScriptsMap::iterator scriptIterator = m_scripts.find(breakpoint.script_id); |
467 if (scriptIterator == m_scripts.end()) return nullptr; | 526 if (scriptIterator == m_scripts.end()) return nullptr; |
468 if (breakpoint.line_number < scriptIterator->second->startLine() || | 527 if (breakpoint.line_number < scriptIterator->second->startLine() || |
469 scriptIterator->second->endLine() < breakpoint.line_number) | 528 scriptIterator->second->endLine() < breakpoint.line_number) |
470 return nullptr; | 529 return nullptr; |
471 | 530 |
472 // Translate from protocol location to v8 location for the debugger. | 531 // Translate from protocol location to v8 location for the debugger. |
473 ScriptBreakpoint translatedBreakpoint = breakpoint; | 532 ScriptBreakpoint translatedBreakpoint = breakpoint; |
533 adjustBreakpointLocation(*scriptIterator->second, hint, | |
534 &translatedBreakpoint); | |
474 m_debugger->wasmTranslation()->TranslateProtocolLocationToWasmScriptLocation( | 535 m_debugger->wasmTranslation()->TranslateProtocolLocationToWasmScriptLocation( |
475 &translatedBreakpoint.script_id, &translatedBreakpoint.line_number, | 536 &translatedBreakpoint.script_id, &translatedBreakpoint.line_number, |
476 &translatedBreakpoint.column_number); | 537 &translatedBreakpoint.column_number); |
477 | 538 |
478 int actualLineNumber; | 539 int actualLineNumber; |
479 int actualColumnNumber; | 540 int actualColumnNumber; |
480 String16 debuggerBreakpointId = m_debugger->setBreakpoint( | 541 String16 debuggerBreakpointId = m_debugger->setBreakpoint( |
481 translatedBreakpoint, &actualLineNumber, &actualColumnNumber); | 542 translatedBreakpoint, &actualLineNumber, &actualColumnNumber); |
482 if (debuggerBreakpointId.isEmpty()) return nullptr; | 543 if (debuggerBreakpointId.isEmpty()) return nullptr; |
483 | 544 |
(...skipping 14 matching lines...) Expand all Loading... | |
498 Response V8DebuggerAgentImpl::searchInContent( | 559 Response V8DebuggerAgentImpl::searchInContent( |
499 const String16& scriptId, const String16& query, | 560 const String16& scriptId, const String16& query, |
500 Maybe<bool> optionalCaseSensitive, Maybe<bool> optionalIsRegex, | 561 Maybe<bool> optionalCaseSensitive, Maybe<bool> optionalIsRegex, |
501 std::unique_ptr<Array<protocol::Debugger::SearchMatch>>* results) { | 562 std::unique_ptr<Array<protocol::Debugger::SearchMatch>>* results) { |
502 v8::HandleScope handles(m_isolate); | 563 v8::HandleScope handles(m_isolate); |
503 ScriptsMap::iterator it = m_scripts.find(scriptId); | 564 ScriptsMap::iterator it = m_scripts.find(scriptId); |
504 if (it == m_scripts.end()) | 565 if (it == m_scripts.end()) |
505 return Response::Error("No script for id: " + scriptId); | 566 return Response::Error("No script for id: " + scriptId); |
506 | 567 |
507 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = | 568 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = |
508 searchInTextByLinesImpl(m_session, it->second->source(m_isolate), query, | 569 searchInTextByLinesImpl(m_session, it->second->source(), query, |
509 optionalCaseSensitive.fromMaybe(false), | 570 optionalCaseSensitive.fromMaybe(false), |
510 optionalIsRegex.fromMaybe(false)); | 571 optionalIsRegex.fromMaybe(false)); |
511 *results = protocol::Array<protocol::Debugger::SearchMatch>::create(); | 572 *results = protocol::Array<protocol::Debugger::SearchMatch>::create(); |
512 for (size_t i = 0; i < matches.size(); ++i) | 573 for (size_t i = 0; i < matches.size(); ++i) |
513 (*results)->addItem(std::move(matches[i])); | 574 (*results)->addItem(std::move(matches[i])); |
514 return Response::OK(); | 575 return Response::OK(); |
515 } | 576 } |
516 | 577 |
517 Response V8DebuggerAgentImpl::setScriptSource( | 578 Response V8DebuggerAgentImpl::setScriptSource( |
518 const String16& scriptId, const String16& newContent, Maybe<bool> dryRun, | 579 const String16& scriptId, const String16& newContent, Maybe<bool> dryRun, |
(...skipping 12 matching lines...) Expand all Loading... | |
531 } | 592 } |
532 | 593 |
533 v8::HandleScope handles(m_isolate); | 594 v8::HandleScope handles(m_isolate); |
534 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent); | 595 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent); |
535 bool compileError = false; | 596 bool compileError = false; |
536 Response response = m_debugger->setScriptSource( | 597 Response response = m_debugger->setScriptSource( |
537 scriptId, newSource, dryRun.fromMaybe(false), optOutCompileError, | 598 scriptId, newSource, dryRun.fromMaybe(false), optOutCompileError, |
538 &m_pausedCallFrames, stackChanged, &compileError); | 599 &m_pausedCallFrames, stackChanged, &compileError); |
539 if (!response.isSuccess() || compileError) return response; | 600 if (!response.isSuccess() || compileError) return response; |
540 | 601 |
541 it->second->setSource(newSource); | 602 it->second->setSource(newContent); |
542 std::unique_ptr<Array<CallFrame>> callFrames; | 603 std::unique_ptr<Array<CallFrame>> callFrames; |
543 response = currentCallFrames(&callFrames); | 604 response = currentCallFrames(&callFrames); |
544 if (!response.isSuccess()) return response; | 605 if (!response.isSuccess()) return response; |
545 *newCallFrames = std::move(callFrames); | 606 *newCallFrames = std::move(callFrames); |
546 *asyncStackTrace = currentAsyncStackTrace(); | 607 *asyncStackTrace = currentAsyncStackTrace(); |
547 return Response::OK(); | 608 return Response::OK(); |
548 } | 609 } |
549 | 610 |
550 Response V8DebuggerAgentImpl::restartFrame( | 611 Response V8DebuggerAgentImpl::restartFrame( |
551 const String16& callFrameId, | 612 const String16& callFrameId, |
(...skipping 24 matching lines...) Expand all Loading... | |
576 *asyncStackTrace = currentAsyncStackTrace(); | 637 *asyncStackTrace = currentAsyncStackTrace(); |
577 return Response::OK(); | 638 return Response::OK(); |
578 } | 639 } |
579 | 640 |
580 Response V8DebuggerAgentImpl::getScriptSource(const String16& scriptId, | 641 Response V8DebuggerAgentImpl::getScriptSource(const String16& scriptId, |
581 String16* scriptSource) { | 642 String16* scriptSource) { |
582 if (!enabled()) return Response::Error(kDebuggerNotEnabled); | 643 if (!enabled()) return Response::Error(kDebuggerNotEnabled); |
583 ScriptsMap::iterator it = m_scripts.find(scriptId); | 644 ScriptsMap::iterator it = m_scripts.find(scriptId); |
584 if (it == m_scripts.end()) | 645 if (it == m_scripts.end()) |
585 return Response::Error("No script for id: " + scriptId); | 646 return Response::Error("No script for id: " + scriptId); |
586 v8::HandleScope handles(m_isolate); | 647 *scriptSource = it->second->source(); |
587 *scriptSource = it->second->source(m_isolate); | |
588 return Response::OK(); | 648 return Response::OK(); |
589 } | 649 } |
590 | 650 |
591 void V8DebuggerAgentImpl::pushBreakDetails( | 651 void V8DebuggerAgentImpl::pushBreakDetails( |
592 const String16& breakReason, | 652 const String16& breakReason, |
593 std::unique_ptr<protocol::DictionaryValue> breakAuxData) { | 653 std::unique_ptr<protocol::DictionaryValue> breakAuxData) { |
594 m_breakReason.push_back(std::make_pair(breakReason, std::move(breakAuxData))); | 654 m_breakReason.push_back(std::make_pair(breakReason, std::move(breakAuxData))); |
595 } | 655 } |
596 | 656 |
597 void V8DebuggerAgentImpl::popBreakDetails() { | 657 void V8DebuggerAgentImpl::popBreakDetails() { |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 V8StackTraceImpl* stackTrace = m_debugger->currentAsyncCallChain(); | 1046 V8StackTraceImpl* stackTrace = m_debugger->currentAsyncCallChain(); |
987 return stackTrace ? stackTrace->buildInspectorObjectForTail(m_debugger) | 1047 return stackTrace ? stackTrace->buildInspectorObjectForTail(m_debugger) |
988 : nullptr; | 1048 : nullptr; |
989 } | 1049 } |
990 | 1050 |
991 bool V8DebuggerAgentImpl::isPaused() const { return m_debugger->isPaused(); } | 1051 bool V8DebuggerAgentImpl::isPaused() const { return m_debugger->isPaused(); } |
992 | 1052 |
993 void V8DebuggerAgentImpl::didParseSource( | 1053 void V8DebuggerAgentImpl::didParseSource( |
994 std::unique_ptr<V8DebuggerScript> script, bool success) { | 1054 std::unique_ptr<V8DebuggerScript> script, bool success) { |
995 v8::HandleScope handles(m_isolate); | 1055 v8::HandleScope handles(m_isolate); |
996 String16 scriptSource = script->source(m_isolate); | 1056 String16 scriptSource = script->source(); |
997 if (!success) script->setSourceURL(findSourceURL(scriptSource, false)); | 1057 if (!success) script->setSourceURL(findSourceURL(scriptSource, false)); |
998 if (!success) | 1058 if (!success) |
999 script->setSourceMappingURL(findSourceMapURL(scriptSource, false)); | 1059 script->setSourceMappingURL(findSourceMapURL(scriptSource, false)); |
1000 | 1060 |
1001 int contextId = script->executionContextId(); | 1061 int contextId = script->executionContextId(); |
1002 int contextGroupId = m_inspector->contextGroupId(contextId); | 1062 int contextGroupId = m_inspector->contextGroupId(contextId); |
1003 InspectedContext* inspected = | 1063 InspectedContext* inspected = |
1004 m_inspector->getContext(contextGroupId, contextId); | 1064 m_inspector->getContext(contextGroupId, contextId); |
1005 std::unique_ptr<protocol::DictionaryValue> executionContextAuxData; | 1065 std::unique_ptr<protocol::DictionaryValue> executionContextAuxData; |
1006 if (inspected) { | 1066 if (inspected) { |
(...skipping 22 matching lines...) Expand all Loading... | |
1029 Maybe<String16> sourceMapURLParam = scriptRef->sourceMappingURL(); | 1089 Maybe<String16> sourceMapURLParam = scriptRef->sourceMappingURL(); |
1030 Maybe<protocol::DictionaryValue> executionContextAuxDataParam( | 1090 Maybe<protocol::DictionaryValue> executionContextAuxDataParam( |
1031 std::move(executionContextAuxData)); | 1091 std::move(executionContextAuxData)); |
1032 const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr; | 1092 const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr; |
1033 const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr; | 1093 const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr; |
1034 const bool* isModuleParam = isModule ? &isModule : nullptr; | 1094 const bool* isModuleParam = isModule ? &isModule : nullptr; |
1035 if (success) | 1095 if (success) |
1036 m_frontend.scriptParsed( | 1096 m_frontend.scriptParsed( |
1037 scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(), | 1097 scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(), |
1038 scriptRef->endLine(), scriptRef->endColumn(), contextId, | 1098 scriptRef->endLine(), scriptRef->endColumn(), contextId, |
1039 scriptRef->hash(m_isolate), std::move(executionContextAuxDataParam), | 1099 scriptRef->hash(), std::move(executionContextAuxDataParam), |
1040 isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam, | 1100 isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam, |
1041 isModuleParam); | 1101 isModuleParam); |
1042 else | 1102 else |
1043 m_frontend.scriptFailedToParse( | 1103 m_frontend.scriptFailedToParse( |
1044 scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(), | 1104 scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(), |
1045 scriptRef->endLine(), scriptRef->endColumn(), contextId, | 1105 scriptRef->endLine(), scriptRef->endColumn(), contextId, |
1046 scriptRef->hash(m_isolate), std::move(executionContextAuxDataParam), | 1106 scriptRef->hash(), std::move(executionContextAuxDataParam), |
1047 std::move(sourceMapURLParam), hasSourceURLParam, isModuleParam); | 1107 std::move(sourceMapURLParam), hasSourceURLParam, isModuleParam); |
1048 | 1108 |
1049 if (scriptURL.isEmpty() || !success) return; | 1109 if (scriptURL.isEmpty() || !success) return; |
1050 | 1110 |
1051 protocol::DictionaryValue* breakpointsCookie = | 1111 protocol::DictionaryValue* breakpointsCookie = |
1052 m_state->getObject(DebuggerAgentState::javaScriptBreakpoints); | 1112 m_state->getObject(DebuggerAgentState::javaScriptBreakpoints); |
1053 if (!breakpointsCookie) return; | 1113 if (!breakpointsCookie) return; |
1054 | 1114 |
1055 for (size_t i = 0; i < breakpointsCookie->size(); ++i) { | 1115 for (size_t i = 0; i < breakpointsCookie->size(); ++i) { |
1056 auto cookie = breakpointsCookie->at(i); | 1116 auto cookie = breakpointsCookie->at(i); |
1057 protocol::DictionaryValue* breakpointObject = | 1117 protocol::DictionaryValue* breakpointObject = |
1058 protocol::DictionaryValue::cast(cookie.second); | 1118 protocol::DictionaryValue::cast(cookie.second); |
1059 bool isRegex; | 1119 bool isRegex; |
1060 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex); | 1120 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex); |
1061 String16 url; | 1121 String16 url; |
1062 breakpointObject->getString(DebuggerAgentState::url, &url); | 1122 breakpointObject->getString(DebuggerAgentState::url, &url); |
1063 if (!matches(m_inspector, scriptURL, url, isRegex)) continue; | 1123 if (!matches(m_inspector, scriptURL, url, isRegex)) continue; |
1064 ScriptBreakpoint breakpoint; | 1124 ScriptBreakpoint breakpoint; |
1065 breakpoint.script_id = scriptId; | 1125 breakpoint.script_id = scriptId; |
1066 breakpointObject->getInteger(DebuggerAgentState::lineNumber, | 1126 breakpointObject->getInteger(DebuggerAgentState::lineNumber, |
1067 &breakpoint.line_number); | 1127 &breakpoint.line_number); |
1068 breakpointObject->getInteger(DebuggerAgentState::columnNumber, | 1128 breakpointObject->getInteger(DebuggerAgentState::columnNumber, |
1069 &breakpoint.column_number); | 1129 &breakpoint.column_number); |
1070 breakpointObject->getString(DebuggerAgentState::condition, | 1130 breakpointObject->getString(DebuggerAgentState::condition, |
1071 &breakpoint.condition); | 1131 &breakpoint.condition); |
1132 String16 hint; | |
1133 bool hasHint = breakpointObject->getString(DebuggerAgentState::hint, &hint); | |
1072 std::unique_ptr<protocol::Debugger::Location> location = | 1134 std::unique_ptr<protocol::Debugger::Location> location = |
1073 resolveBreakpoint(cookie.first, breakpoint, UserBreakpointSource); | 1135 resolveBreakpoint(cookie.first, breakpoint, UserBreakpointSource, hint); |
1136 if (!hasHint) { | |
1137 hint = breakpointHint(*scriptRef, breakpoint); | |
1138 if (!hint.isEmpty()) | |
1139 breakpointObject->setString(DebuggerAgentState::hint, hint); | |
1140 } | |
1074 if (location) | 1141 if (location) |
1075 m_frontend.breakpointResolved(cookie.first, std::move(location)); | 1142 m_frontend.breakpointResolved(cookie.first, std::move(location)); |
1076 } | 1143 } |
1077 } | 1144 } |
1078 | 1145 |
1079 void V8DebuggerAgentImpl::didPause(int contextId, | 1146 void V8DebuggerAgentImpl::didPause(int contextId, |
1080 v8::Local<v8::Value> exception, | 1147 v8::Local<v8::Value> exception, |
1081 const std::vector<String16>& hitBreakpoints, | 1148 const std::vector<String16>& hitBreakpoints, |
1082 bool isPromiseRejection, bool isUncaught, | 1149 bool isPromiseRejection, bool isUncaught, |
1083 bool isOOMBreak) { | 1150 bool isOOMBreak) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 return; | 1269 return; |
1203 breakProgram(breakReason, std::move(data)); | 1270 breakProgram(breakReason, std::move(data)); |
1204 } | 1271 } |
1205 | 1272 |
1206 void V8DebuggerAgentImpl::setBreakpointAt(const String16& scriptId, | 1273 void V8DebuggerAgentImpl::setBreakpointAt(const String16& scriptId, |
1207 int lineNumber, int columnNumber, | 1274 int lineNumber, int columnNumber, |
1208 BreakpointSource source, | 1275 BreakpointSource source, |
1209 const String16& condition) { | 1276 const String16& condition) { |
1210 ScriptBreakpoint breakpoint(scriptId, lineNumber, columnNumber, condition); | 1277 ScriptBreakpoint breakpoint(scriptId, lineNumber, columnNumber, condition); |
1211 String16 breakpointId = generateBreakpointId(breakpoint, source); | 1278 String16 breakpointId = generateBreakpointId(breakpoint, source); |
1212 resolveBreakpoint(breakpointId, breakpoint, source); | 1279 resolveBreakpoint(breakpointId, breakpoint, source, /* hint */ String16()); |
1213 } | 1280 } |
1214 | 1281 |
1215 void V8DebuggerAgentImpl::removeBreakpointAt(const String16& scriptId, | 1282 void V8DebuggerAgentImpl::removeBreakpointAt(const String16& scriptId, |
1216 int lineNumber, int columnNumber, | 1283 int lineNumber, int columnNumber, |
1217 BreakpointSource source) { | 1284 BreakpointSource source) { |
1218 removeBreakpointImpl(generateBreakpointId( | 1285 removeBreakpointImpl(generateBreakpointId( |
1219 ScriptBreakpoint(scriptId, lineNumber, columnNumber, String16()), | 1286 ScriptBreakpoint(scriptId, lineNumber, columnNumber, String16()), |
1220 source)); | 1287 source)); |
1221 } | 1288 } |
1222 | 1289 |
1223 void V8DebuggerAgentImpl::reset() { | 1290 void V8DebuggerAgentImpl::reset() { |
1224 if (!enabled()) return; | 1291 if (!enabled()) return; |
1225 m_scheduledDebuggerStep = NoStep; | 1292 m_scheduledDebuggerStep = NoStep; |
1226 m_blackboxedPositions.clear(); | 1293 m_blackboxedPositions.clear(); |
1227 resetBlackboxedStateCache(); | 1294 resetBlackboxedStateCache(); |
1228 m_scripts.clear(); | 1295 m_scripts.clear(); |
1229 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1296 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1230 } | 1297 } |
1231 | 1298 |
1232 } // namespace v8_inspector | 1299 } // namespace v8_inspector |
OLD | NEW |