Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:44

0001 //===- GlobalsStream.h - PDB Index of Symbols by Name -----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_GLOBALSSTREAM_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_GLOBALSSTREAM_H
0011 
0012 #include "llvm/ADT/iterator.h"
0013 #include "llvm/DebugInfo/CodeView/CVRecord.h"
0014 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
0015 #include "llvm/Support/BinaryStreamArray.h"
0016 #include "llvm/Support/Endian.h"
0017 #include "llvm/Support/Error.h"
0018 
0019 namespace llvm {
0020 class BinaryStreamReader;
0021 namespace msf {
0022 class MappedBlockStream;
0023 }
0024 namespace pdb {
0025 class SymbolStream;
0026 
0027 /// Iterator over hash records producing symbol record offsets. Abstracts away
0028 /// the fact that symbol record offsets on disk are off-by-one.
0029 class GSIHashIterator
0030     : public iterator_adaptor_base<
0031           GSIHashIterator, FixedStreamArrayIterator<PSHashRecord>,
0032           std::random_access_iterator_tag, const uint32_t> {
0033 public:
0034   template <typename T>
0035   GSIHashIterator(T &&v)
0036       : GSIHashIterator::iterator_adaptor_base(std::forward<T &&>(v)) {}
0037 
0038   uint32_t operator*() const {
0039     uint32_t Off = this->I->Off;
0040     return --Off;
0041   }
0042 };
0043 
0044 /// From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp
0045 enum : unsigned { IPHR_HASH = 4096 };
0046 
0047 /// A readonly view of a hash table used in the globals and publics streams.
0048 /// Most clients will only want to iterate this to get symbol record offsets
0049 /// into the PDB symbol stream.
0050 class GSIHashTable {
0051 public:
0052   const GSIHashHeader *HashHdr;
0053   FixedStreamArray<PSHashRecord> HashRecords;
0054   FixedStreamArray<support::ulittle32_t> HashBitmap;
0055   FixedStreamArray<support::ulittle32_t> HashBuckets;
0056   std::array<int32_t, IPHR_HASH + 1> BucketMap;
0057 
0058   Error read(BinaryStreamReader &Reader);
0059 
0060   uint32_t getVerSignature() const { return HashHdr->VerSignature; }
0061   uint32_t getVerHeader() const { return HashHdr->VerHdr; }
0062   uint32_t getHashRecordSize() const { return HashHdr->HrSize; }
0063   uint32_t getNumBuckets() const { return HashHdr->NumBuckets; }
0064 
0065   typedef GSIHashHeader iterator;
0066   GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); }
0067   GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); }
0068 };
0069 
0070 class GlobalsStream {
0071 public:
0072   explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream);
0073   ~GlobalsStream();
0074   const GSIHashTable &getGlobalsTable() const { return GlobalsTable; }
0075   Error reload();
0076 
0077   std::vector<std::pair<uint32_t, codeview::CVSymbol>>
0078   findRecordsByName(StringRef Name, const SymbolStream &Symbols) const;
0079 
0080 private:
0081   GSIHashTable GlobalsTable;
0082   std::unique_ptr<msf::MappedBlockStream> Stream;
0083 };
0084 } // namespace pdb
0085 }
0086 
0087 #endif