OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_INSPECTOR_V8DEBUGGER_H_ |
| 6 #define V8_INSPECTOR_V8DEBUGGER_H_ |
| 7 |
| 8 #include "src/inspector/Allocator.h" |
| 9 #include "src/inspector/JavaScriptCallFrame.h" |
| 10 #include "src/inspector/V8DebuggerScript.h" |
| 11 #include "src/inspector/protocol/Forward.h" |
| 12 #include "src/inspector/protocol/Runtime.h" |
| 13 #include "src/inspector/public/StringView.h" |
| 14 #include "src/inspector/public/V8ContextInfo.h" |
| 15 |
| 16 #include <v8-debug.h> |
| 17 #include <v8.h> |
| 18 #include <vector> |
| 19 |
| 20 namespace v8_inspector { |
| 21 |
| 22 struct ScriptBreakpoint; |
| 23 class V8DebuggerAgentImpl; |
| 24 class V8InspectorImpl; |
| 25 class V8StackTraceImpl; |
| 26 |
| 27 using protocol::ErrorString; |
| 28 |
| 29 class V8Debugger { |
| 30 V8_INSPECTOR_DISALLOW_COPY(V8Debugger); |
| 31 |
| 32 public: |
| 33 V8Debugger(v8::Isolate*, V8InspectorImpl*); |
| 34 ~V8Debugger(); |
| 35 |
| 36 static int contextId(v8::Local<v8::Context>); |
| 37 static int getGroupId(v8::Local<v8::Context>); |
| 38 int markContext(const V8ContextInfo&); |
| 39 |
| 40 bool enabled() const; |
| 41 |
| 42 String16 setBreakpoint(const String16& sourceID, const ScriptBreakpoint&, |
| 43 int* actualLineNumber, int* actualColumnNumber); |
| 44 void removeBreakpoint(const String16& breakpointId); |
| 45 void setBreakpointsActivated(bool); |
| 46 bool breakpointsActivated() const { return m_breakpointsActivated; } |
| 47 |
| 48 enum PauseOnExceptionsState { |
| 49 DontPauseOnExceptions, |
| 50 PauseOnAllExceptions, |
| 51 PauseOnUncaughtExceptions |
| 52 }; |
| 53 PauseOnExceptionsState getPauseOnExceptionsState(); |
| 54 void setPauseOnExceptionsState(PauseOnExceptionsState); |
| 55 void setPauseOnNextStatement(bool); |
| 56 bool canBreakProgram(); |
| 57 void breakProgram(); |
| 58 void continueProgram(); |
| 59 void stepIntoStatement(); |
| 60 void stepOverStatement(); |
| 61 void stepOutOfFunction(); |
| 62 void clearStepping(); |
| 63 |
| 64 bool setScriptSource(const String16& sourceID, |
| 65 v8::Local<v8::String> newSource, bool dryRun, |
| 66 ErrorString*, |
| 67 protocol::Maybe<protocol::Runtime::ExceptionDetails>*, |
| 68 JavaScriptCallFrames* newCallFrames, |
| 69 protocol::Maybe<bool>* stackChanged); |
| 70 JavaScriptCallFrames currentCallFrames(int limit = 0); |
| 71 |
| 72 // Each script inherits debug data from v8::Context where it has been |
| 73 // compiled. |
| 74 // Only scripts whose debug data matches |contextGroupId| will be reported. |
| 75 // Passing 0 will result in reporting all scripts. |
| 76 void getCompiledScripts(int contextGroupId, |
| 77 std::vector<std::unique_ptr<V8DebuggerScript>>&); |
| 78 void enable(); |
| 79 void disable(); |
| 80 |
| 81 bool isPaused(); |
| 82 v8::Local<v8::Context> pausedContext() { return m_pausedContext; } |
| 83 |
| 84 int maxAsyncCallChainDepth() { return m_maxAsyncCallStackDepth; } |
| 85 V8StackTraceImpl* currentAsyncCallChain(); |
| 86 void setAsyncCallStackDepth(V8DebuggerAgentImpl*, int); |
| 87 std::unique_ptr<V8StackTraceImpl> createStackTrace(v8::Local<v8::StackTrace>); |
| 88 std::unique_ptr<V8StackTraceImpl> captureStackTrace(bool fullStack); |
| 89 |
| 90 v8::MaybeLocal<v8::Array> internalProperties(v8::Local<v8::Context>, |
| 91 v8::Local<v8::Value>); |
| 92 |
| 93 void asyncTaskScheduled(const StringView& taskName, void* task, |
| 94 bool recurring); |
| 95 void asyncTaskScheduled(const String16& taskName, void* task, bool recurring); |
| 96 void asyncTaskCanceled(void* task); |
| 97 void asyncTaskStarted(void* task); |
| 98 void asyncTaskFinished(void* task); |
| 99 void allAsyncTasksCanceled(); |
| 100 |
| 101 void muteScriptParsedEvents(); |
| 102 void unmuteScriptParsedEvents(); |
| 103 |
| 104 private: |
| 105 void compileDebuggerScript(); |
| 106 v8::MaybeLocal<v8::Value> callDebuggerMethod(const char* functionName, |
| 107 int argc, |
| 108 v8::Local<v8::Value> argv[]); |
| 109 v8::Local<v8::Context> debuggerContext() const; |
| 110 void clearBreakpoints(); |
| 111 |
| 112 static void breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>&); |
| 113 void handleProgramBreak(v8::Local<v8::Context> pausedContext, |
| 114 v8::Local<v8::Object> executionState, |
| 115 v8::Local<v8::Value> exception, |
| 116 v8::Local<v8::Array> hitBreakpoints, |
| 117 bool isPromiseRejection = false); |
| 118 static void v8DebugEventCallback(const v8::Debug::EventDetails&); |
| 119 v8::Local<v8::Value> callInternalGetterFunction(v8::Local<v8::Object>, |
| 120 const char* functionName); |
| 121 void handleV8DebugEvent(const v8::Debug::EventDetails&); |
| 122 void handleV8AsyncTaskEvent(v8::Local<v8::Context>, |
| 123 v8::Local<v8::Object> executionState, |
| 124 v8::Local<v8::Object> eventData); |
| 125 |
| 126 v8::Local<v8::Value> collectionEntries(v8::Local<v8::Context>, |
| 127 v8::Local<v8::Object>); |
| 128 v8::Local<v8::Value> generatorObjectLocation(v8::Local<v8::Context>, |
| 129 v8::Local<v8::Object>); |
| 130 v8::Local<v8::Value> functionLocation(v8::Local<v8::Context>, |
| 131 v8::Local<v8::Function>); |
| 132 v8::MaybeLocal<v8::Value> functionScopes(v8::Local<v8::Context>, |
| 133 v8::Local<v8::Function>); |
| 134 |
| 135 v8::Isolate* m_isolate; |
| 136 V8InspectorImpl* m_inspector; |
| 137 int m_lastContextId; |
| 138 int m_enableCount; |
| 139 bool m_breakpointsActivated; |
| 140 v8::Global<v8::Object> m_debuggerScript; |
| 141 v8::Global<v8::Context> m_debuggerContext; |
| 142 v8::Local<v8::Object> m_executionState; |
| 143 v8::Local<v8::Context> m_pausedContext; |
| 144 bool m_runningNestedMessageLoop; |
| 145 int m_ignoreScriptParsedEventsCounter; |
| 146 |
| 147 using AsyncTaskToStackTrace = |
| 148 protocol::HashMap<void*, std::unique_ptr<V8StackTraceImpl>>; |
| 149 AsyncTaskToStackTrace m_asyncTaskStacks; |
| 150 protocol::HashSet<void*> m_recurringTasks; |
| 151 int m_maxAsyncCallStackDepth; |
| 152 std::vector<void*> m_currentTasks; |
| 153 std::vector<std::unique_ptr<V8StackTraceImpl>> m_currentStacks; |
| 154 protocol::HashMap<V8DebuggerAgentImpl*, int> m_maxAsyncCallStackDepthMap; |
| 155 }; |
| 156 |
| 157 } // namespace v8_inspector |
| 158 |
| 159 #endif // V8_INSPECTOR_V8DEBUGGER_H_ |
OLD | NEW |