LLVM  10.0.0svn
DbiStreamBuilder.h
Go to the documentation of this file.
1 //===- DbiStreamBuilder.h - PDB Dbi Stream 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_RAW_PDBDBISTREAMBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/StringSet.h"
14 #include "llvm/BinaryFormat/COFF.h"
15 #include "llvm/Support/Error.h"
16 
24 #include "llvm/Support/Endian.h"
25 
26 namespace llvm {
27 namespace codeview {
28 struct FrameData;
29 }
30 namespace msf {
31 class MSFBuilder;
32 }
33 namespace object {
34 struct coff_section;
35 struct FpoData;
36 }
37 namespace pdb {
38 class DbiStream;
39 struct DbiStreamHeader;
40 class DbiModuleDescriptorBuilder;
41 class PDBFile;
42 
44 public:
47 
48  DbiStreamBuilder(const DbiStreamBuilder &) = delete;
49  DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
50 
51  void setVersionHeader(PdbRaw_DbiVer V);
52  void setAge(uint32_t A);
53  void setBuildNumber(uint16_t B);
54  void setBuildNumber(uint8_t Major, uint8_t Minor);
55  void setPdbDllVersion(uint16_t V);
56  void setPdbDllRbld(uint16_t R);
57  void setFlags(uint16_t F);
58  void setMachineType(PDB_Machine M);
59  void setMachineType(COFF::MachineTypes M);
60  void setSectionMap(ArrayRef<SecMapEntry> SecMap);
61 
62  // Add given bytes as a new stream.
64 
65  uint32_t addECName(StringRef Name);
66 
67  uint32_t calculateSerializedLength() const;
68 
69  void setGlobalsStreamIndex(uint32_t Index);
70  void setPublicsStreamIndex(uint32_t Index);
71  void setSymbolRecordStreamIndex(uint32_t Index);
72  void addNewFpoData(const codeview::FrameData &FD);
73  void addOldFpoData(const object::FpoData &Fpo);
74 
75  Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
76  Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
77  Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
78 
79  Error finalizeMsfLayout();
80 
81  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
82 
84  SectionContribs.emplace_back(SC);
85  }
86 
87  // A helper function to create a Section Map from a COFF section header.
88  static std::vector<SecMapEntry>
89  createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
90 
91 private:
92  struct DebugStream {
93  std::function<Error(BinaryStreamWriter &)> WriteFn;
94  uint32_t Size = 0;
95  uint16_t StreamNumber = kInvalidStreamIndex;
96  };
97 
98  Error finalize();
99  uint32_t calculateModiSubstreamSize() const;
100  uint32_t calculateNamesOffset() const;
101  uint32_t calculateSectionContribsStreamSize() const;
102  uint32_t calculateSectionMapStreamSize() const;
103  uint32_t calculateFileInfoSubstreamSize() const;
104  uint32_t calculateNamesBufferSize() const;
105  uint32_t calculateDbgStreamsSize() const;
106 
107  Error generateFileInfoSubstream();
108 
109  msf::MSFBuilder &Msf;
111 
112  Optional<PdbRaw_DbiVer> VerHeader;
113  uint32_t Age;
114  uint16_t BuildNumber;
115  uint16_t PdbDllVersion;
116  uint16_t PdbDllRbld;
117  uint16_t Flags;
118  PDB_Machine MachineType;
119  uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
120  uint32_t PublicsStreamIndex = kInvalidStreamIndex;
121  uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
122 
123  const DbiStreamHeader *Header;
124 
125  std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
126 
128  std::vector<object::FpoData> OldFpoData;
129 
130  StringMap<uint32_t> SourceFileNames;
131 
132  PDBStringTableBuilder ECNamesBuilder;
133  WritableBinaryStreamRef NamesBuffer;
134  MutableBinaryByteStream FileInfoBuffer;
135  std::vector<SectionContrib> SectionContribs;
136  ArrayRef<SecMapEntry> SectionMap;
137  std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
138 };
139 }
140 }
141 
142 #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:23
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:569
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
F(f)
MachineTypes
Definition: COFF.h:93
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
The fixed size header that appears at the beginning of the DBI Stream.
Definition: RawTypes.h:119
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
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:45
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
Instrumentation for Order File
Basic Register Allocator
CHAIN = SC CHAIN, Imm128 - System call.
uint32_t Size
Definition: Profile.cpp:46
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:48