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