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;
34 class DbiModuleDescriptorBuilder;
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<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
61 Error addModuleSourceFile(StringRef Module, StringRef File);
62 Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
64 Error finalizeMsfLayout();
66 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
68 // A helper function to create Section Contributions from COFF input
70 static std::vector<SectionContrib>
71 createSectionContribs(ArrayRef<llvm::object::coff_section> SecHdrs);
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);
79 ArrayRef<uint8_t> Data;
80 uint16_t StreamNumber = 0;
84 uint32_t calculateModiSubstreamSize() const;
85 uint32_t calculateSectionContribsStreamSize() const;
86 uint32_t calculateSectionMapStreamSize() const;
87 uint32_t calculateFileInfoSubstreamSize() const;
88 uint32_t calculateNamesBufferSize() const;
89 uint32_t calculateDbgStreamsSize() const;
91 Error generateModiSubstream();
92 Error generateFileInfoSubstream();
95 BumpPtrAllocator &Allocator;
97 Optional<PdbRaw_DbiVer> VerHeader;
100 uint16_t PdbDllVersion;
103 PDB_Machine MachineType;
105 const DbiStreamHeader *Header;
107 StringMap<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiMap;
108 std::vector<DbiModuleDescriptorBuilder *> ModiList;
110 StringMap<uint32_t> SourceFileNames;
112 WritableBinaryStreamRef NamesBuffer;
113 MutableBinaryByteStream FileInfoBuffer;
114 ArrayRef<SectionContrib> SectionContribs;
115 ArrayRef<SecMapEntry> SectionMap;
116 llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;