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 1598a88afd7..173f36a9c2c 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 @@ -47,11 +47,10 @@ internal object DWARF { } internal class DebugInfo internal constructor(override val context: Context):ContextUtils { - val files = mutableMapOf() - val subprograms = mutableMapOf() + val files = mutableMapOf() + val subprograms = mutableMapOf() var builder: DIBuilderRef? = null var module: DIModuleRef? = null - var compilationModule: DICompileUnitRef? = null var types = mutableMapOf() val llvmTypes = mapOf( @@ -110,15 +109,6 @@ internal fun generateDebugInfoHeader(context: Context) { configurationMacro = "", includePath = "", iSysRoot = "") - context.debugInfo.compilationModule = DICreateCompilationUnit( - builder = context.debugInfo.builder, - lang = DwarfLanguage.DW_LANG_Kotlin.value, - File = path.file, - dir = path.folder, - producer = DWARF.producer, - isOptimized = 0, - flags = "", - rv = DWARF.runtimeVersion) /* TODO: figure out what here 2 means: * * 0:b-backend-dwarf:minamoto@minamoto-osx(0)# cat /dev/null | clang -xc -S -emit-llvm -g -o - - @@ -158,7 +148,8 @@ internal fun KotlinType.dwarfType(context:Context, targetData:LLVMTargetDataRef) classDescriptor != null -> { val type = DICreateStructType( refBuilder = context.debugInfo.builder, - scope = context.debugInfo.compilationModule as DIScopeOpaqueRef, + // TODO: here should be DIFile as scope. + scope = null, name = "ObjHeader", file = null, lineNumber = 0, @@ -217,10 +208,15 @@ internal fun KotlinType.encoding(context:Context):DwarfTypeKind = when { internal fun alignTo(value:Long, align:Long):Long = (value + align - 1) / align * align internal fun FunctionDescriptor.subroutineType(context: Context, llvmTargetData: LLVMTargetDataRef): DISubroutineTypeRef { + val types = this@subroutineType.types + return subroutineType(context, llvmTargetData, types) +} + +internal fun subroutineType(context: Context, llvmTargetData: LLVMTargetDataRef, types: List): DISubroutineTypeRef { return memScoped { DICreateSubroutineType(context.debugInfo.builder, allocArrayOf( - this@subroutineType.types.map { it.diType(context, llvmTargetData) }), - this@subroutineType.types.size)!! + types.map { it.diType(context, llvmTargetData) }), + types.size)!! } } 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 9871980b061..f3e8a699291 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 @@ -209,6 +209,23 @@ internal interface CodeContext { fun classScope(): CodeContext? fun addResumePoint(bbLabel: LLVMBasicBlockRef): Int + + /** + * Returns owning returnable block scope [ReturnableBlockScope]. + * + * @returns the requested value if in the returnableBlockScope scope or null. + */ + fun returnableBlockScope(): CodeContext? + + /** + * Returns location information for given source location [LocationInfo]. + */ + fun location(line:Int, column: Int): LocationInfo? + + /** + * Returns [DIScopeOpaqueRef] instance for corresponding scope. + */ + fun scope(): DIScopeOpaqueRef? } //-------------------------------------------------------------------------// @@ -254,6 +271,12 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map debugInfoLocalVariableLocation( builder = context.debugInfo.builder, - functionScope = functionScope, + functionScope = locationInfo.scope, diType = element.descriptor.type.diType(context, codegen.llvmTargetData), name = element.descriptor.name, file = file, @@ -1123,7 +1155,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map debugInfoParameterLocation( builder = context.debugInfo.builder, - functionScope = functionScope, + functionScope = locationInfo.scope, diType = element.descriptor.type.diType(context, codegen.llvmTargetData), name = element.descriptor.name, argNo = (element.descriptor as? ValueParameterDescriptor)?.index ?: 0, @@ -1413,7 +1445,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map #include #include "DebugInfoC.h" - - /** * c++ --std=c++11 llvmDebugInfoC/src/DebugInfoC.cpp -IllvmDebugInfoC/include/ -Idependencies/all/clang+llvm-3.9.0-darwin-macos/include -Ldependencies/all/clang+llvm-3.9.0-darwin-macos/lib -lLLVMCore -lLLVMSupport -lncurses -shared -o libLLVMDebugInfoC.dylib */ @@ -102,6 +100,15 @@ DISubprogramRef DICreateFunction(DIBuilderRef builder, DIScopeOpaqueRef scope, scopeLine)); } +DIScopeOpaqueRef DICreateLexicalBlockFile(DIBuilderRef builderRef, DIScopeOpaqueRef scopeRef, DIFileRef fileRef) { + return llvm::wrap(llvm::unwrap(builderRef)->createLexicalBlockFile(llvm::unwrap(scopeRef), llvm::unwrap(fileRef))); +} + +DIScopeOpaqueRef DICreateLexicalBlock(DIBuilderRef builderRef, DIScopeOpaqueRef scopeRef, DIFileRef fileRef, int line, int column) { + return llvm::wrap(llvm::unwrap(builderRef)->createLexicalBlock(llvm::unwrap(scopeRef), llvm::unwrap(fileRef), line, column)); +} + + DICompositeTypeRef DICreateStructType(DIBuilderRef refBuilder, DIScopeOpaqueRef scope, const char *name, DIFileRef file, unsigned lineNumber, @@ -277,6 +284,5 @@ const char *DIGetSubprogramLinkName(DISubprogramRef sp) { int DISubprogramDescribesFunction(DISubprogramRef sp, LLVMValueRef fn) { return llvm::unwrap(sp)->describes(llvm::cast(llvm::unwrap(fn))); } - } /* extern "C" */ diff --git a/llvmDebugInfoC/src/main/include/DebugInfoC.h b/llvmDebugInfoC/src/main/include/DebugInfoC.h index f1b4edf5a57..951131d46fe 100644 --- a/llvmDebugInfoC/src/main/include/DebugInfoC.h +++ b/llvmDebugInfoC/src/main/include/DebugInfoC.h @@ -84,6 +84,10 @@ DIModuleRef DICreateModule(DIBuilderRef builder, DIScopeOpaqueRef scope, const char* name, const char* configurationMacro, const char* includePath, const char *iSysRoot); +DIScopeOpaqueRef DICreateLexicalBlockFile(DIBuilderRef builderRef, DIScopeOpaqueRef scopeRef, DIFileRef fileRef); + +DIScopeOpaqueRef DICreateLexicalBlock(DIBuilderRef builderRef, DIScopeOpaqueRef scopeRef, DIFileRef fileRef, int line, int column); + DISubprogramRef DICreateFunction(DIBuilderRef builder, DIScopeOpaqueRef scope, const char* name, const char *linkageName, DIFileRef file, unsigned lineNo, @@ -107,7 +111,6 @@ const char* LLVMBuilderGetCurrentBbName(LLVMBuilderRef builder); const char *DIGetSubprogramLinkName(DISubprogramRef sp); LLVMValueRef LLVMBuilderGetCurrentFunction(LLVMBuilderRef builder); int DISubprogramDescribesFunction(DISubprogramRef sp, LLVMValueRef fn); -//void DIScopeDump(DIScopeOpaqueRef scope); # ifdef __cplusplus } # endif