| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 1 | //===-- CompileUnitIndex.h --------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLDB_PLUGINS_SYMBOLFILENATIVEPDB_COMPILEUNITINDEX_H |
| 11 | #define LLDB_PLUGINS_SYMBOLFILENATIVEPDB_COMPILEUNITINDEX_H |
| 12 | |
| 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/StringsAndChecksums.h" |
| 18 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
| 19 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
| 20 | #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" |
| 21 | #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" |
| 22 | #include "llvm/DebugInfo/PDB/PDBTypes.h" |
| 23 | |
| 24 | #include "PdbSymUid.h" |
| 25 | |
| 26 | #include <map> |
| 27 | #include <memory> |
| 28 | |
| 29 | namespace lldb_private { |
| 30 | |
| 31 | namespace npdb { |
| 32 | class PdbIndex; |
| 33 | |
| 34 | /// Represents a single compile unit. This class is useful for collecting the |
| 35 | /// important accessors and information about a compile unit from disparate |
| 36 | /// parts of the PDB into a single place, simplifying acess to compile unit |
| 37 | /// information for the callers. |
| 38 | struct CompilandIndexItem { |
| Zachary Turner | 6284aee | 2018-11-16 02:42:32 +0000 | [diff] [blame] | 39 | CompilandIndexItem(PdbCompilandId m_id, |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 40 | llvm::pdb::ModuleDebugStreamRef debug_stream, |
| 41 | llvm::pdb::DbiModuleDescriptor descriptor); |
| 42 | |
| Zachary Turner | 6284aee | 2018-11-16 02:42:32 +0000 | [diff] [blame] | 43 | // index of this compile unit. |
| 44 | PdbCompilandId m_id; |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 45 | |
| 46 | // debug stream. |
| 47 | llvm::pdb::ModuleDebugStreamRef m_debug_stream; |
| 48 | |
| 49 | // dbi module descriptor. |
| 50 | llvm::pdb::DbiModuleDescriptor m_module_descriptor; |
| 51 | |
| 52 | llvm::codeview::StringsAndChecksumsRef m_strings; |
| 53 | |
| 54 | // List of files which contribute to this compiland. |
| 55 | std::vector<llvm::StringRef> m_file_list; |
| 56 | |
| 57 | // Maps virtual address to global symbol id, which can then be used to |
| 58 | // locate the exact compile unit and offset of the symbol. Note that this |
| 59 | // is intentionally an ordered map so that we can find all symbols up to a |
| 60 | // given starting address. |
| 61 | std::map<lldb::addr_t, PdbSymUid> m_symbols_by_va; |
| 62 | |
| 63 | // S_COMPILE3 sym describing compilation settings for the module. |
| 64 | llvm::Optional<llvm::codeview::Compile3Sym> m_compile_opts; |
| 65 | |
| 66 | // S_OBJNAME sym describing object name. |
| 67 | llvm::Optional<llvm::codeview::ObjNameSym> m_obj_name; |
| 68 | |
| 69 | // LF_BUILDINFO sym describing source file name, working directory, |
| 70 | // command line, etc. This usually contains exactly 5 items which |
| 71 | // are references to other strings. |
| 72 | llvm::SmallVector<llvm::codeview::TypeIndex, 5> m_build_info; |
| 73 | }; |
| 74 | |
| 75 | /// Indexes information about all compile units. This is really just a map of |
| 76 | /// global compile unit index to |CompilandIndexItem| structures. |
| 77 | class CompileUnitIndex { |
| 78 | PdbIndex &m_index; |
| Zachary Turner | 6284aee | 2018-11-16 02:42:32 +0000 | [diff] [blame] | 79 | llvm::DenseMap<uint16_t, std::unique_ptr<CompilandIndexItem>> m_comp_units; |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 80 | |
| 81 | public: |
| 82 | explicit CompileUnitIndex(PdbIndex &index) : m_index(index) {} |
| 83 | |
| 84 | CompilandIndexItem &GetOrCreateCompiland(uint16_t modi); |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 85 | |
| 86 | const CompilandIndexItem *GetCompiland(uint16_t modi) const; |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 87 | |
| 88 | CompilandIndexItem *GetCompiland(uint16_t modi); |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 89 | |
| 90 | llvm::SmallString<64> GetMainSourceFile(const CompilandIndexItem &item) const; |
| 91 | }; |
| 92 | } // namespace npdb |
| 93 | } // namespace lldb_private |
| 94 | |
| 95 | #endif |