//===- NativeSession.cpp - Native implementation of IPDBSession -*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumInjectedSources.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h" #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/MemoryBuffer.h" #include #include #include #include using namespace llvm; using namespace llvm::msf; using namespace llvm::pdb; static DbiStream *getDbiStreamPtr(PDBFile &File) { Expected DbiS = File.getPDBDbiStream(); if (DbiS) return &DbiS.get(); consumeError(DbiS.takeError()); return nullptr; } NativeSession::NativeSession(std::unique_ptr PdbFile, std::unique_ptr Allocator) : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)), Cache(*this, getDbiStreamPtr(*Pdb)) {} NativeSession::~NativeSession() = default; Error NativeSession::createFromPdb(std::unique_ptr Buffer, std::unique_ptr &Session) { StringRef Path = Buffer->getBufferIdentifier(); auto Stream = llvm::make_unique( std::move(Buffer), llvm::support::little); auto Allocator = llvm::make_unique(); auto File = llvm::make_unique(Path, std::move(Stream), *Allocator); if (auto EC = File->parseFileHeaders()) return EC; if (auto EC = File->parseStreamData()) return EC; Session = llvm::make_unique(std::move(File), std::move(Allocator)); return Error::success(); } Error NativeSession::createFromExe(StringRef Path, std::unique_ptr &Session) { return make_error(raw_error_code::feature_unsupported); } uint64_t NativeSession::getLoadAddress() const { return 0; } bool NativeSession::setLoadAddress(uint64_t Address) { return false; } std::unique_ptr NativeSession::getGlobalScope() { return PDBSymbol::createAs(*this, getNativeGlobalScope()); } std::unique_ptr NativeSession::getSymbolById(SymIndexId SymbolId) const { return Cache.getSymbolById(SymbolId); } bool NativeSession::addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const { return false; } bool NativeSession::addressForRVA(uint32_t VA, uint32_t &Section, uint32_t &Offset) const { return false; } std::unique_ptr NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { return nullptr; } std::unique_ptr NativeSession::findSymbolByRVA(uint32_t RVA, PDB_SymType Type) const { return nullptr; } std::unique_ptr NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) const { return nullptr; } std::unique_ptr NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const { return nullptr; } std::unique_ptr NativeSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { return nullptr; } std::unique_ptr NativeSession::findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const { return nullptr; } std::unique_ptr NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const { return nullptr; } std::unique_ptr NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr> NativeSession::findCompilandsForSourceFile(StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr NativeSession::findOneCompilandForSourceFile(StringRef Pattern, PDB_NameSearchFlags Flags) const { return nullptr; } std::unique_ptr NativeSession::getAllSourceFiles() const { return nullptr; } std::unique_ptr NativeSession::getSourceFilesForCompiland( const PDBSymbolCompiland &Compiland) const { return nullptr; } std::unique_ptr NativeSession::getSourceFileById(uint32_t FileId) const { return nullptr; } std::unique_ptr NativeSession::getDebugStreams() const { return nullptr; } std::unique_ptr NativeSession::getEnumTables() const { return nullptr; } std::unique_ptr NativeSession::getInjectedSources() const { auto ISS = Pdb->getInjectedSourceStream(); if (!ISS) { consumeError(ISS.takeError()); return nullptr; } auto Strings = Pdb->getStringTable(); if (!Strings) { consumeError(Strings.takeError()); return nullptr; } return make_unique(*Pdb, *ISS, *Strings); } std::unique_ptr NativeSession::getSectionContribs() const { return nullptr; } std::unique_ptr NativeSession::getFrameData() const { return nullptr; } void NativeSession::initializeExeSymbol() { if (ExeSymbol == 0) ExeSymbol = Cache.createSymbol(); } NativeExeSymbol &NativeSession::getNativeGlobalScope() const { const_cast(*this).initializeExeSymbol(); return Cache.getNativeSymbolById(ExeSymbol); }