12#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
13#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
14#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
15#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
16#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
17#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
18#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
19#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
20#include "llvm/Object/COFF.h"
21#include "llvm/Support/Error.h"
34#define ASSIGN_PTR_OR_RETURN(result_ptr, expr) \
36 auto expected_result = expr; \
37 if (!expected_result) \
38 return expected_result.takeError(); \
39 result_ptr = &expected_result.get(); \
42llvm::Expected<std::unique_ptr<PdbIndex>>
46 std::unique_ptr<PdbIndex> result(
new PdbIndex());
55 result->m_tpi->buildHashMap();
57 result->m_file = file;
59 return std::move(result);
63 uint32_t offset)
const {
64 uint32_t max_section =
dbi().getSectionHeaders().size();
68 if (segment == 0 || segment > max_section)
71 const llvm::object::coff_section &cs =
dbi().getSectionHeaders()[segment - 1];
77 uint32_t offset)
const {
90 class Visitor :
public ISectionContribVisitor {
92 llvm::IntervalMap<uint64_t, uint16_t> &m_imap;
95 Visitor(
PdbIndex &ctx, llvm::IntervalMap<uint64_t, uint16_t> &imap)
96 : m_ctx(ctx), m_imap(imap) {}
98 void visit(
const SectionContrib &C)
override {
105 uint64_t end = va + C.Size;
108 m_imap.insert(va, end - 1, C.Imod);
110 void visit(
const SectionContrib2 &C)
override { visit(C.Base); }
113 dbi().visitSectionContributions(v);
118 "Addr to symbol map is already built!");
121 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
139 std::vector<SymbolAndUid> result;
180 if (va >= start && va < end)
181 result.push_back({std::move(sym), iter->second});
#define ASSIGN_PTR_OR_RETURN(result_ptr, expr)
CompilandIndexItem & GetOrCreateCompiland(uint16_t modi)
const CompilandIndexItem * GetCompiland(uint16_t modi) const
PdbIndex - Lazy access to the important parts of a PDB file.
void ParseSectionContribs()
std::vector< SymbolAndUid > FindSymbolsByVa(lldb::addr_t va)
CompileUnitIndex & compilands()
llvm::pdb::DbiStream & dbi()
void BuildAddrToSymbolMap(CompilandIndexItem &cci)
llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const
std::optional< uint16_t > GetModuleIndexForVa(lldb::addr_t va) const
std::optional< uint16_t > GetModuleIndexForAddr(uint16_t segment, uint32_t offset) const
lldb::addr_t m_load_address
The address at which the program has been loaded into memory.
llvm::pdb::SymbolStream & symrecords()
llvm::IntervalMap< lldb::addr_t, uint16_t > m_va_to_modi
Maps virtual address to module index.
static llvm::Expected< std::unique_ptr< PdbIndex > > create(llvm::pdb::PDBFile *)
lldb::addr_t MakeVirtualAddress(uint16_t segment, uint32_t offset) const
#define LLDB_INVALID_ADDRESS
bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym)
SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym)
SegmentOffsetLength GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym)
bool SymbolIsCode(const llvm::codeview::CVSymbol &sym)
A class that represents a running process on the host machine.
Represents a single compile unit.
llvm::pdb::ModuleDebugStreamRef m_debug_stream
std::map< lldb::addr_t, PdbSymUid > m_symbols_by_va