LLVM  16.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 
14 #include "llvm/Support/Allocator.h"
16 #include "llvm/Support/Endian.h"
17 #include "llvm/Support/Error.h"
18 
19 #include <memory>
20 
21 namespace llvm {
22 
23 class BinaryStream;
24 
25 namespace msf {
26 class MappedBlockStream;
27 }
28 
29 namespace pdb {
30 class DbiStream;
31 class GlobalsStream;
32 class InfoStream;
33 class InjectedSourceStream;
34 class PDBStringTable;
35 class PDBFileBuilder;
36 class PublicsStream;
37 class SymbolStream;
38 class TpiStream;
39 
40 class PDBFile : public msf::IMSFFile {
41  friend PDBFileBuilder;
42 
43 public:
44  PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer,
45  BumpPtrAllocator &Allocator);
46  ~PDBFile() override;
47 
49  StringRef getFilePath() const;
50 
52  uint32_t getUnknown1() const;
53 
54  uint32_t getBlockSize() const override;
55  uint32_t getBlockCount() const override;
57  uint32_t getBlockMapIndex() const;
60 
61  uint32_t getNumStreams() const override;
62  uint32_t getMaxStreamSize() const;
63  uint32_t getStreamByteSize(uint32_t StreamIndex) const override;
65  getStreamBlockList(uint32_t StreamIndex) const override;
66  uint64_t getFileSize() const;
67 
69  uint32_t NumBytes) const override;
70  Error setBlockData(uint32_t BlockIndex, uint32_t Offset,
71  ArrayRef<uint8_t> Data) const override;
72 
74  return ContainerLayout.StreamSizes;
75  }
77  return ContainerLayout.StreamMap;
78  }
79 
80  const msf::MSFLayout &getMsfLayout() const { return ContainerLayout; }
81  BinaryStreamRef getMsfBuffer() const { return *Buffer; }
82 
84 
85  std::unique_ptr<msf::MappedBlockStream>
86  createIndexedStream(uint16_t SN) const;
88  safelyCreateIndexedStream(uint32_t StreamIndex) const;
91 
94 
97 
107 
109 
110  bool hasPDBDbiStream() const;
111  bool hasPDBGlobalsStream();
112  bool hasPDBInfoStream() const;
113  bool hasPDBIpiStream() const;
114  bool hasPDBPublicsStream();
115  bool hasPDBSymbolStream();
116  bool hasPDBTpiStream() const;
117  bool hasPDBStringTable();
119 
121 
122 private:
123  std::string FilePath;
125 
126  std::unique_ptr<BinaryStream> Buffer;
127 
128  msf::MSFLayout ContainerLayout;
129 
130  std::unique_ptr<GlobalsStream> Globals;
131  std::unique_ptr<InfoStream> Info;
132  std::unique_ptr<DbiStream> Dbi;
133  std::unique_ptr<TpiStream> Tpi;
134  std::unique_ptr<TpiStream> Ipi;
135  std::unique_ptr<PublicsStream> Publics;
136  std::unique_ptr<SymbolStream> Symbols;
137  std::unique_ptr<msf::MappedBlockStream> DirectoryStream;
138  std::unique_ptr<msf::MappedBlockStream> StringTableStream;
139  std::unique_ptr<InjectedSourceStream> InjectedSources;
140  std::unique_ptr<PDBStringTable> Strings;
141 };
142 }
143 }
144 
145 #endif
llvm::pdb::PDBFile::hasPDBIpiStream
bool hasPDBIpiStream() const
Definition: PDBFile.cpp:428
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::pdb::PDBFile::getFreeBlockMapBlock
uint32_t getFreeBlockMapBlock() const
Definition: PDBFile.cpp:56
llvm::pdb::PDBFile::getNumDirectoryBytes
uint32_t getNumDirectoryBytes() const
Definition: PDBFile.cpp:64
llvm::pdb::PDBFile::~PDBFile
~PDBFile() override
llvm::msf::IMSFFile
Definition: IMSFFile.h:20
llvm::pdb::PDBFile::getFilePath
StringRef getFilePath() const
Definition: PDBFile.cpp:48
Allocator.h
llvm::pdb::PDBFile::getAllocator
BumpPtrAllocator & getAllocator()
Definition: PDBFile.h:108
llvm::pdb::PDBFile::getBlockMapIndex
uint32_t getBlockMapIndex() const
Definition: PDBFile.cpp:68
Error.h
llvm::pdb::PDBFile::hasPDBSymbolStream
bool hasPDBSymbolStream()
Definition: PDBFile.cpp:448
llvm::pdb::PDBFile::hasPDBGlobalsStream
bool hasPDBGlobalsStream()
Definition: PDBFile.cpp:416
llvm::pdb::PDBFile::getStreamByteSize
uint32_t getStreamByteSize(uint32_t StreamIndex) const override
Definition: PDBFile.cpp:93
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::PDBFile::getPDBSymbolStream
Expected< SymbolStream & > getPDBSymbolStream()
Definition: PDBFile.cpp:348
llvm::pdb::PDBFile::PDBFile
PDBFile(StringRef Path, std::unique_ptr< BinaryStream > PdbFileBuffer, BumpPtrAllocator &Allocator)
Definition: PDBFile.cpp:41
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::pdb::PDBFile::getBlockCount
uint32_t getBlockCount() const override
Definition: PDBFile.cpp:60
llvm::pdb::PDBFile::getStreamSizes
ArrayRef< support::ulittle32_t > getStreamSizes() const
Definition: PDBFile.h:73
llvm::pdb::PDBFile::getFileDirectory
StringRef getFileDirectory() const
Definition: PDBFile.cpp:50
llvm::pdb::PDBFile::getPDBIpiStream
Expected< TpiStream & > getPDBIpiStream()
Definition: PDBFile.cpp:314
llvm::pdb::PDBFile::getDirectoryBlockArray
ArrayRef< support::ulittle32_t > getDirectoryBlockArray() const
Definition: PDBFile.cpp:233
llvm::pdb::PDBFile::hasPDBTpiStream
bool hasPDBTpiStream() const
Definition: PDBFile.cpp:455
llvm::pdb::PDBFile::getStreamLayout
msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const
Definition: PDBFile.cpp:245
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::PDBFile::hasPDBStringTable
bool hasPDBStringTable()
Definition: PDBFile.cpp:457
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:488
llvm::pdb::PDBFile::getPDBDbiStream
Expected< DbiStream & > getPDBDbiStream()
Definition: PDBFile.cpp:288
llvm::pdb::PDBFile::getStreamMap
ArrayRef< ArrayRef< support::ulittle32_t > > getStreamMap() const
Definition: PDBFile.h:76
llvm::pdb::PDB_ColorItem::Path
@ Path
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:84
IMSFFile.h
llvm::pdb::PDBFile::safelyCreateNamedStream
Expected< std::unique_ptr< msf::MappedBlockStream > > safelyCreateNamedStream(StringRef Name)
Definition: PDBFile.cpp:496
uint64_t
llvm::pdb::PDBFile::getFpmStreamLayout
msf::MSFStreamLayout getFpmStreamLayout() const
Definition: PDBFile.cpp:253
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::pdb::PDBFile::getFileSize
uint64_t getFileSize() const
Definition: PDBFile.cpp:102
llvm::pdb::PDBFile::getBlockSize
uint32_t getBlockSize() const override
Definition: PDBFile.cpp:54
llvm::pdb::PDBFile::setBlockData
Error setBlockData(uint32_t BlockIndex, uint32_t Offset, ArrayRef< uint8_t > Data) const override
Definition: PDBFile.cpp:114
llvm::pdb::PDBFile::getInjectedSourceStream
Expected< InjectedSourceStream & > getInjectedSourceStream()
Definition: PDBFile.cpp:384
llvm::pdb::PDBFile::getPDBInfoStream
Expected< InfoStream & > getPDBInfoStream()
Definition: PDBFile.cpp:275
llvm::pdb::PDBFile::getMsfBuffer
BinaryStreamRef getMsfBuffer() const
Definition: PDBFile.h:81
llvm::pdb::PDBFile::hasPDBDbiStream
bool hasPDBDbiStream() const
Definition: PDBFile.cpp:412
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:50
llvm::pdb::PDBFile::hasPDBInjectedSourceStream
bool hasPDBInjectedSourceStream()
Definition: PDBFile.cpp:470
BinaryStreamRef.h
llvm::pdb::PDBFile::getStringTable
Expected< PDBStringTable & > getStringTable()
Definition: PDBFile.cpp:367
uint32_t
llvm::pdb::PDBFile::parseStreamData
Error parseStreamData()
Definition: PDBFile.cpp:180
llvm::pdb::PDBFile::getUnknown1
uint32_t getUnknown1() const
Definition: PDBFile.cpp:72
MSFCommon.h
llvm::pdb::PDBFile::getStreamBlockList
ArrayRef< support::ulittle32_t > getStreamBlockList(uint32_t StreamIndex) const override
Definition: PDBFile.cpp:98
llvm::pdb::PDBFile::getPDBTpiStream
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:301
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
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:104
llvm::pdb::PDBFile::getMaxStreamSize
uint32_t getMaxStreamSize() const
Definition: PDBFile.cpp:88
llvm::pdb::PDBFile::parseFileHeaders
Error parseFileHeaders()
Definition: PDBFile.cpp:120
llvm::pdb::PDBFile::getMsfLayout
const msf::MSFLayout & getMsfLayout() const
Definition: PDBFile.h:80
llvm::pdb::PDBFile::hasPDBPublicsStream
bool hasPDBPublicsStream()
Definition: PDBFile.cpp:439
llvm::pdb::PDBFile::getPDBPublicsStream
Expected< PublicsStream & > getPDBPublicsStream()
Definition: PDBFile.cpp:330
llvm::pdb::PDBFile
Definition: PDBFile.h:40
llvm::pdb::PDBFile::getPointerSize
uint32_t getPointerSize()
Definition: PDBFile.cpp:402
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
llvm::pdb::PDBFileBuilder
Definition: PDBFileBuilder.h:39
llvm::pdb::PDBFile::hasPDBInfoStream
bool hasPDBInfoStream() const
Definition: PDBFile.cpp:426
llvm::pdb::PDBFile::createIndexedStream
std::unique_ptr< msf::MappedBlockStream > createIndexedStream(uint16_t SN) const
Definition: PDBFile.cpp:238
llvm::pdb::PDBFile::getNumDirectoryBlocks
uint32_t getNumDirectoryBlocks() const
Definition: PDBFile.cpp:74
Endian.h
llvm::pdb::PDBFile::getPDBGlobalsStream
Expected< GlobalsStream & > getPDBGlobalsStream()
Definition: PDBFile.cpp:257
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:155
llvm::pdb::PDBFile::getBlockMapOffset
uint64_t getBlockMapOffset() const
Definition: PDBFile.cpp:79
llvm::msf::MSFStreamLayout
Describes the layout of a stream in an MSF layout.
Definition: MSFCommon.h:77