LLVM  14.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/ArrayRef.h"
13 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/Endian.h"
21 #include "llvm/Support/Error.h"
23 #include <memory>
24 
25 namespace llvm {
26 namespace msf {
27 class MSFBuilder;
28 }
29 namespace pdb {
30 class DbiStreamBuilder;
31 class InfoStreamBuilder;
32 class GSIStreamBuilder;
33 class TpiStreamBuilder;
34 
36 public:
37  explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
39  PDBFileBuilder(const PDBFileBuilder &) = delete;
40  PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
41 
43 
51 
52  // If HashPDBContentsToGUID is true on the InfoStreamBuilder, Guid is filled
53  // with the computed PDB GUID on return.
54  Error commit(StringRef Filename, codeview::GUID *Guid);
55 
58  void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer);
59 
60 private:
61  struct InjectedSourceDescriptor {
62  // The full name of the stream that contains the contents of this injected
63  // source. This is built as a concatenation of the literal "/src/files"
64  // plus the "vname".
65  std::string StreamName;
66 
67  // The exact name of the file name as specified by the user.
68  uint32_t NameIndex;
69 
70  // The string table index of the "vname" of the file. As far as we
71  // understand, this is the same as the name, except it is lowercased and
72  // forward slashes are converted to backslashes.
73  uint32_t VNameIndex;
74  std::unique_ptr<MemoryBuffer> Content;
75  };
76 
77  Error finalizeMsfLayout();
78  Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size);
79 
80  void commitInjectedSources(WritableBinaryStream &MsfBuffer,
81  const msf::MSFLayout &Layout);
82  void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer,
83  const msf::MSFLayout &Layout);
84 
86 
87  std::unique_ptr<msf::MSFBuilder> Msf;
88  std::unique_ptr<InfoStreamBuilder> Info;
89  std::unique_ptr<DbiStreamBuilder> Dbi;
90  std::unique_ptr<GSIStreamBuilder> Gsi;
91  std::unique_ptr<TpiStreamBuilder> Tpi;
92  std::unique_ptr<TpiStreamBuilder> Ipi;
93 
94  PDBStringTableBuilder Strings;
95  StringTableHashTraits InjectedSourceHashTraits;
96  HashTable<SrcHeaderBlockEntry> InjectedSourceTable;
97 
99 
100  NamedStreamMap NamedStreams;
101  DenseMap<uint32_t, std::string> NamedStreamData;
102 };
103 }
104 }
105 
106 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
MemoryBuffer.h
RawConstants.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
BlockSize
static const int BlockSize
Definition: TarWriter.cpp:33
llvm::pdb::PDBFileBuilder::getInfoBuilder
InfoStreamBuilder & getInfoBuilder()
Definition: PDBFileBuilder.cpp:49
RawTypes.h
NamedStreamMap.h
llvm::SmallVector< InjectedSourceDescriptor, 2 >
Allocator.h
Content
T Content
Definition: ELFObjHandler.cpp:90
llvm::codeview::GUID
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21
Error.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::PDBFileBuilder::getStringTableBuilder
PDBStringTableBuilder & getStringTableBuilder()
Definition: PDBFileBuilder.cpp:73
llvm::pdb::PDBFileBuilder::getMsfBuilder
msf::MSFBuilder & getMsfBuilder()
Definition: PDBFileBuilder.cpp:47
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:26
llvm::pdb::PDBFileBuilder::commit
Error commit(StringRef Filename, codeview::GUID *Guid)
Definition: PDBFileBuilder.cpp:262
llvm::pdb::PDBFileBuilder::addNamedStream
Error addNamedStream(StringRef Name, StringRef Data)
Definition: PDBFileBuilder.cpp:91
llvm::pdb::DbiStreamBuilder
Definition: DbiStreamBuilder.h:43
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::StringTableHashTraits
Definition: PDBStringTableBuilder.h:34
llvm::pdb::PDBFileBuilder::getDbiBuilder
DbiStreamBuilder & getDbiBuilder()
Definition: PDBFileBuilder.cpp:55
llvm::pdb::InfoStreamBuilder
Definition: InfoStreamBuilder.h:30
llvm::pdb::PDBFileBuilder::~PDBFileBuilder
~PDBFileBuilder()
Definition: PDBFileBuilder.cpp:37
llvm::pdb::PDBFileBuilder::getNamedStreamIndex
Expected< uint32_t > getNamedStreamIndex(StringRef Name) const
Definition: PDBFileBuilder.cpp:216
llvm::pdb::PDBFileBuilder::getGsiBuilder
GSIStreamBuilder & getGsiBuilder()
Definition: PDBFileBuilder.cpp:77
llvm::pdb::PDBFileBuilder::PDBFileBuilder
PDBFileBuilder(BumpPtrAllocator &Allocator)
Definition: PDBFileBuilder.cpp:33
llvm::pdb::GSIStreamBuilder
Definition: GSIStreamBuilder.h:44
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::DenseMap< uint32_t, std::string >
ArrayRef.h
llvm::pdb::TpiStreamBuilder
Definition: TpiStreamBuilder.h:47
llvm::pdb::NamedStreamMap
Definition: NamedStreamMap.h:37
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:39
llvm::pdb::PDBFileBuilder::getTpiBuilder
TpiStreamBuilder & getTpiBuilder()
Definition: PDBFileBuilder.cpp:61
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::pdb::HashTable< SrcHeaderBlockEntry >
PDBStringTableBuilder.h
SmallVector.h
PDBFile.h
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
llvm::pdb::PDBFileBuilder
Definition: PDBFileBuilder.h:35
llvm::pdb::PDBFileBuilder::operator=
PDBFileBuilder & operator=(const PDBFileBuilder &)=delete
Endian.h
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:67
llvm::pdb::PDBFileBuilder::addInjectedSource
void addInjectedSource(StringRef Name, std::unique_ptr< MemoryBuffer > Buffer)
Definition: PDBFileBuilder.cpp:100