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

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: PTAL 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 {
58 ASSERT(!m_valueToHandleMap.contains(value));
59 int handle = ++m_lastHandle;
60 m_handleToValueMap.set(handle, value);
61 m_valueToHandleMap.set(value, handle);
62 return handle;
63 }
64
65 T get(int handle)
66 {
67 return m_handleToValueMap.get(handle);
68 }
69
70 bool containsValue(T value)
71 {
72 return m_valueToHandleMap.contains(value);
73 }
74
75 int getByValue(T value)
76 {
77 ASSERT(m_valueToHandleMap.contains(value));
78 return m_valueToHandleMap.get(value);
79 }
80
81 T remove(int handle)
82 {
83 T value = m_handleToValueMap.take(handle);
84 m_valueToHandleMap.remove(value);
85 return value;
86 }
87
88 int removeByValue(T value)
89 {
90 int handle = m_valueToHandleMap.take(value);
91 m_handleToValueMap.remove(handle);
92 return handle;
93 }
94
95 void copyValues(Vector<T>& values)
96 {
97 copyKeysToVector(m_valueToHandleMap, values);
98 }
99
100 private:
101 int m_lastHandle;
102 HashMap<int, T> m_handleToValueMap;
103 HashMap<T, int> m_valueToHandleMap;
104 };
105
106 struct DartBreakpoint {
107 DartBreakpoint(intptr_t breakpointId, Dart_Isolate);
108
109 intptr_t m_breakpointId;
110 Dart_Isolate m_isolate;
111 };
112
113
114 struct DartBreakpointInfo {
115 DartBreakpointInfo(const String& scriptUrl, const ScriptBreakpoint&);
116 String m_scriptUrl;
117 ScriptBreakpoint m_scriptBreakpoint;
118 Vector<DartBreakpoint> m_breakpoints;
119 };
120
121 class DartPageDebug {
122 public:
123 DartPageDebug(Page*, size_t pageId);
124 ~DartPageDebug();
125
126 String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* a ctualLineNumber, int* actualColumnNumber, bool interstatementLocation);
127
128 void registerIsolate(Dart_Isolate);
129 void unregisterIsolate(Dart_Isolate);
130
131 intptr_t setBreakpointHelper(DartBreakpointInfo*, const String& breakpointId String, Dart_Isolate, Dart_Handle& exception);
132
133 void removeBreakpoint(const String& breakpointId);
134 void removeBreakpointHelper(DartBreakpointInfo*);
135 void clearBreakpointsForIsolate(Dart_Isolate);
136 void clearBreakpoints();
137 void isolateLoaded();
138 void addListener(ScriptDebugListener*);
139 void removeListener();
140 ScriptDebugListener* listener() { return m_listener; }
141 String getScriptId(const String& url);
142 String lookupBreakpointId(intptr_t dartBreakpointId);
143
144 Vector<Dart_Isolate> isolates();
145 bool containsIsolate(Dart_Isolate isolate) { return m_isolateMap.containsVal ue(isolate); }
146 Page* page() { return m_page; }
147 private:
148 void registerIsolateScripts(Dart_Isolate);
149 void dispatchDidParseSource(intptr_t libraryId, Dart_Handle scriptURL, Dart_ Isolate);
150
151 HandleMap<Dart_Isolate> m_isolateMap;
152
153 Page* m_page;
154 ScriptDebugListener* m_listener;
155 size_t m_pageId;
156 HashMap<String, String> m_idToScriptUrlMap;
157 HashMap<String, String> m_scriptUrlToIdMap;
158
159 typedef HashMap<String, DartBreakpointInfo* > BreakpointMap;
160 BreakpointMap m_breakpoints;
161 typedef HashMap<intptr_t, String> BreakpointIdMap;
162 BreakpointIdMap m_breakpointIdMap;
163 size_t m_nextBreakpointId;
164 size_t m_nextScriptId;
165 };
166
167 class DartScriptDebugServer : public ScriptDebugServerBase {
168 WTF_MAKE_NONCOPYABLE(DartScriptDebugServer);
169 public:
170 static DartScriptDebugServer& shared();
171
172 void addListener(ScriptDebugListener*, Page*);
173 void removeListener(ScriptDebugListener*, Page*);
174
175 void setClientMessageLoop(PageScriptDebugServer::ClientMessageLoop*);
176
177 virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint& , int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation);
178 virtual void removeBreakpoint(const String& breakpointId);
179 virtual void clearBreakpoints();
180 virtual void setBreakpointsActivated(bool);
181
182 virtual ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionsState();
183 virtual void setPauseOnExceptionsState(ScriptDebugServer::PauseOnExceptionsS tate);
184
185 virtual void setPauseOnNextStatement(bool);
186 virtual bool canBreakProgram();
187 virtual void breakProgram();
188 virtual void continueProgram();
189 virtual void stepIntoStatement();
190 virtual void stepOverStatement(const ActivationFrame&);
191 virtual void stepOutOfFunction(const ActivationFrame&);
192
193 virtual bool setScriptSource(const String& sourceID, const String& newConten t, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceErr or>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result);
194 virtual StackTrace currentCallFrames();
195 virtual StackTrace currentCallFramesForAsyncStack();
196
197 virtual bool isPaused();
198 virtual bool runningNestedMessageLoop() { return m_runningNestedMessageLoop; }
199
200 virtual void clearCompiledScripts();
201 virtual void setPreprocessorSource(const String&);
202 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou rceCode&);
203 virtual String preprocessEventListener(LocalFrame*, const String& source, co nst String& url, const String& functionName);
204 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re sult, bool* wasThrown, String* exceptionMessage);
205 virtual bool canPreprocess(LocalFrame*);
206
207 static void pausedEventHandler(Dart_IsolateId, intptr_t breakpointId, const Dart_CodeLocation&);
208 static void exceptionHandler(Dart_IsolateId, Dart_Handle, Dart_StackTrace);
209 void handleException(Dart_IsolateId, Dart_Handle, Dart_StackTrace);
210
211 static void isolateEventHandler(Dart_IsolateId, Dart_IsolateEvent kind);
212 void handleInterrupted(Dart_IsolateId);
213
214 void registerIsolate(Dart_Isolate, Page*);
215 void unregisterIsolate(Dart_Isolate, Page*);
216 void isolateLoaded();
217
218 bool resolveCodeLocation(const Dart_CodeLocation&, int* line, int* column);
219
220 String getScriptId(const String& url, Dart_Isolate);
221
222 ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionState() { return m _pauseOnExceptionState; }
223 protected:
224 explicit DartScriptDebugServer();
225 virtual ~DartScriptDebugServer();
226
227 DartPageDebug* lookupPageDebugForId(const String& id);
228 DartPageDebug* lookupPageDebug(Page*);
229 DartPageDebug* lookupPageDebugForCurrentIsolate();
230 void runMessageLoopOnPause(Dart_Isolate);
231 void quitMessageLoopOnPause();
232 bool executeSkipPauseRequest(ScriptDebugListener::SkipPauseRequest, Dart_Sta ckTrace);
233 void handleProgramBreak(Dart_Isolate, Dart_StackTrace, intptr_t dartBreakpoi ntId, Dart_Handle exception, const Dart_CodeLocation&);
234 void handleDartDebugEvent(Dart_IsolateId, intptr_t breakpointId, Dart_Handle exception, const Dart_CodeLocation&);
235
236 void debugBreak();
237 void cancelDebugBreak();
238 Page* inferPage(Dart_Isolate);
239
240 Vector<Dart_Isolate> isolates();
241 Vector<DartPageDebug*> pages();
242
243 ScriptDebugServer::PauseOnExceptionsState m_pauseOnExceptionState;
244 bool m_breakpointsActivated;
245 bool m_runningNestedMessageLoop;
246 Dart_StackTrace m_executionState;
247 Page* m_pausedPage;
248 HashSet<Dart_Isolate> m_interruptCalled;
249 HashSet<Dart_Isolate> m_interruptCancelled;
250
251 typedef HashMap<size_t, DartPageDebug*> DebugDataMap;
252 DebugDataMap m_pageIdToDebugDataMap;
253 typedef HashMap<Page*, size_t> PageToIdMap;
254 PageToIdMap m_pageToIdMap;
255
256 PageScriptDebugServer::ClientMessageLoop* m_clientMessageLoop;
257
258 size_t m_nextPageId;
259 };
260
261 // FIXMEDART: this is really UnifiedPageScriptDebugServer. For completeness
262 // add a separate UnifiedScriptDebugServer class that lacks methods to add and
263 // remove page listeners.
264 class UnifiedScriptDebugServer : public ScriptDebugServerBase {
265 WTF_MAKE_NONCOPYABLE(UnifiedScriptDebugServer);
266 public:
267 UnifiedScriptDebugServer(DartScriptDebugServer*, PageScriptDebugServer*);
268
269 static UnifiedScriptDebugServer& shared();
270
271 virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint& , int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation);
272 virtual void removeBreakpoint(const String& breakpointId);
273 virtual void clearBreakpoints();
274 virtual void setBreakpointsActivated(bool);
275
276 virtual ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionsState();
277 virtual void setPauseOnExceptionsState(ScriptDebugServer::PauseOnExceptionsS tate);
278
279 virtual void setPauseOnNextStatement(bool);
280 virtual bool canBreakProgram();
281 virtual void breakProgram();
282 virtual void continueProgram();
283 virtual void stepIntoStatement();
284 virtual void stepOverStatement(const ActivationFrame&);
285 virtual void stepOutOfFunction(const ActivationFrame&);
286
287 virtual bool setScriptSource(const String& sourceID, const String& newConten t, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceErr or>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result);
288 virtual StackTrace currentCallFrames();
289 virtual StackTrace currentCallFramesForAsyncStack();
290
291 virtual bool isPaused();
292 virtual bool runningNestedMessageLoop();
293
294 virtual void clearCompiledScripts();
295 virtual void setPreprocessorSource(const String&);
296
297 // FIXMEDART: this signature is v8 specific.
298 virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&);
299 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou rceCode&);
300 virtual String preprocessEventListener(LocalFrame*, const String& source, co nst String& url, const String& functionName);
301 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re sult, bool* wasThrown, String* exceptionMessage);
302
303 void addListener(ScriptDebugListener*, Page*);
304 void removeListener(ScriptDebugListener*, Page*);
305
306 DartScriptDebugServer& dart() { return *m_dart; }
307 PageScriptDebugServer& v8() { return *m_v8; }
308 private:
309
310 bool isDartSourceID(const String& sourceID);
311 bool isDartBreakpointId(const String& breakpointId);
312 DartScriptDebugServer* m_dart;
313 PageScriptDebugServer* m_v8;
314 };
315
316 }
317
318 #endif // DartScriptDebugServer_h
OLDNEW
« no previous file with comments | « Source/bindings/dart/DartInjectedScript.cpp ('k') | Source/bindings/dart/DartScriptDebugServer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698