Fixes bug with stepping

This commit is contained in:
Alexey Andreev 2014-08-24 13:52:57 +04:00
parent 3bc8887e4f
commit 6272c3a79a
3 changed files with 32 additions and 33 deletions

View File

@ -63,11 +63,11 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
debugInformation = null; debugInformation = null;
int fileIndex = files.index(fileName); int fileIndex = files.index(fileName);
if (!Objects.equals(currentFileName, fileName)) { if (!Objects.equals(currentFileName, fileName)) {
fileMapping.add(locationProvider, fileIndex); fileMapping.add(locationProvider, fileIndex, true);
currentFileName = fileName; currentFileName = fileName;
} }
if (currentLine != line) { if (currentLine != line) {
lineMapping.add(locationProvider, line); lineMapping.add(locationProvider, line, true);
currentLine = line; currentLine = line;
} }
} }
@ -77,7 +77,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
debugInformation = null; debugInformation = null;
int classIndex = classes.index(className); int classIndex = classes.index(className);
if (!Objects.equals(className, currentClass)) { if (!Objects.equals(className, currentClass)) {
classMapping.add(locationProvider, classIndex); classMapping.add(locationProvider, classIndex, true);
currentClass = className; currentClass = className;
} }
} }
@ -87,7 +87,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
debugInformation = null; debugInformation = null;
int methodIndex = methods.index(method != null ? method.toString() : null); int methodIndex = methods.index(method != null ? method.toString() : null);
if (!Objects.equals(method, currentMethod)) { if (!Objects.equals(method, currentMethod)) {
methodMapping.add(locationProvider, methodIndex); methodMapping.add(locationProvider, methodIndex, true);
currentMethod = method; currentMethod = method;
} }
if (currentClass != null) { if (currentClass != null) {
@ -133,13 +133,13 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
callSiteMapping.values.set(index, exactMethodIndex); callSiteMapping.values.set(index, exactMethodIndex);
} }
}; };
callSiteMapping.add(locationProvider, -1); callSiteMapping.add(locationProvider, -1, false);
return callSite; return callSite;
} }
@Override @Override
public void emitEmptyCallSite() { public void emitEmptyCallSite() {
callSiteMapping.add(locationProvider, -1); callSiteMapping.add(locationProvider, -1, false);
} }
@Override @Override
@ -238,8 +238,8 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
IntegerArray columns = new IntegerArray(1); IntegerArray columns = new IntegerArray(1);
IntegerArray values = new IntegerArray(1); IntegerArray values = new IntegerArray(1);
public void add(LocationProvider location, int value) { public void add(LocationProvider location, int value, boolean merge) {
if (lines.size() > 1) { if (merge && lines.size() > 1) {
int last = lines.size() - 1; int last = lines.size() - 1;
if (lines.get(last) == location.getLine() && columns.get(last) == location.getColumn()) { if (lines.get(last) == location.getLine() && columns.get(last) == location.getColumn()) {
values.set(last, value); values.set(last, value);

View File

@ -74,43 +74,40 @@ public class Debugger {
step(false); step(false);
} }
private void jsStep(boolean enterMethod) {
if (enterMethod) {
javaScriptDebugger.stepInto();
} else {
javaScriptDebugger.stepOver();
}
}
private void step(boolean enterMethod) { private void step(boolean enterMethod) {
CallFrame[] callStack = getCallStack(); CallFrame[] callStack = getCallStack();
if (callStack == null || callStack.length == 0) { if (callStack == null || callStack.length == 0) {
if (enterMethod) { jsStep(enterMethod);
javaScriptDebugger.stepInto();
} else {
javaScriptDebugger.stepOver();
}
return; return;
} }
CallFrame recentFrame = callStack[0]; CallFrame recentFrame = callStack[0];
if (recentFrame.getLocation() == null || recentFrame.getLocation().getFileName() == null || if (recentFrame.getLocation() == null || recentFrame.getLocation().getFileName() == null ||
recentFrame.getLocation().getLine() < 0) { recentFrame.getLocation().getLine() < 0) {
if (enterMethod) { jsStep(enterMethod);
javaScriptDebugger.stepInto();
} else {
javaScriptDebugger.stepOver();
}
return; return;
} }
Set<JavaScriptLocation> successors = new HashSet<>(); Set<JavaScriptLocation> successors = new HashSet<>();
for (int i = 0; i < callStack.length; ++i) { for (CallFrame frame : callStack) {
CallFrame frame = callStack[i]; boolean exits;
boolean exits = false; String script = frame.originalLocation.getScript();
DebugInformation mainDebugInfo = debugInformationMap.get(frame.originalLocation.getScript());
GeneratedLocation genLoc = new GeneratedLocation(frame.originalLocation.getLine(), GeneratedLocation genLoc = new GeneratedLocation(frame.originalLocation.getLine(),
frame.originalLocation.getColumn()); frame.originalLocation.getColumn());
MethodReference callMethod = null;
if (mainDebugInfo != null) {
GeneratedLocation callSiteLoc = mainDebugInfo.getNearestCallSite(genLoc);
if (callSiteLoc != null) {
callMethod = mainDebugInfo.getCallSite(callSiteLoc);
}
}
String script = frame.originalLocation.getScript();
DebugInformation debugInfo = debugInformationMap.get(script); DebugInformation debugInfo = debugInformationMap.get(script);
if (debugInfo != null) { if (frame.getLocation() != null && debugInfo != null) {
exits = false;
MethodReference callMethod = null;
GeneratedLocation callSiteLoc = debugInfo.getNearestCallSite(genLoc);
if (callSiteLoc != null) {
callMethod = debugInfo.getCallSite(callSiteLoc);
}
SourceLocation[] following = debugInfo.getFollowingLines(frame.getLocation()); SourceLocation[] following = debugInfo.getFollowingLines(frame.getLocation());
if (following != null) { if (following != null) {
for (SourceLocation successor : following) { for (SourceLocation successor : following) {
@ -130,6 +127,8 @@ public class Debugger {
} }
} }
} }
} else {
exits = true;
} }
if (!exits) { if (!exits) {
break; break;

View File

@ -53,12 +53,12 @@ public class JavaScriptLocation {
return false; return false;
} }
JavaScriptLocation other = (JavaScriptLocation)obj; JavaScriptLocation other = (JavaScriptLocation)obj;
return Objects.equals(other.script, script) && other.line == line; return Objects.equals(other.script, script) && other.line == line && other.column == column;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return (31 + line) * 31 + Objects.hashCode(script); return (31 + column) * ((31 + line) * 31 + Objects.hashCode(script));
} }
@Override @Override