diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index fe7a8508883..abca7b02a30 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -150,6 +150,7 @@ class K2Native : CLICompiler() { put(LIST_TARGETS, arguments.listTargets) put(OPTIMIZATION, arguments.optimization) put(DEBUG, arguments.debug) + put(LIGHT_DEBUG, arguments.lightDebug) put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind)) put(PRINT_IR, arguments.printIr) diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index 91f2b2b4358..20bf4a8fb7d 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -133,6 +133,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { ) var frameworkImportHeaders: Array? = null + @Argument(value = "-Xg0", description = "Add light debug information") + var lightDebug: Boolean = false + @Argument(value = "-Xprint-bitcode", deprecatedName = "--print_bitcode", description = "Print llvm bitcode") var printBitCode: Boolean = false diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt index 37f457ce83e..abe48956258 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt @@ -428,6 +428,8 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) { fun shouldProfilePhases() = config.phaseConfig.needProfiling fun shouldContainDebugInfo() = config.debug + fun shouldContainLocationDebugInfo() = shouldContainDebugInfo() || config.lightDebug + fun shouldContainAnyDebugInfo() = shouldContainDebugInfo() || shouldContainLocationDebugInfo() fun shouldOptimize() = config.configuration.getBoolean(KonanConfigKeys.OPTIMIZATION) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index 8ca6b47deea..42af8378942 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -44,7 +44,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration val infoArgsOnly = configuration.kotlinSourceRoots.isEmpty() && !linkOnly + // TODO: debug info generation mode and debug/release variant selection probably requires some refactoring. val debug: Boolean get() = configuration.getBoolean(KonanConfigKeys.DEBUG) + val lightDebug: Boolean get() = configuration.getBoolean(KonanConfigKeys.LIGHT_DEBUG) val memoryModel: MemoryModel get() = configuration.get(KonanConfigKeys.MEMORY_MODEL)!! diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt index da9781bb94a..afd35a32ab8 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt @@ -44,6 +44,8 @@ class KonanConfigKeys { = CompilerConfigurationKey.create("library file paths") val LIBRARY_VERSION: CompilerConfigurationKey = CompilerConfigurationKey.create("library version") + val LIGHT_DEBUG: CompilerConfigurationKey + = CompilerConfigurationKey.create("add light debug information") val LINKER_ARGS: CompilerConfigurationKey> = CompilerConfigurationKey.create("additional linker arguments") val LIST_PHASES: CompilerConfigurationKey diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Linker.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Linker.kt index eac86ab7605..93152557667 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Linker.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Linker.kt @@ -28,7 +28,7 @@ internal class Linker(val context: Context) { private val linker = platform.linker private val target = context.config.target private val optimize = context.shouldOptimize() - private val debug = context.config.debug + private val debug = context.config.debug || context.config.lightDebug // Ideally we'd want to have // #pragma weak main = Konan_main diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt index fa4e850acb1..7c1b12627e2 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt @@ -210,7 +210,7 @@ internal val finalizeDebugInfoPhase = makeKonanModuleOpPhase( name = "FinalizeDebugInfo", description = "Finalize debug info", op = { context, _ -> - if (context.shouldContainDebugInfo()) { + if (context.shouldContainAnyDebugInfo()) { DIFinalize(context.debugInfo.builder) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt index 125425d4368..829791be970 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt @@ -673,7 +673,7 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, } internal fun debugLocation(startLocationInfo: LocationInfo, endLocation: LocationInfo?): DILocationRef? { - if (!context.shouldContainDebugInfo()) return null + if (!context.shouldContainLocationDebugInfo()) return null update(currentBlock, startLocationInfo, endLocation) val debugLocation = codegen.generateLocationInfo(startLocationInfo) currentPositionHolder.setBuilderDebugLocation(debugLocation) @@ -880,7 +880,7 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, } fun resetDebugLocation() { - if (!context.shouldContainDebugInfo()) return + if (!context.shouldContainLocationDebugInfo()) return currentPositionHolder.resetBuilderDebugLocation() } @@ -1057,12 +1057,12 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, } fun resetBuilderDebugLocation() { - if (!context.shouldContainDebugInfo()) return + if (!context.shouldContainLocationDebugInfo()) return LLVMBuilderResetDebugLocation(builder) } fun setBuilderDebugLocation(debugLocation: DILocationRef?) { - if (!context.shouldContainDebugInfo()) return + if (!context.shouldContainLocationDebugInfo()) return LLVMBuilderSetDebugLocation(builder, debugLocation) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt index 038466898df..6d554c044f5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt @@ -116,7 +116,7 @@ internal fun String?.toFileAndFolder():FileAndFolder { } internal fun generateDebugInfoHeader(context: Context) { - if (context.shouldContainDebugInfo()) { + if (context.shouldContainAnyDebugInfo()) { val path = context.config.outputFile .toFileAndFolder() @Suppress("UNCHECKED_CAST") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index a9f23b879d8..2cd22eee524 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -608,7 +608,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map() + + result += Command(linker).apply { +"-demangle" +listOf("-dynamic", "-arch", arch) +osVersionMinFlags @@ -192,7 +196,17 @@ open class MacOSBasedLinker(targetProperties: AppleConfigurables) +libraries +linkerArgs +rpath(dynamic) - }) + if (debug) listOf(dsymUtilCommand(executable, outputDsymBundle)) else emptyList() + } + + // TODO: revise debug information handling. + if (debug) { + result += dsymUtilCommand(executable, outputDsymBundle) + if (optimize) { + result += Command(strip, "-S", executable) + } + } + + return result } private fun rpath(dynamic: Boolean): List = listOfNotNull(