]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / DebugInfo / PDB / Native / DbiStreamBuilder.h
1 //===- DbiStreamBuilder.h - PDB Dbi Stream Creation -------------*- 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_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
12
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/BinaryFormat/COFF.h"
16 #include "llvm/Support/Error.h"
17
18 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
19 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
20 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
21 #include "llvm/DebugInfo/PDB/PDBTypes.h"
22 #include "llvm/Support/BinaryByteStream.h"
23 #include "llvm/Support/BinaryStreamReader.h"
24 #include "llvm/Support/Endian.h"
25
26 namespace llvm {
27 namespace msf {
28 class MSFBuilder;
29 }
30 namespace object {
31 struct coff_section;
32 }
33 namespace pdb {
34 class DbiStream;
35 struct DbiStreamHeader;
36 class DbiModuleDescriptorBuilder;
37 class PDBFile;
38
39 class DbiStreamBuilder {
40 public:
41   DbiStreamBuilder(msf::MSFBuilder &Msf);
42   ~DbiStreamBuilder();
43
44   DbiStreamBuilder(const DbiStreamBuilder &) = delete;
45   DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
46
47   void setVersionHeader(PdbRaw_DbiVer V);
48   void setAge(uint32_t A);
49   void setBuildNumber(uint16_t B);
50   void setBuildNumber(uint8_t Major, uint8_t Minor);
51   void setPdbDllVersion(uint16_t V);
52   void setPdbDllRbld(uint16_t R);
53   void setFlags(uint16_t F);
54   void setMachineType(PDB_Machine M);
55   void setMachineType(COFF::MachineTypes M);
56   void setSectionMap(ArrayRef<SecMapEntry> SecMap);
57
58   // Add given bytes as a new stream.
59   Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
60
61   uint32_t addECName(StringRef Name);
62
63   uint32_t calculateSerializedLength() const;
64
65   void setGlobalsStreamIndex(uint32_t Index);
66   void setPublicsStreamIndex(uint32_t Index);
67   void setSymbolRecordStreamIndex(uint32_t Index);
68
69   Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
70   Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
71   Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
72
73   Error finalizeMsfLayout();
74
75   Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
76
77   void addSectionContrib(const SectionContrib &SC) {
78     SectionContribs.emplace_back(SC);
79   }
80
81   // A helper function to create a Section Map from a COFF section header.
82   static std::vector<SecMapEntry>
83   createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
84
85 private:
86   struct DebugStream {
87     ArrayRef<uint8_t> Data;
88     uint16_t StreamNumber = kInvalidStreamIndex;
89   };
90
91   Error finalize();
92   uint32_t calculateModiSubstreamSize() const;
93   uint32_t calculateNamesOffset() const;
94   uint32_t calculateSectionContribsStreamSize() const;
95   uint32_t calculateSectionMapStreamSize() const;
96   uint32_t calculateFileInfoSubstreamSize() const;
97   uint32_t calculateNamesBufferSize() const;
98   uint32_t calculateDbgStreamsSize() const;
99
100   Error generateFileInfoSubstream();
101
102   msf::MSFBuilder &Msf;
103   BumpPtrAllocator &Allocator;
104
105   Optional<PdbRaw_DbiVer> VerHeader;
106   uint32_t Age;
107   uint16_t BuildNumber;
108   uint16_t PdbDllVersion;
109   uint16_t PdbDllRbld;
110   uint16_t Flags;
111   PDB_Machine MachineType;
112   uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
113   uint32_t PublicsStreamIndex = kInvalidStreamIndex;
114   uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
115
116   const DbiStreamHeader *Header;
117
118   std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
119
120   StringMap<uint32_t> SourceFileNames;
121
122   PDBStringTableBuilder ECNamesBuilder;
123   WritableBinaryStreamRef NamesBuffer;
124   MutableBinaryByteStream FileInfoBuffer;
125   std::vector<SectionContrib> SectionContribs;
126   ArrayRef<SecMapEntry> SectionMap;
127   std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
128 };
129 }
130 }
131
132 #endif