]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / NativePDB / CompileUnitIndex.h
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_PLUGINS_SYMBOLFILENATIVEPDB_COMPILEUNITINDEX_H
10 #define LLDB_PLUGINS_SYMBOLFILENATIVEPDB_COMPILEUNITINDEX_H
11
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"
22
23 #include "PdbSymUid.h"
24
25 #include <map>
26 #include <memory>
27
28 namespace lldb_private {
29
30 namespace npdb {
31 class PdbIndex;
32
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);
41
42   // index of this compile unit.
43   PdbCompilandId m_id;
44
45   // debug stream.
46   llvm::pdb::ModuleDebugStreamRef m_debug_stream;
47
48   // dbi module descriptor.
49   llvm::pdb::DbiModuleDescriptor m_module_descriptor;
50
51   llvm::codeview::StringsAndChecksumsRef m_strings;
52
53   // List of files which contribute to this compiland.
54   std::vector<llvm::StringRef> m_file_list;
55
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;
61
62   // S_COMPILE3 sym describing compilation settings for the module.
63   llvm::Optional<llvm::codeview::Compile3Sym> m_compile_opts;
64
65   // S_OBJNAME sym describing object name.
66   llvm::Optional<llvm::codeview::ObjNameSym> m_obj_name;
67
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;
72 };
73
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 {
77   PdbIndex &m_index;
78   llvm::DenseMap<uint16_t, std::unique_ptr<CompilandIndexItem>> m_comp_units;
79
80 public:
81   explicit CompileUnitIndex(PdbIndex &index) : m_index(index) {}
82
83   CompilandIndexItem &GetOrCreateCompiland(uint16_t modi);
84
85   const CompilandIndexItem *GetCompiland(uint16_t modi) const;
86
87   CompilandIndexItem *GetCompiland(uint16_t modi);
88
89   llvm::SmallString<64> GetMainSourceFile(const CompilandIndexItem &item) const;
90 };
91 } // namespace npdb
92 } // namespace lldb_private
93
94 #endif