LLVM  16.0.0git
NativeSession.h
Go to the documentation of this file.
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"
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/Error.h"
19 
20 namespace llvm {
21 class MemoryBuffer;
22 namespace pdb {
23 class PDBFile;
24 class NativeExeSymbol;
25 class IPDBSourceFile;
26 class ModuleDebugStreamRef;
27 class PDBSymbol;
28 class PDBSymbolCompiland;
29 class PDBSymbolExe;
30 template <typename ChildType> class IPDBEnumChildren;
31 
32 class NativeSession : public IPDBSession {
33  struct PdbSearchOptions {
34  StringRef ExePath;
35  // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv)
36  };
37 
38 public:
39  NativeSession(std::unique_ptr<PDBFile> PdbFile,
40  std::unique_ptr<BumpPtrAllocator> Allocator);
41  ~NativeSession() override;
42 
43  static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB,
44  std::unique_ptr<IPDBSession> &Session);
45  static Error createFromPdbPath(StringRef PdbPath,
46  std::unique_ptr<IPDBSession> &Session);
48  std::unique_ptr<IPDBSession> &Session);
49  static Expected<std::string> searchForPdb(const PdbSearchOptions &Opts);
50 
51  uint64_t getLoadAddress() const override;
52  bool setLoadAddress(uint64_t Address) override;
53  std::unique_ptr<PDBSymbolExe> getGlobalScope() override;
54  std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override;
55 
56  bool addressForVA(uint64_t VA, uint32_t &Section,
57  uint32_t &Offset) const override;
58  bool addressForRVA(uint32_t RVA, uint32_t &Section,
59  uint32_t &Offset) const override;
60 
61  std::unique_ptr<PDBSymbol> findSymbolByAddress(uint64_t Address,
62  PDB_SymType Type) override;
63  std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA,
64  PDB_SymType Type) override;
65  std::unique_ptr<PDBSymbol> findSymbolBySectOffset(uint32_t Sect,
66  uint32_t Offset,
67  PDB_SymType Type) override;
68 
69  std::unique_ptr<IPDBEnumLineNumbers>
71  const IPDBSourceFile &File) const override;
72  std::unique_ptr<IPDBEnumLineNumbers>
73  findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
74  std::unique_ptr<IPDBEnumLineNumbers>
75  findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override;
76  std::unique_ptr<IPDBEnumLineNumbers>
78  uint32_t Length) const override;
79 
80  std::unique_ptr<IPDBEnumSourceFiles>
82  PDB_NameSearchFlags Flags) const override;
83  std::unique_ptr<IPDBSourceFile>
86  PDB_NameSearchFlags Flags) const override;
87  std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
89  PDB_NameSearchFlags Flags) const override;
90  std::unique_ptr<PDBSymbolCompiland>
92  PDB_NameSearchFlags Flags) const override;
93  std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
94  std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
95  const PDBSymbolCompiland &Compiland) const override;
96  std::unique_ptr<IPDBSourceFile>
97  getSourceFileById(uint32_t FileId) const override;
98 
99  std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
100 
101  std::unique_ptr<IPDBEnumTables> getEnumTables() const override;
102 
103  std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override;
104 
105  std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override;
106 
107  std::unique_ptr<IPDBEnumFrameData> getFrameData() const override;
108 
109  PDBFile &getPDBFile() { return *Pdb; }
110  const PDBFile &getPDBFile() const { return *Pdb; }
111 
113  SymbolCache &getSymbolCache() { return Cache; }
114  const SymbolCache &getSymbolCache() const { return Cache; }
115  uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const;
116  uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const;
117  bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const;
118  bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset,
119  uint16_t &ModuleIndex) const;
121 
122 private:
123  void initializeExeSymbol();
124  void parseSectionContribs();
125 
126  std::unique_ptr<PDBFile> Pdb;
127  std::unique_ptr<BumpPtrAllocator> Allocator;
128 
129  SymbolCache Cache;
130  SymIndexId ExeSymbol = 0;
131  uint64_t LoadAddress = 0;
132 
133  /// Map from virtual address to module index.
134  using IMap =
136  IMap::Allocator IMapAllocator;
137  IMap AddrToModuleIndex;
138 };
139 } // namespace pdb
140 } // namespace llvm
141 
142 #endif
llvm::pdb::IPDBSession
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::pdb::NativeSession::getRVAFromSectOffset
uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:381
llvm::pdb::NativeSession::getEnumTables
std::unique_ptr< IPDBEnumTables > getEnumTables() const override
Definition: NativeSession.cpp:341
llvm::pdb::NativeSession::NativeSession
NativeSession(std::unique_ptr< PDBFile > PdbFile, std::unique_ptr< BumpPtrAllocator > Allocator)
Definition: NativeSession.cpp:65
StringRef.h
llvm::pdb::IPDBSourceFile
IPDBSourceFile defines an interface used to represent source files whose information are stored in th...
Definition: IPDBSourceFile.h:23
llvm::pdb::NativeSession::getPDBFile
PDBFile & getPDBFile()
Definition: NativeSession.h:109
llvm::pdb::NativeSession::getSourceFilesForCompiland
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
Definition: NativeSession.cpp:327
Allocator.h
Error.h
llvm::pdb::NativeSession::getVAFromSectOffset
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:397
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::pdb::NativeSession::findOneSourceFile
std::unique_ptr< IPDBSourceFile > findOneSourceFile(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:305
llvm::pdb::NativeSession::createFromExe
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: NativeSession.cpp:150
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::NativeSession::getFrameData
std::unique_ptr< IPDBEnumFrameData > getFrameData() const override
Definition: NativeSession.cpp:366
llvm::pdb::SymbolCache
Definition: SymbolCache.h:37
llvm::pdb::NativeSession::getModuleDebugStream
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
Definition: NativeSession.cpp:453
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::pdb::NativeSession::findLineNumbersBySectOffset
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const override
Definition: NativeSession.cpp:291
llvm::pdb::NativeSession::getLoadAddress
uint64_t getLoadAddress() const override
Definition: NativeSession.cpp:204
llvm::pdb::NativeSession::getInjectedSources
std::unique_ptr< IPDBEnumInjectedSources > getInjectedSources() const override
Definition: NativeSession.cpp:346
llvm::pdb::NativeExeSymbol
Definition: NativeExeSymbol.h:23
llvm::pdb::NativeSession::moduleIndexForVA
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:402
llvm::pdb::NativeSession::findLineNumbersByAddress
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
Definition: NativeSession.cpp:280
llvm::pdb::NativeSession::getPDBFile
const PDBFile & getPDBFile() const
Definition: NativeSession.h:110
llvm::pdb::SymIndexId
uint32_t SymIndexId
Definition: PDBTypes.h:26
llvm::pdb::NativeSession::createFromPdbPath
static Error createFromPdbPath(StringRef PdbPath, std::unique_ptr< IPDBSession > &Session)
Definition: NativeSession.cpp:119
llvm::pdb::NativeSession::getSourceFileById
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
Definition: NativeSession.cpp:333
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::pdb::PDB_NameSearchFlags
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:102
llvm::pdb::PDB_ColorItem::Path
@ Path
PDBTypes.h
llvm::pdb::NativeSession::findSourceFiles
std::unique_ptr< IPDBEnumSourceFiles > findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:298
llvm::IntervalMap< uint64_t, uint16_t, 8, IntervalMapHalfOpenInfo< uint64_t > >::Allocator
typename Sizer::Allocator Allocator
Definition: IntervalMap.h:962
llvm::pdb::NativeSession::getSectionContribs
std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const override
Definition: NativeSession.cpp:361
llvm::pdb::PDB_ColorItem::Address
@ Address
llvm::pdb::NativeSession::createFromPdb
static Error createFromPdb(std::unique_ptr< MemoryBuffer > MB, std::unique_ptr< IPDBSession > &Session)
Definition: NativeSession.cpp:72
llvm::pdb::NativeSession::setLoadAddress
bool setLoadAddress(uint64_t Address) override
Definition: NativeSession.cpp:206
uint64_t
llvm::pdb::NativeSession::findLineNumbersByRVA
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override
Definition: NativeSession.cpp:286
IPDBSession.h
llvm::pdb::NativeSession::findSymbolByRVA
std::unique_ptr< PDBSymbol > findSymbolByRVA(uint32_t RVA, PDB_SymType Type) override
Definition: NativeSession.cpp:256
llvm::pdb::NativeSession::addressForVA
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
Definition: NativeSession.cpp:220
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:113
llvm::pdb::NativeSession::addressForRVA
bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const override
Definition: NativeSession.cpp:226
llvm::pdb::NativeSession::getGlobalScope
std::unique_ptr< PDBSymbolExe > getGlobalScope() override
Definition: NativeSession.cpp:211
llvm::pdb::NativeSession::findSymbolBySectOffset
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) override
Definition: NativeSession.cpp:265
llvm::pdb::NativeSession::getSymbolCache
const SymbolCache & getSymbolCache() const
Definition: NativeSession.h:114
llvm::pdb::NativeSession::getSymbolById
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const override
Definition: NativeSession.cpp:216
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
uint32_t
llvm::pdb::NativeSession::findSymbolByAddress
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) override
Definition: NativeSession.cpp:249
llvm::pdb::NativeSession::~NativeSession
~NativeSession() override
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::pdb::PDB_SymType::Compiland
@ Compiland
llvm::pdb::NativeSession
Definition: NativeSession.h:32
llvm::pdb::NativeSession::searchForPdb
static Expected< std::string > searchForPdb(const PdbSearchOptions &Opts)
Definition: NativeSession.cpp:173
llvm::Pattern
Definition: FileCheckImpl.h:614
llvm::pdb::PDBFile
Definition: PDBFile.h:40
IntervalMap.h
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
SymbolCache.h
llvm::IntervalMap
Definition: IntervalMap.h:936
llvm::pdb::NativeSession::findCompilandsForSourceFile
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > findCompilandsForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:312
llvm::pdb::NativeSession::findLineNumbers
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const override
Definition: NativeSession.cpp:274
llvm::pdb::PDBSymbolCompiland
Definition: PDBSymbolCompiland.h:21
llvm::pdb::NativeSession::getNativeGlobalScope
NativeExeSymbol & getNativeGlobalScope() const
Definition: NativeSession.cpp:375
llvm::pdb::NativeSession::getAllSourceFiles
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
Definition: NativeSession.cpp:323
llvm::pdb::NativeSession::getDebugStreams
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
Definition: NativeSession.cpp:337
llvm::pdb::NativeSession::findOneCompilandForSourceFile
std::unique_ptr< PDBSymbolCompiland > findOneCompilandForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:318
llvm::pdb::NativeSession::moduleIndexForSectOffset
bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:411