From 0bd4dbc0c16899ec5a554895af57bd3a80cae760 Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Fri, 8 Oct 2021 15:05:03 +0300 Subject: [PATCH] [K/N] Disable debug info in runtime by default Bundle grows 200mb if debug info is enabled, it's too much. But probably, this can be useful for debug, so we need gradle option. --- buildSrc/src/main/kotlin/BuildPropertiesExt.kt | 3 +++ kotlin-native/HACKING.md | 9 +++++++++ .../runtime/exceptions/stack_trace_out_of_bounds.kt | 8 +++++--- .../org/jetbrains/kotlin/bitcode/CompileToBitcode.kt | 6 +++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildPropertiesExt.kt b/buildSrc/src/main/kotlin/BuildPropertiesExt.kt index 2c6e0259cec..2b01333a588 100644 --- a/buildSrc/src/main/kotlin/BuildPropertiesExt.kt +++ b/buildSrc/src/main/kotlin/BuildPropertiesExt.kt @@ -33,3 +33,6 @@ val KotlinBuildProperties.pathToYoutrackModularizedTestData: String? val KotlinBuildProperties.isObsoleteJdkOverrideEnabled: Boolean get() = getBoolean("kotlin.build.isObsoleteJdkOverrideEnabled", false) + +val KotlinBuildProperties.isNativeRuntimeDebugInfoEnabled: Boolean + get() = getBoolean("kotlin.native.isNativeRuntimeDebugInfoEnabled", false) \ No newline at end of file diff --git a/kotlin-native/HACKING.md b/kotlin-native/HACKING.md index a3d92a7f6e0..d91353a9209 100644 --- a/kotlin-native/HACKING.md +++ b/kotlin-native/HACKING.md @@ -162,6 +162,15 @@ To generate a compilation database for the Kotlin/Native runtime, run the Gradle This task generates `/kotlin-native/compile_commands.json` file that should be opened in CLion as project. Other developer tools also can use generated compilation database, but then `clangd` tool should be installed manually. +Also, it's possible to build Kotlin/Native runtime with dwarf debug information, which can be useful for debugging. +To do this you should add `kotlin.native.isNativeRuntimeDebugInfoEnabled=true` line to `local.properties` file. Note, that changing +this property requires clean compiler rebuild with gradle daemon restart. + +Unfortunately, this feature works quite unstable because of using several llvm versions simultaneously, +so it's need to be additionally enabled while compiling application with `-Xbinary=stripDebugInfoFromNativeLibs=false` +compiler flag or corresponding setting in gradle build script. After doing this, Kotlin/Native runtime in application +is debuggable in CLion, with Attach to process tool. + ## Performance measurement Firstly, it's necessary to build analyzer tool to have opportunity to compare different performance results: diff --git a/kotlin-native/backend.native/tests/runtime/exceptions/stack_trace_out_of_bounds.kt b/kotlin-native/backend.native/tests/runtime/exceptions/stack_trace_out_of_bounds.kt index f1b023f53f8..7461878fe83 100644 --- a/kotlin-native/backend.native/tests/runtime/exceptions/stack_trace_out_of_bounds.kt +++ b/kotlin-native/backend.native/tests/runtime/exceptions/stack_trace_out_of_bounds.kt @@ -21,14 +21,16 @@ internal val goldValues = arrayOf( "Exceptions.kt" to null, "Exceptions.kt" to null, "RuntimeUtils.kt" to null, - "Arrays.cpp" to null, + null, "stack_trace_out_of_bounds.kt" to 7, "stack_trace_out_of_bounds.kt" to 4, - "launcher.cpp" to null, + null, ) internal fun checkFrame(value:String) { - val (pos, file, line) = regex.find(value)!!.destructured + val pos = value.split(" ")[0] goldValues[pos.toInt()]?.let{ + val (pos_, file, line) = regex.find(value)!!.destructured + assertEquals(pos_, pos) assertEquals(it.first, file) if (it.second != null) { assertEquals(it.second, line.toInt()) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt index 01405c2a406..5ff07fb9bd2 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt @@ -16,6 +16,8 @@ import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.SanitizerKind import java.io.File import javax.inject.Inject +import kotlinBuildProperties +import isNativeRuntimeDebugInfoEnabled open class CompileToBitcode @Inject constructor( @Internal val srcRoot: File, @@ -85,7 +87,9 @@ open class CompileToBitcode @Inject constructor( @get:Input val compilerFlags: List get() { - val commonFlags = listOf("-gdwarf-2", "-c", "-emit-llvm") + headersDirs.map { "-I$it" } + val commonFlags = listOfNotNull( + "-gdwarf-2".takeIf { project.kotlinBuildProperties.isNativeRuntimeDebugInfoEnabled }, + "-c", "-emit-llvm") + headersDirs.map { "-I$it" } val sanitizerFlags = when (sanitizer) { null -> listOf() SanitizerKind.ADDRESS -> listOf("-fsanitize=address")