[cfe-commits] r69387 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h
Devang Patel
dpatel at apple.com
Fri Apr 17 14:07:00 PDT 2009
Author: dpatel
Date: Fri Apr 17 16:06:59 2009
New Revision: 69387
URL: http://llvm.org/viewvc/llvm-project?rev=69387&view=rev
Log:
Appropriately set file name and directory name in debug info compile units.
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=69387&r1=69386&r2=69387&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 17 16:06:59 2009
@@ -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 @@
/// 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 @@
} 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);
}
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=69387&r1=69386&r2=69387&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri Apr 17 16:06:59 2009
@@ -39,7 +39,7 @@
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.
More information about the cfe-commits
mailing list