]> git.saurik.com Git - apple/javascriptcore.git/blob - inspector/agents/InspectorDebuggerAgent.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / inspector / agents / InspectorDebuggerAgent.h
1 /*
2 * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2010-2011 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef InspectorDebuggerAgent_h
31 #define InspectorDebuggerAgent_h
32
33 #include "InspectorBackendDispatchers.h"
34 #include "InspectorFrontendDispatchers.h"
35 #include "bindings/ScriptValue.h"
36 #include "debugger/Debugger.h"
37 #include "inspector/InspectorAgentBase.h"
38 #include "inspector/ScriptBreakpoint.h"
39 #include "inspector/ScriptDebugListener.h"
40 #include <wtf/Forward.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/Noncopyable.h>
43 #include <wtf/Vector.h>
44 #include <wtf/text/StringHash.h>
45
46 namespace WTF {
47 class Stopwatch;
48 }
49
50 namespace Inspector {
51
52 class InjectedScript;
53 class InjectedScriptManager;
54 class InspectorArray;
55 class InspectorObject;
56 class InspectorValue;
57 class ScriptDebugServer;
58 typedef String ErrorString;
59
60 class JS_EXPORT_PRIVATE InspectorDebuggerAgent : public InspectorAgentBase, public ScriptDebugListener, public DebuggerBackendDispatcherHandler {
61 WTF_MAKE_NONCOPYABLE(InspectorDebuggerAgent);
62 WTF_MAKE_FAST_ALLOCATED;
63 public:
64 static const char* backtraceObjectGroup;
65
66 virtual ~InspectorDebuggerAgent();
67
68 virtual void didCreateFrontendAndBackend(FrontendChannel*, BackendDispatcher*) override;
69 virtual void willDestroyFrontendAndBackend(DisconnectReason) override;
70
71 virtual void enable(ErrorString&) override;
72 virtual void disable(ErrorString&) override;
73 virtual void setBreakpointsActive(ErrorString&, bool active) override;
74 virtual void setBreakpointByUrl(ErrorString&, int lineNumber, const String* optionalURL, const String* optionalURLRegex, const int* optionalColumnNumber, const Inspector::InspectorObject* options, Inspector::Protocol::Debugger::BreakpointId*, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Debugger::Location>>& locations) override;
75 virtual void setBreakpoint(ErrorString&, const Inspector::InspectorObject& location, const Inspector::InspectorObject* options, Inspector::Protocol::Debugger::BreakpointId*, RefPtr<Inspector::Protocol::Debugger::Location>& actualLocation) override;
76 virtual void removeBreakpoint(ErrorString&, const String& breakpointIdentifier) override;
77 virtual void continueToLocation(ErrorString&, const InspectorObject& location) override;
78 virtual void searchInContent(ErrorString&, const String& scriptID, const String& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::GenericTypes::SearchMatch>>&) override;
79 virtual void getScriptSource(ErrorString&, const String& scriptID, String* scriptSource) override;
80 virtual void getFunctionDetails(ErrorString&, const String& functionId, RefPtr<Inspector::Protocol::Debugger::FunctionDetails>&) override;
81 virtual void pause(ErrorString&) override;
82 virtual void resume(ErrorString&) override;
83 virtual void stepOver(ErrorString&) override;
84 virtual void stepInto(ErrorString&) override;
85 virtual void stepOut(ErrorString&) override;
86 virtual void setPauseOnExceptions(ErrorString&, const String& pauseState) override;
87 virtual void evaluateOnCallFrame(ErrorString&, const String& callFrameId, const String& expression, const String* objectGroup, const bool* includeCommandLineAPI, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Inspector::Protocol::OptOutput<bool>* wasThrown, Inspector::Protocol::OptOutput<int>* savedResultIndex) override;
88 virtual void setOverlayMessage(ErrorString&, const String*) override;
89
90 bool isPaused();
91
92 void handleConsoleAssert(const String& message);
93
94 void schedulePauseOnNextStatement(DebuggerFrontendDispatcher::Reason breakReason, RefPtr<InspectorObject>&& data);
95 void cancelPauseOnNextStatement();
96 void breakProgram(DebuggerFrontendDispatcher::Reason breakReason, RefPtr<InspectorObject>&& data);
97 void scriptExecutionBlockedByCSP(const String& directiveText);
98
99 class Listener {
100 public:
101 virtual ~Listener() { }
102 virtual void debuggerWasEnabled() = 0;
103 virtual void debuggerWasDisabled() = 0;
104 virtual void stepInto() = 0;
105 virtual void didPause() = 0;
106 };
107 void setListener(Listener* listener) { m_listener = listener; }
108
109 virtual ScriptDebugServer& scriptDebugServer() = 0;
110
111 protected:
112 InspectorDebuggerAgent(InjectedScriptManager*);
113
114 InjectedScriptManager* injectedScriptManager() const { return m_injectedScriptManager; }
115 virtual InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) = 0;
116
117 virtual void startListeningScriptDebugServer() = 0;
118 virtual void stopListeningScriptDebugServer(bool skipRecompile) = 0;
119 virtual void muteConsole() = 0;
120 virtual void unmuteConsole() = 0;
121
122 virtual void enable();
123 virtual void disable(bool skipRecompile);
124 virtual void didPause(JSC::ExecState*, const Deprecated::ScriptValue& callFrames, const Deprecated::ScriptValue& exceptionOrCaughtValue) override;
125 virtual void didContinue() override;
126
127 virtual String sourceMapURLForScript(const Script&);
128
129 void didClearGlobalObject();
130
131 private:
132 Ref<Inspector::Protocol::Array<Inspector::Protocol::Debugger::CallFrame>> currentCallFrames(InjectedScript);
133
134 virtual void didParseSource(JSC::SourceID, const Script&) override final;
135 virtual void failedToParseSource(const String& url, const String& data, int firstLine, int errorLine, const String& errorMessage) override final;
136
137 virtual void breakpointActionSound(int breakpointActionIdentifier) override;
138 virtual void breakpointActionProbe(JSC::ExecState*, const ScriptBreakpointAction&, unsigned batchId, unsigned sampleId, const Deprecated::ScriptValue& sample) override final;
139
140 RefPtr<Inspector::Protocol::Debugger::Location> resolveBreakpoint(const String& breakpointIdentifier, JSC::SourceID, const ScriptBreakpoint&);
141 bool assertPaused(ErrorString&);
142 void clearDebuggerBreakpointState();
143 void clearInspectorBreakpointState();
144 void clearBreakDetails();
145 void clearExceptionValue();
146
147 RefPtr<InspectorObject> buildBreakpointPauseReason(JSC::BreakpointID);
148 RefPtr<InspectorObject> buildExceptionPauseReason(const Deprecated::ScriptValue& exception, const InjectedScript&);
149
150 bool breakpointActionsFromProtocol(ErrorString&, RefPtr<InspectorArray>& actions, BreakpointActions* result);
151
152 typedef HashMap<JSC::SourceID, Script> ScriptsMap;
153 typedef HashMap<String, Vector<JSC::BreakpointID>> BreakpointIdentifierToDebugServerBreakpointIDsMap;
154 typedef HashMap<String, RefPtr<InspectorObject>> BreakpointIdentifierToBreakpointMap;
155 typedef HashMap<JSC::BreakpointID, String> DebugServerBreakpointIDToBreakpointIdentifier;
156
157 InjectedScriptManager* m_injectedScriptManager;
158 std::unique_ptr<DebuggerFrontendDispatcher> m_frontendDispatcher;
159 RefPtr<DebuggerBackendDispatcher> m_backendDispatcher;
160 Listener* m_listener {nullptr};
161 JSC::ExecState* m_pausedScriptState {nullptr};
162 Deprecated::ScriptValue m_currentCallStack;
163 ScriptsMap m_scripts;
164 BreakpointIdentifierToDebugServerBreakpointIDsMap m_breakpointIdentifierToDebugServerBreakpointIDs;
165 BreakpointIdentifierToBreakpointMap m_javaScriptBreakpoints;
166 DebugServerBreakpointIDToBreakpointIdentifier m_debuggerBreakpointIdentifierToInspectorBreakpointIdentifier;
167 JSC::BreakpointID m_continueToLocationBreakpointID;
168 DebuggerFrontendDispatcher::Reason m_breakReason;
169 RefPtr<InspectorObject> m_breakAuxData;
170 bool m_enabled {false};
171 bool m_javaScriptPauseScheduled {false};
172 bool m_hasExceptionValue {false};
173 bool m_didPauseStopwatch {false};
174 RefPtr<WTF::Stopwatch> m_stopwatch;
175 };
176
177 } // namespace Inspector
178
179 #endif // !defined(InspectorDebuggerAgent_h)