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" 13 #include "llvm/DebugInfo/PDB/GenericError.h" 14 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" 15 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" 16 #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" 17 #include "llvm/DebugInfo/PDB/Native/PDBFile.h" 18 #include "llvm/DebugInfo/PDB/Native/RawError.h" 19 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" 20 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" 21 #include "llvm/Support/Allocator.h" 22 #include "llvm/Support/BinaryByteStream.h" 23 #include "llvm/Support/Error.h" 24 #include "llvm/Support/ErrorOr.h" 25 #include "llvm/Support/MemoryBuffer.h" 26 #include <algorithm> 27 #include <memory> 28 29 using namespace llvm; 30 using namespace llvm::msf; 31 using namespace llvm::pdb; 32 33 NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, 34 std::unique_ptr<BumpPtrAllocator> Allocator) 35 : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {} 36 37 NativeSession::~NativeSession() = default; 38 39 Error NativeSession::createFromPdb(StringRef Path, 40 std::unique_ptr<IPDBSession> &Session) { 41 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = 42 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, 43 /*RequiresNullTerminator=*/false); 44 if (!ErrorOrBuffer) 45 return make_error<GenericError>(generic_error_code::invalid_path); 46 47 std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); 48 auto Stream = llvm::make_unique<MemoryBufferByteStream>( 49 std::move(Buffer), llvm::support::little); 50 51 auto Allocator = llvm::make_unique<BumpPtrAllocator>(); 52 auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator); 53 if (auto EC = File->parseFileHeaders()) 54 return EC; 55 if (auto EC = File->parseStreamData()) 56 return EC; 57 58 Session = 59 llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator)); 60 61 return Error::success(); 62 } 63 64 Error NativeSession::createFromExe(StringRef Path, 65 std::unique_ptr<IPDBSession> &Session) { 66 return make_error<RawError>(raw_error_code::feature_unsupported); 67 } 68 69 uint64_t NativeSession::getLoadAddress() const { return 0; } 70 71 void NativeSession::setLoadAddress(uint64_t Address) {} 72 73 std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() const { 74 auto RawSymbol = 75 llvm::make_unique<NativeExeSymbol>(const_cast<NativeSession &>(*this)); 76 auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); 77 std::unique_ptr<PDBSymbolExe> ExeSymbol( 78 static_cast<PDBSymbolExe *>(PdbSymbol.release())); 79 return ExeSymbol; 80 } 81 82 std::unique_ptr<PDBSymbol> 83 NativeSession::getSymbolById(uint32_t SymbolId) const { 84 return nullptr; 85 } 86 87 std::unique_ptr<PDBSymbol> 88 NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { 89 return nullptr; 90 } 91 92 std::unique_ptr<IPDBEnumLineNumbers> 93 NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland, 94 const IPDBSourceFile &File) const { 95 return nullptr; 96 } 97 98 std::unique_ptr<IPDBEnumLineNumbers> 99 NativeSession::findLineNumbersByAddress(uint64_t Address, 100 uint32_t Length) const { 101 return nullptr; 102 } 103 104 std::unique_ptr<IPDBEnumSourceFiles> 105 NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, 106 StringRef Pattern, 107 PDB_NameSearchFlags Flags) const { 108 return nullptr; 109 } 110 111 std::unique_ptr<IPDBSourceFile> 112 NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, 113 StringRef Pattern, 114 PDB_NameSearchFlags Flags) const { 115 return nullptr; 116 } 117 118 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> 119 NativeSession::findCompilandsForSourceFile(StringRef Pattern, 120 PDB_NameSearchFlags Flags) const { 121 return nullptr; 122 } 123 124 std::unique_ptr<PDBSymbolCompiland> 125 NativeSession::findOneCompilandForSourceFile(StringRef Pattern, 126 PDB_NameSearchFlags Flags) const { 127 return nullptr; 128 } 129 130 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const { 131 return nullptr; 132 } 133 134 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland( 135 const PDBSymbolCompiland &Compiland) const { 136 return nullptr; 137 } 138 139 std::unique_ptr<IPDBSourceFile> 140 NativeSession::getSourceFileById(uint32_t FileId) const { 141 return nullptr; 142 } 143 144 std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const { 145 return nullptr; 146 } 147