LLVM  8.0.1
GlobalsStream.h
Go to the documentation of this file.
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/ADT/iterator.h"
20 #include "llvm/Support/Error.h"
21 
22 namespace llvm {
23 namespace pdb {
24 class DbiStream;
25 class PDBFile;
26 class SymbolStream;
27 
28 /// Iterator over hash records producing symbol record offsets. Abstracts away
29 /// the fact that symbol record offsets on disk are off-by-one.
31  : public iterator_adaptor_base<
32  GSIHashIterator, FixedStreamArrayIterator<PSHashRecord>,
33  std::random_access_iterator_tag, const uint32_t> {
34 public:
35  template <typename T>
37  : GSIHashIterator::iterator_adaptor_base(std::forward<T &&>(v)) {}
38 
39  uint32_t operator*() const {
40  uint32_t Off = this->I->Off;
41  return --Off;
42  }
43 };
44 
45 /// From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp
46 enum : unsigned { IPHR_HASH = 4096 };
47 
48 /// A readonly view of a hash table used in the globals and publics streams.
49 /// Most clients will only want to iterate this to get symbol record offsets
50 /// into the PDB symbol stream.
51 class GSIHashTable {
52 public:
57  std::array<int32_t, IPHR_HASH + 1> BucketMap;
58 
59  Error read(BinaryStreamReader &Reader);
60 
61  uint32_t getVerSignature() const { return HashHdr->VerSignature; }
62  uint32_t getVerHeader() const { return HashHdr->VerHdr; }
63  uint32_t getHashRecordSize() const { return HashHdr->HrSize; }
64  uint32_t getNumBuckets() const { return HashHdr->NumBuckets; }
65 
67  GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); }
68  GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); }
69 };
70 
72 public:
73  explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream);
74  ~GlobalsStream();
75  const GSIHashTable &getGlobalsTable() const { return GlobalsTable; }
76  Error reload();
77 
78  std::vector<std::pair<uint32_t, codeview::CVSymbol>>
79  findRecordsByName(StringRef Name, const SymbolStream &Symbols) const;
80 
81 private:
82  GSIHashTable GlobalsTable;
83  std::unique_ptr<msf::MappedBlockStream> Stream;
84 };
85 }
86 }
87 
88 #endif
A readonly view of a hash table used in the globals and publics streams.
Definition: GlobalsStream.h:51
FixedStreamArray< support::ulittle32_t > HashBitmap
Definition: GlobalsStream.h:55
support::ulittle32_t VerSignature
Definition: RawTypes.h:34
This class represents lattice values for constants.
Definition: AllocatorList.h:24
support::ulittle32_t VerHdr
Definition: RawTypes.h:35
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
uint32_t getVerSignature() const
Definition: GlobalsStream.h:61
Header of the hash tables found in the globals and publics sections.
Definition: RawTypes.h:29
uint32_t getHashRecordSize() const
Definition: GlobalsStream.h:63
GSIHashIterator begin() const
Definition: GlobalsStream.h:67
const GSIHashHeader * HashHdr
Definition: GlobalsStream.h:53
support::ulittle32_t NumBuckets
Definition: RawTypes.h:37
std::array< int32_t, IPHR_HASH+1 > BucketMap
Definition: GlobalsStream.h:57
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:206
uint32_t getVerHeader() const
Definition: GlobalsStream.h:62
GSIHashIterator end() const
Definition: GlobalsStream.h:68
GSIHashHeader iterator
Definition: GlobalsStream.h:66
FixedStreamArray< support::ulittle32_t > HashBuckets
Definition: GlobalsStream.h:56
uint32_t operator*() const
Definition: GlobalsStream.h:39
uint32_t getNumBuckets() const
Definition: GlobalsStream.h:64
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:66
const GSIHashTable & getGlobalsTable() const
Definition: GlobalsStream.h:75
FixedStreamArrayIterator< T > end() const
FixedStreamArray< PSHashRecord > HashRecords
Definition: GlobalsStream.h:54
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
support::ulittle32_t HrSize
Definition: RawTypes.h:36
FixedStreamArrayIterator< T > begin() const
Iterator over hash records producing symbol record offsets.
Definition: GlobalsStream.h:30