Yi Kong | 878f994 | 2023-12-13 12:55:04 +0900 | [diff] [blame^] | 1 | //===- PDBFile.h - Low level interface to a PDB file ------------*- 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_PDBFILE_H |
| 10 | #define LLVM_DEBUGINFO_PDB_NATIVE_PDBFILE_H |
| 11 | |
| 12 | #include "llvm/DebugInfo/MSF/IMSFFile.h" |
| 13 | #include "llvm/DebugInfo/MSF/MSFCommon.h" |
| 14 | #include "llvm/Support/Allocator.h" |
| 15 | #include "llvm/Support/BinaryStreamRef.h" |
| 16 | #include "llvm/Support/Endian.h" |
| 17 | #include "llvm/Support/Error.h" |
| 18 | |
| 19 | #include <memory> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | class BinaryStream; |
| 24 | |
| 25 | namespace msf { |
| 26 | class MappedBlockStream; |
| 27 | } |
| 28 | |
| 29 | namespace pdb { |
| 30 | class DbiStream; |
| 31 | class GlobalsStream; |
| 32 | class InfoStream; |
| 33 | class InjectedSourceStream; |
| 34 | class PDBStringTable; |
| 35 | class PDBFileBuilder; |
| 36 | class PublicsStream; |
| 37 | class SymbolStream; |
| 38 | class TpiStream; |
| 39 | |
| 40 | class PDBFile : public msf::IMSFFile { |
| 41 | friend PDBFileBuilder; |
| 42 | |
| 43 | public: |
| 44 | PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer, |
| 45 | BumpPtrAllocator &Allocator); |
| 46 | ~PDBFile() override; |
| 47 | |
| 48 | StringRef getFileDirectory() const; |
| 49 | StringRef getFilePath() const; |
| 50 | |
| 51 | uint32_t getFreeBlockMapBlock() const; |
| 52 | uint32_t getUnknown1() const; |
| 53 | |
| 54 | uint32_t getBlockSize() const override; |
| 55 | uint32_t getBlockCount() const override; |
| 56 | uint32_t getNumDirectoryBytes() const; |
| 57 | uint32_t getBlockMapIndex() const; |
| 58 | uint32_t getNumDirectoryBlocks() const; |
| 59 | uint64_t getBlockMapOffset() const; |
| 60 | |
| 61 | uint32_t getNumStreams() const override; |
| 62 | uint32_t getMaxStreamSize() const; |
| 63 | uint32_t getStreamByteSize(uint32_t StreamIndex) const override; |
| 64 | ArrayRef<support::ulittle32_t> |
| 65 | getStreamBlockList(uint32_t StreamIndex) const override; |
| 66 | uint64_t getFileSize() const; |
| 67 | |
| 68 | Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex, |
| 69 | uint32_t NumBytes) const override; |
| 70 | Error setBlockData(uint32_t BlockIndex, uint32_t Offset, |
| 71 | ArrayRef<uint8_t> Data) const override; |
| 72 | |
| 73 | ArrayRef<support::ulittle32_t> getStreamSizes() const { |
| 74 | return ContainerLayout.StreamSizes; |
| 75 | } |
| 76 | ArrayRef<ArrayRef<support::ulittle32_t>> getStreamMap() const { |
| 77 | return ContainerLayout.StreamMap; |
| 78 | } |
| 79 | |
| 80 | const msf::MSFLayout &getMsfLayout() const { return ContainerLayout; } |
| 81 | BinaryStreamRef getMsfBuffer() const { return *Buffer; } |
| 82 | |
| 83 | ArrayRef<support::ulittle32_t> getDirectoryBlockArray() const; |
| 84 | |
| 85 | std::unique_ptr<msf::MappedBlockStream> |
| 86 | createIndexedStream(uint16_t SN) const; |
| 87 | Expected<std::unique_ptr<msf::MappedBlockStream>> |
| 88 | safelyCreateIndexedStream(uint32_t StreamIndex) const; |
| 89 | Expected<std::unique_ptr<msf::MappedBlockStream>> |
| 90 | safelyCreateNamedStream(StringRef Name); |
| 91 | |
| 92 | msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const; |
| 93 | msf::MSFStreamLayout getFpmStreamLayout() const; |
| 94 | |
| 95 | Error parseFileHeaders(); |
| 96 | Error parseStreamData(); |
| 97 | |
| 98 | Expected<InfoStream &> getPDBInfoStream(); |
| 99 | Expected<DbiStream &> getPDBDbiStream(); |
| 100 | Expected<GlobalsStream &> getPDBGlobalsStream(); |
| 101 | Expected<TpiStream &> getPDBTpiStream(); |
| 102 | Expected<TpiStream &> getPDBIpiStream(); |
| 103 | Expected<PublicsStream &> getPDBPublicsStream(); |
| 104 | Expected<SymbolStream &> getPDBSymbolStream(); |
| 105 | Expected<PDBStringTable &> getStringTable(); |
| 106 | Expected<InjectedSourceStream &> getInjectedSourceStream(); |
| 107 | |
| 108 | BumpPtrAllocator &getAllocator() { return Allocator; } |
| 109 | |
| 110 | bool hasPDBDbiStream() const; |
| 111 | bool hasPDBGlobalsStream(); |
| 112 | bool hasPDBInfoStream() const; |
| 113 | bool hasPDBIpiStream() const; |
| 114 | bool hasPDBPublicsStream(); |
| 115 | bool hasPDBSymbolStream(); |
| 116 | bool hasPDBTpiStream() const; |
| 117 | bool hasPDBStringTable(); |
| 118 | bool hasPDBInjectedSourceStream(); |
| 119 | |
| 120 | uint32_t getPointerSize(); |
| 121 | |
| 122 | private: |
| 123 | std::string FilePath; |
| 124 | BumpPtrAllocator &Allocator; |
| 125 | |
| 126 | std::unique_ptr<BinaryStream> Buffer; |
| 127 | |
| 128 | msf::MSFLayout ContainerLayout; |
| 129 | |
| 130 | std::unique_ptr<GlobalsStream> Globals; |
| 131 | std::unique_ptr<InfoStream> Info; |
| 132 | std::unique_ptr<DbiStream> Dbi; |
| 133 | std::unique_ptr<TpiStream> Tpi; |
| 134 | std::unique_ptr<TpiStream> Ipi; |
| 135 | std::unique_ptr<PublicsStream> Publics; |
| 136 | std::unique_ptr<SymbolStream> Symbols; |
| 137 | std::unique_ptr<msf::MappedBlockStream> DirectoryStream; |
| 138 | std::unique_ptr<msf::MappedBlockStream> StringTableStream; |
| 139 | std::unique_ptr<InjectedSourceStream> InjectedSources; |
| 140 | std::unique_ptr<PDBStringTable> Strings; |
| 141 | }; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | #endif |