v8-debugger-agent-impl.h 8.58 KB
Newer Older
1 2 3 4
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_INSPECTOR_V8_DEBUGGER_AGENT_IMPL_H_
#define V8_INSPECTOR_V8_DEBUGGER_AGENT_IMPL_H_
7

8 9
#include <vector>

10
#include "src/base/macros.h"
11
#include "src/debug/debug-interface.h"
12
#include "src/debug/interface-types.h"
13 14 15 16 17 18 19 20 21 22 23 24 25
#include "src/inspector/protocol/Debugger.h"
#include "src/inspector/protocol/Forward.h"

namespace v8_inspector {

struct ScriptBreakpoint;
class V8Debugger;
class V8DebuggerScript;
class V8InspectorImpl;
class V8InspectorSessionImpl;
class V8Regex;

using protocol::Maybe;
26
using protocol::Response;
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
 public:
  enum BreakpointSource {
    UserBreakpointSource,
    DebugCommandBreakpointSource,
    MonitorCommandBreakpointSource
  };

  V8DebuggerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
                      protocol::DictionaryValue* state);
  ~V8DebuggerAgentImpl() override;
  void restore();

  // Part of the protocol.
42
  Response enable(String16* outDebuggerId) override;
43 44 45 46 47
  Response disable() override;
  Response setBreakpointsActive(bool active) override;
  Response setSkipAllPauses(bool skip) override;
  Response setBreakpointByUrl(
      int lineNumber, Maybe<String16> optionalURL,
48 49 50
      Maybe<String16> optionalURLRegex, Maybe<String16> optionalScriptHash,
      Maybe<int> optionalColumnNumber, Maybe<String16> optionalCondition,
      String16*,
51 52
      std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
      override;
53 54 55
  Response setBreakpoint(
      std::unique_ptr<protocol::Debugger::Location>,
      Maybe<String16> optionalCondition, String16*,
56
      std::unique_ptr<protocol::Debugger::Location>* actualLocation) override;
57
  Response removeBreakpoint(const String16& breakpointId) override;
58 59
  Response continueToLocation(std::unique_ptr<protocol::Debugger::Location>,
                              Maybe<String16> targetCallFrames) override;
60 61 62
  Response getStackTrace(
      std::unique_ptr<protocol::Runtime::StackTraceId> inStackTraceId,
      std::unique_ptr<protocol::Runtime::StackTrace>* outStackTrace) override;
63 64 65
  Response searchInContent(
      const String16& scriptId, const String16& query,
      Maybe<bool> optionalCaseSensitive, Maybe<bool> optionalIsRegex,
66 67
      std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>>*)
      override;
68 69
  Response getPossibleBreakpoints(
      std::unique_ptr<protocol::Debugger::Location> start,
70
      Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction,
71 72
      std::unique_ptr<protocol::Array<protocol::Debugger::BreakLocation>>*
          locations) override;
73 74 75
  Response setScriptSource(
      const String16& inScriptId, const String16& inScriptSource,
      Maybe<bool> dryRun,
76 77 78
      Maybe<protocol::Array<protocol::Debugger::CallFrame>>* optOutCallFrames,
      Maybe<bool>* optOutStackChanged,
      Maybe<protocol::Runtime::StackTrace>* optOutAsyncStackTrace,
79
      Maybe<protocol::Runtime::StackTraceId>* optOutAsyncStackTraceId,
80
      Maybe<protocol::Runtime::ExceptionDetails>* optOutCompileError) override;
81 82
  Response restartFrame(
      const String16& callFrameId,
83 84
      std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*
          newCallFrames,
85 86
      Maybe<protocol::Runtime::StackTrace>* asyncStackTrace,
      Maybe<protocol::Runtime::StackTraceId>* asyncStackTraceId) override;
87 88 89 90 91
  Response getScriptSource(const String16& scriptId,
                           String16* scriptSource) override;
  Response pause() override;
  Response resume() override;
  Response stepOver() override;
92
  Response stepInto(Maybe<bool> inBreakOnAsyncCall) override;
93
  Response stepOut() override;
94 95
  void scheduleStepIntoAsync(
      std::unique_ptr<ScheduleStepIntoAsyncCallback> callback) override;
96 97
  Response pauseOnAsyncCall(std::unique_ptr<protocol::Runtime::StackTraceId>
                                inParentStackTraceId) override;
98 99 100 101 102
  Response setPauseOnExceptions(const String16& pauseState) override;
  Response evaluateOnCallFrame(
      const String16& callFrameId, const String16& expression,
      Maybe<String16> objectGroup, Maybe<bool> includeCommandLineAPI,
      Maybe<bool> silent, Maybe<bool> returnByValue,
103
      Maybe<bool> generatePreview, Maybe<bool> throwOnSideEffect,
104 105
      std::unique_ptr<protocol::Runtime::RemoteObject>* result,
      Maybe<protocol::Runtime::ExceptionDetails>*) override;
106 107
  Response setVariableValue(
      int scopeNumber, const String16& variableName,
108 109
      std::unique_ptr<protocol::Runtime::CallArgument> newValue,
      const String16& callFrame) override;
110 111
  Response setReturnValue(
      std::unique_ptr<protocol::Runtime::CallArgument> newValue) override;
112 113
  Response setAsyncCallStackDepth(int depth) override;
  Response setBlackboxPatterns(
114
      std::unique_ptr<protocol::Array<String16>> patterns) override;
115 116
  Response setBlackboxedRanges(
      const String16& scriptId,
117 118 119
      std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>>
          positions) override;

120
  bool enabled() const { return m_enabled; }
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

  void setBreakpointAt(const String16& scriptId, int lineNumber,
                       int columnNumber, BreakpointSource,
                       const String16& condition = String16());
  void removeBreakpointAt(const String16& scriptId, int lineNumber,
                          int columnNumber, BreakpointSource);
  void schedulePauseOnNextStatement(
      const String16& breakReason,
      std::unique_ptr<protocol::DictionaryValue> data);
  void cancelPauseOnNextStatement();
  void breakProgram(const String16& breakReason,
                    std::unique_ptr<protocol::DictionaryValue> data);

  void reset();

  // Interface for V8InspectorImpl
137
  void didPause(int contextId, v8::Local<v8::Value> exception,
138
                const std::vector<v8::debug::BreakpointId>& hitBreakpoints,
139 140
                bool isPromiseRejection, bool isUncaught, bool isOOMBreak,
                bool isAssert);
141 142 143
  void didContinue();
  void didParseSource(std::unique_ptr<V8DebuggerScript>, bool success);

144 145 146 147
  bool isFunctionBlackboxed(const String16& scriptId,
                            const v8::debug::Location& start,
                            const v8::debug::Location& end);

148
  bool acceptsPause(bool isOOMBreak) const;
149

150 151 152
  v8::Isolate* isolate() { return m_isolate; }

 private:
153
  void enableImpl();
154

155 156
  Response currentCallFrames(
      std::unique_ptr<protocol::Array<protocol::Debugger::CallFrame>>*);
157
  std::unique_ptr<protocol::Runtime::StackTrace> currentAsyncStackTrace();
158
  std::unique_ptr<protocol::Runtime::StackTraceId> currentExternalStackTrace();
159
  std::unique_ptr<protocol::Runtime::StackTraceId> currentScheduledAsyncCall();
160

161
  void setPauseOnExceptionsImpl(int);
162

163 164 165
  std::unique_ptr<protocol::Debugger::Location> setBreakpointImpl(
      const String16& breakpointId, const String16& scriptId,
      const String16& condition, int lineNumber, int columnNumber);
166
  void removeBreakpointImpl(const String16& breakpointId);
167 168 169 170 171
  void clearBreakDetails();

  void internalSetAsyncCallStackDepth(int);
  void increaseCachedSkipStackGeneration();

172
  Response setBlackboxPattern(const String16& pattern);
173
  void resetBlackboxedStateCache();
174

175 176
  bool isPaused() const;

177 178 179
  using ScriptsMap =
      protocol::HashMap<String16, std::unique_ptr<V8DebuggerScript>>;
  using BreakpointIdToDebuggerBreakpointIdsMap =
180
      protocol::HashMap<String16, std::vector<v8::debug::BreakpointId>>;
181 182
  using DebuggerBreakpointIdToBreakpointIdMap =
      protocol::HashMap<v8::debug::BreakpointId, String16>;
183 184 185 186 187 188 189 190 191 192

  V8InspectorImpl* m_inspector;
  V8Debugger* m_debugger;
  V8InspectorSessionImpl* m_session;
  bool m_enabled;
  protocol::DictionaryValue* m_state;
  protocol::Debugger::Frontend m_frontend;
  v8::Isolate* m_isolate;
  ScriptsMap m_scripts;
  BreakpointIdToDebuggerBreakpointIdsMap m_breakpointIdToDebuggerBreakpointIds;
193
  DebuggerBreakpointIdToBreakpointIdMap m_debuggerBreakpointIdToBreakpointId;
194 195 196 197 198 199 200 201 202 203

  using BreakReason =
      std::pair<String16, std::unique_ptr<protocol::DictionaryValue>>;
  std::vector<BreakReason> m_breakReason;

  void pushBreakDetails(
      const String16& breakReason,
      std::unique_ptr<protocol::DictionaryValue> breakAuxData);
  void popBreakDetails();

204
  bool m_skipAllPauses = false;
205
  bool m_breakpointsActive = false;
206 207 208 209

  std::unique_ptr<V8Regex> m_blackboxPattern;
  protocol::HashMap<String16, std::vector<std::pair<int, int>>>
      m_blackboxedPositions;
210 211

  DISALLOW_COPY_AND_ASSIGN(V8DebuggerAgentImpl);
212 213
};

214 215
String16 scopeType(v8::debug::ScopeIterator::ScopeType type);

216 217
}  // namespace v8_inspector

218
#endif  // V8_INSPECTOR_V8_DEBUGGER_AGENT_IMPL_H_