LLVM  14.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/DenseMap.h"
13 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/Error.h"
21 
22 namespace llvm {
23 class MemoryBuffer;
24 namespace pdb {
25 class PDBFile;
26 class NativeExeSymbol;
27 
28 class NativeSession : public IPDBSession {
29  struct PdbSearchOptions {
30  StringRef ExePath;
31  // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv)
32  };
33 
34 public:
35  NativeSession(std::unique_ptr<PDBFile> PdbFile,
36  std::unique_ptr<BumpPtrAllocator> Allocator);
37  ~NativeSession() override;
38 
39  static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB,
40  std::unique_ptr<IPDBSession> &Session);
41  static Error createFromPdbPath(StringRef PdbPath,
42  std::unique_ptr<IPDBSession> &Session);
43  static Error createFromExe(StringRef Path,
44  std::unique_ptr<IPDBSession> &Session);
45  static Expected<std::string> searchForPdb(const PdbSearchOptions &Opts);
46 
47  uint64_t getLoadAddress() const override;
48  bool setLoadAddress(uint64_t Address) override;
49  std::unique_ptr<PDBSymbolExe> getGlobalScope() override;
50  std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override;
51 
53  uint32_t &Offset) const override;
55  uint32_t &Offset) const override;
56 
57  std::unique_ptr<PDBSymbol> findSymbolByAddress(uint64_t Address,
58  PDB_SymType Type) override;
59  std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA,
60  PDB_SymType Type) override;
61  std::unique_ptr<PDBSymbol> findSymbolBySectOffset(uint32_t Sect,
63  PDB_SymType Type) override;
64 
65  std::unique_ptr<IPDBEnumLineNumbers>
67  const IPDBSourceFile &File) const override;
68  std::unique_ptr<IPDBEnumLineNumbers>
69  findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
70  std::unique_ptr<IPDBEnumLineNumbers>
71  findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override;
72  std::unique_ptr<IPDBEnumLineNumbers>
74  uint32_t Length) const override;
75 
76  std::unique_ptr<IPDBEnumSourceFiles>
78  PDB_NameSearchFlags Flags) const override;
79  std::unique_ptr<IPDBSourceFile>
82  PDB_NameSearchFlags Flags) const override;
83  std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
85  PDB_NameSearchFlags Flags) const override;
86  std::unique_ptr<PDBSymbolCompiland>
88  PDB_NameSearchFlags Flags) const override;
89  std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
90  std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
91  const PDBSymbolCompiland &Compiland) const override;
92  std::unique_ptr<IPDBSourceFile>
93  getSourceFileById(uint32_t FileId) const override;
94 
95  std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
96 
97  std::unique_ptr<IPDBEnumTables> getEnumTables() const override;
98 
99  std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override;
100 
101  std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override;
102 
103  std::unique_ptr<IPDBEnumFrameData> getFrameData() const override;
104 
105  PDBFile &getPDBFile() { return *Pdb; }
106  const PDBFile &getPDBFile() const { return *Pdb; }
107 
109  SymbolCache &getSymbolCache() { return Cache; }
110  const SymbolCache &getSymbolCache() const { return Cache; }
113  bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const;
115  uint16_t &ModuleIndex) const;
117 
118 private:
119  void initializeExeSymbol();
120  void parseSectionContribs();
121 
122  std::unique_ptr<PDBFile> Pdb;
123  std::unique_ptr<BumpPtrAllocator> Allocator;
124 
125  SymbolCache Cache;
126  SymIndexId ExeSymbol = 0;
127  uint64_t LoadAddress = 0;
128 
129  /// Map from virtual address to module index.
130  using IMap =
132  IMap::Allocator IMapAllocator;
133  IMap AddrToModuleIndex;
134 };
135 } // namespace pdb
136 } // namespace llvm
137 
138 #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
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::pdb::NativeSession::getRVAFromSectOffset
uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:373
llvm::pdb::NativeSession::getEnumTables
std::unique_ptr< IPDBEnumTables > getEnumTables() const override
Definition: NativeSession.cpp:333
llvm::pdb::NativeSession::NativeSession
NativeSession(std::unique_ptr< PDBFile > PdbFile, std::unique_ptr< BumpPtrAllocator > Allocator)
Definition: NativeSession.cpp:57
StringRef.h
IPDBRawSymbol.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:105
llvm::pdb::NativeSession::getSourceFilesForCompiland
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
Definition: NativeSession.cpp:319
Allocator.h
Error.h
llvm::pdb::NativeSession::getVAFromSectOffset
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:389
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:297
DenseMap.h
llvm::pdb::NativeSession::createFromExe
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: NativeSession.cpp:142
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::NativeSession::getFrameData
std::unique_ptr< IPDBEnumFrameData > getFrameData() const override
Definition: NativeSession.cpp:358
llvm::pdb::SymbolCache
Definition: SymbolCache.h:31
llvm::pdb::NativeSession::getModuleDebugStream
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
Definition: NativeSession.cpp:445
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:283
llvm::pdb::NativeSession::getLoadAddress
uint64_t getLoadAddress() const override
Definition: NativeSession.cpp:196
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::pdb::NativeSession::getInjectedSources
std::unique_ptr< IPDBEnumInjectedSources > getInjectedSources() const override
Definition: NativeSession.cpp:338
llvm::pdb::NativeExeSymbol
Definition: NativeExeSymbol.h:20
llvm::pdb::NativeSession::moduleIndexForVA
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:394
llvm::pdb::NativeSession::findLineNumbersByAddress
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
Definition: NativeSession.cpp:272
llvm::pdb::NativeSession::getPDBFile
const PDBFile & getPDBFile() const
Definition: NativeSession.h:106
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:111
llvm::pdb::NativeSession::getSourceFileById
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
Definition: NativeSession.cpp:325
llvm::pdb::PDB_NameSearchFlags
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:102
llvm::pdb::NativeSession::findSourceFiles
std::unique_ptr< IPDBEnumSourceFiles > findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:290
llvm::IntervalMap< uint64_t, uint16_t, 8, IntervalMapHalfOpenInfo< uint64_t > >::Allocator
typename Sizer::Allocator Allocator
Definition: IntervalMap.h:964
llvm::pdb::NativeSession::getSectionContribs
std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const override
Definition: NativeSession.cpp:353
llvm::pdb::NativeSession::createFromPdb
static Error createFromPdb(std::unique_ptr< MemoryBuffer > MB, std::unique_ptr< IPDBSession > &Session)
Definition: NativeSession.cpp:64
llvm::pdb::NativeSession::setLoadAddress
bool setLoadAddress(uint64_t Address) override
Definition: NativeSession.cpp:198
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
llvm::pdb::NativeSession::findLineNumbersByRVA
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override
Definition: NativeSession.cpp:278
IPDBSession.h
llvm::pdb::NativeSession::findSymbolByRVA
std::unique_ptr< PDBSymbol > findSymbolByRVA(uint32_t RVA, PDB_SymType Type) override
Definition: NativeSession.cpp:248
llvm::pdb::NativeSession::addressForVA
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
Definition: NativeSession.cpp:212
llvm::HighlightColor::Address
@ Address
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:109
llvm::pdb::NativeSession::addressForRVA
bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const override
Definition: NativeSession.cpp:218
llvm::pdb::NativeSession::getGlobalScope
std::unique_ptr< PDBSymbolExe > getGlobalScope() override
Definition: NativeSession.cpp:203
llvm::pdb::NativeSession::findSymbolBySectOffset
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) override
Definition: NativeSession.cpp:257
llvm::pdb::NativeSession::getSymbolCache
const SymbolCache & getSymbolCache() const
Definition: NativeSession.h:110
llvm::pdb::NativeSession::getSymbolById
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const override
Definition: NativeSession.cpp:208
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::pdb::NativeSession::findSymbolByAddress
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) override
Definition: NativeSession.cpp:241
llvm::pdb::NativeSession::~NativeSession
~NativeSession() override
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::pdb::PDB_SymType::Compiland
@ Compiland
NativeRawSymbol.h
TypeIndex.h
llvm::pdb::NativeSession
Definition: NativeSession.h:28
llvm::pdb::NativeSession::searchForPdb
static Expected< std::string > searchForPdb(const PdbSearchOptions &Opts)
Definition: NativeSession.cpp:165
llvm::Pattern
Definition: FileCheckImpl.h:614
llvm::pdb::PDBFile
Definition: PDBFile.h:42
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
SymbolCache.h
llvm::IntervalMap
Definition: IntervalMap.h:938
llvm::pdb::NativeSession::findCompilandsForSourceFile
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > findCompilandsForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:304
llvm::pdb::NativeSession::findLineNumbers
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const override
Definition: NativeSession.cpp:266
llvm::pdb::PDBSymbolCompiland
Definition: PDBSymbolCompiland.h:21
llvm::pdb::NativeSession::getNativeGlobalScope
NativeExeSymbol & getNativeGlobalScope() const
Definition: NativeSession.cpp:367
llvm::pdb::NativeSession::getAllSourceFiles
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
Definition: NativeSession.cpp:315
llvm::pdb::NativeSession::getDebugStreams
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
Definition: NativeSession.cpp:329
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::pdb::NativeSession::findOneCompilandForSourceFile
std::unique_ptr< PDBSymbolCompiland > findOneCompilandForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition: NativeSession.cpp:310
llvm::pdb::NativeSession::moduleIndexForSectOffset
bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:403