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

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: fixed test flakiness Created 7 years 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return; 441 return;
442 } 442 }
443 443
444 injectedScript.getStepInPositions(errorString, m_currentCallStack, callFrame Id, positions); 444 injectedScript.getStepInPositions(errorString, m_currentCallStack, callFrame Id, positions);
445 } 445 }
446 446
447 void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array <CallFrame> >& callFrames, RefPtr<StackTrace>& asyncStackTrace) 447 void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array <CallFrame> >& callFrames, RefPtr<StackTrace>& asyncStackTrace)
448 { 448 {
449 if (!assertPaused(errorString)) 449 if (!assertPaused(errorString))
450 return; 450 return;
451 scriptDebugServer().updateCallStack(&m_currentCallStack); 451 m_currentCallStack = scriptDebugServer().currentCallFrames();
452 callFrames = currentCallFrames(); 452 callFrames = currentCallFrames();
453 asyncStackTrace = currentAsyncStackTrace(); 453 asyncStackTrace = currentAsyncStackTrace();
454 } 454 }
455 455
456 String InspectorDebuggerAgent::scriptURL(JavaScriptCallFrame* frame) 456 String InspectorDebuggerAgent::scriptURL(JavaScriptCallFrame* frame)
457 { 457 {
458 String scriptIdString = String::number(frame->sourceID()); 458 String scriptIdString = String::number(frame->sourceID());
459 ScriptsMap::iterator it = m_scripts.find(scriptIdString); 459 ScriptsMap::iterator it = m_scripts.find(scriptIdString);
460 if (it == m_scripts.end()) 460 if (it == m_scripts.end())
461 return String(); 461 return String();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 *errorString = "Attempt to access callframe when debugger is not on paus e"; 612 *errorString = "Attempt to access callframe when debugger is not on paus e";
613 return; 613 return;
614 } 614 }
615 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId); 615 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb jectId(callFrameId);
616 if (injectedScript.hasNoValue()) { 616 if (injectedScript.hasNoValue()) {
617 *errorString = "Inspected frame has gone"; 617 *errorString = "Inspected frame has gone";
618 return; 618 return;
619 } 619 }
620 620
621 injectedScript.restartFrame(errorString, m_currentCallStack, callFrameId, &r esult); 621 injectedScript.restartFrame(errorString, m_currentCallStack, callFrameId, &r esult);
622 scriptDebugServer().updateCallStack(&m_currentCallStack); 622 m_currentCallStack = scriptDebugServer().currentCallFrames();
623 newCallFrames = currentCallFrames(); 623 newCallFrames = currentCallFrames();
624 asyncStackTrace = currentAsyncStackTrace(); 624 asyncStackTrace = currentAsyncStackTrace();
625 } 625 }
626 626
627 void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& s criptId, String* scriptSource) 627 void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& s criptId, String* scriptSource)
628 { 628 {
629 ScriptsMap::iterator it = m_scripts.find(scriptId); 629 ScriptsMap::iterator it = m_scripts.find(scriptId);
630 if (it != m_scripts.end()) 630 if (it != m_scripts.end())
631 *scriptSource = it->value.source; 631 *scriptSource = it->value.source;
632 else 632 else
(...skipping 20 matching lines...) Expand all
653 } 653 }
654 654
655 void InspectorDebuggerAgent::cancelPauseOnNextStatement() 655 void InspectorDebuggerAgent::cancelPauseOnNextStatement()
656 { 656 {
657 if (m_javaScriptPauseScheduled) 657 if (m_javaScriptPauseScheduled)
658 return; 658 return;
659 clearBreakDetails(); 659 clearBreakDetails();
660 scriptDebugServer().setPauseOnNextStatement(false); 660 scriptDebugServer().setPauseOnNextStatement(false);
661 } 661 }
662 662
663 void InspectorDebuggerAgent::didInstallTimer(ExecutionContext*, int timerId, int timeout, bool singleShot)
664 {
665 if (m_asyncCallStackTracker.isEnabled())
666 m_asyncCallStackTracker.didInstallTimer(timerId, singleShot, scriptDebug Server().currentCallFrames());
667 }
668
669 void InspectorDebuggerAgent::didRemoveTimer(ExecutionContext*, int timerId)
670 {
671 m_asyncCallStackTracker.didRemoveTimer(timerId);
672 }
673
674 bool InspectorDebuggerAgent::willFireTimer(ExecutionContext*, int timerId)
675 {
676 m_asyncCallStackTracker.willFireTimer(timerId);
677 return true;
678 }
679
663 void InspectorDebuggerAgent::didFireTimer() 680 void InspectorDebuggerAgent::didFireTimer()
664 { 681 {
682 m_asyncCallStackTracker.didFireAsyncCall();
665 cancelPauseOnNextStatement(); 683 cancelPauseOnNextStatement();
666 } 684 }
667 685
686 void InspectorDebuggerAgent::didRequestAnimationFrame(Document*, int callbackId)
687 {
688 if (m_asyncCallStackTracker.isEnabled())
689 m_asyncCallStackTracker.didRequestAnimationFrame(callbackId, scriptDebug Server().currentCallFrames());
690 }
691
692 void InspectorDebuggerAgent::didCancelAnimationFrame(Document*, int callbackId)
693 {
694 m_asyncCallStackTracker.didCancelAnimationFrame(callbackId);
695 }
696
697 bool InspectorDebuggerAgent::willFireAnimationFrame(Document*, int callbackId)
698 {
699 m_asyncCallStackTracker.willFireAnimationFrame(callbackId);
700 return true;
701 }
702
703 void InspectorDebuggerAgent::didFireAnimationFrame()
704 {
705 m_asyncCallStackTracker.didFireAsyncCall();
706 }
707
668 void InspectorDebuggerAgent::didHandleEvent() 708 void InspectorDebuggerAgent::didHandleEvent()
669 { 709 {
670 cancelPauseOnNextStatement(); 710 cancelPauseOnNextStatement();
671 } 711 }
672 712
673 void InspectorDebuggerAgent::pause(ErrorString*) 713 void InspectorDebuggerAgent::pause(ErrorString*)
674 { 714 {
675 if (m_javaScriptPauseScheduled) 715 if (m_javaScriptPauseScheduled)
676 return; 716 return;
677 clearBreakDetails(); 717 clearBreakDetails();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 compiled = compileSkipCallFramePattern(patternValue); 922 compiled = compileSkipCallFramePattern(patternValue);
883 if (!compiled) { 923 if (!compiled) {
884 *errorString = "Invalid regular expression"; 924 *errorString = "Invalid regular expression";
885 return; 925 return;
886 } 926 }
887 } 927 }
888 m_state->setString(DebuggerAgentState::skipStackPattern, patternValue); 928 m_state->setString(DebuggerAgentState::skipStackPattern, patternValue);
889 m_cachedSkipStackRegExp = compiled.release(); 929 m_cachedSkipStackRegExp = compiled.release();
890 } 930 }
891 931
932 void InspectorDebuggerAgent::setAsyncCallStackDepth(ErrorString*, int depth)
933 {
934 m_asyncCallStackTracker.setAsyncCallStackDepth(depth);
935 }
936
892 void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directive Text) 937 void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directive Text)
893 { 938 {
894 if (scriptDebugServer().pauseOnExceptionsState() != ScriptDebugServer::DontP auseOnExceptions) { 939 if (scriptDebugServer().pauseOnExceptionsState() != ScriptDebugServer::DontP auseOnExceptions) {
895 RefPtr<JSONObject> directive = JSONObject::create(); 940 RefPtr<JSONObject> directive = JSONObject::create();
896 directive->setString("directiveText", directiveText); 941 directive->setString("directiveText", directiveText);
897 breakProgram(InspectorFrontend::Debugger::Reason::CSPViolation, directiv e.release()); 942 breakProgram(InspectorFrontend::Debugger::Reason::CSPViolation, directiv e.release());
898 } 943 }
899 } 944 }
900 945
901 PassRefPtr<Array<CallFrame> > InspectorDebuggerAgent::currentCallFrames() 946 PassRefPtr<Array<CallFrame> > InspectorDebuggerAgent::currentCallFrames()
902 { 947 {
903 if (!m_pausedScriptState) 948 if (!m_pausedScriptState)
904 return Array<CallFrame>::create(); 949 return Array<CallFrame>::create();
905 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m _pausedScriptState); 950 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m _pausedScriptState);
906 if (injectedScript.hasNoValue()) { 951 if (injectedScript.hasNoValue()) {
907 ASSERT_NOT_REACHED(); 952 ASSERT_NOT_REACHED();
908 return Array<CallFrame>::create(); 953 return Array<CallFrame>::create();
909 } 954 }
910 return injectedScript.wrapCallFrames(m_currentCallStack); 955 return injectedScript.wrapCallFrames(m_currentCallStack);
911 } 956 }
912 957
913 PassRefPtr<StackTrace> InspectorDebuggerAgent::currentAsyncStackTrace() 958 PassRefPtr<StackTrace> InspectorDebuggerAgent::currentAsyncStackTrace()
914 { 959 {
915 // FIXME: Implement async stack traces. 960 if (!m_pausedScriptState || !m_asyncCallStackTracker.isEnabled())
916 return 0; 961 return 0;
962 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m _pausedScriptState);
963 if (injectedScript.hasNoValue()) {
964 ASSERT_NOT_REACHED();
965 return 0;
966 }
967 const AsyncCallStackTracker::AsyncCallChain* chain = m_asyncCallStackTracker .currentAsyncCallChain();
968 if (!chain)
969 return 0;
970 const AsyncCallStackTracker::AsyncCallStackVector& callStacks = chain->callS tacks();
971 if (callStacks.isEmpty())
972 return 0;
973 RefPtr<StackTrace> result;
974 for (AsyncCallStackTracker::AsyncCallStackVector::const_reverse_iterator it = callStacks.rbegin(); it != callStacks.rend(); ++it) {
975 RefPtr<StackTrace> next = StackTrace::create()
976 .setCallFrames(injectedScript.wrapCallFrames((*it)->callFrames()))
977 .release();
978 if (result)
979 next->setAsyncStackTrace(result.release());
980 result.swap(next);
981 }
982 return result.release();
917 } 983 }
918 984
919 String InspectorDebuggerAgent::sourceMapURLForScript(const Script& script) 985 String InspectorDebuggerAgent::sourceMapURLForScript(const Script& script)
920 { 986 {
921 bool deprecated; 987 bool deprecated;
922 String sourceMapURL = ContentSearchUtils::findSourceMapURL(script.source, Co ntentSearchUtils::JavaScriptMagicComment, &deprecated); 988 String sourceMapURL = ContentSearchUtils::findSourceMapURL(script.source, Co ntentSearchUtils::JavaScriptMagicComment, &deprecated);
923 if (!sourceMapURL.isEmpty()) { 989 if (!sourceMapURL.isEmpty()) {
924 // FIXME: add deprecated console message here. 990 // FIXME: add deprecated console message here.
925 return sourceMapURL; 991 return sourceMapURL;
926 } 992 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 ASSERT(scriptState && !m_pausedScriptState); 1057 ASSERT(scriptState && !m_pausedScriptState);
992 m_pausedScriptState = scriptState; 1058 m_pausedScriptState = scriptState;
993 m_currentCallStack = callFrames; 1059 m_currentCallStack = callFrames;
994 1060
995 m_skipStepInCount = numberOfStepsBeforeStepOut; 1061 m_skipStepInCount = numberOfStepsBeforeStepOut;
996 1062
997 if (!exception.hasNoValue()) { 1063 if (!exception.hasNoValue()) {
998 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptF or(scriptState); 1064 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptF or(scriptState);
999 if (!injectedScript.hasNoValue()) { 1065 if (!injectedScript.hasNoValue()) {
1000 m_breakReason = InspectorFrontend::Debugger::Reason::Exception; 1066 m_breakReason = InspectorFrontend::Debugger::Reason::Exception;
1001 m_breakAuxData = injectedScript.wrapObject(exception, "backtrace")-> openAccessors(); 1067 m_breakAuxData = injectedScript.wrapObject(exception, InspectorDebug gerAgent::backtraceObjectGroup)->openAccessors();
1002 // m_breakAuxData might be null after this. 1068 // m_breakAuxData might be null after this.
1003 } 1069 }
1004 } 1070 }
1005 1071
1006 RefPtr<Array<String> > hitBreakpointIds = Array<String>::create(); 1072 RefPtr<Array<String> > hitBreakpointIds = Array<String>::create();
1007 1073
1008 for (Vector<String>::const_iterator i = hitBreakpoints.begin(); i != hitBrea kpoints.end(); ++i) { 1074 for (Vector<String>::const_iterator i = hitBreakpoints.begin(); i != hitBrea kpoints.end(); ++i) {
1009 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter ator = m_serverBreakpoints.find(*i); 1075 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter ator = m_serverBreakpoints.find(*i);
1010 if (breakpointIterator != m_serverBreakpoints.end()) { 1076 if (breakpointIterator != m_serverBreakpoints.end()) {
1011 const String& localId = breakpointIterator->value.first; 1077 const String& localId = breakpointIterator->value.first;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 m_breakAuxData = data; 1115 m_breakAuxData = data;
1050 scriptDebugServer().breakProgram(); 1116 scriptDebugServer().breakProgram();
1051 } 1117 }
1052 1118
1053 void InspectorDebuggerAgent::clear() 1119 void InspectorDebuggerAgent::clear()
1054 { 1120 {
1055 m_pausedScriptState = 0; 1121 m_pausedScriptState = 0;
1056 m_currentCallStack = ScriptValue(); 1122 m_currentCallStack = ScriptValue();
1057 m_scripts.clear(); 1123 m_scripts.clear();
1058 m_breakpointIdToDebugServerBreakpointIds.clear(); 1124 m_breakpointIdToDebugServerBreakpointIds.clear();
1125 m_asyncCallStackTracker.clear();
1059 m_continueToLocationBreakpointId = String(); 1126 m_continueToLocationBreakpointId = String();
1060 clearBreakDetails(); 1127 clearBreakDetails();
1061 m_javaScriptPauseScheduled = false; 1128 m_javaScriptPauseScheduled = false;
1062 ErrorString error; 1129 ErrorString error;
1063 setOverlayMessage(&error, 0); 1130 setOverlayMessage(&error, 0);
1064 } 1131 }
1065 1132
1066 bool InspectorDebuggerAgent::assertPaused(ErrorString* errorString) 1133 bool InspectorDebuggerAgent::assertPaused(ErrorString* errorString)
1067 { 1134 {
1068 if (!m_pausedScriptState) { 1135 if (!m_pausedScriptState) {
(...skipping 18 matching lines...) Expand all
1087 1154
1088 void InspectorDebuggerAgent::removeBreakpoint(const String& scriptId, int lineNu mber, int columnNumber, BreakpointSource source) 1155 void InspectorDebuggerAgent::removeBreakpoint(const String& scriptId, int lineNu mber, int columnNumber, BreakpointSource source)
1089 { 1156 {
1090 removeBreakpoint(generateBreakpointId(scriptId, lineNumber, columnNumber, so urce)); 1157 removeBreakpoint(generateBreakpointId(scriptId, lineNumber, columnNumber, so urce));
1091 } 1158 }
1092 1159
1093 void InspectorDebuggerAgent::reset() 1160 void InspectorDebuggerAgent::reset()
1094 { 1161 {
1095 m_scripts.clear(); 1162 m_scripts.clear();
1096 m_breakpointIdToDebugServerBreakpointIds.clear(); 1163 m_breakpointIdToDebugServerBreakpointIds.clear();
1164 m_asyncCallStackTracker.clear();
1097 if (m_frontend) 1165 if (m_frontend)
1098 m_frontend->globalObjectCleared(); 1166 m_frontend->globalObjectCleared();
1099 } 1167 }
1100 1168
1101 } // namespace WebCore 1169 } // namespace WebCore
1102 1170
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorDebuggerAgent.h ('k') | Source/core/inspector/InspectorInstrumentation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698