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