Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:45

0001 //===- NativeSession.h - Native implementation of IPDBSession ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H
0011 
0012 #include "llvm/ADT/IntervalMap.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/DebugInfo/PDB/IPDBSession.h"
0015 #include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
0016 #include "llvm/DebugInfo/PDB/PDBTypes.h"
0017 #include "llvm/Support/Allocator.h"
0018 #include "llvm/Support/Error.h"
0019 
0020 namespace llvm {
0021 class MemoryBuffer;
0022 namespace pdb {
0023 class PDBFile;
0024 class NativeExeSymbol;
0025 class IPDBSourceFile;
0026 class ModuleDebugStreamRef;
0027 class PDBSymbol;
0028 class PDBSymbolCompiland;
0029 class PDBSymbolExe;
0030 template <typename ChildType> class IPDBEnumChildren;
0031 
0032 class NativeSession : public IPDBSession {
0033   struct PdbSearchOptions {
0034     StringRef ExePath;
0035     // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv)
0036   };
0037 
0038 public:
0039   NativeSession(std::unique_ptr<PDBFile> PdbFile,
0040                 std::unique_ptr<BumpPtrAllocator> Allocator);
0041   ~NativeSession() override;
0042 
0043   static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB,
0044                              std::unique_ptr<IPDBSession> &Session);
0045   static Error createFromPdbPath(StringRef PdbPath,
0046                                  std::unique_ptr<IPDBSession> &Session);
0047   static Error createFromExe(StringRef Path,
0048                              std::unique_ptr<IPDBSession> &Session);
0049   static Expected<std::string> searchForPdb(const PdbSearchOptions &Opts);
0050 
0051   uint64_t getLoadAddress() const override;
0052   bool setLoadAddress(uint64_t Address) override;
0053   std::unique_ptr<PDBSymbolExe> getGlobalScope() override;
0054   std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override;
0055 
0056   bool addressForVA(uint64_t VA, uint32_t &Section,
0057                     uint32_t &Offset) const override;
0058   bool addressForRVA(uint32_t RVA, uint32_t &Section,
0059                      uint32_t &Offset) const override;
0060 
0061   std::unique_ptr<PDBSymbol> findSymbolByAddress(uint64_t Address,
0062                                                  PDB_SymType Type) override;
0063   std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA,
0064                                              PDB_SymType Type) override;
0065   std::unique_ptr<PDBSymbol> findSymbolBySectOffset(uint32_t Sect,
0066                                                     uint32_t Offset,
0067                                                     PDB_SymType Type) override;
0068 
0069   std::unique_ptr<IPDBEnumLineNumbers>
0070   findLineNumbers(const PDBSymbolCompiland &Compiland,
0071                   const IPDBSourceFile &File) const override;
0072   std::unique_ptr<IPDBEnumLineNumbers>
0073   findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
0074   std::unique_ptr<IPDBEnumLineNumbers>
0075   findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override;
0076   std::unique_ptr<IPDBEnumLineNumbers>
0077   findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset,
0078                               uint32_t Length) const override;
0079 
0080   std::unique_ptr<IPDBEnumSourceFiles>
0081   findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
0082                   PDB_NameSearchFlags Flags) const override;
0083   std::unique_ptr<IPDBSourceFile>
0084   findOneSourceFile(const PDBSymbolCompiland *Compiland,
0085                     llvm::StringRef Pattern,
0086                     PDB_NameSearchFlags Flags) const override;
0087   std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
0088   findCompilandsForSourceFile(llvm::StringRef Pattern,
0089                               PDB_NameSearchFlags Flags) const override;
0090   std::unique_ptr<PDBSymbolCompiland>
0091   findOneCompilandForSourceFile(llvm::StringRef Pattern,
0092                                 PDB_NameSearchFlags Flags) const override;
0093   std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
0094   std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
0095       const PDBSymbolCompiland &Compiland) const override;
0096   std::unique_ptr<IPDBSourceFile>
0097   getSourceFileById(uint32_t FileId) const override;
0098 
0099   std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
0100 
0101   std::unique_ptr<IPDBEnumTables> getEnumTables() const override;
0102 
0103   std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override;
0104 
0105   std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override;
0106 
0107   std::unique_ptr<IPDBEnumFrameData> getFrameData() const override;
0108 
0109   PDBFile &getPDBFile() { return *Pdb; }
0110   const PDBFile &getPDBFile() const { return *Pdb; }
0111 
0112   NativeExeSymbol &getNativeGlobalScope() const;
0113   SymbolCache &getSymbolCache() { return Cache; }
0114   const SymbolCache &getSymbolCache() const { return Cache; }
0115   uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const;
0116   uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const;
0117   bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const;
0118   bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset,
0119                                 uint16_t &ModuleIndex) const;
0120   Expected<ModuleDebugStreamRef> getModuleDebugStream(uint32_t Index) const;
0121 
0122 private:
0123   void initializeExeSymbol();
0124   void parseSectionContribs();
0125 
0126   std::unique_ptr<PDBFile> Pdb;
0127   std::unique_ptr<BumpPtrAllocator> Allocator;
0128 
0129   SymbolCache Cache;
0130   SymIndexId ExeSymbol = 0;
0131   uint64_t LoadAddress = 0;
0132 
0133   /// Map from virtual address to module index.
0134   using IMap =
0135       IntervalMap<uint64_t, uint16_t, 8, IntervalMapHalfOpenInfo<uint64_t>>;
0136   IMap::Allocator IMapAllocator;
0137   IMap AddrToModuleIndex;
0138 };
0139 } // namespace pdb
0140 } // namespace llvm
0141 
0142 #endif