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

View File

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

View File

@ -53,12 +53,12 @@ public class JavaScriptLocation {
return false;
}
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
public int hashCode() {
return (31 + line) * 31 + Objects.hashCode(script);
return (31 + column) * ((31 + line) * 31 + Objects.hashCode(script));
}
@Override