author | Eugene Ostroukhov <eugeneo@symbian.org> |
Tue, 02 Mar 2010 14:35:28 -0800 | |
changeset 214 | 3a649437adec |
parent 115 | d367ed1b2991 |
child 276 | f2f4a1259de8 |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.debug.core.model; |
|
6 |
||
214
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
7 |
import java.util.List; |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
8 |
|
2 | 9 |
import org.chromium.debug.core.ChromiumDebugPlugin; |
10 |
import org.chromium.sdk.CallFrame; |
|
11 |
import org.chromium.sdk.DebugContext; |
|
12 |
import org.chromium.sdk.DebugEventListener; |
|
13 |
import org.chromium.sdk.ExceptionData; |
|
14 |
import org.chromium.sdk.JavascriptVm; |
|
15 |
import org.chromium.sdk.Script; |
|
16 |
import org.chromium.sdk.DebugContext.State; |
|
17 |
import org.chromium.sdk.DebugContext.StepAction; |
|
18 |
import org.eclipse.core.resources.IFile; |
|
19 |
import org.eclipse.core.resources.IMarkerDelta; |
|
20 |
import org.eclipse.core.runtime.CoreException; |
|
21 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
22 |
import org.eclipse.core.runtime.IStatus; |
|
23 |
import org.eclipse.core.runtime.Status; |
|
24 |
import org.eclipse.core.runtime.jobs.Job; |
|
25 |
import org.eclipse.debug.core.DebugEvent; |
|
26 |
import org.eclipse.debug.core.DebugException; |
|
27 |
import org.eclipse.debug.core.DebugPlugin; |
|
28 |
import org.eclipse.debug.core.ILaunch; |
|
29 |
import org.eclipse.debug.core.ILaunchListener; |
|
30 |
import org.eclipse.debug.core.model.IBreakpoint; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
31 |
import org.eclipse.debug.core.model.IDebugTarget; |
2 | 32 |
import org.eclipse.debug.core.model.IMemoryBlock; |
33 |
import org.eclipse.debug.core.model.IProcess; |
|
34 |
import org.eclipse.debug.core.model.IThread; |
|
35 |
||
36 |
/** |
|
37 |
* An IDebugTarget implementation for remote JavaScript debugging. |
|
38 |
* Can debug any target that supports the ChromeDevTools protocol. |
|
39 |
*/ |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
40 |
public class DebugTargetImpl extends DebugElementImpl implements IDebugTarget { |
2 | 41 |
|
42 |
private static final IThread[] EMPTY_THREADS = new IThread[0]; |
|
43 |
||
44 |
private final ILaunch launch; |
|
45 |
||
46 |
private final JavascriptThread[] threads; |
|
47 |
||
48 |
private JavascriptVmEmbedder vmEmbedder = STUB_VM_EMBEDDER; |
|
49 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
50 |
private volatile DebugContext debugContext; |
2 | 51 |
|
52 |
private boolean isSuspended = false; |
|
53 |
||
54 |
private boolean isDisconnected = false; |
|
55 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
56 |
private final WorkspaceBridge.Factory workspaceBridgeFactory; |
2 | 57 |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
58 |
private WorkspaceBridge workspaceRelations = null; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
59 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
60 |
private final ListenerBlock listenerBlock = new ListenerBlock(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
61 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
62 |
public DebugTargetImpl(ILaunch launch, WorkspaceBridge.Factory workspaceBridgeFactory) { |
2 | 63 |
super(null); |
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
64 |
this.workspaceBridgeFactory = workspaceBridgeFactory; |
2 | 65 |
this.launch = launch; |
66 |
this.threads = new JavascriptThread[] { new JavascriptThread(this) }; |
|
67 |
} |
|
68 |
||
69 |
||
70 |
/** |
|
71 |
* Loads browser tabs, consults the {@code selector} which of the tabs to |
|
72 |
* attach to, and if any has been selected, requests an attachment to the tab. |
|
73 |
* |
|
74 |
* @param remoteServer embedding application we are connected with |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
75 |
* @param attachCallback to invoke on successful attachment, can fail to be called |
2 | 76 |
* @param monitor to report the progress to |
77 |
* @return whether the target has attached to a tab |
|
78 |
* @throws CoreException |
|
79 |
*/ |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
80 |
public boolean attach(JavascriptVmEmbedder.ConnectionToRemote remoteServer, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
81 |
DestructingGuard destructingGuard, Runnable attachCallback, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
82 |
IProgressMonitor monitor) throws CoreException { |
2 | 83 |
monitor.beginTask("", 2); //$NON-NLS-1$ |
84 |
JavascriptVmEmbedder.VmConnector connector = remoteServer.selectVm(); |
|
85 |
if (connector == null) { |
|
86 |
return false; |
|
87 |
} |
|
88 |
monitor.worked(1); |
|
89 |
final JavascriptVmEmbedder embedder = connector.attach(embedderListener, debugEventListener); |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
90 |
// From this moment V8 may call our listeners. We block them by listenerBlock for a while. |
2 | 91 |
|
92 |
Destructable embedderDestructor = new Destructable() { |
|
93 |
public void destruct() { |
|
94 |
embedder.getJavascriptVm().detach(); |
|
95 |
} |
|
96 |
}; |
|
97 |
||
98 |
destructingGuard.addValue(embedderDestructor); |
|
99 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
100 |
this.vmEmbedder = embedder; |
2 | 101 |
|
102 |
// We'd like to know when launch is removed to remove our project. |
|
103 |
DebugPlugin.getDefault().getLaunchManager().addLaunchListener(launchListener); |
|
104 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
105 |
this.workspaceRelations = workspaceBridgeFactory.attachedToVm(this, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
106 |
vmEmbedder.getJavascriptVm()); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
107 |
listenerBlock.unblock(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
108 |
|
2 | 109 |
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); |
110 |
reloadScriptsAndPossiblyResume(attachCallback); |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
111 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
112 |
return true; |
2 | 113 |
} |
114 |
||
115 |
private void reloadScriptsAndPossiblyResume(final Runnable attachCallback) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
116 |
workspaceRelations.reloadScriptsAtStart(); |
2 | 117 |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
118 |
try { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
119 |
if (attachCallback != null) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
120 |
attachCallback.run(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
121 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
122 |
} finally { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
123 |
fireCreationEvent(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
124 |
} |
2 | 125 |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
126 |
Job job = new Job("Update debugger state") { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
127 |
@Override |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
128 |
protected IStatus run(IProgressMonitor monitor) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
129 |
debugEventListener.resumedByDefault(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
130 |
return Status.OK_STATUS; |
2 | 131 |
} |
132 |
}; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
133 |
job.schedule(); |
2 | 134 |
} |
135 |
||
136 |
public String getName() throws DebugException { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
137 |
return workspaceBridgeFactory.getLabelProvider().getTargetLabel(this); |
2 | 138 |
} |
139 |
||
140 |
public IProcess getProcess() { |
|
141 |
return null; |
|
142 |
} |
|
143 |
||
144 |
public JavascriptVmEmbedder getJavascriptEmbedder() { |
|
145 |
return vmEmbedder; |
|
146 |
} |
|
147 |
||
148 |
public IThread[] getThreads() throws DebugException { |
|
149 |
return isDisconnected() |
|
150 |
? EMPTY_THREADS |
|
151 |
: threads; |
|
152 |
} |
|
153 |
||
154 |
public boolean hasThreads() throws DebugException { |
|
155 |
return getThreads().length > 0; |
|
156 |
} |
|
157 |
||
158 |
public boolean supportsBreakpoint(IBreakpoint breakpoint) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
159 |
return workspaceRelations.getBreakpointHandler().supportsBreakpoint(breakpoint); |
2 | 160 |
} |
161 |
||
162 |
@Override |
|
163 |
public DebugTargetImpl getDebugTarget() { |
|
164 |
return this; |
|
165 |
} |
|
166 |
||
167 |
@Override |
|
168 |
public ILaunch getLaunch() { |
|
169 |
return launch; |
|
170 |
} |
|
171 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
172 |
public String getChromiumModelIdentifier() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
173 |
return workspaceBridgeFactory.getDebugModelIdentifier(); |
2 | 174 |
} |
175 |
||
176 |
public boolean canTerminate() { |
|
177 |
return !isTerminated(); |
|
178 |
} |
|
179 |
||
180 |
public boolean isTerminated() { |
|
181 |
return isDisconnected(); |
|
182 |
} |
|
183 |
||
184 |
public void terminate() throws DebugException { |
|
185 |
disconnect(); |
|
186 |
} |
|
187 |
||
188 |
public boolean canResume() { |
|
189 |
return !isDisconnected() && isSuspended(); |
|
190 |
} |
|
191 |
||
192 |
public synchronized boolean isSuspended() { |
|
193 |
return isSuspended; |
|
194 |
} |
|
195 |
||
196 |
private synchronized void setSuspended(boolean isSuspended) { |
|
197 |
this.isSuspended = isSuspended; |
|
198 |
} |
|
199 |
||
200 |
public void suspended(int detail) { |
|
201 |
setSuspended(true); |
|
202 |
getThread().reset(); |
|
203 |
fireSuspendEvent(detail); |
|
204 |
} |
|
205 |
||
206 |
public void resume() throws DebugException { |
|
207 |
debugContext.continueVm(StepAction.CONTINUE, 1, null); |
|
208 |
// Let's pretend Chromium does respond to the "continue" request immediately |
|
209 |
resumed(DebugEvent.CLIENT_REQUEST); |
|
210 |
} |
|
211 |
||
212 |
public void resumed(int detail) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
213 |
debugContext = null; |
2 | 214 |
fireResumeEvent(detail); |
215 |
} |
|
216 |
||
217 |
public boolean canSuspend() { |
|
218 |
return !isDisconnected() && !isSuspended(); |
|
219 |
} |
|
220 |
||
221 |
public void suspend() throws DebugException { |
|
222 |
vmEmbedder.getJavascriptVm().suspend(null); |
|
223 |
} |
|
224 |
||
225 |
public boolean canDisconnect() { |
|
226 |
return !isDisconnected(); |
|
227 |
} |
|
228 |
||
229 |
public void disconnect() throws DebugException { |
|
230 |
if (!canDisconnect()) { |
|
231 |
return; |
|
232 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
233 |
workspaceRelations.beforeDetach(); |
2 | 234 |
if (!vmEmbedder.getJavascriptVm().detach()) { |
235 |
ChromiumDebugPlugin.logWarning(Messages.DebugTargetImpl_BadResultWhileDisconnecting); |
|
236 |
} |
|
237 |
// This is a duplicated call to disconnected(). |
|
238 |
// The primary one comes from V8DebuggerToolHandler#onDebuggerDetached |
|
239 |
// but we want to make sure the target becomes disconnected even if |
|
240 |
// there is a browser failure and it does not respond. |
|
241 |
debugEventListener.disconnected(); |
|
242 |
} |
|
243 |
||
244 |
public synchronized boolean isDisconnected() { |
|
245 |
return isDisconnected; |
|
246 |
} |
|
247 |
||
248 |
public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException { |
|
249 |
return null; |
|
250 |
} |
|
251 |
||
252 |
public boolean supportsStorageRetrieval() { |
|
253 |
return false; |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Fires a debug event |
|
258 |
* |
|
259 |
* @param event to be fired |
|
260 |
*/ |
|
261 |
public void fireEvent(DebugEvent event) { |
|
262 |
DebugPlugin debugPlugin = DebugPlugin.getDefault(); |
|
263 |
if (debugPlugin != null) { |
|
264 |
debugPlugin.fireDebugEventSet(new DebugEvent[] { event }); |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
public void fireEventForThread(int kind, int detail) { |
|
269 |
try { |
|
270 |
IThread[] threads = getThreads(); |
|
271 |
if (threads.length > 0) { |
|
272 |
fireEvent(new DebugEvent(threads[0], kind, detail)); |
|
273 |
} |
|
274 |
} catch (DebugException e) { |
|
275 |
// Actually, this is not thrown in our getThreads() |
|
276 |
return; |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
public void fireCreationEvent() { |
|
281 |
setDisconnected(false); |
|
282 |
fireEventForThread(DebugEvent.CREATE, DebugEvent.UNSPECIFIED); |
|
283 |
} |
|
284 |
||
285 |
public synchronized void setDisconnected(boolean disconnected) { |
|
286 |
isDisconnected = disconnected; |
|
287 |
} |
|
288 |
||
289 |
public void fireResumeEvent(int detail) { |
|
290 |
setSuspended(false); |
|
291 |
fireEventForThread(DebugEvent.RESUME, detail); |
|
292 |
fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail)); |
|
293 |
} |
|
294 |
||
295 |
public void fireSuspendEvent(int detail) { |
|
296 |
setSuspended(true); |
|
297 |
fireEventForThread(DebugEvent.SUSPEND, detail); |
|
298 |
fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail)); |
|
299 |
} |
|
300 |
||
301 |
public void fireTerminateEvent() { |
|
302 |
// TODO(peter.rybin): from Alexander Pavlov: I think you need to fire a terminate event after |
|
303 |
// this line, for consolePseudoProcess if one is not null. |
|
304 |
fireEventForThread(DebugEvent.TERMINATE, DebugEvent.UNSPECIFIED); |
|
305 |
fireEvent(new DebugEvent(this, DebugEvent.TERMINATE, DebugEvent.UNSPECIFIED)); |
|
306 |
fireEvent(new DebugEvent(getLaunch(), DebugEvent.TERMINATE, DebugEvent.UNSPECIFIED)); |
|
307 |
} |
|
308 |
||
309 |
public void breakpointAdded(IBreakpoint breakpoint) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
310 |
workspaceRelations.getBreakpointHandler().breakpointAdded(breakpoint); |
2 | 311 |
} |
312 |
||
313 |
public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
314 |
workspaceRelations.getBreakpointHandler().breakpointChanged(breakpoint, delta); |
2 | 315 |
} |
316 |
||
317 |
public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
318 |
workspaceRelations.getBreakpointHandler().breakpointRemoved(breakpoint, delta); |
2 | 319 |
} |
320 |
||
321 |
@SuppressWarnings("unchecked") |
|
322 |
@Override |
|
323 |
public Object getAdapter(Class adapter) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
324 |
if (adapter == EvaluateContext.class) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
325 |
JavascriptThread thread = getThread(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
326 |
if (thread == null) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
327 |
return null; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
328 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
329 |
return thread.getAdapter(adapter); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
330 |
} else if (adapter == ILaunch.class) { |
2 | 331 |
return this.launch; |
332 |
} |
|
333 |
return super.getAdapter(adapter); |
|
334 |
} |
|
335 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
336 |
public IFile getScriptResource(Script script) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
337 |
return workspaceRelations.getScriptResource(script); |
2 | 338 |
} |
339 |
||
340 |
public JavascriptThread getThread() { |
|
341 |
return isDisconnected() |
|
342 |
? null |
|
343 |
: threads[0]; |
|
344 |
} |
|
345 |
||
346 |
private static String trim(String text, int maxLength) { |
|
347 |
if (text == null || text.length() <= maxLength) { |
|
348 |
return text; |
|
349 |
} |
|
350 |
return text.substring(0, maxLength - 3) + "..."; //$NON-NLS-1$ |
|
351 |
} |
|
352 |
||
353 |
public DebugContext getDebugContext() { |
|
354 |
return debugContext; |
|
355 |
} |
|
356 |
||
357 |
private final DebugEventListenerImpl debugEventListener = new DebugEventListenerImpl(); |
|
358 |
||
359 |
class DebugEventListenerImpl implements DebugEventListener { |
|
360 |
// Synchronizes calls from ReaderThread of Connection and one call from some worker thread |
|
361 |
private final Object suspendResumeMonitor = new Object(); |
|
362 |
private boolean alreadyResumedOrSuspended = false; |
|
363 |
||
364 |
public void disconnected() { |
|
365 |
if (!isDisconnected()) { |
|
366 |
setDisconnected(true); |
|
367 |
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( |
|
368 |
DebugTargetImpl.this); |
|
369 |
fireTerminateEvent(); |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
public void resumedByDefault() { |
|
374 |
synchronized (suspendResumeMonitor) { |
|
375 |
if (!alreadyResumedOrSuspended) { |
|
376 |
resumed(); |
|
377 |
} |
|
378 |
} |
|
379 |
} |
|
380 |
||
381 |
public void resumed() { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
382 |
listenerBlock.waitUntilReady(); |
2 | 383 |
synchronized (suspendResumeMonitor) { |
384 |
DebugTargetImpl.this.resumed(DebugEvent.CLIENT_REQUEST); |
|
385 |
alreadyResumedOrSuspended = true; |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
public void scriptLoaded(Script newScript) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
390 |
listenerBlock.waitUntilReady(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
391 |
workspaceRelations.scriptLoaded(newScript); |
2 | 392 |
} |
393 |
||
394 |
public void suspended(DebugContext context) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
395 |
listenerBlock.waitUntilReady(); |
2 | 396 |
synchronized (suspendResumeMonitor) { |
397 |
DebugTargetImpl.this.debugContext = context; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
398 |
workspaceRelations.getBreakpointHandler().breakpointsHit(context.getBreakpointsHit()); |
2 | 399 |
int suspendedDetail; |
400 |
if (context.getState() == State.EXCEPTION) { |
|
401 |
logExceptionFromContext(context); |
|
402 |
suspendedDetail = DebugEvent.BREAKPOINT; |
|
403 |
} else { |
|
404 |
if (context.getBreakpointsHit().isEmpty()) { |
|
405 |
suspendedDetail = DebugEvent.STEP_END; |
|
406 |
} else { |
|
407 |
suspendedDetail = DebugEvent.BREAKPOINT; |
|
408 |
} |
|
409 |
} |
|
410 |
DebugTargetImpl.this.suspended(suspendedDetail); |
|
411 |
||
412 |
alreadyResumedOrSuspended = true; |
|
413 |
} |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
private void logExceptionFromContext(DebugContext context) { |
|
418 |
ExceptionData exceptionData = context.getExceptionData(); |
|
214
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
419 |
List<? extends CallFrame> callFrames = context.getCallFrames(); |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
420 |
if (callFrames.size() > 0) { |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
421 |
CallFrame topFrame = callFrames.get(0); |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
422 |
Script script = topFrame.getScript(); |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
423 |
ChromiumDebugPlugin.logError( |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
424 |
Messages.DebugTargetImpl_LogExceptionFormat, |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
425 |
exceptionData.isUncaught() |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
426 |
? Messages.DebugTargetImpl_Uncaught |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
427 |
: Messages.DebugTargetImpl_Caught, |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
428 |
exceptionData.getExceptionMessage(), |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
429 |
script != null ? script.getName() : "<unknown>", //$NON-NLS-1$ |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
430 |
topFrame.getLineNumber(), |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
431 |
trim(exceptionData.getSourceText(), 80)); |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
432 |
} else { |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
433 |
ChromiumDebugPlugin.logError( |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
434 |
Messages.DebugTargetImpl_LogExceptionFormat, |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
435 |
exceptionData.isUncaught() |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
436 |
? Messages.DebugTargetImpl_Uncaught |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
437 |
: Messages.DebugTargetImpl_Caught, |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
438 |
exceptionData.getExceptionMessage(), |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
439 |
"<unknown>", //$NON-NLS-1$ |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
440 |
"<unknown>", |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
441 |
trim(exceptionData.getSourceText(), 80)); |
3a649437adec
Bug 2122 - Debugger hangs when debugging Wikipedia widget
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
115
diff
changeset
|
442 |
} |
2 | 443 |
} |
444 |
||
445 |
private final JavascriptVmEmbedder.Listener embedderListener = |
|
446 |
new JavascriptVmEmbedder.Listener() { |
|
447 |
public void reset() { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
448 |
listenerBlock.waitUntilReady(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
449 |
workspaceRelations.handleVmResetEvent(); |
2 | 450 |
fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.STATE)); |
451 |
} |
|
452 |
public void closed() { |
|
453 |
debugEventListener.disconnected(); |
|
454 |
} |
|
455 |
}; |
|
456 |
||
457 |
private final ILaunchListener launchListener = new ILaunchListener() { |
|
458 |
public void launchAdded(ILaunch launch) { |
|
459 |
} |
|
460 |
public void launchChanged(ILaunch launch) { |
|
461 |
} |
|
462 |
// TODO(peter.rybin): maybe have one instance of listener for all targets? |
|
463 |
public void launchRemoved(ILaunch launch) { |
|
464 |
if (launch != DebugTargetImpl.this.launch) { |
|
465 |
return; |
|
466 |
} |
|
467 |
DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
468 |
workspaceRelations.launchRemoved(); |
2 | 469 |
} |
470 |
}; |
|
471 |
||
472 |
private final static JavascriptVmEmbedder STUB_VM_EMBEDDER = new JavascriptVmEmbedder() { |
|
473 |
public JavascriptVm getJavascriptVm() { |
|
474 |
//TODO(peter.rybin): decide and redo this exception |
|
475 |
throw new UnsupportedOperationException(); |
|
476 |
} |
|
477 |
||
478 |
public String getTargetName() { |
|
479 |
//TODO(peter.rybin): decide and redo this exception |
|
480 |
throw new UnsupportedOperationException(); |
|
481 |
} |
|
482 |
||
483 |
public String getThreadName() { |
|
484 |
//TODO(peter.rybin): decide and redo this exception |
|
485 |
throw new UnsupportedOperationException(); |
|
486 |
} |
|
487 |
}; |
|
488 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
489 |
public WorkspaceBridge.JsLabelProvider getLabelProvider() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
490 |
return workspaceBridgeFactory.getLabelProvider(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
491 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
492 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
493 |
private static class ListenerBlock { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
494 |
private volatile boolean isBlocked = true; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
495 |
private final Object monitor = new Object(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
496 |
void waitUntilReady() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
497 |
if (isBlocked) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
498 |
return; |
2 | 499 |
} |
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
500 |
synchronized (monitor) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
501 |
while (isBlocked) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
502 |
try { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
503 |
monitor.wait(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
504 |
} catch (InterruptedException e) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
505 |
throw new RuntimeException(e); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
506 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
507 |
} |
2 | 508 |
} |
509 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
510 |
void unblock() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
511 |
isBlocked = true; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
512 |
synchronized (monitor) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
513 |
monitor.notifyAll(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
514 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
515 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
516 |
} |
115
d367ed1b2991
Bug 1665 (HTML Files Cannot be Debugged) was fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
517 |
|
d367ed1b2991
Bug 1665 (HTML Files Cannot be Debugged) was fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
518 |
public int getLineNumber(CallFrame stackFrame) { |
d367ed1b2991
Bug 1665 (HTML Files Cannot be Debugged) was fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
519 |
return workspaceRelations.getLineNumber(stackFrame); |
d367ed1b2991
Bug 1665 (HTML Files Cannot be Debugged) was fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
520 |
} |
2 | 521 |
} |