From abb485f0b58dd3d2da20f9b34f99695899a68cf2 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 1 Feb 2010 19:16:32 +0000 Subject: Emit debug info for namespaces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94991 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/CodeGen/CGDebugInfo.cpp') diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index b0f2c0fa42..36b3a8390f 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -57,6 +57,8 @@ llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *D, I = RegionMap.find(Parent); if (I != RegionMap.end()) return llvm::DIDescriptor(dyn_cast_or_null(I->second)); + if (const NamespaceDecl *NSDecl = dyn_cast(Parent)) + return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit)); } return CompileUnit; } @@ -1802,3 +1804,26 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, Var->hasInternalLinkage(), true/*definition*/, Var); } + +/// getOrCreateNamesSpace - Return namespace descriptor for the given +/// namespace decl. +llvm::DINameSpace +CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, + llvm::DIDescriptor Unit) { + llvm::DenseMap::iterator I = + NameSpaceCache.find(NSDecl); + if (I != NameSpaceCache.end()) + return llvm::DINameSpace(cast(I->second)); + + SourceManager &SM = CGM.getContext().getSourceManager(); + PresumedLoc PLoc = SM.getPresumedLoc(NSDecl->getLocation()); + unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); + + llvm::DIDescriptor Context = + getContextDescriptor(NSDecl, Unit); + llvm::DINameSpace NS = + DebugFactory.CreateNameSpace(Context, NSDecl->getName(), + llvm::DICompileUnit(Unit.getNode()), LineNo); + NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode()); + return NS; +} -- cgit v1.2.3-18-g5258