5 #ifndef V8_INSPECTOR_V8_DEBUGGER_H_ 6 #define V8_INSPECTOR_V8_DEBUGGER_H_ 9 #include <unordered_map> 10 #include <unordered_set> 13 #include "src/base/macros.h" 14 #include "src/inspector/inspected-context.h" 15 #include "src/inspector/protocol/Debugger.h" 16 #include "src/inspector/protocol/Forward.h" 17 #include "src/inspector/protocol/Runtime.h" 18 #include "src/inspector/v8-debugger-script.h" 19 #include "src/inspector/wasm-translation.h" 21 #include "include/v8-inspector.h" 25 class AsyncStackTrace;
28 class V8DebuggerAgentImpl;
29 class V8InspectorImpl;
30 class V8StackTraceImpl;
31 struct V8StackTraceId;
33 enum class WrapMode { kForceValue, kNoPreview, kWithPreview };
35 using protocol::Response;
36 using ScheduleStepIntoAsyncCallback =
37 protocol::Debugger::Backend::ScheduleStepIntoAsyncCallback;
38 using TerminateExecutionCallback =
39 protocol::Runtime::Backend::TerminateExecutionCallback;
48 v8::Isolate* isolate()
const {
return m_isolate; }
50 void setBreakpointsActive(
bool);
52 v8::debug::ExceptionBreakState getPauseOnExceptionsState();
53 void setPauseOnExceptionsState(v8::debug::ExceptionBreakState);
54 bool canBreakProgram();
55 void breakProgram(
int targetContextGroupId);
56 void interruptAndBreak(
int targetContextGroupId);
57 void continueProgram(
int targetContextGroupId);
58 void breakProgramOnAssert(
int targetContextGroupId);
60 void setPauseOnNextCall(
bool,
int targetContextGroupId);
61 void stepIntoStatement(
int targetContextGroupId,
bool breakOnAsyncCall);
62 void stepOverStatement(
int targetContextGroupId);
63 void stepOutOfFunction(
int targetContextGroupId);
64 void scheduleStepIntoAsync(
65 std::unique_ptr<ScheduleStepIntoAsyncCallback> callback,
66 int targetContextGroupId);
67 void pauseOnAsyncCall(
int targetContextGroupId,
uintptr_t task,
70 void terminateExecution(std::unique_ptr<TerminateExecutionCallback> callback);
72 Response continueToLocation(
int targetContextGroupId,
74 std::unique_ptr<protocol::Debugger::Location>,
81 void getCompiledScripts(
int contextGroupId,
82 std::vector<std::unique_ptr<V8DebuggerScript>>&);
86 bool isPaused()
const {
return m_pausedContextGroupId; }
87 bool isPausedInContextGroup(
int contextGroupId)
const;
89 int maxAsyncCallChainDepth() {
return m_maxAsyncCallStackDepth; }
92 std::shared_ptr<AsyncStackTrace> currentAsyncParent();
98 std::unique_ptr<V8StackTraceImpl> captureStackTrace(
bool fullStack);
106 void asyncTaskScheduled(
const StringView& taskName,
void* task,
108 void asyncTaskCanceled(
void* task);
109 void asyncTaskStarted(
void* task);
110 void asyncTaskFinished(
void* task);
111 void allAsyncTasksCanceled();
117 uintptr_t storeStackTrace(std::shared_ptr<AsyncStackTrace> stack);
119 void muteScriptParsedEvents();
120 void unmuteScriptParsedEvents();
126 void setMaxAsyncTaskStacksForTest(
int limit);
127 void dumpAsyncTaskStacksStateForTest();
130 return m_scheduledAsyncCall;
133 std::pair<int64_t, int64_t> debuggerIdFor(
int contextGroupId);
134 std::pair<int64_t, int64_t> debuggerIdFor(
135 const String16& serializedDebuggerId);
136 std::shared_ptr<AsyncStackTrace> stackTraceFor(
int contextGroupId,
142 V8InternalValueType
type);
144 void clearContinueToLocation();
145 bool shouldContinueToCurrentLocation();
147 static size_t nearHeapLimitCallback(
void* data,
size_t current_heap_limit,
148 size_t initial_heap_limit);
149 static void terminateExecutionCompletedCallback(v8::Isolate* isolate);
151 void handleProgramBreak(
153 const std::vector<v8::debug::BreakpointId>& hitBreakpoints,
154 v8::debug::ExceptionType exception_type = v8::debug::kException,
155 bool isUncaught =
false);
157 enum ScopeTargetKind {
172 void asyncTaskScheduledForStack(
const String16& taskName,
void* task,
174 void asyncTaskCanceledForStack(
void* task);
175 void asyncTaskStartedForStack(
void* task);
176 void asyncTaskFinishedForStack(
void* task);
178 void asyncTaskCandidateForStepping(
void* task,
bool isLocal);
179 void asyncTaskStartedForStepping(
void* task);
180 void asyncTaskFinishedForStepping(
void* task);
181 void asyncTaskCanceledForStepping(
void* task);
184 void AsyncEventOccurred(v8::debug::DebugAsyncActionType
type,
int id,
185 bool isBlackboxed)
override;
187 bool has_compile_error)
override;
188 void BreakProgramRequested(
190 const std::vector<v8::debug::BreakpointId>& break_points_hit)
override;
194 v8::debug::ExceptionType exception_type)
override;
199 int currentContextGroupId();
200 bool asyncStepOutOfFunction(
int targetContextGroupId,
bool onlyAtReturn);
202 v8::Isolate* m_isolate;
205 int m_breakpointsActiveCount = 0;
206 int m_ignoreScriptParsedEventsCounter;
207 size_t m_originalHeapLimit = 0;
208 bool m_scheduledOOMBreak =
false;
209 bool m_scheduledAssertBreak =
false;
210 int m_targetContextGroupId = 0;
211 int m_pausedContextGroupId = 0;
212 int m_continueToLocationBreakpointId;
213 String16 m_continueToLocationTargetCallFrames;
214 std::unique_ptr<V8StackTraceImpl> m_continueToLocationStack;
216 using AsyncTaskToStackTrace =
217 std::unordered_map<void*, std::weak_ptr<AsyncStackTrace>>;
218 AsyncTaskToStackTrace m_asyncTaskStacks;
219 std::unordered_set<void*> m_recurringTasks;
221 int m_maxAsyncCallStacks;
222 int m_maxAsyncCallStackDepth;
224 std::vector<void*> m_currentTasks;
225 std::vector<std::shared_ptr<AsyncStackTrace>> m_currentAsyncParent;
226 std::vector<V8StackTraceId> m_currentExternalParent;
228 void collectOldAsyncStacksIfNeeded();
229 int m_asyncStacksCount = 0;
232 std::list<std::shared_ptr<AsyncStackTrace>> m_allAsyncStacks;
233 std::unordered_map<int, std::weak_ptr<StackFrame>> m_framesCache;
235 std::unordered_map<V8DebuggerAgentImpl*, int> m_maxAsyncCallStackDepthMap;
236 void* m_taskWithScheduledBreak =
nullptr;
237 String16 m_taskWithScheduledBreakDebuggerId;
239 std::unique_ptr<ScheduleStepIntoAsyncCallback> m_stepIntoAsyncCallback;
240 bool m_breakRequested =
false;
242 v8::debug::ExceptionBreakState m_pauseOnExceptionsState;
243 bool m_pauseOnAsyncCall =
false;
246 using StackTraceIdToStackTrace =
247 std::unordered_map<uintptr_t, std::weak_ptr<AsyncStackTrace>>;
248 StackTraceIdToStackTrace m_storedStackTraces;
251 std::unordered_map<int, std::pair<int64_t, int64_t>>
252 m_contextGroupIdToDebuggerId;
253 std::unordered_map<String16, std::pair<int64_t, int64_t>>
254 m_serializedDebuggerIdToDebuggerId;
256 std::unique_ptr<TerminateExecutionCallback> m_terminateExecutionCallback;
265 #endif // V8_INSPECTOR_V8_DEBUGGER_H_