[cfe-commits] r109507 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h

Devang Patel dpatel at apple.com
Tue Jul 27 08:17:16 PDT 2010


Author: dpatel
Date: Tue Jul 27 10:17:16 2010
New Revision: 109507

URL: http://llvm.org/viewvc/llvm-project?rev=109507&view=rev
Log:
Reapply 109303. 

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=109507&r1=109506&r2=109507&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Jul 27 10:17:16 2010
@@ -148,13 +148,8 @@
       return llvm::DIFile(cast<llvm::MDNode>(it->second));
   }
 
-  // FIXME: We shouldn't even need to call 'makeAbsolute()' in the cases
-  // where we can consult the FileEntry.
-  llvm::sys::Path AbsFileName(PLoc.getFilename());
-  AbsFileName.makeAbsolute();
-
-  llvm::DIFile F = DebugFactory.CreateFile(AbsFileName.getLast(),
-                                           AbsFileName.getDirname(), TheCU);
+  llvm::DIFile F = DebugFactory.CreateFile(PLoc.getFilename(),
+                                           getCurrentDirname(), TheCU);
 
   DIFileCache[fname] = F;
   return F;
@@ -179,6 +174,25 @@
   return PLoc.getColumn();
 }
 
+llvm::StringRef CGDebugInfo::getCurrentDirname() {
+  if (!CWDName.empty())
+    return CWDName;
+  char *CompDirnamePtr = NULL;
+  llvm::sys::Path CWD = llvm::sys::Path::GetCurrentDirectory();
+  CompDirnamePtr = DebugInfoNames.Allocate<char>(CWD.size());
+  memcpy(CompDirnamePtr, CWD.c_str(), CWD.size());
+  return CWDName = llvm::StringRef(CompDirnamePtr, CWD.size());
+}
+
+/// getCompDirname -  AT_comp_dir is empty if filename is absulte otherwise 
+/// it points to compilation directory.
+llvm::StringRef CGDebugInfo::getCompDirname(llvm::StringRef Filename) {
+  llvm::sys::Path FilePath(Filename);
+  if (FilePath.isAbsolute())
+    return llvm::StringRef();
+  return getCurrentDirname();
+}
+
 /// CreateCompileUnit - Create new compile unit.
 void CGDebugInfo::CreateCompileUnit() {
 
@@ -188,19 +202,22 @@
   if (MainFileName.empty())
     MainFileName = "<unknown>";
 
-  llvm::sys::Path AbsFileName(MainFileName);
-  AbsFileName.makeAbsolute();
-
   // The main file name provided via the "-main-file-name" option contains just
   // the file name itself with no path information. This file name may have had
   // a relative path, so we look into the actual file entry for the main
   // file to determine the real absolute path for the file.
   std::string MainFileDir;
-  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID()))
+  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
     MainFileDir = MainFile->getDir()->getName();
-  else
-    MainFileDir = AbsFileName.getDirname();
+    if (MainFileDir != ".")
+      MainFileName = MainFileDir + "/" + MainFileName;
+  }
 
+  // Save filename string.
+  char *FilenamePtr = DebugInfoNames.Allocate<char>(MainFileName.length());
+  memcpy(FilenamePtr, MainFileName.c_str(), MainFileName.length());
+  llvm::StringRef Filename(FilenamePtr, MainFileName.length());
+  
   unsigned LangTag;
   const LangOptions &LO = CGM.getLangOptions();
   if (LO.CPlusPlus) {
@@ -229,7 +246,8 @@
 
   // Create new compile unit.
   TheCU = DebugFactory.CreateCompileUnit(
-    LangTag, AbsFileName.getLast(), MainFileDir, Producer, true,
+    LangTag, Filename, getCompDirname(Filename),
+    Producer, true,
     LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers);
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=109507&r1=109506&r2=109507&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Jul 27 10:17:16 2010
@@ -70,6 +70,7 @@
   /// DebugInfoNames - This is a storage for names that are
   /// constructed on demand. For example, C++ destructors, C++ operators etc..
   llvm::BumpPtrAllocator DebugInfoNames;
+  llvm::StringRef CWDName;
 
   llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
   llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
@@ -198,6 +199,13 @@
   llvm::DIDescriptor getContextDescriptor(const Decl *Decl,
                                           llvm::DIDescriptor &CU);
 
+  /// getCompDirname -  AT_comp_dir is empty if filename is absulte otherwise 
+  /// it points to compilation directory.
+  llvm::StringRef getCompDirname(llvm::StringRef Filename);
+
+  /// getCurrentDirname - Return current directory name.
+  llvm::StringRef getCurrentDirname();
+
   /// CreateCompileUnit - Create new compile unit.
   void CreateCompileUnit();
 





More information about the cfe-commits mailing list