[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
This commit is contained in:
Vasily Levchenko
2017-09-13 13:52:39 +03:00
committed by Vasily Levchenko
parent b367a0d255
commit 82b2b76c09
3 changed files with 6 additions and 43 deletions
@@ -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,
@@ -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
@@ -639,10 +639,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
return
}
using(ClassScope(declaration)) {
debugClassDeclaration(declaration) {
declaration.declarations.forEach {
it.acceptVoid(this)
}
declaration.declarations.forEach {
it.acceptVoid(this)
}
}
}
@@ -1690,31 +1688,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
//-------------------------------------------------------------------------//
private fun IrElement.endColumn() = file().fileEntry.column(this.endOffset)
//-------------------------------------------------------------------------//
@Suppress("UNCHECKED_CAST")
private fun debugClassDeclaration(declaration: IrClass, body: () -> 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