diff options
author | Devang Patel <dpatel@apple.com> | 2009-04-17 21:06:59 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-04-17 21:06:59 +0000 |
commit | 75009454e328c663bccf6be53f4f1a279c592563 (patch) | |
tree | 10044127f3d183e57c90aad244e7d1b8ce8900e6 | |
parent | 6395285306e00d7e09129485fe5b7fd0f6f86cd7 (diff) | |
download | bcm5719-llvm-75009454e328c663bccf6be53f4f1a279c592563.tar.gz bcm5719-llvm-75009454e328c663bccf6be53f4f1a279c592563.zip |
Appropriately set file name and directory name in debug info compile units.
llvm-svn: 69387
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 56 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.h | 2 |
2 files changed, 31 insertions, 27 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index f2fc90c6cfb..83719e4681a 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Dwarf.h" +#include "llvm/System/Path.h" #include "llvm/Target/TargetMachine.h" using namespace clang; using namespace clang::CodeGen; @@ -48,37 +49,39 @@ void CGDebugInfo::setLocation(SourceLocation Loc) { /// 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) { - // FIXME: Until we do a complete job of emitting debug information, - // we need to support making dummy compile units so that we generate - // "well formed" debug info. - const FileEntry *FE = 0; - + // Get source file information. + const char *FileName = "<unknown>"; SourceManager &SM = M->getContext().getSourceManager(); - bool isMain; + unsigned FID; if (Loc.isValid()) { - Loc = SM.getInstantiationLoc(Loc); - FE = SM.getFileEntryForID(SM.getFileID(Loc)); - isMain = SM.getFileID(Loc) == SM.getMainFileID(); - } else { - // If Loc is not valid then use main file id. - FE = SM.getFileEntryForID(SM.getMainFileID()); - isMain = true; + PresumedLoc PLoc = SM.getPresumedLoc(Loc); + FileName = PLoc.getFilename(); + FID = PLoc.getIncludeLoc().getRawEncoding(); } // See if this compile unit has been used before. - llvm::DICompileUnit &Unit = CompileUnitCache[FE]; + llvm::DICompileUnit &Unit = CompileUnitCache[FID]; if (!Unit.isNull()) return Unit; - - // Get source file information. - const char *FileName = FE ? FE->getName() : "<unknown>"; - const char *DirName = FE ? FE->getDir()->getName() : "<unknown>"; - - const LangOptions &LO = M->getLangOptions(); - // If this is the main file, use the user provided main file name if - // specified. - if (isMain && LO.getMainFileName()) - FileName = LO.getMainFileName(); + // Get absolute path name. + llvm::sys::Path AbsFileName(FileName); + if (!AbsFileName.isAbsolute()) { + llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory(); + tmp.appendComponent(FileName); + AbsFileName = tmp; + } + + // See if thie compile unit is represnting main source file. + bool isMain = false; + const LangOptions &LO = M->getLangOptions(); + const char *MainFileName = LO.getMainFileName(); + if (MainFileName) { + if (!strcmp(AbsFileName.getLast().c_str(), MainFileName)) + isMain = true; + } else { + if (Loc.isValid() && SM.isFromMainFile(Loc)) + isMain = true; + } unsigned LangTag; if (LO.CPlusPlus) { @@ -93,12 +96,13 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { } else { LangTag = llvm::dwarf::DW_LANG_C89; } - + // Create new compile unit. // FIXME: Do not know how to get clang version yet. // FIXME: Encode command line options. // FIXME: Encode optimization level. - return Unit = DebugFactory.CreateCompileUnit(LangTag, FileName, DirName, + return Unit = DebugFactory.CreateCompileUnit(LangTag, AbsFileName.getLast(), + AbsFileName.getDirname(), "clang", isMain); } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index e9529c45652..1798165dfa1 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -39,7 +39,7 @@ class CGDebugInfo { SourceLocation CurLoc, PrevLoc; /// CompileUnitCache - Cache of previously constructed CompileUnits. - llvm::DenseMap<const FileEntry*, llvm::DICompileUnit> CompileUnitCache; + llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache; /// TypeCache - Cache of previously constructed Types. // FIXME: Eliminate this map. Be careful of iterator invalidation. |