Debugger: Fix breakpoint applicability (KT-10984)

Ensure that breakpoints of each type can be placed only on lines where it makes sense to place a breakpoint.

Here is a quick summary of the rules:
1. Method breakpoints are available for functions, property accessors, constructors;
2. Line breakpoints are available on any line with an expression, excluding some cases like 'const' property initializers or annotations;
3. Line breakpoints should be available on a '}' in functions and lambdas;
4. Line breakpoints are not suggested for one-liners;
5. Lambda breakpoints should be shown for single-line lambdas.
This commit is contained in:
Yan Zhulanow
2019-07-03 18:27:47 +09:00
parent 22c18ffaa9
commit 129ca7f2d8
18 changed files with 407 additions and 126 deletions
@@ -5,7 +5,7 @@ class Derived2(): Base(1) {
// constructor with body
// EXPRESSION: p
// RESULT: 1: I
//Breakpoint!
//FunctionBreakpoint!
constructor(p: Int): this() {
// EXPRESSION: p + 1
// RESULT: 2: I
@@ -16,7 +16,7 @@ class Derived2(): Base(1) {
// constructor without body
// EXPRESSION: p1 + p2
// RESULT: 2: I
//Breakpoint!
//FunctionBreakpoint!
constructor(p1: Int, p2: Int): this()
}
@@ -36,6 +36,7 @@ fun main(args: Array<String>) {
Derived1(1)
A()
AA()
B()
C(1)
D()
@@ -45,33 +46,40 @@ fun main(args: Array<String>) {
// EXPRESSION: 1 + 1
// RESULT: 2: I
//Breakpoint!
//FunctionBreakpoint!
class A
// EXPRESSION: 1 + 3
// RESULT: 4: I
//FunctionBreakpoint!
class AA {
}
// EXPRESSION: 1 + 2
// RESULT: 3: I
//Breakpoint!
//FunctionBreakpoint!
class B()
// EXPRESSION: a
// RESULT: 1: I
//Breakpoint!
//FunctionBreakpoint!
class C(val a: Int)
class D {
// EXPRESSION: 1 + 3
// RESULT: 4: I
//Breakpoint!
//FunctionBreakpoint!
constructor()
}
class E {
// EXPRESSION: i
// RESULT: 1: I
//Breakpoint!
//FunctionBreakpoint!
constructor(i: Int)
}
// EXPRESSION: a
// RESULT: "foo": Ljava/lang/String;
//Breakpoint!
//FunctionBreakpoint!
class F(val a: String)
@@ -1,13 +1,14 @@
LineBreakpoint created at constructors.kt:9
FunctionBreakpoint created at constructors.kt:9
LineBreakpoint created at constructors.kt:13
LineBreakpoint created at constructors.kt:20
FunctionBreakpoint created at constructors.kt:20
LineBreakpoint created at constructors.kt:28
LineBreakpoint created at constructors.kt:49
LineBreakpoint created at constructors.kt:54
LineBreakpoint created at constructors.kt:59
LineBreakpoint created at constructors.kt:65
LineBreakpoint created at constructors.kt:71
LineBreakpoint created at constructors.kt:77
FunctionBreakpoint created at constructors.kt:50
FunctionBreakpoint created at constructors.kt:55
FunctionBreakpoint created at constructors.kt:62
FunctionBreakpoint created at constructors.kt:67
FunctionBreakpoint created at constructors.kt:73
FunctionBreakpoint created at constructors.kt:79
FunctionBreakpoint created at constructors.kt:85
Run Java
Connected to the target VM
constructors.kt:9
@@ -18,17 +19,19 @@ constructors.kt:20
Compile bytecode for p1 + p2
constructors.kt:28
Compile bytecode for i1
constructors.kt:49
constructors.kt:50
Compile bytecode for 1 + 1
constructors.kt:54
Compile bytecode for 1 + 2
constructors.kt:59
Compile bytecode for a
constructors.kt:65
constructors.kt:55
Compile bytecode for 1 + 3
constructors.kt:71
constructors.kt:62
Compile bytecode for 1 + 2
constructors.kt:67
Compile bytecode for a
constructors.kt:73
Compile bytecode for 1 + 3
constructors.kt:79
Compile bytecode for i
constructors.kt:77
constructors.kt:85
Compile bytecode for a
Disconnected from the target VM
@@ -5,13 +5,13 @@ import kotlin.properties.Delegates
// EXPRESSION: 1 + 1
// RESULT: 2: I
val aGet: Int
//Breakpoint!
//FunctionBreakpoint!
get() = 1
// EXPRESSION: 1 + 2
// RESULT: 3: I
val aGet2: Int
//Breakpoint!
//FunctionBreakpoint!
get() { return 1 }
fun fooWithBody(i: Int): Int {
@@ -23,23 +23,23 @@ fun fooWithBody(i: Int): Int {
// EXPRESSION: i
// RESULT: 2: I
//Breakpoint!
//FunctionBreakpoint!
fun foo(i: Int) = i
// EXPRESSION: i
// RESULT: 2: I
//Breakpoint!
//FunctionBreakpoint!
fun fooOneLine(i: Int): Int { return 1 }
// EXPRESSION: i
// RESULT: 2: I
//Breakpoint!
//FunctionBreakpoint!
fun fooEmpty(i: Int) {}
object A {
// EXPRESSION: test2()
// RESULT: 2: I
//Breakpoint!
//FunctionBreakpoint!
@JvmStatic fun fooWithoutBodyInsideObject() = test2()
fun test2() = 2
}
@@ -1,10 +1,10 @@
LineBreakpoint created at withoutBodyFunctions.kt:9
LineBreakpoint created at withoutBodyFunctions.kt:15
FunctionBreakpoint created at withoutBodyFunctions.kt:9
FunctionBreakpoint created at withoutBodyFunctions.kt:15
LineBreakpoint created at withoutBodyFunctions.kt:21
LineBreakpoint created at withoutBodyFunctions.kt:27
LineBreakpoint created at withoutBodyFunctions.kt:32
LineBreakpoint created at withoutBodyFunctions.kt:37
LineBreakpoint created at withoutBodyFunctions.kt:43
FunctionBreakpoint created at withoutBodyFunctions.kt:27
FunctionBreakpoint created at withoutBodyFunctions.kt:32
FunctionBreakpoint created at withoutBodyFunctions.kt:37
FunctionBreakpoint created at withoutBodyFunctions.kt:43
Run Java
Connected to the target VM
withoutBodyFunctions.kt:9
@@ -4,7 +4,7 @@ import kotlin.properties.Delegates
// EXPRESSION: i
// RESULT: instance of java.lang.Integer(id=ID): Ljava/lang/Integer;
//Breakpoint!
//FunctionBreakpoint!
fun <T> foo(i: T) = i
fun run(i: () -> Int) = 1
@@ -1,4 +1,4 @@
LineBreakpoint created at withoutBodyTypeParameters.kt:8
FunctionBreakpoint created at withoutBodyTypeParameters.kt:8
Run Java
Connected to the target VM
withoutBodyTypeParameters.kt:8
@@ -1,7 +1,7 @@
package evFunctionDeclaration
class A(val a: Int) {
//Breakpoint!
//FunctionBreakpoint!
fun foo() = a
}
@@ -1,4 +1,4 @@
LineBreakpoint created at evFunctionDeclaration.kt:5
FunctionBreakpoint created at evFunctionDeclaration.kt:5
Run Java
Connected to the target VM
evFunctionDeclaration.kt:5
@@ -3,12 +3,15 @@ package kt15259
interface ObjectFace
private fun makeFace() = object : ObjectFace {
//Breakpoint!
//Breakpoint!
init { 5 }
}
fun main() {
makeFace()
}
// STEP_OVER: 1
// EXPRESSION: this
// RESULT: 'this' is not defined in this context
@@ -2,6 +2,7 @@ LineBreakpoint created at kt15259.kt:7
Run Java
Connected to the target VM
kt15259.kt:7
kt15259.kt:8
Disconnected from the target VM
Process finished with exit code 0
@@ -5,7 +5,7 @@ fun main() {
}
val x: String = "x"
//Breakpoint!
//FunctionBreakpoint!
get() = "foo" + field
// EXPRESSION: field
@@ -1,4 +1,4 @@
LineBreakpoint created at staticField.kt:9
FunctionBreakpoint created at staticField.kt:9
Run Java
Connected to the target VM
staticField.kt:9