Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: Source/core/inspector/InspectorDebuggerAgent.cpp

Issue 74063002: DevTools: Support asynchronous call stacks on backend. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Async call stacks are off by default, added Debugger.enableAsyncCallStacks protocol command Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010-2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010-2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/inspector/InspectorPageAgent.h" 42 #include "core/inspector/InspectorPageAgent.h"
43 #include "core/inspector/InspectorState.h" 43 #include "core/inspector/InspectorState.h"
44 #include "core/inspector/InstrumentingAgents.h" 44 #include "core/inspector/InstrumentingAgents.h"
45 #include "core/inspector/ScriptArguments.h" 45 #include "core/inspector/ScriptArguments.h"
46 #include "core/inspector/ScriptCallStack.h" 46 #include "core/inspector/ScriptCallStack.h"
47 #include "core/platform/text/RegularExpression.h" 47 #include "core/platform/text/RegularExpression.h"
48 #include "platform/JSONValues.h" 48 #include "platform/JSONValues.h"
49 #include "wtf/text/WTFString.h" 49 #include "wtf/text/WTFString.h"
50 50
51 using WebCore::TypeBuilder::Array; 51 using WebCore::TypeBuilder::Array;
52 using WebCore::TypeBuilder::Debugger::BreakpointId;
53 using WebCore::TypeBuilder::Debugger::CallFrame;
52 using WebCore::TypeBuilder::Debugger::FunctionDetails; 54 using WebCore::TypeBuilder::Debugger::FunctionDetails;
55 using WebCore::TypeBuilder::Debugger::Location;
53 using WebCore::TypeBuilder::Debugger::ScriptId; 56 using WebCore::TypeBuilder::Debugger::ScriptId;
54 using WebCore::TypeBuilder::Runtime::RemoteObject; 57 using WebCore::TypeBuilder::Runtime::RemoteObject;
55 58
56 namespace WebCore { 59 namespace WebCore {
57 60
58 namespace DebuggerAgentState { 61 namespace DebuggerAgentState {
59 static const char debuggerEnabled[] = "debuggerEnabled"; 62 static const char debuggerEnabled[] = "debuggerEnabled";
60 static const char javaScriptBreakpoints[] = "javaScriptBreakopints"; 63 static const char javaScriptBreakpoints[] = "javaScriptBreakopints";
61 static const char pauseOnExceptionsState[] = "pauseOnExceptionsState"; 64 static const char pauseOnExceptionsState[] = "pauseOnExceptionsState";
62 65
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 291
289 static bool matches(const String& url, const String& pattern, bool isRegex) 292 static bool matches(const String& url, const String& pattern, bool isRegex)
290 { 293 {
291 if (isRegex) { 294 if (isRegex) {
292 RegularExpression regex(pattern, TextCaseSensitive); 295 RegularExpression regex(pattern, TextCaseSensitive);
293 return regex.match(url) != -1; 296 return regex.match(url) != -1;
294 } 297 }
295 return url == pattern; 298 return url == pattern;
296 } 299 }
297 300
298 void InspectorDebuggerAgent::setBreakpointByUrl(ErrorString* errorString, int li neNumber, const String* const optionalURL, const String* const optionalURLRegex, const int* const optionalColumnNumber, const String* const optionalCondition, c onst bool* isAntiBreakpoint, TypeBuilder::Debugger::BreakpointId* outBreakpointI d, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::Location> >& locations) 301 void InspectorDebuggerAgent::setBreakpointByUrl(ErrorString* errorString, int li neNumber, const String* const optionalURL, const String* const optionalURLRegex, const int* const optionalColumnNumber, const String* const optionalCondition, c onst bool* isAntiBreakpoint, BreakpointId* outBreakpointId, RefPtr<Array<Locatio n> >& locations)
299 { 302 {
300 locations = Array<TypeBuilder::Debugger::Location>::create(); 303 locations = Array<Location>::create();
301 if (!optionalURL == !optionalURLRegex) { 304 if (!optionalURL == !optionalURLRegex) {
302 *errorString = "Either url or urlRegex must be specified."; 305 *errorString = "Either url or urlRegex must be specified.";
303 return; 306 return;
304 } 307 }
305 308
306 bool isAntiBreakpointValue = isAntiBreakpoint && *isAntiBreakpoint; 309 bool isAntiBreakpointValue = isAntiBreakpoint && *isAntiBreakpoint;
307 310
308 String url = optionalURL ? *optionalURL : *optionalURLRegex; 311 String url = optionalURL ? *optionalURL : *optionalURLRegex;
309 int columnNumber; 312 int columnNumber;
310 if (optionalColumnNumber) { 313 if (optionalColumnNumber) {
(...skipping 16 matching lines...) Expand all
327 } 330 }
328 331
329 breakpointsCookie->setObject(breakpointId, buildObjectForBreakpointCookie(ur l, lineNumber, columnNumber, condition, isRegex, isAntiBreakpointValue)); 332 breakpointsCookie->setObject(breakpointId, buildObjectForBreakpointCookie(ur l, lineNumber, columnNumber, condition, isRegex, isAntiBreakpointValue));
330 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, breakpointsCoo kie); 333 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, breakpointsCoo kie);
331 334
332 if (!isAntiBreakpointValue) { 335 if (!isAntiBreakpointValue) {
333 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); 336 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition);
334 for (ScriptsMap::iterator it = m_scripts.begin(); it != m_scripts.end(); ++it) { 337 for (ScriptsMap::iterator it = m_scripts.begin(); it != m_scripts.end(); ++it) {
335 if (!matches(it->value.url, url, isRegex)) 338 if (!matches(it->value.url, url, isRegex))
336 continue; 339 continue;
337 RefPtr<TypeBuilder::Debugger::Location> location = resolveBreakpoint (breakpointId, it->key, breakpoint, UserBreakpointSource); 340 RefPtr<Location> location = resolveBreakpoint(breakpointId, it->key, breakpoint, UserBreakpointSource);
338 if (location) 341 if (location)
339 locations->addItem(location); 342 locations->addItem(location);
340 } 343 }
341 } 344 }
342 *outBreakpointId = breakpointId; 345 *outBreakpointId = breakpointId;
343 } 346 }
344 347
345 static bool parseLocation(ErrorString* errorString, PassRefPtr<JSONObject> locat ion, String* scriptId, int* lineNumber, int* columnNumber) 348 static bool parseLocation(ErrorString* errorString, PassRefPtr<JSONObject> locat ion, String* scriptId, int* lineNumber, int* columnNumber)
346 { 349 {
347 if (!location->getString("scriptId", scriptId) || !location->getNumber("line Number", lineNumber)) { 350 if (!location->getString("scriptId", scriptId) || !location->getNumber("line Number", lineNumber)) {
348 // FIXME: replace with input validation. 351 // FIXME: replace with input validation.
349 *errorString = "scriptId and lineNumber are required."; 352 *errorString = "scriptId and lineNumber are required.";
350 return false; 353 return false;
351 } 354 }
352 *columnNumber = 0; 355 *columnNumber = 0;
353 location->getNumber("columnNumber", columnNumber); 356 location->getNumber("columnNumber", columnNumber);
354 return true; 357 return true;
355 } 358 }
356 359
357 void InspectorDebuggerAgent::setBreakpoint(ErrorString* errorString, const RefPt r<JSONObject>& location, const String* const optionalCondition, TypeBuilder::Deb ugger::BreakpointId* outBreakpointId, RefPtr<TypeBuilder::Debugger::Location>& a ctualLocation) 360 void InspectorDebuggerAgent::setBreakpoint(ErrorString* errorString, const RefPt r<JSONObject>& location, const String* const optionalCondition, BreakpointId* ou tBreakpointId, RefPtr<Location>& actualLocation)
358 { 361 {
359 String scriptId; 362 String scriptId;
360 int lineNumber; 363 int lineNumber;
361 int columnNumber; 364 int columnNumber;
362 365
363 if (!parseLocation(errorString, location, &scriptId, &lineNumber, &columnNum ber)) 366 if (!parseLocation(errorString, location, &scriptId, &lineNumber, &columnNum ber))
364 return; 367 return;
365 368
366 String condition = optionalCondition ? *optionalCondition : emptyString(); 369 String condition = optionalCondition ? *optionalCondition : emptyString();
367 370
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 int columnNumber; 423 int columnNumber;
421 424
422 if (!parseLocation(errorString, location, &scriptId, &lineNumber, &columnNum ber)) 425 if (!parseLocation(errorString, location, &scriptId, &lineNumber, &columnNum ber))
423 return; 426 return;
424 427
425 ScriptBreakpoint breakpoint(lineNumber, columnNumber, ""); 428 ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
426 m_continueToLocationBreakpointId = scriptDebugServer().setBreakpoint(scriptI d, breakpoint, &lineNumber, &columnNumber, interstateLocation); 429 m_continueToLocationBreakpointId = scriptDebugServer().setBreakpoint(scriptI d, breakpoint, &lineNumber, &columnNumber, interstateLocation);
427 resume(errorString); 430 resume(errorString);
428 } 431 }
429 432
430 void InspectorDebuggerAgent::getStepInPositions(ErrorString* errorString, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugger::Location> >& positions) 433 void InspectorDebuggerAgent::getStepInPositions(ErrorString* errorString, const String& callFrameId, RefPtr<Array<Location> >& positions)
431 { 434 {
432 if (!isPaused() || m_currentCallStack.isNull()) { 435 if (!isPaused() || m_currentCallStack.isNull()) {
433 *errorString = "Attempt to access callframe when debugger is not on paus e"; 436 *errorString = "Attempt to access callframe when debugger is not on paus e";
434 return; 437 return;
435 } 438 }
436 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId); 439 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId);
437 if (injectedScript.hasNoValue()) { 440 if (injectedScript.hasNoValue()) {
438 *errorString = "Inspected frame has gone"; 441 *errorString = "Inspected frame has gone";
439 return; 442 return;
440 } 443 }
441 444
442 injectedScript.getStepInPositions(errorString, m_currentCallStack, callFrame Id, positions); 445 injectedScript.getStepInPositions(errorString, m_currentCallStack, callFrame Id, positions);
443 } 446 }
444 447
445 void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array <TypeBuilder::Debugger::CallFrame> >& callFrames) 448 void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array <CallFrame> >& callFrames)
loislo 2013/11/20 01:39:18 please move these changes into another patch.
aandrey 2013/11/20 15:20:02 Extracted to https://codereview.chromium.org/77173
446 { 449 {
447 if (!assertPaused(errorString)) 450 if (!assertPaused(errorString))
448 return; 451 return;
449 scriptDebugServer().updateCallStack(&m_currentCallStack); 452 scriptDebugServer().updateCallStack(&m_currentCallStack);
450 callFrames = currentCallFrames(); 453 callFrames = currentCallFrames();
451 } 454 }
452 455
453 String InspectorDebuggerAgent::scriptURL(JavaScriptCallFrame* frame) 456 String InspectorDebuggerAgent::scriptURL(JavaScriptCallFrame* frame)
454 { 457 {
455 String scriptIdString = String::number(frame->sourceID()); 458 String scriptIdString = String::number(frame->sourceID());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (m_skipStepInCount > 0) { 535 if (m_skipStepInCount > 0) {
533 --m_skipStepInCount; 536 --m_skipStepInCount;
534 return ScriptDebugListener::StepInto; 537 return ScriptDebugListener::StepInto;
535 } 538 }
536 return ScriptDebugListener::StepOut; 539 return ScriptDebugListener::StepOut;
537 } 540 }
538 } 541 }
539 return ScriptDebugListener::NoSkip; 542 return ScriptDebugListener::NoSkip;
540 } 543 }
541 544
542 PassRefPtr<TypeBuilder::Debugger::Location> InspectorDebuggerAgent::resolveBreak point(const String& breakpointId, const String& scriptId, const ScriptBreakpoint & breakpoint, BreakpointSource source) 545 PassRefPtr<Location> InspectorDebuggerAgent::resolveBreakpoint(const String& bre akpointId, const String& scriptId, const ScriptBreakpoint& breakpoint, Breakpoin tSource source)
543 { 546 {
544 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId); 547 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId);
545 if (scriptIterator == m_scripts.end()) 548 if (scriptIterator == m_scripts.end())
546 return 0; 549 return 0;
547 Script& script = scriptIterator->value; 550 Script& script = scriptIterator->value;
548 if (breakpoint.lineNumber < script.startLine || script.endLine < breakpoint. lineNumber) 551 if (breakpoint.lineNumber < script.startLine || script.endLine < breakpoint. lineNumber)
549 return 0; 552 return 0;
550 553
551 int actualLineNumber; 554 int actualLineNumber;
552 int actualColumnNumber; 555 int actualColumnNumber;
553 String debugServerBreakpointId = scriptDebugServer().setBreakpoint(scriptId, breakpoint, &actualLineNumber, &actualColumnNumber, false); 556 String debugServerBreakpointId = scriptDebugServer().setBreakpoint(scriptId, breakpoint, &actualLineNumber, &actualColumnNumber, false);
554 if (debugServerBreakpointId.isEmpty()) 557 if (debugServerBreakpointId.isEmpty())
555 return 0; 558 return 0;
556 559
557 m_serverBreakpoints.set(debugServerBreakpointId, std::make_pair(breakpointId , source)); 560 m_serverBreakpoints.set(debugServerBreakpointId, std::make_pair(breakpointId , source));
558 561
559 BreakpointIdToDebugServerBreakpointIdsMap::iterator debugServerBreakpointIds Iterator = m_breakpointIdToDebugServerBreakpointIds.find(breakpointId); 562 BreakpointIdToDebugServerBreakpointIdsMap::iterator debugServerBreakpointIds Iterator = m_breakpointIdToDebugServerBreakpointIds.find(breakpointId);
560 if (debugServerBreakpointIdsIterator == m_breakpointIdToDebugServerBreakpoin tIds.end()) 563 if (debugServerBreakpointIdsIterator == m_breakpointIdToDebugServerBreakpoin tIds.end())
561 debugServerBreakpointIdsIterator = m_breakpointIdToDebugServerBreakpoint Ids.set(breakpointId, Vector<String>()).iterator; 564 debugServerBreakpointIdsIterator = m_breakpointIdToDebugServerBreakpoint Ids.set(breakpointId, Vector<String>()).iterator;
562 debugServerBreakpointIdsIterator->value.append(debugServerBreakpointId); 565 debugServerBreakpointIdsIterator->value.append(debugServerBreakpointId);
563 566
564 RefPtr<TypeBuilder::Debugger::Location> location = TypeBuilder::Debugger::Lo cation::create() 567 RefPtr<Location> location = Location::create()
565 .setScriptId(scriptId) 568 .setScriptId(scriptId)
566 .setLineNumber(actualLineNumber); 569 .setLineNumber(actualLineNumber);
567 location->setColumnNumber(actualColumnNumber); 570 location->setColumnNumber(actualColumnNumber);
568 return location; 571 return location;
569 } 572 }
570 573
571 static PassRefPtr<JSONObject> scriptToInspectorObject(ScriptObject scriptObject) 574 static PassRefPtr<JSONObject> scriptToInspectorObject(ScriptObject scriptObject)
572 { 575 {
573 if (scriptObject.hasNoValue()) 576 if (scriptObject.hasNoValue())
574 return 0; 577 return 0;
575 RefPtr<JSONValue> value = scriptObject.toJSONValue(scriptObject.scriptState( )); 578 RefPtr<JSONValue> value = scriptObject.toJSONValue(scriptObject.scriptState( ));
576 if (!value) 579 if (!value)
577 return 0; 580 return 0;
578 return value->asObject(); 581 return value->asObject();
579 } 582 }
580 583
581 void InspectorDebuggerAgent::searchInContent(ErrorString* error, const String& s criptId, const String& query, const bool* const optionalCaseSensitive, const boo l* const optionalIsRegex, RefPtr<Array<WebCore::TypeBuilder::Page::SearchMatch> >& results) 584 void InspectorDebuggerAgent::searchInContent(ErrorString* error, const String& s criptId, const String& query, const bool* const optionalCaseSensitive, const boo l* const optionalIsRegex, RefPtr<Array<WebCore::TypeBuilder::Page::SearchMatch> >& results)
582 { 585 {
583 bool isRegex = optionalIsRegex ? *optionalIsRegex : false; 586 bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
584 bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false; 587 bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
585 588
586 ScriptsMap::iterator it = m_scripts.find(scriptId); 589 ScriptsMap::iterator it = m_scripts.find(scriptId);
587 if (it != m_scripts.end()) 590 if (it != m_scripts.end())
588 results = ContentSearchUtils::searchInTextByLines(it->value.source, quer y, caseSensitive, isRegex); 591 results = ContentSearchUtils::searchInTextByLines(it->value.source, quer y, caseSensitive, isRegex);
589 else 592 else
590 *error = "No script for id: " + scriptId; 593 *error = "No script for id: " + scriptId;
591 } 594 }
592 595
593 void InspectorDebuggerAgent::setScriptSource(ErrorString* error, RefPtr<TypeBuil der::Debugger::SetScriptSourceError>& errorData, const String& scriptId, const S tring& newContent, const bool* const preview, RefPtr<Array<TypeBuilder::Debugger ::CallFrame> >& newCallFrames, RefPtr<JSONObject>& result) 596 void InspectorDebuggerAgent::setScriptSource(ErrorString* error, RefPtr<TypeBuil der::Debugger::SetScriptSourceError>& errorData, const String& scriptId, const S tring& newContent, const bool* const preview, RefPtr<Array<CallFrame> >& newCall Frames, RefPtr<JSONObject>& result)
594 { 597 {
595 bool previewOnly = preview && *preview; 598 bool previewOnly = preview && *preview;
596 ScriptObject resultObject; 599 ScriptObject resultObject;
597 if (!scriptDebugServer().setScriptSource(scriptId, newContent, previewOnly, error, errorData, &m_currentCallStack, &resultObject)) 600 if (!scriptDebugServer().setScriptSource(scriptId, newContent, previewOnly, error, errorData, &m_currentCallStack, &resultObject))
598 return; 601 return;
599 newCallFrames = currentCallFrames(); 602 newCallFrames = currentCallFrames();
600 RefPtr<JSONObject> object = scriptToInspectorObject(resultObject); 603 RefPtr<JSONObject> object = scriptToInspectorObject(resultObject);
601 if (object) 604 if (object)
602 result = object; 605 result = object;
603 } 606 }
604 void InspectorDebuggerAgent::restartFrame(ErrorString* errorString, const String & callFrameId, RefPtr<Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<JSONObject>& result) 607 void InspectorDebuggerAgent::restartFrame(ErrorString* errorString, const String & callFrameId, RefPtr<Array<CallFrame> >& newCallFrames, RefPtr<JSONObject>& res ult)
605 { 608 {
606 if (!isPaused() || m_currentCallStack.isNull()) { 609 if (!isPaused() || m_currentCallStack.isNull()) {
607 *errorString = "Attempt to access callframe when debugger is not on paus e"; 610 *errorString = "Attempt to access callframe when debugger is not on paus e";
608 return; 611 return;
609 } 612 }
610 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId); 613 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId);
611 if (injectedScript.hasNoValue()) { 614 if (injectedScript.hasNoValue()) {
612 *errorString = "Inspected frame has gone"; 615 *errorString = "Inspected frame has gone";
613 return; 616 return;
614 } 617 }
615 618
616 injectedScript.restartFrame(errorString, m_currentCallStack, callFrameId, &r esult); 619 injectedScript.restartFrame(errorString, m_currentCallStack, callFrameId, &r esult);
617 scriptDebugServer().updateCallStack(&m_currentCallStack); 620 scriptDebugServer().updateCallStack(&m_currentCallStack);
618 newCallFrames = currentCallFrames(); 621 newCallFrames = currentCallFrames();
619 } 622 }
620 623
621 void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& s criptId, String* scriptSource) 624 void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& s criptId, String* scriptSource)
622 { 625 {
623 ScriptsMap::iterator it = m_scripts.find(scriptId); 626 ScriptsMap::iterator it = m_scripts.find(scriptId);
624 if (it != m_scripts.end()) 627 if (it != m_scripts.end())
625 *scriptSource = it->value.source; 628 *scriptSource = it->value.source;
626 else 629 else
627 *error = "No script for id: " + scriptId; 630 *error = "No script for id: " + scriptId;
628 } 631 }
629 632
630 void InspectorDebuggerAgent::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<TypeBuilder::Debugger::FunctionDetails>& details) 633 void InspectorDebuggerAgent::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>& details)
631 { 634 {
632 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(functionId); 635 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(functionId);
633 if (injectedScript.hasNoValue()) { 636 if (injectedScript.hasNoValue()) {
634 *errorString = "Function object id is obsolete"; 637 *errorString = "Function object id is obsolete";
635 return; 638 return;
636 } 639 }
637 injectedScript.getFunctionDetails(errorString, functionId, &details); 640 injectedScript.getFunctionDetails(errorString, functionId, &details);
638 } 641 }
639 642
640 void InspectorDebuggerAgent::schedulePauseOnNextStatement(InspectorFrontend::Deb ugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data) 643 void InspectorDebuggerAgent::schedulePauseOnNextStatement(InspectorFrontend::Deb ugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data)
641 { 644 {
642 if (m_javaScriptPauseScheduled) 645 if (m_javaScriptPauseScheduled)
643 return; 646 return;
644 m_breakReason = breakReason; 647 m_breakReason = breakReason;
645 m_breakAuxData = data; 648 m_breakAuxData = data;
646 scriptDebugServer().setPauseOnNextStatement(true); 649 scriptDebugServer().setPauseOnNextStatement(true);
647 } 650 }
648 651
649 void InspectorDebuggerAgent::cancelPauseOnNextStatement() 652 void InspectorDebuggerAgent::cancelPauseOnNextStatement()
650 { 653 {
651 if (m_javaScriptPauseScheduled) 654 if (m_javaScriptPauseScheduled)
652 return; 655 return;
653 clearBreakDetails(); 656 clearBreakDetails();
654 scriptDebugServer().setPauseOnNextStatement(false); 657 scriptDebugServer().setPauseOnNextStatement(false);
655 } 658 }
656 659
660 void InspectorDebuggerAgent::requestAsyncCallFramesIfNeeded()
661 {
662 if (m_asyncCallStackTracker.isEnabled())
663 scriptDebugServer().requestAsyncCallFrames();
664 }
665
666 void InspectorDebuggerAgent::didRequestAsyncCallFrames(ScriptValue callFrames)
667 {
668 m_asyncCallStackTracker.didRequestAsyncCallFrames(callFrames);
669 }
670
671 void InspectorDebuggerAgent::didInstallTimer(ExecutionContext*, int timerId, int timeout, bool singleShot)
672 {
673 m_asyncCallStackTracker.didInstallTimer(timerId, singleShot);
674 requestAsyncCallFramesIfNeeded();
675 }
676
677 void InspectorDebuggerAgent::didRemoveTimer(ExecutionContext*, int timerId)
678 {
679 m_asyncCallStackTracker.didRemoveTimer(timerId);
680 }
681
682 bool InspectorDebuggerAgent::willFireTimer(ExecutionContext*, int timerId)
683 {
684 m_asyncCallStackTracker.willFireTimer(timerId);
685 return true;
686 }
687
657 void InspectorDebuggerAgent::didFireTimer() 688 void InspectorDebuggerAgent::didFireTimer()
658 { 689 {
690 m_asyncCallStackTracker.didAsyncCall();
659 cancelPauseOnNextStatement(); 691 cancelPauseOnNextStatement();
660 } 692 }
661 693
694 void InspectorDebuggerAgent::didRequestAnimationFrame(Document*, int callbackId)
695 {
696 m_asyncCallStackTracker.didRequestAnimationFrame(callbackId);
697 requestAsyncCallFramesIfNeeded();
698 }
699
700 void InspectorDebuggerAgent::didCancelAnimationFrame(Document*, int callbackId)
701 {
702 m_asyncCallStackTracker.didCancelAnimationFrame(callbackId);
703 }
704
705 bool InspectorDebuggerAgent::willFireAnimationFrame(Document*, int callbackId)
706 {
707 m_asyncCallStackTracker.willFireAnimationFrame(callbackId);
708 return true;
709 }
710
711 void InspectorDebuggerAgent::didFireAnimationFrame()
712 {
713 m_asyncCallStackTracker.didAsyncCall();
714 }
715
662 void InspectorDebuggerAgent::didHandleEvent() 716 void InspectorDebuggerAgent::didHandleEvent()
663 { 717 {
664 cancelPauseOnNextStatement(); 718 cancelPauseOnNextStatement();
665 } 719 }
666 720
667 void InspectorDebuggerAgent::pause(ErrorString*) 721 void InspectorDebuggerAgent::pause(ErrorString*)
668 { 722 {
669 if (m_javaScriptPauseScheduled) 723 if (m_javaScriptPauseScheduled)
670 return; 724 return;
671 clearBreakDetails(); 725 clearBreakDetails();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 801
748 void InspectorDebuggerAgent::setPauseOnExceptionsImpl(ErrorString* errorString, int pauseState) 802 void InspectorDebuggerAgent::setPauseOnExceptionsImpl(ErrorString* errorString, int pauseState)
749 { 803 {
750 scriptDebugServer().setPauseOnExceptionsState(static_cast<ScriptDebugServer: :PauseOnExceptionsState>(pauseState)); 804 scriptDebugServer().setPauseOnExceptionsState(static_cast<ScriptDebugServer: :PauseOnExceptionsState>(pauseState));
751 if (scriptDebugServer().pauseOnExceptionsState() != pauseState) 805 if (scriptDebugServer().pauseOnExceptionsState() != pauseState)
752 *errorString = "Internal error. Could not change pause on exceptions sta te"; 806 *errorString = "Internal error. Could not change pause on exceptions sta te";
753 else 807 else
754 m_state->setLong(DebuggerAgentState::pauseOnExceptionsState, pauseState) ; 808 m_state->setLong(DebuggerAgentState::pauseOnExceptionsState, pauseState) ;
755 } 809 }
756 810
757 void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, const String& callFrameId, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptio nsAndMuteConsole, const bool* const returnByValue, const bool* generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool> * wasThrown) 811 void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, const String& callFrameId, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptio nsAndMuteConsole, const bool* const returnByValue, const bool* generatePreview, RefPtr<RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown)
758 { 812 {
759 if (!isPaused() || m_currentCallStack.isNull()) { 813 if (!isPaused() || m_currentCallStack.isNull()) {
760 *errorString = "Attempt to access callframe when debugger is not on paus e"; 814 *errorString = "Attempt to access callframe when debugger is not on paus e";
761 return; 815 return;
762 } 816 }
763 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId); 817 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId);
764 if (injectedScript.hasNoValue()) { 818 if (injectedScript.hasNoValue()) {
765 *errorString = "Inspected frame has gone"; 819 *errorString = "Inspected frame has gone";
766 return; 820 return;
767 } 821 }
(...skipping 26 matching lines...) Expand all
794 String exceptionMessage; 848 String exceptionMessage;
795 scriptDebugServer().compileScript(injectedScript.scriptState(), expression, sourceURL, &scriptIdValue, &exceptionMessage); 849 scriptDebugServer().compileScript(injectedScript.scriptState(), expression, sourceURL, &scriptIdValue, &exceptionMessage);
796 if (!scriptIdValue && !exceptionMessage) { 850 if (!scriptIdValue && !exceptionMessage) {
797 *errorString = "Script compilation failed"; 851 *errorString = "Script compilation failed";
798 return; 852 return;
799 } 853 }
800 *syntaxErrorMessage = exceptionMessage; 854 *syntaxErrorMessage = exceptionMessage;
801 *scriptId = scriptIdValue; 855 *scriptId = scriptIdValue;
802 } 856 }
803 857
804 void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId& scriptId, const int* executionContextId, const String* const objectGroup, const bool* const doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime:: RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) 858 void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId& scriptId, const int* executionContextId, const String* const objectGroup, const bool* const doNotPauseOnExceptionsAndMuteConsole, RefPtr<RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown)
805 { 859 {
806 InjectedScript injectedScript = injectedScriptForEval(errorString, execution ContextId); 860 InjectedScript injectedScript = injectedScriptForEval(errorString, execution ContextId);
807 if (injectedScript.hasNoValue()) { 861 if (injectedScript.hasNoValue()) {
808 *errorString = "Inspected frame has gone"; 862 *errorString = "Inspected frame has gone";
809 return; 863 return;
810 } 864 }
811 865
812 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = s criptDebugServer().pauseOnExceptionsState(); 866 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = s criptDebugServer().pauseOnExceptionsState();
813 if (doNotPauseOnExceptionsAndMuteConsole && *doNotPauseOnExceptionsAndMuteCo nsole) { 867 if (doNotPauseOnExceptionsAndMuteConsole && *doNotPauseOnExceptionsAndMuteCo nsole) {
814 if (previousPauseOnExceptionsState != ScriptDebugServer::DontPauseOnExce ptions) 868 if (previousPauseOnExceptionsState != ScriptDebugServer::DontPauseOnExce ptions)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 compiled = compileSkipCallFramePattern(patternValue); 930 compiled = compileSkipCallFramePattern(patternValue);
877 if (!compiled) { 931 if (!compiled) {
878 *errorString = "Invalid regular expression"; 932 *errorString = "Invalid regular expression";
879 return; 933 return;
880 } 934 }
881 } 935 }
882 m_state->setString(DebuggerAgentState::skipStackPattern, patternValue); 936 m_state->setString(DebuggerAgentState::skipStackPattern, patternValue);
883 m_cachedSkipStackRegExp = compiled.release(); 937 m_cachedSkipStackRegExp = compiled.release();
884 } 938 }
885 939
940 void InspectorDebuggerAgent::enableAsyncCallStacks(ErrorString*, int depth)
941 {
942 m_asyncCallStackTracker.setMaxAsyncCallStackDepth(depth);
943 }
944
886 void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directive Text) 945 void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directive Text)
887 { 946 {
888 if (scriptDebugServer().pauseOnExceptionsState() != ScriptDebugServer::DontP auseOnExceptions) { 947 if (scriptDebugServer().pauseOnExceptionsState() != ScriptDebugServer::DontP auseOnExceptions) {
889 RefPtr<JSONObject> directive = JSONObject::create(); 948 RefPtr<JSONObject> directive = JSONObject::create();
890 directive->setString("directiveText", directiveText); 949 directive->setString("directiveText", directiveText);
891 breakProgram(InspectorFrontend::Debugger::Reason::CSPViolation, directiv e.release()); 950 breakProgram(InspectorFrontend::Debugger::Reason::CSPViolation, directiv e.release());
892 } 951 }
893 } 952 }
894 953
895 PassRefPtr<Array<TypeBuilder::Debugger::CallFrame> > InspectorDebuggerAgent::cur rentCallFrames() 954 PassRefPtr<Array<CallFrame> > InspectorDebuggerAgent::currentCallFrames()
896 { 955 {
897 if (!m_pausedScriptState) 956 if (!m_pausedScriptState)
898 return Array<TypeBuilder::Debugger::CallFrame>::create(); 957 return Array<CallFrame>::create();
899 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m _pausedScriptState); 958 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m _pausedScriptState);
900 if (injectedScript.hasNoValue()) { 959 if (injectedScript.hasNoValue()) {
901 ASSERT_NOT_REACHED(); 960 ASSERT_NOT_REACHED();
902 return Array<TypeBuilder::Debugger::CallFrame>::create(); 961 return Array<CallFrame>::create();
903 } 962 }
904 return injectedScript.wrapCallFrames(m_currentCallStack); 963 RefPtr<Array<CallFrame> > result = injectedScript.wrapCallFrames(m_currentCa llStack);
964 if (!result->length())
965 return result.release();
966 RefPtr<Array<CallFrame> > lastCallFrames = result;
967 AsyncCallStackIterator asyncCallStacks = m_asyncCallStackTracker.currentAsyn cCallStack();
968 while (asyncCallStacks.hasNext()) {
969 RefPtr<CallFrame> last = CallFrame::runtimeCast(lastCallFrames->asArray( )->get(lastCallFrames->length() - 1));
yurys 2013/11/20 01:23:43 Wouldn't lastCallFrames->get(lastCallFrames->lengt
aandrey 2013/11/20 15:20:02 Nope. TypeBuilder::Array::get is protected as well
970 lastCallFrames = injectedScript.wrapCallFrames(asyncCallStacks.next());
971 if (!lastCallFrames->length())
972 break;
973 last->setAsyncCallFrames(lastCallFrames);
974 }
975 return result.release();
905 } 976 }
906 977
907 String InspectorDebuggerAgent::sourceMapURLForScript(const Script& script) 978 String InspectorDebuggerAgent::sourceMapURLForScript(const Script& script)
908 { 979 {
909 bool deprecated; 980 bool deprecated;
910 String sourceMapURL = ContentSearchUtils::findSourceMapURL(script.source, Co ntentSearchUtils::JavaScriptMagicComment, &deprecated); 981 String sourceMapURL = ContentSearchUtils::findSourceMapURL(script.source, Co ntentSearchUtils::JavaScriptMagicComment, &deprecated);
911 if (!sourceMapURL.isEmpty()) { 982 if (!sourceMapURL.isEmpty()) {
912 // FIXME: add deprecated console message here. 983 // FIXME: add deprecated console message here.
913 return sourceMapURL; 984 return sourceMapURL;
914 } 985 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 bool isRegex; 1027 bool isRegex;
957 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex); 1028 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex);
958 String url; 1029 String url;
959 breakpointObject->getString(DebuggerAgentState::url, &url); 1030 breakpointObject->getString(DebuggerAgentState::url, &url);
960 if (!matches(scriptURL, url, isRegex)) 1031 if (!matches(scriptURL, url, isRegex))
961 continue; 1032 continue;
962 ScriptBreakpoint breakpoint; 1033 ScriptBreakpoint breakpoint;
963 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1034 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
964 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1035 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
965 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1036 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
966 RefPtr<TypeBuilder::Debugger::Location> location = resolveBreakpoint(it- >key, scriptId, breakpoint, UserBreakpointSource); 1037 RefPtr<Location> location = resolveBreakpoint(it->key, scriptId, breakpo int, UserBreakpointSource);
967 if (location) 1038 if (location)
968 m_frontend->breakpointResolved(it->key, location); 1039 m_frontend->breakpointResolved(it->key, location);
969 } 1040 }
970 } 1041 }
971 1042
972 void InspectorDebuggerAgent::failedToParseSource(const String& url, const String & data, int firstLine, int errorLine, const String& errorMessage) 1043 void InspectorDebuggerAgent::failedToParseSource(const String& url, const String & data, int firstLine, int errorLine, const String& errorMessage)
973 { 1044 {
974 m_frontend->scriptFailedToParse(url, data, firstLine, errorLine, errorMessag e); 1045 m_frontend->scriptFailedToParse(url, data, firstLine, errorLine, errorMessag e);
975 } 1046 }
976 1047
977 void InspectorDebuggerAgent::didPause(ScriptState* scriptState, const ScriptValu e& callFrames, const ScriptValue& exception, const Vector<String>& hitBreakpoint s) 1048 void InspectorDebuggerAgent::didPause(ScriptState* scriptState, const ScriptValu e& callFrames, const ScriptValue& exception, const Vector<String>& hitBreakpoint s)
978 { 1049 {
979 ASSERT(scriptState && !m_pausedScriptState); 1050 ASSERT(scriptState && !m_pausedScriptState);
980 m_pausedScriptState = scriptState; 1051 m_pausedScriptState = scriptState;
981 m_currentCallStack = callFrames; 1052 m_currentCallStack = callFrames;
982 1053
983 m_skipStepInCount = numberOfStepsBeforeStepOut; 1054 m_skipStepInCount = numberOfStepsBeforeStepOut;
984 1055
985 if (!exception.hasNoValue()) { 1056 if (!exception.hasNoValue()) {
986 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptF or(scriptState); 1057 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptF or(scriptState);
987 if (!injectedScript.hasNoValue()) { 1058 if (!injectedScript.hasNoValue()) {
988 m_breakReason = InspectorFrontend::Debugger::Reason::Exception; 1059 m_breakReason = InspectorFrontend::Debugger::Reason::Exception;
989 m_breakAuxData = injectedScript.wrapObject(exception, "backtrace")-> openAccessors(); 1060 m_breakAuxData = injectedScript.wrapObject(exception, InspectorDebug gerAgent::backtraceObjectGroup)->openAccessors();
990 // m_breakAuxData might be null after this. 1061 // m_breakAuxData might be null after this.
991 } 1062 }
992 } 1063 }
993 1064
994 RefPtr<Array<String> > hitBreakpointIds = Array<String>::create(); 1065 RefPtr<Array<String> > hitBreakpointIds = Array<String>::create();
995 1066
996 for (Vector<String>::const_iterator i = hitBreakpoints.begin(); i != hitBrea kpoints.end(); ++i) { 1067 for (Vector<String>::const_iterator i = hitBreakpoints.begin(); i != hitBrea kpoints.end(); ++i) {
997 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter ator = m_serverBreakpoints.find(*i); 1068 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter ator = m_serverBreakpoints.find(*i);
998 if (breakpointIterator != m_serverBreakpoints.end()) { 1069 if (breakpointIterator != m_serverBreakpoints.end()) {
999 const String& localId = breakpointIterator->value.first; 1070 const String& localId = breakpointIterator->value.first;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 m_breakAuxData = data; 1108 m_breakAuxData = data;
1038 scriptDebugServer().breakProgram(); 1109 scriptDebugServer().breakProgram();
1039 } 1110 }
1040 1111
1041 void InspectorDebuggerAgent::clear() 1112 void InspectorDebuggerAgent::clear()
1042 { 1113 {
1043 m_pausedScriptState = 0; 1114 m_pausedScriptState = 0;
1044 m_currentCallStack = ScriptValue(); 1115 m_currentCallStack = ScriptValue();
1045 m_scripts.clear(); 1116 m_scripts.clear();
1046 m_breakpointIdToDebugServerBreakpointIds.clear(); 1117 m_breakpointIdToDebugServerBreakpointIds.clear();
1118 m_asyncCallStackTracker.clear();
1047 m_continueToLocationBreakpointId = String(); 1119 m_continueToLocationBreakpointId = String();
1048 clearBreakDetails(); 1120 clearBreakDetails();
1049 m_javaScriptPauseScheduled = false; 1121 m_javaScriptPauseScheduled = false;
1050 ErrorString error; 1122 ErrorString error;
1051 setOverlayMessage(&error, 0); 1123 setOverlayMessage(&error, 0);
1052 } 1124 }
1053 1125
1054 bool InspectorDebuggerAgent::assertPaused(ErrorString* errorString) 1126 bool InspectorDebuggerAgent::assertPaused(ErrorString* errorString)
1055 { 1127 {
1056 if (!m_pausedScriptState) { 1128 if (!m_pausedScriptState) {
(...skipping 18 matching lines...) Expand all
1075 1147
1076 void InspectorDebuggerAgent::removeBreakpoint(const String& scriptId, int lineNu mber, int columnNumber, BreakpointSource source) 1148 void InspectorDebuggerAgent::removeBreakpoint(const String& scriptId, int lineNu mber, int columnNumber, BreakpointSource source)
1077 { 1149 {
1078 removeBreakpoint(generateBreakpointId(scriptId, lineNumber, columnNumber, so urce)); 1150 removeBreakpoint(generateBreakpointId(scriptId, lineNumber, columnNumber, so urce));
1079 } 1151 }
1080 1152
1081 void InspectorDebuggerAgent::reset() 1153 void InspectorDebuggerAgent::reset()
1082 { 1154 {
1083 m_scripts.clear(); 1155 m_scripts.clear();
1084 m_breakpointIdToDebugServerBreakpointIds.clear(); 1156 m_breakpointIdToDebugServerBreakpointIds.clear();
1157 m_asyncCallStackTracker.clear();
1085 if (m_frontend) 1158 if (m_frontend)
1086 m_frontend->globalObjectCleared(); 1159 m_frontend->globalObjectCleared();
1087 } 1160 }
1088 1161
1089 } // namespace WebCore 1162 } // namespace WebCore
1090 1163
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698