1 //===-- CompileUnitIndex.h --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_PLUGINS_SYMBOLFILENATIVEPDB_COMPILEUNITINDEX_H
10 #define LLDB_PLUGINS_SYMBOLFILENATIVEPDB_COMPILEUNITINDEX_H
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/IntervalMap.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
17 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
18 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
19 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
20 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
21 #include "llvm/DebugInfo/PDB/PDBTypes.h"
23 #include "PdbSymUid.h"
28 namespace lldb_private {
33 /// Represents a single compile unit. This class is useful for collecting the
34 /// important accessors and information about a compile unit from disparate
35 /// parts of the PDB into a single place, simplifying acess to compile unit
36 /// information for the callers.
37 struct CompilandIndexItem {
38 CompilandIndexItem(PdbCompilandId m_id,
39 llvm::pdb::ModuleDebugStreamRef debug_stream,
40 llvm::pdb::DbiModuleDescriptor descriptor);
42 // index of this compile unit.
46 llvm::pdb::ModuleDebugStreamRef m_debug_stream;
48 // dbi module descriptor.
49 llvm::pdb::DbiModuleDescriptor m_module_descriptor;
51 llvm::codeview::StringsAndChecksumsRef m_strings;
53 // List of files which contribute to this compiland.
54 std::vector<llvm::StringRef> m_file_list;
56 // Maps virtual address to global symbol id, which can then be used to
57 // locate the exact compile unit and offset of the symbol. Note that this
58 // is intentionally an ordered map so that we can find all symbols up to a
59 // given starting address.
60 std::map<lldb::addr_t, PdbSymUid> m_symbols_by_va;
62 // S_COMPILE3 sym describing compilation settings for the module.
63 llvm::Optional<llvm::codeview::Compile3Sym> m_compile_opts;
65 // S_OBJNAME sym describing object name.
66 llvm::Optional<llvm::codeview::ObjNameSym> m_obj_name;
68 // LF_BUILDINFO sym describing source file name, working directory,
69 // command line, etc. This usually contains exactly 5 items which
70 // are references to other strings.
71 llvm::SmallVector<llvm::codeview::TypeIndex, 5> m_build_info;
74 /// Indexes information about all compile units. This is really just a map of
75 /// global compile unit index to |CompilandIndexItem| structures.
76 class CompileUnitIndex {
78 llvm::DenseMap<uint16_t, std::unique_ptr<CompilandIndexItem>> m_comp_units;
81 explicit CompileUnitIndex(PdbIndex &index) : m_index(index) {}
83 CompilandIndexItem &GetOrCreateCompiland(uint16_t modi);
85 const CompilandIndexItem *GetCompiland(uint16_t modi) const;
87 CompilandIndexItem *GetCompiland(uint16_t modi);
89 llvm::SmallString<64> GetMainSourceFile(const CompilandIndexItem &item) const;
92 } // namespace lldb_private