LLDB  mainline
PdbIndex.h
Go to the documentation of this file.
1 //===-- PdbIndex.h ----------------------------------------------*- 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 LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBINDEX_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBINDEX_H
11 
12 #include "lldb/lldb-types.h"
13 #include "llvm/ADT/IntervalMap.h"
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
16 #include "llvm/DebugInfo/PDB/PDBTypes.h"
17 
18 #include "CompileUnitIndex.h"
19 #include "PdbSymUid.h"
20 
21 #include <map>
22 #include <memory>
23 
24 namespace llvm {
25 namespace pdb {
26 class DbiStream;
27 class TpiStream;
28 class TpiStream;
29 class InfoStream;
30 class PublicsStream;
31 class GlobalsStream;
32 class SymbolStream;
33 } // namespace pdb
34 } // namespace llvm
35 
36 namespace lldb_private {
37 namespace npdb {
38 struct SegmentOffset;
39 
40 /// PdbIndex - Lazy access to the important parts of a PDB file.
41 ///
42 /// This is a layer on top of LLVM's native PDB support libraries which cache
43 /// certain data when it is accessed the first time. The entire PDB file is
44 /// mapped into memory, and the underlying support libraries vend out memory
45 /// that is always backed by the file, so it is safe to hold StringRefs and
46 /// ArrayRefs into the backing memory as long as the PdbIndex instance is
47 /// alive.
48 class PdbIndex {
49 
50  /// The underlying PDB file.
51  llvm::pdb::PDBFile *m_file = nullptr;
52 
53  /// The DBI stream. This contains general high level information about the
54  /// features present in the PDB file, compile units (such as the information
55  /// necessary to locate full symbol information for each compile unit),
56  /// section contributions, and other data which is not specifically symbol or
57  /// type records.
58  llvm::pdb::DbiStream *m_dbi = nullptr;
59 
60  /// TPI (types) and IPI (indices) streams. These are both in the exact same
61  /// format with different data. Most type records are stored in the TPI
62  /// stream but certain specific types of records are stored in the IPI stream.
63  /// The IPI stream records can refer to the records in the TPI stream, but not
64  /// the other way around.
65  llvm::pdb::TpiStream *m_tpi = nullptr;
66  llvm::pdb::TpiStream *m_ipi = nullptr;
67 
68  /// This is called the "PDB Stream" in the Microsoft reference implementation.
69  /// It contains information about the structure of the file, as well as fields
70  /// used to match EXE and PDB.
71  llvm::pdb::InfoStream *m_info = nullptr;
72 
73  /// Publics stream. Is actually a serialized hash table where the keys are
74  /// addresses of symbols in the executable, and values are a record containing
75  /// mangled names and an index which can be used to locate more detailed info
76  /// about the symbol in the Symbol Records stream. The publics stream only
77  /// contains info about externally visible symbols.
78  llvm::pdb::PublicsStream *m_publics = nullptr;
79 
80  /// Globals stream. Contrary to its name, this does not contain information
81  /// about all "global variables" or "global functions". Rather, it is the
82  /// "global symbol table", i.e. it contains information about *every* symbol
83  /// in the executable. It is a hash table keyed on name, whose values are
84  /// indices into the symbol records stream to find the full record.
85  llvm::pdb::GlobalsStream *m_globals = nullptr;
86 
87  /// Symbol records stream. The publics and globals stream refer to records
88  /// in this stream. For some records, like constants and typedefs, the
89  /// complete record lives in this stream. For other symbol types, such as
90  /// functions, data, and other things that have been materialied into a
91  /// specific compile unit, the records here simply provide a reference
92  /// necessary to locate the full information.
93  llvm::pdb::SymbolStream *m_symrecords = nullptr;
94 
95  /// Index of all compile units, mapping identifier to |CompilandIndexItem|
96  /// instance.
98 
99  /// An allocator for the interval maps
100  llvm::IntervalMap<lldb::addr_t, uint32_t>::Allocator m_allocator;
101 
102  /// Maps virtual address to module index
103  llvm::IntervalMap<lldb::addr_t, uint16_t> m_va_to_modi;
104 
105  /// The address at which the program has been loaded into memory.
107 
108  PdbIndex();
109 
111 
112 public:
113  static llvm::Expected<std::unique_ptr<PdbIndex>> create(llvm::pdb::PDBFile *);
114 
117  void ParseSectionContribs();
118 
119  llvm::pdb::PDBFile &pdb() { return *m_file; }
120  const llvm::pdb::PDBFile &pdb() const { return *m_file; }
121 
122  llvm::pdb::DbiStream &dbi() { return *m_dbi; }
123  const llvm::pdb::DbiStream &dbi() const { return *m_dbi; }
124 
125  llvm::pdb::TpiStream &tpi() { return *m_tpi; }
126  const llvm::pdb::TpiStream &tpi() const { return *m_tpi; }
127 
128  llvm::pdb::TpiStream &ipi() { return *m_ipi; }
129  const llvm::pdb::TpiStream &ipi() const { return *m_ipi; }
130 
131  llvm::pdb::InfoStream &info() { return *m_info; }
132  const llvm::pdb::InfoStream &info() const { return *m_info; }
133 
134  llvm::pdb::PublicsStream &publics() { return *m_publics; }
135  const llvm::pdb::PublicsStream &publics() const { return *m_publics; }
136 
137  llvm::pdb::GlobalsStream &globals() { return *m_globals; }
138  const llvm::pdb::GlobalsStream &globals() const { return *m_globals; }
139 
140  llvm::pdb::SymbolStream &symrecords() { return *m_symrecords; }
141  const llvm::pdb::SymbolStream &symrecords() const { return *m_symrecords; }
142 
144  const CompileUnitIndex &compilands() const { return m_cus; }
145 
146  lldb::addr_t MakeVirtualAddress(uint16_t segment, uint32_t offset) const;
148 
149  std::vector<SymbolAndUid> FindSymbolsByVa(lldb::addr_t va);
150 
151  llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const;
152  llvm::codeview::CVSymbol ReadSymbolRecord(PdbGlobalSymId global) const;
153 
154  llvm::Optional<uint16_t> GetModuleIndexForAddr(uint16_t segment,
155  uint32_t offset) const;
156  llvm::Optional<uint16_t> GetModuleIndexForVa(lldb::addr_t va) const;
157 };
158 } // namespace npdb
159 } // namespace lldb_private
160 
161 #endif
llvm
Definition: Debugger.h:49
lldb_private::npdb::PdbIndex::globals
const llvm::pdb::GlobalsStream & globals() const
Definition: PdbIndex.h:138
lldb_private::npdb::PdbIndex::publics
llvm::pdb::PublicsStream & publics()
Definition: PdbIndex.h:134
lldb_private::npdb::CompileUnitIndex
Indexes information about all compile units.
Definition: CompileUnitIndex.h:76
lldb_private::npdb::PdbIndex::compilands
CompileUnitIndex & compilands()
Definition: PdbIndex.h:143
lldb_private::npdb::PdbIndex::GetLoadAddress
lldb::addr_t GetLoadAddress() const
Definition: PdbIndex.h:116
lldb_private::npdb::PdbIndex::tpi
const llvm::pdb::TpiStream & tpi() const
Definition: PdbIndex.h:126
lldb_private::npdb::PdbIndex
PdbIndex - Lazy access to the important parts of a PDB file.
Definition: PdbIndex.h:48
lldb_private::npdb::PdbCompilandSymId
Definition: PdbSymUid.h:44
lldb_private::npdb::SegmentOffset
Definition: PdbUtil.h:88
lldb_private::npdb::PdbIndex::m_va_to_modi
llvm::IntervalMap< lldb::addr_t, uint16_t > m_va_to_modi
Maps virtual address to module index.
Definition: PdbIndex.h:103
lldb_private::npdb::PdbIndex::m_publics
llvm::pdb::PublicsStream * m_publics
Publics stream.
Definition: PdbIndex.h:78
lldb_private::npdb::PdbIndex::m_allocator
llvm::IntervalMap< lldb::addr_t, uint32_t >::Allocator m_allocator
An allocator for the interval maps.
Definition: PdbIndex.h:100
lldb_private::npdb::PdbIndex::info
const llvm::pdb::InfoStream & info() const
Definition: PdbIndex.h:132
lldb_private::npdb::PdbIndex::ReadSymbolRecord
llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const
Definition: PdbIndex.cpp:187
lldb_private::npdb::PdbIndex::BuildAddrToSymbolMap
void BuildAddrToSymbolMap(CompilandIndexItem &cci)
Definition: PdbIndex.cpp:121
lldb_private::npdb::PdbIndex::pdb
const llvm::pdb::PDBFile & pdb() const
Definition: PdbIndex.h:120
CompileUnitIndex.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::npdb::PdbIndex::m_dbi
llvm::pdb::DbiStream * m_dbi
The DBI stream.
Definition: PdbIndex.h:58
lldb_private::npdb::PdbIndex::GetModuleIndexForVa
llvm::Optional< uint16_t > GetModuleIndexForVa(lldb::addr_t va) const
Definition: PdbIndex.cpp:88
lldb_private::npdb::PdbGlobalSymId
Definition: PdbSymUid.h:57
lldb_private::npdb::PdbIndex::ipi
const llvm::pdb::TpiStream & ipi() const
Definition: PdbIndex.h:129
lldb_private::npdb::PdbIndex::m_globals
llvm::pdb::GlobalsStream * m_globals
Globals stream.
Definition: PdbIndex.h:85
lldb_private::npdb::PdbIndex::tpi
llvm::pdb::TpiStream & tpi()
Definition: PdbIndex.h:125
lldb_private::npdb::PdbIndex::compilands
const CompileUnitIndex & compilands() const
Definition: PdbIndex.h:144
lldb_private::npdb::PdbIndex::dbi
llvm::pdb::DbiStream & dbi()
Definition: PdbIndex.h:122
lldb_private::npdb::PdbIndex::publics
const llvm::pdb::PublicsStream & publics() const
Definition: PdbIndex.h:135
lldb_private::npdb::PdbIndex::m_info
llvm::pdb::InfoStream * m_info
This is called the "PDB Stream" in the Microsoft reference implementation.
Definition: PdbIndex.h:71
lldb_private::npdb::PdbIndex::create
static llvm::Expected< std::unique_ptr< PdbIndex > > create(llvm::pdb::PDBFile *)
Definition: PdbIndex.cpp:42
lldb_private::npdb::PdbIndex::m_load_address
lldb::addr_t m_load_address
The address at which the program has been loaded into memory.
Definition: PdbIndex.h:106
lldb_private::npdb::PdbIndex::SetLoadAddress
void SetLoadAddress(lldb::addr_t addr)
Definition: PdbIndex.h:115
lldb_private::npdb::PdbIndex::m_cus
CompileUnitIndex m_cus
Index of all compile units, mapping identifier to |CompilandIndexItem| instance.
Definition: PdbIndex.h:97
lldb_private::npdb::PdbIndex::info
llvm::pdb::InfoStream & info()
Definition: PdbIndex.h:131
lldb_private::npdb::PdbIndex::m_tpi
llvm::pdb::TpiStream * m_tpi
TPI (types) and IPI (indices) streams.
Definition: PdbIndex.h:65
lldb-types.h
lldb_private::npdb::PdbIndex::FindSymbolsByVa
std::vector< SymbolAndUid > FindSymbolsByVa(lldb::addr_t va)
Definition: PdbIndex.cpp:141
lldb_private::npdb::CompilandIndexItem
Represents a single compile unit.
Definition: CompileUnitIndex.h:37
uint32_t
lldb_private::npdb::PdbIndex::dbi
const llvm::pdb::DbiStream & dbi() const
Definition: PdbIndex.h:123
PdbSymUid.h
lldb_private::npdb::PdbIndex::MakeVirtualAddress
lldb::addr_t MakeVirtualAddress(uint16_t segment, uint32_t offset) const
Definition: PdbIndex.cpp:61
uint16_t
lldb_private::npdb::PdbIndex::ipi
llvm::pdb::TpiStream & ipi()
Definition: PdbIndex.h:128
lldb_private::npdb::PdbIndex::symrecords
llvm::pdb::SymbolStream & symrecords()
Definition: PdbIndex.h:140
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::npdb::PdbIndex::m_file
llvm::pdb::PDBFile * m_file
The underlying PDB file.
Definition: PdbIndex.h:51
lldb_private::npdb::PdbIndex::GetModuleIndexForAddr
llvm::Optional< uint16_t > GetModuleIndexForAddr(uint16_t segment, uint32_t offset) const
Definition: PdbIndex.cpp:84
lldb_private::npdb::PdbIndex::symrecords
const llvm::pdb::SymbolStream & symrecords() const
Definition: PdbIndex.h:141
lldb_private::npdb::PdbIndex::PdbIndex
PdbIndex()
Definition: PdbIndex.cpp:31
lldb_private::npdb::PdbIndex::pdb
llvm::pdb::PDBFile & pdb()
Definition: PdbIndex.h:119
lldb_private::npdb::PdbIndex::m_ipi
llvm::pdb::TpiStream * m_ipi
Definition: PdbIndex.h:66
lldb_private::npdb::PdbIndex::m_symrecords
llvm::pdb::SymbolStream * m_symrecords
Symbol records stream.
Definition: PdbIndex.h:93
lldb_private::npdb::PdbIndex::globals
llvm::pdb::GlobalsStream & globals()
Definition: PdbIndex.h:137
lldb_private::npdb::PdbIndex::ParseSectionContribs
void ParseSectionContribs()
Definition: PdbIndex.cpp:96