LLVM  15.0.0git
PDBFileBuilder.h
Go to the documentation of this file.
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"
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/Error.h"
20 #include <memory>
21 
22 namespace llvm {
23 class WritableBinaryStream;
24 namespace codeview {
25 struct GUID;
26 }
27 
28 namespace msf {
29 class MSFBuilder;
30 struct MSFLayout;
31 }
32 namespace pdb {
33 struct SrcHeaderBlockEntry;
34 class DbiStreamBuilder;
35 class InfoStreamBuilder;
36 class GSIStreamBuilder;
37 class TpiStreamBuilder;
38 
40 public:
41  explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
43  PDBFileBuilder(const PDBFileBuilder &) = delete;
44  PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
45 
47 
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 
62  void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer);
63 
64 private:
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 
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 
103 
104  NamedStreamMap NamedStreams;
105  DenseMap<uint32_t, std::string> NamedStreamData;
106 };
107 }
108 }
109 
110 #endif
MemoryBuffer.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
BlockSize
static const int BlockSize
Definition: TarWriter.cpp:33
llvm::pdb::PDBFileBuilder::getInfoBuilder
InfoStreamBuilder & getInfoBuilder()
Definition: PDBFileBuilder.cpp:56
NamedStreamMap.h
llvm::SmallVector< InjectedSourceDescriptor, 2 >
Allocator.h
Content
T Content
Definition: ELFObjHandler.cpp:88
llvm::codeview::GUID
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21
Error.h
DenseMap.h
HashTable.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::PDBFileBuilder::getStringTableBuilder
PDBStringTableBuilder & getStringTableBuilder()
Definition: PDBFileBuilder.cpp:80
llvm::pdb::PDBFileBuilder::getMsfBuilder
msf::MSFBuilder & getMsfBuilder()
Definition: PDBFileBuilder.cpp:54
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:27
llvm::pdb::PDBFileBuilder::commit
Error commit(StringRef Filename, codeview::GUID *Guid)
Definition: PDBFileBuilder.cpp:269
llvm::pdb::PDBFileBuilder::addNamedStream
Error addNamedStream(StringRef Name, StringRef Data)
Definition: PDBFileBuilder.cpp:98
llvm::pdb::DbiStreamBuilder
Definition: DbiStreamBuilder.h:41
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::StringTableHashTraits
Definition: PDBStringTableBuilder.h:34
llvm::pdb::PDBFileBuilder::getDbiBuilder
DbiStreamBuilder & getDbiBuilder()
Definition: PDBFileBuilder.cpp:62
llvm::pdb::InfoStreamBuilder
Definition: InfoStreamBuilder.h:28
llvm::pdb::PDBFileBuilder::~PDBFileBuilder
~PDBFileBuilder()
llvm::pdb::PDBFileBuilder::getNamedStreamIndex
Expected< uint32_t > getNamedStreamIndex(StringRef Name) const
Definition: PDBFileBuilder.cpp:223
llvm::pdb::PDBFileBuilder::getGsiBuilder
GSIStreamBuilder & getGsiBuilder()
Definition: PDBFileBuilder.cpp:84
llvm::pdb::PDBFileBuilder::PDBFileBuilder
PDBFileBuilder(BumpPtrAllocator &Allocator)
Definition: PDBFileBuilder.cpp:40
llvm::pdb::GSIStreamBuilder
Definition: GSIStreamBuilder.h:46
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::DenseMap< uint32_t, std::string >
llvm::pdb::TpiStreamBuilder
Definition: TpiStreamBuilder.h:40
llvm::pdb::NamedStreamMap
Definition: NamedStreamMap.h:36
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::pdb::PDBFileBuilder::initialize
Error initialize(uint32_t BlockSize)
Definition: PDBFileBuilder.cpp:46
llvm::pdb::PDBFileBuilder::getTpiBuilder
TpiStreamBuilder & getTpiBuilder()
Definition: PDBFileBuilder.cpp:68
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::pdb::HashTable< SrcHeaderBlockEntry >
PDBStringTableBuilder.h
SmallVector.h
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:142
llvm::pdb::PDBFileBuilder
Definition: PDBFileBuilder.h:39
llvm::pdb::PDBFileBuilder::operator=
PDBFileBuilder & operator=(const PDBFileBuilder &)=delete
llvm::pdb::PDBStringTableBuilder
Definition: PDBStringTableBuilder.h:43
llvm::WritableBinaryStream
A BinaryStream which can be read from as well as written to.
Definition: BinaryStream.h:73
llvm::pdb::PDBFileBuilder::getIpiBuilder
TpiStreamBuilder & getIpiBuilder()
Definition: PDBFileBuilder.cpp:74
llvm::pdb::PDBFileBuilder::addInjectedSource
void addInjectedSource(StringRef Name, std::unique_ptr< MemoryBuffer > Buffer)
Definition: PDBFileBuilder.cpp:107