1 //===- InputFile.h -------------------------------------------- *- C++ --*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H
11 #define LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H
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"
26 class LazyRandomTypeCollection;
38 class SymbolGroupIterator;
44 std::unique_ptr<NativeSession> PdbSession;
45 object::OwningBinary<object::Binary> CoffObject;
46 PointerUnion<PDBFile *, object::COFFObjectFile *> PdbOrObj;
48 using TypeCollectionPtr = std::unique_ptr<codeview::LazyRandomTypeCollection>;
50 TypeCollectionPtr Types;
51 TypeCollectionPtr Ids;
53 enum TypeCollectionKind { kTypes, kIds };
54 codeview::LazyRandomTypeCollection &
55 getOrCreateTypeCollection(TypeCollectionKind Kind);
59 InputFile(InputFile &&Other) = default;
61 static Expected<InputFile> open(StringRef Path);
64 const PDBFile &pdb() const;
65 object::COFFObjectFile &obj();
66 const object::COFFObjectFile &obj() const;
68 bool hasTypes() const;
71 codeview::LazyRandomTypeCollection &types();
72 codeview::LazyRandomTypeCollection &ids();
74 iterator_range<SymbolGroupIterator> symbol_groups();
75 SymbolGroupIterator symbol_groups_begin();
76 SymbolGroupIterator symbol_groups_end();
83 friend class SymbolGroupIterator;
86 explicit SymbolGroup(InputFile *File, uint32_t GroupIndex = 0);
88 Expected<StringRef> getNameFromStringTable(uint32_t Offset) const;
90 void formatFromFileName(LinePrinter &Printer, StringRef File,
91 bool Append = false) const;
93 void formatFromChecksumsOffset(LinePrinter &Printer, uint32_t Offset,
94 bool Append = false) const;
96 StringRef name() const;
98 codeview::DebugSubsectionArray getDebugSubsections() const {
101 const ModuleDebugStreamRef &getPdbModuleStream() const;
103 const InputFile &getFile() const { return *File; }
104 InputFile &getFile() { return *File; }
107 void initializeForPdb(uint32_t Modi);
108 void updatePdbModi(uint32_t Modi);
109 void updateDebugS(const codeview::DebugSubsectionArray &SS);
111 void rebuildChecksumMap();
112 InputFile *File = nullptr;
114 codeview::DebugSubsectionArray Subsections;
115 std::shared_ptr<ModuleDebugStreamRef> DebugStream;
116 codeview::StringsAndChecksumsRef SC;
117 StringMap<codeview::FileChecksumEntry> ChecksumsByFile;
120 class SymbolGroupIterator
121 : public iterator_facade_base<SymbolGroupIterator,
122 std::forward_iterator_tag, SymbolGroup> {
124 SymbolGroupIterator();
125 explicit SymbolGroupIterator(InputFile &File);
126 SymbolGroupIterator(const SymbolGroupIterator &Other) = default;
127 SymbolGroupIterator &operator=(const SymbolGroupIterator &R) = default;
129 const SymbolGroup &operator*() const;
130 SymbolGroup &operator*();
132 bool operator==(const SymbolGroupIterator &R) const;
133 SymbolGroupIterator &operator++();
136 void scanToNextDebugS();
140 Optional<object::section_iterator> SectionIter;