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