OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions |
| 7 * are met: |
| 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. |
| 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 15 * its contributors may be used to endorse or promote products derived |
| 16 * from this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ |
| 29 |
| 30 #include "config.h" |
| 31 #include "bindings/core/dart/DartInspectorDebuggerAgent.h" |
| 32 |
| 33 #include "bindings/common/ScriptValue.h" |
| 34 #include "bindings/core/dart/DartInjectedScriptManager.h" |
| 35 #include "bindings/core/dart/DartScriptDebugServer.h" |
| 36 #include "bindings/core/v8/ScriptDebugServer.h" |
| 37 #include "bindings/core/v8/ScriptRegexp.h" |
| 38 #include "bindings/core/v8/ScriptSourceCode.h" |
| 39 #include "core/dom/Document.h" |
| 40 #include "core/dom/ExecutionContextTask.h" |
| 41 #include "core/fetch/Resource.h" |
| 42 #include "core/inspector/ContentSearchUtils.h" |
| 43 #include "core/inspector/InspectorDebuggerAgent.h" |
| 44 #include "core/inspector/InspectorPageAgent.h" |
| 45 #include "core/inspector/InspectorState.h" |
| 46 #include "core/inspector/InstrumentingAgents.h" |
| 47 #include "core/inspector/JavaScriptCallFrame.h" |
| 48 #include "core/inspector/ScriptArguments.h" |
| 49 #include "core/inspector/ScriptCallFrame.h" |
| 50 #include "core/inspector/ScriptCallStack.h" |
| 51 #include "platform/JSONValues.h" |
| 52 #include "wtf/text/StringBuilder.h" |
| 53 #include "wtf/text/WTFString.h" |
| 54 |
| 55 using blink::TypeBuilder::Array; |
| 56 using blink::TypeBuilder::Debugger::BreakpointId; |
| 57 using blink::TypeBuilder::Debugger::CallFrame; |
| 58 using blink::TypeBuilder::Debugger::ExceptionDetails; |
| 59 using blink::TypeBuilder::Debugger::FunctionDetails; |
| 60 using blink::TypeBuilder::Debugger::ScriptId; |
| 61 using blink::TypeBuilder::Debugger::StackTrace; |
| 62 using blink::TypeBuilder::Runtime::RemoteObject; |
| 63 |
| 64 |
| 65 namespace blink { |
| 66 |
| 67 namespace DartDebuggerAgentState { |
| 68 static const char debuggerEnabled[] = "debuggerEnabledDart"; |
| 69 static const char dartBreakpoints[] = "dartBreakpoints"; |
| 70 static const char pauseOnExceptionsState[] = "dartPauseOnExceptionsState"; |
| 71 static const char asyncCallStackDepth[] = "dartAsyncCallStackDepth"; |
| 72 |
| 73 // Breakpoint properties. |
| 74 static const char url[] = "url"; |
| 75 static const char isRegex[] = "isRegex"; |
| 76 static const char lineNumber[] = "lineNumber"; |
| 77 static const char columnNumber[] = "columnNumber"; |
| 78 static const char condition[] = "condition"; |
| 79 static const char isAnti[] = "isAnti"; |
| 80 static const char skipStackPattern[] = "skipStackPattern"; |
| 81 static const char skipAllPauses[] = "skipAllPauses"; |
| 82 static const char skipAllPausesExpiresOnReload[] = "skipAllPausesExpiresOnReload
"; |
| 83 |
| 84 }; |
| 85 |
| 86 static const int maxSkipStepInCountDart = 20; |
| 87 |
| 88 const char DartInspectorDebuggerAgent::backtraceObjectGroup[] = "backtrace"; |
| 89 |
| 90 static String breakpointIdSuffixDart(DartInspectorDebuggerAgent::BreakpointSourc
e source) |
| 91 { |
| 92 switch (source) { |
| 93 case DartInspectorDebuggerAgent::UserBreakpointSource: |
| 94 break; |
| 95 case DartInspectorDebuggerAgent::DebugCommandBreakpointSource: |
| 96 return ":debug"; |
| 97 case DartInspectorDebuggerAgent::MonitorCommandBreakpointSource: |
| 98 return ":monitor"; |
| 99 } |
| 100 return String(); |
| 101 } |
| 102 |
| 103 static String generateBreakpointIdDart(const String& scriptId, int lineNumber, i
nt columnNumber, DartInspectorDebuggerAgent::BreakpointSource source) |
| 104 { |
| 105 return scriptId + ':' + String::number(lineNumber) + ':' + String::number(co
lumnNumber) + breakpointIdSuffixDart(source); |
| 106 } |
| 107 |
| 108 DartInspectorDebuggerAgent::DartInspectorDebuggerAgent(DartInjectedScriptManager
* injectedScriptManager, InspectorDebuggerAgent* inspectorDebuggerAgent, Inspect
orPageAgent* pageAgent) |
| 109 : m_injectedScriptManager(injectedScriptManager) |
| 110 , m_frontend(0) |
| 111 , m_pausedScriptState(nullptr) |
| 112 , m_currentCallStack(0) |
| 113 , m_javaScriptPauseScheduled(false) |
| 114 , m_debuggerStepScheduled(false) |
| 115 , m_steppingFromFramework(false) |
| 116 , m_pausingOnNativeEvent(false) |
| 117 , m_listener(nullptr) |
| 118 , m_skippedStepInCount(0) |
| 119 , m_skipAllPauses(false) |
| 120 , m_inspectorDebuggerAgent(inspectorDebuggerAgent) |
| 121 , m_pageAgent(pageAgent) |
| 122 { |
| 123 } |
| 124 |
| 125 DartInspectorDebuggerAgent::~DartInspectorDebuggerAgent() |
| 126 { |
| 127 } |
| 128 |
| 129 InspectorState* DartInspectorDebuggerAgent::state() |
| 130 { |
| 131 return m_inspectorDebuggerAgent->m_state.get(); |
| 132 } |
| 133 |
| 134 void DartInspectorDebuggerAgent::init() |
| 135 { |
| 136 // FIXME: make breakReason optional so that there was no need to init it wit
h "other". |
| 137 clearBreakDetails(); |
| 138 state()->setLong(DartDebuggerAgentState::pauseOnExceptionsState, ScriptDebug
Server::DontPauseOnExceptions); |
| 139 } |
| 140 |
| 141 void DartInspectorDebuggerAgent::enable() |
| 142 { |
| 143 startListeningScriptDebugServer(); |
| 144 // FIXME(WK44513): breakpoints activated flag should be synchronized between
all front-ends |
| 145 scriptDebugServer().setBreakpointsActivated(true); |
| 146 |
| 147 if (m_listener) |
| 148 m_listener->debuggerWasEnabled(); |
| 149 } |
| 150 |
| 151 void DartInspectorDebuggerAgent::disable() |
| 152 { |
| 153 state()->setObject(DartDebuggerAgentState::dartBreakpoints, JSONObject::crea
te()); |
| 154 state()->setLong(DartDebuggerAgentState::pauseOnExceptionsState, ScriptDebug
Server::DontPauseOnExceptions); |
| 155 state()->setString(DartDebuggerAgentState::skipStackPattern, ""); |
| 156 state()->setLong(DartDebuggerAgentState::asyncCallStackDepth, 0); |
| 157 |
| 158 scriptDebugServer().clearBreakpoints(); |
| 159 stopListeningScriptDebugServer(); |
| 160 clear(); |
| 161 |
| 162 if (m_listener) |
| 163 m_listener->debuggerWasDisabled(); |
| 164 |
| 165 m_skipAllPauses = false; |
| 166 } |
| 167 |
| 168 bool DartInspectorDebuggerAgent::enabled() |
| 169 { |
| 170 return state()->getBoolean(DartDebuggerAgentState::debuggerEnabled); |
| 171 } |
| 172 |
| 173 void DartInspectorDebuggerAgent::enable(ErrorString*) |
| 174 { |
| 175 if (enabled()) |
| 176 return; |
| 177 |
| 178 enable(); |
| 179 state()->setBoolean(DartDebuggerAgentState::debuggerEnabled, true); |
| 180 |
| 181 ASSERT(m_frontend); |
| 182 } |
| 183 |
| 184 void DartInspectorDebuggerAgent::disable(ErrorString*) |
| 185 { |
| 186 if (!enabled()) |
| 187 return; |
| 188 |
| 189 disable(); |
| 190 state()->setBoolean(DartDebuggerAgentState::debuggerEnabled, false); |
| 191 } |
| 192 |
| 193 static PassOwnPtr<ScriptRegexp> compileSkipCallFramePattern(String patternText) |
| 194 { |
| 195 if (patternText.isEmpty()) |
| 196 return nullptr; |
| 197 OwnPtr<ScriptRegexp> result = adoptPtr(new ScriptRegexp(patternText, TextCas
eSensitive)); |
| 198 if (!result->isValid()) |
| 199 result.clear(); |
| 200 return result.release(); |
| 201 } |
| 202 |
| 203 void DartInspectorDebuggerAgent::restore() |
| 204 { |
| 205 if (enabled()) { |
| 206 m_frontend->globalObjectCleared(); |
| 207 enable(); |
| 208 long pauseState = state()->getLong(DartDebuggerAgentState::pauseOnExcept
ionsState); |
| 209 String error; |
| 210 setPauseOnExceptionsImpl(&error, pauseState); |
| 211 m_cachedSkipStackRegExp = compileSkipCallFramePattern(state()->getString
(DartDebuggerAgentState::skipStackPattern)); |
| 212 m_skipAllPauses = state()->getBoolean(DartDebuggerAgentState::skipAllPau
ses); |
| 213 if (m_skipAllPauses && state()->getBoolean(DartDebuggerAgentState::skipA
llPausesExpiresOnReload)) { |
| 214 m_skipAllPauses = false; |
| 215 state()->setBoolean(DartDebuggerAgentState::skipAllPauses, false); |
| 216 } |
| 217 } |
| 218 } |
| 219 |
| 220 void DartInspectorDebuggerAgent::setFrontend(InspectorFrontend* frontend) |
| 221 { |
| 222 m_frontend = frontend->debugger(); |
| 223 } |
| 224 |
| 225 void DartInspectorDebuggerAgent::clearFrontend() |
| 226 { |
| 227 m_frontend = 0; |
| 228 |
| 229 if (!enabled()) |
| 230 return; |
| 231 |
| 232 disable(); |
| 233 |
| 234 // FIXME: due to state()->mute() hack in InspectorController, debuggerEnable
d is actually set to false only |
| 235 // in InspectorState, but not in cookie. That's why after navigation debugge
rEnabled will be true, |
| 236 // but after front-end re-open it will still be false. |
| 237 state()->setBoolean(DartDebuggerAgentState::debuggerEnabled, false); |
| 238 } |
| 239 |
| 240 void DartInspectorDebuggerAgent::setBreakpointsActive(ErrorString*, bool active) |
| 241 { |
| 242 scriptDebugServer().setBreakpointsActivated(active); |
| 243 } |
| 244 |
| 245 void DartInspectorDebuggerAgent::setSkipAllPauses(ErrorString*, bool skipped, co
nst bool* untilReload) |
| 246 { |
| 247 m_skipAllPauses = skipped; |
| 248 state()->setBoolean(DartDebuggerAgentState::skipAllPauses, m_skipAllPauses); |
| 249 state()->setBoolean(DartDebuggerAgentState::skipAllPausesExpiresOnReload, as
Bool(untilReload)); |
| 250 } |
| 251 |
| 252 void DartInspectorDebuggerAgent::pageDidCommitLoad() |
| 253 { |
| 254 if (state()->getBoolean(DartDebuggerAgentState::skipAllPausesExpiresOnReload
)) { |
| 255 m_skipAllPauses = false; |
| 256 state()->setBoolean(DartDebuggerAgentState::skipAllPauses, m_skipAllPaus
es); |
| 257 } |
| 258 } |
| 259 |
| 260 bool DartInspectorDebuggerAgent::isPaused() |
| 261 { |
| 262 return scriptDebugServer().isPaused(); |
| 263 } |
| 264 |
| 265 bool DartInspectorDebuggerAgent::runningNestedMessageLoop() |
| 266 { |
| 267 return scriptDebugServer().runningNestedMessageLoop(); |
| 268 } |
| 269 |
| 270 static PassRefPtr<JSONObject> buildObjectForBreakpointCookie(const String& url,
int lineNumber, int columnNumber, const String& condition, bool isRegex, bool is
Anti) |
| 271 { |
| 272 RefPtr<JSONObject> breakpointObject = JSONObject::create(); |
| 273 breakpointObject->setString(DartDebuggerAgentState::url, url); |
| 274 breakpointObject->setNumber(DartDebuggerAgentState::lineNumber, lineNumber); |
| 275 breakpointObject->setNumber(DartDebuggerAgentState::columnNumber, columnNumb
er); |
| 276 breakpointObject->setString(DartDebuggerAgentState::condition, condition); |
| 277 breakpointObject->setBoolean(DartDebuggerAgentState::isRegex, isRegex); |
| 278 breakpointObject->setBoolean(DartDebuggerAgentState::isAnti, isAnti); |
| 279 return breakpointObject; |
| 280 } |
| 281 |
| 282 static String scriptSourceURL(const DartScriptDebugListener::Script& script) |
| 283 { |
| 284 bool hasSourceURL = !script.sourceURL.isEmpty(); |
| 285 return hasSourceURL ? script.sourceURL : script.url; |
| 286 } |
| 287 |
| 288 static bool matches(const String& url, const String& pattern, bool isRegex) |
| 289 { |
| 290 if (isRegex) { |
| 291 ScriptRegexp regex(pattern, TextCaseSensitive); |
| 292 return regex.match(url) != -1; |
| 293 } |
| 294 return url == pattern; |
| 295 } |
| 296 |
| 297 void DartInspectorDebuggerAgent::setBreakpointByUrl(ErrorString* errorString, in
t lineNumber, const String* const optionalURL, const String* const optionalURLRe
gex, const int* const optionalColumnNumber, const String* const optionalConditio
n, const bool* isAntiBreakpoint, BreakpointId* outBreakpointId, RefPtr<Array<Typ
eBuilder::Debugger::Location> >& locations) |
| 298 { |
| 299 locations = Array<TypeBuilder::Debugger::Location>::create(); |
| 300 if (!optionalURL == !optionalURLRegex) { |
| 301 *errorString = "Either url or urlRegex must be specified."; |
| 302 return; |
| 303 } |
| 304 |
| 305 bool isAntiBreakpointValue = asBool(isAntiBreakpoint); |
| 306 |
| 307 String url = optionalURL ? *optionalURL : *optionalURLRegex; |
| 308 int columnNumber; |
| 309 if (optionalColumnNumber) { |
| 310 columnNumber = *optionalColumnNumber; |
| 311 if (columnNumber < 0) { |
| 312 *errorString = "Incorrect column number"; |
| 313 return; |
| 314 } |
| 315 } else { |
| 316 columnNumber = isAntiBreakpointValue ? -1 : 0; |
| 317 } |
| 318 String condition = optionalCondition ? *optionalCondition : ""; |
| 319 bool isRegex = optionalURLRegex; |
| 320 |
| 321 String breakpointId = (isRegex ? "/" + url + "/" : url) + ':' + String::numb
er(lineNumber) + ':' + String::number(columnNumber); |
| 322 RefPtr<JSONObject> breakpointsCookie = state()->getObject(DartDebuggerAgentS
tate::dartBreakpoints); |
| 323 if (breakpointsCookie->find(breakpointId) != breakpointsCookie->end()) { |
| 324 *errorString = "Breakpoint at specified location already exists."; |
| 325 return; |
| 326 } |
| 327 |
| 328 breakpointsCookie->setObject(breakpointId, buildObjectForBreakpointCookie(ur
l, lineNumber, columnNumber, condition, isRegex, isAntiBreakpointValue)); |
| 329 state()->setObject(DartDebuggerAgentState::dartBreakpoints, breakpointsCooki
e); |
| 330 |
| 331 if (!isAntiBreakpointValue) { |
| 332 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); |
| 333 for (ScriptsMap::iterator it = m_scripts.begin(); it != m_scripts.end();
++it) { |
| 334 if (!matches(scriptSourceURL(it->value), url, isRegex)) |
| 335 continue; |
| 336 RefPtr<TypeBuilder::Debugger::Location> location = resolveBreakpoint
(breakpointId, it->key, breakpoint, UserBreakpointSource); |
| 337 if (location) |
| 338 locations->addItem(location); |
| 339 } |
| 340 } |
| 341 *outBreakpointId = breakpointId; |
| 342 } |
| 343 |
| 344 static bool parseLocation(ErrorString* errorString, PassRefPtr<JSONObject> locat
ion, String* scriptId, int* lineNumber, int* columnNumber) |
| 345 { |
| 346 if (!location->getString("scriptId", scriptId) || !location->getNumber("line
Number", lineNumber)) { |
| 347 // FIXME: replace with input validation. |
| 348 *errorString = "scriptId and lineNumber are required."; |
| 349 return false; |
| 350 } |
| 351 *columnNumber = 0; |
| 352 location->getNumber("columnNumber", columnNumber); |
| 353 return true; |
| 354 } |
| 355 |
| 356 void DartInspectorDebuggerAgent::setBreakpoint(ErrorString* errorString, const R
efPtr<JSONObject>& location, const String* const optionalCondition, BreakpointId
* outBreakpointId, RefPtr<TypeBuilder::Debugger::Location>& actualLocation) |
| 357 { |
| 358 String scriptId; |
| 359 int lineNumber; |
| 360 int columnNumber; |
| 361 |
| 362 if (!parseLocation(errorString, location, &scriptId, &lineNumber, &columnNum
ber)) |
| 363 return; |
| 364 |
| 365 String condition = optionalCondition ? *optionalCondition : emptyString(); |
| 366 |
| 367 String breakpointId = generateBreakpointIdDart(scriptId, lineNumber, columnN
umber, UserBreakpointSource); |
| 368 if (m_breakpointIdToDebugServerBreakpointIds.find(breakpointId) != m_breakpo
intIdToDebugServerBreakpointIds.end()) { |
| 369 *errorString = "Breakpoint at specified location already exists."; |
| 370 return; |
| 371 } |
| 372 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); |
| 373 actualLocation = resolveBreakpoint(breakpointId, scriptId, breakpoint, UserB
reakpointSource); |
| 374 if (actualLocation) |
| 375 *outBreakpointId = breakpointId; |
| 376 else |
| 377 *errorString = "Could not resolve breakpoint"; |
| 378 } |
| 379 |
| 380 void DartInspectorDebuggerAgent::removeBreakpoint(ErrorString*, const String& br
eakpointId) |
| 381 { |
| 382 RefPtr<JSONObject> breakpointsCookie = state()->getObject(DartDebuggerAgentS
tate::dartBreakpoints); |
| 383 JSONObject::iterator it = breakpointsCookie->find(breakpointId); |
| 384 bool isAntibreakpoint = false; |
| 385 if (it != breakpointsCookie->end()) { |
| 386 RefPtr<JSONObject> breakpointObject = it->value->asObject(); |
| 387 breakpointObject->getBoolean(DartDebuggerAgentState::isAnti, &isAntibrea
kpoint); |
| 388 breakpointsCookie->remove(breakpointId); |
| 389 state()->setObject(DartDebuggerAgentState::dartBreakpoints, breakpointsC
ookie); |
| 390 } |
| 391 |
| 392 if (!isAntibreakpoint) |
| 393 removeBreakpoint(breakpointId); |
| 394 } |
| 395 |
| 396 void DartInspectorDebuggerAgent::removeBreakpoint(const String& breakpointId) |
| 397 { |
| 398 BreakpointIdToDebugServerBreakpointIdsMap::iterator debugServerBreakpointIds
Iterator = m_breakpointIdToDebugServerBreakpointIds.find(breakpointId); |
| 399 if (debugServerBreakpointIdsIterator == m_breakpointIdToDebugServerBreakpoin
tIds.end()) |
| 400 return; |
| 401 for (size_t i = 0; i < debugServerBreakpointIdsIterator->value.size(); ++i)
{ |
| 402 const String& debugServerBreakpointId = debugServerBreakpointIdsIterator
->value[i]; |
| 403 scriptDebugServer().removeBreakpoint(debugServerBreakpointId); |
| 404 m_serverBreakpoints.remove(debugServerBreakpointId); |
| 405 } |
| 406 m_breakpointIdToDebugServerBreakpointIds.remove(debugServerBreakpointIdsIter
ator); |
| 407 } |
| 408 |
| 409 void DartInspectorDebuggerAgent::continueToLocation(ErrorString* errorString, co
nst RefPtr<JSONObject>& location, const bool* interstateLocationOpt) |
| 410 { |
| 411 if (!m_continueToLocationBreakpointId.isEmpty()) { |
| 412 scriptDebugServer().removeBreakpoint(m_continueToLocationBreakpointId); |
| 413 m_continueToLocationBreakpointId = ""; |
| 414 } |
| 415 |
| 416 String scriptId; |
| 417 int lineNumber; |
| 418 int columnNumber; |
| 419 |
| 420 if (!parseLocation(errorString, location, &scriptId, &lineNumber, &columnNum
ber)) |
| 421 return; |
| 422 |
| 423 ScriptBreakpoint breakpoint(lineNumber, columnNumber, ""); |
| 424 m_continueToLocationBreakpointId = scriptDebugServer().setBreakpoint(scriptI
d, breakpoint, &lineNumber, &columnNumber, asBool(interstateLocationOpt)); |
| 425 resume(errorString); |
| 426 } |
| 427 |
| 428 void DartInspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<A
rray<CallFrame> >& callFrames, WTF::RefPtr<blink::TypeBuilder::Debugger::StackTr
ace>& asyncStackTrace) |
| 429 { |
| 430 if (!assertPaused(errorString)) |
| 431 return; |
| 432 m_currentCallStack = scriptDebugServer().currentCallFrames(); |
| 433 callFrames = currentCallFrames(); |
| 434 } |
| 435 |
| 436 ScriptCallFrame DartInspectorDebuggerAgent::topCallFrameSkipUnknownSources() |
| 437 { |
| 438 for (int index = 0; ; ++index) { |
| 439 ScriptCallFrame frame = scriptDebugServer().callFrameNoScopes(index); |
| 440 if (frame.isEmpty()) |
| 441 return ScriptCallFrame(); |
| 442 // FIXMEDART: is this the correct scriptId? |
| 443 if (m_scripts.contains(frame.scriptId())) |
| 444 return frame; |
| 445 } |
| 446 } |
| 447 |
| 448 DartScriptDebugListener::SkipPauseRequest DartInspectorDebuggerAgent::shouldSkip
ExceptionPause() |
| 449 { |
| 450 if (m_steppingFromFramework) |
| 451 return DartScriptDebugListener::NoSkip; |
| 452 |
| 453 // FIXME: Fast return: if (!m_cachedSkipStackRegExp && !has_any_anti_breakpo
int) return DartScriptDebugListener::NoSkip; |
| 454 |
| 455 const ScriptCallFrame& topFrame = topCallFrameSkipUnknownSources(); |
| 456 if (topFrame.isEmpty()) |
| 457 return DartScriptDebugListener::NoSkip; |
| 458 |
| 459 String topFrameScriptUrl = topFrame.sourceURL(); |
| 460 if (m_cachedSkipStackRegExp && !topFrameScriptUrl.isEmpty() && m_cachedSkipS
tackRegExp->match(topFrameScriptUrl) != -1) |
| 461 return DartScriptDebugListener::Continue; |
| 462 |
| 463 // Match against breakpoints. |
| 464 if (topFrameScriptUrl.isEmpty()) |
| 465 return DartScriptDebugListener::NoSkip; |
| 466 |
| 467 // Prepare top frame parameters. |
| 468 int topFrameLineNumber = topFrame.lineNumber(); |
| 469 int topFrameColumnNumber = topFrame.columnNumber(); |
| 470 |
| 471 RefPtr<JSONObject> breakpointsCookie = state()->getObject(DartDebuggerAgentS
tate::dartBreakpoints); |
| 472 for (JSONObject::iterator it = breakpointsCookie->begin(); it != breakpoints
Cookie->end(); ++it) { |
| 473 RefPtr<JSONObject> breakpointObject = it->value->asObject(); |
| 474 bool isAntibreakpoint; |
| 475 breakpointObject->getBoolean(DartDebuggerAgentState::isAnti, &isAntibrea
kpoint); |
| 476 if (!isAntibreakpoint) |
| 477 continue; |
| 478 |
| 479 int breakLineNumber; |
| 480 breakpointObject->getNumber(DartDebuggerAgentState::lineNumber, &breakLi
neNumber); |
| 481 int breakColumnNumber; |
| 482 breakpointObject->getNumber(DartDebuggerAgentState::columnNumber, &break
ColumnNumber); |
| 483 |
| 484 if (breakLineNumber != topFrameLineNumber) |
| 485 continue; |
| 486 |
| 487 if (breakColumnNumber != -1 && breakColumnNumber != topFrameColumnNumber
) |
| 488 continue; |
| 489 |
| 490 bool isRegex; |
| 491 breakpointObject->getBoolean(DartDebuggerAgentState::isRegex, &isRegex); |
| 492 String url; |
| 493 breakpointObject->getString(DartDebuggerAgentState::url, &url); |
| 494 if (!matches(topFrameScriptUrl, url, isRegex)) |
| 495 continue; |
| 496 |
| 497 return DartScriptDebugListener::Continue; |
| 498 } |
| 499 |
| 500 return DartScriptDebugListener::NoSkip; |
| 501 } |
| 502 |
| 503 DartScriptDebugListener::SkipPauseRequest DartInspectorDebuggerAgent::shouldSkip
StepPause() |
| 504 { |
| 505 if (!m_cachedSkipStackRegExp || m_steppingFromFramework) |
| 506 return DartScriptDebugListener::NoSkip; |
| 507 |
| 508 ScriptCallFrame topFrame = topCallFrameSkipUnknownSources(); |
| 509 String scriptUrl = topFrame.sourceURL(); |
| 510 if (scriptUrl.isEmpty() || m_cachedSkipStackRegExp->match(scriptUrl) == -1) |
| 511 return DartScriptDebugListener::NoSkip; |
| 512 |
| 513 if (m_skippedStepInCount == 0) { |
| 514 m_minFrameCountForSkip = scriptDebugServer().frameCount(); |
| 515 m_skippedStepInCount = 1; |
| 516 return DartScriptDebugListener::StepInto; |
| 517 } |
| 518 |
| 519 if (m_skippedStepInCount < maxSkipStepInCountDart && scriptDebugServer().fra
meCount() <= m_minFrameCountForSkip) |
| 520 m_skippedStepInCount = maxSkipStepInCountDart; |
| 521 |
| 522 if (m_skippedStepInCount >= maxSkipStepInCountDart) { |
| 523 if (m_pausingOnNativeEvent) { |
| 524 m_pausingOnNativeEvent = false; |
| 525 m_skippedStepInCount = 0; |
| 526 return DartScriptDebugListener::Continue; |
| 527 } |
| 528 return DartScriptDebugListener::StepOut; |
| 529 } |
| 530 |
| 531 ++m_skippedStepInCount; |
| 532 return DartScriptDebugListener::StepInto; |
| 533 } |
| 534 |
| 535 bool DartInspectorDebuggerAgent::isTopCallFrameInFramework() |
| 536 { |
| 537 if (!m_cachedSkipStackRegExp) |
| 538 return false; |
| 539 |
| 540 ScriptCallFrame topFrame = topCallFrameSkipUnknownSources(); |
| 541 if (topFrame.isEmpty()) |
| 542 return false; |
| 543 |
| 544 String scriptUrl = topFrame.sourceURL(); |
| 545 return !scriptUrl.isEmpty() && m_cachedSkipStackRegExp->match(scriptUrl) !=
-1; |
| 546 } |
| 547 |
| 548 bool DartInspectorDebuggerAgent::isDartScriptId(const String& scriptId) |
| 549 { |
| 550 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId); |
| 551 return scriptIterator != m_scripts.end(); |
| 552 } |
| 553 |
| 554 bool DartInspectorDebuggerAgent::isDartURL(const String* const optionalURL, cons
t String* const optionalURLRegex) |
| 555 { |
| 556 return (optionalURL && (optionalURL->endsWith(".dart", false) || optionalURL
->startsWith("dart:"))) || (optionalURLRegex && (optionalURLRegex->endsWith(".da
rt", false) || optionalURLRegex->startsWith("dart:"))); |
| 557 } |
| 558 |
| 559 PassRefPtr<TypeBuilder::Debugger::Location> DartInspectorDebuggerAgent::resolveB
reakpoint(const String& breakpointId, const String& scriptId, const ScriptBreakp
oint& breakpoint, BreakpointSource source) |
| 560 { |
| 561 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId); |
| 562 if (scriptIterator == m_scripts.end()) |
| 563 return nullptr; |
| 564 Script& script = scriptIterator->value; |
| 565 if (breakpoint.lineNumber < script.startLine || script.endLine < breakpoint.
lineNumber) |
| 566 return nullptr; |
| 567 |
| 568 int actualLineNumber; |
| 569 int actualColumnNumber; |
| 570 String debugServerBreakpointId = scriptDebugServer().setBreakpoint(scriptId,
breakpoint, &actualLineNumber, &actualColumnNumber, false); |
| 571 if (debugServerBreakpointId.isEmpty()) |
| 572 return nullptr; |
| 573 |
| 574 m_serverBreakpoints.set(debugServerBreakpointId, std::make_pair(breakpointId
, source)); |
| 575 |
| 576 BreakpointIdToDebugServerBreakpointIdsMap::iterator debugServerBreakpointIds
Iterator = m_breakpointIdToDebugServerBreakpointIds.find(breakpointId); |
| 577 if (debugServerBreakpointIdsIterator == m_breakpointIdToDebugServerBreakpoin
tIds.end()) |
| 578 m_breakpointIdToDebugServerBreakpointIds.set(breakpointId, Vector<String
>()).storedValue->value.append(debugServerBreakpointId); |
| 579 else |
| 580 debugServerBreakpointIdsIterator->value.append(debugServerBreakpointId); |
| 581 |
| 582 RefPtr<TypeBuilder::Debugger::Location> location = TypeBuilder::Debugger::Lo
cation::create() |
| 583 .setScriptId(scriptId) |
| 584 .setLineNumber(actualLineNumber); |
| 585 location->setColumnNumber(actualColumnNumber); |
| 586 return location; |
| 587 } |
| 588 |
| 589 void DartInspectorDebuggerAgent::searchInContent(ErrorString* error, const Strin
g& scriptId, const String& query, const bool* const optionalCaseSensitive, const
bool* const optionalIsRegex, RefPtr<Array<blink::TypeBuilder::Page::SearchMatch
> >& results) |
| 590 { |
| 591 ScriptsMap::iterator it = m_scripts.find(scriptId); |
| 592 if (it != m_scripts.end()) |
| 593 results = ContentSearchUtils::searchInTextByLines(it->value.source, quer
y, asBool(optionalCaseSensitive), asBool(optionalIsRegex)); |
| 594 else |
| 595 *error = "No script for id: " + scriptId; |
| 596 } |
| 597 |
| 598 void DartInspectorDebuggerAgent::getScriptSource(ErrorString* error, const Strin
g& scriptId, String* scriptSource) |
| 599 { |
| 600 ScriptsMap::iterator it = m_scripts.find(scriptId); |
| 601 if (it == m_scripts.end()) { |
| 602 *error = "No script for id: " + scriptId; |
| 603 return; |
| 604 } |
| 605 |
| 606 String url = it->value.url; |
| 607 if (!url.isEmpty()) { |
| 608 if (m_pageAgent) { |
| 609 bool success = m_pageAgent->getEditedResourceContent(url, scriptSour
ce); |
| 610 if (success) |
| 611 return; |
| 612 } |
| 613 } |
| 614 *scriptSource = it->value.source; |
| 615 } |
| 616 |
| 617 void DartInspectorDebuggerAgent::getFunctionDetails(ErrorString* errorString, co
nst String& functionId, RefPtr<FunctionDetails>& details) |
| 618 { |
| 619 DartInjectedScript* injectedScript = m_injectedScriptManager->injectedScript
ForObjectId(functionId); |
| 620 if (!injectedScript) { |
| 621 *errorString = "Function object id is obsolete"; |
| 622 return; |
| 623 } |
| 624 injectedScript->getFunctionDetails(errorString, functionId, &details); |
| 625 } |
| 626 |
| 627 void DartInspectorDebuggerAgent::schedulePauseOnNextStatement(InspectorFrontend:
:Debugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data) |
| 628 { |
| 629 if (m_javaScriptPauseScheduled || isPaused()) |
| 630 return; |
| 631 m_breakReason = breakReason; |
| 632 m_breakAuxData = data; |
| 633 m_pausingOnNativeEvent = true; |
| 634 scriptDebugServer().setPauseOnNextStatement(true); |
| 635 } |
| 636 |
| 637 void DartInspectorDebuggerAgent::cancelPauseOnNextStatement() |
| 638 { |
| 639 if (m_javaScriptPauseScheduled || isPaused()) |
| 640 return; |
| 641 clearBreakDetails(); |
| 642 m_pausingOnNativeEvent = false; |
| 643 scriptDebugServer().setPauseOnNextStatement(false); |
| 644 } |
| 645 |
| 646 void DartInspectorDebuggerAgent::pause(ErrorString*) |
| 647 { |
| 648 if (m_javaScriptPauseScheduled || isPaused()) |
| 649 return; |
| 650 clearBreakDetails(); |
| 651 m_javaScriptPauseScheduled = true; |
| 652 scriptDebugServer().setPauseOnNextStatement(true); |
| 653 } |
| 654 |
| 655 void DartInspectorDebuggerAgent::resume(ErrorString* errorString) |
| 656 { |
| 657 if (!assertPaused(errorString)) |
| 658 return; |
| 659 m_debuggerStepScheduled = false; |
| 660 m_steppingFromFramework = false; |
| 661 m_injectedScriptManager->releaseObjectGroup(DartInspectorDebuggerAgent::back
traceObjectGroup); |
| 662 scriptDebugServer().continueProgram(); |
| 663 } |
| 664 |
| 665 void DartInspectorDebuggerAgent::stepOver(ErrorString* errorString) |
| 666 { |
| 667 if (!assertPaused(errorString)) |
| 668 return; |
| 669 m_debuggerStepScheduled = true; |
| 670 m_steppingFromFramework = isTopCallFrameInFramework(); |
| 671 m_injectedScriptManager->releaseObjectGroup(DartInspectorDebuggerAgent::back
traceObjectGroup); |
| 672 scriptDebugServer().stepOverStatement(); |
| 673 } |
| 674 |
| 675 void DartInspectorDebuggerAgent::stepInto(ErrorString* errorString) |
| 676 { |
| 677 if (!assertPaused(errorString)) |
| 678 return; |
| 679 m_debuggerStepScheduled = true; |
| 680 m_steppingFromFramework = isTopCallFrameInFramework(); |
| 681 m_injectedScriptManager->releaseObjectGroup(DartInspectorDebuggerAgent::back
traceObjectGroup); |
| 682 scriptDebugServer().stepIntoStatement(); |
| 683 if (m_listener) |
| 684 m_listener->stepInto(); |
| 685 } |
| 686 |
| 687 void DartInspectorDebuggerAgent::stepOut(ErrorString* errorString) |
| 688 { |
| 689 if (!assertPaused(errorString)) |
| 690 return; |
| 691 m_debuggerStepScheduled = true; |
| 692 m_steppingFromFramework = isTopCallFrameInFramework(); |
| 693 m_injectedScriptManager->releaseObjectGroup(DartInspectorDebuggerAgent::back
traceObjectGroup); |
| 694 scriptDebugServer().stepOutOfFunction(); |
| 695 } |
| 696 |
| 697 void DartInspectorDebuggerAgent::setPauseOnExceptions(ErrorString* errorString,
const String& stringPauseState) |
| 698 { |
| 699 ScriptDebugServer::PauseOnExceptionsState pauseState; |
| 700 if (stringPauseState == "none") { |
| 701 pauseState = ScriptDebugServer::DontPauseOnExceptions; |
| 702 } else if (stringPauseState == "all") { |
| 703 pauseState = ScriptDebugServer::PauseOnAllExceptions; |
| 704 } else if (stringPauseState == "uncaught") { |
| 705 pauseState = ScriptDebugServer::PauseOnUncaughtExceptions; |
| 706 } else { |
| 707 *errorString = "Unknown pause on exceptions mode: " + stringPauseState; |
| 708 return; |
| 709 } |
| 710 setPauseOnExceptionsImpl(errorString, pauseState); |
| 711 } |
| 712 |
| 713 void DartInspectorDebuggerAgent::setPauseOnExceptionsImpl(ErrorString* errorStri
ng, int pauseState) |
| 714 { |
| 715 scriptDebugServer().setPauseOnExceptionsState(static_cast<ScriptDebugServer:
:PauseOnExceptionsState>(pauseState)); |
| 716 if (scriptDebugServer().pauseOnExceptionsState() != pauseState) |
| 717 *errorString = "Internal error. Could not change pause on exceptions sta
te"; |
| 718 else |
| 719 state()->setLong(DartDebuggerAgentState::pauseOnExceptionsState, pauseSt
ate); |
| 720 } |
| 721 |
| 722 void DartInspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, c
onst String& callFrameId, const String& expression, const String* const objectGr
oup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExce
ptionsAndMuteConsole, const bool* const returnByValue, const bool* generatePrevi
ew, RefPtr<RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown, RefPt
r<TypeBuilder::Debugger::ExceptionDetails>& exceptionDetails) |
| 723 { |
| 724 if (!isPaused() || !m_currentCallStack) { |
| 725 *errorString = "Attempt to access callframe when debugger is not on paus
e"; |
| 726 return; |
| 727 } |
| 728 DartInjectedScript* injectedScript = m_injectedScriptManager->injectedScript
ForObjectId(callFrameId); |
| 729 if (!injectedScript) { |
| 730 *errorString = "Inspected frame has gone"; |
| 731 return; |
| 732 } |
| 733 |
| 734 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = s
criptDebugServer().pauseOnExceptionsState(); |
| 735 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) { |
| 736 if (previousPauseOnExceptionsState != ScriptDebugServer::DontPauseOnExce
ptions) |
| 737 scriptDebugServer().setPauseOnExceptionsState(ScriptDebugServer::Don
tPauseOnExceptions); |
| 738 muteConsole(); |
| 739 } |
| 740 |
| 741 injectedScript->evaluateOnCallFrame(errorString, m_currentCallStack, callFra
meId, expression, objectGroup ? *objectGroup : "", asBool(includeCommandLineAPI)
, asBool(returnByValue), asBool(generatePreview), &result, wasThrown, &exception
Details); |
| 742 // V8 doesn't generate afterCompile event when it's in debugger therefore th
ere is no content of evaluated scripts on frontend |
| 743 // therefore contents of the stack does not provide necessary information |
| 744 if (exceptionDetails) |
| 745 exceptionDetails->setStackTrace(TypeBuilder::Array<TypeBuilder::Console:
:CallFrame>::create()); |
| 746 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) { |
| 747 unmuteConsole(); |
| 748 if (scriptDebugServer().pauseOnExceptionsState() != previousPauseOnExcep
tionsState) |
| 749 scriptDebugServer().setPauseOnExceptionsState(previousPauseOnExcepti
onsState); |
| 750 } |
| 751 } |
| 752 |
| 753 void DartInspectorDebuggerAgent::getCompletionsOnCallFrame(ErrorString* errorStr
ing, const String& callFrameId, const String& expression, RefPtr<TypeBuilder::Ar
ray<String> >& result) |
| 754 { |
| 755 if (!isPaused() || !m_currentCallStack) { |
| 756 *errorString = "Attempt to access callframe when debugger is not on paus
e"; |
| 757 return; |
| 758 } |
| 759 DartInjectedScript* injectedScript = m_injectedScriptManager->injectedScript
ForObjectId(callFrameId); |
| 760 if (!injectedScript) { |
| 761 *errorString = "Inspected frame has gone"; |
| 762 return; |
| 763 } |
| 764 |
| 765 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = s
criptDebugServer().pauseOnExceptionsState(); |
| 766 if (previousPauseOnExceptionsState != ScriptDebugServer::DontPauseOnExceptio
ns) |
| 767 scriptDebugServer().setPauseOnExceptionsState(ScriptDebugServer::DontPau
seOnExceptions); |
| 768 muteConsole(); |
| 769 |
| 770 injectedScript->getCompletionsOnCallFrame(errorString, m_currentCallStack, c
allFrameId, expression, &result); |
| 771 |
| 772 unmuteConsole(); |
| 773 if (scriptDebugServer().pauseOnExceptionsState() != previousPauseOnException
sState) |
| 774 scriptDebugServer().setPauseOnExceptionsState(previousPauseOnExceptionsS
tate); |
| 775 } |
| 776 |
| 777 void DartInspectorDebuggerAgent::setOverlayMessage(ErrorString*, const String*) |
| 778 { |
| 779 } |
| 780 |
| 781 void DartInspectorDebuggerAgent::setVariableValue(ErrorString* errorString, int
scopeNumber, const String& variableName, const RefPtr<JSONObject>& newValue, con
st String* callFrameId, const String* functionObjectId) |
| 782 { |
| 783 DartInjectedScript* injectedScript = 0; |
| 784 if (callFrameId) { |
| 785 if (!isPaused() || !m_currentCallStack) { |
| 786 *errorString = "Attempt to access callframe when debugger is not on
pause"; |
| 787 return; |
| 788 } |
| 789 injectedScript = m_injectedScriptManager->injectedScriptForObjectId(*cal
lFrameId); |
| 790 if (injectedScript->isEmpty()) { |
| 791 *errorString = "Inspected frame has gone"; |
| 792 return; |
| 793 } |
| 794 } else if (functionObjectId) { |
| 795 injectedScript = m_injectedScriptManager->injectedScriptForObjectId(*fun
ctionObjectId); |
| 796 if (injectedScript->isEmpty()) { |
| 797 *errorString = "Function object id cannot be resolved"; |
| 798 return; |
| 799 } |
| 800 } else { |
| 801 *errorString = "Either call frame or function object must be specified"; |
| 802 return; |
| 803 } |
| 804 String newValueString = newValue->toJSONString(); |
| 805 ASSERT(injectedScript); |
| 806 injectedScript->setVariableValue(errorString, m_currentCallStack, callFrameI
d, functionObjectId, scopeNumber, variableName, newValueString); |
| 807 } |
| 808 |
| 809 void DartInspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const
String* pattern) |
| 810 { |
| 811 OwnPtr<ScriptRegexp> compiled; |
| 812 String patternValue = pattern ? *pattern : ""; |
| 813 if (!patternValue.isEmpty()) { |
| 814 compiled = compileSkipCallFramePattern(patternValue); |
| 815 if (!compiled) { |
| 816 *errorString = "Invalid regular expression"; |
| 817 return; |
| 818 } |
| 819 } |
| 820 state()->setString(DartDebuggerAgentState::skipStackPattern, patternValue); |
| 821 m_cachedSkipStackRegExp = compiled.release(); |
| 822 } |
| 823 |
| 824 void DartInspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& direc
tiveText) |
| 825 { |
| 826 if (scriptDebugServer().pauseOnExceptionsState() != ScriptDebugServer::DontP
auseOnExceptions) { |
| 827 RefPtr<JSONObject> directive = JSONObject::create(); |
| 828 directive->setString("directiveText", directiveText); |
| 829 breakProgram(InspectorFrontend::Debugger::Reason::CSPViolation, directiv
e.release()); |
| 830 } |
| 831 } |
| 832 |
| 833 PassRefPtr<Array<CallFrame> > DartInspectorDebuggerAgent::currentCallFrames() |
| 834 { |
| 835 if (!m_pausedScriptState || !m_currentCallStack) |
| 836 return Array<TypeBuilder::Debugger::CallFrame>::create(); |
| 837 DartInjectedScript* injectedScript = m_injectedScriptManager->injectedScript
For(m_pausedScriptState.get()); |
| 838 if (!injectedScript) { |
| 839 ASSERT_NOT_REACHED(); |
| 840 return Array<CallFrame>::create(); |
| 841 } |
| 842 return injectedScript->wrapCallFrames(m_currentCallStack, 0); |
| 843 } |
| 844 |
| 845 String DartInspectorDebuggerAgent::sourceMapURLForScript(const Script& script, C
ompileResult compileResult) |
| 846 { |
| 847 bool hasSyntaxError = compileResult != CompileSuccess; |
| 848 if (hasSyntaxError) { |
| 849 bool deprecated; |
| 850 String sourceMapURL = ContentSearchUtils::findSourceMapURL(script.source
, ContentSearchUtils::JavaScriptMagicComment, &deprecated); |
| 851 if (!sourceMapURL.isEmpty()) |
| 852 return sourceMapURL; |
| 853 } |
| 854 |
| 855 if (!script.sourceMappingURL.isEmpty()) |
| 856 return script.sourceMappingURL; |
| 857 |
| 858 if (script.url.isEmpty()) |
| 859 return String(); |
| 860 |
| 861 if (!m_pageAgent) |
| 862 return String(); |
| 863 return m_pageAgent->resourceSourceMapURL(script.url); |
| 864 } |
| 865 |
| 866 // DartScriptDebugListener functions |
| 867 |
| 868 void DartInspectorDebuggerAgent::didParseSource(const String& scriptId, const Sc
ript& parsedScript, CompileResult compileResult) |
| 869 { |
| 870 Script script = parsedScript; |
| 871 const bool* isContentScript = script.isContentScript ? &script.isContentScri
pt : 0; |
| 872 |
| 873 const String* languageParam = script.language.isNull() ? 0 : &(script.langua
ge); |
| 874 const int* libraryIdParam = script.libraryId < 0 ? 0 : &(script.libraryId); |
| 875 bool hasSyntaxError = compileResult != CompileSuccess; |
| 876 if (!script.startLine && !script.startColumn) { |
| 877 if (hasSyntaxError) { |
| 878 bool deprecated; |
| 879 script.sourceURL = ContentSearchUtils::findSourceURL(script.source,
ContentSearchUtils::JavaScriptMagicComment, &deprecated); |
| 880 } |
| 881 } else { |
| 882 script.sourceURL = String(); |
| 883 } |
| 884 |
| 885 bool hasSourceURL = !script.sourceURL.isEmpty(); |
| 886 String scriptURL = hasSourceURL ? script.sourceURL : script.url; |
| 887 |
| 888 String sourceMapURL = sourceMapURLForScript(script, compileResult); |
| 889 String* sourceMapURLParam = sourceMapURL.isNull() ? 0 : &sourceMapURL; |
| 890 |
| 891 bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : 0; |
| 892 if (!hasSyntaxError) |
| 893 m_frontend->scriptParsed(scriptId, scriptURL, script.startLine, script.s
tartColumn, script.endLine, script.endColumn, isContentScript, sourceMapURLParam
, hasSourceURLParam, languageParam, libraryIdParam); |
| 894 else |
| 895 m_frontend->scriptFailedToParse(scriptId, scriptURL, script.startLine, s
cript.startColumn, script.endLine, script.endColumn, isContentScript, sourceMapU
RLParam, hasSourceURLParam, languageParam, libraryIdParam); |
| 896 |
| 897 m_scripts.set(scriptId, script); |
| 898 |
| 899 if (scriptURL.isEmpty() || hasSyntaxError) |
| 900 return; |
| 901 |
| 902 RefPtr<JSONObject> breakpointsCookie = state()->getObject(DartDebuggerAgentS
tate::dartBreakpoints); |
| 903 for (JSONObject::iterator it = breakpointsCookie->begin(); it != breakpoints
Cookie->end(); ++it) { |
| 904 RefPtr<JSONObject> breakpointObject = it->value->asObject(); |
| 905 bool isAntibreakpoint; |
| 906 breakpointObject->getBoolean(DartDebuggerAgentState::isAnti, &isAntibrea
kpoint); |
| 907 if (isAntibreakpoint) |
| 908 continue; |
| 909 bool isRegex; |
| 910 breakpointObject->getBoolean(DartDebuggerAgentState::isRegex, &isRegex); |
| 911 String url; |
| 912 breakpointObject->getString(DartDebuggerAgentState::url, &url); |
| 913 if (!matches(scriptURL, url, isRegex)) |
| 914 continue; |
| 915 ScriptBreakpoint breakpoint; |
| 916 breakpointObject->getNumber(DartDebuggerAgentState::lineNumber, &breakpo
int.lineNumber); |
| 917 breakpointObject->getNumber(DartDebuggerAgentState::columnNumber, &break
point.columnNumber); |
| 918 breakpointObject->getString(DartDebuggerAgentState::condition, &breakpoi
nt.condition); |
| 919 RefPtr<TypeBuilder::Debugger::Location> location = resolveBreakpoint(it-
>key, scriptId, breakpoint, UserBreakpointSource); |
| 920 if (location) |
| 921 m_frontend->breakpointResolved(it->key, location); |
| 922 } |
| 923 } |
| 924 |
| 925 DartScriptDebugListener::SkipPauseRequest DartInspectorDebuggerAgent::didPause(S
criptState* scriptState, Dart_StackTrace callFrames, const ScriptValue& exceptio
n, const Vector<String>& hitBreakpoints) |
| 926 { |
| 927 DartScriptDebugListener::SkipPauseRequest result; |
| 928 if (!callFrames) |
| 929 result = DartScriptDebugListener::Continue; // Skip pauses inside V8 int
ernal scripts and on syntax errors. |
| 930 else if (m_javaScriptPauseScheduled) |
| 931 result = DartScriptDebugListener::NoSkip; // Don't skip explicit pause r
equests from front-end. |
| 932 else if (m_skipAllPauses) |
| 933 result = DartScriptDebugListener::Continue; |
| 934 else if (!hitBreakpoints.isEmpty()) |
| 935 result = DartScriptDebugListener::NoSkip; // Don't skip explicit breakpo
ints even if set in frameworks. |
| 936 else if (!exception.isEmpty()) |
| 937 result = shouldSkipExceptionPause(); |
| 938 else if (m_debuggerStepScheduled || m_pausingOnNativeEvent) |
| 939 result = shouldSkipStepPause(); |
| 940 else |
| 941 result = DartScriptDebugListener::NoSkip; |
| 942 |
| 943 if (result != DartScriptDebugListener::NoSkip) |
| 944 return result; |
| 945 |
| 946 ASSERT(scriptState && !m_pausedScriptState); |
| 947 m_pausedScriptState = scriptState; |
| 948 m_currentCallStack = callFrames; |
| 949 |
| 950 if (!exception.isEmpty()) { |
| 951 DartInjectedScript* injectedScript = m_injectedScriptManager->injectedSc
riptFor(scriptState); |
| 952 if (injectedScript) { |
| 953 m_breakReason = InspectorFrontend::Debugger::Reason::Exception; |
| 954 m_breakAuxData = injectedScript->wrapObject(exception, DartInspector
DebuggerAgent::backtraceObjectGroup)->openAccessors(); |
| 955 // m_breakAuxData might be null after this. |
| 956 } |
| 957 } |
| 958 |
| 959 RefPtr<Array<String> > hitBreakpointIds = Array<String>::create(); |
| 960 |
| 961 for (Vector<String>::const_iterator i = hitBreakpoints.begin(); i != hitBrea
kpoints.end(); ++i) { |
| 962 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter
ator = m_serverBreakpoints.find(*i); |
| 963 if (breakpointIterator != m_serverBreakpoints.end()) { |
| 964 const String& localId = breakpointIterator->value.first; |
| 965 hitBreakpointIds->addItem(localId); |
| 966 |
| 967 BreakpointSource source = breakpointIterator->value.second; |
| 968 if (m_breakReason == InspectorFrontend::Debugger::Reason::Other && s
ource == DebugCommandBreakpointSource) |
| 969 m_breakReason = InspectorFrontend::Debugger::Reason::DebugComman
d; |
| 970 } |
| 971 } |
| 972 |
| 973 m_frontend->paused(currentCallFrames(), m_breakReason, m_breakAuxData, hitBr
eakpointIds, nullptr); |
| 974 m_javaScriptPauseScheduled = false; |
| 975 m_debuggerStepScheduled = false; |
| 976 m_steppingFromFramework = false; |
| 977 m_pausingOnNativeEvent = false; |
| 978 m_skippedStepInCount = 0; |
| 979 |
| 980 if (!m_continueToLocationBreakpointId.isEmpty()) { |
| 981 scriptDebugServer().removeBreakpoint(m_continueToLocationBreakpointId); |
| 982 m_continueToLocationBreakpointId = ""; |
| 983 } |
| 984 if (m_listener) |
| 985 m_listener->didPause(); |
| 986 return result; |
| 987 } |
| 988 |
| 989 void DartInspectorDebuggerAgent::didContinue() |
| 990 { |
| 991 m_pausedScriptState = nullptr; |
| 992 m_currentCallStack = 0; |
| 993 clearBreakDetails(); |
| 994 // Already called by InspectorDebuggerAgent? |
| 995 m_frontend->resumed(); |
| 996 } |
| 997 |
| 998 bool DartInspectorDebuggerAgent::canBreakProgram() |
| 999 { |
| 1000 return scriptDebugServer().canBreakProgram(); |
| 1001 } |
| 1002 |
| 1003 void DartInspectorDebuggerAgent::breakProgram(InspectorFrontend::Debugger::Reaso
n::Enum breakReason, PassRefPtr<JSONObject> data) |
| 1004 { |
| 1005 if (m_skipAllPauses) |
| 1006 return; |
| 1007 m_breakReason = breakReason; |
| 1008 m_breakAuxData = data; |
| 1009 m_debuggerStepScheduled = false; |
| 1010 m_steppingFromFramework = false; |
| 1011 m_pausingOnNativeEvent = false; |
| 1012 scriptDebugServer().breakProgram(); |
| 1013 } |
| 1014 |
| 1015 void DartInspectorDebuggerAgent::clear() |
| 1016 { |
| 1017 m_pausedScriptState = nullptr; |
| 1018 m_currentCallStack = 0; |
| 1019 m_scripts.clear(); |
| 1020 m_breakpointIdToDebugServerBreakpointIds.clear(); |
| 1021 m_continueToLocationBreakpointId = String(); |
| 1022 clearBreakDetails(); |
| 1023 m_javaScriptPauseScheduled = false; |
| 1024 m_debuggerStepScheduled = false; |
| 1025 m_steppingFromFramework = false; |
| 1026 m_pausingOnNativeEvent = false; |
| 1027 ErrorString error; |
| 1028 setOverlayMessage(&error, 0); |
| 1029 } |
| 1030 |
| 1031 bool DartInspectorDebuggerAgent::assertPaused(ErrorString* errorString) |
| 1032 { |
| 1033 if (!m_pausedScriptState) { |
| 1034 *errorString = "Can only perform operation while paused."; |
| 1035 return false; |
| 1036 } |
| 1037 return true; |
| 1038 } |
| 1039 |
| 1040 void DartInspectorDebuggerAgent::clearBreakDetails() |
| 1041 { |
| 1042 m_breakReason = InspectorFrontend::Debugger::Reason::Other; |
| 1043 m_breakAuxData = nullptr; |
| 1044 } |
| 1045 |
| 1046 void DartInspectorDebuggerAgent::setBreakpoint(const String& scriptId, int lineN
umber, int columnNumber, BreakpointSource source, const String& condition) |
| 1047 { |
| 1048 String breakpointId = generateBreakpointIdDart(scriptId, lineNumber, columnN
umber, source); |
| 1049 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); |
| 1050 resolveBreakpoint(breakpointId, scriptId, breakpoint, source); |
| 1051 } |
| 1052 |
| 1053 void DartInspectorDebuggerAgent::removeBreakpoint(const String& scriptId, int li
neNumber, int columnNumber, BreakpointSource source) |
| 1054 { |
| 1055 removeBreakpoint(generateBreakpointIdDart(scriptId, lineNumber, columnNumber
, source)); |
| 1056 } |
| 1057 |
| 1058 void DartInspectorDebuggerAgent::reset() |
| 1059 { |
| 1060 m_scripts.clear(); |
| 1061 m_breakpointIdToDebugServerBreakpointIds.clear(); |
| 1062 } |
| 1063 |
| 1064 DartScriptDebugServer& DartInspectorDebuggerAgent::scriptDebugServer() |
| 1065 { |
| 1066 return DartScriptDebugServer::shared(); |
| 1067 } |
| 1068 |
| 1069 } // namespace blink |
| 1070 |
OLD | NEW |