2018-04-10 23:25:04 +08:00
|
|
|
//===- PDBSymbolCompiland.cpp - compiland details ---------------*- C++ -*-===//
|
2015-02-08 08:29:29 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-03-20 05:20:04 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
|
|
|
|
|
2015-02-14 11:53:56 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
2018-03-20 05:20:04 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
|
2018-04-10 23:25:04 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
|
2015-02-23 06:03:38 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
|
2015-02-14 11:53:56 +08:00
|
|
|
|
2018-03-20 05:20:04 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
2015-02-13 17:09:03 +08:00
|
|
|
#include <utility>
|
2015-02-08 08:29:29 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
2016-05-05 04:32:13 +08:00
|
|
|
using namespace llvm::pdb;
|
2015-02-08 08:29:29 +08:00
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const {
|
|
|
|
Dumper.dump(*this);
|
2015-02-08 08:29:29 +08:00
|
|
|
}
|
2016-02-19 02:47:29 +08:00
|
|
|
|
2018-03-20 05:20:04 +08:00
|
|
|
std::string PDBSymbolCompiland::getSourceFileName() const {
|
2018-04-10 23:25:04 +08:00
|
|
|
return sys::path::filename(getSourceFileFullPath()).str();
|
2018-03-20 05:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2016-02-19 02:47:29 +08:00
|
|
|
std::string Var = Env->getName();
|
2018-03-20 05:20:04 +08:00
|
|
|
if (Var == "cwd") {
|
|
|
|
EnvWorkingDir = Env->getValue();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Var == "src") {
|
|
|
|
EnvSrc = Env->getValue();
|
2018-04-10 23:25:04 +08:00
|
|
|
if (sys::path::is_absolute(EnvSrc))
|
2018-03-20 05:20:04 +08:00
|
|
|
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.
|
2018-04-10 23:25:04 +08:00
|
|
|
if (sys::path::is_absolute(Path))
|
2018-03-20 05:20:04 +08:00
|
|
|
SourceFileFullPath = Path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RecordedResult.empty()) {
|
2018-04-10 23:25:04 +08:00
|
|
|
if (sys::path::is_absolute(RecordedResult))
|
2018-03-20 05:20:04 +08:00
|
|
|
return RecordedResult;
|
|
|
|
|
|
|
|
// This searches name that has same basename as the one in RecordedResult.
|
2018-04-10 23:25:04 +08:00
|
|
|
auto OneSrcFile = Session.findOneSourceFile(
|
|
|
|
this, RecordedResult, PDB_NameSearchFlags::NS_CaseInsensitive);
|
2018-03-20 05:20:04 +08:00
|
|
|
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();
|
2018-04-10 23:25:04 +08:00
|
|
|
auto file_extension = sys::path::extension(FileName);
|
2018-03-20 05:20:04 +08:00
|
|
|
if (StringSwitch<bool>(file_extension.lower())
|
2018-04-10 23:25:04 +08:00
|
|
|
.Case(".cpp", LangC)
|
|
|
|
.Case(".c", LangC)
|
|
|
|
.Case(".cc", LangC)
|
|
|
|
.Case(".cxx", LangC)
|
|
|
|
.Case(".asm", Lang == PDB_Lang::Masm)
|
|
|
|
.Default(false))
|
2018-03-20 05:20:04 +08:00
|
|
|
return File->getFileName();
|
2016-02-19 02:47:29 +08:00
|
|
|
}
|
2018-03-20 05:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return SourceFileFullPath;
|
2016-02-19 02:47:29 +08:00
|
|
|
}
|