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