1 //===- GlobalsStream.h - PDB Index of Symbols by Name -----------*- 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_GLOBALS_STREAM_H 11 #define LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_H 12 13 #include "llvm/DebugInfo/MSF/MappedBlockStream.h" 14 #include "llvm/DebugInfo/PDB/Native/RawConstants.h" 15 #include "llvm/DebugInfo/PDB/Native/RawTypes.h" 16 #include "llvm/DebugInfo/PDB/PDBTypes.h" 17 #include "llvm/Support/BinaryStreamArray.h" 18 #include "llvm/Support/Error.h" 19 #include "llvm/ADT/iterator.h" 20 21 namespace llvm { 22 namespace pdb { 23 class DbiStream; 24 class PDBFile; 25 26 /// Iterator over hash records producing symbol record offsets. Abstracts away 27 /// the fact that symbol record offsets on disk are off-by-one. 28 class GSIHashIterator 29 : public iterator_adaptor_base< 30 GSIHashIterator, FixedStreamArrayIterator<PSHashRecord>, 31 std::random_access_iterator_tag, const uint32_t> { 32 public: 33 template <typename T> GSIHashIterator(T && v)34 GSIHashIterator(T &&v) 35 : GSIHashIterator::iterator_adaptor_base(std::forward<T &&>(v)) {} 36 37 uint32_t operator*() const { 38 uint32_t Off = this->I->Off; 39 return --Off; 40 } 41 }; 42 43 /// From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp 44 enum : unsigned { IPHR_HASH = 4096 }; 45 46 /// A readonly view of a hash table used in the globals and publics streams. 47 /// Most clients will only want to iterate this to get symbol record offsets 48 /// into the PDB symbol stream. 49 class GSIHashTable { 50 public: 51 const GSIHashHeader *HashHdr; 52 FixedStreamArray<PSHashRecord> HashRecords; 53 ArrayRef<uint8_t> HashBitmap; 54 FixedStreamArray<support::ulittle32_t> HashBuckets; 55 56 Error read(BinaryStreamReader &Reader); 57 getVerSignature()58 uint32_t getVerSignature() const { return HashHdr->VerSignature; } getVerHeader()59 uint32_t getVerHeader() const { return HashHdr->VerHdr; } getHashRecordSize()60 uint32_t getHashRecordSize() const { return HashHdr->HrSize; } getNumBuckets()61 uint32_t getNumBuckets() const { return HashHdr->NumBuckets; } 62 63 typedef GSIHashHeader iterator; begin()64 GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); } end()65 GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); } 66 }; 67 68 class GlobalsStream { 69 public: 70 explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream); 71 ~GlobalsStream(); getGlobalsTable()72 const GSIHashTable &getGlobalsTable() const { return GlobalsTable; } 73 Error reload(); 74 75 private: 76 GSIHashTable GlobalsTable; 77 std::unique_ptr<msf::MappedBlockStream> Stream; 78 }; 79 } 80 } 81 82 #endif 83