• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- PDBFileBuilder.h - PDB File Creation ---------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBFILEBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_PDBFILEBUILDER_H
12 
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"
25 
26 #include <memory>
27 #include <vector>
28 
29 namespace llvm {
30 namespace msf {
31 class MSFBuilder;
32 }
33 namespace pdb {
34 class DbiStreamBuilder;
35 class InfoStreamBuilder;
36 class GSIStreamBuilder;
37 class TpiStreamBuilder;
38 
39 class PDBFileBuilder {
40 public:
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   Error commit(StringRef Filename);
57 
58   Expected<uint32_t> getNamedStreamIndex(StringRef Name) const;
59   Error addNamedStream(StringRef Name, StringRef Data);
60   void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer);
61 
62 private:
63   struct InjectedSourceDescriptor {
64     // The full name of the stream that contains the contents of this injected
65     // source.  This is built as a concatenation of the literal "/src/files"
66     // plus the "vname".
67     std::string StreamName;
68 
69     // The exact name of the file name as specified by the user.
70     uint32_t NameIndex;
71 
72     // The string table index of the "vname" of the file.  As far as we
73     // understand, this is the same as the name, except it is lowercased and
74     // forward slashes are converted to backslashes.
75     uint32_t VNameIndex;
76     std::unique_ptr<MemoryBuffer> Content;
77   };
78 
79   Error finalizeMsfLayout();
80   Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size);
81 
82   void commitFpm(WritableBinaryStream &MsfBuffer, const msf::MSFLayout &Layout);
83   void commitInjectedSources(WritableBinaryStream &MsfBuffer,
84                              const msf::MSFLayout &Layout);
85   void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer,
86                             const msf::MSFLayout &Layout);
87 
88   BumpPtrAllocator &Allocator;
89 
90   std::unique_ptr<msf::MSFBuilder> Msf;
91   std::unique_ptr<InfoStreamBuilder> Info;
92   std::unique_ptr<DbiStreamBuilder> Dbi;
93   std::unique_ptr<GSIStreamBuilder> Gsi;
94   std::unique_ptr<TpiStreamBuilder> Tpi;
95   std::unique_ptr<TpiStreamBuilder> Ipi;
96 
97   PDBStringTableBuilder Strings;
98   StringTableHashTraits InjectedSourceHashTraits;
99   HashTable<SrcHeaderBlockEntry, StringTableHashTraits> InjectedSourceTable;
100 
101   SmallVector<InjectedSourceDescriptor, 2> InjectedSources;
102 
103   NamedStreamMap NamedStreams;
104   DenseMap<uint32_t, std::string> NamedStreamData;
105 };
106 }
107 }
108 
109 #endif
110