xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1061da546Spatrick //===-- CompileUnitIndex.h --------------------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H
10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H
11061da546Spatrick 
12*f6aab3d8Srobert #include "lldb/Utility/RangeMap.h"
13061da546Spatrick #include "llvm/ADT/DenseMap.h"
14061da546Spatrick #include "llvm/ADT/DenseSet.h"
15061da546Spatrick #include "llvm/ADT/IntervalMap.h"
16*f6aab3d8Srobert #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
17061da546Spatrick #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
18061da546Spatrick #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
19061da546Spatrick #include "llvm/DebugInfo/CodeView/TypeIndex.h"
20061da546Spatrick #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
21061da546Spatrick #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
22061da546Spatrick #include "llvm/DebugInfo/PDB/PDBTypes.h"
23061da546Spatrick 
24061da546Spatrick #include "PdbSymUid.h"
25061da546Spatrick 
26061da546Spatrick #include <map>
27061da546Spatrick #include <memory>
28*f6aab3d8Srobert #include <optional>
29061da546Spatrick 
30061da546Spatrick namespace lldb_private {
31061da546Spatrick 
32061da546Spatrick namespace npdb {
33061da546Spatrick class PdbIndex;
34061da546Spatrick 
35061da546Spatrick /// Represents a single compile unit.  This class is useful for collecting the
36061da546Spatrick /// important accessors and information about a compile unit from disparate
37061da546Spatrick /// parts of the PDB into a single place, simplifying acess to compile unit
38061da546Spatrick /// information for the callers.
39061da546Spatrick struct CompilandIndexItem {
40061da546Spatrick   CompilandIndexItem(PdbCompilandId m_id,
41061da546Spatrick                      llvm::pdb::ModuleDebugStreamRef debug_stream,
42061da546Spatrick                      llvm::pdb::DbiModuleDescriptor descriptor);
43061da546Spatrick 
44061da546Spatrick   // index of this compile unit.
45061da546Spatrick   PdbCompilandId m_id;
46061da546Spatrick 
47061da546Spatrick   // debug stream.
48061da546Spatrick   llvm::pdb::ModuleDebugStreamRef m_debug_stream;
49061da546Spatrick 
50061da546Spatrick   // dbi module descriptor.
51061da546Spatrick   llvm::pdb::DbiModuleDescriptor m_module_descriptor;
52061da546Spatrick 
53061da546Spatrick   llvm::codeview::StringsAndChecksumsRef m_strings;
54061da546Spatrick 
55061da546Spatrick   // List of files which contribute to this compiland.
56061da546Spatrick   std::vector<llvm::StringRef> m_file_list;
57061da546Spatrick 
58061da546Spatrick   // Maps virtual address to global symbol id, which can then be used to
59061da546Spatrick   // locate the exact compile unit and offset of the symbol.  Note that this
60061da546Spatrick   // is intentionally an ordered map so that we can find all symbols up to a
61061da546Spatrick   // given starting address.
62061da546Spatrick   std::map<lldb::addr_t, PdbSymUid> m_symbols_by_va;
63061da546Spatrick 
64061da546Spatrick   // S_COMPILE3 sym describing compilation settings for the module.
65*f6aab3d8Srobert   std::optional<llvm::codeview::Compile3Sym> m_compile_opts;
66061da546Spatrick 
67061da546Spatrick   // S_OBJNAME sym describing object name.
68*f6aab3d8Srobert   std::optional<llvm::codeview::ObjNameSym> m_obj_name;
69061da546Spatrick 
70061da546Spatrick   // LF_BUILDINFO sym describing source file name, working directory,
71061da546Spatrick   // command line, etc.  This usually contains exactly 5 items which
72061da546Spatrick   // are references to other strings.
73061da546Spatrick   llvm::SmallVector<llvm::codeview::TypeIndex, 5> m_build_info;
74*f6aab3d8Srobert 
75*f6aab3d8Srobert   // Inlinee lines table in this compile unit.
76*f6aab3d8Srobert   std::map<llvm::codeview::TypeIndex, llvm::codeview::InlineeSourceLine>
77*f6aab3d8Srobert       m_inline_map;
78*f6aab3d8Srobert 
79*f6aab3d8Srobert   // It's the line table parsed from DEBUG_S_LINES sections, mapping the file
80*f6aab3d8Srobert   // address range to file index and source line number.
81*f6aab3d8Srobert   using GlobalLineTable =
82*f6aab3d8Srobert       lldb_private::RangeDataVector<lldb::addr_t, uint32_t,
83*f6aab3d8Srobert                                     std::pair<uint32_t, uint32_t>>;
84*f6aab3d8Srobert   GlobalLineTable m_global_line_table;
85061da546Spatrick };
86061da546Spatrick 
87061da546Spatrick /// Indexes information about all compile units.  This is really just a map of
88061da546Spatrick /// global compile unit index to |CompilandIndexItem| structures.
89061da546Spatrick class CompileUnitIndex {
90061da546Spatrick   PdbIndex &m_index;
91061da546Spatrick   llvm::DenseMap<uint16_t, std::unique_ptr<CompilandIndexItem>> m_comp_units;
92061da546Spatrick 
93061da546Spatrick public:
CompileUnitIndex(PdbIndex & index)94061da546Spatrick   explicit CompileUnitIndex(PdbIndex &index) : m_index(index) {}
95061da546Spatrick 
96061da546Spatrick   CompilandIndexItem &GetOrCreateCompiland(uint16_t modi);
97061da546Spatrick 
98061da546Spatrick   const CompilandIndexItem *GetCompiland(uint16_t modi) const;
99061da546Spatrick 
100061da546Spatrick   CompilandIndexItem *GetCompiland(uint16_t modi);
101061da546Spatrick 
102061da546Spatrick   llvm::SmallString<64> GetMainSourceFile(const CompilandIndexItem &item) const;
103061da546Spatrick };
104061da546Spatrick } // namespace npdb
105061da546Spatrick } // namespace lldb_private
106061da546Spatrick 
107061da546Spatrick #endif
108