Merge KT-MR-3224 from rrn/minamoto/kt-33364

This commit is contained in:
Vasily Levchenko
2021-06-09 11:50:28 +00:00
committed by Space
7 changed files with 53 additions and 16 deletions
@@ -169,12 +169,12 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
null
}
})
putIfNotNull(GENERATE_INLINED_FUNCTION_BODY_MARKER, when (val it = arguments.generateInlinedFunctionMarkerString) {
putIfNotNull(GENERATE_DEBUG_TRAMPOLINE, when (val it = arguments.generateDebugTrampolineString) {
"enable" -> true
"disable" -> false
null -> null
else -> {
configuration.report(ERROR, "Unsupported -Xg-generate-inline-function-body-marker= value: $it. Possible values are 'enable'/'disable'")
configuration.report(ERROR, "Unsupported -Xg-generate-debug-tramboline= value: $it. Possible values are 'enable'/'disable'")
null
}
})
@@ -166,11 +166,11 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
var lightDebugDeprecated: Boolean = false
@Argument(
value = "-Xg-generate-inline-function-body-marker",
value = "-Xg-generate-debug-trampoline",
valueDescription = "{disable|enable}",
description = """generates marker of inlined function body on call site to make debugger breakpoint resolution more accurate"""
description = """generates trampolines to make debugger breakpoint resolution more accurate (inlines, when, etc.)"""
)
var generateInlinedFunctionMarkerString: String? = null
var generateDebugTrampolineString: String? = null
@Argument(
@@ -43,7 +43,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
val debug: Boolean get() = configuration.getBoolean(KonanConfigKeys.DEBUG)
val lightDebug: Boolean = configuration.get(KonanConfigKeys.LIGHT_DEBUG)
?: target.family.isAppleFamily // Default is true for Apple targets.
val generateInlinedBodyTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_INLINED_FUNCTION_BODY_MARKER) ?: false
val generateDebugTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_DEBUG_TRAMPOLINE) ?: false
val memoryModel: MemoryModel get() = configuration.get(KonanConfigKeys.MEMORY_MODEL)!!
val destroyRuntimeMode: DestroyRuntimeMode get() = configuration.get(KonanConfigKeys.DESTROY_RUNTIME_MODE)!!
@@ -56,8 +56,8 @@ class KonanConfigKeys {
= CompilerConfigurationKey.create("library version")
val LIGHT_DEBUG: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("add light debug information")
val GENERATE_INLINED_FUNCTION_BODY_MARKER: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("generates inlined function body marker on call site")
val GENERATE_DEBUG_TRAMPOLINE: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("generates debug trampolines to make debugger breakpoint resolution more accurate")
val LINKER_ARGS: CompilerConfigurationKey<List<String>>
= CompilerConfigurationKey.create("additional linker arguments")
val LIST_PHASES: CompilerConfigurationKey<Boolean>
@@ -1177,6 +1177,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
val whenEmittingContext = WhenEmittingContext(expression)
generateDebugTrambolineIf("when", expression)
expression.branches.forEach {
val bbNext = if (it == expression.branches.last())
null
@@ -1196,6 +1197,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}
}
private fun generateDebugTrambolineIf(name: String, expression: IrExpression) {
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
.takeIf { context.config.generateDebugTrampoline }
generationContext?.basicBlock(name, expression.startLocation)?.let {
generationContext.br(it)
generationContext.positionAtEnd(it)
}
}
private fun generateWhenCase(whenEmittingContext: WhenEmittingContext, branch: IrBranch, bbNext: LLVMBasicBlockRef?) {
val brResult = if (isUnconditional(branch))
evaluateExpression(branch.result)
@@ -1818,12 +1828,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
context.log{"evaluateReturnableBlock : ${value.statements.forEach { ir2string(it) }}"}
val returnableBlockScope = ReturnableBlockScope(value)
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
.takeIf { context.config.generateInlinedBodyTrampoline }
generationContext?.basicBlock("inline", value.startLocation)?.let {
generationContext.br(it)
generationContext.positionAtEnd(it)
}
generateDebugTrambolineIf("inline", value)
using(returnableBlockScope) {
using(VariableScope()) {
value.statements.forEach {
@@ -2413,7 +2413,7 @@ standaloneTest("check_stacktrace_format") {
standaloneTest("stack_trace_inline") {
// TODO: Enable after the test has been fixed.
disabled = !isAppleTarget(project) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'ios_arm64')
flags = ['-g', '-Xg-generate-inline-function-body-marker=enable']
flags = ['-g', '-Xg-generate-debug-trampoline=enable']
source = "runtime/exceptions/stack_trace_inline.kt"
}
@@ -146,6 +146,7 @@ class LldbTests {
> b kfun:#a(){}kotlin.String
Breakpoint 2: where = [..]`kfun:#a(){}kotlin.String [..] at a.kt:1:1, [..]
> q
""".trimIndent().lldb(application)
}
@@ -163,13 +164,44 @@ class LldbTests {
|fun main(args: Array<String>) {
| println(question("Subject", args))
|}
""".trimMargin().binary("kt33055", "-g", "-Xg-generate-inline-function-body-marker=enable")
""".trimMargin().binary("kt33055", "-g", "-Xg-generate-debug-trampoline=enable")
"""
> b 2
Breakpoint 1: where = [..]`kfun:#question(kotlin.String;kotlin.Array<kotlin.String>){}kotlin.String [..] at kt33055.kt:2:12, [..]
> q
""".trimIndent().lldb(kt33055)
}
@Test
fun `kt33364`() = lldbComplexTest {
val kt33364 = """
|fun main() {
| val param = 3
|
| //breakpoint here (line: 4, breakpoint is set to 5th line)
| when(param) {
| 1 -> print("A")
| 2 -> print("B")
| else -> print("C")
| }
|
| // breakpoint here (line: 11, breakpoint is set to 12th line)
| when {
| param == 1 -> print("A")
| param == 2 -> print("B")
| else -> print("C")
| }
|}
""".trimMargin().binary("kt33364", "-g", "-Xg-generate-debug-trampoline=enable")
"""
> b 5
Breakpoint 1: where = [..]kfun:#main(){} [..] at kt33364.kt:5:[..]
> b 11
Breakpoint 2: where = [..]kfun:#main(){} [..] at kt33364.kt:12:[..]
> q
""".trimIndent().lldb(kt33364)
}
@Test
fun `kt42208`() = lldbComplexTest {
val kt42208One = """