blob: 41a18a8d3688e2da939d6928b6e95cb567d4f25b [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"
Ben Murdoch62ed6312017-06-06 11:06:27 +010011#include "src/debug/interface-types.h"
Ben Murdochf3b273f2017-01-17 12:11:28 +000012#include "src/inspector/java-script-call-frame.h"
13#include "src/inspector/protocol/Debugger.h"
14#include "src/inspector/protocol/Forward.h"
15
16namespace v8_inspector {
17
18struct ScriptBreakpoint;
19class JavaScriptCallFrame;
20class PromiseTracker;
21class V8Debugger;
22class V8DebuggerScript;
23class V8InspectorImpl;
24class V8InspectorSessionImpl;
25class V8Regex;
26class V8StackTraceImpl;
27
Ben Murdochf3b273f2017-01-17 12:11:28 +000028using protocol::Maybe;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000029using protocol::Response;
Ben Murdochf3b273f2017-01-17 12:11:28 +000030
31class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
32 public:
Ben Murdochf3b273f2017-01-17 12:11:28 +000033 enum BreakpointSource {
34 UserBreakpointSource,
35 DebugCommandBreakpointSource,
36 MonitorCommandBreakpointSource
37 };
38
39 V8DebuggerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
40 protocol::DictionaryValue* state);
41 ~V8DebuggerAgentImpl() override;
42 void restore();
43
44 // Part of the protocol.
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000045 Response enable() override;
46 Response disable() override;
47 Response setBreakpointsActive(bool active) override;
48 Response setSkipAllPauses(bool skip) override;
49 Response setBreakpointByUrl(
50 int lineNumber, Maybe<String16> optionalURL,
51 Maybe<String16> optionalURLRegex, Maybe<int> optionalColumnNumber,
52 Maybe<String16> optionalCondition, String16*,
Ben Murdochf3b273f2017-01-17 12:11:28 +000053 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
54 override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000055 Response setBreakpoint(
56 std::unique_ptr<protocol::Debugger::Location>,
57 Maybe<String16> optionalCondition, String16*,
Ben Murdochf3b273f2017-01-17 12:11:28 +000058 std::unique_ptr<protocol::Debugger::Location>* actualLocation) override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000059 Response removeBreakpoint(const String16& breakpointId) override;
60 Response continueToLocation(
61 std::unique_ptr<protocol::Debugger::Location>) override;
62 Response searchInContent(
63 const String16& scriptId, const String16& query,
64 Maybe<bool> optionalCaseSensitive, Maybe<bool> optionalIsRegex,
Ben Murdochf3b273f2017-01-17 12:11:28 +000065 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>>*)
66 override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000067 Response getPossibleBreakpoints(
68 std::unique_ptr<protocol::Debugger::Location> start,
69 Maybe<protocol::Debugger::Location> end,
70 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
71 override;
72 Response setScriptSource(
73 const String16& inScriptId, const String16& inScriptSource,
74 Maybe<bool> dryRun,
Ben Murdochf3b273f2017-01-17 12:11:28 +000075 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* optOutCallFrames,
76 Maybe<bool>* optOutStackChanged,
77 Maybe<protocol::Runtime::StackTrace>* optOutAsyncStackTrace,
78 Maybe<protocol::Runtime::ExceptionDetails>* optOutCompileError) override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000079 Response restartFrame(
80 const String16& callFrameId,
Ben Murdochf3b273f2017-01-17 12:11:28 +000081 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*
82 newCallFrames,
83 Maybe<protocol::Runtime::StackTrace>* asyncStackTrace) override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000084 Response getScriptSource(const String16& scriptId,
85 String16* scriptSource) override;
86 Response pause() override;
87 Response resume() override;
88 Response stepOver() override;
89 Response stepInto() override;
90 Response stepOut() override;
91 Response setPauseOnExceptions(const String16& pauseState) override;
92 Response evaluateOnCallFrame(
93 const String16& callFrameId, const String16& expression,
94 Maybe<String16> objectGroup, Maybe<bool> includeCommandLineAPI,
95 Maybe<bool> silent, Maybe<bool> returnByValue,
Ben Murdoch62ed6312017-06-06 11:06:27 +010096 Maybe<bool> generatePreview, Maybe<bool> throwOnSideEffect,
Ben Murdochf3b273f2017-01-17 12:11:28 +000097 std::unique_ptr<protocol::Runtime::RemoteObject>* result,
98 Maybe<protocol::Runtime::ExceptionDetails>*) override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000099 Response setVariableValue(
100 int scopeNumber, const String16& variableName,
Ben Murdochf3b273f2017-01-17 12:11:28 +0000101 std::unique_ptr<protocol::Runtime::CallArgument> newValue,
102 const String16& callFrame) override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000103 Response setAsyncCallStackDepth(int depth) override;
104 Response setBlackboxPatterns(
Ben Murdochf3b273f2017-01-17 12:11:28 +0000105 std::unique_ptr<protocol::Array<String16>> patterns) override;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000106 Response setBlackboxedRanges(
107 const String16& scriptId,
Ben Murdochf3b273f2017-01-17 12:11:28 +0000108 std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>>
109 positions) override;
110
111 bool enabled();
112
113 void setBreakpointAt(const String16& scriptId, int lineNumber,
114 int columnNumber, BreakpointSource,
115 const String16& condition = String16());
116 void removeBreakpointAt(const String16& scriptId, int lineNumber,
117 int columnNumber, BreakpointSource);
118 void schedulePauseOnNextStatement(
119 const String16& breakReason,
120 std::unique_ptr<protocol::DictionaryValue> data);
121 void cancelPauseOnNextStatement();
122 void breakProgram(const String16& breakReason,
123 std::unique_ptr<protocol::DictionaryValue> data);
124 void breakProgramOnException(const String16& breakReason,
125 std::unique_ptr<protocol::DictionaryValue> data);
126
127 void reset();
128
129 // Interface for V8InspectorImpl
Ben Murdoch62ed6312017-06-06 11:06:27 +0100130 void didPause(int contextId, v8::Local<v8::Value> exception,
131 const std::vector<String16>& hitBreakpoints,
132 bool isPromiseRejection, bool isUncaught, bool isOOMBreak);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000133 void didContinue();
134 void didParseSource(std::unique_ptr<V8DebuggerScript>, bool success);
135 void willExecuteScript(int scriptId);
136 void didExecuteScript();
137
Ben Murdoch62ed6312017-06-06 11:06:27 +0100138 bool isFunctionBlackboxed(const String16& scriptId,
139 const v8::debug::Location& start,
140 const v8::debug::Location& end);
141
142 bool skipAllPauses() const { return m_skipAllPauses; }
143
Ben Murdochf3b273f2017-01-17 12:11:28 +0000144 v8::Isolate* isolate() { return m_isolate; }
145
146 private:
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000147 void enableImpl();
Ben Murdochf3b273f2017-01-17 12:11:28 +0000148
Ben Murdochf3b273f2017-01-17 12:11:28 +0000149 void schedulePauseOnNextStatementIfSteppingInto();
150
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000151 Response currentCallFrames(
152 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000153 std::unique_ptr<protocol::Runtime::StackTrace> currentAsyncStackTrace();
154
155 void changeJavaScriptRecursionLevel(int step);
156
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000157 void setPauseOnExceptionsImpl(int);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000158
159 std::unique_ptr<protocol::Debugger::Location> resolveBreakpoint(
Ben Murdoch62ed6312017-06-06 11:06:27 +0100160 const String16& breakpointId, const ScriptBreakpoint&, BreakpointSource);
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000161 void removeBreakpointImpl(const String16& breakpointId);
Ben Murdochf3b273f2017-01-17 12:11:28 +0000162 void clearBreakDetails();
163
Ben Murdochf3b273f2017-01-17 12:11:28 +0000164 void internalSetAsyncCallStackDepth(int);
165 void increaseCachedSkipStackGeneration();
166
Ben Murdochc8c1d9e2017-03-08 14:04:23 +0000167 Response setBlackboxPattern(const String16& pattern);
Ben Murdoch62ed6312017-06-06 11:06:27 +0100168 void resetBlackboxedStateCache();
169
170 bool isPaused() const;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000171
172 using ScriptsMap =
173 protocol::HashMap<String16, std::unique_ptr<V8DebuggerScript>>;
174 using BreakpointIdToDebuggerBreakpointIdsMap =
175 protocol::HashMap<String16, std::vector<String16>>;
176 using DebugServerBreakpointToBreakpointIdAndSourceMap =
177 protocol::HashMap<String16, std::pair<String16, BreakpointSource>>;
178 using MuteBreakpoins = protocol::HashMap<String16, std::pair<String16, int>>;
179
180 enum DebuggerStep { NoStep = 0, StepInto, StepOver, StepOut };
181
182 V8InspectorImpl* m_inspector;
183 V8Debugger* m_debugger;
184 V8InspectorSessionImpl* m_session;
185 bool m_enabled;
186 protocol::DictionaryValue* m_state;
187 protocol::Debugger::Frontend m_frontend;
188 v8::Isolate* m_isolate;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000189 JavaScriptCallFrames m_pausedCallFrames;
190 ScriptsMap m_scripts;
191 BreakpointIdToDebuggerBreakpointIdsMap m_breakpointIdToDebuggerBreakpointIds;
192 DebugServerBreakpointToBreakpointIdAndSourceMap m_serverBreakpoints;
193 String16 m_continueToLocationBreakpointId;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000194
Ben Murdoch62ed6312017-06-06 11:06:27 +0100195 using BreakReason =
196 std::pair<String16, std::unique_ptr<protocol::DictionaryValue>>;
197 std::vector<BreakReason> m_breakReason;
198
199 void pushBreakDetails(
200 const String16& breakReason,
201 std::unique_ptr<protocol::DictionaryValue> breakAuxData);
202 void popBreakDetails();
203
204 DebuggerStep m_scheduledDebuggerStep;
205 bool m_javaScriptPauseScheduled;
206
Ben Murdochf3b273f2017-01-17 12:11:28 +0000207 int m_recursionLevelForStepOut;
Ben Murdoch62ed6312017-06-06 11:06:27 +0100208 bool m_skipAllPauses = false;
Ben Murdochf3b273f2017-01-17 12:11:28 +0000209
210 std::unique_ptr<V8Regex> m_blackboxPattern;
211 protocol::HashMap<String16, std::vector<std::pair<int, int>>>
212 m_blackboxedPositions;
213
214 DISALLOW_COPY_AND_ASSIGN(V8DebuggerAgentImpl);
215};
216
217} // namespace v8_inspector
218
219#endif // V8_INSPECTOR_V8DEBUGGERAGENTIMPL_H_