LLVM 22.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
13#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Error.h"
20
21namespace llvm {
22class MemoryBuffer;
23namespace pdb {
24class PDBFile;
25class NativeExeSymbol;
26class IPDBSourceFile;
27class ModuleDebugStreamRef;
28class PDBSymbol;
29class PDBSymbolCompiland;
30class PDBSymbolExe;
31template <typename ChildType> class IPDBEnumChildren;
32
34 struct PdbSearchOptions {
35 StringRef ExePath;
36 // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv)
37 };
38
39public:
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,
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,
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
110 PDBFile &getPDBFile() { return *Pdb; }
111 const PDBFile &getPDBFile() const { return *Pdb; }
112
113 NativeExeSymbol &getNativeGlobalScope() const;
114 SymbolCache &getSymbolCache() { return Cache; }
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;
122
123private:
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 =
137 IMap::Allocator IMapAllocator;
138 IMap AddrToModuleIndex;
139};
140} // namespace pdb
141} // namespace llvm
142
143#endif
This file defines the BumpPtrAllocator interface.
#define LLVM_ABI
Definition: Compiler.h:213
uint32_t Index
uint64_t Offset
Definition: ELF_riscv.cpp:478
This file implements a coalescing interval map for small objects.
Basic Register Allocator
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:26
IPDBSourceFile defines an interface used to represent source files whose information are stored in th...
SymbolCache & getSymbolCache()
const SymbolCache & getSymbolCache() const
const PDBFile & getPDBFile() const
uint32_t SymIndexId
Definition: PDBTypes.h:26
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:102
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
LLVM_ABI Expected< ModuleDebugStreamRef > getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index)
Definition: InputFile.cpp:39
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18