LLVM  8.0.1
NativeSession.cpp
Go to the documentation of this file.
1 //===- NativeSession.cpp - Native implementation of IPDBSession -*- 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 
11 
12 #include "llvm/ADT/STLExtras.h"
28 #include "llvm/Support/Allocator.h"
30 #include "llvm/Support/Error.h"
31 #include "llvm/Support/ErrorOr.h"
33 
34 #include <algorithm>
35 #include <cassert>
36 #include <memory>
37 #include <utility>
38 
39 using namespace llvm;
40 using namespace llvm::msf;
41 using namespace llvm::pdb;
42 
45  if (DbiS)
46  return &DbiS.get();
47 
48  consumeError(DbiS.takeError());
49  return nullptr;
50 }
51 
52 NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
53  std::unique_ptr<BumpPtrAllocator> Allocator)
54  : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)),
55  Cache(*this, getDbiStreamPtr(*Pdb)) {}
56 
58 
59 Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
60  std::unique_ptr<IPDBSession> &Session) {
61  StringRef Path = Buffer->getBufferIdentifier();
62  auto Stream = llvm::make_unique<MemoryBufferByteStream>(
63  std::move(Buffer), llvm::support::little);
64 
65  auto Allocator = llvm::make_unique<BumpPtrAllocator>();
66  auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
67  if (auto EC = File->parseFileHeaders())
68  return EC;
69  if (auto EC = File->parseStreamData())
70  return EC;
71 
72  Session =
73  llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
74 
75  return Error::success();
76 }
77 
79  std::unique_ptr<IPDBSession> &Session) {
80  return make_error<RawError>(raw_error_code::feature_unsupported);
81 }
82 
83 uint64_t NativeSession::getLoadAddress() const { return 0; }
84 
85 bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
86 
87 std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
88  return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope());
89 }
90 
91 std::unique_ptr<PDBSymbol>
93  return Cache.getSymbolById(SymbolId);
94 }
95 
97  uint32_t &Offset) const {
98  return false;
99 }
100 
102  uint32_t &Offset) const {
103  return false;
104 }
105 
106 std::unique_ptr<PDBSymbol>
108  return nullptr;
109 }
110 
111 std::unique_ptr<PDBSymbol>
113  return nullptr;
114 }
115 
116 std::unique_ptr<PDBSymbol>
118  PDB_SymType Type) const {
119  return nullptr;
120 }
121 
122 std::unique_ptr<IPDBEnumLineNumbers>
124  const IPDBSourceFile &File) const {
125  return nullptr;
126 }
127 
128 std::unique_ptr<IPDBEnumLineNumbers>
130  uint32_t Length) const {
131  return nullptr;
132 }
133 
134 std::unique_ptr<IPDBEnumLineNumbers>
136  return nullptr;
137 }
138 
139 std::unique_ptr<IPDBEnumLineNumbers>
141  uint32_t Length) const {
142  return nullptr;
143 }
144 
145 std::unique_ptr<IPDBEnumSourceFiles>
147  StringRef Pattern,
148  PDB_NameSearchFlags Flags) const {
149  return nullptr;
150 }
151 
152 std::unique_ptr<IPDBSourceFile>
154  StringRef Pattern,
155  PDB_NameSearchFlags Flags) const {
156  return nullptr;
157 }
158 
159 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
161  PDB_NameSearchFlags Flags) const {
162  return nullptr;
163 }
164 
165 std::unique_ptr<PDBSymbolCompiland>
167  PDB_NameSearchFlags Flags) const {
168  return nullptr;
169 }
170 
171 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
172  return nullptr;
173 }
174 
175 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
176  const PDBSymbolCompiland &Compiland) const {
177  return nullptr;
178 }
179 
180 std::unique_ptr<IPDBSourceFile>
182  return nullptr;
183 }
184 
185 std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
186  return nullptr;
187 }
188 
189 std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const {
190  return nullptr;
191 }
192 
193 std::unique_ptr<IPDBEnumInjectedSources>
195  return nullptr;
196 }
197 
198 std::unique_ptr<IPDBEnumSectionContribs>
200  return nullptr;
201 }
202 
203 std::unique_ptr<IPDBEnumFrameData>
205  return nullptr;
206 }
207 
208 void NativeSession::initializeExeSymbol() {
209  if (ExeSymbol == 0)
210  ExeSymbol = Cache.createSymbol<NativeExeSymbol>();
211 }
212 
214  const_cast<NativeSession &>(*this).initializeExeSymbol();
215 
216  return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol);
217 }
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const override
This class represents lattice values for constants.
Definition: AllocatorList.h:24
std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const override
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:101
Error takeError()
Take ownership of the stored error.
Definition: Error.h:553
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override
IPDBSourceFile defines an interface used to represent source files whose information are stored in th...
std::unique_ptr< IPDBEnumSourceFiles > findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: BitVector.h:938
NativeExeSymbol & getNativeGlobalScope() const
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
static DbiStream * getDbiStreamPtr(PDBFile &File)
std::unique_ptr< IPDBEnumFrameData > getFrameData() const override
std::unique_ptr< IPDBEnumTables > getEnumTables() const override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
Definition: PDBTypes.h:183
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const override
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
std::unique_ptr< PDBSymbol > findSymbolByRVA(uint32_t RVA, PDB_SymType Type) const override
uint64_t getLoadAddress() const override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const override
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:982
Expected< DbiStream & > getPDBDbiStream()
Definition: PDBFile.cpp:287
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) const override
Basic Register Allocator
static ErrorSuccess success()
Create a success value.
Definition: Error.h:327
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
SymIndexId createSymbol(Args &&... ConstructorArgs)
Definition: SymbolCache.h:86
reference get()
Returns a reference to the stored T value.
Definition: Error.h:533
NativeRawSymbol & getNativeSymbolById(SymIndexId SymbolId) const
std::unique_ptr< PDBSymbolExe > getGlobalScope() override
bool setLoadAddress(uint64_t Address) override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
std::unique_ptr< PDBSymbolCompiland > findOneCompilandForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > findCompilandsForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Provides ErrorOr<T> smart pointer.
std::unique_ptr< IPDBSourceFile > findOneSourceFile(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
static Error createFromPdb(std::unique_ptr< MemoryBuffer > MB, std::unique_ptr< IPDBSession > &Session)
bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const override
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
std::unique_ptr< IPDBEnumInjectedSources > getInjectedSources() const override