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 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&, in
t* actualLineNumber, int* actualColumnNumber); | |
42 void removeBreakpoint(const String16& breakpointId); | |
43 void setBreakpointsActivated(bool); | |
44 bool breakpointsActivated() const { return m_breakpointsActivated; } | |
45 | |
46 enum PauseOnExceptionsState { | |
47 DontPauseOnExceptions, | |
48 PauseOnAllExceptions, | |
49 PauseOnUncaughtExceptions | |
50 }; | |
51 PauseOnExceptionsState getPauseOnExceptionsState(); | |
52 void setPauseOnExceptionsState(PauseOnExceptionsState); | |
53 void setPauseOnNextStatement(bool); | |
54 bool canBreakProgram(); | |
55 void breakProgram(); | |
56 void continueProgram(); | |
57 void stepIntoStatement(); | |
58 void stepOverStatement(); | |
59 void stepOutOfFunction(); | |
60 void clearStepping(); | |
61 | |
62 bool setScriptSource(const String16& sourceID, v8::Local<v8::String> newSour
ce, bool dryRun, ErrorString*, protocol::Maybe<protocol::Runtime::ExceptionDetai
ls>*, JavaScriptCallFrames* newCallFrames, protocol::Maybe<bool>* stackChanged); | |
63 JavaScriptCallFrames currentCallFrames(int limit = 0); | |
64 | |
65 // Each script inherits debug data from v8::Context where it has been compil
ed. | |
66 // Only scripts whose debug data matches |contextGroupId| will be reported. | |
67 // Passing 0 will result in reporting all scripts. | |
68 void getCompiledScripts(int contextGroupId, std::vector<std::unique_ptr<V8De
buggerScript>>&); | |
69 void enable(); | |
70 void disable(); | |
71 | |
72 bool isPaused(); | |
73 v8::Local<v8::Context> pausedContext() { return m_pausedContext; } | |
74 | |
75 int maxAsyncCallChainDepth() { return m_maxAsyncCallStackDepth; } | |
76 V8StackTraceImpl* currentAsyncCallChain(); | |
77 void setAsyncCallStackDepth(V8DebuggerAgentImpl*, int); | |
78 std::unique_ptr<V8StackTraceImpl> createStackTrace(v8::Local<v8::StackTrace>
); | |
79 std::unique_ptr<V8StackTraceImpl> captureStackTrace(bool fullStack); | |
80 | |
81 v8::MaybeLocal<v8::Array> internalProperties(v8::Local<v8::Context>, v8::Loc
al<v8::Value>); | |
82 | |
83 void asyncTaskScheduled(const StringView& taskName, void* task, bool recurri
ng); | |
84 void asyncTaskScheduled(const String16& taskName, void* task, bool recurring
); | |
85 void asyncTaskCanceled(void* task); | |
86 void asyncTaskStarted(void* task); | |
87 void asyncTaskFinished(void* task); | |
88 void allAsyncTasksCanceled(); | |
89 | |
90 void muteScriptParsedEvents(); | |
91 void unmuteScriptParsedEvents(); | |
92 | |
93 private: | |
94 void compileDebuggerScript(); | |
95 v8::MaybeLocal<v8::Value> callDebuggerMethod(const char* functionName, int a
rgc, v8::Local<v8::Value> argv[]); | |
96 v8::Local<v8::Context> debuggerContext() const; | |
97 void clearBreakpoints(); | |
98 | |
99 static void breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>&)
; | |
100 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); | |
101 static void v8DebugEventCallback(const v8::Debug::EventDetails&); | |
102 v8::Local<v8::Value> callInternalGetterFunction(v8::Local<v8::Object>, const
char* functionName); | |
103 void handleV8DebugEvent(const v8::Debug::EventDetails&); | |
104 void handleV8AsyncTaskEvent(v8::Local<v8::Context>, v8::Local<v8::Object> ex
ecutionState, v8::Local<v8::Object> eventData); | |
105 | |
106 v8::Local<v8::Value> collectionEntries(v8::Local<v8::Context>, v8::Local<v8:
:Object>); | |
107 v8::Local<v8::Value> generatorObjectLocation(v8::Local<v8::Context>, v8::Loc
al<v8::Object>); | |
108 v8::Local<v8::Value> functionLocation(v8::Local<v8::Context>, v8::Local<v8::
Function>); | |
109 v8::MaybeLocal<v8::Value> functionScopes(v8::Local<v8::Context>, v8::Local<v
8::Function>); | |
110 | |
111 v8::Isolate* m_isolate; | |
112 V8InspectorImpl* m_inspector; | |
113 int m_lastContextId; | |
114 int m_enableCount; | |
115 bool m_breakpointsActivated; | |
116 v8::Global<v8::Object> m_debuggerScript; | |
117 v8::Global<v8::Context> m_debuggerContext; | |
118 v8::Local<v8::Object> m_executionState; | |
119 v8::Local<v8::Context> m_pausedContext; | |
120 bool m_runningNestedMessageLoop; | |
121 int m_ignoreScriptParsedEventsCounter; | |
122 | |
123 using AsyncTaskToStackTrace = protocol::HashMap<void*, std::unique_ptr<V8Sta
ckTraceImpl>>; | |
124 AsyncTaskToStackTrace m_asyncTaskStacks; | |
125 protocol::HashSet<void*> m_recurringTasks; | |
126 int m_maxAsyncCallStackDepth; | |
127 std::vector<void*> m_currentTasks; | |
128 std::vector<std::unique_ptr<V8StackTraceImpl>> m_currentStacks; | |
129 protocol::HashMap<V8DebuggerAgentImpl*, int> m_maxAsyncCallStackDepthMap; | |
130 }; | |
131 | |
132 } // namespace v8_inspector | |
133 | |
134 #endif // V8_INSPECTOR_V8DEBUGGER_H_ | |
OLD | NEW |