File indexing completed on 2026-05-10 08:43:44
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULEDESCRIPTORBUILDER_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULEDESCRIPTORBUILDER_H
0011
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/DebugInfo/CodeView/CVRecord.h"
0015 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
0016 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
0017 #include "llvm/Support/BinaryStreamRef.h"
0018 #include "llvm/Support/Error.h"
0019 #include <cstdint>
0020 #include <string>
0021 #include <vector>
0022
0023 namespace llvm {
0024 class BinaryStreamWriter;
0025 namespace codeview {
0026 class DebugSubsection;
0027 }
0028
0029 namespace msf {
0030 class MSFBuilder;
0031 struct MSFLayout;
0032 }
0033 namespace pdb {
0034
0035
0036
0037
0038 struct SymbolListWrapper {
0039 explicit SymbolListWrapper(ArrayRef<uint8_t> Syms)
0040 : SymPtr(const_cast<uint8_t *>(Syms.data())), SymSize(Syms.size()),
0041 NeedsToBeMerged(false) {}
0042 explicit SymbolListWrapper(void *SymSrc, uint32_t Length)
0043 : SymPtr(SymSrc), SymSize(Length), NeedsToBeMerged(true) {}
0044
0045 ArrayRef<uint8_t> asArray() const {
0046 return ArrayRef<uint8_t>(static_cast<const uint8_t *>(SymPtr), SymSize);
0047 }
0048
0049 uint32_t size() const { return SymSize; }
0050
0051 void *SymPtr = nullptr;
0052 uint32_t SymSize = 0;
0053 bool NeedsToBeMerged = false;
0054 };
0055
0056
0057
0058 struct StringTableFixup {
0059 uint32_t StrTabOffset = 0;
0060 uint32_t SymOffsetOfReference = 0;
0061 };
0062
0063 class DbiModuleDescriptorBuilder {
0064 friend class DbiStreamBuilder;
0065
0066 public:
0067 DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex,
0068 msf::MSFBuilder &Msf);
0069 ~DbiModuleDescriptorBuilder();
0070
0071 DbiModuleDescriptorBuilder(const DbiModuleDescriptorBuilder &) = delete;
0072 DbiModuleDescriptorBuilder &
0073 operator=(const DbiModuleDescriptorBuilder &) = delete;
0074
0075 void setPdbFilePathNI(uint32_t NI);
0076 void setObjFileName(StringRef Name);
0077
0078
0079 using MergeSymbolsCallback = Error (*)(void *Ctx, void *Symbols,
0080 BinaryStreamWriter &Writer);
0081
0082 void setMergeSymbolsCallback(void *Ctx, MergeSymbolsCallback Callback) {
0083 MergeSymsCtx = Ctx;
0084 MergeSymsCallback = Callback;
0085 }
0086
0087 void setStringTableFixups(std::vector<StringTableFixup> &&Fixups) {
0088 StringTableFixups = std::move(Fixups);
0089 }
0090
0091 void setFirstSectionContrib(const SectionContrib &SC);
0092 void addSymbol(codeview::CVSymbol Symbol);
0093 void addSymbolsInBulk(ArrayRef<uint8_t> BulkSymbols);
0094
0095
0096
0097 void addUnmergedSymbols(void *SymSrc, uint32_t SymLength);
0098
0099 void
0100 addDebugSubsection(std::shared_ptr<codeview::DebugSubsection> Subsection);
0101
0102 void
0103 addDebugSubsection(const codeview::DebugSubsectionRecord &SubsectionContents);
0104
0105 uint16_t getStreamIndex() const;
0106 StringRef getModuleName() const { return ModuleName; }
0107 StringRef getObjFileName() const { return ObjFileName; }
0108
0109 unsigned getModuleIndex() const { return Layout.Mod; }
0110
0111 ArrayRef<std::string> source_files() const { return SourceFiles; }
0112
0113 uint32_t calculateSerializedLength() const;
0114
0115
0116
0117 uint32_t getNextSymbolOffset() const { return SymbolByteSize + 4; }
0118
0119 void finalize();
0120 Error finalizeMsfLayout();
0121
0122
0123 Error commit(BinaryStreamWriter &ModiWriter);
0124
0125
0126
0127
0128 Error commitSymbolStream(const msf::MSFLayout &MsfLayout,
0129 WritableBinaryStreamRef MsfBuffer);
0130
0131 private:
0132 uint32_t calculateC13DebugInfoSize() const;
0133
0134 void addSourceFile(StringRef Path);
0135 msf::MSFBuilder &MSF;
0136
0137 uint32_t SymbolByteSize = 0;
0138 uint32_t PdbFilePathNI = 0;
0139 std::string ModuleName;
0140 std::string ObjFileName;
0141 std::vector<std::string> SourceFiles;
0142 std::vector<SymbolListWrapper> Symbols;
0143
0144 void *MergeSymsCtx = nullptr;
0145 MergeSymbolsCallback MergeSymsCallback = nullptr;
0146
0147 std::vector<StringTableFixup> StringTableFixups;
0148
0149 std::vector<codeview::DebugSubsectionRecordBuilder> C13Builders;
0150
0151 ModuleInfoHeader Layout;
0152 };
0153
0154 }
0155
0156 }
0157
0158 #endif