Permalink
Browse files

Bug 309279 - JavaScript launcher goes crazy when the debug target te…

…rminates
  • Loading branch information...
mrennie
mrennie committed Apr 26, 2010
1 parent 74d1d51 commit 2662d33ccf8aa6aaf326bd71c3b8e4abf54409bd
@@ -14,11 +14,13 @@
import java.util.HashMap;
import java.util.Iterator;
+import org.eclipse.debug.core.DebugException;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.Event;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventQueue;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventSet;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequest;
+import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
/**
* Event dispatcher that notifies registered model elements
@@ -87,9 +89,18 @@ public void run() {
EventQueue queue = vm.eventQueue();
EventSet eventset = null;
while (!shutdown) {
- eventset = queue.remove();
- if (eventset != null) {
- dispatch(eventset);
+ try {
+ eventset = queue.remove();
+ if (eventset != null) {
+ dispatch(eventset);
+ }
+ }
+ catch(RuntimeException rte) {
+ try {
+ this.target.terminate();
+ } catch (DebugException e) {
+ JavaScriptDebugPlugin.log(e);
+ }
}
}
}
@@ -544,9 +544,7 @@ public void resume() throws DebugException {
}
}
this.suspended = false;
- if (this.vm != null) {
- this.vm.resume();
- }
+ resumeVM(false);
fireResumeEvent(DebugEvent.CLIENT_REQUEST);
}
@@ -604,11 +602,11 @@ public void disconnect() throws DebugException {
try {
// first resume the VM, do not leave it in a suspended state
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304574
- if(this.vm != null) {
- this.vm.resume();
- this.vm.dispose();
- }
- } finally {
+ resumeVM(true);
+ }
+ catch(RuntimeException rte) {}
+ finally {
+ disposeVM(true);
cleanup();
this.disconnected = true;
fireTerminateEvent();
@@ -634,22 +632,58 @@ public void terminate() throws DebugException {
try {
// first resume the VM, do not leave it in a suspended state
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304574
- if (this.vm != null) {
- this.vm.resume();
- this.vm.dispose();
- }
+ resumeVM(true);
// next terminate the underlying process
if (this.process != null) {
this.process.terminate();
}
this.terminated = true;
} finally {
+ disposeVM(true);
cleanup();
this.terminating = false;
fireTerminateEvent();
}
}
+ /**
+ * disposes the underlying {@link VirtualMachine}
+ *
+ * @param shutdown
+ * @throws DebugException
+ */
+ void disposeVM(boolean shutdown) throws DebugException {
+ if(this.vm != null) {
+ try {
+ this.vm.dispose();
+ }
+ catch(RuntimeException rte) {
+ if(!shutdown) {
+ disconnect();
+ }
+ }
+ }
+ }
+
+ /**
+ * resumes the underlying {@link VirtualMachine}
+ *
+ * @param shutdown if the method is being called during a terminating call
+ * @throws DebugException
+ */
+ void resumeVM(boolean shutdown) throws DebugException {
+ if(this.vm != null) {
+ try {
+ this.vm.resume();
+ }
+ catch(RuntimeException rte) {
+ if(!shutdown) {
+ disconnect();
+ }
+ }
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -70,7 +70,7 @@
public void step(int kind, int detail) {
if (canResume()) {
request = createStepRequest(this, kind);
- thread.resume();
+ resumeUnderlyingThread();
pendingstep = this;
clearFrames();
clearBreakpoints();
@@ -99,7 +99,7 @@ StepRequest createStepRequest(IJavaScriptEventListener listener, int step) {
void abort() {
try {
deleteRequest(this, request);
- thread.resume();
+ resumeUnderlyingThread();
fireResumeEvent(DebugEvent.CLIENT_REQUEST);
}
finally {
@@ -401,7 +401,7 @@ public synchronized void targetResume() {
void resume(boolean fireevent) {
if (canResume()) {
abortPendingStep();
- this.thread.resume();
+ resumeUnderlyingThread();
markResumed();
if (fireevent) {
fireResumeEvent(DebugEvent.CLIENT_REQUEST);
@@ -430,6 +430,24 @@ public synchronized void suspend() throws DebugException {
}
}
+ /**
+ * Resumes the underlying thread
+ */
+ void resumeUnderlyingThread() {
+ if(canResume()) {
+ try {
+ this.thread.resume();
+ }
+ catch(Exception e) {
+ try {
+ disconnect();
+ } catch (DebugException de) {
+ /*JavaScriptDebugPlugin.log(de);*/
+ }
+ }
+ }
+ }
+
/**
* Delegate method to suspend the underlying thread
*/
@@ -663,7 +681,7 @@ public boolean canStepInto() {
* otherwise
*/
boolean atScriptLoadBreakpoint() {
- if(this.breakpoints != null && this.breakpoints.size() > 1) {
+ if(this.breakpoints != null && this.breakpoints.size() > 0) {
return this.breakpoints.get(0) instanceof IJavaScriptLoadBreakpoint;
}
return false;
@@ -32,10 +32,31 @@ public MirrorImpl(VirtualMachineImpl vm) {
this.vm = vm;
}
+ /**
+ * This constructor is only to be used by {@link VirtualMachineImpl}. The name
+ * field is not store anywhere or used in any way.
+ *
+ * @param name
+ * @noreference This constructor is not intended to be referenced by clients.
+ */
+ public MirrorImpl(String name) {
+ vm = (VirtualMachineImpl)this;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.Mirror#virtualMachine()
*/
public VirtualMachine virtualMachine() {
return this.vm;
}
+
+ /**
+ * Re-throws the given exception as a {@link RuntimeException} with the given message
+ * @param message
+ * @param t
+ * @since 1.1
+ */
+ protected void handleException(String message, Throwable t) {
+ throw new RuntimeException(message, t);
+ }
}
@@ -20,6 +20,7 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.StackFrame;
import org.eclipse.wst.jsdt.debug.core.jsdi.Value;
import org.eclipse.wst.jsdt.debug.core.jsdi.Variable;
+import org.eclipse.wst.jsdt.debug.internal.rhino.RhinoDebugPlugin;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.DisconnectedException;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.JSONConstants;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.Request;
@@ -83,9 +84,9 @@ public Value evaluate(String expression) {
Response response = vm.sendRequest(request, 30000);
return createValue(response.getBody(), true);
} catch (DisconnectedException e) {
- e.printStackTrace();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
- e.printStackTrace();
+ RhinoDebugPlugin.log(e);
}
return null;
}
@@ -110,9 +111,9 @@ public Value lookupValue(Number ref) {
this.cache.put(ref, value);
return value;
} catch (DisconnectedException e) {
- e.printStackTrace();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
- e.printStackTrace();
+ RhinoDebugPlugin.log(e);
}
}
return value;
@@ -209,9 +210,9 @@ private void initializeVariables() {
variables.add(variable);
}
} catch (DisconnectedException e) {
- e.printStackTrace();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
- e.printStackTrace();
+ RhinoDebugPlugin.log(e);
}
}
@@ -98,7 +98,7 @@ public synchronized List frames() {
frames.add(frame);
}
} catch (DisconnectedException e) {
- RhinoDebugPlugin.log(e);
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -124,7 +124,7 @@ private StackFrameImpl createStackFrame(Long frameId) {
Map jsonFrame = (Map) response.getBody().get(JSONConstants.FRAME);
return new StackFrameImpl(vm, jsonFrame);
} catch (DisconnectedException e) {
- RhinoDebugPlugin.log(e);
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -183,7 +183,7 @@ public synchronized void resume() {
atBreakpoint = false;
}
} catch (DisconnectedException e) {
- RhinoDebugPlugin.log(e);
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -204,7 +204,7 @@ public void suspend() {
markSuspended(false);
}
} catch (DisconnectedException e) {
- RhinoDebugPlugin.log(e);
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -41,7 +41,7 @@
*
* @since 1.0
*/
-public class VirtualMachineImpl implements VirtualMachine {
+public class VirtualMachineImpl extends MirrorImpl implements VirtualMachine {
public final UndefinedValueImpl undefinedValue = new UndefinedValueImpl(this);
public final NullValueImpl nullValue = new NullValueImpl(this);
@@ -59,6 +59,7 @@
* @param debugSession
*/
public VirtualMachineImpl(DebugSession debugSession) {
+ super(Constants.SPACE);
this.session = debugSession;
initalizeScripts();
}
@@ -80,6 +81,7 @@ private void initalizeScripts() {
}
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -99,6 +101,7 @@ private ScriptReferenceImpl createScriptReference(Long scriptId) {
return new ScriptReferenceImpl(this, jsonScript);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -197,6 +200,7 @@ public synchronized List allThreads() {
threads = allThreads;
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -229,6 +233,7 @@ private ThreadReferenceImpl createThreadReference(Long threadId) {
return new ThreadReferenceImpl(this, jsonThread);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -267,6 +272,7 @@ public String description() {
return buffer.toString();
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -282,6 +288,7 @@ public void dispose() {
sendRequest(request);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
} finally {
@@ -300,6 +307,7 @@ public String name() {
return (String) response.getBody().get(JSONConstants.VM_NAME);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -315,6 +323,7 @@ public void resume() {
sendRequest(request);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -329,6 +338,7 @@ public void suspend() {
sendRequest(request);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
@@ -351,6 +361,7 @@ public String version() {
return (String) response.getBody().get(JSONConstants.VM_VERSION);
} catch (DisconnectedException e) {
disconnectVM();
+ handleException(e.getMessage(), e);
} catch (TimeoutException e) {
RhinoDebugPlugin.log(e);
}
Oops, something went wrong.

0 comments on commit 2662d33

Please sign in to comment.