LLVM 20.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/StringMap.h"
13#include "llvm/ADT/StringRef.h"
15#include "llvm/Object/COFF.h"
17#include "llvm/Support/Error.h"
18
26
27namespace llvm {
28
29class BinaryStreamWriter;
30namespace codeview {
31struct FrameData;
32}
33namespace msf {
34class MSFBuilder;
35struct MSFLayout;
36}
37namespace pdb {
38class DbiModuleDescriptorBuilder;
39
41public:
44
47
49 void setAge(uint32_t A);
51 void setBuildNumber(uint8_t Major, uint8_t Minor);
53 void setPdbDllRbld(uint16_t R);
54 void setFlags(uint16_t F);
57
58 // Add given bytes as a new stream.
60
62
64
68 void addNewFpoData(const codeview::FrameData &FD);
69 void addOldFpoData(const object::FpoData &Fpo);
70
74
76
77 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
78
80 SectionContribs.emplace_back(SC);
81 }
82
83 // Populate the Section Map from COFF section headers.
85
86private:
87 struct DebugStream {
88 std::function<Error(BinaryStreamWriter &)> WriteFn;
89 uint32_t Size = 0;
90 uint16_t StreamNumber = kInvalidStreamIndex;
91 };
92
93 Error finalize();
94 uint32_t calculateModiSubstreamSize() const;
95 uint32_t calculateNamesOffset() const;
96 uint32_t calculateSectionContribsStreamSize() const;
97 uint32_t calculateSectionMapStreamSize() const;
98 uint32_t calculateFileInfoSubstreamSize() const;
99 uint32_t calculateNamesBufferSize() const;
100 uint32_t calculateDbgStreamsSize() const;
101
102 Error generateFileInfoSubstream();
103
104 msf::MSFBuilder &Msf;
105 BumpPtrAllocator &Allocator;
106
107 std::optional<PdbRaw_DbiVer> VerHeader;
108 uint32_t Age;
109 uint16_t BuildNumber;
110 uint16_t PdbDllVersion;
111 uint16_t PdbDllRbld;
112 uint16_t Flags;
113 PDB_Machine MachineType;
114 uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
115 uint32_t PublicsStreamIndex = kInvalidStreamIndex;
116 uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
117
118 const DbiStreamHeader *Header;
119
120 std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
121
122 std::optional<codeview::DebugFrameDataSubsection> NewFpoData;
123 std::vector<object::FpoData> OldFpoData;
124
125 StringMap<uint32_t> SourceFileNames;
126
127 PDBStringTableBuilder ECNamesBuilder;
128 WritableBinaryStreamRef NamesBuffer;
129 MutableBinaryByteStream FileInfoBuffer;
130 std::vector<SectionContrib> SectionContribs;
131 std::vector<SecMapEntry> SectionMap;
132 std::array<std::optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
133};
134} // namespace pdb
135}
136
137#endif
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string Name
uint32_t Index
#define F(x, y, z)
Definition: MD5.cpp:55
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Provides write only access to a subclass of WritableBinaryStream.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
void addSectionContrib(const SectionContrib &SC)
void createSectionMap(ArrayRef< llvm::object::coff_section > SecHdrs)
void addOldFpoData(const object::FpoData &Fpo)
void setPublicsStreamIndex(uint32_t Index)
Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File)
DbiStreamBuilder(const DbiStreamBuilder &)=delete
void setGlobalsStreamIndex(uint32_t Index)
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
DbiStreamBuilder & operator=(const DbiStreamBuilder &)=delete
void setSymbolRecordStreamIndex(uint32_t Index)
void addNewFpoData(const codeview::FrameData &FD)
void setVersionHeader(PdbRaw_DbiVer V)
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer)
Expected< DbiModuleDescriptorBuilder & > addModuleInfo(StringRef ModuleName)
uint32_t calculateSerializedLength() const
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef< uint8_t > Data)
uint32_t addECName(StringRef Name)
void setMachineType(PDB_Machine M)
MachineTypes
Definition: COFF.h:92
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Data in the SUBSEC_FRAMEDATA subection.
Definition: CodeView.h:584