fix: use debug line numbers only at fixed offsets (#1315)

This commit is contained in:
Skylot 2021-12-22 19:54:21 +00:00
parent 3566669303
commit 99c70872c1
No known key found for this signature in database
GPG Key ID: 1E23F5B52567AA39
2 changed files with 41 additions and 11 deletions

View File

@ -0,0 +1,39 @@
package jadx.tests.integration.debuginfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import jadx.tests.api.extensions.inputs.InputPlugin;
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestLineNumbers3 extends IntegrationTest {
public static class TestCls extends Exception {
public TestCls(final Object message) {
super((message == null) ? "" : message.toString());
/*
* comment to increase line number in return instruction
* -
* -
* -
* -
* -
* -
* -
* -
* -
* -
*/
}
}
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
public void test() {
ClassNode cls = getClassNode(TestCls.class);
assertThat(cls).code().containsOne("super(message == null ? \"\" : message.toString());");
String linesMapStr = cls.getCode().getLineMapping().toString();
assertThat(linesMapStr).isEqualTo("{4=13, 5=14, 6=15}");
}
}

View File

@ -185,25 +185,16 @@ public class DebugInfoParser {
}
}
}
setSourceLines(addr, codeSize, line);
return new DebugInfo(linesMap, resultList);
}
private int addrChange(int addr, int addrInc, int line) {
int newAddr = addr + addrInc;
int maxAddr = codeSize - 1;
newAddr = Math.min(newAddr, maxAddr);
setSourceLines(addr, newAddr, line);
int newAddr = Math.min(addr + addrInc, codeSize - 1);
setLine(newAddr, line);
return newAddr;
}
private void setSourceLines(int start, int end, int line) {
for (int offset = start + 1; offset < end; offset++) {
setLine(offset, line);
}
}
private void setLine(int offset, int line) {
linesMap.put(offset, line);
}