Zachary Turner | 6ef51e8 | 2017-09-01 20:06:56 +0000 | [diff] [blame] | 1 | //===- InputFile.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 LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H |
| 11 | #define LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H |
| 12 | |
| 13 | #include "llvm/ADT/Optional.h" |
| 14 | #include "llvm/ADT/PointerUnion.h" |
| 15 | #include "llvm/ADT/StringMap.h" |
| 16 | #include "llvm/ADT/iterator.h" |
| 17 | #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" |
| 18 | #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" |
| 19 | #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" |
| 20 | #include "llvm/Object/Binary.h" |
| 21 | #include "llvm/Object/ObjectFile.h" |
| 22 | #include "llvm/Support/Error.h" |
| 23 | |
| 24 | namespace llvm { |
| 25 | namespace codeview { |
| 26 | class LazyRandomTypeCollection; |
| 27 | } |
| 28 | namespace object { |
| 29 | class COFFObjectFile; |
| 30 | class SectionRef; |
| 31 | } // namespace object |
| 32 | |
| 33 | namespace pdb { |
| 34 | class InputFile; |
| 35 | class LinePrinter; |
| 36 | class PDBFile; |
| 37 | class NativeSession; |
| 38 | class SymbolGroupIterator; |
| 39 | class SymbolGroup; |
| 40 | |
| 41 | class InputFile { |
| 42 | InputFile(); |
| 43 | |
| 44 | std::unique_ptr<NativeSession> PdbSession; |
| 45 | object::OwningBinary<object::Binary> CoffObject; |
Zachary Turner | 06e4df3 | 2018-04-04 17:29:09 +0000 | [diff] [blame] | 46 | std::unique_ptr<MemoryBuffer> UnknownFile; |
| 47 | PointerUnion3<PDBFile *, object::COFFObjectFile *, MemoryBuffer *> PdbOrObj; |
Zachary Turner | 6ef51e8 | 2017-09-01 20:06:56 +0000 | [diff] [blame] | 48 | |
| 49 | using TypeCollectionPtr = std::unique_ptr<codeview::LazyRandomTypeCollection>; |
| 50 | |
| 51 | TypeCollectionPtr Types; |
| 52 | TypeCollectionPtr Ids; |
| 53 | |
| 54 | enum TypeCollectionKind { kTypes, kIds }; |
| 55 | codeview::LazyRandomTypeCollection & |
| 56 | getOrCreateTypeCollection(TypeCollectionKind Kind); |
| 57 | |
| 58 | public: |
| 59 | ~InputFile(); |
| 60 | InputFile(InputFile &&Other) = default; |
| 61 | |
Zachary Turner | 06e4df3 | 2018-04-04 17:29:09 +0000 | [diff] [blame] | 62 | static Expected<InputFile> open(StringRef Path, |
| 63 | bool AllowUnknownFile = false); |
Zachary Turner | 6ef51e8 | 2017-09-01 20:06:56 +0000 | [diff] [blame] | 64 | |
| 65 | PDBFile &pdb(); |
| 66 | const PDBFile &pdb() const; |
| 67 | object::COFFObjectFile &obj(); |
| 68 | const object::COFFObjectFile &obj() const; |
Zachary Turner | 06e4df3 | 2018-04-04 17:29:09 +0000 | [diff] [blame] | 69 | MemoryBuffer &unknown(); |
| 70 | const MemoryBuffer &unknown() const; |
| 71 | |
| 72 | StringRef getFilePath() const; |
Zachary Turner | 6ef51e8 | 2017-09-01 20:06:56 +0000 | [diff] [blame] | 73 | |
| 74 | bool hasTypes() const; |
| 75 | bool hasIds() const; |
| 76 | |
| 77 | codeview::LazyRandomTypeCollection &types(); |
| 78 | codeview::LazyRandomTypeCollection &ids(); |
| 79 | |
| 80 | iterator_range<SymbolGroupIterator> symbol_groups(); |
| 81 | SymbolGroupIterator symbol_groups_begin(); |
| 82 | SymbolGroupIterator symbol_groups_end(); |
| 83 | |
| 84 | bool isPdb() const; |
| 85 | bool isObj() const; |
Zachary Turner | 06e4df3 | 2018-04-04 17:29:09 +0000 | [diff] [blame] | 86 | bool isUnknown() const; |
Zachary Turner | 6ef51e8 | 2017-09-01 20:06:56 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | class SymbolGroup { |
| 90 | friend class SymbolGroupIterator; |
| 91 | |
| 92 | public: |
| 93 | explicit SymbolGroup(InputFile *File, uint32_t GroupIndex = 0); |
| 94 | |
| 95 | Expected<StringRef> getNameFromStringTable(uint32_t Offset) const; |
| 96 | |
| 97 | void formatFromFileName(LinePrinter &Printer, StringRef File, |
| 98 | bool Append = false) const; |
| 99 | |
| 100 | void formatFromChecksumsOffset(LinePrinter &Printer, uint32_t Offset, |
| 101 | bool Append = false) const; |
| 102 | |
| 103 | StringRef name() const; |
| 104 | |
| 105 | codeview::DebugSubsectionArray getDebugSubsections() const { |
| 106 | return Subsections; |
| 107 | } |
| 108 | const ModuleDebugStreamRef &getPdbModuleStream() const; |
| 109 | |
| 110 | const InputFile &getFile() const { return *File; } |
| 111 | InputFile &getFile() { return *File; } |
| 112 | |
Leonard Mosescu | 437cbaf | 2018-11-02 18:00:37 +0000 | [diff] [blame] | 113 | bool hasDebugStream() const { return DebugStream != nullptr; } |
| 114 | |
Zachary Turner | 6ef51e8 | 2017-09-01 20:06:56 +0000 | [diff] [blame] | 115 | private: |
| 116 | void initializeForPdb(uint32_t Modi); |
| 117 | void updatePdbModi(uint32_t Modi); |
| 118 | void updateDebugS(const codeview::DebugSubsectionArray &SS); |
| 119 | |
| 120 | void rebuildChecksumMap(); |
| 121 | InputFile *File = nullptr; |
| 122 | StringRef Name; |
| 123 | codeview::DebugSubsectionArray Subsections; |
| 124 | std::shared_ptr<ModuleDebugStreamRef> DebugStream; |
| 125 | codeview::StringsAndChecksumsRef SC; |
| 126 | StringMap<codeview::FileChecksumEntry> ChecksumsByFile; |
| 127 | }; |
| 128 | |
| 129 | class SymbolGroupIterator |
| 130 | : public iterator_facade_base<SymbolGroupIterator, |
| 131 | std::forward_iterator_tag, SymbolGroup> { |
| 132 | public: |
| 133 | SymbolGroupIterator(); |
| 134 | explicit SymbolGroupIterator(InputFile &File); |
| 135 | SymbolGroupIterator(const SymbolGroupIterator &Other) = default; |
| 136 | SymbolGroupIterator &operator=(const SymbolGroupIterator &R) = default; |
| 137 | |
| 138 | const SymbolGroup &operator*() const; |
| 139 | SymbolGroup &operator*(); |
| 140 | |
| 141 | bool operator==(const SymbolGroupIterator &R) const; |
| 142 | SymbolGroupIterator &operator++(); |
| 143 | |
| 144 | private: |
| 145 | void scanToNextDebugS(); |
| 146 | bool isEnd() const; |
| 147 | |
| 148 | uint32_t Index = 0; |
| 149 | Optional<object::section_iterator> SectionIter; |
| 150 | SymbolGroup Value; |
| 151 | }; |
| 152 | |
| 153 | } // namespace pdb |
| 154 | } // namespace llvm |
| 155 | |
| 156 | #endif |