[DI] compilation unit generated on file compilation, instead of file reference

This commit is contained in:
Vasily Levchenko
2019-12-20 20:27:32 +01:00
parent b065a35545
commit 58aad06f14
@@ -501,7 +501,20 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
context.llvm.objects.clear()
context.llvm.sharedObjects.clear()
using(FileScope(declaration)) {
val compilationUnit = if (context.shouldContainLocationDebugInfo()) {
val path = declaration.fileEntry.name.toFileAndFolder()
DICreateCompilationUnit(
builder = context.debugInfo.builder,
lang = DWARF.language(context.config),
File = path.file,
dir = path.folder,
producer = DWARF.producer,
isOptimized = 0,
flags = "",
rv = DWARF.runtimeVersion(context.config))
} else null
@Suppress("UNCHECKED_CAST")
using(FileScope(declaration, compilationUnit as DIScopeOpaqueRef?)) {
declaration.acceptChildrenVoid(this)
if (context.llvm.fileInitializers.isEmpty() && context.llvm.objects.isEmpty() && context.llvm.sharedObjects.isEmpty())
@@ -1752,7 +1765,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
//-------------------------------------------------------------------------//
private open inner class FileScope(val file: IrFile) : InnerScopeImpl() {
private open inner class FileScope(val file: IrFile, private val compilationUnit: DIScopeOpaqueRef? = null) : InnerScopeImpl() {
override fun fileScope(): CodeContext? = this
override fun location(line: Int, column: Int) = scope()?.let { LocationInfo(it, line, column) }
@@ -1765,6 +1778,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}
override fun scope() = scope
fun diCompilationUnit(): DIScopeOpaqueRef? = compilationUnit ?:
(this.outerContext.fileScope() as? FileScope)?.diCompilationUnit() ?:
error("no compilation unit found")
}
//-------------------------------------------------------------------------//
@@ -1921,15 +1938,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
private fun IrFile.file(): DIFileRef {
return context.debugInfo.files.getOrPut(this.fileEntry.name) {
val path = this.fileEntry.name.toFileAndFolder()
DICreateCompilationUnit(
builder = context.debugInfo.builder,
lang = DWARF.language(context.config),
File = path.file,
dir = path.folder,
producer = DWARF.producer,
isOptimized = 0,
flags = "",
rv = DWARF.runtimeVersion(context.config))
DICreateFile(context.debugInfo.builder, path.file, path.folder)!!
}
}
@@ -1981,7 +1989,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
@Suppress("UNCHECKED_CAST")
private fun diFunctionScope(name: String, linkageName: String, startLine: Int, subroutineType: DISubroutineTypeRef) = DICreateFunction(
builder = context.debugInfo.builder,
scope = (currentCodeContext.fileScope() as FileScope).file.file() as DIScopeOpaqueRef,
scope = (currentCodeContext.fileScope() as FileScope).diCompilationUnit(),
name = name,
linkageName = linkageName,
file = file().file(),