1//===- PDBFileBuilder.h - PDB File 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_PDBFILEBUILDER_H
10#define LLVM_DEBUGINFO_PDB_NATIVE_PDBFILEBUILDER_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/DebugInfo/PDB/Native/HashTable.h"
15#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
16#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
17#include "llvm/Support/Allocator.h"
18#include "llvm/Support/Error.h"
19#include "llvm/Support/MemoryBuffer.h"
20#include <memory>
21
22namespace llvm {
23class WritableBinaryStream;
24namespace codeview {
25struct GUID;
26}
27
28namespace msf {
29class MSFBuilder;
30struct MSFLayout;
31}
32namespace pdb {
33struct SrcHeaderBlockEntry;
34class DbiStreamBuilder;
35class InfoStreamBuilder;
36class GSIStreamBuilder;
37class TpiStreamBuilder;
38
39class PDBFileBuilder {
40public:
41 explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
42 ~PDBFileBuilder();
43 PDBFileBuilder(const PDBFileBuilder &) = delete;
44 PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
45
46 Error initialize(uint32_t BlockSize);
47
48 msf::MSFBuilder &getMsfBuilder();
49 InfoStreamBuilder &getInfoBuilder();
50 DbiStreamBuilder &getDbiBuilder();
51 TpiStreamBuilder &getTpiBuilder();
52 TpiStreamBuilder &getIpiBuilder();
53 PDBStringTableBuilder &getStringTableBuilder();
54 GSIStreamBuilder &getGsiBuilder();
55
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);
59
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);
63
64private:
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"
68 // plus the "vname".
69 std::string StreamName;
70
71 // The exact name of the file name as specified by the user.
72 uint32_t NameIndex;
73
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.
77 uint32_t VNameIndex;
78 std::unique_ptr<MemoryBuffer> Content;
79 };
80
81 Error finalizeMsfLayout();
82 Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size);
83
84 void commitInjectedSources(WritableBinaryStream &MsfBuffer,
85 const msf::MSFLayout &Layout);
86 void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer,
87 const msf::MSFLayout &Layout);
88
89 BumpPtrAllocator &Allocator;
90
91 std::unique_ptr<msf::MSFBuilder> Msf;
92 std::unique_ptr<InfoStreamBuilder> Info;
93 std::unique_ptr<DbiStreamBuilder> Dbi;
94 std::unique_ptr<GSIStreamBuilder> Gsi;
95 std::unique_ptr<TpiStreamBuilder> Tpi;
96 std::unique_ptr<TpiStreamBuilder> Ipi;
97
98 PDBStringTableBuilder Strings;
99 StringTableHashTraits InjectedSourceHashTraits;
100 HashTable<SrcHeaderBlockEntry> InjectedSourceTable;
101
102 SmallVector<InjectedSourceDescriptor, 2> InjectedSources;
103
104 NamedStreamMap NamedStreams;
105 DenseMap<uint32_t, std::string> NamedStreamData;
106};
107}
108}
109
110#endif
111

source code of llvm/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h