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