LLVM  8.0.1
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 
25 #include "llvm/Support/Endian.h"
26 
27 namespace llvm {
28 namespace codeview {
29 struct FrameData;
30 }
31 namespace msf {
32 class MSFBuilder;
33 }
34 namespace object {
35 struct coff_section;
36 struct FpoData;
37 }
38 namespace pdb {
39 class DbiStream;
40 struct DbiStreamHeader;
41 class DbiModuleDescriptorBuilder;
42 class PDBFile;
43 
45 public:
48 
49  DbiStreamBuilder(const DbiStreamBuilder &) = delete;
50  DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
51 
52  void setVersionHeader(PdbRaw_DbiVer V);
53  void setAge(uint32_t A);
54  void setBuildNumber(uint16_t B);
55  void setBuildNumber(uint8_t Major, uint8_t Minor);
56  void setPdbDllVersion(uint16_t V);
57  void setPdbDllRbld(uint16_t R);
58  void setFlags(uint16_t F);
59  void setMachineType(PDB_Machine M);
60  void setMachineType(COFF::MachineTypes M);
61  void setSectionMap(ArrayRef<SecMapEntry> SecMap);
62 
63  // Add given bytes as a new stream.
65 
66  uint32_t addECName(StringRef Name);
67 
68  uint32_t calculateSerializedLength() const;
69 
70  void setGlobalsStreamIndex(uint32_t Index);
71  void setPublicsStreamIndex(uint32_t Index);
72  void setSymbolRecordStreamIndex(uint32_t Index);
73  void addNewFpoData(const codeview::FrameData &FD);
74  void addOldFpoData(const object::FpoData &Fpo);
75 
76  Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
77  Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
78  Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
79 
80  Error finalizeMsfLayout();
81 
82  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
83 
85  SectionContribs.emplace_back(SC);
86  }
87 
88  // A helper function to create a Section Map from a COFF section header.
89  static std::vector<SecMapEntry>
90  createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
91 
92 private:
93  struct DebugStream {
94  std::function<Error(BinaryStreamWriter &)> WriteFn;
95  uint32_t Size = 0;
96  uint16_t StreamNumber = kInvalidStreamIndex;
97  };
98 
99  Error finalize();
100  uint32_t calculateModiSubstreamSize() const;
101  uint32_t calculateNamesOffset() const;
102  uint32_t calculateSectionContribsStreamSize() const;
103  uint32_t calculateSectionMapStreamSize() const;
104  uint32_t calculateFileInfoSubstreamSize() const;
105  uint32_t calculateNamesBufferSize() const;
106  uint32_t calculateDbgStreamsSize() const;
107 
108  Error generateFileInfoSubstream();
109 
110  msf::MSFBuilder &Msf;
112 
113  Optional<PdbRaw_DbiVer> VerHeader;
114  uint32_t Age;
115  uint16_t BuildNumber;
116  uint16_t PdbDllVersion;
117  uint16_t PdbDllRbld;
118  uint16_t Flags;
119  PDB_Machine MachineType;
120  uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
121  uint32_t PublicsStreamIndex = kInvalidStreamIndex;
122  uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
123 
124  const DbiStreamHeader *Header;
125 
126  std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
127 
129  std::vector<object::FpoData> OldFpoData;
130 
131  StringMap<uint32_t> SourceFileNames;
132 
133  PDBStringTableBuilder ECNamesBuilder;
134  WritableBinaryStreamRef NamesBuffer;
135  MutableBinaryByteStream FileInfoBuffer;
136  std::vector<SectionContrib> SectionContribs;
137  ArrayRef<SecMapEntry> SectionMap;
138  std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
139 };
140 }
141 }
142 
143 #endif
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
This class represents lattice values for constants.
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:65
Data in the SUBSEC_FRAMEDATA subection.
Definition: CodeView.h:552
F(f)
MachineTypes
Definition: COFF.h:94
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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:141
Basic Register Allocator
CHAIN = SC CHAIN, Imm128 - System call.
uint32_t Size
Definition: Profile.cpp:47
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49