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/NativeRawSymbol.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() { 74 auto RawSymbol = llvm::make_unique<NativeRawSymbol>(*this); 75 auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); 76 std::unique_ptr<PDBSymbolExe> ExeSymbol( 77 static_cast<PDBSymbolExe *>(PdbSymbol.release())); 78 return ExeSymbol; 79 } 80 81 std::unique_ptr<PDBSymbol> 82 NativeSession::getSymbolById(uint32_t SymbolId) const { 83 return nullptr; 84 } 85 86 std::unique_ptr<PDBSymbol> 87 NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { 88 return nullptr; 89 } 90 91 std::unique_ptr<IPDBEnumLineNumbers> 92 NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland, 93 const IPDBSourceFile &File) const { 94 return nullptr; 95 } 96 97 std::unique_ptr<IPDBEnumLineNumbers> 98 NativeSession::findLineNumbersByAddress(uint64_t Address, 99 uint32_t Length) const { 100 return nullptr; 101 } 102 103 std::unique_ptr<IPDBEnumSourceFiles> 104 NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, 105 StringRef Pattern, 106 PDB_NameSearchFlags Flags) const { 107 return nullptr; 108 } 109 110 std::unique_ptr<IPDBSourceFile> 111 NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, 112 StringRef Pattern, 113 PDB_NameSearchFlags Flags) const { 114 return nullptr; 115 } 116 117 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> 118 NativeSession::findCompilandsForSourceFile(StringRef Pattern, 119 PDB_NameSearchFlags Flags) const { 120 return nullptr; 121 } 122 123 std::unique_ptr<PDBSymbolCompiland> 124 NativeSession::findOneCompilandForSourceFile(StringRef Pattern, 125 PDB_NameSearchFlags Flags) const { 126 return nullptr; 127 } 128 129 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const { 130 return nullptr; 131 } 132 133 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland( 134 const PDBSymbolCompiland &Compiland) const { 135 return nullptr; 136 } 137 138 std::unique_ptr<IPDBSourceFile> 139 NativeSession::getSourceFileById(uint32_t FileId) const { 140 return nullptr; 141 } 142 143 std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const { 144 return nullptr; 145 } 146