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 setPublicsStreamIndex(uint32_t Index);
63 void setSymbolRecordStreamIndex(uint32_t Index);
65 Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
66 Error addModuleSourceFile(StringRef Module, StringRef File);
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(DbiModuleDescriptorBuilder *ModuleDbi,
75 const llvm::object::coff_section *SecHdr);
77 // A helper function to create a Section Map from a COFF section header.
78 static std::vector<SecMapEntry>
79 createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
83 ArrayRef<uint8_t> Data;
84 uint16_t StreamNumber = kInvalidStreamIndex;
88 uint32_t calculateModiSubstreamSize() const;
89 uint32_t calculateNamesOffset() const;
90 uint32_t calculateSectionContribsStreamSize() const;
91 uint32_t calculateSectionMapStreamSize() const;
92 uint32_t calculateFileInfoSubstreamSize() const;
93 uint32_t calculateNamesBufferSize() const;
94 uint32_t calculateDbgStreamsSize() const;
96 Error generateFileInfoSubstream();
99 BumpPtrAllocator &Allocator;
101 Optional<PdbRaw_DbiVer> VerHeader;
103 uint16_t BuildNumber;
104 uint16_t PdbDllVersion;
107 PDB_Machine MachineType;
108 uint32_t PublicsStreamIndex = kInvalidStreamIndex;
109 uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
111 const DbiStreamHeader *Header;
113 StringMap<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiMap;
114 std::vector<DbiModuleDescriptorBuilder *> ModiList;
116 StringMap<uint32_t> SourceFileNames;
118 PDBStringTableBuilder ECNamesBuilder;
119 WritableBinaryStreamRef NamesBuffer;
120 MutableBinaryByteStream FileInfoBuffer;
121 std::vector<SectionContrib> SectionContribs;
122 ArrayRef<SecMapEntry> SectionMap;
123 llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;