Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h
39642 views
//===-- PdbIndex.h ----------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBINDEX_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBINDEX_H1011#include "lldb/lldb-types.h"12#include "llvm/ADT/IntervalMap.h"13#include "llvm/DebugInfo/PDB/Native/PDBFile.h"14#include "llvm/DebugInfo/PDB/PDBTypes.h"1516#include "CompileUnitIndex.h"17#include "PdbSymUid.h"1819#include <map>20#include <memory>21#include <optional>2223namespace llvm {24namespace pdb {25class DbiStream;26class TpiStream;27class InfoStream;28class PublicsStream;29class GlobalsStream;30class SymbolStream;31} // namespace pdb32} // namespace llvm3334namespace lldb_private {35namespace npdb {36struct SegmentOffset;3738/// PdbIndex - Lazy access to the important parts of a PDB file.39///40/// This is a layer on top of LLVM's native PDB support libraries which cache41/// certain data when it is accessed the first time. The entire PDB file is42/// mapped into memory, and the underlying support libraries vend out memory43/// that is always backed by the file, so it is safe to hold StringRefs and44/// ArrayRefs into the backing memory as long as the PdbIndex instance is45/// alive.46class PdbIndex {4748/// The underlying PDB file.49llvm::pdb::PDBFile *m_file = nullptr;5051/// The DBI stream. This contains general high level information about the52/// features present in the PDB file, compile units (such as the information53/// necessary to locate full symbol information for each compile unit),54/// section contributions, and other data which is not specifically symbol or55/// type records.56llvm::pdb::DbiStream *m_dbi = nullptr;5758/// TPI (types) and IPI (indices) streams. These are both in the exact same59/// format with different data. Most type records are stored in the TPI60/// stream but certain specific types of records are stored in the IPI stream.61/// The IPI stream records can refer to the records in the TPI stream, but not62/// the other way around.63llvm::pdb::TpiStream *m_tpi = nullptr;64llvm::pdb::TpiStream *m_ipi = nullptr;6566/// This is called the "PDB Stream" in the Microsoft reference implementation.67/// It contains information about the structure of the file, as well as fields68/// used to match EXE and PDB.69llvm::pdb::InfoStream *m_info = nullptr;7071/// Publics stream. Is actually a serialized hash table where the keys are72/// addresses of symbols in the executable, and values are a record containing73/// mangled names and an index which can be used to locate more detailed info74/// about the symbol in the Symbol Records stream. The publics stream only75/// contains info about externally visible symbols.76llvm::pdb::PublicsStream *m_publics = nullptr;7778/// Globals stream. Contrary to its name, this does not contain information79/// about all "global variables" or "global functions". Rather, it is the80/// "global symbol table", i.e. it contains information about *every* symbol81/// in the executable. It is a hash table keyed on name, whose values are82/// indices into the symbol records stream to find the full record.83llvm::pdb::GlobalsStream *m_globals = nullptr;8485/// Symbol records stream. The publics and globals stream refer to records86/// in this stream. For some records, like constants and typedefs, the87/// complete record lives in this stream. For other symbol types, such as88/// functions, data, and other things that have been materialied into a89/// specific compile unit, the records here simply provide a reference90/// necessary to locate the full information.91llvm::pdb::SymbolStream *m_symrecords = nullptr;9293/// Index of all compile units, mapping identifier to |CompilandIndexItem|94/// instance.95CompileUnitIndex m_cus;9697/// An allocator for the interval maps98llvm::IntervalMap<lldb::addr_t, uint32_t>::Allocator m_allocator;99100/// Maps virtual address to module index101llvm::IntervalMap<lldb::addr_t, uint16_t> m_va_to_modi;102103/// The address at which the program has been loaded into memory.104lldb::addr_t m_load_address = 0;105106PdbIndex();107108void BuildAddrToSymbolMap(CompilandIndexItem &cci);109110public:111static llvm::Expected<std::unique_ptr<PdbIndex>> create(llvm::pdb::PDBFile *);112113void SetLoadAddress(lldb::addr_t addr) { m_load_address = addr; }114lldb::addr_t GetLoadAddress() const { return m_load_address; }115void ParseSectionContribs();116117llvm::pdb::PDBFile &pdb() { return *m_file; }118const llvm::pdb::PDBFile &pdb() const { return *m_file; }119120llvm::pdb::DbiStream &dbi() { return *m_dbi; }121const llvm::pdb::DbiStream &dbi() const { return *m_dbi; }122123llvm::pdb::TpiStream &tpi() { return *m_tpi; }124const llvm::pdb::TpiStream &tpi() const { return *m_tpi; }125126llvm::pdb::TpiStream &ipi() { return *m_ipi; }127const llvm::pdb::TpiStream &ipi() const { return *m_ipi; }128129llvm::pdb::InfoStream &info() { return *m_info; }130const llvm::pdb::InfoStream &info() const { return *m_info; }131132llvm::pdb::PublicsStream &publics() { return *m_publics; }133const llvm::pdb::PublicsStream &publics() const { return *m_publics; }134135llvm::pdb::GlobalsStream &globals() { return *m_globals; }136const llvm::pdb::GlobalsStream &globals() const { return *m_globals; }137138llvm::pdb::SymbolStream &symrecords() { return *m_symrecords; }139const llvm::pdb::SymbolStream &symrecords() const { return *m_symrecords; }140141CompileUnitIndex &compilands() { return m_cus; }142const CompileUnitIndex &compilands() const { return m_cus; }143144lldb::addr_t MakeVirtualAddress(uint16_t segment, uint32_t offset) const;145146std::vector<SymbolAndUid> FindSymbolsByVa(lldb::addr_t va);147148llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const;149llvm::codeview::CVSymbol ReadSymbolRecord(PdbGlobalSymId global) const;150151std::optional<uint16_t> GetModuleIndexForAddr(uint16_t segment,152uint32_t offset) const;153std::optional<uint16_t> GetModuleIndexForVa(lldb::addr_t va) const;154};155} // namespace npdb156} // namespace lldb_private157158#endif159160161