Debugger: Fix breakpoints and stepping for inline-only function lambda arguments (#KT-23064)

This commit is contained in:
Yan Zhulanow
2018-03-06 00:46:29 +03:00
parent ae37cc30a1
commit eec9c6bffa
16 changed files with 238 additions and 49 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.codegen.inline
import org.jetbrains.kotlin.backend.jvm.codegen.IrExpressionLambda
import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.ClosureCodegen
import org.jetbrains.kotlin.codegen.StackValue
@@ -368,7 +369,14 @@ class MethodInliner(
)
val transformationVisitor = object : MethodVisitor(API, transformedNode) {
private val GENERATE_DEBUG_INFO = GENERATE_SMAP && inlineOnlySmapSkipper == null
/*
Ignore simple @InlineOnly functions such as 'error()' or 'assert()' without lambda parameters,
as we likely to want to have a line number from the call site in a stack trace.
*/
private val GENERATE_LINE_NUMBERS = GENERATE_SMAP && (inlineOnlySmapSkipper == null || run {
val callableDescriptor = inliningContext.root.sourceCompilerForInline.callableDescriptor
callableDescriptor != null && callableDescriptor.valueParameters.any { it.type.isFunctionType }
})
private val isInliningLambda = nodeRemapper.isInsideInliningLambda
@@ -400,7 +408,7 @@ class MethodInliner(
}
override fun visitLineNumber(line: Int, start: Label) {
if (isInliningLambda || GENERATE_DEBUG_INFO) {
if (isInliningLambda || GENERATE_LINE_NUMBERS) {
super.visitLineNumber(line, start)
}
}
@@ -428,7 +436,7 @@ class MethodInliner(
override fun visitLocalVariable(
name: String, desc: String, signature: String?, start: Label, end: Label, index: Int
) {
if (isInliningLambda || GENERATE_DEBUG_INFO) {
if (isInliningLambda || (GENERATE_SMAP && inlineOnlySmapSkipper == null)) {
val varSuffix = if (inliningContext.isRoot && !isFakeLocalVariableForInline(name)) INLINE_FUN_VAR_SUFFIX else ""
val varName = if (!varSuffix.isEmpty() && name == "this") name + "_" else name
super.visitLocalVariable(varName + varSuffix, desc, signature, start, end, getNewIndex(index))
@@ -46,6 +46,8 @@ interface SourceCompilerForInline {
val callElement: Any
val callableDescriptor: CallableDescriptor?
val lookupLocation: LookupLocation
val callElementText: String
@@ -99,6 +101,8 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
override val lookupLocation = KotlinLookupLocation(callElement)
override val callableDescriptor: CallableDescriptor?
get() = (this.context as? MethodContext)?.functionDescriptor
override val callElementText by lazy {
callElement.text
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.SourceInfo
import org.jetbrains.kotlin.codegen.inline.*
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
@@ -50,6 +51,9 @@ class IrSourceCompilerForInline(
override val callElementText: String
get() = callElement.toString()
override val callableDescriptor: CallableDescriptor
get() = callElement.descriptor
override val callsiteFile: PsiFile?
get() = TODO("not implemented")
@@ -87,22 +87,26 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
+ 2 Standard.kt
kotlin/StandardKt__StandardKt
+ 3 1.kt
test/_1Kt
+ 4 1.kt
test/_1Kt$lParams$1
*L
1#1,10:1
31#2,5:11
29#2:17
32#3:16
34#2,4:11
31#3,5:15
29#3:21
32#4:20
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1,5:11
5#1:17
5#1:16
5#1,4:11
5#1,5:15
5#1:21
5#1:20
*E
@@ -123,26 +123,30 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
+ 2 Standard.kt
kotlin/StandardKt__StandardKt
+ 3 1.kt
test/_1Kt
+ 4 1.kt
test/_1Kt$lParams$1
*L
1#1,10:1
31#2:11
70#2,2:12
29#2:15
50#3:14
68#3:16
34#2,4:11
31#3:15
70#3,2:16
29#3:19
50#4:18
68#4:20
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:11
5#1,2:12
5#1,4:11
5#1:15
5#1:14
5#1:16
5#1,2:16
5#1:19
5#1:18
5#1:20
*E
@@ -112,24 +112,28 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
+ 2 Standard.kt
kotlin/StandardKt__StandardKt
+ 3 1.kt
test/_1Kt
+ 4 1.kt
test/_1Kt$lParams$1
*L
1#1,10:1
31#2,5:11
29#2:17
32#3:16
34#2,4:11
31#3,5:15
29#3:21
32#4:20
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1,5:11
5#1:17
5#1:16
5#1,4:11
5#1,5:15
5#1:21
5#1:20
*E
// FILE: 2.smap-separate-compilation
@@ -140,24 +144,28 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
+ 2 Standard.kt
kotlin/StandardKt__StandardKt
+ 3 1.kt
test/_1Kt
+ 4 1.kt
test/_1Kt$lParams$1
*L
1#1,10:1
31#2,5:11
29#2:17
32#3:16
34#2,4:11
31#3,5:15
29#3:21
32#4:20
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1,5:11
5#1:17
5#1:16
5#1,4:11
5#1,5:15
5#1:21
5#1:20
*E
SMAP
@@ -76,20 +76,24 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
+ 2 Standard.kt
kotlin/StandardKt__StandardKt
+ 3 1.kt
test/_1Kt
+ 4 1.kt
test/_1Kt$lParams$1
*L
1#1,10:1
30#2,5:11
31#3:16
34#2,4:11
30#3,5:15
31#4:20
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1,5:11
5#1:16
5#1,4:11
5#1,5:15
5#1:20
*E
@@ -20,6 +20,16 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 _Strings.kt
kotlin/text/StringsKt___StringsKt
*L
1#1,7:1
498#2:8
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
4#1:8
*E
@@ -25,6 +25,16 @@ Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
*L
1#1,8:1
10#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E