LLDB mainline
CompileUnitIndex.h
Go to the documentation of this file.
1//===-- CompileUnitIndex.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_COMPILEUNITINDEX_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H
11
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
15#include "llvm/ADT/IntervalMap.h"
16#include "llvm/ADT/SmallString.h"
17#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
18#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
19#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
20#include "llvm/DebugInfo/CodeView/TypeIndex.h"
21#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
22#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
23#include "llvm/DebugInfo/PDB/PDBTypes.h"
24#include "llvm/Support/Error.h"
25
26#include "PdbSymUid.h"
27
28#include <map>
29#include <memory>
30#include <optional>
31
32namespace lldb_private {
33
34namespace npdb {
35class PdbIndex;
36
37/// Represents a single compile unit. This class is useful for collecting the
38/// important accessors and information about a compile unit from disparate
39/// parts of the PDB into a single place, simplifying acess to compile unit
40/// information for the callers.
43 llvm::pdb::ModuleDebugStreamRef debug_stream,
44 llvm::pdb::DbiModuleDescriptor descriptor);
45
46 // index of this compile unit.
48
49 // debug stream.
50 llvm::pdb::ModuleDebugStreamRef m_debug_stream;
51
52 // dbi module descriptor.
53 llvm::pdb::DbiModuleDescriptor m_module_descriptor;
54
55 llvm::codeview::StringsAndChecksumsRef m_strings;
56
57 // List of files which contribute to this compiland.
58 std::vector<llvm::StringRef> m_file_list;
59
60 // Maps virtual address to global symbol id, which can then be used to
61 // locate the exact compile unit and offset of the symbol. Note that this
62 // is intentionally an ordered map so that we can find all symbols up to a
63 // given starting address.
64 std::map<lldb::addr_t, PdbSymUid> m_symbols_by_va;
65
66 // S_COMPILE3 sym describing compilation settings for the module.
67 std::optional<llvm::codeview::Compile3Sym> m_compile_opts;
68
69 // S_OBJNAME sym describing object name.
70 std::optional<llvm::codeview::ObjNameSym> m_obj_name;
71
72 // LF_BUILDINFO sym describing source file name, working directory,
73 // command line, etc. This usually contains exactly 5 items which
74 // are references to other strings.
75 llvm::SmallVector<llvm::codeview::TypeIndex, 5> m_build_info;
76
77 // Inlinee lines table in this compile unit.
78 std::map<llvm::codeview::TypeIndex, llvm::codeview::InlineeSourceLine>
80
81 // It's the line table parsed from DEBUG_S_LINES sections, mapping the file
82 // address range to file index and source line number.
85 std::pair<uint32_t, uint32_t>>;
87};
88
89/// Indexes information about all compile units. This is really just a map of
90/// global compile unit index to |CompilandIndexItem| structures.
93 llvm::DenseMap<uint16_t, std::unique_ptr<CompilandIndexItem>> m_comp_units;
94
95public:
96 explicit CompileUnitIndex(PdbIndex &index) : m_index(index) {}
97
99
100 const CompilandIndexItem *GetCompiland(uint16_t modi) const;
101
102 CompilandIndexItem *GetCompiland(uint16_t modi);
103
104 llvm::Expected<llvm::SmallString<64>>
105 GetMainSourceFile(const CompilandIndexItem &item) const;
106};
107} // namespace npdb
108} // namespace lldb_private
109
110#endif
llvm::DenseMap< uint16_t, std::unique_ptr< CompilandIndexItem > > m_comp_units
CompilandIndexItem & GetOrCreateCompiland(uint16_t modi)
const CompilandIndexItem * GetCompiland(uint16_t modi) const
llvm::Expected< llvm::SmallString< 64 > > GetMainSourceFile(const CompilandIndexItem &item) const
PdbIndex - Lazy access to the important parts of a PDB file.
Definition PdbIndex.h:47
A class that represents a running process on the host machine.
uint64_t addr_t
Definition lldb-types.h:80
Represents a single compile unit.
llvm::pdb::DbiModuleDescriptor m_module_descriptor
lldb_private::RangeDataVector< lldb::addr_t, uint32_t, std::pair< uint32_t, uint32_t > > GlobalLineTable
std::map< llvm::codeview::TypeIndex, llvm::codeview::InlineeSourceLine > m_inline_map
llvm::SmallVector< llvm::codeview::TypeIndex, 5 > m_build_info
CompilandIndexItem(PdbCompilandId m_id, llvm::pdb::ModuleDebugStreamRef debug_stream, llvm::pdb::DbiModuleDescriptor descriptor)
std::optional< llvm::codeview::ObjNameSym > m_obj_name
std::optional< llvm::codeview::Compile3Sym > m_compile_opts
llvm::pdb::ModuleDebugStreamRef m_debug_stream
std::map< lldb::addr_t, PdbSymUid > m_symbols_by_va
llvm::codeview::StringsAndChecksumsRef m_strings
std::vector< llvm::StringRef > m_file_list