Replace return with nop to avoid merging line instructions (KT-18949)

Dex ignores subsequent line numbers for same instructions and interprets
instruction after inline as if they were inlined. This makes debugger
behaves as if there's nowhere to stop on line with breakpoint.

This also makes stepping through inline function consistent with
non-inline analog. In both context debugger now stops on '}'.

 #KT-18949 Fixed
 #KT-17120 Fixed
This commit is contained in:
Nikolay Krasko
2017-07-10 15:41:57 +03:00
parent fc685aa03f
commit ce4f923ba0
30 changed files with 76 additions and 15 deletions
@@ -846,9 +846,13 @@ class MethodInliner(
}
if (isLocalReturn && endLabel != null) {
val nop = InsnNode(Opcodes.NOP)
instructions.insert(insnNode, nop)
val labelNode = endLabel.info as LabelNode
val jumpInsnNode = JumpInsnNode(Opcodes.GOTO, labelNode)
instructions.insert(insnNode, jumpInsnNode)
instructions.insert(nop, jumpInsnNode)
instructions.remove(insnNode)
insnNode = jumpInsnNode
}
@@ -24,10 +24,23 @@ final class InlineWithoutStateMachineKt$complexSuspend$1 {
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
final class InlineWithoutStateMachineKt$suspendHere$1 {
field L$0: java.lang.Object
synthetic field data: java.lang.Object
synthetic field exception: java.lang.Throwable
inner class InlineWithoutStateMachineKt$suspendHere$1
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
synthetic final method getLabel(): int
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
public final class InlineWithoutStateMachineKt {
inner class InlineWithoutStateMachineKt$box$1
inner class InlineWithoutStateMachineKt$complexSuspend$1
inner class InlineWithoutStateMachineKt$suspendHere$1
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
public final static @org.jetbrains.annotations.Nullable method complexSuspend(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): java.lang.Object
@@ -23,4 +23,4 @@ fun simpleFunVoid(f: () -> Unit): Unit {
return f()
}
// 5 NOP
// 7 NOP
@@ -6,4 +6,4 @@ fun f() {
// 1 ISTORE 0\s+L3
// 1 ILOAD 0\s+INVOKEVIRTUAL java/io/PrintStream.print \(C\)V
// 1 LOCALVARIABLE c C L3 L6 0
// 1 LOCALVARIABLE c C L3 L7 0
@@ -9,4 +9,4 @@ inline fun lookAtMe(f: (String) -> Unit) {
f(a) // Should be no unneeded nops on this line, that might be generated for zero-parameters lambda
}
// 2 NOP
// 4 NOP
@@ -14,4 +14,4 @@ fun main(args: Array<String>) {
}
/*Threre are two constuctors so we should be sure that we check LOCALVARIABLEs from same method*/
// 1 LOCALVARIABLE this LInlinedConstuctorWithSuperCallParamsKt\$main\$\$inlined\$test\$1; L0 L6 0\s+LOCALVARIABLE \$super_call_param\$1 Ljava/lang/String; L0 L6 1
// 1 LOCALVARIABLE this LInlinedConstuctorWithSuperCallParamsKt\$main\$\$inlined\$test\$1; L0 L7 0\s+LOCALVARIABLE \$super_call_param\$1 Ljava/lang/String; L0 L7 1
@@ -9,4 +9,4 @@ fun foo(i: Int = 1) {
inline fun bar(i: Int = 1) {
}
// 2 3 13 14 +4 7 6 10 9 15
// 2 3 13 14 4 7 6 10 9 15
@@ -13,4 +13,4 @@ inline fun foo(f: () -> Unit) {
f()
}
// 2 17 18 3 4 19 +6 20 21 7 8 22 +9 12 13 14
// 2 17 18 3 4 19 6 20 21 7 8 22 9 12 13 14
@@ -9,4 +9,4 @@ inline fun lookAtMe(f: () -> Int) {
a + f()
}
// 2 13 14 3 15 +5 8 9 10
// 2 13 14 3 15 5 8 9 10
@@ -5,4 +5,4 @@ fun main(args: Array<String>) {
}
// ADDITIONAL_BREAKPOINT: functionInLibrary.kt:public inline fun simpleFun()
// STEP_INTO: 2
// STEP_INTO: 4
@@ -3,6 +3,8 @@ Run Java
Connected to the target VM
functionInLibrary.kt:4
functionInLibrary.kt:8
functionInLibrary.kt:9
functionInLibrary.kt:5
stepIntoStdlibInlineFun2step.kt:5
Disconnected from the target VM
@@ -14,4 +14,4 @@ inline fun foo(f: () -> Unit) {
f()
}
// STEP_OVER: 2
// STEP_OVER: 3
@@ -3,6 +3,7 @@ Run Java
Connected to the target VM
soInlineCallInLastStatementInInline.kt:9
soInlineCallInLastStatementInInline.kt:10
soInlineCallInLastStatementInInline.kt:11
soInlineCallInLastStatementInInline.kt:5
Disconnected from the target VM
@@ -3,6 +3,7 @@ Run Java
Connected to the target VM
soInlineCallInLastStatementInInlineDex.kt:10
soInlineCallInLastStatementInInlineDex.kt:11
soInlineCallInLastStatementInInlineDex.kt:12
soInlineCallInLastStatementInInlineDex.kt:5
soInlineCallInLastStatementInInlineDex.kt:6
Disconnected from the target VM
@@ -3,6 +3,7 @@ Run Java
Connected to the target VM
soInlineCallInLastStatementInInlineFunctionArgument.kt:7
soInlineCallInLastStatementInInlineFunctionArgument.kt:8
soInlineCallInLastStatementInInlineFunctionArgument.kt:14
soInlineCallInLastStatementInInlineFunctionArgument.kt:9
Disconnected from the target VM
@@ -4,7 +4,7 @@ fun main(args: Array<String>) {
bar {
nop()
//Breakpoint!
foo()
foo() // <-- Should not stop here twice
}
}
@@ -2,7 +2,7 @@ LineBreakpoint created at soInlineCallInLastStatementInInlineFunctionArgumentDex
Run Java
Connected to the target VM
soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:7
soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:8
soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:7
soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:9
Disconnected from the target VM
@@ -2,6 +2,8 @@ LineBreakpoint created at soInlineCallInLastStatementInInlineInInline.kt:15
Run Java
Connected to the target VM
soInlineCallInLastStatementInInlineInInline.kt:15
soInlineCallInLastStatementInInlineInInline.kt:16
soInlineCallInLastStatementInInlineInInline.kt:11
soInlineCallInLastStatementInInlineInInline.kt:5
soInlineCallInLastStatementInInlineInInline.kt:6
Disconnected from the target VM
@@ -17,4 +17,4 @@ inline fun foo(f1: () -> Unit, f2: () -> Unit) {
f2()
}
// STEP_OVER 5
// STEP_OVER: 5
@@ -2,6 +2,7 @@ LineBreakpoint created at soInlineFunCallInLastStatementOfInlineWithArgumentFrom
Run Java
Connected to the target VM
soInlineFunCallInLastStatementOfInlineWithArgumentFromCalleeAndOwn.kt:11
soInlineFunCallInLastStatementOfInlineWithArgumentFromCalleeAndOwn.kt:13
soInlineFunCallInLastStatementOfInlineWithArgumentFromCalleeAndOwn.kt:7
Disconnected from the target VM
@@ -14,4 +14,4 @@ inline fun bar(f: (Int) -> Unit) {
f(1)
}
// STEP_OVER: 1
// STEP_OVER: 2
@@ -2,6 +2,7 @@ LineBreakpoint created at soInlineFunWithLastStatementMultilineArgumentCall.kt:1
Run Java
Connected to the target VM
soInlineFunWithLastStatementMultilineArgumentCall.kt:14
soInlineFunWithLastStatementMultilineArgumentCall.kt:15
soInlineFunWithLastStatementMultilineArgumentCall.kt:9
Disconnected from the target VM
@@ -2,6 +2,7 @@ LineBreakpoint created at soInlineFunWithLastStatementOneLineArgumentCall.kt:11
Run Java
Connected to the target VM
soInlineFunWithLastStatementOneLineArgumentCall.kt:11
soInlineFunWithLastStatementOneLineArgumentCall.kt:12
soInlineFunWithLastStatementOneLineArgumentCall.kt:6
soInlineFunWithLastStatementOneLineArgumentCall.kt:7
Disconnected from the target VM
@@ -4,6 +4,7 @@ Connected to the target VM
soInlineIfConditionLambdaFalse.kt:11
soInlineIfConditionLambdaFalse.kt:15
soInlineIfConditionLambdaFalse.kt:18
soInlineIfConditionLambdaFalse.kt:19
soInlineIfConditionLambdaFalse.kt:7
Disconnected from the target VM
@@ -4,6 +4,7 @@ Connected to the target VM
soInlineIfConditionLambdaTrue.kt:11
soInlineIfConditionLambdaTrue.kt:12
soInlineIfConditionLambdaTrue.kt:18
soInlineIfConditionLambdaTrue.kt:19
soInlineIfConditionLambdaTrue.kt:7
Disconnected from the target VM
@@ -0,0 +1,17 @@
package soInlineUnitFunDex
fun main(args: Array<String>) {
process()
}
fun process(): String {
simple()
//Breakpoint!
return "Constant" // 1
}
inline fun simple() {
inner()
}
fun inner() {}
@@ -0,0 +1,8 @@
LineBreakpoint created at soInlineUnitFunDex.kt:10
Run Java
Connected to the target VM
soInlineUnitFunDex.kt:10
soInlineUnitFunDex.kt:4
Disconnected from the target VM
Process finished with exit code 0
@@ -16,4 +16,4 @@ inline fun bar(f: (Int) -> Unit) {
fun foo() {}
// STEP_OVER: 4
// STEP_OVER: 5
@@ -5,6 +5,7 @@ stepOverInsideInlineFun.kt:11
stepOverInsideInlineFun.kt:12
stepOverInsideInlineFun.kt:13
stepOverInsideInlineFun.kt:14
stepOverInsideInlineFun.kt:15
stepOverInsideInlineFun.kt:7
Disconnected from the target VM
@@ -602,6 +602,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest {
doStepOverTest(fileName);
}
@TestMetadata("soInlineUnitFunDex.kt")
public void testSoInlineUnitFunDex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/soInlineUnitFunDex.kt");
doStepOverTest(fileName);
}
@TestMetadata("soInlineWhileCondition.kt")
public void testSoInlineWhileCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/soInlineWhileCondition.kt");