Little improvements

This commit is contained in:
konsoletyper 2014-08-01 20:03:40 +04:00
parent c490e2f9f8
commit 97531523e6
2 changed files with 50 additions and 24 deletions

View File

@ -1,7 +1,8 @@
package org.teavm.eclipse.debugger; package org.teavm.eclipse.debugger;
import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.Map; import java.util.concurrent.ConcurrentMap;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta; import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugEvent;
@ -26,13 +27,13 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
Debugger teavmDebugger; Debugger teavmDebugger;
JavaScriptDebugger jsDebugger; JavaScriptDebugger jsDebugger;
private ChromeRDPServer server; private ChromeRDPServer server;
private boolean terminated; private volatile boolean terminated;
private TeaVMDebugProcess process; private TeaVMDebugProcess process;
private TeaVMThread thread; private TeaVMThread thread;
Map<IBreakpoint, Breakpoint> breakpointMap = new HashMap<>(); ConcurrentMap<IBreakpoint, Breakpoint> breakpointMap = new ConcurrentHashMap<>();
Map<Breakpoint, IBreakpoint> breakpointBackMap = new HashMap<>(); ConcurrentMap<Breakpoint, IBreakpoint> breakpointBackMap = new ConcurrentHashMap<>();
public TeaVMDebugTarget(ILaunch launch, Debugger teavmDebugger, ChromeRDPServer server) { public TeaVMDebugTarget(ILaunch launch, final Debugger teavmDebugger, ChromeRDPServer server) {
this.launch = launch; this.launch = launch;
this.teavmDebugger = teavmDebugger; this.teavmDebugger = teavmDebugger;
this.server = server; this.server = server;
@ -56,23 +57,45 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
@Override @Override
public void detached() { public void detached() {
fireEvent(new DebugEvent(TeaVMDebugTarget.this, DebugEvent.CHANGE)); fireEvent(new DebugEvent(TeaVMDebugTarget.this, DebugEvent.CHANGE));
for (Breakpoint teavmBreakpoint : teavmDebugger.getBreakpoints()) {
updateBreakpoint(teavmBreakpoint);
}
} }
@Override @Override
public void breakpointStatusChanged(Breakpoint teavmBreakpoint) { public void breakpointStatusChanged(Breakpoint teavmBreakpoint) {
IBreakpoint breakpoint = breakpointBackMap.get(teavmBreakpoint); updateBreakpoint(teavmBreakpoint);
if (breakpoint != null) {
fireEvent(new DebugEvent(breakpoint, DebugEvent.CHANGE));
}
} }
@Override @Override
public void attached() { public void attached() {
fireEvent(new DebugEvent(TeaVMDebugTarget.this, DebugEvent.CHANGE)); fireEvent(new DebugEvent(TeaVMDebugTarget.this, DebugEvent.CHANGE));
for (Breakpoint teavmBreakpoint : teavmDebugger.getBreakpoints()) {
updateBreakpoint(teavmBreakpoint);
}
} }
}); });
} }
private void updateBreakpoint(Breakpoint teavmBreakpoint) {
IBreakpoint breakpoint = breakpointBackMap.get(teavmBreakpoint);
if (breakpoint != null) {
try {
if (!teavmBreakpoint.isValid() && teavmDebugger.isAttached()) {
breakpoint.getMarker().setAttribute(IMarker.PROBLEM,
"Can't transfer this breakpoint to browser");
breakpoint.getMarker().setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
} else {
breakpoint.getMarker().setAttribute(IMarker.PROBLEM, null);
breakpoint.getMarker().setAttribute(IMarker.SEVERITY, null);
}
} catch (CoreException e) {
throw new RuntimeException(e);
}
fireEvent(new DebugEvent(breakpoint, DebugEvent.CHANGE));
}
}
private void fireEvent(DebugEvent event) { private void fireEvent(DebugEvent event) {
DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { event }); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { event });
} }
@ -91,8 +114,13 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
public void terminate() throws DebugException { public void terminate() throws DebugException {
terminated = true; terminated = true;
server.stop(); server.stop();
fireEvent(new DebugEvent(this, DebugEvent.RESUME));
fireEvent(new DebugEvent(thread, DebugEvent.RESUME));
fireEvent(new DebugEvent(process, DebugEvent.RESUME));
fireEvent(new DebugEvent(this, DebugEvent.TERMINATE)); fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
fireEvent(new DebugEvent(thread, DebugEvent.TERMINATE)); fireEvent(new DebugEvent(thread, DebugEvent.TERMINATE));
fireEvent(new DebugEvent(process, DebugEvent.TERMINATE));
launch.removeProcess(process);
} }
@Override @Override
@ -103,16 +131,11 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
@Override @Override
public void breakpointAdded(IBreakpoint breakpoint) { public void breakpointAdded(IBreakpoint breakpoint) {
try { try {
if (breakpoint instanceof IJavaLineBreakpoint) {
IJavaLineBreakpoint lineBreakpoint = (IJavaLineBreakpoint)breakpoint; IJavaLineBreakpoint lineBreakpoint = (IJavaLineBreakpoint)breakpoint;
String fileName = lineBreakpoint.getTypeName().replace('.', '/') + ".java"; String fileName = lineBreakpoint.getTypeName().replace('.', '/') + ".java";
Breakpoint teavmBreakpoint = teavmDebugger.createBreakpoint(fileName, lineBreakpoint.getLineNumber()); Breakpoint teavmBreakpoint = teavmDebugger.createBreakpoint(fileName, lineBreakpoint.getLineNumber());
breakpointMap.put(lineBreakpoint, teavmBreakpoint); breakpointMap.put(lineBreakpoint, teavmBreakpoint);
breakpointBackMap.put(teavmBreakpoint, lineBreakpoint); breakpointBackMap.put(teavmBreakpoint, lineBreakpoint);
breakpoint.setRegistered(true);
} else {
breakpoint.setRegistered(false);
}
} catch (CoreException e) { } catch (CoreException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -145,7 +168,7 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return teavmDebugger.isSuspended(); return teavmDebugger.isSuspended() && !terminated;
} }
@Override @Override

View File

@ -20,7 +20,7 @@ import org.teavm.debugging.DebuggerListener;
public class TeaVMThread implements IThread { public class TeaVMThread implements IThread {
private Debugger teavmDebugger; private Debugger teavmDebugger;
private TeaVMDebugTarget debugTarget; private TeaVMDebugTarget debugTarget;
private TeaVMStackFrame[] stackTrace; private volatile TeaVMStackFrame[] stackTrace;
public TeaVMThread(TeaVMDebugTarget debugTarget) { public TeaVMThread(TeaVMDebugTarget debugTarget) {
this.debugTarget = debugTarget; this.debugTarget = debugTarget;
@ -54,14 +54,15 @@ public class TeaVMThread implements IThread {
private void updateStackTrace() { private void updateStackTrace() {
if (teavmDebugger.getCallStack() == null) { if (teavmDebugger.getCallStack() == null) {
stackTrace = null; this.stackTrace = null;
} else { } else {
CallFrame[] teavmCallStack = teavmDebugger.getCallStack(); CallFrame[] teavmCallStack = teavmDebugger.getCallStack();
stackTrace = new TeaVMStackFrame[teavmCallStack.length]; TeaVMStackFrame[] stackTrace = new TeaVMStackFrame[teavmCallStack.length];
for (int i = 0; i < teavmCallStack.length; ++i) { for (int i = 0; i < teavmCallStack.length; ++i) {
CallFrame teavmFrame = teavmCallStack[i]; CallFrame teavmFrame = teavmCallStack[i];
stackTrace[i] = new TeaVMStackFrame(this, teavmFrame); stackTrace[i] = new TeaVMStackFrame(this, teavmFrame);
} }
this.stackTrace = stackTrace;
} }
fireEvent(new DebugEvent(this, DebugEvent.CHANGE)); fireEvent(new DebugEvent(this, DebugEvent.CHANGE));
} }
@ -183,11 +184,13 @@ public class TeaVMThread implements IThread {
@Override @Override
public IStackFrame[] getStackFrames() throws DebugException { public IStackFrame[] getStackFrames() throws DebugException {
TeaVMStackFrame[] stackTrace = this.stackTrace;
return stackTrace != null ? stackTrace.clone() : new IStackFrame[0]; return stackTrace != null ? stackTrace.clone() : new IStackFrame[0];
} }
@Override @Override
public IStackFrame getTopStackFrame() { public IStackFrame getTopStackFrame() {
TeaVMStackFrame[] stackTrace = this.stackTrace;
return stackTrace != null && stackTrace.length > 0 ? stackTrace[0] : null; return stackTrace != null && stackTrace.length > 0 ? stackTrace[0] : null;
} }