LLVM  15.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_NATIVE_DBISTREAMBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_DBISTREAMBUILDER_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/BinaryFormat/COFF.h"
16 #include "llvm/Object/COFF.h"
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/Error.h"
19 
27 
28 namespace llvm {
29 
30 class BinaryStreamWriter;
31 namespace codeview {
32 struct FrameData;
33 }
34 namespace msf {
35 class MSFBuilder;
36 struct MSFLayout;
37 }
38 namespace pdb {
39 class DbiModuleDescriptorBuilder;
40 
42 public:
45 
46  DbiStreamBuilder(const DbiStreamBuilder &) = delete;
47  DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
48 
50  void setAge(uint32_t A);
52  void setBuildNumber(uint8_t Major, uint8_t Minor);
53  void setPdbDllVersion(uint16_t V);
54  void setPdbDllRbld(uint16_t R);
55  void setFlags(uint16_t F);
58 
59  // Add given bytes as a new stream.
61 
63 
65 
66  void setGlobalsStreamIndex(uint32_t Index);
67  void setPublicsStreamIndex(uint32_t Index);
69  void addNewFpoData(const codeview::FrameData &FD);
70  void addOldFpoData(const object::FpoData &Fpo);
71 
75 
77 
78  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
79 
81  SectionContribs.emplace_back(SC);
82  }
83 
84  // Populate the Section Map from COFF section headers.
86 
87 private:
88  struct DebugStream {
90  uint32_t Size = 0;
91  uint16_t StreamNumber = kInvalidStreamIndex;
92  };
93 
94  Error finalize();
95  uint32_t calculateModiSubstreamSize() const;
96  uint32_t calculateNamesOffset() const;
97  uint32_t calculateSectionContribsStreamSize() const;
98  uint32_t calculateSectionMapStreamSize() const;
99  uint32_t calculateFileInfoSubstreamSize() const;
100  uint32_t calculateNamesBufferSize() const;
101  uint32_t calculateDbgStreamsSize() const;
102 
103  Error generateFileInfoSubstream();
104 
105  msf::MSFBuilder &Msf;
106  BumpPtrAllocator &Allocator;
107 
108  Optional<PdbRaw_DbiVer> VerHeader;
109  uint32_t Age;
110  uint16_t BuildNumber;
111  uint16_t PdbDllVersion;
112  uint16_t PdbDllRbld;
113  uint16_t Flags;
114  PDB_Machine MachineType;
115  uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
116  uint32_t PublicsStreamIndex = kInvalidStreamIndex;
117  uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
118 
119  const DbiStreamHeader *Header;
120 
121  std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
122 
124  std::vector<object::FpoData> OldFpoData;
125 
126  StringMap<uint32_t> SourceFileNames;
127 
128  PDBStringTableBuilder ECNamesBuilder;
129  WritableBinaryStreamRef NamesBuffer;
130  MutableBinaryByteStream FileInfoBuffer;
131  std::vector<SectionContrib> SectionContribs;
132  std::vector<SecMapEntry> SectionMap;
133  std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
134 };
135 } // namespace pdb
136 }
137 
138 #endif
llvm::pdb::DbiStreamBuilder::commit
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer)
Definition: DbiStreamBuilder.cpp:382
llvm::pdb::DbiStreamBuilder::setBuildNumber
void setBuildNumber(uint16_t B)
Definition: DbiStreamBuilder.cpp:38
RawConstants.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
Optional.h
llvm::pdb::SectionContrib
Definition: RawTypes.h:46
llvm::MutableBinaryByteStream
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Definition: BinaryByteStream.h:88
llvm::pdb::DbiStreamBuilder::addModuleInfo
Expected< DbiModuleDescriptorBuilder & > addModuleInfo(StringRef ModuleName)
Definition: DbiStreamBuilder.cpp:110
RawTypes.h
StringRef.h
BinaryByteStream.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
llvm::pdb::DbiStreamBuilder::setMachineType
void setMachineType(PDB_Machine M)
Definition: DbiStreamBuilder.cpp:54
Allocator.h
llvm::pdb::DbiStreamBuilder::~DbiStreamBuilder
~DbiStreamBuilder()
llvm::pdb::kInvalidStreamIndex
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
Error.h
llvm::pdb::DbiStreamBuilder::addDbgStream
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef< uint8_t > Data)
Definition: DbiStreamBuilder.cpp:84
COFF.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::codeview::FrameData
Data in the SUBSEC_FRAMEDATA subection.
Definition: CodeView.h:574
llvm::Optional< PdbRaw_DbiVer >
llvm::pdb::DbiStreamBuilder::addModuleSourceFile
Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File)
Definition: DbiStreamBuilder.cpp:117
llvm::pdb::DbiStreamBuilder::setVersionHeader
void setVersionHeader(PdbRaw_DbiVer V)
Definition: DbiStreamBuilder.cpp:34
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::DbiStreamBuilder::addNewFpoData
void addNewFpoData(const codeview::FrameData &FD)
Definition: DbiStreamBuilder.cpp:73
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::pdb::DbiStreamBuilder::addOldFpoData
void addOldFpoData(const object::FpoData &Fpo)
Definition: DbiStreamBuilder.cpp:80
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:27
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::pdb::DbiStreamBuilder::createSectionMap
void createSectionMap(ArrayRef< llvm::object::coff_section > SecHdrs)
Definition: DbiStreamBuilder.cpp:350
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:418
llvm::pdb::DbiStreamBuilder::getSourceFileNameIndex
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
Definition: DbiStreamBuilder.cpp:125
llvm::pdb::DbiStreamBuilder
Definition: DbiStreamBuilder.h:41
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
StringMap.h
PDBTypes.h
llvm::pdb::DbiStreamBuilder::addECName
uint32_t addECName(StringRef Name)
Definition: DbiStreamBuilder.cpp:97
llvm::StringMap< uint32_t >
llvm::pdb::DbiStreamBuilder::setPdbDllVersion
void setPdbDllVersion(uint16_t V)
Definition: DbiStreamBuilder.cpp:48
llvm::pdb::DbiStreamBuilder::setPublicsStreamIndex
void setPublicsStreamIndex(uint32_t Index)
Definition: DbiStreamBuilder.cpp:69
llvm::pdb::DbiStreamBuilder::setFlags
void setFlags(uint16_t F)
Definition: DbiStreamBuilder.cpp:52
llvm::pdb::DbiStreamBuilder::setGlobalsStreamIndex
void setGlobalsStreamIndex(uint32_t Index)
Definition: DbiStreamBuilder.cpp:61
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::pdb::DbiStreamBuilder::DbiStreamBuilder
DbiStreamBuilder(msf::MSFBuilder &Msf)
Definition: DbiStreamBuilder.cpp:27
ModuleName
Definition: ItaniumDemangle.h:989
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::ArrayRef< uint8_t >
llvm::pdb::PdbRaw_DbiVer
PdbRaw_DbiVer
Definition: RawConstants.h:51
llvm::pdb::PDB_Machine
PDB_Machine
Definition: PDBTypes.h:125
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BinaryStreamRef.h
uint32_t
llvm::pdb::DbiStreamBuilder::finalizeMsfLayout
Error finalizeMsfLayout()
Definition: DbiStreamBuilder.cpp:287
llvm::pdb::DbiStreamBuilder::setSymbolRecordStreamIndex
void setSymbolRecordStreamIndex(uint32_t Index)
Definition: DbiStreamBuilder.cpp:65
llvm::pdb::DbiStreamBuilder::setAge
void setAge(uint32_t A)
Definition: DbiStreamBuilder.cpp:36
llvm::pdb::DbiStreamBuilder::setPdbDllRbld
void setPdbDllRbld(uint16_t R)
Definition: DbiStreamBuilder.cpp:50
llvm::pdb::DbiStreamBuilder::operator=
DbiStreamBuilder & operator=(const DbiStreamBuilder &)=delete
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::pdb::DbiModuleDescriptorBuilder
Definition: DbiModuleDescriptorBuilder.h:63
PDBStringTableBuilder.h
llvm::COFF::MachineTypes
MachineTypes
Definition: COFF.h:92
llvm::pdb::DbiStreamBuilder::addSectionContrib
void addSectionContrib(const SectionContrib &SC)
Definition: DbiStreamBuilder.h:80
llvm::pdb::DbiStreamBuilder::calculateSerializedLength
uint32_t calculateSerializedLength() const
Definition: DbiStreamBuilder.cpp:101
llvm::pdb::DbgHeaderType::Max
@ Max
COFF.h
DebugFrameDataSubsection.h
llvm::pdb::DbgHeaderType
DbgHeaderType
Definition: RawConstants.h:86
llvm::WritableBinaryStreamRef
Definition: BinaryStreamRef.h:220
llvm::codeview::DebugSubsectionKind::FrameData
@ FrameData
llvm::object::FpoData
Definition: COFF.h:1278