Home | History | Annotate | Download | only in Raw
      1 //===- DbiStream.h - PDB Dbi Stream (Stream 3) Access -----------*- 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_PDBDBISTREAM_H
     11 #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H
     12 
     13 #include "llvm/DebugInfo/CodeView/ModuleSubstream.h"
     14 #include "llvm/DebugInfo/CodeView/StreamArray.h"
     15 #include "llvm/DebugInfo/CodeView/StreamRef.h"
     16 #include "llvm/DebugInfo/PDB/PDBTypes.h"
     17 #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
     18 #include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
     19 #include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
     20 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
     21 #include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
     22 #include "llvm/Support/Endian.h"
     23 #include "llvm/Support/Error.h"
     24 
     25 namespace llvm {
     26 namespace object {
     27 struct FpoData;
     28 struct coff_section;
     29 }
     30 
     31 namespace pdb {
     32 class DbiStreamBuilder;
     33 class PDBFile;
     34 class ISectionContribVisitor;
     35 
     36 class DbiStream {
     37   friend class DbiStreamBuilder;
     38 
     39   struct HeaderInfo {
     40     support::little32_t VersionSignature;
     41     support::ulittle32_t VersionHeader;
     42     support::ulittle32_t Age;                     // Should match InfoStream.
     43     support::ulittle16_t GlobalSymbolStreamIndex; // Global symbol stream #
     44     support::ulittle16_t BuildNumber;             // See DbiBuildNo structure.
     45     support::ulittle16_t PublicSymbolStreamIndex; // Public symbols stream #
     46     support::ulittle16_t PdbDllVersion;           // version of mspdbNNN.dll
     47     support::ulittle16_t SymRecordStreamIndex;    // Symbol records stream #
     48     support::ulittle16_t PdbDllRbld;              // rbld number of mspdbNNN.dll
     49     support::little32_t ModiSubstreamSize;        // Size of module info stream
     50     support::little32_t SecContrSubstreamSize;    // Size of sec. contrib stream
     51     support::little32_t SectionMapSize;           // Size of sec. map substream
     52     support::little32_t FileInfoSize;             // Size of file info substream
     53     support::little32_t TypeServerSize;           // Size of type server map
     54     support::ulittle32_t MFCTypeServerIndex;      // Index of MFC Type Server
     55     support::little32_t OptionalDbgHdrSize;       // Size of DbgHeader info
     56     support::little32_t ECSubstreamSize; // Size of EC stream (what is EC?)
     57     support::ulittle16_t Flags;          // See DbiFlags enum.
     58     support::ulittle16_t MachineType;    // See PDB_MachineType enum.
     59 
     60     support::ulittle32_t Reserved; // Pad to 64 bytes
     61   };
     62 
     63 public:
     64   DbiStream(PDBFile &File, std::unique_ptr<MappedBlockStream> Stream);
     65   ~DbiStream();
     66   Error reload();
     67 
     68   PdbRaw_DbiVer getDbiVersion() const;
     69   uint32_t getAge() const;
     70   uint16_t getPublicSymbolStreamIndex() const;
     71   uint16_t getGlobalSymbolStreamIndex() const;
     72 
     73   uint16_t getFlags() const;
     74   bool isIncrementallyLinked() const;
     75   bool hasCTypes() const;
     76   bool isStripped() const;
     77 
     78   uint16_t getBuildNumber() const;
     79   uint16_t getBuildMajorVersion() const;
     80   uint16_t getBuildMinorVersion() const;
     81 
     82   uint16_t getPdbDllRbld() const;
     83   uint32_t getPdbDllVersion() const;
     84 
     85   uint32_t getSymRecordStreamIndex() const;
     86 
     87   PDB_Machine getMachineType() const;
     88 
     89   enum { InvalidStreamIndex = 0xffff };
     90 
     91   /// If the given stream type is present, returns its stream index. If it is
     92   /// not present, returns InvalidStreamIndex.
     93   uint32_t getDebugStreamIndex(DbgHeaderType Type) const;
     94 
     95   ArrayRef<ModuleInfoEx> modules() const;
     96 
     97   Expected<StringRef> getFileNameForIndex(uint32_t Index) const;
     98 
     99   codeview::FixedStreamArray<object::coff_section> getSectionHeaders();
    100 
    101   codeview::FixedStreamArray<object::FpoData> getFpoRecords();
    102 
    103   codeview::FixedStreamArray<SecMapEntry> getSectionMap() const;
    104   void visitSectionContributions(ISectionContribVisitor &Visitor) const;
    105 
    106   Error commit();
    107 
    108 private:
    109   Error initializeSectionContributionData();
    110   Error initializeSectionHeadersData();
    111   Error initializeSectionMapData();
    112   Error initializeFileInfo();
    113   Error initializeFpoRecords();
    114 
    115   PDBFile &Pdb;
    116   std::unique_ptr<MappedBlockStream> Stream;
    117 
    118   std::vector<ModuleInfoEx> ModuleInfos;
    119   NameHashTable ECNames;
    120 
    121   codeview::StreamRef ModInfoSubstream;
    122   codeview::StreamRef SecContrSubstream;
    123   codeview::StreamRef SecMapSubstream;
    124   codeview::StreamRef FileInfoSubstream;
    125   codeview::StreamRef TypeServerMapSubstream;
    126   codeview::StreamRef ECSubstream;
    127 
    128   codeview::StreamRef NamesBuffer;
    129 
    130   codeview::FixedStreamArray<support::ulittle16_t> DbgStreams;
    131 
    132   PdbRaw_DbiSecContribVer SectionContribVersion;
    133   codeview::FixedStreamArray<SectionContrib> SectionContribs;
    134   codeview::FixedStreamArray<SectionContrib2> SectionContribs2;
    135   codeview::FixedStreamArray<SecMapEntry> SectionMap;
    136   codeview::FixedStreamArray<support::little32_t> FileNameOffsets;
    137 
    138   std::unique_ptr<MappedBlockStream> SectionHeaderStream;
    139   codeview::FixedStreamArray<object::coff_section> SectionHeaders;
    140 
    141   std::unique_ptr<MappedBlockStream> FpoStream;
    142   codeview::FixedStreamArray<object::FpoData> FpoRecords;
    143 
    144   const HeaderInfo *Header;
    145 };
    146 }
    147 }
    148 
    149 #endif
    150