diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java index 5df6e2371..01ad4c6be 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java +++ b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java @@ -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); diff --git a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java index 7173a29b4..4aa568231 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java @@ -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 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; diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java b/teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java index 0bb830ac3..45dc1e24a 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java @@ -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