Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: Source/bindings/dart/DartScriptDebugServer.h

Issue 300393002: Merge DevTools Refactor CL to Blink36 (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1985
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef DartScriptDebugServer_h
32 #define DartScriptDebugServer_h
33
34 #include "bindings/v8/PageScriptDebugServer.h"
35 #include "bindings/v8/ScopedPersistent.h"
36 #include "bindings/v8/ScriptDebugServer.h"
37 #include "bindings/v8/ScriptPreprocessor.h"
38 #include "wtf/Forward.h"
39 #include "wtf/HashSet.h"
40 #include "wtf/RefCounted.h"
41 #include <dart_api.h>
42 #include <dart_debugger_api.h>
43 #include <v8.h>
44
45 namespace WebCore {
46
47 class Page;
48
49 template<typename T>
50 class HandleMap {
51 public:
52 HandleMap() : m_lastHandle(0)
53 {
54 }
55
56 int add(T value)
57 {
vsm 2014/06/03 14:24:49 Do you want to assert whether the value is already
Jacob 2014/06/03 20:23:13 This helper class was just copied from the old Dar
58 int handle = ++m_lastHandle;
59 m_handleToValueMap.set(handle, value);
60 m_valueToHandleMap.set(value, handle);
61 return handle;
62 }
63
64 T get(int handle)
65 {
66 return m_handleToValueMap.get(handle);
67 }
68
69 bool containsValue(T value)
70 {
71 return m_valueToHandleMap.contains(value);
72 }
73
74 int getByValue(T value)
75 {
76 ASSERT(m_valueToHandleMap.contains(value));
77 return m_valueToHandleMap.get(value);
78 }
79
80 T remove(int handle)
81 {
82 T value = m_handleToValueMap.take(handle);
83 m_valueToHandleMap.remove(value);
84 return value;
85 }
86
87 int removeByValue(T value)
88 {
89 int handle = m_valueToHandleMap.take(value);
90 m_handleToValueMap.remove(handle);
91 return handle;
92 }
93
94 void copyValues(Vector<T>& values)
95 {
96 copyKeysToVector(m_valueToHandleMap, values);
97 }
98
99 private:
100 int m_lastHandle;
101 HashMap<int, T> m_handleToValueMap;
102 HashMap<T, int> m_valueToHandleMap;
103 };
104
105 struct DartBreakpoint {
106 DartBreakpoint(intptr_t breakpointId, Dart_Isolate);
107
108 intptr_t m_breakpointId;
109 Dart_Isolate m_isolate;
110 };
111
112
113 struct DartBreakpointInfo {
114 DartBreakpointInfo(const String& scriptUrl, const ScriptBreakpoint&);
115 String m_scriptUrl;
116 ScriptBreakpoint m_scriptBreakpoint;
117 Vector<DartBreakpoint> m_breakpoints;
118 };
119
120 class DartPageDebug {
121 public:
122 DartPageDebug(Page*, size_t pageId);
123 ~DartPageDebug();
124
125 String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* a ctualLineNumber, int* actualColumnNumber, bool interstatementLocation);
126
127 void registerIsolate(Dart_Isolate);
128 void unregisterIsolate(Dart_Isolate);
129
130 intptr_t setBreakpointHelper(DartBreakpointInfo*, const String& breakpointId String, Dart_Isolate, Dart_Handle& exception);
131
132 void removeBreakpoint(const String& breakpointId);
133 void removeBreakpointHelper(DartBreakpointInfo*);
134 void clearBreakpointsForIsolate(Dart_Isolate);
135 void clearBreakpoints();
136 void isolateLoaded();
137 void addListener(ScriptDebugListener*);
138 void removeListener();
139 ScriptDebugListener* listener() { return m_listener; }
140 String getScriptId(const String& url);
141 String lookupBreakpointId(intptr_t dartBreakpointId);
142
143 Vector<Dart_Isolate> isolates();
144 bool containsIsolate(Dart_Isolate isolate) { return m_isolateMap.containsVal ue(isolate); }
145 Page* page() { return m_page; }
146 private:
147 void registerIsolateScripts(Dart_Isolate);
148 void dispatchDidParseSource(intptr_t libraryId, Dart_Handle scriptURL, Dart_ Isolate);
149
150 HandleMap<Dart_Isolate> m_isolateMap;
151
152 Page* m_page;
153 ScriptDebugListener* m_listener;
154 size_t m_pageId;
155 HashMap<String, String> m_idToScriptUrlMap;
156 HashMap<String, String> m_scriptUrlToIdMap;
157
158 typedef HashMap<String, DartBreakpointInfo* > BreakpointMap;
159 BreakpointMap m_breakpoints;
160 typedef HashMap<intptr_t, String> BreakpointIdMap;
161 BreakpointIdMap m_breakpointIdMap;
162 size_t m_nextBreakpointId;
163 size_t m_nextScriptId;
164 };
165
166 class DartScriptDebugServer : public ScriptDebugServerBase {
167 WTF_MAKE_NONCOPYABLE(DartScriptDebugServer);
168 public:
169 static DartScriptDebugServer& shared();
170
171 void addListener(ScriptDebugListener*, Page*);
172 void removeListener(ScriptDebugListener*, Page*);
173
174 void setClientMessageLoop(PageScriptDebugServer::ClientMessageLoop*);
175
176 virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint& , int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation);
177 virtual void removeBreakpoint(const String& breakpointId);
178 virtual void clearBreakpoints();
179 virtual void setBreakpointsActivated(bool);
180
181 virtual ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionsState();
182 virtual void setPauseOnExceptionsState(ScriptDebugServer::PauseOnExceptionsS tate);
183
184 virtual void setPauseOnNextStatement(bool);
185 virtual bool canBreakProgram();
186 virtual void breakProgram();
187 virtual void continueProgram();
188 virtual void stepIntoStatement();
189 virtual void stepOverStatement(const ActivationFrame&);
190 virtual void stepOutOfFunction(const ActivationFrame&);
191
192 virtual bool setScriptSource(const String& sourceID, const String& newConten t, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceErr or>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result);
193 virtual StackTrace currentCallFrames();
194 virtual StackTrace currentCallFramesForAsyncStack();
195
196 virtual bool isPaused();
197 virtual bool runningNestedMessageLoop() { return m_runningNestedMessageLoop; }
198
199 virtual void clearCompiledScripts();
200 virtual void setPreprocessorSource(const String&);
201 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou rceCode&);
202 virtual String preprocessEventListener(LocalFrame*, const String& source, co nst String& url, const String& functionName);
203 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re sult, bool* wasThrown, String* exceptionMessage);
204 virtual bool canPreprocess(LocalFrame*);
205
206 static void pausedEventHandler(Dart_IsolateId, intptr_t breakpointId, const Dart_CodeLocation&);
207 static void exceptionHandler(Dart_IsolateId, Dart_Handle, Dart_StackTrace);
208 void handleException(Dart_IsolateId, Dart_Handle, Dart_StackTrace);
209
210 static void isolateEventHandler(Dart_IsolateId, Dart_IsolateEvent kind);
211 void handleInterrupted(Dart_IsolateId);
212
213 void registerIsolate(Dart_Isolate, Page*);
214 void unregisterIsolate(Dart_Isolate, Page*);
215 void isolateLoaded();
216
217 bool resolveCodeLocation(const Dart_CodeLocation&, int* line, int* column);
218
219 String getScriptId(const String& url, Dart_Isolate);
220
221 ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionState() { return m _pauseOnExceptionState; }
222 protected:
223 explicit DartScriptDebugServer();
224 virtual ~DartScriptDebugServer();
225
226 DartPageDebug* lookupPageDebugForId(const String& id);
227 DartPageDebug* lookupPageDebug(Page*);
228 DartPageDebug* lookupPageDebugForCurrentIsolate();
229 void runMessageLoopOnPause(Dart_Isolate);
230 void quitMessageLoopOnPause();
231 bool executeSkipPauseRequest(ScriptDebugListener::SkipPauseRequest, Dart_Sta ckTrace);
232 void handleProgramBreak(Dart_Isolate, Dart_StackTrace, intptr_t dartBreakpoi ntId, Dart_Handle exception, const Dart_CodeLocation&);
233 void handleDartDebugEvent(Dart_IsolateId, intptr_t breakpointId, Dart_Handle exception, const Dart_CodeLocation&);
234
235 void debugBreak();
236 void cancelDebugBreak();
237 Page* inferPage(Dart_Isolate);
238
239 Vector<Dart_Isolate> isolates();
240 Vector<DartPageDebug*> pages();
241
242 ScriptDebugServer::PauseOnExceptionsState m_pauseOnExceptionState;
243 bool m_breakpointsActivated;
244 bool m_runningNestedMessageLoop;
245 Dart_StackTrace m_executionState;
246 Page* m_pausedPage;
247 HashSet<Dart_Isolate> m_interruptCalled;
248 HashSet<Dart_Isolate> m_interruptCancelled;
249
250 typedef HashMap<size_t, DartPageDebug*> DebugDataMap;
251 DebugDataMap m_pageIdToDebugDataMap;
252 typedef HashMap<Page*, size_t> PageToIdMap;
253 PageToIdMap m_pageToIdMap;
254
255 PageScriptDebugServer::ClientMessageLoop* m_clientMessageLoop;
256
257 size_t m_nextPageId;
258 };
259
260 // FIXMEDART: this is really UnifiedPageScriptDebugServer. For completeness
261 // add a separate UnifiedScriptDebugServer class that lacks methods to add and
262 // remove page listeners.
263 class UnifiedScriptDebugServer : public ScriptDebugServerBase {
264 WTF_MAKE_NONCOPYABLE(UnifiedScriptDebugServer);
265 public:
266 UnifiedScriptDebugServer(DartScriptDebugServer*, PageScriptDebugServer*);
267
268 static UnifiedScriptDebugServer& shared();
269
270 virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint& , int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation);
271 virtual void removeBreakpoint(const String& breakpointId);
272 virtual void clearBreakpoints();
273 virtual void setBreakpointsActivated(bool);
274
275 virtual ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionsState();
276 virtual void setPauseOnExceptionsState(ScriptDebugServer::PauseOnExceptionsS tate);
277
278 virtual void setPauseOnNextStatement(bool);
279 virtual bool canBreakProgram();
280 virtual void breakProgram();
281 virtual void continueProgram();
282 virtual void stepIntoStatement();
283 virtual void stepOverStatement(const ActivationFrame&);
284 virtual void stepOutOfFunction(const ActivationFrame&);
285
286 virtual bool setScriptSource(const String& sourceID, const String& newConten t, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceErr or>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result);
287 virtual StackTrace currentCallFrames();
288 virtual StackTrace currentCallFramesForAsyncStack();
289
290 virtual bool isPaused();
291 virtual bool runningNestedMessageLoop();
292
293 virtual void clearCompiledScripts();
294 virtual void setPreprocessorSource(const String&);
295
296 // FIXMEDART: this signature is v8 specific.
297 virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&);
298 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou rceCode&);
299 virtual String preprocessEventListener(LocalFrame*, const String& source, co nst String& url, const String& functionName);
300 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re sult, bool* wasThrown, String* exceptionMessage);
301
302 void addListener(ScriptDebugListener*, Page*);
303 void removeListener(ScriptDebugListener*, Page*);
304
305 DartScriptDebugServer& dart() { return *m_dart; }
306 PageScriptDebugServer& v8() { return *m_v8; }
307 private:
308
309 bool isDartSourceID(const String& sourceID);
310 bool isDartBreakpointId(const String& breakpointId);
311 DartScriptDebugServer* m_dart;
312 PageScriptDebugServer* m_v8;
313 };
314
315 }
316
317 #endif // DartScriptDebugServer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698