File indexing completed on 2026-05-10 08:43:43
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_DEBUGINFO_MSF_MAPPEDBLOCKSTREAM_H
0010 #define LLVM_DEBUGINFO_MSF_MAPPEDBLOCKSTREAM_H
0011
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/DenseMap.h"
0014 #include "llvm/DebugInfo/MSF/MSFCommon.h"
0015 #include "llvm/Support/Allocator.h"
0016 #include "llvm/Support/BinaryStream.h"
0017 #include "llvm/Support/BinaryStreamRef.h"
0018 #include "llvm/Support/Endian.h"
0019 #include "llvm/Support/Error.h"
0020 #include <cstdint>
0021 #include <memory>
0022 #include <vector>
0023
0024 namespace llvm {
0025 namespace msf {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 class MappedBlockStream : public BinaryStream {
0038 friend class WritableMappedBlockStream;
0039
0040 public:
0041 static std::unique_ptr<MappedBlockStream>
0042 createStream(uint32_t BlockSize, const MSFStreamLayout &Layout,
0043 BinaryStreamRef MsfData, BumpPtrAllocator &Allocator);
0044
0045 static std::unique_ptr<MappedBlockStream>
0046 createIndexedStream(const MSFLayout &Layout, BinaryStreamRef MsfData,
0047 uint32_t StreamIndex, BumpPtrAllocator &Allocator);
0048
0049 static std::unique_ptr<MappedBlockStream>
0050 createFpmStream(const MSFLayout &Layout, BinaryStreamRef MsfData,
0051 BumpPtrAllocator &Allocator);
0052
0053 static std::unique_ptr<MappedBlockStream>
0054 createDirectoryStream(const MSFLayout &Layout, BinaryStreamRef MsfData,
0055 BumpPtrAllocator &Allocator);
0056
0057 llvm::endianness getEndian() const override {
0058 return llvm::endianness::little;
0059 }
0060
0061 Error readBytes(uint64_t Offset, uint64_t Size,
0062 ArrayRef<uint8_t> &Buffer) override;
0063 Error readLongestContiguousChunk(uint64_t Offset,
0064 ArrayRef<uint8_t> &Buffer) override;
0065
0066 uint64_t getLength() override;
0067
0068 BumpPtrAllocator &getAllocator() { return Allocator; }
0069
0070 void invalidateCache();
0071
0072 uint32_t getBlockSize() const { return BlockSize; }
0073 uint32_t getNumBlocks() const { return StreamLayout.Blocks.size(); }
0074 uint32_t getStreamLength() const { return StreamLayout.Length; }
0075
0076 protected:
0077 MappedBlockStream(uint32_t BlockSize, const MSFStreamLayout &StreamLayout,
0078 BinaryStreamRef MsfData, BumpPtrAllocator &Allocator);
0079
0080 private:
0081 const MSFStreamLayout &getStreamLayout() const { return StreamLayout; }
0082 void fixCacheAfterWrite(uint64_t Offset, ArrayRef<uint8_t> Data) const;
0083
0084 Error readBytes(uint64_t Offset, MutableArrayRef<uint8_t> Buffer);
0085 bool tryReadContiguously(uint64_t Offset, uint64_t Size,
0086 ArrayRef<uint8_t> &Buffer);
0087
0088 const uint32_t BlockSize;
0089 const MSFStreamLayout StreamLayout;
0090 BinaryStreamRef MsfData;
0091
0092 using CacheEntry = MutableArrayRef<uint8_t>;
0093
0094
0095
0096
0097
0098
0099
0100
0101 BumpPtrAllocator &Allocator;
0102 DenseMap<uint32_t, std::vector<CacheEntry>> CacheMap;
0103 };
0104
0105 class WritableMappedBlockStream : public WritableBinaryStream {
0106 public:
0107 static std::unique_ptr<WritableMappedBlockStream>
0108 createStream(uint32_t BlockSize, const MSFStreamLayout &Layout,
0109 WritableBinaryStreamRef MsfData, BumpPtrAllocator &Allocator);
0110
0111 static std::unique_ptr<WritableMappedBlockStream>
0112 createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData,
0113 uint32_t StreamIndex, BumpPtrAllocator &Allocator);
0114
0115 static std::unique_ptr<WritableMappedBlockStream>
0116 createDirectoryStream(const MSFLayout &Layout,
0117 WritableBinaryStreamRef MsfData,
0118 BumpPtrAllocator &Allocator);
0119
0120 static std::unique_ptr<WritableMappedBlockStream>
0121 createFpmStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData,
0122 BumpPtrAllocator &Allocator, bool AltFpm = false);
0123
0124 llvm::endianness getEndian() const override {
0125 return llvm::endianness::little;
0126 }
0127
0128 Error readBytes(uint64_t Offset, uint64_t Size,
0129 ArrayRef<uint8_t> &Buffer) override;
0130 Error readLongestContiguousChunk(uint64_t Offset,
0131 ArrayRef<uint8_t> &Buffer) override;
0132 uint64_t getLength() override;
0133
0134 Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Buffer) override;
0135
0136 Error commit() override;
0137
0138 const MSFStreamLayout &getStreamLayout() const {
0139 return ReadInterface.getStreamLayout();
0140 }
0141
0142 uint32_t getBlockSize() const { return ReadInterface.getBlockSize(); }
0143 uint32_t getNumBlocks() const { return ReadInterface.getNumBlocks(); }
0144 uint32_t getStreamLength() const { return ReadInterface.getStreamLength(); }
0145
0146 protected:
0147 WritableMappedBlockStream(uint32_t BlockSize,
0148 const MSFStreamLayout &StreamLayout,
0149 WritableBinaryStreamRef MsfData,
0150 BumpPtrAllocator &Allocator);
0151
0152 private:
0153 MappedBlockStream ReadInterface;
0154 WritableBinaryStreamRef WriteInterface;
0155 };
0156
0157 }
0158 }
0159
0160 #endif