changeset 247:56199753e637 trunk

[svn r264] Fixed debug info for global variables.
author lindquist
date Mon, 09 Jun 2008 17:49:30 +0200
parents b604c56945b0
children 890b4862ec6c
files gen/todebug.cpp gen/todebug.h gen/toobj.cpp llvmdc.kdevelop.filelist tangotests/debug7.d
diffstat 5 files changed, 61 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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<LLConstant*> 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;
--- 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
 
 
--- 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.
--- 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
--- /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;
+}