1 //===- DbiModuleDescriptorBuilder.h - PDB module information ----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H 11 #define LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H 12 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" 15 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" 16 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" 17 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" 18 #include "llvm/DebugInfo/CodeView/SymbolRecord.h" 19 #include "llvm/DebugInfo/PDB/Native/RawTypes.h" 20 #include "llvm/Support/Error.h" 21 #include <cstdint> 22 #include <string> 23 #include <vector> 24 25 namespace llvm { 26 class BinaryStreamWriter; 27 28 namespace codeview { 29 class DebugSubsectionRecordBuilder; 30 } 31 32 namespace msf { 33 class MSFBuilder; 34 struct MSFLayout; 35 } 36 namespace pdb { 37 38 class DbiModuleDescriptorBuilder { 39 friend class DbiStreamBuilder; 40 41 public: 42 DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex, 43 msf::MSFBuilder &Msf); 44 ~DbiModuleDescriptorBuilder(); 45 46 DbiModuleDescriptorBuilder(const DbiModuleDescriptorBuilder &) = delete; 47 DbiModuleDescriptorBuilder & 48 operator=(const DbiModuleDescriptorBuilder &) = delete; 49 50 void setPdbFilePathNI(uint32_t NI); 51 void setObjFileName(StringRef Name); 52 void setFirstSectionContrib(const SectionContrib &SC); 53 void addSymbol(codeview::CVSymbol Symbol); 54 55 void 56 addDebugSubsection(std::shared_ptr<codeview::DebugSubsection> Subsection); 57 58 void 59 addDebugSubsection(const codeview::DebugSubsectionRecord &SubsectionContents); 60 61 uint16_t getStreamIndex() const; getModuleName()62 StringRef getModuleName() const { return ModuleName; } getObjFileName()63 StringRef getObjFileName() const { return ObjFileName; } 64 getModuleIndex()65 unsigned getModuleIndex() const { return Layout.Mod; } 66 source_files()67 ArrayRef<std::string> source_files() const { 68 return makeArrayRef(SourceFiles); 69 } 70 71 uint32_t calculateSerializedLength() const; 72 73 /// Return the offset within the module symbol stream of the next symbol 74 /// record passed to addSymbol. Add four to account for the signature. getNextSymbolOffset()75 uint32_t getNextSymbolOffset() const { return SymbolByteSize + 4; } 76 77 void finalize(); 78 Error finalizeMsfLayout(); 79 80 Error commit(BinaryStreamWriter &ModiWriter, const msf::MSFLayout &MsfLayout, 81 WritableBinaryStreamRef MsfBuffer); 82 83 private: 84 uint32_t calculateC13DebugInfoSize() const; 85 86 void addSourceFile(StringRef Path); 87 msf::MSFBuilder &MSF; 88 89 uint32_t SymbolByteSize = 0; 90 uint32_t PdbFilePathNI = 0; 91 std::string ModuleName; 92 std::string ObjFileName; 93 std::vector<std::string> SourceFiles; 94 std::vector<codeview::CVSymbol> Symbols; 95 96 std::vector<std::unique_ptr<codeview::DebugSubsectionRecordBuilder>> 97 C13Builders; 98 99 ModuleInfoHeader Layout; 100 }; 101 102 } // end namespace pdb 103 104 } // end namespace llvm 105 106 #endif // LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H 107