1 //===- InfoStreamBuilder.h - PDB Info Stream Creation -----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_INFOSTREAMBUILDER_H 10 #define LLVM_DEBUGINFO_PDB_NATIVE_INFOSTREAMBUILDER_H 11 12 #include "llvm/Support/Compiler.h" 13 #include "llvm/Support/Error.h" 14 15 #include "llvm/DebugInfo/CodeView/GUID.h" 16 #include "llvm/DebugInfo/PDB/Native/RawConstants.h" 17 18 namespace llvm { 19 class WritableBinaryStreamRef; 20 21 namespace msf { 22 class MSFBuilder; 23 struct MSFLayout; 24 } 25 namespace pdb { 26 class NamedStreamMap; 27 28 class InfoStreamBuilder { 29 public: 30 LLVM_ABI InfoStreamBuilder(msf::MSFBuilder &Msf, 31 NamedStreamMap &NamedStreams); 32 InfoStreamBuilder(const InfoStreamBuilder &) = delete; 33 InfoStreamBuilder &operator=(const InfoStreamBuilder &) = delete; 34 35 LLVM_ABI void setVersion(PdbRaw_ImplVer V); 36 LLVM_ABI void addFeature(PdbRaw_FeatureSig Sig); 37 38 // If this is true, the PDB contents are hashed and this hash is used as 39 // PDB GUID and as Signature. The age is always 1. 40 LLVM_ABI void setHashPDBContentsToGUID(bool B); 41 42 // These only have an effect if hashPDBContentsToGUID() is false. 43 LLVM_ABI void setSignature(uint32_t S); 44 LLVM_ABI void setAge(uint32_t A); 45 LLVM_ABI void setGuid(codeview::GUID G); 46 hashPDBContentsToGUID()47 bool hashPDBContentsToGUID() const { return HashPDBContentsToGUID; } getAge()48 uint32_t getAge() const { return Age; } getGuid()49 codeview::GUID getGuid() const { return Guid; } getSignature()50 std::optional<uint32_t> getSignature() const { return Signature; } 51 52 LLVM_ABI uint32_t finalize(); 53 54 LLVM_ABI Error finalizeMsfLayout(); 55 56 LLVM_ABI Error commit(const msf::MSFLayout &Layout, 57 WritableBinaryStreamRef Buffer) const; 58 59 private: 60 msf::MSFBuilder &Msf; 61 62 std::vector<PdbRaw_FeatureSig> Features; 63 PdbRaw_ImplVer Ver; 64 uint32_t Age; 65 std::optional<uint32_t> Signature; 66 codeview::GUID Guid; 67 68 bool HashPDBContentsToGUID = false; 69 70 NamedStreamMap &NamedStreams; 71 }; 72 } // namespace pdb 73 } 74 75 #endif 76