Line data Source code
1 : // Copyright 2015 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_V8_DEBUGGER_AGENT_IMPL_H_
6 : #define V8_INSPECTOR_V8_DEBUGGER_AGENT_IMPL_H_
7 :
8 : #include <deque>
9 : #include <unordered_map>
10 : #include <vector>
11 :
12 : #include "src/base/macros.h"
13 : #include "src/debug/debug-interface.h"
14 : #include "src/debug/interface-types.h"
15 : #include "src/inspector/protocol/Debugger.h"
16 : #include "src/inspector/protocol/Forward.h"
17 :
18 : namespace v8_inspector {
19 :
20 : struct ScriptBreakpoint;
21 : class V8Debugger;
22 : class V8DebuggerScript;
23 : class V8InspectorImpl;
24 : class V8InspectorSessionImpl;
25 : class V8Regex;
26 :
27 : using protocol::Maybe;
28 : using protocol::Response;
29 :
30 15328 : class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
31 : public:
32 : enum BreakpointSource {
33 : UserBreakpointSource,
34 : DebugCommandBreakpointSource,
35 : MonitorCommandBreakpointSource
36 : };
37 :
38 : V8DebuggerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
39 : protocol::DictionaryValue* state);
40 : ~V8DebuggerAgentImpl() override;
41 : void restore();
42 :
43 : // Part of the protocol.
44 : Response enable(String16* outDebuggerId) override;
45 : Response disable() override;
46 : Response setBreakpointsActive(bool active) override;
47 : Response setSkipAllPauses(bool skip) override;
48 : Response setBreakpointByUrl(
49 : int lineNumber, Maybe<String16> optionalURL,
50 : Maybe<String16> optionalURLRegex, Maybe<String16> optionalScriptHash,
51 : Maybe<int> optionalColumnNumber, Maybe<String16> optionalCondition,
52 : String16*,
53 : std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
54 : override;
55 : Response setBreakpoint(
56 : std::unique_ptr<protocol::Debugger::Location>,
57 : Maybe<String16> optionalCondition, String16*,
58 : std::unique_ptr<protocol::Debugger::Location>* actualLocation) override;
59 : Response setBreakpointOnFunctionCall(const String16& functionObjectId,
60 : Maybe<String16> optionalCondition,
61 : String16* outBreakpointId) override;
62 : Response removeBreakpoint(const String16& breakpointId) override;
63 : Response continueToLocation(std::unique_ptr<protocol::Debugger::Location>,
64 : Maybe<String16> targetCallFrames) override;
65 : Response getStackTrace(
66 : std::unique_ptr<protocol::Runtime::StackTraceId> inStackTraceId,
67 : std::unique_ptr<protocol::Runtime::StackTrace>* outStackTrace) override;
68 : Response searchInContent(
69 : const String16& scriptId, const String16& query,
70 : Maybe<bool> optionalCaseSensitive, Maybe<bool> optionalIsRegex,
71 : std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>>*)
72 : override;
73 : Response getPossibleBreakpoints(
74 : std::unique_ptr<protocol::Debugger::Location> start,
75 : Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction,
76 : std::unique_ptr<protocol::Array<protocol::Debugger::BreakLocation>>*
77 : locations) override;
78 : Response setScriptSource(
79 : const String16& inScriptId, const String16& inScriptSource,
80 : Maybe<bool> dryRun,
81 : Maybe<protocol::Array<protocol::Debugger::CallFrame>>* optOutCallFrames,
82 : Maybe<bool>* optOutStackChanged,
83 : Maybe<protocol::Runtime::StackTrace>* optOutAsyncStackTrace,
84 : Maybe<protocol::Runtime::StackTraceId>* optOutAsyncStackTraceId,
85 : Maybe<protocol::Runtime::ExceptionDetails>* optOutCompileError) override;
86 : Response restartFrame(
87 : const String16& callFrameId,
88 : std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*
89 : newCallFrames,
90 : Maybe<protocol::Runtime::StackTrace>* asyncStackTrace,
91 : Maybe<protocol::Runtime::StackTraceId>* asyncStackTraceId) override;
92 : Response getScriptSource(const String16& scriptId,
93 : String16* scriptSource) override;
94 : Response pause() override;
95 : Response resume() override;
96 : Response stepOver() override;
97 : Response stepInto(Maybe<bool> inBreakOnAsyncCall) override;
98 : Response stepOut() override;
99 : Response pauseOnAsyncCall(std::unique_ptr<protocol::Runtime::StackTraceId>
100 : inParentStackTraceId) override;
101 : Response setPauseOnExceptions(const String16& pauseState) override;
102 : Response evaluateOnCallFrame(
103 : const String16& callFrameId, const String16& expression,
104 : Maybe<String16> objectGroup, Maybe<bool> includeCommandLineAPI,
105 : Maybe<bool> silent, Maybe<bool> returnByValue,
106 : Maybe<bool> generatePreview, Maybe<bool> throwOnSideEffect,
107 : Maybe<double> timeout,
108 : std::unique_ptr<protocol::Runtime::RemoteObject>* result,
109 : Maybe<protocol::Runtime::ExceptionDetails>*) override;
110 : Response setVariableValue(
111 : int scopeNumber, const String16& variableName,
112 : std::unique_ptr<protocol::Runtime::CallArgument> newValue,
113 : const String16& callFrame) override;
114 : Response setReturnValue(
115 : std::unique_ptr<protocol::Runtime::CallArgument> newValue) override;
116 : Response setAsyncCallStackDepth(int depth) override;
117 : Response setBlackboxPatterns(
118 : std::unique_ptr<protocol::Array<String16>> patterns) override;
119 : Response setBlackboxedRanges(
120 : const String16& scriptId,
121 : std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>>
122 : positions) override;
123 :
124 : bool enabled() const { return m_enabled; }
125 :
126 : void setBreakpointFor(v8::Local<v8::Function> function,
127 : v8::Local<v8::String> condition,
128 : BreakpointSource source);
129 : void removeBreakpointFor(v8::Local<v8::Function> function,
130 : BreakpointSource source);
131 : void schedulePauseOnNextStatement(
132 : const String16& breakReason,
133 : std::unique_ptr<protocol::DictionaryValue> data);
134 : void cancelPauseOnNextStatement();
135 : void breakProgram(const String16& breakReason,
136 : std::unique_ptr<protocol::DictionaryValue> data);
137 :
138 : void reset();
139 :
140 : // Interface for V8InspectorImpl
141 : void didPause(int contextId, v8::Local<v8::Value> exception,
142 : const std::vector<v8::debug::BreakpointId>& hitBreakpoints,
143 : v8::debug::ExceptionType exceptionType, bool isUncaught,
144 : bool isOOMBreak, bool isAssert);
145 : void didContinue();
146 : void didParseSource(std::unique_ptr<V8DebuggerScript>, bool success);
147 :
148 : bool isFunctionBlackboxed(const String16& scriptId,
149 : const v8::debug::Location& start,
150 : const v8::debug::Location& end);
151 :
152 : bool acceptsPause(bool isOOMBreak) const;
153 :
154 : v8::Isolate* isolate() { return m_isolate; }
155 :
156 : private:
157 : void enableImpl();
158 :
159 : Response currentCallFrames(
160 : std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*);
161 : std::unique_ptr<protocol::Runtime::StackTrace> currentAsyncStackTrace();
162 : std::unique_ptr<protocol::Runtime::StackTraceId> currentExternalStackTrace();
163 : std::unique_ptr<protocol::Runtime::StackTraceId> currentScheduledAsyncCall();
164 :
165 : void setPauseOnExceptionsImpl(int);
166 :
167 : std::unique_ptr<protocol::Debugger::Location> setBreakpointImpl(
168 : const String16& breakpointId, const String16& scriptId,
169 : const String16& condition, int lineNumber, int columnNumber);
170 : void setBreakpointImpl(const String16& breakpointId,
171 : v8::Local<v8::Function> function,
172 : v8::Local<v8::String> condition);
173 : void removeBreakpointImpl(const String16& breakpointId);
174 : void clearBreakDetails();
175 :
176 : void internalSetAsyncCallStackDepth(int);
177 : void increaseCachedSkipStackGeneration();
178 :
179 : Response setBlackboxPattern(const String16& pattern);
180 : void resetBlackboxedStateCache();
181 :
182 : bool isPaused() const;
183 :
184 : using ScriptsMap =
185 : std::unordered_map<String16, std::unique_ptr<V8DebuggerScript>>;
186 : using BreakpointIdToDebuggerBreakpointIdsMap =
187 : std::unordered_map<String16, std::vector<v8::debug::BreakpointId>>;
188 : using DebuggerBreakpointIdToBreakpointIdMap =
189 : std::unordered_map<v8::debug::BreakpointId, String16>;
190 :
191 : V8InspectorImpl* m_inspector;
192 : V8Debugger* m_debugger;
193 : V8InspectorSessionImpl* m_session;
194 : bool m_enabled;
195 : protocol::DictionaryValue* m_state;
196 : protocol::Debugger::Frontend m_frontend;
197 : v8::Isolate* m_isolate;
198 : ScriptsMap m_scripts;
199 : BreakpointIdToDebuggerBreakpointIdsMap m_breakpointIdToDebuggerBreakpointIds;
200 : DebuggerBreakpointIdToBreakpointIdMap m_debuggerBreakpointIdToBreakpointId;
201 :
202 : std::deque<String16> m_failedToParseAnonymousScriptIds;
203 : void cleanupOldFailedToParseAnonymousScriptsIfNeeded();
204 :
205 : using BreakReason =
206 : std::pair<String16, std::unique_ptr<protocol::DictionaryValue>>;
207 : std::vector<BreakReason> m_breakReason;
208 :
209 : void pushBreakDetails(
210 : const String16& breakReason,
211 : std::unique_ptr<protocol::DictionaryValue> breakAuxData);
212 : void popBreakDetails();
213 :
214 : bool m_skipAllPauses = false;
215 : bool m_breakpointsActive = false;
216 :
217 : std::unique_ptr<V8Regex> m_blackboxPattern;
218 : std::unordered_map<String16, std::vector<std::pair<int, int>>>
219 : m_blackboxedPositions;
220 :
221 : DISALLOW_COPY_AND_ASSIGN(V8DebuggerAgentImpl);
222 : };
223 :
224 : String16 scopeType(v8::debug::ScopeIterator::ScopeType type);
225 :
226 : } // namespace v8_inspector
227 :
228 : #endif // V8_INSPECTOR_V8_DEBUGGER_AGENT_IMPL_H_
|