blob: 62aa67b64bb33a9c90a13176babbef57e7d9ed61 [file] [log] [blame]
Ben Murdochf3b273f2017-01-17 12:11:28 +00001// 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_V8DEBUGGERAGENTIMPL_H_
6#define V8_INSPECTOR_V8DEBUGGERAGENTIMPL_H_
7
8#include <vector>
9
10#include "src/base/macros.h"
11#include "src/inspector/java-script-call-frame.h"
12#include "src/inspector/protocol/Debugger.h"
13#include "src/inspector/protocol/Forward.h"
14
15namespace v8_inspector {
16
17struct ScriptBreakpoint;
18class JavaScriptCallFrame;
19class PromiseTracker;
20class V8Debugger;
21class V8DebuggerScript;
22class V8InspectorImpl;
23class V8InspectorSessionImpl;
24class V8Regex;
25class V8StackTraceImpl;
26
27using protocol::ErrorString;
28using protocol::Maybe;
29
30class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
31 public:
32 enum SkipPauseRequest {
33 RequestNoSkip,
34 RequestContinue,
35 RequestStepInto,
36 RequestStepOut,
37 RequestStepFrame
38 };
39
40 enum BreakpointSource {
41 UserBreakpointSource,
42 DebugCommandBreakpointSource,
43 MonitorCommandBreakpointSource
44 };
45
46 V8DebuggerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
47 protocol::DictionaryValue* state);
48 ~V8DebuggerAgentImpl() override;
49 void restore();
50
51 // Part of the protocol.
52 void enable(ErrorString*) override;
53 void disable(ErrorString*) override;
54 void setBreakpointsActive(ErrorString*, bool active) override;
55 void setSkipAllPauses(ErrorString*, bool skip) override;
56 void setBreakpointByUrl(
57 ErrorString*, int lineNumber, const Maybe<String16>& optionalURL,
58 const Maybe<String16>& optionalURLRegex,
59 const Maybe<int>& optionalColumnNumber,
60 const Maybe<String16>& optionalCondition, String16*,
61 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
62 override;
63 void setBreakpoint(
64 ErrorString*, std::unique_ptr<protocol::Debugger::Location>,
65 const Maybe<String16>& optionalCondition, String16*,
66 std::unique_ptr<protocol::Debugger::Location>* actualLocation) override;
67 void removeBreakpoint(ErrorString*, const String16& breakpointId) override;
68 void continueToLocation(
69 ErrorString*, std::unique_ptr<protocol::Debugger::Location>) override;
70 void searchInContent(
71 ErrorString*, const String16& scriptId, const String16& query,
72 const Maybe<bool>& optionalCaseSensitive,
73 const Maybe<bool>& optionalIsRegex,
74 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>>*)
75 override;
76 void setScriptSource(
77 ErrorString*, const String16& inScriptId, const String16& inScriptSource,
78 const Maybe<bool>& dryRun,
79 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* optOutCallFrames,
80 Maybe<bool>* optOutStackChanged,
81 Maybe<protocol::Runtime::StackTrace>* optOutAsyncStackTrace,
82 Maybe<protocol::Runtime::ExceptionDetails>* optOutCompileError) override;
83 void restartFrame(
84 ErrorString*, const String16& callFrameId,
85 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*
86 newCallFrames,
87 Maybe<protocol::Runtime::StackTrace>* asyncStackTrace) override;
88 void getScriptSource(ErrorString*, const String16& scriptId,
89 String16* scriptSource) override;
90 void pause(ErrorString*) override;
91 void resume(ErrorString*) override;
92 void stepOver(ErrorString*) override;
93 void stepInto(ErrorString*) override;
94 void stepOut(ErrorString*) override;
95 void setPauseOnExceptions(ErrorString*, const String16& pauseState) override;
96 void evaluateOnCallFrame(
97 ErrorString*, const String16& callFrameId, const String16& expression,
98 const Maybe<String16>& objectGroup,
99 const Maybe<bool>& includeCommandLineAPI, const Maybe<bool>& silent,
100 const Maybe<bool>& returnByValue, const Maybe<bool>& generatePreview,
101 std::unique_ptr<protocol::Runtime::RemoteObject>* result,
102 Maybe<protocol::Runtime::ExceptionDetails>*) override;
103 void setVariableValue(
104 ErrorString*, int scopeNumber, const String16& variableName,
105 std::unique_ptr<protocol::Runtime::CallArgument> newValue,
106 const String16& callFrame) override;
107 void setAsyncCallStackDepth(ErrorString*, int depth) override;
108 void setBlackboxPatterns(
109 ErrorString*,
110 std::unique_ptr<protocol::Array<String16>> patterns) override;
111 void setBlackboxedRanges(
112 ErrorString*, const String16& scriptId,
113 std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>>
114 positions) override;
115
116 bool enabled();
117
118 void setBreakpointAt(const String16& scriptId, int lineNumber,
119 int columnNumber, BreakpointSource,
120 const String16& condition = String16());
121 void removeBreakpointAt(const String16& scriptId, int lineNumber,
122 int columnNumber, BreakpointSource);
123 void schedulePauseOnNextStatement(
124 const String16& breakReason,
125 std::unique_ptr<protocol::DictionaryValue> data);
126 void cancelPauseOnNextStatement();
127 void breakProgram(const String16& breakReason,
128 std::unique_ptr<protocol::DictionaryValue> data);
129 void breakProgramOnException(const String16& breakReason,
130 std::unique_ptr<protocol::DictionaryValue> data);
131
132 void reset();
133
134 // Interface for V8InspectorImpl
135 SkipPauseRequest didPause(v8::Local<v8::Context>,
136 v8::Local<v8::Value> exception,
137 const std::vector<String16>& hitBreakpoints,
138 bool isPromiseRejection);
139 void didContinue();
140 void didParseSource(std::unique_ptr<V8DebuggerScript>, bool success);
141 void willExecuteScript(int scriptId);
142 void didExecuteScript();
143
144 v8::Isolate* isolate() { return m_isolate; }
145
146 private:
147 bool checkEnabled(ErrorString*);
148 void enable();
149
150 SkipPauseRequest shouldSkipExceptionPause(JavaScriptCallFrame* topCallFrame);
151 SkipPauseRequest shouldSkipStepPause(JavaScriptCallFrame* topCallFrame);
152
153 void schedulePauseOnNextStatementIfSteppingInto();
154
155 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>
156 currentCallFrames(ErrorString*);
157 std::unique_ptr<protocol::Runtime::StackTrace> currentAsyncStackTrace();
158
159 void changeJavaScriptRecursionLevel(int step);
160
161 void setPauseOnExceptionsImpl(ErrorString*, int);
162
163 std::unique_ptr<protocol::Debugger::Location> resolveBreakpoint(
164 const String16& breakpointId, const String16& scriptId,
165 const ScriptBreakpoint&, BreakpointSource);
166 void removeBreakpoint(const String16& breakpointId);
167 bool assertPaused(ErrorString*);
168 void clearBreakDetails();
169
170 bool isCurrentCallStackEmptyOrBlackboxed();
171 bool isTopPausedCallFrameBlackboxed();
172 bool isCallFrameWithUnknownScriptOrBlackboxed(JavaScriptCallFrame*);
173
174 void internalSetAsyncCallStackDepth(int);
175 void increaseCachedSkipStackGeneration();
176
177 bool setBlackboxPattern(ErrorString*, const String16& pattern);
178
179 using ScriptsMap =
180 protocol::HashMap<String16, std::unique_ptr<V8DebuggerScript>>;
181 using BreakpointIdToDebuggerBreakpointIdsMap =
182 protocol::HashMap<String16, std::vector<String16>>;
183 using DebugServerBreakpointToBreakpointIdAndSourceMap =
184 protocol::HashMap<String16, std::pair<String16, BreakpointSource>>;
185 using MuteBreakpoins = protocol::HashMap<String16, std::pair<String16, int>>;
186
187 enum DebuggerStep { NoStep = 0, StepInto, StepOver, StepOut };
188
189 V8InspectorImpl* m_inspector;
190 V8Debugger* m_debugger;
191 V8InspectorSessionImpl* m_session;
192 bool m_enabled;
193 protocol::DictionaryValue* m_state;
194 protocol::Debugger::Frontend m_frontend;
195 v8::Isolate* m_isolate;
196 v8::Global<v8::Context> m_pausedContext;
197 JavaScriptCallFrames m_pausedCallFrames;
198 ScriptsMap m_scripts;
199 BreakpointIdToDebuggerBreakpointIdsMap m_breakpointIdToDebuggerBreakpointIds;
200 DebugServerBreakpointToBreakpointIdAndSourceMap m_serverBreakpoints;
201 String16 m_continueToLocationBreakpointId;
202 String16 m_breakReason;
203 std::unique_ptr<protocol::DictionaryValue> m_breakAuxData;
204 DebuggerStep m_scheduledDebuggerStep;
205 bool m_skipNextDebuggerStepOut;
206 bool m_javaScriptPauseScheduled;
207 bool m_steppingFromFramework;
208 bool m_pausingOnNativeEvent;
209
210 int m_skippedStepFrameCount;
211 int m_recursionLevelForStepOut;
212 int m_recursionLevelForStepFrame;
213 bool m_skipAllPauses;
214
215 std::unique_ptr<V8Regex> m_blackboxPattern;
216 protocol::HashMap<String16, std::vector<std::pair<int, int>>>
217 m_blackboxedPositions;
218
219 DISALLOW_COPY_AND_ASSIGN(V8DebuggerAgentImpl);
220};
221
222} // namespace v8_inspector
223
224#endif // V8_INSPECTOR_V8DEBUGGERAGENTIMPL_H_