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 | 446c619f37349815a3ccfb703b1ac08684279ae1 (patch) | |
tree | 81fcb41ac0811ff23b31e956ef3abfb90055b9e4 | |
parent | 75a97cb31903061b96579020905b459fdeb37a49 (diff) |
Appropriately set file name and directory name in debug info compile units.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69387 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 56 | ||||
-rw-r--r-- | lib/CodeGen/CGDebugInfo.h | 2 |
2 files changed, 31 insertions, 27 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index f2fc90c6cf..83719e4681 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/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/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index e9529c4565..1798165dfa 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/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. |