File indexing completed on 2026-05-10 08:43:44
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_DBISTREAMBUILDER_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_DBISTREAMBUILDER_H
0011
0012 #include "llvm/ADT/StringMap.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/BinaryFormat/COFF.h"
0015 #include "llvm/Object/COFF.h"
0016 #include "llvm/Support/Allocator.h"
0017 #include "llvm/Support/Error.h"
0018
0019 #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
0020 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
0021 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
0022 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
0023 #include "llvm/DebugInfo/PDB/PDBTypes.h"
0024 #include "llvm/Support/BinaryByteStream.h"
0025 #include "llvm/Support/BinaryStreamRef.h"
0026
0027 namespace llvm {
0028
0029 class BinaryStreamWriter;
0030 namespace codeview {
0031 struct FrameData;
0032 }
0033 namespace msf {
0034 class MSFBuilder;
0035 struct MSFLayout;
0036 }
0037 namespace pdb {
0038 class DbiModuleDescriptorBuilder;
0039
0040 class DbiStreamBuilder {
0041 public:
0042 DbiStreamBuilder(msf::MSFBuilder &Msf);
0043 ~DbiStreamBuilder();
0044
0045 DbiStreamBuilder(const DbiStreamBuilder &) = delete;
0046 DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
0047
0048 void setVersionHeader(PdbRaw_DbiVer V);
0049 void setAge(uint32_t A);
0050 void setBuildNumber(uint16_t B);
0051 void setBuildNumber(uint8_t Major, uint8_t Minor);
0052 void setPdbDllVersion(uint16_t V);
0053 void setPdbDllRbld(uint16_t R);
0054 void setFlags(uint16_t F);
0055 void setMachineType(PDB_Machine M);
0056 void setMachineType(COFF::MachineTypes M);
0057
0058
0059 Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
0060
0061 uint32_t addECName(StringRef Name);
0062
0063 uint32_t calculateSerializedLength() const;
0064
0065 void setGlobalsStreamIndex(uint32_t Index);
0066 void setPublicsStreamIndex(uint32_t Index);
0067 void setSymbolRecordStreamIndex(uint32_t Index);
0068 void addNewFpoData(const codeview::FrameData &FD);
0069 void addOldFpoData(const object::FpoData &Fpo);
0070
0071 Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName);
0072 Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File);
0073 Expected<uint32_t> getSourceFileNameIndex(StringRef FileName);
0074
0075 Error finalizeMsfLayout();
0076
0077 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
0078
0079 void addSectionContrib(const SectionContrib &SC) {
0080 SectionContribs.emplace_back(SC);
0081 }
0082
0083
0084 void createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
0085
0086 private:
0087 struct DebugStream {
0088 std::function<Error(BinaryStreamWriter &)> WriteFn;
0089 uint32_t Size = 0;
0090 uint16_t StreamNumber = kInvalidStreamIndex;
0091 };
0092
0093 Error finalize();
0094 uint32_t calculateModiSubstreamSize() const;
0095 uint32_t calculateNamesOffset() const;
0096 uint32_t calculateSectionContribsStreamSize() const;
0097 uint32_t calculateSectionMapStreamSize() const;
0098 uint32_t calculateFileInfoSubstreamSize() const;
0099 uint32_t calculateNamesBufferSize() const;
0100 uint32_t calculateDbgStreamsSize() const;
0101
0102 Error generateFileInfoSubstream();
0103
0104 msf::MSFBuilder &Msf;
0105 BumpPtrAllocator &Allocator;
0106
0107 std::optional<PdbRaw_DbiVer> VerHeader;
0108 uint32_t Age;
0109 uint16_t BuildNumber;
0110 uint16_t PdbDllVersion;
0111 uint16_t PdbDllRbld;
0112 uint16_t Flags;
0113 PDB_Machine MachineType;
0114 uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
0115 uint32_t PublicsStreamIndex = kInvalidStreamIndex;
0116 uint32_t SymRecordStreamIndex = kInvalidStreamIndex;
0117
0118 const DbiStreamHeader *Header;
0119
0120 std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList;
0121
0122 std::optional<codeview::DebugFrameDataSubsection> NewFpoData;
0123 std::vector<object::FpoData> OldFpoData;
0124
0125 StringMap<uint32_t> SourceFileNames;
0126
0127 PDBStringTableBuilder ECNamesBuilder;
0128 WritableBinaryStreamRef NamesBuffer;
0129 MutableBinaryByteStream FileInfoBuffer;
0130 std::vector<SectionContrib> SectionContribs;
0131 std::vector<SecMapEntry> SectionMap;
0132 std::array<std::optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
0133 };
0134 }
0135 }
0136
0137 #endif