[llvm] r327910 - [PDB] Add a method to get the full path of the source file for PDBSymbolCompiland
Aaron Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 19 14:20:04 PDT 2018
Author: asmith
Date: Mon Mar 19 14:20:04 2018
New Revision: 327910
URL: http://llvm.org/viewvc/llvm-project?rev=327910&view=rev
Log:
[PDB] Add a method to get the full path of the source file for PDBSymbolCompiland
Summary:
Redefine PDBSymbolCompiland::getSourceFileName() to return the filename (w/o directory) of the source file that is used to compile the compiland. This is because the result returned previously is ambiguous. It could be the filename, relative path or full path of the source file.
Move the implementation of SymbolFilePDB::GetSourceFileNameForPDBCompiland() into a new method PDBSymbolCompiland::getSourceFileFullPath().
Reviewers: zturner, rnk, llvm-commits
Reviewed By: zturner
Differential Revision: https://reviews.llvm.org/D44458
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h
llvm/trunk/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h?rev=327910&r1=327909&r2=327910&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h Mon Mar 19 14:20:04 2018
@@ -34,6 +34,7 @@ public:
FORWARD_SYMBOL_METHOD(getName)
std::string getSourceFileName() const;
+ std::string getSourceFileFullPath() const;
};
}
}
Modified: llvm/trunk/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp?rev=327910&r1=327909&r2=327910&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp Mon Mar 19 14:20:04 2018
@@ -7,11 +7,16 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/PDB/IPDBSession.h"
+#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
+
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
-
+#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Path.h"
#include <utility>
using namespace llvm;
@@ -27,20 +32,86 @@ void PDBSymbolCompiland::dump(PDBSymDump
Dumper.dump(*this);
}
-std::string PDBSymbolCompiland::getSourceFileName() const
-{
- std::string Result = RawSymbol->getSourceFileName();
- if (!Result.empty())
- return Result;
- auto Envs = findAllChildren<PDBSymbolCompilandEnv>();
- if (!Envs)
- return std::string();
- while (auto Env = Envs->getNext()) {
+std::string PDBSymbolCompiland::getSourceFileName() const {
+ return llvm::sys::path::filename(getSourceFileFullPath()).str();
+}
+
+std::string PDBSymbolCompiland::getSourceFileFullPath() const {
+ std::string SourceFileFullPath;
+
+ // RecordedResult could be the basename, relative path or full path of the
+ // source file. Usually it is retrieved and recorded from the command that
+ // compiles this compiland.
+ //
+ // cmd FileName -> RecordedResult = .\\FileName
+ // cmd (Path)\\FileName -> RecordedResult = (Path)\\FileName
+ //
+ std::string RecordedResult = RawSymbol->getSourceFileName();
+
+ if (RecordedResult.empty()) {
+ if (auto Envs = findAllChildren<PDBSymbolCompilandEnv>()) {
+ std::string EnvWorkingDir, EnvSrc;
+
+ while (auto Env = Envs->getNext()) {
std::string Var = Env->getName();
- if (Var != "src")
- continue;
- std::string Value = Env->getValue();
- return Value;
+ if (Var == "cwd") {
+ EnvWorkingDir = Env->getValue();
+ continue;
+ }
+ if (Var == "src") {
+ EnvSrc = Env->getValue();
+ if (llvm::sys::path::is_absolute(EnvSrc))
+ return EnvSrc;
+ RecordedResult = EnvSrc;
+ continue;
+ }
+ }
+ if (!EnvWorkingDir.empty() && !EnvSrc.empty()) {
+ auto Len = EnvWorkingDir.length();
+ if (EnvWorkingDir[Len - 1] != '/' && EnvWorkingDir[Len - 1] != '\\') {
+ std::string Path = EnvWorkingDir + "\\" + EnvSrc;
+ std::replace(Path.begin(), Path.end(), '/', '\\');
+ // We will return it as full path if we can't find a better one.
+ if (llvm::sys::path::is_absolute(Path))
+ SourceFileFullPath = Path;
+ }
+ }
+ }
+ }
+
+ if (!RecordedResult.empty()) {
+ if (llvm::sys::path::is_absolute(RecordedResult))
+ return RecordedResult;
+
+ // This searches name that has same basename as the one in RecordedResult.
+ auto OneSrcFile =
+ Session.findOneSourceFile(this, RecordedResult,
+ PDB_NameSearchFlags::NS_CaseInsensitive);
+ if (OneSrcFile)
+ return OneSrcFile->getFileName();
+ }
+
+ // At this point, we have to walk through all source files of this compiland,
+ // and determine the right source file if any that is used to generate this
+ // compiland based on language indicated in compilanddetails language field.
+ auto Details = findOneChild<PDBSymbolCompilandDetails>();
+ PDB_Lang Lang = Details ? Details->getLanguage() : PDB_Lang::Cpp;
+ auto SrcFiles = Session.getSourceFilesForCompiland(*this);
+ if (SrcFiles) {
+ bool LangC = (Lang == PDB_Lang::Cpp || Lang == PDB_Lang::C);
+ while (auto File = SrcFiles->getNext()) {
+ std::string FileName = File->getFileName();
+ auto file_extension = llvm::sys::path::extension(FileName);
+ if (StringSwitch<bool>(file_extension.lower())
+ .Case(".cpp", LangC)
+ .Case(".c", LangC)
+ .Case(".cc", LangC)
+ .Case(".cxx", LangC)
+ .Case(".asm", Lang == PDB_Lang::Masm)
+ .Default(false))
+ return File->getFileName();
}
- return std::string();
+ }
+
+ return SourceFileFullPath;
}
More information about the llvm-commits
mailing list