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