# HG changeset patch # User lindquist # Date 1213026570 -7200 # Node ID 56199753e637141f7adb676954f27d46697596f7 # Parent b604c56945b096c2a5c357f5afa34e3ddc4aa3ac [svn r264] Fixed debug info for global variables. diff -r b604c56945b0 -r 56199753e637 gen/todebug.cpp --- a/gen/todebug.cpp Mon Jun 09 15:52:22 2008 +0200 +++ b/gen/todebug.cpp Mon Jun 09 17:49:30 2008 +0200 @@ -111,6 +111,10 @@ return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type")); } +static const llvm::StructType* getDwarfGlobalVariableType() { + return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type")); +} + ////////////////////////////////////////////////////////////////////////////////////////////////// LLGlobalVariable* DtoDwarfCompileUnit(Module* m) @@ -486,12 +490,47 @@ ////////////////////////////////////////////////////////////////////////////////////////////////// +LLGlobalVariable* DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) +{ + assert(vd->isDataseg()); + llvm::GlobalVariable* compileUnit = DtoDwarfCompileUnit(gIR->dmodule); + + std::vector vals; + vals.push_back(llvm::ConstantExpr::getAdd( + DtoConstUint(DW_TAG_variable), + DtoConstUint(llvm::LLVMDebugVersion))); + vals.push_back(DBG_CAST(GetDwarfAnchor(DW_TAG_variable))); + + vals.push_back(DBG_CAST(compileUnit)); + + vals.push_back(DtoConstStringPtr(vd->mangle(), "llvm.metadata")); + vals.push_back(DtoConstStringPtr(vd->toPrettyChars(), "llvm.metadata")); + vals.push_back(DtoConstStringPtr(vd->toChars(), "llvm.metadata")); + + vals.push_back(DBG_CAST(DtoDwarfCompileUnit(vd->getModule()))); + vals.push_back(DtoConstUint(vd->loc.linnum)); + + LLGlobalVariable* TY = dwarfTypeDescription(vd->loc, vd->type, compileUnit, NULL); + vals.push_back(TY ? DBG_CAST(TY) : DBG_NULL); + vals.push_back(DtoConstBool(vd->protection == PROTprivate)); + vals.push_back(DtoConstBool(vd->getModule() == gIR->dmodule)); + + vals.push_back(DBG_CAST(ll)); + + LLConstant* c = llvm::ConstantStruct::get(getDwarfGlobalVariableType(), vals); + llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.global_variable", gIR->module); + gv->setSection("llvm.metadata"); + return gv; +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + static LLGlobalVariable* dwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) { unsigned tag; if (vd->isParameter()) tag = DW_TAG_arg_variable; - else if (vd->isCodeseg()) + else if (vd->isDataseg()) assert(0 && "a static variable"); else tag = DW_TAG_auto_variable; diff -r b604c56945b0 -r 56199753e637 gen/todebug.h --- a/gen/todebug.h Mon Jun 09 15:52:22 2008 +0200 +++ b/gen/todebug.h Mon Jun 09 17:49:30 2008 +0200 @@ -18,6 +18,14 @@ */ void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd); +/** + * Emits all things necessary for making debug info for a global variable vd. + * @param ll + * @param vd + * @return + */ +LLGlobalVariable* DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd); + #endif // LLVMDC_GEN_TODEBUG_H diff -r b604c56945b0 -r 56199753e637 gen/toobj.cpp --- a/gen/toobj.cpp Mon Jun 09 15:52:22 2008 +0200 +++ b/gen/toobj.cpp Mon Jun 09 17:49:30 2008 +0200 @@ -574,6 +574,9 @@ DtoConstInitGlobal(this); else gIR->constInitList.push_back(this); + + if (global.params.symdebug) + DtoDwarfGlobalVariable(gvar, this); } // inside aggregate declaration. declare a field. diff -r b604c56945b0 -r 56199753e637 llvmdc.kdevelop.filelist --- a/llvmdc.kdevelop.filelist Mon Jun 09 15:52:22 2008 +0200 +++ b/llvmdc.kdevelop.filelist Mon Jun 09 17:49:30 2008 +0200 @@ -768,6 +768,7 @@ tangotests/debug4.d tangotests/debug5.d tangotests/debug6.d +tangotests/debug7.d tangotests/e.d tangotests/f.d tangotests/files1.d diff -r b604c56945b0 -r 56199753e637 tangotests/debug7.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tangotests/debug7.d Mon Jun 09 17:49:30 2008 +0200 @@ -0,0 +1,9 @@ +module tangotests.debug7; + +int gi; + +void main() +{ + int* fail; + *fail = 0; +}