]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
Merge libc++ trunk r300890, and update build glue.
[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 ModInfoBuilder;
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<ModInfoBuilder &> addModuleInfo(StringRef ModuleName);
61   Error addModuleSourceFile(StringRef Module, StringRef File);
62
63   Error finalizeMsfLayout();
64
65   Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
66
67   // A helper function to create Section Contributions from COFF input
68   // section headers.
69   static std::vector<SectionContrib>
70   createSectionContribs(ArrayRef<llvm::object::coff_section> SecHdrs);
71
72   // A helper function to create a Section Map from a COFF section header.
73   static std::vector<SecMapEntry>
74   createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
75
76 private:
77   struct DebugStream {
78     ArrayRef<uint8_t> Data;
79     uint16_t StreamNumber = 0;
80   };
81
82   Error finalize();
83   uint32_t calculateModiSubstreamSize() const;
84   uint32_t calculateSectionContribsStreamSize() const;
85   uint32_t calculateSectionMapStreamSize() const;
86   uint32_t calculateFileInfoSubstreamSize() const;
87   uint32_t calculateNamesBufferSize() const;
88   uint32_t calculateDbgStreamsSize() const;
89
90   Error generateModiSubstream();
91   Error generateFileInfoSubstream();
92
93   msf::MSFBuilder &Msf;
94   BumpPtrAllocator &Allocator;
95
96   Optional<PdbRaw_DbiVer> VerHeader;
97   uint32_t Age;
98   uint16_t BuildNumber;
99   uint16_t PdbDllVersion;
100   uint16_t PdbDllRbld;
101   uint16_t Flags;
102   PDB_Machine MachineType;
103
104   const DbiStreamHeader *Header;
105
106   StringMap<std::unique_ptr<ModInfoBuilder>> ModiMap;
107   std::vector<ModInfoBuilder *> ModiList;
108
109   StringMap<uint32_t> SourceFileNames;
110
111   WritableBinaryStreamRef NamesBuffer;
112   MutableBinaryByteStream FileInfoBuffer;
113   ArrayRef<SectionContrib> SectionContribs;
114   ArrayRef<SecMapEntry> SectionMap;
115   llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;
116 };
117 }
118 }
119
120 #endif