1 //===- NativeSession.h - Native implementation of IPDBSession ---*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H 10 #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H 11 12 #include "llvm/ADT/IntervalMap.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/DebugInfo/PDB/IPDBSession.h" 15 #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" 16 #include "llvm/DebugInfo/PDB/PDBTypes.h" 17 #include "llvm/Support/Allocator.h" 18 #include "llvm/Support/Compiler.h" 19 #include "llvm/Support/Error.h" 20 21 namespace llvm { 22 class MemoryBuffer; 23 namespace pdb { 24 class PDBFile; 25 class NativeExeSymbol; 26 class IPDBSourceFile; 27 class ModuleDebugStreamRef; 28 class PDBSymbol; 29 class PDBSymbolCompiland; 30 class PDBSymbolExe; 31 template <typename ChildType> class IPDBEnumChildren; 32 33 class LLVM_ABI NativeSession : public IPDBSession { 34 struct PdbSearchOptions { 35 StringRef ExePath; 36 // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv) 37 }; 38 39 public: 40 NativeSession(std::unique_ptr<PDBFile> PdbFile, 41 std::unique_ptr<BumpPtrAllocator> Allocator); 42 ~NativeSession() override; 43 44 static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB, 45 std::unique_ptr<IPDBSession> &Session); 46 static Error createFromPdbPath(StringRef PdbPath, 47 std::unique_ptr<IPDBSession> &Session); 48 static Error createFromExe(StringRef Path, 49 std::unique_ptr<IPDBSession> &Session); 50 static Expected<std::string> searchForPdb(const PdbSearchOptions &Opts); 51 52 uint64_t getLoadAddress() const override; 53 bool setLoadAddress(uint64_t Address) override; 54 std::unique_ptr<PDBSymbolExe> getGlobalScope() override; 55 std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override; 56 57 bool addressForVA(uint64_t VA, uint32_t &Section, 58 uint32_t &Offset) const override; 59 bool addressForRVA(uint32_t RVA, uint32_t &Section, 60 uint32_t &Offset) const override; 61 62 std::unique_ptr<PDBSymbol> findSymbolByAddress(uint64_t Address, 63 PDB_SymType Type) override; 64 std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA, 65 PDB_SymType Type) override; 66 std::unique_ptr<PDBSymbol> findSymbolBySectOffset(uint32_t Sect, 67 uint32_t Offset, 68 PDB_SymType Type) override; 69 70 std::unique_ptr<IPDBEnumLineNumbers> 71 findLineNumbers(const PDBSymbolCompiland &Compiland, 72 const IPDBSourceFile &File) const override; 73 std::unique_ptr<IPDBEnumLineNumbers> 74 findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override; 75 std::unique_ptr<IPDBEnumLineNumbers> 76 findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override; 77 std::unique_ptr<IPDBEnumLineNumbers> 78 findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, 79 uint32_t Length) const override; 80 81 std::unique_ptr<IPDBEnumSourceFiles> 82 findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, 83 PDB_NameSearchFlags Flags) const override; 84 std::unique_ptr<IPDBSourceFile> 85 findOneSourceFile(const PDBSymbolCompiland *Compiland, 86 llvm::StringRef Pattern, 87 PDB_NameSearchFlags Flags) const override; 88 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> 89 findCompilandsForSourceFile(llvm::StringRef Pattern, 90 PDB_NameSearchFlags Flags) const override; 91 std::unique_ptr<PDBSymbolCompiland> 92 findOneCompilandForSourceFile(llvm::StringRef Pattern, 93 PDB_NameSearchFlags Flags) const override; 94 std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override; 95 std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland( 96 const PDBSymbolCompiland &Compiland) const override; 97 std::unique_ptr<IPDBSourceFile> 98 getSourceFileById(uint32_t FileId) const override; 99 100 std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override; 101 102 std::unique_ptr<IPDBEnumTables> getEnumTables() const override; 103 104 std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override; 105 106 std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override; 107 108 std::unique_ptr<IPDBEnumFrameData> getFrameData() const override; 109 getPDBFile()110 PDBFile &getPDBFile() { return *Pdb; } getPDBFile()111 const PDBFile &getPDBFile() const { return *Pdb; } 112 113 NativeExeSymbol &getNativeGlobalScope() const; getSymbolCache()114 SymbolCache &getSymbolCache() { return Cache; } getSymbolCache()115 const SymbolCache &getSymbolCache() const { return Cache; } 116 uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const; 117 uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const; 118 bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const; 119 bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, 120 uint16_t &ModuleIndex) const; 121 Expected<ModuleDebugStreamRef> getModuleDebugStream(uint32_t Index) const; 122 123 private: 124 void initializeExeSymbol(); 125 void parseSectionContribs(); 126 127 std::unique_ptr<PDBFile> Pdb; 128 std::unique_ptr<BumpPtrAllocator> Allocator; 129 130 SymbolCache Cache; 131 SymIndexId ExeSymbol = 0; 132 uint64_t LoadAddress = 0; 133 134 /// Map from virtual address to module index. 135 using IMap = 136 IntervalMap<uint64_t, uint16_t, 8, IntervalMapHalfOpenInfo<uint64_t>>; 137 IMap::Allocator IMapAllocator; 138 IMap AddrToModuleIndex; 139 }; 140 } // namespace pdb 141 } // namespace llvm 142 143 #endif 144