diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java b/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java index 8d9e914c9..aeed36f18 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java @@ -325,10 +325,9 @@ public class DebugInformation { FileDescription build() { FileDescription description = new FileDescription(); description.generatedLocationData = new int[generatedLocationData.size()]; - description.generatedLocationStart = new int[generatedLocationStart.size()]; + description.generatedLocationStart = new int[generatedLocationStart.size() + 1]; int current = 0; for (int i = 0; i < generatedLocationStart.size(); ++i) { - description.generatedLocationStart[i] = current; current += generatedLocationSize.get(i) * 2; int j = current; int ptr = generatedLocationStart.get(i); @@ -336,6 +335,7 @@ public class DebugInformation { description.generatedLocationData[--j] = generatedLocationData.get(ptr); ptr = generatedLocationPointers.get(ptr); } + description.generatedLocationStart[i + 1] = current; } return description; } 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 743ec5514..c69fb4b8f 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java +++ b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java @@ -348,7 +348,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter { IntegerArray linesChunk = new IntegerArray(1); IntegerArray filesChunk = new IntegerArray(1); int ptr = start.get(i); - while (ptr > 0) { + while (ptr >= 0) { linesChunk.add(lines.get(ptr)); filesChunk.add(files.get(ptr)); ptr = next.get(ptr); @@ -361,7 +361,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter { int distinctSize = 0; for (int j = 0; j < pairs.length; ++j) { long pair = pairs[j]; - if (distinctSize == 0 || pair != pairs[distinctSize]) { + if (distinctSize == 0 || pair != pairs[distinctSize - 1]) { pairs[distinctSize++] = pair; filesData.add((int)(pair >>> 32)); linesData.add((int)pair); diff --git a/teavm-core/src/main/java/org/teavm/model/util/ListingBuilder.java b/teavm-core/src/main/java/org/teavm/model/util/ListingBuilder.java index d32a5e82a..c7d0852f3 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/ListingBuilder.java +++ b/teavm-core/src/main/java/org/teavm/model/util/ListingBuilder.java @@ -16,6 +16,7 @@ package org.teavm.model.util; import java.util.List; +import java.util.Objects; import org.teavm.model.*; /** @@ -25,7 +26,8 @@ import org.teavm.model.*; public class ListingBuilder { public String buildListing(ProgramReader program, String prefix) { StringBuilder sb = new StringBuilder(); - InstructionStringifier stringifier = new InstructionStringifier(sb); + StringBuilder insnSb = new StringBuilder(); + InstructionStringifier stringifier = new InstructionStringifier(insnSb); for (int i = 0; i < program.variableCount(); ++i) { sb.append(prefix).append("var @").append(i); VariableReader var = program.variableAt(i); @@ -59,10 +61,16 @@ public class ListingBuilder { } sb.append("\n"); } + InstructionLocation location = null; for (int j = 0; j < block.instructionCount(); ++j) { - sb.append(prefix).append(" "); + insnSb.setLength(0); block.readInstruction(j, stringifier); - sb.append("\n"); + if (!Objects.equals(location, stringifier.getLocation())) { + location = stringifier.getLocation(); + sb.append(prefix).append(" at ").append(location != null ? location.toString() : + "unknown location").append('\n'); + } + sb.append(prefix).append(" ").append(insnSb).append("\n"); } for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { sb.append(prefix).append(" catch ").append(tryCatch.getExceptionType()).append(" @")