From 82b2b76c099b4a40335051f3d64f3e135ccf09fe Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Wed, 13 Sep 2017 13:52:39 +0300 Subject: [PATCH] [codegen][debug] fix of KT-20207 (problem with accessing structs) - removed artifacts of dwarf type generation, instead debugger will use runtime debugger functions - fixed variable offset calculation --- .../backend/konan/llvm/CodeGenerator.kt | 7 ++--- .../kotlin/backend/konan/llvm/DebugUtils.kt | 11 +------ .../kotlin/backend/konan/llvm/IrToBitcode.kt | 31 ++----------------- 3 files changed, 6 insertions(+), 43 deletions(-) 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 678a3a534eb..00a90a4fa31 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 @@ -504,14 +504,13 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, call(context.llvm.enterFrameFunction, listOf(slots, Int32(slotCount).llvm)) } addPhiIncoming(slotsPhi!!, prologueBb to slots) - val slotOffset = pointerSize * slotCount memScoped { slotToVariableLocation.forEach { slot, variable -> - val expr = longArrayOf(DwarfOp.DW_OP_minus.value, - slotOffset + runtime.pointerSize * slot.toLong()).toCValues() + val expr = longArrayOf(DwarfOp.DW_OP_plus.value, + runtime.pointerSize * slot.toLong()).toCValues() DIInsertDeclaration( builder = codegen.context.debugInfo.builder, - value = slotsPhi, + value = slots, localVariable = variable.localVariable, location = variable.location, bb = prologueBb, 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 0d1a32ca338..52d8b73f5f8 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 @@ -225,20 +225,11 @@ internal fun alignTo(value:Long, align:Long):Long = (value + align - 1) / align internal fun FunctionDescriptor.subroutineType(context: Context, llvmTargetData: LLVMTargetDataRef): DISubroutineTypeRef { return memScoped { DICreateSubroutineType(context.debugInfo.builder, allocArrayOf( - this@subroutineType.types.map { it.referenceOrValue(context, llvmTargetData) }), + this@subroutineType.types.map { it.diType(context, llvmTargetData) }), this@subroutineType.types.size)!! } } -@Suppress("UNCHECKED_CAST") -private fun KotlinType.referenceOrValue(context: Context, llvmTargetData: LLVMTargetDataRef):DITypeOpaqueRef { - val refType = this.dwarfType(context, llvmTargetData) - return if (KotlinBuiltIns.isPrimitiveType(this)) - refType - else - dwarfPointerType(context, refType) -} - @Suppress("UNCHECKED_CAST") private fun dwarfPointerType(context: Context, type: DITypeOpaqueRef) = DICreatePointerType(context.debugInfo.builder, type) as DITypeOpaqueRef 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 90fc7176feb..cfddfc7e624 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 @@ -639,10 +639,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map Unit): Unit { - val doDebugInfo = context.shouldContainDebugInfo() && declaration.descriptor.isExported() - val classScope = currentCodeContext.classScope() as ClassScope - if (doDebugInfo) context.debugInfo.types[declaration.descriptor.defaultType] = classScope.scope!! - body() - memScoped { - if (doDebugInfo) context.debugInfo.types[declaration.descriptor.defaultType] = DICreateStructType( - refBuilder = context.debugInfo.builder, - scope = context.debugInfo.compilationModule as DIScopeOpaqueRef, - name = declaration.descriptor.typeInfoSymbolName, - file = file().file(), - lineNumber = declaration.startLine(), - sizeInBits = 64 /* TODO */, - alignInBits = 4 /* TODO */, - derivedFrom = null, - elements = classScope.members.toCValues(), - elementsCount = classScope.members.size.toLong(), - refPlace = context.debugInfo.types[declaration.descriptor.defaultType] as DICompositeTypeRef, - flags = 0 - ) as DITypeOpaqueRef - } - } - //-------------------------------------------------------------------------// private fun debugFieldDeclaration(expression: IrField) { val scope = currentCodeContext.classScope() as? ClassScope ?: return