LLVM  5.0.0
DbiStreamBuilder.h
Go to the documentation of this file.
1 //===- DbiStreamBuilder.h - PDB Dbi Stream 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_PDBDBISTREAMBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
12 
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/Support/Error.h"
16 
23 #include "llvm/Support/Endian.h"
24 
25 namespace llvm {
26 namespace msf {
27 class MSFBuilder;
28 }
29 namespace object {
30 struct coff_section;
31 }
32 namespace pdb {
33 class DbiStream;
34 struct DbiStreamHeader;
35 class DbiModuleDescriptorBuilder;
36 class PDBFile;
37 
39 public:
42 
43  DbiStreamBuilder(const DbiStreamBuilder &) = delete;
44  DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
45 
47  void setAge(uint32_t A);
48  void setBuildNumber(uint16_t B);
49  void setPdbDllVersion(uint16_t V);
50  void setPdbDllRbld(uint16_t R);
51  void setFlags(uint16_t F);
54 
55  // Add given bytes as a new stream.
57 
59 
61 
62  void setPublicsStreamIndex(uint32_t Index);
64 
69 
71 
72  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
73 
75  const llvm::object::coff_section *SecHdr);
76 
77  // A helper function to create a Section Map from a COFF section header.
78  static std::vector<SecMapEntry>
80 
81 private:
82  struct DebugStream {
84  uint16_t StreamNumber = kInvalidStreamIndex;
85  };
86 
87  Error finalize();
88  uint32_t calculateModiSubstreamSize() const;
89  uint32_t calculateNamesOffset() const;
90  uint32_t calculateSectionContribsStreamSize() const;
91  uint32_t calculateSectionMapStreamSize() const;
92  uint32_t calculateFileInfoSubstreamSize() const;
93  uint32_t calculateNamesBufferSize() const;
94  uint32_t calculateDbgStreamsSize() const;
95 
96  Error generateFileInfoSubstream();
97 
98  msf::MSFBuilder &Msf;
99  BumpPtrAllocator &Allocator;
100 
101  Optional<PdbRaw_DbiVer> VerHeader;
102  uint32_t Age;
103  uint16_t BuildNumber;
104  uint16_t PdbDllVersion;
105  uint16_t PdbDllRbld;
106  uint16_t Flags;
107  PDB_Machine MachineType;
108  uint32_t PublicsStreamIndex = kInvalidStreamIndex;
109  uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
110 
111  const DbiStreamHeader *Header;
112 
114  std::vector<DbiModuleDescriptorBuilder *> ModiList;
115 
116  StringMap<uint32_t> SourceFileNames;
117 
118  PDBStringTableBuilder ECNamesBuilder;
119  WritableBinaryStreamRef NamesBuffer;
120  MutableBinaryByteStream FileInfoBuffer;
121  std::vector<SectionContrib> SectionContribs;
122  ArrayRef<SecMapEntry> SectionMap;
124 };
125 }
126 }
127 
128 #endif
uint32_t addECName(StringRef Name)
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
uint32_t calculateSerializedLength() const
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
void setSectionMap(ArrayRef< SecMapEntry > SecMap)
void setMachineType(PDB_Machine M)
static std::vector< SecMapEntry > createSectionMap(ArrayRef< llvm::object::coff_section > SecHdrs)
void addSectionContrib(DbiModuleDescriptorBuilder *ModuleDbi, const llvm::object::coff_section *SecHdr)
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
The fixed size header that appears at the beginning of the DBI Stream.
Definition: RawTypes.h:104
void setSymbolRecordStreamIndex(uint32_t Index)
#define F(x, y, z)
Definition: MD5.cpp:55
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef< uint8_t > Data)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
const char * Name
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:20
DbiStreamBuilder & operator=(const DbiStreamBuilder &)=delete
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
#define A
Definition: LargeTest.cpp:12
void setVersionHeader(PdbRaw_DbiVer V)
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer)
#define B
Definition: LargeTest.cpp:24
Expected< DbiModuleDescriptorBuilder & > addModuleInfo(StringRef ModuleName)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
Error addModuleSourceFile(StringRef Module, StringRef File)
void setPublicsStreamIndex(uint32_t Index)
DbiStreamBuilder(msf::MSFBuilder &Msf)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49