aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGDebugInfo.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2010-07-27 15:17:16 +0000
committerDevang Patel <dpatel@apple.com>2010-07-27 15:17:16 +0000
commitac4d13c0cc78a3b28a8af8001e4da6b18fa9029d (patch)
tree3a9198cde72f7a29944acf9f0ac21e9760d4b03d /lib/CodeGen/CGDebugInfo.cpp
parent28233428da1ebec20c893d6297ae3191318940dd (diff)
Reapply 109303.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109507 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r--lib/CodeGen/CGDebugInfo.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 753cdcddd2..0309c6e09b 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -148,13 +148,8 @@ llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
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 @@ unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc) {
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 @@ void CGDebugInfo::CreateCompileUnit() {
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 @@ void CGDebugInfo::CreateCompileUnit() {
// 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);
}