• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MappedBlockStream.h - Reads stream data from a PDBFile ---*- 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_MAPPEDBLOCKSTREAM_H
11 #define LLVM_DEBUGINFO_PDB_RAW_MAPPEDBLOCKSTREAM_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/DebugInfo/CodeView/StreamInterface.h"
17 #include "llvm/DebugInfo/PDB/Raw/IPDBStreamData.h"
18 #include "llvm/Support/Allocator.h"
19 #include "llvm/Support/Endian.h"
20 #include "llvm/Support/Error.h"
21 #include <cstdint>
22 #include <vector>
23 
24 namespace llvm {
25 namespace pdb {
26 
27 class IPDBFile;
28 class PDBFile;
29 
30 class MappedBlockStream : public codeview::StreamInterface {
31 public:
32   Error readBytes(uint32_t Offset, uint32_t Size,
33                   ArrayRef<uint8_t> &Buffer) const override;
34   Error readLongestContiguousChunk(uint32_t Offset,
35                                    ArrayRef<uint8_t> &Buffer) const override;
36   Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const override;
37 
38   uint32_t getLength() const override;
39   Error commit() const override;
40 
41   uint32_t getNumBytesCopied() const;
42 
43   static Expected<std::unique_ptr<MappedBlockStream>>
44   createIndexedStream(uint32_t StreamIdx, const IPDBFile &File);
45   static Expected<std::unique_ptr<MappedBlockStream>>
46   createDirectoryStream(const PDBFile &File);
47 
getAllocator()48   llvm::BumpPtrAllocator &getAllocator() { return Pool; }
49 
50 protected:
51   MappedBlockStream(std::unique_ptr<IPDBStreamData> Data, const IPDBFile &File);
52 
53   Error readBytes(uint32_t Offset, MutableArrayRef<uint8_t> Buffer) const;
54   bool tryReadContiguously(uint32_t Offset, uint32_t Size,
55                            ArrayRef<uint8_t> &Buffer) const;
56 
57   const IPDBFile &Pdb;
58   std::unique_ptr<IPDBStreamData> Data;
59 
60   typedef MutableArrayRef<uint8_t> CacheEntry;
61   mutable llvm::BumpPtrAllocator Pool;
62   mutable DenseMap<uint32_t, std::vector<CacheEntry>> CacheMap;
63 };
64 
65 } // end namespace pdb
66 } // end namespace llvm
67 
68 #endif // LLVM_DEBUGINFO_PDB_RAW_MAPPEDBLOCKSTREAM_H
69