[NFC] Update memcpy tests
[llvm-complete.git] / lib / DebugInfo / PDB / Native / NativeSession.cpp
blob5fb2ea3fec5db2859b17f9aedac7db232e6e25fc
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 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
15 #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
16 #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
17 #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
18 #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
19 #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
20 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
21 #include "llvm/DebugInfo/PDB/Native/RawError.h"
22 #include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
23 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
27 #include "llvm/Support/Allocator.h"
28 #include "llvm/Support/BinaryByteStream.h"
29 #include "llvm/Support/Error.h"
30 #include "llvm/Support/ErrorOr.h"
31 #include "llvm/Support/MemoryBuffer.h"
33 #include <algorithm>
34 #include <cassert>
35 #include <memory>
36 #include <utility>
38 using namespace llvm;
39 using namespace llvm::msf;
40 using namespace llvm::pdb;
42 static DbiStream *getDbiStreamPtr(PDBFile &File) {
43 Expected<DbiStream &> DbiS = File.getPDBDbiStream();
44 if (DbiS)
45 return &DbiS.get();
47 consumeError(DbiS.takeError());
48 return nullptr;
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)) {}
56 NativeSession::~NativeSession() = default;
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);
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;
71 Session =
72 llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
74 return Error::success();
77 Error NativeSession::createFromExe(StringRef Path,
78 std::unique_ptr<IPDBSession> &Session) {
79 return make_error<RawError>(raw_error_code::feature_unsupported);
82 uint64_t NativeSession::getLoadAddress() const { return 0; }
84 bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
86 std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
87 return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope());
90 std::unique_ptr<PDBSymbol>
91 NativeSession::getSymbolById(SymIndexId SymbolId) const {
92 return Cache.getSymbolById(SymbolId);
95 bool NativeSession::addressForVA(uint64_t VA, uint32_t &Section,
96 uint32_t &Offset) const {
97 return false;
100 bool NativeSession::addressForRVA(uint32_t VA, uint32_t &Section,
101 uint32_t &Offset) const {
102 return false;
105 std::unique_ptr<PDBSymbol>
106 NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
107 return nullptr;
110 std::unique_ptr<PDBSymbol>
111 NativeSession::findSymbolByRVA(uint32_t RVA, PDB_SymType Type) const {
112 return nullptr;
115 std::unique_ptr<PDBSymbol>
116 NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset,
117 PDB_SymType Type) const {
118 return nullptr;
121 std::unique_ptr<IPDBEnumLineNumbers>
122 NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
123 const IPDBSourceFile &File) const {
124 return nullptr;
127 std::unique_ptr<IPDBEnumLineNumbers>
128 NativeSession::findLineNumbersByAddress(uint64_t Address,
129 uint32_t Length) const {
130 return nullptr;
133 std::unique_ptr<IPDBEnumLineNumbers>
134 NativeSession::findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const {
135 return nullptr;
138 std::unique_ptr<IPDBEnumLineNumbers>
139 NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset,
140 uint32_t Length) const {
141 return nullptr;
144 std::unique_ptr<IPDBEnumSourceFiles>
145 NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
146 StringRef Pattern,
147 PDB_NameSearchFlags Flags) const {
148 return nullptr;
151 std::unique_ptr<IPDBSourceFile>
152 NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
153 StringRef Pattern,
154 PDB_NameSearchFlags Flags) const {
155 return nullptr;
158 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
159 NativeSession::findCompilandsForSourceFile(StringRef Pattern,
160 PDB_NameSearchFlags Flags) const {
161 return nullptr;
164 std::unique_ptr<PDBSymbolCompiland>
165 NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
166 PDB_NameSearchFlags Flags) const {
167 return nullptr;
170 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
171 return nullptr;
174 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
175 const PDBSymbolCompiland &Compiland) const {
176 return nullptr;
179 std::unique_ptr<IPDBSourceFile>
180 NativeSession::getSourceFileById(uint32_t FileId) const {
181 return nullptr;
184 std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
185 return nullptr;
188 std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const {
189 return nullptr;
192 std::unique_ptr<IPDBEnumInjectedSources>
193 NativeSession::getInjectedSources() const {
194 return nullptr;
197 std::unique_ptr<IPDBEnumSectionContribs>
198 NativeSession::getSectionContribs() const {
199 return nullptr;
202 std::unique_ptr<IPDBEnumFrameData>
203 NativeSession::getFrameData() const {
204 return nullptr;
207 void NativeSession::initializeExeSymbol() {
208 if (ExeSymbol == 0)
209 ExeSymbol = Cache.createSymbol<NativeExeSymbol>();
212 NativeExeSymbol &NativeSession::getNativeGlobalScope() const {
213 const_cast<NativeSession &>(*this).initializeExeSymbol();
215 return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol);