| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_INSPECTOR_V8DEBUGGER_H_ | 5 #ifndef V8_INSPECTOR_V8DEBUGGER_H_ |
| 6 #define V8_INSPECTOR_V8DEBUGGER_H_ | 6 #define V8_INSPECTOR_V8DEBUGGER_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <vector> | 8 #include <vector> |
| 10 | 9 |
| 11 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
| 12 #include "src/debug/debug-interface.h" | 11 #include "src/debug/debug-interface.h" |
| 13 #include "src/inspector/java-script-call-frame.h" | 12 #include "src/inspector/java-script-call-frame.h" |
| 14 #include "src/inspector/protocol/Debugger.h" | 13 #include "src/inspector/protocol/Debugger.h" |
| 15 #include "src/inspector/protocol/Forward.h" | 14 #include "src/inspector/protocol/Forward.h" |
| 16 #include "src/inspector/protocol/Runtime.h" | 15 #include "src/inspector/protocol/Runtime.h" |
| 17 #include "src/inspector/v8-debugger-script.h" | 16 #include "src/inspector/v8-debugger-script.h" |
| 18 #include "src/inspector/wasm-translation.h" | 17 #include "src/inspector/wasm-translation.h" |
| 19 | 18 |
| 20 #include "include/v8-inspector.h" | 19 #include "include/v8-inspector.h" |
| 21 | 20 |
| 22 namespace v8_inspector { | 21 namespace v8_inspector { |
| 23 | 22 |
| 24 class AsyncStackTrace; | |
| 25 struct ScriptBreakpoint; | 23 struct ScriptBreakpoint; |
| 26 class V8Debugger; | |
| 27 class V8DebuggerAgentImpl; | 24 class V8DebuggerAgentImpl; |
| 28 class V8InspectorImpl; | 25 class V8InspectorImpl; |
| 29 class V8StackTraceImpl; | 26 class V8StackTraceImpl; |
| 30 | 27 |
| 31 using protocol::Response; | 28 using protocol::Response; |
| 32 using ScheduleStepIntoAsyncCallback = | 29 using ScheduleStepIntoAsyncCallback = |
| 33 protocol::Debugger::Backend::ScheduleStepIntoAsyncCallback; | 30 protocol::Debugger::Backend::ScheduleStepIntoAsyncCallback; |
| 34 | 31 |
| 35 class V8Debugger : public v8::debug::DebugDelegate { | 32 class V8Debugger : public v8::debug::DebugDelegate { |
| 36 public: | 33 public: |
| 37 V8Debugger(v8::Isolate*, V8InspectorImpl*); | 34 V8Debugger(v8::Isolate*, V8InspectorImpl*); |
| 38 ~V8Debugger(); | 35 ~V8Debugger(); |
| 39 | 36 |
| 40 bool enabled() const; | 37 bool enabled() const; |
| 41 v8::Isolate* isolate() const { return m_isolate; } | |
| 42 | 38 |
| 43 String16 setBreakpoint(const ScriptBreakpoint&, int* actualLineNumber, | 39 String16 setBreakpoint(const ScriptBreakpoint&, int* actualLineNumber, |
| 44 int* actualColumnNumber); | 40 int* actualColumnNumber); |
| 45 void removeBreakpoint(const String16& breakpointId); | 41 void removeBreakpoint(const String16& breakpointId); |
| 46 void setBreakpointsActivated(bool); | 42 void setBreakpointsActivated(bool); |
| 47 bool breakpointsActivated() const { return m_breakpointsActivated; } | 43 bool breakpointsActivated() const { return m_breakpointsActivated; } |
| 48 | 44 |
| 49 v8::debug::ExceptionBreakState getPauseOnExceptionsState(); | 45 v8::debug::ExceptionBreakState getPauseOnExceptionsState(); |
| 50 void setPauseOnExceptionsState(v8::debug::ExceptionBreakState); | 46 void setPauseOnExceptionsState(v8::debug::ExceptionBreakState); |
| 51 bool canBreakProgram(); | 47 bool canBreakProgram(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 // Passing 0 will result in reporting all scripts. | 69 // Passing 0 will result in reporting all scripts. |
| 74 void getCompiledScripts(int contextGroupId, | 70 void getCompiledScripts(int contextGroupId, |
| 75 std::vector<std::unique_ptr<V8DebuggerScript>>&); | 71 std::vector<std::unique_ptr<V8DebuggerScript>>&); |
| 76 void enable(); | 72 void enable(); |
| 77 void disable(); | 73 void disable(); |
| 78 | 74 |
| 79 bool isPaused() const { return m_runningNestedMessageLoop; } | 75 bool isPaused() const { return m_runningNestedMessageLoop; } |
| 80 v8::Local<v8::Context> pausedContext() { return m_pausedContext; } | 76 v8::Local<v8::Context> pausedContext() { return m_pausedContext; } |
| 81 | 77 |
| 82 int maxAsyncCallChainDepth() { return m_maxAsyncCallStackDepth; } | 78 int maxAsyncCallChainDepth() { return m_maxAsyncCallStackDepth; } |
| 79 V8StackTraceImpl* currentAsyncCallChain(); |
| 80 V8StackTraceImpl* currentAsyncTaskCreationStack(); |
| 83 void setAsyncCallStackDepth(V8DebuggerAgentImpl*, int); | 81 void setAsyncCallStackDepth(V8DebuggerAgentImpl*, int); |
| 84 | |
| 85 std::shared_ptr<AsyncStackTrace> currentAsyncParent(); | |
| 86 std::shared_ptr<AsyncStackTrace> currentAsyncCreation(); | |
| 87 | |
| 88 std::unique_ptr<V8StackTraceImpl> createStackTrace(v8::Local<v8::StackTrace>); | 82 std::unique_ptr<V8StackTraceImpl> createStackTrace(v8::Local<v8::StackTrace>); |
| 89 std::unique_ptr<V8StackTraceImpl> captureStackTrace(bool fullStack); | 83 std::unique_ptr<V8StackTraceImpl> captureStackTrace(bool fullStack); |
| 90 | 84 |
| 91 v8::MaybeLocal<v8::Array> internalProperties(v8::Local<v8::Context>, | 85 v8::MaybeLocal<v8::Array> internalProperties(v8::Local<v8::Context>, |
| 92 v8::Local<v8::Value>); | 86 v8::Local<v8::Value>); |
| 93 | 87 |
| 94 void asyncTaskScheduled(const StringView& taskName, void* task, | 88 void asyncTaskScheduled(const StringView& taskName, void* task, |
| 95 bool recurring); | 89 bool recurring); |
| 96 void asyncTaskCanceled(void* task); | 90 void asyncTaskCanceled(void* task); |
| 97 void asyncTaskStarted(void* task); | 91 void asyncTaskStarted(void* task); |
| 98 void asyncTaskFinished(void* task); | 92 void asyncTaskFinished(void* task); |
| 99 void allAsyncTasksCanceled(); | 93 void allAsyncTasksCanceled(); |
| 100 | 94 |
| 101 void muteScriptParsedEvents(); | 95 void muteScriptParsedEvents(); |
| 102 void unmuteScriptParsedEvents(); | 96 void unmuteScriptParsedEvents(); |
| 103 | 97 |
| 104 V8InspectorImpl* inspector() { return m_inspector; } | 98 V8InspectorImpl* inspector() { return m_inspector; } |
| 105 | 99 |
| 106 WasmTranslation* wasmTranslation() { return &m_wasmTranslation; } | 100 WasmTranslation* wasmTranslation() { return &m_wasmTranslation; } |
| 107 | 101 |
| 108 void setMaxAsyncTaskStacksForTest(int limit); | 102 void setMaxAsyncTaskStacksForTest(int limit) { m_maxAsyncCallStacks = limit; } |
| 109 | 103 |
| 110 private: | 104 private: |
| 111 void compileDebuggerScript(); | 105 void compileDebuggerScript(); |
| 112 v8::MaybeLocal<v8::Value> callDebuggerMethod(const char* functionName, | 106 v8::MaybeLocal<v8::Value> callDebuggerMethod(const char* functionName, |
| 113 int argc, | 107 int argc, |
| 114 v8::Local<v8::Value> argv[], | 108 v8::Local<v8::Value> argv[], |
| 115 bool catchExceptions); | 109 bool catchExceptions); |
| 116 v8::Local<v8::Context> debuggerContext() const; | 110 v8::Local<v8::Context> debuggerContext() const; |
| 117 void clearBreakpoints(); | 111 void clearBreakpoints(); |
| 118 | 112 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 143 bool recurring); | 137 bool recurring); |
| 144 void asyncTaskCanceledForStack(void* task); | 138 void asyncTaskCanceledForStack(void* task); |
| 145 void asyncTaskStartedForStack(void* task); | 139 void asyncTaskStartedForStack(void* task); |
| 146 void asyncTaskFinishedForStack(void* task); | 140 void asyncTaskFinishedForStack(void* task); |
| 147 | 141 |
| 148 void asyncTaskCandidateForStepping(void* task); | 142 void asyncTaskCandidateForStepping(void* task); |
| 149 void asyncTaskStartedForStepping(void* task); | 143 void asyncTaskStartedForStepping(void* task); |
| 150 void asyncTaskFinishedForStepping(void* task); | 144 void asyncTaskFinishedForStepping(void* task); |
| 151 void asyncTaskCanceledForStepping(void* task); | 145 void asyncTaskCanceledForStepping(void* task); |
| 152 | 146 |
| 147 void registerAsyncTaskIfNeeded(void* task); |
| 148 |
| 153 // v8::debug::DebugEventListener implementation. | 149 // v8::debug::DebugEventListener implementation. |
| 154 void PromiseEventOccurred(v8::debug::PromiseDebugActionType type, int id, | 150 void PromiseEventOccurred(v8::debug::PromiseDebugActionType type, int id, |
| 155 int parentId, bool createdByUser) override; | 151 int parentId, bool createdByUser) override; |
| 156 void ScriptCompiled(v8::Local<v8::debug::Script> script, | 152 void ScriptCompiled(v8::Local<v8::debug::Script> script, |
| 157 bool has_compile_error) override; | 153 bool has_compile_error) override; |
| 158 void BreakProgramRequested(v8::Local<v8::Context> paused_context, | 154 void BreakProgramRequested(v8::Local<v8::Context> paused_context, |
| 159 v8::Local<v8::Object> exec_state, | 155 v8::Local<v8::Object> exec_state, |
| 160 v8::Local<v8::Value> break_points_hit) override; | 156 v8::Local<v8::Value> break_points_hit) override; |
| 161 void ExceptionThrown(v8::Local<v8::Context> paused_context, | 157 void ExceptionThrown(v8::Local<v8::Context> paused_context, |
| 162 v8::Local<v8::Object> exec_state, | 158 v8::Local<v8::Object> exec_state, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 v8::Global<v8::Object> m_debuggerScript; | 171 v8::Global<v8::Object> m_debuggerScript; |
| 176 v8::Global<v8::Context> m_debuggerContext; | 172 v8::Global<v8::Context> m_debuggerContext; |
| 177 v8::Local<v8::Object> m_executionState; | 173 v8::Local<v8::Object> m_executionState; |
| 178 v8::Local<v8::Context> m_pausedContext; | 174 v8::Local<v8::Context> m_pausedContext; |
| 179 bool m_runningNestedMessageLoop; | 175 bool m_runningNestedMessageLoop; |
| 180 int m_ignoreScriptParsedEventsCounter; | 176 int m_ignoreScriptParsedEventsCounter; |
| 181 bool m_scheduledOOMBreak = false; | 177 bool m_scheduledOOMBreak = false; |
| 182 int m_targetContextGroupId = 0; | 178 int m_targetContextGroupId = 0; |
| 183 | 179 |
| 184 using AsyncTaskToStackTrace = | 180 using AsyncTaskToStackTrace = |
| 185 protocol::HashMap<void*, std::weak_ptr<AsyncStackTrace>>; | 181 protocol::HashMap<void*, std::unique_ptr<V8StackTraceImpl>>; |
| 186 AsyncTaskToStackTrace m_asyncTaskStacks; | 182 AsyncTaskToStackTrace m_asyncTaskStacks; |
| 187 AsyncTaskToStackTrace m_asyncTaskCreationStacks; | 183 AsyncTaskToStackTrace m_asyncTaskCreationStacks; |
| 188 int m_maxAsyncCallStacks; | 184 int m_maxAsyncCallStacks; |
| 185 std::map<int, void*> m_idToTask; |
| 186 std::unordered_map<void*, int> m_taskToId; |
| 187 int m_lastTaskId; |
| 189 protocol::HashSet<void*> m_recurringTasks; | 188 protocol::HashSet<void*> m_recurringTasks; |
| 190 int m_maxAsyncCallStackDepth; | 189 int m_maxAsyncCallStackDepth; |
| 191 | |
| 192 std::vector<void*> m_currentTasks; | 190 std::vector<void*> m_currentTasks; |
| 193 std::vector<std::shared_ptr<AsyncStackTrace>> m_currentAsyncParent; | 191 std::vector<std::unique_ptr<V8StackTraceImpl>> m_currentStacks; |
| 194 std::vector<std::shared_ptr<AsyncStackTrace>> m_currentAsyncCreation; | 192 std::vector<std::unique_ptr<V8StackTraceImpl>> m_currentCreationStacks; |
| 195 | |
| 196 void collectOldAsyncStacksIfNeeded(); | |
| 197 void removeOldAsyncTasks(AsyncTaskToStackTrace& map); | |
| 198 int m_asyncStacksCount = 0; | |
| 199 // V8Debugger owns all the async stacks, while most of the other references | |
| 200 // are weak, which allows to collect some stacks when there are too many. | |
| 201 std::list<std::shared_ptr<AsyncStackTrace>> m_allAsyncStacks; | |
| 202 | |
| 203 protocol::HashMap<V8DebuggerAgentImpl*, int> m_maxAsyncCallStackDepthMap; | 193 protocol::HashMap<V8DebuggerAgentImpl*, int> m_maxAsyncCallStackDepthMap; |
| 204 protocol::HashMap<void*, void*> m_parentTask; | 194 protocol::HashMap<void*, void*> m_parentTask; |
| 205 protocol::HashMap<void*, void*> m_firstNextTask; | 195 protocol::HashMap<void*, void*> m_firstNextTask; |
| 206 void* m_taskWithScheduledBreak = nullptr; | 196 void* m_taskWithScheduledBreak = nullptr; |
| 207 | 197 |
| 208 std::unique_ptr<ScheduleStepIntoAsyncCallback> m_stepIntoAsyncCallback; | 198 std::unique_ptr<ScheduleStepIntoAsyncCallback> m_stepIntoAsyncCallback; |
| 209 bool m_breakRequested = false; | 199 bool m_breakRequested = false; |
| 210 | 200 |
| 211 v8::debug::ExceptionBreakState m_pauseOnExceptionsState; | 201 v8::debug::ExceptionBreakState m_pauseOnExceptionsState; |
| 212 | 202 |
| 213 WasmTranslation m_wasmTranslation; | 203 WasmTranslation m_wasmTranslation; |
| 214 | 204 |
| 215 DISALLOW_COPY_AND_ASSIGN(V8Debugger); | 205 DISALLOW_COPY_AND_ASSIGN(V8Debugger); |
| 216 }; | 206 }; |
| 217 | 207 |
| 218 } // namespace v8_inspector | 208 } // namespace v8_inspector |
| 219 | 209 |
| 220 #endif // V8_INSPECTOR_V8DEBUGGER_H_ | 210 #endif // V8_INSPECTOR_V8DEBUGGER_H_ |
| OLD | NEW |