]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/InputFile.h
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / InputFile.h
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;
46   PointerUnion<PDBFile *, object::COFFObjectFile *> PdbOrObj;
47
48   using TypeCollectionPtr = std::unique_ptr<codeview::LazyRandomTypeCollection>;
49
50   TypeCollectionPtr Types;
51   TypeCollectionPtr Ids;
52
53   enum TypeCollectionKind { kTypes, kIds };
54   codeview::LazyRandomTypeCollection &
55   getOrCreateTypeCollection(TypeCollectionKind Kind);
56
57 public:
58   ~InputFile();
59   InputFile(InputFile &&Other) = default;
60
61   static Expected<InputFile> open(StringRef Path);
62
63   PDBFile &pdb();
64   const PDBFile &pdb() const;
65   object::COFFObjectFile &obj();
66   const object::COFFObjectFile &obj() const;
67
68   bool hasTypes() const;
69   bool hasIds() const;
70
71   codeview::LazyRandomTypeCollection &types();
72   codeview::LazyRandomTypeCollection &ids();
73
74   iterator_range<SymbolGroupIterator> symbol_groups();
75   SymbolGroupIterator symbol_groups_begin();
76   SymbolGroupIterator symbol_groups_end();
77
78   bool isPdb() const;
79   bool isObj() const;
80 };
81
82 class SymbolGroup {
83   friend class SymbolGroupIterator;
84
85 public:
86   explicit SymbolGroup(InputFile *File, uint32_t GroupIndex = 0);
87
88   Expected<StringRef> getNameFromStringTable(uint32_t Offset) const;
89
90   void formatFromFileName(LinePrinter &Printer, StringRef File,
91                           bool Append = false) const;
92
93   void formatFromChecksumsOffset(LinePrinter &Printer, uint32_t Offset,
94                                  bool Append = false) const;
95
96   StringRef name() const;
97
98   codeview::DebugSubsectionArray getDebugSubsections() const {
99     return Subsections;
100   }
101   const ModuleDebugStreamRef &getPdbModuleStream() const;
102
103   const InputFile &getFile() const { return *File; }
104   InputFile &getFile() { return *File; }
105
106 private:
107   void initializeForPdb(uint32_t Modi);
108   void updatePdbModi(uint32_t Modi);
109   void updateDebugS(const codeview::DebugSubsectionArray &SS);
110
111   void rebuildChecksumMap();
112   InputFile *File = nullptr;
113   StringRef Name;
114   codeview::DebugSubsectionArray Subsections;
115   std::shared_ptr<ModuleDebugStreamRef> DebugStream;
116   codeview::StringsAndChecksumsRef SC;
117   StringMap<codeview::FileChecksumEntry> ChecksumsByFile;
118 };
119
120 class SymbolGroupIterator
121     : public iterator_facade_base<SymbolGroupIterator,
122                                   std::forward_iterator_tag, SymbolGroup> {
123 public:
124   SymbolGroupIterator();
125   explicit SymbolGroupIterator(InputFile &File);
126   SymbolGroupIterator(const SymbolGroupIterator &Other) = default;
127   SymbolGroupIterator &operator=(const SymbolGroupIterator &R) = default;
128
129   const SymbolGroup &operator*() const;
130   SymbolGroup &operator*();
131
132   bool operator==(const SymbolGroupIterator &R) const;
133   SymbolGroupIterator &operator++();
134
135 private:
136   void scanToNextDebugS();
137   bool isEnd() const;
138
139   uint32_t Index = 0;
140   Optional<object::section_iterator> SectionIter;
141   SymbolGroup Value;
142 };
143
144 } // namespace pdb
145 } // namespace llvm
146
147 #endif