109467b48Spatrick //===- NativeSession.h - Native implementation of IPDBSession ---*- C++ -*-===// 209467b48Spatrick // 309467b48Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 409467b48Spatrick // See https://llvm.org/LICENSE.txt for license information. 509467b48Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 609467b48Spatrick // 709467b48Spatrick //===----------------------------------------------------------------------===// 809467b48Spatrick 909467b48Spatrick #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H 1009467b48Spatrick #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H 1109467b48Spatrick 12*d415bd75Srobert #include "llvm/ADT/IntervalMap.h" 1309467b48Spatrick #include "llvm/ADT/StringRef.h" 1409467b48Spatrick #include "llvm/DebugInfo/PDB/IPDBSession.h" 1509467b48Spatrick #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" 16*d415bd75Srobert #include "llvm/DebugInfo/PDB/PDBTypes.h" 1709467b48Spatrick #include "llvm/Support/Allocator.h" 1809467b48Spatrick #include "llvm/Support/Error.h" 1909467b48Spatrick 2009467b48Spatrick namespace llvm { 2109467b48Spatrick class MemoryBuffer; 2209467b48Spatrick namespace pdb { 2309467b48Spatrick class PDBFile; 2409467b48Spatrick class NativeExeSymbol; 25*d415bd75Srobert class IPDBSourceFile; 26*d415bd75Srobert class ModuleDebugStreamRef; 27*d415bd75Srobert class PDBSymbol; 28*d415bd75Srobert class PDBSymbolCompiland; 29*d415bd75Srobert class PDBSymbolExe; 30*d415bd75Srobert template <typename ChildType> class IPDBEnumChildren; 3109467b48Spatrick 3209467b48Spatrick class NativeSession : public IPDBSession { 33097a140dSpatrick struct PdbSearchOptions { 34097a140dSpatrick StringRef ExePath; 35097a140dSpatrick // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv) 36097a140dSpatrick }; 37097a140dSpatrick 3809467b48Spatrick public: 3909467b48Spatrick NativeSession(std::unique_ptr<PDBFile> PdbFile, 4009467b48Spatrick std::unique_ptr<BumpPtrAllocator> Allocator); 4109467b48Spatrick ~NativeSession() override; 4209467b48Spatrick 4309467b48Spatrick static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB, 4409467b48Spatrick std::unique_ptr<IPDBSession> &Session); 45097a140dSpatrick static Error createFromPdbPath(StringRef PdbPath, 46097a140dSpatrick std::unique_ptr<IPDBSession> &Session); 4709467b48Spatrick static Error createFromExe(StringRef Path, 4809467b48Spatrick std::unique_ptr<IPDBSession> &Session); 49097a140dSpatrick static Expected<std::string> searchForPdb(const PdbSearchOptions &Opts); 5009467b48Spatrick 5109467b48Spatrick uint64_t getLoadAddress() const override; 5209467b48Spatrick bool setLoadAddress(uint64_t Address) override; 5309467b48Spatrick std::unique_ptr<PDBSymbolExe> getGlobalScope() override; 5409467b48Spatrick std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override; 5509467b48Spatrick 5609467b48Spatrick bool addressForVA(uint64_t VA, uint32_t &Section, 5709467b48Spatrick uint32_t &Offset) const override; 5809467b48Spatrick bool addressForRVA(uint32_t RVA, uint32_t &Section, 5909467b48Spatrick uint32_t &Offset) const override; 6009467b48Spatrick 61097a140dSpatrick std::unique_ptr<PDBSymbol> findSymbolByAddress(uint64_t Address, 62097a140dSpatrick PDB_SymType Type) override; 6309467b48Spatrick std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA, 64097a140dSpatrick PDB_SymType Type) override; 65097a140dSpatrick std::unique_ptr<PDBSymbol> findSymbolBySectOffset(uint32_t Sect, 66097a140dSpatrick uint32_t Offset, 67097a140dSpatrick PDB_SymType Type) override; 6809467b48Spatrick 6909467b48Spatrick std::unique_ptr<IPDBEnumLineNumbers> 7009467b48Spatrick findLineNumbers(const PDBSymbolCompiland &Compiland, 7109467b48Spatrick const IPDBSourceFile &File) const override; 7209467b48Spatrick std::unique_ptr<IPDBEnumLineNumbers> 7309467b48Spatrick findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override; 7409467b48Spatrick std::unique_ptr<IPDBEnumLineNumbers> 7509467b48Spatrick findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override; 7609467b48Spatrick std::unique_ptr<IPDBEnumLineNumbers> 7709467b48Spatrick findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, 7809467b48Spatrick uint32_t Length) const override; 7909467b48Spatrick 8009467b48Spatrick std::unique_ptr<IPDBEnumSourceFiles> 8109467b48Spatrick findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, 8209467b48Spatrick PDB_NameSearchFlags Flags) const override; 8309467b48Spatrick std::unique_ptr<IPDBSourceFile> 8409467b48Spatrick findOneSourceFile(const PDBSymbolCompiland *Compiland, 8509467b48Spatrick llvm::StringRef Pattern, 8609467b48Spatrick PDB_NameSearchFlags Flags) const override; 8709467b48Spatrick std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> 8809467b48Spatrick findCompilandsForSourceFile(llvm::StringRef Pattern, 8909467b48Spatrick PDB_NameSearchFlags Flags) const override; 9009467b48Spatrick std::unique_ptr<PDBSymbolCompiland> 9109467b48Spatrick findOneCompilandForSourceFile(llvm::StringRef Pattern, 9209467b48Spatrick PDB_NameSearchFlags Flags) const override; 9309467b48Spatrick std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override; 9409467b48Spatrick std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland( 9509467b48Spatrick const PDBSymbolCompiland &Compiland) const override; 9609467b48Spatrick std::unique_ptr<IPDBSourceFile> 9709467b48Spatrick getSourceFileById(uint32_t FileId) const override; 9809467b48Spatrick 9909467b48Spatrick std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override; 10009467b48Spatrick 10109467b48Spatrick std::unique_ptr<IPDBEnumTables> getEnumTables() const override; 10209467b48Spatrick 10309467b48Spatrick std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override; 10409467b48Spatrick 10509467b48Spatrick std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override; 10609467b48Spatrick 10709467b48Spatrick std::unique_ptr<IPDBEnumFrameData> getFrameData() const override; 10809467b48Spatrick getPDBFile()10909467b48Spatrick PDBFile &getPDBFile() { return *Pdb; } getPDBFile()11009467b48Spatrick const PDBFile &getPDBFile() const { return *Pdb; } 11109467b48Spatrick 11209467b48Spatrick NativeExeSymbol &getNativeGlobalScope() const; getSymbolCache()11309467b48Spatrick SymbolCache &getSymbolCache() { return Cache; } getSymbolCache()11409467b48Spatrick const SymbolCache &getSymbolCache() const { return Cache; } 115097a140dSpatrick uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const; 116097a140dSpatrick uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const; 11773471bf0Spatrick bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const; 11873471bf0Spatrick bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, 11973471bf0Spatrick uint16_t &ModuleIndex) const; 12073471bf0Spatrick Expected<ModuleDebugStreamRef> getModuleDebugStream(uint32_t Index) const; 12109467b48Spatrick 12209467b48Spatrick private: 12309467b48Spatrick void initializeExeSymbol(); 12473471bf0Spatrick void parseSectionContribs(); 12509467b48Spatrick 12609467b48Spatrick std::unique_ptr<PDBFile> Pdb; 12709467b48Spatrick std::unique_ptr<BumpPtrAllocator> Allocator; 12809467b48Spatrick 12909467b48Spatrick SymbolCache Cache; 13009467b48Spatrick SymIndexId ExeSymbol = 0; 131097a140dSpatrick uint64_t LoadAddress = 0; 13273471bf0Spatrick 13373471bf0Spatrick /// Map from virtual address to module index. 13473471bf0Spatrick using IMap = 13573471bf0Spatrick IntervalMap<uint64_t, uint16_t, 8, IntervalMapHalfOpenInfo<uint64_t>>; 13673471bf0Spatrick IMap::Allocator IMapAllocator; 13773471bf0Spatrick IMap AddrToModuleIndex; 13809467b48Spatrick }; 13909467b48Spatrick } // namespace pdb 14009467b48Spatrick } // namespace llvm 14109467b48Spatrick 14209467b48Spatrick #endif 143