LLVM  9.0.0svn
PDBFile.h
Go to the documentation of this file.
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_RAW_PDBFILE_H
10 #define LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H
11 
12 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/Support/Allocator.h"
17 #include "llvm/Support/Endian.h"
18 #include "llvm/Support/Error.h"
20 
21 #include <memory>
22 
23 namespace llvm {
24 
25 class BinaryStream;
26 
27 namespace msf {
28 class MappedBlockStream;
29 }
30 
31 namespace pdb {
32 class DbiStream;
33 class GlobalsStream;
34 class InfoStream;
35 class PDBStringTable;
36 class PDBFileBuilder;
37 class PublicsStream;
38 class SymbolStream;
39 class TpiStream;
40 
41 class PDBFile : public msf::IMSFFile {
42  friend PDBFileBuilder;
43 
44 public:
45  PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer,
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;
66  getStreamBlockList(uint32_t StreamIndex) const override;
67  uint32_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 
75  return ContainerLayout.StreamSizes;
76  }
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> createIndexedStream(uint16_t SN);
87 
88  msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const;
90 
91  Error parseFileHeaders();
92  Error parseStreamData();
93 
94  Expected<InfoStream &> getPDBInfoStream();
95  Expected<DbiStream &> getPDBDbiStream();
96  Expected<GlobalsStream &> getPDBGlobalsStream();
97  Expected<TpiStream &> getPDBTpiStream();
98  Expected<TpiStream &> getPDBIpiStream();
99  Expected<PublicsStream &> getPDBPublicsStream();
100  Expected<SymbolStream &> getPDBSymbolStream();
101  Expected<PDBStringTable &> getStringTable();
102 
104 
105  bool hasPDBDbiStream() const;
106  bool hasPDBGlobalsStream();
107  bool hasPDBInfoStream() const;
108  bool hasPDBIpiStream() const;
109  bool hasPDBPublicsStream();
110  bool hasPDBSymbolStream();
111  bool hasPDBTpiStream() const;
112  bool hasPDBStringTable();
113 
115 
116 private:
118  safelyCreateIndexedStream(const msf::MSFLayout &Layout,
119  BinaryStreamRef MsfData,
120  uint32_t StreamIndex) const;
121 
122  std::string FilePath;
124 
125  std::unique_ptr<BinaryStream> Buffer;
126 
127  msf::MSFLayout ContainerLayout;
128 
129  std::unique_ptr<GlobalsStream> Globals;
130  std::unique_ptr<InfoStream> Info;
131  std::unique_ptr<DbiStream> Dbi;
132  std::unique_ptr<TpiStream> Tpi;
133  std::unique_ptr<TpiStream> Ipi;
134  std::unique_ptr<PublicsStream> Publics;
135  std::unique_ptr<SymbolStream> Symbols;
136  std::unique_ptr<msf::MappedBlockStream> DirectoryStream;
137  std::unique_ptr<msf::MappedBlockStream> StringTableStream;
138  std::unique_ptr<PDBStringTable> Strings;
139 };
140 }
141 }
142 
143 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
Describes the layout of a stream in an MSF layout.
Definition: MSFCommon.h:77
MSFStreamLayout getFpmStreamLayout(const MSFLayout &Msf, bool IncludeUnusedFpmData=false, bool AltFpm=false)
Determine the layout of the FPM stream, given the MSF layout.
Definition: MSFCommon.cpp:62
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
static uint64_t getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
BinaryStreamRef getMsfBuffer() const
Definition: PDBFile.h:82
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
BumpPtrAllocator & getAllocator()
Definition: PDBFile.h:103
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
ArrayRef< support::ulittle32_t > getStreamSizes() const
Definition: PDBFile.h:74
Basic Register Allocator
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
ArrayRef< ArrayRef< support::ulittle32_t > > getStreamMap() const
Definition: PDBFile.h:77
const msf::MSFLayout & getMsfLayout() const
Definition: PDBFile.h:81
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48