[cfe-commits] r51993 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h CGDecl.cpp CodeGenModule.cpp
Sanjiv Gupta
sanjiv.gupta at microchip.com
Thu Jun 5 01:59:10 PDT 2008
Author: sgupta
Date: Thu Jun 5 03:59:10 2008
New Revision: 51993
URL: http://llvm.org/viewvc/llvm-project?rev=51993&view=rev
Log:
Emit debug information for global and static variables when -g is specified.
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=51993&r1=51992&r2=51993&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Jun 5 03:59:10 2008
@@ -43,8 +43,10 @@
, RegionEndFn(NULL)
, CompileUnitAnchor(NULL)
, SubprogramAnchor(NULL)
+, GlobalVariableAnchor(NULL)
, RegionStack()
, VariableDescList()
+, GlobalVarDescList(NULL)
, Subprogram(NULL)
{
SR = new llvm::DISerializer();
@@ -79,8 +81,14 @@
delete *I;
}
+ for (std::vector<llvm::GlobalVariableDesc *>::iterator I
+ = GlobalVarDescList.begin(); I != GlobalVarDescList.end(); ++I) {
+ delete *I;
+ }
+
delete CompileUnitAnchor;
delete SubprogramAnchor;
+ delete GlobalVariableAnchor;
}
void CGDebugInfo::setLocation(SourceLocation loc)
@@ -566,3 +574,41 @@
Builder.CreateCall2(DeclareFn, AllocACast, getCastValueFor(Variable), "");
}
+/// EmitGlobalVariable - Emit information about a global variable.
+void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *GV,
+ const VarDecl *decl)
+{
+ // Create global variable debug descriptor.
+ llvm::GlobalVariableDesc *Global = new llvm::GlobalVariableDesc();
+
+ // Push it onto the list so that we can free it.
+ GlobalVarDescList.push_back(Global);
+
+ // Make sure we have an anchor.
+ if (!GlobalVariableAnchor)
+ GlobalVariableAnchor = new llvm::AnchorDesc(Global);
+
+ // Get name information.
+ Global->setName(decl->getName());
+ Global->setFullName(decl->getName());
+
+ llvm::CompileUnitDesc *Unit = getOrCreateCompileUnit(CurLoc);
+ SourceManager &SM = M->getContext().getSourceManager();
+ uint64_t Loc = SM.getLogicalLineNumber(CurLoc);
+
+ llvm::TypeDesc *TyD = getOrCreateType(decl->getType(), Unit);
+
+ // Fill in the Global information.
+ Global->setAnchor(GlobalVariableAnchor);
+ Global->setContext(Unit);
+ Global->setFile(Unit);
+ Global->setLine(Loc);
+ Global->setType(TyD);
+ Global->setIsDefinition(true);
+ Global->setIsStatic(GV->hasInternalLinkage());
+ Global->setGlobalVariable(GV);
+
+ // Make sure global is created if needed.
+ getValueFor(Global);
+}
+
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=51993&r1=51992&r2=51993&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Jun 5 03:59:10 2008
@@ -32,6 +32,8 @@
class TypeDesc;
class VariableDesc;
class SubprogramDesc;
+ class GlobalVariable;
+ class GlobalVariableDesc;
}
namespace clang {
@@ -63,8 +65,10 @@
llvm::Function *RegionEndFn;
llvm::AnchorDesc *CompileUnitAnchor;
llvm::AnchorDesc *SubprogramAnchor;
+ llvm::AnchorDesc *GlobalVariableAnchor;
std::vector<llvm::DebugInfoDesc *> RegionStack;
std::vector<llvm::VariableDesc *> VariableDescList;
+ std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
llvm::SubprogramDesc *Subprogram;
/// Helper functions for getOrCreateType.
@@ -105,6 +109,9 @@
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
llvm::IRBuilder &Builder);
+
+ /// EmitGlobalVariable - Emit information about a global variable.
+ void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
/// getOrCreateCompileUnit - Get the compile unit from the cache or create a
/// new one if necessary.
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=51993&r1=51992&r2=51993&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Jun 5 03:59:10 2008
@@ -116,6 +116,15 @@
}
DMEntry = GV;
+
+ // Emit global variable debug descriptor for static vars.
+ CGDebugInfo *DI = CGM.getDebugInfo();
+ if(DI) {
+ if(D.getLocation().isValid())
+ DI->setLocation(D.getLocation());
+ DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(GV), &D);
+ }
+
}
/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=51993&r1=51992&r2=51993&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jun 5 03:59:10 2008
@@ -739,6 +739,14 @@
break;
}
}
+
+ // Emit global variable debug information.
+ CGDebugInfo *DI = getDebugInfo();
+ if(DI) {
+ if(D->getLocation().isValid())
+ DI->setLocation(D->getLocation());
+ DI->EmitGlobalVariable(GV, D);
+ }
}
/// EmitGlobalVarDeclarator - Emit all the global vars attached to the specified
More information about the cfe-commits
mailing list