LLVM  7.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/BinaryFormat/COFF.h"
16 #include "llvm/Support/Error.h"
17 
24 #include "llvm/Support/Endian.h"
25 
26 namespace llvm {
27 namespace msf {
28 class MSFBuilder;
29 }
30 namespace object {
31 struct coff_section;
32 }
33 namespace pdb {
34 class DbiStream;
35 struct DbiStreamHeader;
36 class DbiModuleDescriptorBuilder;
37 class PDBFile;
38 
40 public:
43 
44  DbiStreamBuilder(const DbiStreamBuilder &) = delete;
45  DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
46 
47  void setVersionHeader(PdbRaw_DbiVer V);
48  void setAge(uint32_t A);
49  void setBuildNumber(uint16_t B);
50  void setBuildNumber(uint8_t Major, uint8_t Minor);
51  void setPdbDllVersion(uint16_t V);
52  void setPdbDllRbld(uint16_t R);
53  void setFlags(uint16_t F);
54  void setMachineType(PDB_Machine M);
55  void setMachineType(COFF::MachineTypes M);
56  void setSectionMap(ArrayRef<SecMapEntry> SecMap);
57 
58  // Add given bytes as a new stream.
60 
61  uint32_t addECName(StringRef Name);
62 
63  uint32_t calculateSerializedLength() const;
64 
65  void setGlobalsStreamIndex(uint32_t Index);
66  void setPublicsStreamIndex(uint32_t Index);
67  void setSymbolRecordStreamIndex(uint32_t Index);
68 
69  Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
70  Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
71  Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
72 
73  Error finalizeMsfLayout();
74 
75  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
76 
78  SectionContribs.emplace_back(SC);
79  }
80 
81  // A helper function to create a Section Map from a COFF section header.
82  static std::vector<SecMapEntry>
83  createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
84 
85 private:
86  struct DebugStream {
87  ArrayRef<uint8_t> Data;
88  uint16_t StreamNumber = kInvalidStreamIndex;
89  };
90 
91  Error finalize();
92  uint32_t calculateModiSubstreamSize() const;
93  uint32_t calculateNamesOffset() const;
94  uint32_t calculateSectionContribsStreamSize() const;
95  uint32_t calculateSectionMapStreamSize() const;
96  uint32_t calculateFileInfoSubstreamSize() const;
97  uint32_t calculateNamesBufferSize() const;
98  uint32_t calculateDbgStreamsSize() const;
99 
100  Error generateFileInfoSubstream();
101 
102  msf::MSFBuilder &Msf;
104 
105  Optional<PdbRaw_DbiVer> VerHeader;
106  uint32_t Age;
107  uint16_t BuildNumber;
108  uint16_t PdbDllVersion;
109  uint16_t PdbDllRbld;
110  uint16_t Flags;
111  PDB_Machine MachineType;
112  uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
113  uint32_t PublicsStreamIndex = kInvalidStreamIndex;
114  uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
115 
116  const DbiStreamHeader *Header;
117 
118  std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
119 
120  StringMap<uint32_t> SourceFileNames;
121 
122  PDBStringTableBuilder ECNamesBuilder;
123  WritableBinaryStreamRef NamesBuffer;
124  MutableBinaryByteStream FileInfoBuffer;
125  std::vector<SectionContrib> SectionContribs;
126  ArrayRef<SecMapEntry> SectionMap;
127  std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
128 };
129 }
130 }
131 
132 #endif
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
arc branch finalize
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
F(f)
MachineTypes
Definition: COFF.h:94
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:120
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:20
void addSectionContrib(const SectionContrib &SC)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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:140
Basic Register Allocator
CHAIN = SC CHAIN, Imm128 - System call.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49