LLVM  12.0.0git
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 
61  // Add given bytes as a new stream.
63 
64  uint32_t addECName(StringRef Name);
65 
66  uint32_t calculateSerializedLength() const;
67 
68  void setGlobalsStreamIndex(uint32_t Index);
69  void setPublicsStreamIndex(uint32_t Index);
70  void setSymbolRecordStreamIndex(uint32_t Index);
71  void addNewFpoData(const codeview::FrameData &FD);
72  void addOldFpoData(const object::FpoData &Fpo);
73 
74  Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
75  Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
76  Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
77 
78  Error finalizeMsfLayout();
79 
80  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
81 
83  SectionContribs.emplace_back(SC);
84  }
85 
86  // Populate the Section Map from COFF section headers.
87  void createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
88 
89 private:
90  struct DebugStream {
91  std::function<Error(BinaryStreamWriter &)> WriteFn;
92  uint32_t Size = 0;
93  uint16_t StreamNumber = kInvalidStreamIndex;
94  };
95 
96  Error finalize();
97  uint32_t calculateModiSubstreamSize() const;
98  uint32_t calculateNamesOffset() const;
99  uint32_t calculateSectionContribsStreamSize() const;
100  uint32_t calculateSectionMapStreamSize() const;
101  uint32_t calculateFileInfoSubstreamSize() const;
102  uint32_t calculateNamesBufferSize() const;
103  uint32_t calculateDbgStreamsSize() const;
104 
105  Error generateFileInfoSubstream();
106 
107  msf::MSFBuilder &Msf;
109 
110  Optional<PdbRaw_DbiVer> VerHeader;
111  uint32_t Age;
112  uint16_t BuildNumber;
113  uint16_t PdbDllVersion;
114  uint16_t PdbDllRbld;
115  uint16_t Flags;
116  PDB_Machine MachineType;
117  uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
118  uint32_t PublicsStreamIndex = kInvalidStreamIndex;
119  uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
120 
121  const DbiStreamHeader *Header;
122 
123  std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
124 
126  std::vector<object::FpoData> OldFpoData;
127 
128  StringMap<uint32_t> SourceFileNames;
129 
130  PDBStringTableBuilder ECNamesBuilder;
131  WritableBinaryStreamRef NamesBuffer;
132  MutableBinaryByteStream FileInfoBuffer;
133  std::vector<SectionContrib> SectionContribs;
134  std::vector<SecMapEntry> SectionMap;
135  std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
136 };
137 }
138 }
139 
140 #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:67
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: APFloat.h:42
The fixed size header that appears at the beginning of the DBI Stream.
Definition: RawTypes.h:119
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:46
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
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:57