changeset 955:8a70b4381369

Make sure debug info uses the right compilation units - in particular the current cu if a symbol is a template instance. Fixes #211.
author Christian Kamm <kamm incasoftware de>
date Sat, 14 Feb 2009 21:18:47 +0100
parents e048e36bc155
children 369996c08420
files gen/structs.cpp gen/todebug.cpp
diffstat 2 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gen/structs.cpp	Sat Feb 14 15:25:48 2009 +0100
+++ b/gen/structs.cpp	Sat Feb 14 21:18:47 2009 +0100
@@ -642,7 +642,7 @@
     gIR->structs.pop_back();
 
     // emit typeinfo
-    if (sd->getCompilationModule() == gIR->dmodule && sd->llvmInternal != LLVMno_typeinfo)
+    if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMno_typeinfo)
         DtoTypeInfoOf(sd->type, false);
 }
 
--- a/gen/todebug.cpp	Sat Feb 14 15:25:48 2009 +0100
+++ b/gen/todebug.cpp	Sat Feb 14 21:18:47 2009 +0100
@@ -11,6 +11,7 @@
 #include "gen/irstate.h"
 #include "gen/tollvm.h"
 #include "gen/logger.h"
+#include "gen/llvmhelpers.h"
 
 #include "ir/irmodule.h"
 
@@ -85,6 +86,16 @@
     return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type"));
 }
 
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+// get the module the symbol is in, or - for template instances - the current module
+static Module* getDefinedModule(Dsymbol* s)
+{
+    if (!DtoIsTemplateInstance(s))
+        return s->getModule();
+    else
+	return gIR->dmodule;
+}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -269,7 +280,7 @@
 
         name = DtoConstStringPtr(sd->toChars(), "llvm.metadata");
         linnum = sd->loc.linnum;
-        definedCU = DtoDwarfCompileUnit(sd->getCompilationModule());
+        definedCU = DtoDwarfCompileUnit(getDefinedModule(sd));
 
         std::vector<LLConstant*> elems;
         if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one
@@ -361,11 +372,11 @@
         vd->mangle(), // name
         vd->toPrettyChars(), // displayname
         vd->toChars(), // linkage name
-        DtoDwarfCompileUnit(vd->getCompilationModule()), // compile unit
+        DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit
         vd->loc.linnum, // line num
         dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type
         vd->protection == PROTprivate, // is local to unit
-        vd->getCompilationModule() == gIR->dmodule, // is definition
+        getDefinedModule(vd) == gIR->dmodule, // is definition
         ll // value
     );
 }
@@ -386,7 +397,7 @@
         tag, // tag
         gIR->func()->diSubprogram, // context
         vd->toChars(), // name
-        DtoDwarfCompileUnit(vd->getCompilationModule()), // compile unit
+        DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit
         vd->loc.linnum, // line num
         type // type
     );
@@ -434,9 +445,7 @@
 
     // get compile units
     llvm::DICompileUnit thisCU = DtoDwarfCompileUnit(gIR->dmodule);
-    llvm::DICompileUnit varCU = thisCU;
-    if (vd->getCompilationModule() != gIR->dmodule)
-        varCU = DtoDwarfCompileUnit(vd->getCompilationModule());
+    llvm::DICompileUnit varCU = DtoDwarfCompileUnit(getDefinedModule(vd));
 
     // get type description
     llvm::DIType TD = dwarfTypeDescription(vd->type, thisCU, NULL);
@@ -499,7 +508,7 @@
     LOG_SCOPE;
 
     llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule);
-    llvm::DICompileUnit definition = DtoDwarfCompileUnit(fd->getCompilationModule());
+    llvm::DICompileUnit definition = DtoDwarfCompileUnit(getDefinedModule(fd));
 
     // FIXME: duplicates ?
     return gIR->difactory.CreateSubprogram(
@@ -581,7 +590,7 @@
     LOG_SCOPE;
 
     gIR->difactory.InsertStopPoint(
-        DtoDwarfCompileUnit(gIR->func()->decl->getCompilationModule()), // compile unit
+        DtoDwarfCompileUnit(getDefinedModule(gIR->func()->decl)), // compile unit
         ln, // line no
         0, // col no
         gIR->scopebb()