diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java index 11973fa51..e0d04f96a 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java +++ b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java @@ -93,35 +93,35 @@ class DebugInformationReader { } private DebugInformation.CFG readCFG(int index) throws IOException { - int[] offsets = new int[readUnsignedNumber() + 1]; - IntegerArray lines = new IntegerArray(1); - IntegerArray files = new IntegerArray(1); - for (int i = 0; i < offsets.length - 1; ++i) { - offsets[i] = lines.size(); + IntegerArray offsets = new IntegerArray(1); + int[] lines = new int[readUnsignedNumber()]; + int[] files = new int[lines.length]; + int i = 0; + int line = 0; + offsets.add(0); + while (i < lines.length) { + line += readUnsignedNumber(); int sz = readUnsignedNumber(); if (sz == 0) { - continue; + lines[i] = -1; + files[i++] = -1; } else if (sz == 1) { - lines.add(-1); - files.add(-1); - } else if (sz == 2) { - lines.add(i + 1); - files.add(index); - } else { - sz -= 2; - int last = i; - for (int j = 0; j < sz; ++j) { - last += readNumber(); - lines.add(last); - files.add(index + readNumber()); - } + lines[i] = line + 1; + files[i++] = index; } + sz -= 1; + int last = line; + for (int j = 0; j < sz; ++j) { + last += readNumber(); + lines[i] = last; + files[i++] = index + readNumber(); + } + offsets.add(i); } - offsets[offsets.length - 1] = lines.size(); DebugInformation.CFG cfg = new DebugInformation.CFG(); - cfg.offsets = offsets; - cfg.lines = lines.getAll(); - cfg.files = files.getAll(); + cfg.offsets = offsets.getAll(); + cfg.lines = lines; + cfg.files = files; return cfg; } diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java index 3a7414395..ab796da2e 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java +++ b/teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java @@ -147,18 +147,21 @@ class DebugInformationWriter { } private void writeCFG(DebugInformation.CFG mapping, int fileIndex) throws IOException { - writeUnsignedNumber(mapping.offsets.length - 1); + writeUnsignedNumber(mapping.lines.length); + int lastLine = 0; for (int i = 0; i < mapping.offsets.length - 1; ++i) { int start = mapping.offsets[i]; int sz = mapping.offsets[i + 1] - start; if (sz == 0) { + continue; + } + writeUnsignedNumber(i - lastLine); + if (sz == 1 && mapping.lines[start] == -1) { writeUnsignedNumber(0); - } else if (sz == 1 && mapping.lines[start] == -1) { - writeUnsignedNumber(1); } else if (sz == 1 && mapping.lines[start] == i + 1 && mapping.files[start] == fileIndex) { - writeUnsignedNumber(2); + writeUnsignedNumber(1); } else { - writeUnsignedNumber(2 + sz); + writeUnsignedNumber(1 + sz); int[] lines = Arrays.copyOfRange(mapping.lines, start, start + sz); int[] files = Arrays.copyOfRange(mapping.files, start, start + sz); int last = i; @@ -169,6 +172,7 @@ class DebugInformationWriter { last = succ; } } + lastLine = i; } }