LLVM  9.0.0svn
NativeSession.cpp
Go to the documentation of this file.
1 //===- NativeSession.cpp - Native implementation of IPDBSession -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "llvm/ADT/STLExtras.h"
27 #include "llvm/Support/Allocator.h"
29 #include "llvm/Support/Error.h"
30 #include "llvm/Support/ErrorOr.h"
32 
33 #include <algorithm>
34 #include <cassert>
35 #include <memory>
36 #include <utility>
37 
38 using namespace llvm;
39 using namespace llvm::msf;
40 using namespace llvm::pdb;
41 
44  if (DbiS)
45  return &DbiS.get();
46 
47  consumeError(DbiS.takeError());
48  return nullptr;
49 }
50 
51 NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
52  std::unique_ptr<BumpPtrAllocator> Allocator)
53  : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)),
54  Cache(*this, getDbiStreamPtr(*Pdb)) {}
55 
57 
58 Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
59  std::unique_ptr<IPDBSession> &Session) {
60  StringRef Path = Buffer->getBufferIdentifier();
61  auto Stream = llvm::make_unique<MemoryBufferByteStream>(
62  std::move(Buffer), llvm::support::little);
63 
64  auto Allocator = llvm::make_unique<BumpPtrAllocator>();
65  auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
66  if (auto EC = File->parseFileHeaders())
67  return EC;
68  if (auto EC = File->parseStreamData())
69  return EC;
70 
71  Session =
72  llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
73 
74  return Error::success();
75 }
76 
78  std::unique_ptr<IPDBSession> &Session) {
79  return make_error<RawError>(raw_error_code::feature_unsupported);
80 }
81 
82 uint64_t NativeSession::getLoadAddress() const { return 0; }
83 
84 bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
85 
86 std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
87  return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope());
88 }
89 
90 std::unique_ptr<PDBSymbol>
92  return Cache.getSymbolById(SymbolId);
93 }
94 
96  uint32_t &Offset) const {
97  return false;
98 }
99 
101  uint32_t &Offset) const {
102  return false;
103 }
104 
105 std::unique_ptr<PDBSymbol>
107  return nullptr;
108 }
109 
110 std::unique_ptr<PDBSymbol>
112  return nullptr;
113 }
114 
115 std::unique_ptr<PDBSymbol>
117  PDB_SymType Type) const {
118  return nullptr;
119 }
120 
121 std::unique_ptr<IPDBEnumLineNumbers>
123  const IPDBSourceFile &File) const {
124  return nullptr;
125 }
126 
127 std::unique_ptr<IPDBEnumLineNumbers>
129  uint32_t Length) const {
130  return nullptr;
131 }
132 
133 std::unique_ptr<IPDBEnumLineNumbers>
135  return nullptr;
136 }
137 
138 std::unique_ptr<IPDBEnumLineNumbers>
140  uint32_t Length) const {
141  return nullptr;
142 }
143 
144 std::unique_ptr<IPDBEnumSourceFiles>
146  StringRef Pattern,
147  PDB_NameSearchFlags Flags) const {
148  return nullptr;
149 }
150 
151 std::unique_ptr<IPDBSourceFile>
153  StringRef Pattern,
154  PDB_NameSearchFlags Flags) const {
155  return nullptr;
156 }
157 
158 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
160  PDB_NameSearchFlags Flags) const {
161  return nullptr;
162 }
163 
164 std::unique_ptr<PDBSymbolCompiland>
166  PDB_NameSearchFlags Flags) const {
167  return nullptr;
168 }
169 
170 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
171  return nullptr;
172 }
173 
174 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
175  const PDBSymbolCompiland &Compiland) const {
176  return nullptr;
177 }
178 
179 std::unique_ptr<IPDBSourceFile>
181  return nullptr;
182 }
183 
184 std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
185  return nullptr;
186 }
187 
188 std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const {
189  return nullptr;
190 }
191 
192 std::unique_ptr<IPDBEnumInjectedSources>
194  return nullptr;
195 }
196 
197 std::unique_ptr<IPDBEnumSectionContribs>
199  return nullptr;
200 }
201 
202 std::unique_ptr<IPDBEnumFrameData>
204  return nullptr;
205 }
206 
207 void NativeSession::initializeExeSymbol() {
208  if (ExeSymbol == 0)
209  ExeSymbol = Cache.createSymbol<NativeExeSymbol>();
210 }
211 
213  const_cast<NativeSession &>(*this).initializeExeSymbol();
214 
215  return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol);
216 }
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:23
std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const override
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:100
Error takeError()
Take ownership of the stored error.
Definition: Error.h:552
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:937
NativeExeSymbol & getNativeGlobalScope() const
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
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:182
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:45
Instrumentation for Order File
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:981
Expected< DbiStream & > getPDBDbiStream()
Definition: PDBFile.cpp:286
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:326
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
SymIndexId createSymbol(Args &&... ConstructorArgs)
Definition: SymbolCache.h:85
reference get()
Returns a reference to the stored T value.
Definition: Error.h:532
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:157
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:48
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