LLVM  14.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/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 
52  void setAge(uint32_t A);
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);
60 
61  // Add given bytes as a new stream.
63 
65 
67 
71  void addNewFpoData(const codeview::FrameData &FD);
72  void addOldFpoData(const object::FpoData &Fpo);
73 
77 
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.
88 
89 private:
90  struct DebugStream {
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;
108  BumpPtrAllocator &Allocator;
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
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
BinaryStreamReader.h
llvm::pdb::DbiStreamBuilder::commit
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer)
Definition: DbiStreamBuilder.cpp:383
llvm::pdb::DbiStreamBuilder::setBuildNumber
void setBuildNumber(uint16_t B)
Definition: DbiStreamBuilder.cpp:39
RawConstants.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
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:89
llvm::pdb::DbiStreamBuilder::addModuleInfo
Expected< DbiModuleDescriptorBuilder & > addModuleInfo(StringRef ModuleName)
Definition: DbiStreamBuilder.cpp:111
BinaryByteStream.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
llvm::pdb::DbiStreamBuilder::setMachineType
void setMachineType(PDB_Machine M)
Definition: DbiStreamBuilder.cpp:55
llvm::pdb::DbiStreamBuilder::~DbiStreamBuilder
~DbiStreamBuilder()
Definition: DbiStreamBuilder.cpp:33
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:85
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:572
llvm::Optional< PdbRaw_DbiVer >
llvm::pdb::DbiStreamBuilder::addModuleSourceFile
Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File)
Definition: DbiStreamBuilder.cpp:118
llvm::pdb::DbiStreamBuilder::setVersionHeader
void setVersionHeader(PdbRaw_DbiVer V)
Definition: DbiStreamBuilder.cpp:35
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::DbiStreamBuilder::addNewFpoData
void addNewFpoData(const codeview::FrameData &FD)
Definition: DbiStreamBuilder.cpp:74
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::pdb::DbiStreamBuilder::addOldFpoData
void addOldFpoData(const object::FpoData &Fpo)
Definition: DbiStreamBuilder.cpp:81
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:26
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::pdb::DbiStreamBuilder::createSectionMap
void createSectionMap(ArrayRef< llvm::object::coff_section > SecHdrs)
Definition: DbiStreamBuilder.cpp:351
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:410
llvm::pdb::DbiStreamBuilder::getSourceFileNameIndex
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
Definition: DbiStreamBuilder.cpp:126
llvm::pdb::DbiStreamBuilder
Definition: DbiStreamBuilder.h:43
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")
PDBTypes.h
llvm::pdb::DbiStreamBuilder::addECName
uint32_t addECName(StringRef Name)
Definition: DbiStreamBuilder.cpp:98
llvm::StringMap< uint32_t >
llvm::pdb::DbiStreamBuilder::setPdbDllVersion
void setPdbDllVersion(uint16_t V)
Definition: DbiStreamBuilder.cpp:49
llvm::pdb::DbiStreamBuilder::setPublicsStreamIndex
void setPublicsStreamIndex(uint32_t Index)
Definition: DbiStreamBuilder.cpp:70
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::pdb::DbiStreamBuilder::setFlags
void setFlags(uint16_t F)
Definition: DbiStreamBuilder.cpp:53
llvm::pdb::DbiStreamBuilder::setGlobalsStreamIndex
void setGlobalsStreamIndex(uint32_t Index)
Definition: DbiStreamBuilder.cpp:62
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::pdb::DbiStreamBuilder::DbiStreamBuilder
DbiStreamBuilder(msf::MSFBuilder &Msf)
Definition: DbiStreamBuilder.cpp:28
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
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
uint32_t
llvm::pdb::DbiStreamBuilder::finalizeMsfLayout
Error finalizeMsfLayout()
Definition: DbiStreamBuilder.cpp:288
llvm::pdb::DbiStreamBuilder::setSymbolRecordStreamIndex
void setSymbolRecordStreamIndex(uint32_t Index)
Definition: DbiStreamBuilder.cpp:66
llvm::pdb::DbiStreamBuilder::setAge
void setAge(uint32_t A)
Definition: DbiStreamBuilder.cpp:37
llvm::pdb::DbiStreamBuilder::setPdbDllRbld
void setPdbDllRbld(uint16_t R)
Definition: DbiStreamBuilder.cpp:51
StringSet.h
llvm::pdb::DbiStreamBuilder::operator=
DbiStreamBuilder & operator=(const DbiStreamBuilder &)=delete
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::pdb::DbiModuleDescriptorBuilder
Definition: DbiModuleDescriptorBuilder.h:65
PDBStringTableBuilder.h
llvm::COFF::MachineTypes
MachineTypes
Definition: COFF.h:93
llvm::pdb::DbiStreamBuilder::addSectionContrib
void addSectionContrib(const SectionContrib &SC)
Definition: DbiStreamBuilder.h:82
llvm::pdb::DbiStreamBuilder::calculateSerializedLength
uint32_t calculateSerializedLength() const
Definition: DbiStreamBuilder.cpp:102
llvm::pdb::DbgHeaderType::Max
@ Max
PDBFile.h
DebugFrameDataSubsection.h
llvm::pdb::DbgHeaderType
DbgHeaderType
Definition: RawConstants.h:86
Endian.h
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::WritableBinaryStreamRef
Definition: BinaryStreamRef.h:221
llvm::codeview::DebugSubsectionKind::FrameData
@ FrameData
llvm::object::FpoData
Definition: COFF.h:1276