# HG changeset patch # User Christian Kamm # Date 1234642727 -3600 # Node ID 8a70b4381369ea12b2a34a377f878dbefc75af32 # Parent e048e36bc1559c6e293c5e8273dba7d079940a2a Make sure debug info uses the right compilation units - in particular the current cu if a symbol is a template instance. Fixes #211. diff -r e048e36bc155 -r 8a70b4381369 gen/structs.cpp --- 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); } diff -r e048e36bc155 -r 8a70b4381369 gen/todebug.cpp --- 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 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()