]> granicus.if.org Git - clang/commitdiff
Set appropriate context for a global variable while emitting debug info.
authorDevang Patel <dpatel@apple.com>
Tue, 6 Oct 2009 00:35:31 +0000 (00:35 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 6 Oct 2009 00:35:31 +0000 (00:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83352 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h

index 7d0c1ad8a55f38876cea678fde37aac905cde575..be742d9b8067dc5e62ad814b0451e60b937ffc24 100644 (file)
@@ -49,6 +49,22 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
     CurLoc = M->getContext().getSourceManager().getInstantiationLoc(Loc);
 }
 
+/// getContext - Get context info for the decl.
+llvm::DIDescriptor CGDebugInfo::getContext(const VarDecl *Decl,
+                                           llvm::DIDescriptor &CompileUnit) {
+  if (Decl->isFileVarDecl())
+    return CompileUnit;
+  if (Decl->getDeclContext()->isFunctionOrMethod()) {
+    // Find the last subprogram in region stack.
+    for (unsigned RI = RegionStack.size(), RE = 0; RI != RE; --RI) {
+      llvm::DIDescriptor R = RegionStack[RI - 1];
+      if (R.isSubprogram())
+        return R;
+    }
+  }
+  return CompileUnit;
+}
+
 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a new
 /// one if necessary. This returns null for invalid source locations.
 llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
@@ -1327,7 +1343,8 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
                                            ArrayType::Normal, 0);
   }
 
-  DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo,
+  DebugFactory.CreateGlobalVariable(getContext(Decl, Unit), 
+                                    Name, Name, "", Unit, LineNo,
                                     getOrCreateType(T, Unit),
                                     Var->hasInternalLinkage(),
                                     true/*definition*/, Var);
index 17237ddfc650ccd6fa9fe8c3245da7bcb6da7884..ff8ec0574c27e6a5efdf711679228acb7c722e6b 100644 (file)
@@ -131,6 +131,9 @@ private:
   void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI,
                    CGBuilderTy &Builder, CodeGenFunction *CGF);
 
+  /// getContext - Get context info for the decl.
+  llvm::DIDescriptor getContext(const VarDecl *Decl,llvm::DIDescriptor &CU);
+
   /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
   /// new one if necessary.
   llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);