GlobalsStream.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- GlobalsStream.h - PDB Index of Symbols by Name -----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_PDB_NATIVE_GLOBALSSTREAM_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_GLOBALSSTREAM_H
  15. #include "llvm/ADT/iterator.h"
  16. #include "llvm/DebugInfo/CodeView/CVRecord.h"
  17. #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
  18. #include "llvm/Support/BinaryStreamArray.h"
  19. #include "llvm/Support/Endian.h"
  20. #include "llvm/Support/Error.h"
  21. namespace llvm {
  22. class BinaryStreamReader;
  23. namespace msf {
  24. class MappedBlockStream;
  25. }
  26. namespace pdb {
  27. class SymbolStream;
  28. /// Iterator over hash records producing symbol record offsets. Abstracts away
  29. /// the fact that symbol record offsets on disk are off-by-one.
  30. class GSIHashIterator
  31. : public iterator_adaptor_base<
  32. GSIHashIterator, FixedStreamArrayIterator<PSHashRecord>,
  33. std::random_access_iterator_tag, const uint32_t> {
  34. public:
  35. template <typename T>
  36. GSIHashIterator(T &&v)
  37. : GSIHashIterator::iterator_adaptor_base(std::forward<T &&>(v)) {}
  38. uint32_t operator*() const {
  39. uint32_t Off = this->I->Off;
  40. return --Off;
  41. }
  42. };
  43. /// From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp
  44. enum : unsigned { IPHR_HASH = 4096 };
  45. /// A readonly view of a hash table used in the globals and publics streams.
  46. /// Most clients will only want to iterate this to get symbol record offsets
  47. /// into the PDB symbol stream.
  48. class GSIHashTable {
  49. public:
  50. const GSIHashHeader *HashHdr;
  51. FixedStreamArray<PSHashRecord> HashRecords;
  52. FixedStreamArray<support::ulittle32_t> HashBitmap;
  53. FixedStreamArray<support::ulittle32_t> HashBuckets;
  54. std::array<int32_t, IPHR_HASH + 1> BucketMap;
  55. Error read(BinaryStreamReader &Reader);
  56. uint32_t getVerSignature() const { return HashHdr->VerSignature; }
  57. uint32_t getVerHeader() const { return HashHdr->VerHdr; }
  58. uint32_t getHashRecordSize() const { return HashHdr->HrSize; }
  59. uint32_t getNumBuckets() const { return HashHdr->NumBuckets; }
  60. typedef GSIHashHeader iterator;
  61. GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); }
  62. GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); }
  63. };
  64. class GlobalsStream {
  65. public:
  66. explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream);
  67. ~GlobalsStream();
  68. const GSIHashTable &getGlobalsTable() const { return GlobalsTable; }
  69. Error reload();
  70. std::vector<std::pair<uint32_t, codeview::CVSymbol>>
  71. findRecordsByName(StringRef Name, const SymbolStream &Symbols) const;
  72. private:
  73. GSIHashTable GlobalsTable;
  74. std::unique_ptr<msf::MappedBlockStream> Stream;
  75. };
  76. } // namespace pdb
  77. }
  78. #endif
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif