From f115bde682da21b03f0cb4eb71ba8ec97b5ef081 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 29 Nov 2019 18:55:33 +0900 Subject: [PATCH] Debugger, BE: Provide Java-like stepping for 'for' loops - Visit '}' instead of 'for' keyword on post-condition - Visit 'for' keyword on pre-condition --- .idea/artifacts/dist_root.xml | 8 ------- .../kotlin/codegen/ExpressionCodegen.java | 10 ++++++++- .../localVariables/destructuringInFor.kt | 1 - compiler/testData/debug/stepping/for.kt | 21 +++++++++++++++++++ .../IrSteppingTestGenerated.java | 6 ++++++ .../SteppingTestGenerated.java | 6 ++++++ .../stepping/stepInto/continueLabel.out | 1 - .../testData/stepping/stepInto/forLoop.kt | 2 +- .../testData/stepping/stepInto/forLoop.out | 1 + .../stepping/stepOver/asIterableInFor.kt | 2 +- .../inlineCallInForRangeExpression.out | 1 + 11 files changed, 46 insertions(+), 13 deletions(-) delete mode 100644 .idea/artifacts/dist_root.xml create mode 100644 compiler/testData/debug/stepping/for.kt diff --git a/.idea/artifacts/dist_root.xml b/.idea/artifacts/dist_root.xml deleted file mode 100644 index a75a0e0cecc..00000000000 --- a/.idea/artifacts/dist_root.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - $PROJECT_DIR$/dist - - - - - \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 4f49bd1d5cf..5a8295b8a83 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -677,6 +677,10 @@ public class ExpressionCodegen extends KtVisitor impleme generator.checkEmptyLoop(loopExit); v.mark(loopEntry); + resetLastLineNumber(); + markStartLineNumber(generator.getForExpression()); + v.nop(); + generator.checkPreCondition(loopExit); // Some forms of for-loop can be optimized as post-condition loops. @@ -1507,10 +1511,14 @@ public class ExpressionCodegen extends KtVisitor impleme } } else { //if it used as argument of infix call (in this case lineNumber for simple inlineCall also would be reset) - myLastLineNumber = -1; + resetLastLineNumber(); } } + private void resetLastLineNumber() { + myLastLineNumber = -1; + } + @Override public int getLastLineNumber() { return myLastLineNumber; diff --git a/compiler/testData/debug/localVariables/destructuringInFor.kt b/compiler/testData/debug/localVariables/destructuringInFor.kt index a7528b12d5a..85e091411b9 100644 --- a/compiler/testData/debug/localVariables/destructuringInFor.kt +++ b/compiler/testData/debug/localVariables/destructuringInFor.kt @@ -16,5 +16,4 @@ fun box() { // TestKt:7: map:java.util.Collections$SingletonMap // TestKt:9: map:java.util.Collections$SingletonMap, a:java.lang.String, b:java.lang.String // TestKt:7: map:java.util.Collections$SingletonMap -// TestKt:8: map:java.util.Collections$SingletonMap // TestKt:11: map:java.util.Collections$SingletonMap diff --git a/compiler/testData/debug/stepping/for.kt b/compiler/testData/debug/stepping/for.kt new file mode 100644 index 00000000000..e57500da511 --- /dev/null +++ b/compiler/testData/debug/stepping/for.kt @@ -0,0 +1,21 @@ +//FILE: test.kt +fun box() { + for (i in 1..3) { + foo(i) + } +} + +inline fun foo(n: Int) {} + +// LINENUMBERS +// TestKt.box():3 +// TestKt.box():4 +// TestKt.box():8 +// TestKt.box():3 +// TestKt.box():4 +// TestKt.box():8 +// TestKt.box():3 +// TestKt.box():4 +// TestKt.box():8 +// TestKt.box():3 +// TestKt.box():6 \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java index d2e060c6d16..c614deb883a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java @@ -43,6 +43,12 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest { runTest("compiler/testData/debug/stepping/conjunction.kt"); } + @Test + @TestMetadata("for.kt") + public void testFor() throws Exception { + runTest("compiler/testData/debug/stepping/for.kt"); + } + @Test @TestMetadata("functionInAnotherFile.kt") public void testFunctionInAnotherFile() throws Exception { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java index e826a68cd10..5ed1b014239 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java @@ -43,6 +43,12 @@ public class SteppingTestGenerated extends AbstractSteppingTest { runTest("compiler/testData/debug/stepping/conjunction.kt"); } + @Test + @TestMetadata("for.kt") + public void testFor() throws Exception { + runTest("compiler/testData/debug/stepping/for.kt"); + } + @Test @TestMetadata("functionInAnotherFile.kt") public void testFunctionInAnotherFile() throws Exception { diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/continueLabel.out b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/continueLabel.out index 9f2bac02ba4..5f61c05af23 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/continueLabel.out +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/continueLabel.out @@ -5,7 +5,6 @@ continueLabel.kt:5 continueLabel.kt:6 continueLabel.kt:7 continueLabel.kt:8 -continueLabel.kt:10 continueLabel.kt:5 continueLabel.kt:6 continueLabel.kt:7 diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.kt index 87325c8107c..bcb632b5b1f 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.kt @@ -15,4 +15,4 @@ fun main(args: Array) { val z = 1 } -// STEP_INTO: 14 \ No newline at end of file +// STEP_INTO: 17 \ No newline at end of file diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.out b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.out index 7a2e4027f9a..dfec9f225f3 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.out +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/forLoop.out @@ -16,6 +16,7 @@ forLoop.kt:12 forLoop.kt:13 forLoop.kt:11 forLoop.kt:15 +forLoop.kt:16 Disconnected from the target VM Process finished with exit code 0 diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/asIterableInFor.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/asIterableInFor.kt index bf404fe9e7f..e378ca7fd9a 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/asIterableInFor.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/asIterableInFor.kt @@ -12,4 +12,4 @@ fun main(args: Array) { // STEP_OVER: 4 -// Tests that last line will be "9", no "11". See KT-13534. +// See KT-13534. diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineCallInForRangeExpression.out b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineCallInForRangeExpression.out index 09f66c8c145..49a2c93441a 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineCallInForRangeExpression.out +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineCallInForRangeExpression.out @@ -6,6 +6,7 @@ inlineCallInForRangeExpression.kt:8 inlineCallInForRangeExpression.kt:9 inlineCallInForRangeExpression.kt:8 inlineCallInForRangeExpression.kt:9 +inlineCallInForRangeExpression.kt:8 inlineCallInForRangeExpression.kt:11 Disconnected from the target VM