Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 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 | |
| 10 | #include "llvm/DebugInfo/PDB/Native/NativeSession.h" |
| 11 | |
| 12 | #include "llvm/ADT/STLExtras.h" |
Adrian McCarthy | 8d090fc | 2017-07-12 19:38:11 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 15 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" |
Adrian McCarthy | bf0afc3 | 2017-06-28 22:47:40 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h" |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" |
Zachary Turner | 5d62996 | 2018-09-07 00:12:56 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" |
| 20 | #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 22 | #include "llvm/DebugInfo/PDB/Native/RawError.h" |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 23 | #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/PDB/Native/TpiStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
| 26 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Allocator.h" |
Zachary Turner | d9dc282 | 2017-03-02 20:52:51 +0000 | [diff] [blame] | 29 | #include "llvm/Support/BinaryByteStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Error.h" |
| 31 | #include "llvm/Support/ErrorOr.h" |
| 32 | #include "llvm/Support/MemoryBuffer.h" |
Adrian McCarthy | bf0afc3 | 2017-06-28 22:47:40 +0000 | [diff] [blame] | 33 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 34 | #include <algorithm> |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 35 | #include <cassert> |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 36 | #include <memory> |
Adrian McCarthy | bf0afc3 | 2017-06-28 22:47:40 +0000 | [diff] [blame] | 37 | #include <utility> |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace llvm; |
| 40 | using namespace llvm::msf; |
| 41 | using namespace llvm::pdb; |
| 42 | |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 43 | static DbiStream *getDbiStreamPtr(PDBFile &File) { |
| 44 | Expected<DbiStream &> DbiS = File.getPDBDbiStream(); |
| 45 | if (DbiS) |
| 46 | return &DbiS.get(); |
| 47 | |
| 48 | consumeError(DbiS.takeError()); |
| 49 | return nullptr; |
| 50 | } |
Adrian McCarthy | 8d090fc | 2017-07-12 19:38:11 +0000 | [diff] [blame] | 51 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 52 | NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, |
| 53 | std::unique_ptr<BumpPtrAllocator> Allocator) |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 54 | : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)), |
| 55 | Cache(*this, getDbiStreamPtr(*Pdb)) {} |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 56 | |
| 57 | NativeSession::~NativeSession() = default; |
| 58 | |
Peter Collingbourne | 75257bc | 2017-10-20 19:48:26 +0000 | [diff] [blame] | 59 | Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer, |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 60 | std::unique_ptr<IPDBSession> &Session) { |
Peter Collingbourne | 75257bc | 2017-10-20 19:48:26 +0000 | [diff] [blame] | 61 | StringRef Path = Buffer->getBufferIdentifier(); |
Zachary Turner | 695ed56 | 2017-02-28 00:04:07 +0000 | [diff] [blame] | 62 | auto Stream = llvm::make_unique<MemoryBufferByteStream>( |
| 63 | std::move(Buffer), llvm::support::little); |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 64 | |
| 65 | auto Allocator = llvm::make_unique<BumpPtrAllocator>(); |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 66 | auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator); |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 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 | |
| 78 | Error NativeSession::createFromExe(StringRef Path, |
| 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 | |
Aaron Smith | 89a19ac | 2018-02-23 00:02:27 +0000 | [diff] [blame] | 85 | bool NativeSession::setLoadAddress(uint64_t Address) { return false; } |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 86 | |
Adrian McCarthy | 6a4b080 | 2017-06-22 18:42:23 +0000 | [diff] [blame] | 87 | std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() { |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 88 | return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope()); |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | std::unique_ptr<PDBSymbol> |
Zachary Turner | cae73458 | 2018-09-10 21:30:59 +0000 | [diff] [blame] | 92 | NativeSession::getSymbolById(SymIndexId SymbolId) const { |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 93 | return Cache.getSymbolById(SymbolId); |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Aaron Smith | 53708a5 | 2018-03-26 22:10:02 +0000 | [diff] [blame] | 96 | bool NativeSession::addressForVA(uint64_t VA, uint32_t &Section, |
| 97 | uint32_t &Offset) const { |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | bool NativeSession::addressForRVA(uint32_t VA, uint32_t &Section, |
| 102 | uint32_t &Offset) const { |
| 103 | return false; |
| 104 | } |
| 105 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 106 | std::unique_ptr<PDBSymbol> |
| 107 | NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { |
| 108 | return nullptr; |
| 109 | } |
| 110 | |
Aaron Smith | 3dca0be | 2018-04-10 17:33:18 +0000 | [diff] [blame] | 111 | std::unique_ptr<PDBSymbol> |
| 112 | NativeSession::findSymbolByRVA(uint32_t RVA, PDB_SymType Type) const { |
| 113 | return nullptr; |
| 114 | } |
| 115 | |
| 116 | std::unique_ptr<PDBSymbol> |
| 117 | NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, |
| 118 | PDB_SymType Type) const { |
| 119 | return nullptr; |
| 120 | } |
| 121 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 122 | std::unique_ptr<IPDBEnumLineNumbers> |
| 123 | NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland, |
| 124 | const IPDBSourceFile &File) const { |
| 125 | return nullptr; |
| 126 | } |
| 127 | |
| 128 | std::unique_ptr<IPDBEnumLineNumbers> |
| 129 | NativeSession::findLineNumbersByAddress(uint64_t Address, |
| 130 | uint32_t Length) const { |
| 131 | return nullptr; |
| 132 | } |
| 133 | |
Aaron Smith | 40198f5 | 2018-03-15 06:04:51 +0000 | [diff] [blame] | 134 | std::unique_ptr<IPDBEnumLineNumbers> |
Aaron Smith | ed81a9d | 2018-03-26 22:13:22 +0000 | [diff] [blame] | 135 | NativeSession::findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const { |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | std::unique_ptr<IPDBEnumLineNumbers> |
Aaron Smith | 40198f5 | 2018-03-15 06:04:51 +0000 | [diff] [blame] | 140 | NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, |
| 141 | uint32_t Length) const { |
| 142 | return nullptr; |
| 143 | } |
| 144 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 145 | std::unique_ptr<IPDBEnumSourceFiles> |
| 146 | NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, |
| 147 | StringRef Pattern, |
| 148 | PDB_NameSearchFlags Flags) const { |
| 149 | return nullptr; |
| 150 | } |
| 151 | |
| 152 | std::unique_ptr<IPDBSourceFile> |
| 153 | NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, |
| 154 | StringRef Pattern, |
| 155 | PDB_NameSearchFlags Flags) const { |
| 156 | return nullptr; |
| 157 | } |
| 158 | |
| 159 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 160 | NativeSession::findCompilandsForSourceFile(StringRef Pattern, |
| 161 | PDB_NameSearchFlags Flags) const { |
| 162 | return nullptr; |
| 163 | } |
| 164 | |
| 165 | std::unique_ptr<PDBSymbolCompiland> |
| 166 | NativeSession::findOneCompilandForSourceFile(StringRef Pattern, |
| 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> |
| 181 | NativeSession::getSourceFileById(uint32_t FileId) const { |
| 182 | return nullptr; |
| 183 | } |
| 184 | |
| 185 | std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const { |
| 186 | return nullptr; |
| 187 | } |
Aaron Smith | 89bca9e | 2017-11-16 14:33:09 +0000 | [diff] [blame] | 188 | |
| 189 | std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const { |
| 190 | return nullptr; |
| 191 | } |
Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 192 | |
| 193 | std::unique_ptr<IPDBEnumInjectedSources> |
| 194 | NativeSession::getInjectedSources() const { |
| 195 | return nullptr; |
| 196 | } |
Aaron Smith | 523de05 | 2018-03-22 04:08:15 +0000 | [diff] [blame] | 197 | |
| 198 | std::unique_ptr<IPDBEnumSectionContribs> |
| 199 | NativeSession::getSectionContribs() const { |
| 200 | return nullptr; |
| 201 | } |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 202 | |
Aleksandr Urakov | c43e086 | 2018-10-23 08:14:53 +0000 | [diff] [blame] | 203 | std::unique_ptr<IPDBEnumFrameData> |
| 204 | NativeSession::getFrameData() const { |
| 205 | return nullptr; |
| 206 | } |
| 207 | |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 208 | void NativeSession::initializeExeSymbol() { |
| 209 | if (ExeSymbol == 0) |
| 210 | ExeSymbol = Cache.createSymbol<NativeExeSymbol>(); |
| 211 | } |
| 212 | |
| 213 | NativeExeSymbol &NativeSession::getNativeGlobalScope() const { |
| 214 | const_cast<NativeSession &>(*this).initializeExeSymbol(); |
| 215 | |
| 216 | return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol); |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 217 | } |