1 //===- PDBFileBuilder.h - PDB File 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_PDBFILEBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_PDBFILEBUILDER_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/BitVector.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.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/Native/RawTypes.h"
21 #include "llvm/Support/Allocator.h"
22 #include "llvm/Support/Endian.h"
23 #include "llvm/Support/Error.h"
24 #include "llvm/Support/MemoryBuffer.h"
34 class DbiStreamBuilder;
35 class InfoStreamBuilder;
36 class GSIStreamBuilder;
37 class TpiStreamBuilder;
39 class PDBFileBuilder {
41 explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
43 PDBFileBuilder(const PDBFileBuilder &) = delete;
44 PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
46 Error initialize(uint32_t BlockSize);
48 msf::MSFBuilder &getMsfBuilder();
49 InfoStreamBuilder &getInfoBuilder();
50 DbiStreamBuilder &getDbiBuilder();
51 TpiStreamBuilder &getTpiBuilder();
52 TpiStreamBuilder &getIpiBuilder();
53 PDBStringTableBuilder &getStringTableBuilder();
54 GSIStreamBuilder &getGsiBuilder();
56 // If HashPDBContentsToGUID is true on the InfoStreamBuilder, Guid is filled
57 // with the computed PDB GUID on return.
58 Error commit(StringRef Filename, codeview::GUID *Guid);
60 Expected<uint32_t> getNamedStreamIndex(StringRef Name) const;
61 Error addNamedStream(StringRef Name, StringRef Data);
62 void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer);
65 struct InjectedSourceDescriptor {
66 // The full name of the stream that contains the contents of this injected
67 // source. This is built as a concatenation of the literal "/src/files"
69 std::string StreamName;
71 // The exact name of the file name as specified by the user.
74 // The string table index of the "vname" of the file. As far as we
75 // understand, this is the same as the name, except it is lowercased and
76 // forward slashes are converted to backslashes.
78 std::unique_ptr<MemoryBuffer> Content;
81 Error finalizeMsfLayout();
82 Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size);
84 void commitFpm(WritableBinaryStream &MsfBuffer, const msf::MSFLayout &Layout);
85 void commitInjectedSources(WritableBinaryStream &MsfBuffer,
86 const msf::MSFLayout &Layout);
87 void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer,
88 const msf::MSFLayout &Layout);
90 BumpPtrAllocator &Allocator;
92 std::unique_ptr<msf::MSFBuilder> Msf;
93 std::unique_ptr<InfoStreamBuilder> Info;
94 std::unique_ptr<DbiStreamBuilder> Dbi;
95 std::unique_ptr<GSIStreamBuilder> Gsi;
96 std::unique_ptr<TpiStreamBuilder> Tpi;
97 std::unique_ptr<TpiStreamBuilder> Ipi;
99 PDBStringTableBuilder Strings;
100 StringTableHashTraits InjectedSourceHashTraits;
101 HashTable<SrcHeaderBlockEntry, StringTableHashTraits> InjectedSourceTable;
103 SmallVector<InjectedSourceDescriptor, 2> InjectedSources;
105 NamedStreamMap NamedStreams;
106 DenseMap<uint32_t, std::string> NamedStreamData;