LLVM  7.0.0svn
PDBSymbolCompiland.cpp
Go to the documentation of this file.
1 //===- PDBSymbolCompiland.cpp - compiland details ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 
17 
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/Support/Path.h"
20 #include <utility>
21 
22 using namespace llvm;
23 using namespace llvm::pdb;
24 
26  std::unique_ptr<IPDBRawSymbol> Symbol)
27  : PDBSymbol(PDBSession, std::move(Symbol)) {
28  assert(RawSymbol->getSymTag() == PDB_SymType::Compiland);
29 }
30 
32  Dumper.dump(*this);
33 }
34 
37 }
38 
40  std::string SourceFileFullPath;
41 
42  // RecordedResult could be the basename, relative path or full path of the
43  // source file. Usually it is retrieved and recorded from the command that
44  // compiles this compiland.
45  //
46  // cmd FileName -> RecordedResult = .\\FileName
47  // cmd (Path)\\FileName -> RecordedResult = (Path)\\FileName
48  //
49  std::string RecordedResult = RawSymbol->getSourceFileName();
50 
51  if (RecordedResult.empty()) {
52  if (auto Envs = findAllChildren<PDBSymbolCompilandEnv>()) {
53  std::string EnvWorkingDir, EnvSrc;
54 
55  while (auto Env = Envs->getNext()) {
56  std::string Var = Env->getName();
57  if (Var == "cwd") {
58  EnvWorkingDir = Env->getValue();
59  continue;
60  }
61  if (Var == "src") {
62  EnvSrc = Env->getValue();
63  if (sys::path::is_absolute(EnvSrc))
64  return EnvSrc;
65  RecordedResult = EnvSrc;
66  continue;
67  }
68  }
69  if (!EnvWorkingDir.empty() && !EnvSrc.empty()) {
70  auto Len = EnvWorkingDir.length();
71  if (EnvWorkingDir[Len - 1] != '/' && EnvWorkingDir[Len - 1] != '\\') {
72  std::string Path = EnvWorkingDir + "\\" + EnvSrc;
73  std::replace(Path.begin(), Path.end(), '/', '\\');
74  // We will return it as full path if we can't find a better one.
75  if (sys::path::is_absolute(Path))
76  SourceFileFullPath = Path;
77  }
78  }
79  }
80  }
81 
82  if (!RecordedResult.empty()) {
83  if (sys::path::is_absolute(RecordedResult))
84  return RecordedResult;
85 
86  // This searches name that has same basename as the one in RecordedResult.
87  auto OneSrcFile = Session.findOneSourceFile(
88  this, RecordedResult, PDB_NameSearchFlags::NS_CaseInsensitive);
89  if (OneSrcFile)
90  return OneSrcFile->getFileName();
91  }
92 
93  // At this point, we have to walk through all source files of this compiland,
94  // and determine the right source file if any that is used to generate this
95  // compiland based on language indicated in compilanddetails language field.
96  auto Details = findOneChild<PDBSymbolCompilandDetails>();
97  PDB_Lang Lang = Details ? Details->getLanguage() : PDB_Lang::Cpp;
98  auto SrcFiles = Session.getSourceFilesForCompiland(*this);
99  if (SrcFiles) {
100  bool LangC = (Lang == PDB_Lang::Cpp || Lang == PDB_Lang::C);
101  while (auto File = SrcFiles->getNext()) {
102  std::string FileName = File->getFileName();
103  auto file_extension = sys::path::extension(FileName);
104  if (StringSwitch<bool>(file_extension.lower())
105  .Case(".cpp", LangC)
106  .Case(".c", LangC)
107  .Case(".cc", LangC)
108  .Case(".cxx", LangC)
109  .Case(".asm", Lang == PDB_Lang::Masm)
110  .Default(false))
111  return File->getFileName();
112  }
113  }
114 
115  return SourceFileFullPath;
116 }
uint64_t CallInst * C
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:26
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
std::string getSourceFileFullPath() const
void dump(PDBSymDumper &Dumper) const override
Dumps the contents of a symbol a raw_ostream.
std::unique_ptr< IPDBRawSymbol > RawSymbol
Definition: PDBSymbol.h:134
Definition: BitVector.h:921
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:679
virtual std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const =0
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
Definition: StringSwitch.h:203
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
PDBSymbolCompiland(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > CompilandSymbol)
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx.
Definition: CodeView.h:144
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:61
virtual std::unique_ptr< IPDBSourceFile > findOneSourceFile(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const =0
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:70
std::string getSourceFileName() const
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:581
virtual void dump(const PDBSymbolAnnotation &Symbol)
const IPDBSession & Session
Definition: PDBSymbol.h:133
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Expected< std::string > replace(StringRef S, StringRef From, StringRef To)
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
Definition: Path.cpp:596