v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-debugger-agent-impl.h
Go to the documentation of this file.
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 <memory>
10#include <unordered_map>
11#include <vector>
12
13#include "src/base/enum-set.h"
14#include "src/base/macros.h"
16#include "src/inspector/protocol/Debugger.h"
17#include "src/inspector/protocol/Forward.h"
18
19namespace v8_inspector {
20
21struct ScriptBreakpoint;
22class DisassemblyCollectorImpl;
23class V8Debugger;
24class V8DebuggerScript;
25class V8InspectorImpl;
26class V8InspectorSessionImpl;
27class V8Regex;
28
29using protocol::Response;
30
31class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
32 public:
38
39 V8DebuggerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
40 protocol::DictionaryValue* state);
44 void restore();
45 void stop();
46
47 // Part of the protocol.
48 Response enable(std::optional<double> maxScriptsCacheSize,
49 String16* outDebuggerId) override;
50 Response disable() override;
51 Response setBreakpointsActive(bool active) override;
52 Response setSkipAllPauses(bool skip) override;
53 Response setBreakpointByUrl(
54 int lineNumber, std::optional<String16> optionalURL,
55 std::optional<String16> optionalURLRegex,
56 std::optional<String16> optionalScriptHash,
57 std::optional<int> optionalColumnNumber,
58 std::optional<String16> optionalCondition, String16*,
59 std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
60 override;
61 Response setBreakpoint(
62 std::unique_ptr<protocol::Debugger::Location>,
63 std::optional<String16> optionalCondition, String16*,
64 std::unique_ptr<protocol::Debugger::Location>* actualLocation) override;
66 const String16& functionObjectId,
67 std::optional<String16> optionalCondition,
68 String16* outBreakpointId) override;
69 Response setInstrumentationBreakpoint(const String16& instrumentation,
70 String16* outBreakpointId) override;
71 Response removeBreakpoint(const String16& breakpointId) override;
72 Response continueToLocation(
73 std::unique_ptr<protocol::Debugger::Location>,
74 std::optional<String16> targetCallFrames) override;
75 Response getStackTrace(
76 std::unique_ptr<protocol::Runtime::StackTraceId> inStackTraceId,
77 std::unique_ptr<protocol::Runtime::StackTrace>* outStackTrace) override;
78 Response searchInContent(
79 const String16& scriptId, const String16& query,
80 std::optional<bool> optionalCaseSensitive,
81 std::optional<bool> optionalIsRegex,
82 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>>*)
83 override;
85 std::unique_ptr<protocol::Debugger::Location> start,
86 std::unique_ptr<protocol::Debugger::Location> end,
87 std::optional<bool> restrictToFunction,
88 std::unique_ptr<protocol::Array<protocol::Debugger::BreakLocation>>*
89 locations) override;
90 Response setScriptSource(
91 const String16& inScriptId, const String16& inScriptSource,
92 std::optional<bool> dryRun, std::optional<bool> allowTopFrameEditing,
93 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*
94 optOutCallFrames,
95 std::optional<bool>* optOutStackChanged,
96 std::unique_ptr<protocol::Runtime::StackTrace>* optOutAsyncStackTrace,
97 std::unique_ptr<protocol::Runtime::StackTraceId>* optOutAsyncStackTraceId,
98 String16* outStatus,
99 std::unique_ptr<protocol::Runtime::ExceptionDetails>* optOutCompileError)
100 override;
101 Response restartFrame(
102 const String16& callFrameId, std::optional<String16> mode,
103 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*
104 newCallFrames,
105 std::unique_ptr<protocol::Runtime::StackTrace>* asyncStackTrace,
106 std::unique_ptr<protocol::Runtime::StackTraceId>* asyncStackTraceId)
107 override;
108 Response getScriptSource(const String16& scriptId, String16* scriptSource,
109 std::optional<protocol::Binary>* bytecode) override;
110 Response disassembleWasmModule(
111 const String16& in_scriptId, std::optional<String16>* out_streamId,
112 int* out_totalNumberOfLines,
113 std::unique_ptr<protocol::Array<int>>* out_functionBodyOffsets,
114 std::unique_ptr<protocol::Debugger::WasmDisassemblyChunk>* out_chunk)
115 override;
117 const String16& in_streamId,
118 std::unique_ptr<protocol::Debugger::WasmDisassemblyChunk>* out_chunk)
119 override;
120 Response getWasmBytecode(const String16& scriptId,
121 protocol::Binary* bytecode) override;
122 Response pause() override;
123 Response resume(std::optional<bool> terminateOnResume) override;
124 Response stepOver(
125 std::unique_ptr<protocol::Array<protocol::Debugger::LocationRange>>
126 inSkipList) override;
127 Response stepInto(
128 std::optional<bool> inBreakOnAsyncCall,
129 std::unique_ptr<protocol::Array<protocol::Debugger::LocationRange>>
130 inSkipList) override;
131 Response stepOut() override;
132 Response pauseOnAsyncCall(std::unique_ptr<protocol::Runtime::StackTraceId>
133 inParentStackTraceId) override;
134 Response setPauseOnExceptions(const String16& pauseState) override;
135 Response evaluateOnCallFrame(
136 const String16& callFrameId, const String16& expression,
137 std::optional<String16> objectGroup,
138 std::optional<bool> includeCommandLineAPI, std::optional<bool> silent,
139 std::optional<bool> returnByValue, std::optional<bool> generatePreview,
140 std::optional<bool> throwOnSideEffect, std::optional<double> timeout,
141 std::unique_ptr<protocol::Runtime::RemoteObject>* result,
142 std::unique_ptr<protocol::Runtime::ExceptionDetails>*) override;
143 Response setVariableValue(
144 int scopeNumber, const String16& variableName,
145 std::unique_ptr<protocol::Runtime::CallArgument> newValue,
146 const String16& callFrame) override;
147 Response setReturnValue(
148 std::unique_ptr<protocol::Runtime::CallArgument> newValue) override;
149 Response setAsyncCallStackDepth(int depth) override;
150 Response setBlackboxPatterns(
151 std::unique_ptr<protocol::Array<String16>> patterns,
152 std::optional<bool> skipAnonymous) override;
154 std::unique_ptr<protocol::Array<String16>> uniqueIds) override;
155 Response setBlackboxedRanges(
156 const String16& scriptId,
157 std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>>
158 positions) override;
159
160 bool enabled() const { return m_enableState == kEnabled; }
161
164 BreakpointSource source);
166 BreakpointSource source);
168 const String16& breakReason,
169 std::unique_ptr<protocol::DictionaryValue> data);
171 void breakProgram(const String16& breakReason,
172 std::unique_ptr<protocol::DictionaryValue> data);
173
174 void reset();
175
177 // Interface for V8InspectorImpl
179
180 void didPause(int contextId, v8::Local<v8::Value> exception,
181 const std::vector<v8::debug::BreakpointId>& hitBreakpoints,
182 v8::debug::ExceptionType exceptionType, bool isUncaught,
183 v8::debug::BreakReasons breakReasons);
184 void didContinue();
185 void didParseSource(std::unique_ptr<V8DebuggerScript>, bool success);
186
187 bool isFunctionBlackboxed(const String16& scriptId,
189 const v8::debug::Location& end);
190 bool shouldBeSkipped(const String16& scriptId, int line, int column);
191
192 bool acceptsPause(bool isOOMBreak) const;
193
194 void ScriptCollected(const V8DebuggerScript* script);
195
197
198 void clearBreakDetails();
199
200 private:
201 void enableImpl();
202
203 Response currentCallFrames(
204 std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*);
205 std::unique_ptr<protocol::Runtime::StackTrace> currentAsyncStackTrace();
206 std::unique_ptr<protocol::Runtime::StackTraceId> currentExternalStackTrace();
207
208 void setPauseOnExceptionsImpl(int);
209
210 std::unique_ptr<protocol::Debugger::Location> setBreakpointImpl(
211 const String16& breakpointId, const String16& scriptId,
212 const String16& condition, int lineNumber, int columnNumber);
213 void setBreakpointImpl(const String16& breakpointId,
216 void removeBreakpointImpl(const String16& breakpointId,
217 const std::vector<V8DebuggerScript*>& scripts);
218
221
222 Response setBlackboxPattern(const String16& pattern);
224
225 bool isPaused() const;
226
228
229 Response processSkipList(
230 protocol::Array<protocol::Debugger::LocationRange>& skipList);
231
233 std::unordered_map<String16, std::unique_ptr<V8DebuggerScript>>;
235 std::unordered_map<String16, std::vector<v8::debug::BreakpointId>>;
237 std::unordered_map<v8::debug::BreakpointId, String16>;
238
242 kStopping, // This is the same as 'disabled', but it cannot become enabled
243 // again.
244 };
245
250 protocol::DictionaryValue* m_state;
251 protocol::Debugger::Frontend m_frontend;
256 std::map<String16, std::unique_ptr<DisassemblyCollectorImpl>>
259
265 std::vector<uint8_t> bytecode;
266
267 size_t size() const {
268 return source.length() * sizeof(UChar) + bytecode.size();
269 }
270 };
271 std::deque<CachedScript> m_cachedScripts;
272
274 std::pair<String16, std::unique_ptr<protocol::DictionaryValue>>;
275 std::vector<BreakReason> m_breakReason;
276
277 void pushBreakDetails(
278 const String16& breakReason,
279 std::unique_ptr<protocol::DictionaryValue> breakAuxData);
280 void popBreakDetails();
281
282 bool m_skipAllPauses = false;
286
287 std::unique_ptr<V8Regex> m_blackboxPattern;
288 std::unordered_map<String16, std::vector<std::pair<int, int>>>
290 std::unordered_map<String16, std::vector<std::pair<int, int>>> m_skipList;
291 std::unordered_set<String16> m_blackboxedExecutionContexts;
292};
293
294} // namespace v8_inspector
295
296#endif // V8_INSPECTOR_V8_DEBUGGER_AGENT_IMPL_H_
Response setBlackboxPatterns(std::unique_ptr< protocol::Array< String16 > > patterns, std::optional< bool > skipAnonymous) override
Response setVariableValue(int scopeNumber, const String16 &variableName, std::unique_ptr< protocol::Runtime::CallArgument > newValue, const String16 &callFrame) override
Response setSkipAllPauses(bool skip) override
std::unordered_map< String16, std::unique_ptr< V8DebuggerScript > > ScriptsMap
Response searchInContent(const String16 &scriptId, const String16 &query, std::optional< bool > optionalCaseSensitive, std::optional< bool > optionalIsRegex, std::unique_ptr< protocol::Array< protocol::Debugger::SearchMatch > > *) override
Response resume(std::optional< bool > terminateOnResume) override
void removeBreakpointFor(v8::Local< v8::Function > function, BreakpointSource source)
Response setBreakpointOnFunctionCall(const String16 &functionObjectId, std::optional< String16 > optionalCondition, String16 *outBreakpointId) override
V8DebuggerAgentImpl & operator=(const V8DebuggerAgentImpl &)=delete
std::unique_ptr< V8Regex > m_blackboxPattern
void schedulePauseOnNextStatement(const String16 &breakReason, std::unique_ptr< protocol::DictionaryValue > data)
std::map< String16, std::unique_ptr< DisassemblyCollectorImpl > > m_wasmDisassemblies
Response enable(std::optional< double > maxScriptsCacheSize, String16 *outDebuggerId) override
V8DebuggerAgentImpl(const V8DebuggerAgentImpl &)=delete
Response setPauseOnExceptions(const String16 &pauseState) override
Response setBreakpointByUrl(int lineNumber, std::optional< String16 > optionalURL, std::optional< String16 > optionalURLRegex, std::optional< String16 > optionalScriptHash, std::optional< int > optionalColumnNumber, std::optional< String16 > optionalCondition, String16 *, std::unique_ptr< protocol::Array< protocol::Debugger::Location > > *locations) override
Response removeBreakpoint(const String16 &breakpointId) override
Response getScriptSource(const String16 &scriptId, String16 *scriptSource, std::optional< protocol::Binary > *bytecode) override
void ScriptCollected(const V8DebuggerScript *script)
std::vector< BreakReason > m_breakReason
std::unique_ptr< protocol::Runtime::StackTraceId > currentExternalStackTrace()
std::unordered_map< String16, std::vector< std::pair< int, int > > > m_blackboxedPositions
void removeBreakpointImpl(const String16 &breakpointId, const std::vector< V8DebuggerScript * > &scripts)
void setScriptInstrumentationBreakpointIfNeeded(V8DebuggerScript *script)
std::deque< CachedScript > m_cachedScripts
Response setBreakpointsActive(bool active) override
Response continueToLocation(std::unique_ptr< protocol::Debugger::Location >, std::optional< String16 > targetCallFrames) override
Response setInstrumentationBreakpoint(const String16 &instrumentation, String16 *outBreakpointId) override
std::unordered_map< v8::debug::BreakpointId, String16 > DebuggerBreakpointIdToBreakpointIdMap
Response getStackTrace(std::unique_ptr< protocol::Runtime::StackTraceId > inStackTraceId, std::unique_ptr< protocol::Runtime::StackTrace > *outStackTrace) override
Response disassembleWasmModule(const String16 &in_scriptId, std::optional< String16 > *out_streamId, int *out_totalNumberOfLines, std::unique_ptr< protocol::Array< int > > *out_functionBodyOffsets, std::unique_ptr< protocol::Debugger::WasmDisassemblyChunk > *out_chunk) override
std::unordered_map< String16, std::vector< v8::debug::BreakpointId > > BreakpointIdToDebuggerBreakpointIdsMap
std::unique_ptr< protocol::Debugger::Location > setBreakpointImpl(const String16 &breakpointId, const String16 &scriptId, const String16 &condition, int lineNumber, int columnNumber)
Response setScriptSource(const String16 &inScriptId, const String16 &inScriptSource, std::optional< bool > dryRun, std::optional< bool > allowTopFrameEditing, std::unique_ptr< protocol::Array< protocol::Debugger::CallFrame > > *optOutCallFrames, std::optional< bool > *optOutStackChanged, std::unique_ptr< protocol::Runtime::StackTrace > *optOutAsyncStackTrace, std::unique_ptr< protocol::Runtime::StackTraceId > *optOutAsyncStackTraceId, String16 *outStatus, std::unique_ptr< protocol::Runtime::ExceptionDetails > *optOutCompileError) override
Response stepOver(std::unique_ptr< protocol::Array< protocol::Debugger::LocationRange > > inSkipList) override
BreakpointIdToDebuggerBreakpointIdsMap m_breakpointIdToDebuggerBreakpointIds
Response pauseOnAsyncCall(std::unique_ptr< protocol::Runtime::StackTraceId > inParentStackTraceId) override
Response setBreakpoint(std::unique_ptr< protocol::Debugger::Location >, std::optional< String16 > optionalCondition, String16 *, std::unique_ptr< protocol::Debugger::Location > *actualLocation) override
Response setBlackboxExecutionContexts(std::unique_ptr< protocol::Array< String16 > > uniqueIds) override
bool isFunctionBlackboxed(const String16 &scriptId, const v8::debug::Location &start, const v8::debug::Location &end)
Response getPossibleBreakpoints(std::unique_ptr< protocol::Debugger::Location > start, std::unique_ptr< protocol::Debugger::Location > end, std::optional< bool > restrictToFunction, std::unique_ptr< protocol::Array< protocol::Debugger::BreakLocation > > *locations) override
void pushBreakDetails(const String16 &breakReason, std::unique_ptr< protocol::DictionaryValue > breakAuxData)
void didPauseOnInstrumentation(v8::debug::BreakpointId instrumentationId)
Response setReturnValue(std::unique_ptr< protocol::Runtime::CallArgument > newValue) override
Response setBlackboxedRanges(const String16 &scriptId, std::unique_ptr< protocol::Array< protocol::Debugger::ScriptPosition > > positions) override
void setBreakpointFor(v8::Local< v8::Function > function, v8::Local< v8::String > condition, BreakpointSource source)
Response stepInto(std::optional< bool > inBreakOnAsyncCall, std::unique_ptr< protocol::Array< protocol::Debugger::LocationRange > > inSkipList) override
Response restartFrame(const String16 &callFrameId, std::optional< String16 > mode, std::unique_ptr< protocol::Array< protocol::Debugger::CallFrame > > *newCallFrames, std::unique_ptr< protocol::Runtime::StackTrace > *asyncStackTrace, std::unique_ptr< protocol::Runtime::StackTraceId > *asyncStackTraceId) override
V8DebuggerAgentImpl(V8InspectorSessionImpl *, protocol::FrontendChannel *, protocol::DictionaryValue *state)
Response evaluateOnCallFrame(const String16 &callFrameId, const String16 &expression, std::optional< String16 > objectGroup, std::optional< bool > includeCommandLineAPI, std::optional< bool > silent, std::optional< bool > returnByValue, std::optional< bool > generatePreview, std::optional< bool > throwOnSideEffect, std::optional< double > timeout, std::unique_ptr< protocol::Runtime::RemoteObject > *result, std::unique_ptr< protocol::Runtime::ExceptionDetails > *) override
std::unordered_set< String16 > m_blackboxedExecutionContexts
Response processSkipList(protocol::Array< protocol::Debugger::LocationRange > &skipList)
void didPause(int contextId, v8::Local< v8::Value > exception, const std::vector< v8::debug::BreakpointId > &hitBreakpoints, v8::debug::ExceptionType exceptionType, bool isUncaught, v8::debug::BreakReasons breakReasons)
std::pair< String16, std::unique_ptr< protocol::DictionaryValue > > BreakReason
protocol::Debugger::Frontend m_frontend
Response getWasmBytecode(const String16 &scriptId, protocol::Binary *bytecode) override
void breakProgram(const String16 &breakReason, std::unique_ptr< protocol::DictionaryValue > data)
Response setBlackboxPattern(const String16 &pattern)
std::unordered_map< String16, std::vector< std::pair< int, int > > > m_skipList
std::unique_ptr< protocol::Runtime::StackTrace > currentAsyncStackTrace()
Response nextWasmDisassemblyChunk(const String16 &in_streamId, std::unique_ptr< protocol::Debugger::WasmDisassemblyChunk > *out_chunk) override
void didParseSource(std::unique_ptr< V8DebuggerScript >, bool success)
Response currentCallFrames(std::unique_ptr< protocol::Array< protocol::Debugger::CallFrame > > *)
Response setAsyncCallStackDepth(int depth) override
bool shouldBeSkipped(const String16 &scriptId, int line, int column)
DebuggerBreakpointIdToBreakpointIdMap m_debuggerBreakpointIdToBreakpointId
int start
int end
std::string pattern
ZoneVector< RpoNumber > & result
char16_t UChar
Definition string-16.h:22