1 //===- DbiStreamBuilder.h - PDB Dbi Stream Creation -------------*- 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_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/Support/Error.h"
17 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
18 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
19 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
20 #include "llvm/DebugInfo/PDB/PDBTypes.h"
21 #include "llvm/Support/BinaryByteStream.h"
22 #include "llvm/Support/BinaryStreamReader.h"
23 #include "llvm/Support/Endian.h"
34 struct DbiStreamHeader;
35 class DbiModuleDescriptorBuilder;
38 class DbiStreamBuilder {
40 DbiStreamBuilder(msf::MSFBuilder &Msf);
43 DbiStreamBuilder(const DbiStreamBuilder &) = delete;
44 DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
46 void setVersionHeader(PdbRaw_DbiVer V);
47 void setAge(uint32_t A);
48 void setBuildNumber(uint16_t B);
49 void setPdbDllVersion(uint16_t V);
50 void setPdbDllRbld(uint16_t R);
51 void setFlags(uint16_t F);
52 void setMachineType(PDB_Machine M);
53 void setSectionMap(ArrayRef<SecMapEntry> SecMap);
55 // Add given bytes as a new stream.
56 Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
58 uint32_t addECName(StringRef Name);
60 uint32_t calculateSerializedLength() const;
62 void setGlobalsStreamIndex(uint32_t Index);
63 void setPublicsStreamIndex(uint32_t Index);
64 void setSymbolRecordStreamIndex(uint32_t Index);
66 Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
67 Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
68 Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
70 Error finalizeMsfLayout();
72 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
74 void addSectionContrib(const SectionContrib &SC) {
75 SectionContribs.emplace_back(SC);
78 // A helper function to create a Section Map from a COFF section header.
79 static std::vector<SecMapEntry>
80 createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
84 ArrayRef<uint8_t> Data;
85 uint16_t StreamNumber = kInvalidStreamIndex;
89 uint32_t calculateModiSubstreamSize() const;
90 uint32_t calculateNamesOffset() const;
91 uint32_t calculateSectionContribsStreamSize() const;
92 uint32_t calculateSectionMapStreamSize() const;
93 uint32_t calculateFileInfoSubstreamSize() const;
94 uint32_t calculateNamesBufferSize() const;
95 uint32_t calculateDbgStreamsSize() const;
97 Error generateFileInfoSubstream();
100 BumpPtrAllocator &Allocator;
102 Optional<PdbRaw_DbiVer> VerHeader;
104 uint16_t BuildNumber;
105 uint16_t PdbDllVersion;
108 PDB_Machine MachineType;
109 uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
110 uint32_t PublicsStreamIndex = kInvalidStreamIndex;
111 uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
113 const DbiStreamHeader *Header;
115 std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
117 StringMap<uint32_t> SourceFileNames;
119 PDBStringTableBuilder ECNamesBuilder;
120 WritableBinaryStreamRef NamesBuffer;
121 MutableBinaryByteStream FileInfoBuffer;
122 std::vector<SectionContrib> SectionContribs;
123 ArrayRef<SecMapEntry> SectionMap;
124 llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;