Home | History | Annotate | Download | only in Native
      1 //===- PDBFile.h - Low level interface to a PDB file ------------*- 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_PDBFILE_H
     11 #define LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H
     12 
     13 #include "llvm/ADT/DenseMap.h"
     14 #include "llvm/DebugInfo/MSF/IMSFFile.h"
     15 #include "llvm/DebugInfo/MSF/MSFCommon.h"
     16 #include "llvm/Support/Allocator.h"
     17 #include "llvm/Support/BinaryStreamRef.h"
     18 #include "llvm/Support/Endian.h"
     19 #include "llvm/Support/Error.h"
     20 #include "llvm/Support/MathExtras.h"
     21 
     22 #include <memory>
     23 
     24 namespace llvm {
     25 
     26 class BinaryStream;
     27 
     28 namespace msf {
     29 class MappedBlockStream;
     30 }
     31 
     32 namespace pdb {
     33 class DbiStream;
     34 class GlobalsStream;
     35 class InfoStream;
     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 
     50   StringRef getFileDirectory() const;
     51   StringRef getFilePath() const;
     52 
     53   uint32_t getFreeBlockMapBlock() const;
     54   uint32_t getUnknown1() const;
     55 
     56   uint32_t getBlockSize() const override;
     57   uint32_t getBlockCount() const override;
     58   uint32_t getNumDirectoryBytes() const;
     59   uint32_t getBlockMapIndex() const;
     60   uint32_t getNumDirectoryBlocks() const;
     61   uint64_t getBlockMapOffset() const;
     62 
     63   uint32_t getNumStreams() const override;
     64   uint32_t getStreamByteSize(uint32_t StreamIndex) const override;
     65   ArrayRef<support::ulittle32_t>
     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 
     74   ArrayRef<uint32_t> getFpmPages() const { return FpmPages; }
     75 
     76   ArrayRef<support::ulittle32_t> getStreamSizes() const {
     77     return ContainerLayout.StreamSizes;
     78   }
     79   ArrayRef<ArrayRef<support::ulittle32_t>> getStreamMap() const {
     80     return ContainerLayout.StreamMap;
     81   }
     82 
     83   const msf::MSFLayout &getMsfLayout() const { return ContainerLayout; }
     84   BinaryStreamRef getMsfBuffer() const { return *Buffer; }
     85 
     86   ArrayRef<support::ulittle32_t> getDirectoryBlockArray() const;
     87 
     88   Error parseFileHeaders();
     89   Error parseStreamData();
     90 
     91   Expected<InfoStream &> getPDBInfoStream();
     92   Expected<DbiStream &> getPDBDbiStream();
     93   Expected<GlobalsStream &> getPDBGlobalsStream();
     94   Expected<TpiStream &> getPDBTpiStream();
     95   Expected<TpiStream &> getPDBIpiStream();
     96   Expected<PublicsStream &> getPDBPublicsStream();
     97   Expected<SymbolStream &> getPDBSymbolStream();
     98   Expected<PDBStringTable &> getStringTable();
     99 
    100   BumpPtrAllocator &getAllocator() { return Allocator; }
    101 
    102   bool hasPDBDbiStream() const;
    103   bool hasPDBGlobalsStream();
    104   bool hasPDBInfoStream();
    105   bool hasPDBIpiStream() const;
    106   bool hasPDBPublicsStream();
    107   bool hasPDBSymbolStream();
    108   bool hasPDBTpiStream() const;
    109   bool hasPDBStringTable();
    110 
    111   uint32_t getPointerSize();
    112 
    113 private:
    114   Expected<std::unique_ptr<msf::MappedBlockStream>>
    115   safelyCreateIndexedStream(const msf::MSFLayout &Layout,
    116                             BinaryStreamRef MsfData,
    117                             uint32_t StreamIndex) const;
    118 
    119   std::string FilePath;
    120   BumpPtrAllocator &Allocator;
    121 
    122   std::unique_ptr<BinaryStream> Buffer;
    123 
    124   std::vector<uint32_t> FpmPages;
    125   msf::MSFLayout ContainerLayout;
    126 
    127   std::unique_ptr<GlobalsStream> Globals;
    128   std::unique_ptr<InfoStream> Info;
    129   std::unique_ptr<DbiStream> Dbi;
    130   std::unique_ptr<TpiStream> Tpi;
    131   std::unique_ptr<TpiStream> Ipi;
    132   std::unique_ptr<PublicsStream> Publics;
    133   std::unique_ptr<SymbolStream> Symbols;
    134   std::unique_ptr<msf::MappedBlockStream> DirectoryStream;
    135   std::unique_ptr<msf::MappedBlockStream> StringTableStream;
    136   std::unique_ptr<PDBStringTable> Strings;
    137 };
    138 }
    139 }
    140 
    141 #endif
    142