1 //===- DbiStream.h - PDB Dbi Stream (Stream 3) Access -----------*- 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_DBISTREAM_H 10 #define LLVM_DEBUGINFO_PDB_NATIVE_DBISTREAM_H 11 12 #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" 13 #include "llvm/DebugInfo/PDB/Native/DbiModuleList.h" 14 #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h" 15 #include "llvm/DebugInfo/PDB/Native/RawConstants.h" 16 #include "llvm/DebugInfo/PDB/PDBTypes.h" 17 #include "llvm/Support/BinaryStreamArray.h" 18 #include "llvm/Support/BinaryStreamRef.h" 19 #include "llvm/Support/Endian.h" 20 #include "llvm/Support/Error.h" 21 22 namespace llvm { 23 class BinaryStream; 24 namespace object { 25 struct FpoData; 26 struct coff_section; 27 } 28 namespace msf { 29 class MappedBlockStream; 30 } 31 namespace pdb { 32 struct DbiStreamHeader; 33 struct SecMapEntry; 34 struct SectionContrib2; 35 struct SectionContrib; 36 class PDBFile; 37 class ISectionContribVisitor; 38 39 class DbiStream { 40 friend class DbiStreamBuilder; 41 42 public: 43 explicit DbiStream(std::unique_ptr<BinaryStream> Stream); 44 ~DbiStream(); 45 Error reload(PDBFile *Pdb); 46 47 PdbRaw_DbiVer getDbiVersion() const; 48 uint32_t getAge() const; 49 uint16_t getPublicSymbolStreamIndex() const; 50 uint16_t getGlobalSymbolStreamIndex() const; 51 52 uint16_t getFlags() const; 53 bool isIncrementallyLinked() const; 54 bool hasCTypes() const; 55 bool isStripped() const; 56 57 uint16_t getBuildNumber() const; 58 uint16_t getBuildMajorVersion() const; 59 uint16_t getBuildMinorVersion() const; 60 61 uint16_t getPdbDllRbld() const; 62 uint32_t getPdbDllVersion() const; 63 64 uint32_t getSymRecordStreamIndex() const; 65 66 PDB_Machine getMachineType() const; 67 getHeader()68 const DbiStreamHeader *getHeader() const { return Header; } 69 70 BinarySubstreamRef getSectionContributionData() const; 71 BinarySubstreamRef getSecMapSubstreamData() const; 72 BinarySubstreamRef getModiSubstreamData() const; 73 BinarySubstreamRef getFileInfoSubstreamData() const; 74 BinarySubstreamRef getTypeServerMapSubstreamData() const; 75 BinarySubstreamRef getECSubstreamData() const; 76 77 /// If the given stream type is present, returns its stream index. If it is 78 /// not present, returns InvalidStreamIndex. 79 uint32_t getDebugStreamIndex(DbgHeaderType Type) const; 80 81 const DbiModuleList &modules() const; 82 83 FixedStreamArray<object::coff_section> getSectionHeaders() const; 84 85 bool hasOldFpoRecords() const; 86 FixedStreamArray<object::FpoData> getOldFpoRecords() const; 87 bool hasNewFpoRecords() const; 88 const codeview::DebugFrameDataSubsectionRef &getNewFpoRecords() const; 89 90 FixedStreamArray<SecMapEntry> getSectionMap() const; 91 void visitSectionContributions(ISectionContribVisitor &Visitor) const; 92 93 Expected<StringRef> getECName(uint32_t NI) const; 94 95 private: 96 Error initializeSectionContributionData(); 97 Error initializeSectionHeadersData(PDBFile *Pdb); 98 Error initializeSectionMapData(); 99 Error initializeOldFpoRecords(PDBFile *Pdb); 100 Error initializeNewFpoRecords(PDBFile *Pdb); 101 102 Expected<std::unique_ptr<msf::MappedBlockStream>> 103 createIndexedStreamForHeaderType(PDBFile *Pdb, DbgHeaderType Type) const; 104 105 std::unique_ptr<BinaryStream> Stream; 106 107 PDBStringTable ECNames; 108 109 BinarySubstreamRef SecContrSubstream; 110 BinarySubstreamRef SecMapSubstream; 111 BinarySubstreamRef ModiSubstream; 112 BinarySubstreamRef FileInfoSubstream; 113 BinarySubstreamRef TypeServerMapSubstream; 114 BinarySubstreamRef ECSubstream; 115 116 DbiModuleList Modules; 117 118 FixedStreamArray<support::ulittle16_t> DbgStreams; 119 120 PdbRaw_DbiSecContribVer SectionContribVersion = 121 PdbRaw_DbiSecContribVer::DbiSecContribVer60; 122 FixedStreamArray<SectionContrib> SectionContribs; 123 FixedStreamArray<SectionContrib2> SectionContribs2; 124 FixedStreamArray<SecMapEntry> SectionMap; 125 126 std::unique_ptr<msf::MappedBlockStream> SectionHeaderStream; 127 FixedStreamArray<object::coff_section> SectionHeaders; 128 129 std::unique_ptr<msf::MappedBlockStream> OldFpoStream; 130 FixedStreamArray<object::FpoData> OldFpoRecords; 131 132 std::unique_ptr<msf::MappedBlockStream> NewFpoStream; 133 codeview::DebugFrameDataSubsectionRef NewFpoRecords; 134 135 const DbiStreamHeader *Header; 136 }; 137 } 138 } 139 140 #endif 141