From 9760c156a48424ff18977f555fe13921c5c734c2 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 20 Jun 2019 21:30:45 +0900 Subject: [PATCH] Debugger: Fix breakpoints on if/loops with constant conditions (KT-14421) --- .../jetbrains/kotlin/codegen/BranchedValue.kt | 4 ++ .../custom/beforeGotoToWhileStart.kt | 2 +- .../src/stepping/custom/constantConditions.kt | 52 +++++++++++++++++++ .../stepping/custom/constantConditions.out | 17 ++++++ .../debugger/KotlinSteppingTestGenerated.java | 5 ++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.out diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/BranchedValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/BranchedValue.kt index aa2c1757e39..dd0125d3f03 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/BranchedValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/BranchedValue.kt @@ -51,12 +51,14 @@ open class BranchedValue( val TRUE: BranchedValue = object : BranchedValue(StackValue.none()/*not used*/, null, Type.BOOLEAN_TYPE, IFEQ) { override fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { + v.nop() if (!jumpIfFalse) { v.goTo(jumpLabel) } } override fun loopJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { + v.nop() if (!jumpIfFalse) { v.fakeAlwaysTrueIfeq(jumpLabel) } else { @@ -72,12 +74,14 @@ open class BranchedValue( val FALSE: BranchedValue = object : BranchedValue(StackValue.none()/*not used*/, null, Type.BOOLEAN_TYPE, IFEQ) { override fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { + v.nop() if (jumpIfFalse) { v.goTo(jumpLabel) } } override fun loopJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { + v.nop() if (jumpIfFalse) { v.fakeAlwaysTrueIfeq(jumpLabel) } else { diff --git a/compiler/testData/lineNumber/custom/beforeGotoToWhileStart.kt b/compiler/testData/lineNumber/custom/beforeGotoToWhileStart.kt index 6427ee7de86..0cb7ee0dfd4 100644 --- a/compiler/testData/lineNumber/custom/beforeGotoToWhileStart.kt +++ b/compiler/testData/lineNumber/custom/beforeGotoToWhileStart.kt @@ -10,4 +10,4 @@ fun testSome(): Boolean { return false } -// 2 +3 4 2 7 10 \ No newline at end of file +// 2 3 4 2 7 10 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.kt new file mode 100644 index 00000000000..66264af73b3 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.kt @@ -0,0 +1,52 @@ +package constantConditions + +fun main() { + trueIf() + falseIf() + elseIf() + whileFalse() + whileTrue() +} + +private fun trueIf() { + //Breakpoint! + if (true) + foo("true") + else + foo("false") +} + +private fun falseIf() { + //Breakpoint! + if(false) + foo("false") + else + foo("true") +} + +private fun elseIf() { + //Breakpoint! + if (false) + foo("false") + //Breakpoint! + else if (true) + foo("true") +} + + +private fun whileFalse() { + //Breakpoint! + while (false) + foo("while false") +} + + +private fun whileTrue() { + //Breakpoint! + while (true) + break +} + +private fun foo(text: String) {} + +// RESUME: 6 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.out b/idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.out new file mode 100644 index 00000000000..655aa2ab042 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.out @@ -0,0 +1,17 @@ +LineBreakpoint created at constantConditions.kt:13 +LineBreakpoint created at constantConditions.kt:21 +LineBreakpoint created at constantConditions.kt:29 +LineBreakpoint created at constantConditions.kt:32 +LineBreakpoint created at constantConditions.kt:39 +LineBreakpoint created at constantConditions.kt:46 +Run Java +Connected to the target VM +constantConditions.kt:13 +constantConditions.kt:21 +constantConditions.kt:29 +constantConditions.kt:32 +constantConditions.kt:39 +constantConditions.kt:46 +Disconnected from the target VM + +Process finished with exit code 0 diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index a059d66a456..c36845a0c9f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -1037,6 +1037,11 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { runTest("idea/testData/debugger/tinyApp/src/stepping/custom/anonymousFunAsParamDefaultValue.kt"); } + @TestMetadata("constantConditions.kt") + public void testConstantConditions() throws Exception { + runTest("idea/testData/debugger/tinyApp/src/stepping/custom/constantConditions.kt"); + } + @TestMetadata("coroutine.kt") public void testCoroutine() throws Exception { runTest("idea/testData/debugger/tinyApp/src/stepping/custom/coroutine.kt");