LLVM  14.0.0git
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_NATIVE_PDBFILE_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_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 InjectedSourceStream;
36 class PDBStringTable;
37 class PDBFileBuilder;
38 class PublicsStream;
39 class SymbolStream;
40 class TpiStream;
41 
42 class PDBFile : public msf::IMSFFile {
43  friend PDBFileBuilder;
44 
45 public:
46  PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer,
47  BumpPtrAllocator &Allocator);
48  ~PDBFile() override;
49 
51  StringRef getFilePath() const;
52 
54  uint32_t getUnknown1() const;
55 
56  uint32_t getBlockSize() const override;
57  uint32_t getBlockCount() const override;
59  uint32_t getBlockMapIndex() const;
62 
63  uint32_t getNumStreams() const override;
64  uint32_t getMaxStreamSize() const;
65  uint32_t getStreamByteSize(uint32_t StreamIndex) const override;
67  getStreamBlockList(uint32_t StreamIndex) const override;
68  uint32_t getFileSize() const;
69 
71  uint32_t NumBytes) const override;
73  ArrayRef<uint8_t> Data) const override;
74 
76  return ContainerLayout.StreamSizes;
77  }
79  return ContainerLayout.StreamMap;
80  }
81 
82  const msf::MSFLayout &getMsfLayout() const { return ContainerLayout; }
83  BinaryStreamRef getMsfBuffer() const { return *Buffer; }
84 
86 
87  std::unique_ptr<msf::MappedBlockStream>
88  createIndexedStream(uint16_t SN) const;
90  safelyCreateIndexedStream(uint32_t StreamIndex) const;
93 
96 
99 
109 
111 
112  bool hasPDBDbiStream() const;
113  bool hasPDBGlobalsStream();
114  bool hasPDBInfoStream() const;
115  bool hasPDBIpiStream() const;
116  bool hasPDBPublicsStream();
117  bool hasPDBSymbolStream();
118  bool hasPDBTpiStream() const;
119  bool hasPDBStringTable();
121 
123 
124 private:
125  std::string FilePath;
127 
128  std::unique_ptr<BinaryStream> Buffer;
129 
130  msf::MSFLayout ContainerLayout;
131 
132  std::unique_ptr<GlobalsStream> Globals;
133  std::unique_ptr<InfoStream> Info;
134  std::unique_ptr<DbiStream> Dbi;
135  std::unique_ptr<TpiStream> Tpi;
136  std::unique_ptr<TpiStream> Ipi;
137  std::unique_ptr<PublicsStream> Publics;
138  std::unique_ptr<SymbolStream> Symbols;
139  std::unique_ptr<msf::MappedBlockStream> DirectoryStream;
140  std::unique_ptr<msf::MappedBlockStream> StringTableStream;
141  std::unique_ptr<InjectedSourceStream> InjectedSources;
142  std::unique_ptr<PDBStringTable> Strings;
143 };
144 }
145 }
146 
147 #endif
llvm::pdb::PDBFile::hasPDBIpiStream
bool hasPDBIpiStream() const
Definition: PDBFile.cpp:429
MathExtras.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::pdb::PDBFile::getFileSize
uint32_t getFileSize() const
Definition: PDBFile.cpp:103
llvm::pdb::PDBFile::getFreeBlockMapBlock
uint32_t getFreeBlockMapBlock() const
Definition: PDBFile.cpp:57
llvm::pdb::PDBFile::getNumDirectoryBytes
uint32_t getNumDirectoryBytes() const
Definition: PDBFile.cpp:65
llvm::pdb::PDBFile::~PDBFile
~PDBFile() override
llvm::msf::IMSFFile
Definition: IMSFFile.h:20
llvm::pdb::PDBFile::getFilePath
StringRef getFilePath() const
Definition: PDBFile.cpp:49
Allocator.h
llvm::pdb::PDBFile::getAllocator
BumpPtrAllocator & getAllocator()
Definition: PDBFile.h:110
llvm::pdb::PDBFile::getBlockMapIndex
uint32_t getBlockMapIndex() const
Definition: PDBFile.cpp:69
Error.h
DenseMap.h
llvm::pdb::PDBFile::hasPDBSymbolStream
bool hasPDBSymbolStream()
Definition: PDBFile.cpp:449
llvm::pdb::PDBFile::hasPDBGlobalsStream
bool hasPDBGlobalsStream()
Definition: PDBFile.cpp:417
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::pdb::PDBFile::getStreamByteSize
uint32_t getStreamByteSize(uint32_t StreamIndex) const override
Definition: PDBFile.cpp:94
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::PDBFile::getPDBSymbolStream
Expected< SymbolStream & > getPDBSymbolStream()
Definition: PDBFile.cpp:349
llvm::pdb::PDBFile::PDBFile
PDBFile(StringRef Path, std::unique_ptr< BinaryStream > PdbFileBuffer, BumpPtrAllocator &Allocator)
Definition: PDBFile.cpp:42
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::pdb::PDBFile::getBlockCount
uint32_t getBlockCount() const override
Definition: PDBFile.cpp:61
llvm::pdb::PDBFile::getStreamSizes
ArrayRef< support::ulittle32_t > getStreamSizes() const
Definition: PDBFile.h:75
llvm::pdb::PDBFile::getFileDirectory
StringRef getFileDirectory() const
Definition: PDBFile.cpp:51
llvm::pdb::PDBFile::getPDBIpiStream
Expected< TpiStream & > getPDBIpiStream()
Definition: PDBFile.cpp:315
llvm::pdb::PDBFile::getDirectoryBlockArray
ArrayRef< support::ulittle32_t > getDirectoryBlockArray() const
Definition: PDBFile.cpp:234
llvm::pdb::PDBFile::hasPDBTpiStream
bool hasPDBTpiStream() const
Definition: PDBFile.cpp:456
llvm::pdb::PDBFile::getStreamLayout
msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const
Definition: PDBFile.cpp:246
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::PDBFile::hasPDBStringTable
bool hasPDBStringTable()
Definition: PDBFile.cpp:458
llvm::pdb::PDBFile::safelyCreateIndexedStream
Expected< std::unique_ptr< msf::MappedBlockStream > > safelyCreateIndexedStream(uint32_t StreamIndex) const
Wrapper around MappedBlockStream::createIndexedStream() that checks if a stream with that index actua...
Definition: PDBFile.cpp:489
llvm::pdb::PDBFile::getPDBDbiStream
Expected< DbiStream & > getPDBDbiStream()
Definition: PDBFile.cpp:289
llvm::pdb::PDBFile::getStreamMap
ArrayRef< ArrayRef< support::ulittle32_t > > getStreamMap() const
Definition: PDBFile.h:78
llvm::msf::MSFLayout::StreamSizes
ArrayRef< support::ulittle32_t > StreamSizes
Definition: MSFCommon.h:67
llvm::pdb::PDBFile::getNumStreams
uint32_t getNumStreams() const override
Definition: PDBFile.cpp:85
IMSFFile.h
llvm::pdb::PDBFile::safelyCreateNamedStream
Expected< std::unique_ptr< msf::MappedBlockStream > > safelyCreateNamedStream(StringRef Name)
Definition: PDBFile.cpp:497
uint64_t
llvm::pdb::PDBFile::getFpmStreamLayout
msf::MSFStreamLayout getFpmStreamLayout() const
Definition: PDBFile.cpp:254
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::pdb::PDBFile::getBlockSize
uint32_t getBlockSize() const override
Definition: PDBFile.cpp:55
llvm::pdb::PDBFile::setBlockData
Error setBlockData(uint32_t BlockIndex, uint32_t Offset, ArrayRef< uint8_t > Data) const override
Definition: PDBFile.cpp:115
llvm::pdb::PDBFile::getInjectedSourceStream
Expected< InjectedSourceStream & > getInjectedSourceStream()
Definition: PDBFile.cpp:385
llvm::pdb::PDBFile::getPDBInfoStream
Expected< InfoStream & > getPDBInfoStream()
Definition: PDBFile.cpp:276
llvm::pdb::PDBFile::getMsfBuffer
BinaryStreamRef getMsfBuffer() const
Definition: PDBFile.h:83
llvm::pdb::PDBFile::hasPDBDbiStream
bool hasPDBDbiStream() const
Definition: PDBFile.cpp:413
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::pdb::PDBFile::hasPDBInjectedSourceStream
bool hasPDBInjectedSourceStream()
Definition: PDBFile.cpp:471
BinaryStreamRef.h
llvm::pdb::PDBFile::getStringTable
Expected< PDBStringTable & > getStringTable()
Definition: PDBFile.cpp:368
uint32_t
llvm::pdb::PDBFile::parseStreamData
Error parseStreamData()
Definition: PDBFile.cpp:181
llvm::pdb::PDBFile::getUnknown1
uint32_t getUnknown1() const
Definition: PDBFile.cpp:73
MSFCommon.h
llvm::pdb::PDBFile::getStreamBlockList
ArrayRef< support::ulittle32_t > getStreamBlockList(uint32_t StreamIndex) const override
Definition: PDBFile.cpp:99
llvm::pdb::PDBFile::getPDBTpiStream
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:302
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::msf::MSFLayout::StreamMap
std::vector< ArrayRef< support::ulittle32_t > > StreamMap
Definition: MSFCommon.h:68
llvm::pdb::PDBFile::getBlockData
Expected< ArrayRef< uint8_t > > getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const override
Definition: PDBFile.cpp:105
llvm::pdb::PDBFile::getMaxStreamSize
uint32_t getMaxStreamSize() const
Definition: PDBFile.cpp:89
llvm::pdb::PDBFile::parseFileHeaders
Error parseFileHeaders()
Definition: PDBFile.cpp:121
llvm::pdb::PDBFile::getMsfLayout
const msf::MSFLayout & getMsfLayout() const
Definition: PDBFile.h:82
llvm::pdb::PDBFile::hasPDBPublicsStream
bool hasPDBPublicsStream()
Definition: PDBFile.cpp:440
llvm::pdb::PDBFile::getPDBPublicsStream
Expected< PublicsStream & > getPDBPublicsStream()
Definition: PDBFile.cpp:331
llvm::pdb::PDBFile
Definition: PDBFile.h:42
llvm::pdb::PDBFile::getPointerSize
uint32_t getPointerSize()
Definition: PDBFile.cpp:403
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
llvm::pdb::PDBFileBuilder
Definition: PDBFileBuilder.h:35
llvm::pdb::PDBFile::hasPDBInfoStream
bool hasPDBInfoStream() const
Definition: PDBFile.cpp:427
llvm::pdb::PDBFile::createIndexedStream
std::unique_ptr< msf::MappedBlockStream > createIndexedStream(uint16_t SN) const
Definition: PDBFile.cpp:239
llvm::pdb::PDBFile::getNumDirectoryBlocks
uint32_t getNumDirectoryBlocks() const
Definition: PDBFile.cpp:75
Endian.h
llvm::pdb::PDBFile::getPDBGlobalsStream
Expected< GlobalsStream & > getPDBGlobalsStream()
Definition: PDBFile.cpp:258
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156
llvm::pdb::PDBFile::getBlockMapOffset
uint64_t getBlockMapOffset() const
Definition: PDBFile.cpp:80
llvm::msf::MSFStreamLayout
Describes the layout of a stream in an MSF layout.
Definition: MSFCommon.h:77