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/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"
33 struct DbiStreamHeader;
37 class DbiStreamBuilder {
39 DbiStreamBuilder(msf::MSFBuilder &Msf);
42 DbiStreamBuilder(const DbiStreamBuilder &) = delete;
43 DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
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);
55 // Add given bytes as a new stream.
56 Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
58 uint32_t calculateSerializedLength() const;
60 Expected<ModInfoBuilder &> addModuleInfo(StringRef ModuleName);
61 Error addModuleSourceFile(StringRef Module, StringRef File);
63 Error finalizeMsfLayout();
65 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
67 // A helper function to create Section Contributions from COFF input
69 static std::vector<SectionContrib>
70 createSectionContribs(ArrayRef<llvm::object::coff_section> SecHdrs);
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);
78 ArrayRef<uint8_t> Data;
79 uint16_t StreamNumber = 0;
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;
90 Error generateModiSubstream();
91 Error generateFileInfoSubstream();
94 BumpPtrAllocator &Allocator;
96 Optional<PdbRaw_DbiVer> VerHeader;
99 uint16_t PdbDllVersion;
102 PDB_Machine MachineType;
104 const DbiStreamHeader *Header;
106 StringMap<std::unique_ptr<ModInfoBuilder>> ModiMap;
107 std::vector<ModInfoBuilder *> ModiList;
109 StringMap<uint32_t> SourceFileNames;
111 WritableBinaryStreamRef NamesBuffer;
112 MutableBinaryByteStream FileInfoBuffer;
113 ArrayRef<SectionContrib> SectionContribs;
114 ArrayRef<SecMapEntry> SectionMap;
115 llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;