| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef V8DebuggerImpl_h | |
| 32 #define V8DebuggerImpl_h | |
| 33 | |
| 34 #include "platform/inspector_protocol/Collections.h" | |
| 35 #include "platform/inspector_protocol/Maybe.h" | |
| 36 #include "platform/inspector_protocol/Platform.h" | |
| 37 #include "platform/v8_inspector/JavaScriptCallFrame.h" | |
| 38 #include "platform/v8_inspector/V8DebuggerScript.h" | |
| 39 #include "platform/v8_inspector/protocol/Debugger.h" | |
| 40 #include "platform/v8_inspector/public/V8Debugger.h" | |
| 41 | |
| 42 #include <v8-debug.h> | |
| 43 #include <v8.h> | |
| 44 #include <vector> | |
| 45 | |
| 46 #include <vector> | |
| 47 | |
| 48 namespace blink { | |
| 49 | |
| 50 using protocol::Maybe; | |
| 51 | |
| 52 struct ScriptBreakpoint; | |
| 53 class InspectedContext; | |
| 54 class V8ConsoleMessageStorage; | |
| 55 class V8DebuggerAgentImpl; | |
| 56 class V8InspectorSessionImpl; | |
| 57 class V8RuntimeAgentImpl; | |
| 58 class V8StackTraceImpl; | |
| 59 | |
| 60 class V8DebuggerImpl : public V8Debugger { | |
| 61 PROTOCOL_DISALLOW_COPY(V8DebuggerImpl); | |
| 62 public: | |
| 63 V8DebuggerImpl(v8::Isolate*, V8DebuggerClient*); | |
| 64 ~V8DebuggerImpl() override; | |
| 65 | |
| 66 static int contextId(v8::Local<v8::Context>); | |
| 67 static int getGroupId(v8::Local<v8::Context>); | |
| 68 | |
| 69 bool enabled() const; | |
| 70 | |
| 71 String16 setBreakpoint(const String16& sourceID, const ScriptBreakpoint&, in
t* actualLineNumber, int* actualColumnNumber, bool interstatementLocation); | |
| 72 void removeBreakpoint(const String16& breakpointId); | |
| 73 void setBreakpointsActivated(bool); | |
| 74 bool breakpointsActivated() const { return m_breakpointsActivated; } | |
| 75 | |
| 76 enum PauseOnExceptionsState { | |
| 77 DontPauseOnExceptions, | |
| 78 PauseOnAllExceptions, | |
| 79 PauseOnUncaughtExceptions | |
| 80 }; | |
| 81 PauseOnExceptionsState getPauseOnExceptionsState(); | |
| 82 void setPauseOnExceptionsState(PauseOnExceptionsState); | |
| 83 void setPauseOnNextStatement(bool); | |
| 84 bool canBreakProgram(); | |
| 85 void breakProgram(); | |
| 86 void continueProgram(); | |
| 87 void stepIntoStatement(); | |
| 88 void stepOverStatement(); | |
| 89 void stepOutOfFunction(); | |
| 90 void clearStepping(); | |
| 91 | |
| 92 bool setScriptSource(const String16& sourceID, v8::Local<v8::String> newSour
ce, bool preview, ErrorString*, Maybe<protocol::Runtime::ExceptionDetails>*, Jav
aScriptCallFrames* newCallFrames, Maybe<bool>* stackChanged); | |
| 93 JavaScriptCallFrames currentCallFrames(int limit = 0); | |
| 94 | |
| 95 // Each script inherits debug data from v8::Context where it has been compil
ed. | |
| 96 // Only scripts whose debug data matches |contextGroupId| will be reported. | |
| 97 // Passing 0 will result in reporting all scripts. | |
| 98 void getCompiledScripts(int contextGroupId, std::vector<std::unique_ptr<V8De
buggerScript>>&); | |
| 99 void debuggerAgentEnabled(); | |
| 100 void debuggerAgentDisabled(); | |
| 101 | |
| 102 bool isPaused(); | |
| 103 v8::Local<v8::Context> pausedContext() { return m_pausedContext; } | |
| 104 int maxAsyncCallChainDepth() { return m_maxAsyncCallStackDepth; } | |
| 105 V8StackTraceImpl* currentAsyncCallChain(); | |
| 106 void setAsyncCallStackDepth(V8DebuggerAgentImpl*, int); | |
| 107 | |
| 108 v8::MaybeLocal<v8::Value> functionScopes(v8::Local<v8::Function>); | |
| 109 v8::MaybeLocal<v8::Array> internalProperties(v8::Local<v8::Context>, v8::Loc
al<v8::Value>); | |
| 110 | |
| 111 v8::Isolate* isolate() const { return m_isolate; } | |
| 112 V8DebuggerClient* client() { return m_client; } | |
| 113 | |
| 114 v8::MaybeLocal<v8::Value> runCompiledScript(v8::Local<v8::Context>, v8::Loca
l<v8::Script>); | |
| 115 v8::MaybeLocal<v8::Value> callFunction(v8::Local<v8::Function>, v8::Local<v8
::Context>, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]
); | |
| 116 v8::MaybeLocal<v8::Value> compileAndRunInternalScript(v8::Local<v8::Context>
, v8::Local<v8::String>); | |
| 117 v8::Local<v8::Script> compileScript(v8::Local<v8::Context>, v8::Local<v8::St
ring>, const String16& fileName, bool markAsInternal); | |
| 118 v8::Local<v8::Context> regexContext(); | |
| 119 | |
| 120 void enableStackCapturingIfNeeded(); | |
| 121 void disableStackCapturingIfNeeded(); | |
| 122 V8ConsoleMessageStorage* ensureConsoleMessageStorage(int contextGroupId); | |
| 123 std::unique_ptr<V8StackTraceImpl> createStackTraceImpl(v8::Local<v8::StackTr
ace>); | |
| 124 std::unique_ptr<V8StackTraceImpl> captureStackTraceImpl(bool fullStack); | |
| 125 | |
| 126 // V8Debugger implementation | |
| 127 std::unique_ptr<V8InspectorSession> connect(int contextGroupId, protocol::Fr
ontendChannel*, V8InspectorSessionClient*, const String16* state) override; | |
| 128 void contextCreated(const V8ContextInfo&) override; | |
| 129 void contextDestroyed(v8::Local<v8::Context>) override; | |
| 130 void resetContextGroup(int contextGroupId) override; | |
| 131 void willExecuteScript(v8::Local<v8::Context>, int scriptId) override; | |
| 132 void didExecuteScript(v8::Local<v8::Context>) override; | |
| 133 void idleStarted() override; | |
| 134 void idleFinished() override; | |
| 135 unsigned exceptionThrown(v8::Local<v8::Context>, const String16& message, v8
::Local<v8::Value> exception, const String16& detailedMessage, const String16& u
rl, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace>, i
nt scriptId) override; | |
| 136 void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId, const St
ring16& message) override; | |
| 137 std::unique_ptr<V8StackTrace> createStackTrace(v8::Local<v8::StackTrace>) ov
erride; | |
| 138 std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) override; | |
| 139 void asyncTaskScheduled(const String16& taskName, void* task, bool recurring
) override; | |
| 140 void asyncTaskCanceled(void* task) override; | |
| 141 void asyncTaskStarted(void* task) override; | |
| 142 void asyncTaskFinished(void* task) override; | |
| 143 void allAsyncTasksCanceled() override; | |
| 144 | |
| 145 using ContextByIdMap = protocol::HashMap<int, std::unique_ptr<InspectedConte
xt>>; | |
| 146 void discardInspectedContext(int contextGroupId, int contextId); | |
| 147 const ContextByIdMap* contextGroup(int contextGroupId); | |
| 148 void disconnect(V8InspectorSessionImpl*); | |
| 149 V8InspectorSessionImpl* sessionForContextGroup(int contextGroupId); | |
| 150 InspectedContext* getContext(int groupId, int contextId) const; | |
| 151 | |
| 152 private: | |
| 153 void enable(); | |
| 154 void disable(); | |
| 155 V8DebuggerAgentImpl* findEnabledDebuggerAgent(int contextGroupId); | |
| 156 V8DebuggerAgentImpl* findEnabledDebuggerAgent(v8::Local<v8::Context>); | |
| 157 | |
| 158 void compileDebuggerScript(); | |
| 159 v8::MaybeLocal<v8::Value> callDebuggerMethod(const char* functionName, int a
rgc, v8::Local<v8::Value> argv[]); | |
| 160 v8::Local<v8::Context> debuggerContext() const; | |
| 161 void clearBreakpoints(); | |
| 162 | |
| 163 static void breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>&)
; | |
| 164 void handleProgramBreak(v8::Local<v8::Context> pausedContext, v8::Local<v8::
Object> executionState, v8::Local<v8::Value> exception, v8::Local<v8::Array> hit
Breakpoints, bool isPromiseRejection = false); | |
| 165 static void v8DebugEventCallback(const v8::Debug::EventDetails&); | |
| 166 v8::Local<v8::Value> callInternalGetterFunction(v8::Local<v8::Object>, const
char* functionName); | |
| 167 void handleV8DebugEvent(const v8::Debug::EventDetails&); | |
| 168 | |
| 169 v8::Local<v8::String> v8InternalizedString(const char*) const; | |
| 170 | |
| 171 void handleV8AsyncTaskEvent(v8::Local<v8::Context>, v8::Local<v8::Object> ex
ecutionState, v8::Local<v8::Object> eventData); | |
| 172 | |
| 173 using ContextsByGroupMap = protocol::HashMap<int, std::unique_ptr<ContextByI
dMap>>; | |
| 174 | |
| 175 v8::Local<v8::Value> collectionEntries(v8::Local<v8::Context>, v8::Local<v8:
:Object>); | |
| 176 v8::Local<v8::Value> generatorObjectLocation(v8::Local<v8::Object>); | |
| 177 v8::Local<v8::Value> functionLocation(v8::Local<v8::Context>, v8::Local<v8::
Function>); | |
| 178 | |
| 179 v8::Isolate* m_isolate; | |
| 180 V8DebuggerClient* m_client; | |
| 181 ContextsByGroupMap m_contexts; | |
| 182 using SessionMap = protocol::HashMap<int, V8InspectorSessionImpl*>; | |
| 183 SessionMap m_sessions; | |
| 184 using ConsoleStorageMap = protocol::HashMap<int, std::unique_ptr<V8ConsoleMe
ssageStorage>>; | |
| 185 ConsoleStorageMap m_consoleStorageMap; | |
| 186 int m_capturingStackTracesCount; | |
| 187 unsigned m_lastExceptionId; | |
| 188 int m_enabledAgentsCount; | |
| 189 bool m_breakpointsActivated; | |
| 190 v8::Global<v8::Object> m_debuggerScript; | |
| 191 v8::Global<v8::Context> m_debuggerContext; | |
| 192 v8::Local<v8::Object> m_executionState; | |
| 193 v8::Local<v8::Context> m_pausedContext; | |
| 194 bool m_runningNestedMessageLoop; | |
| 195 v8::Global<v8::Context> m_regexContext; | |
| 196 | |
| 197 using AsyncTaskToStackTrace = protocol::HashMap<void*, std::unique_ptr<V8Sta
ckTraceImpl>>; | |
| 198 AsyncTaskToStackTrace m_asyncTaskStacks; | |
| 199 protocol::HashSet<void*> m_recurringTasks; | |
| 200 int m_maxAsyncCallStackDepth; | |
| 201 std::vector<void*> m_currentTasks; | |
| 202 std::vector<std::unique_ptr<V8StackTraceImpl>> m_currentStacks; | |
| 203 protocol::HashMap<V8DebuggerAgentImpl*, int> m_maxAsyncCallStackDepthMap; | |
| 204 }; | |
| 205 | |
| 206 } // namespace blink | |
| 207 | |
| 208 | |
| 209 #endif // V8DebuggerImpl_h | |
| OLD | NEW |