PDBFile.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- PDBFile.h - Low level interface to a PDB file ------------*- 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_PDBFILE_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_PDBFILE_H
  15. #include "llvm/DebugInfo/MSF/IMSFFile.h"
  16. #include "llvm/DebugInfo/MSF/MSFCommon.h"
  17. #include "llvm/Support/Allocator.h"
  18. #include "llvm/Support/BinaryStreamRef.h"
  19. #include "llvm/Support/Endian.h"
  20. #include "llvm/Support/Error.h"
  21. #include <memory>
  22. namespace llvm {
  23. class BinaryStream;
  24. namespace msf {
  25. class MappedBlockStream;
  26. }
  27. namespace pdb {
  28. class DbiStream;
  29. class GlobalsStream;
  30. class InfoStream;
  31. class InjectedSourceStream;
  32. class PDBStringTable;
  33. class PDBFileBuilder;
  34. class PublicsStream;
  35. class SymbolStream;
  36. class TpiStream;
  37. class PDBFile : public msf::IMSFFile {
  38. friend PDBFileBuilder;
  39. public:
  40. PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer,
  41. BumpPtrAllocator &Allocator);
  42. ~PDBFile() override;
  43. StringRef getFileDirectory() const;
  44. StringRef getFilePath() const;
  45. uint32_t getFreeBlockMapBlock() const;
  46. uint32_t getUnknown1() const;
  47. uint32_t getBlockSize() const override;
  48. uint32_t getBlockCount() const override;
  49. uint32_t getNumDirectoryBytes() const;
  50. uint32_t getBlockMapIndex() const;
  51. uint32_t getNumDirectoryBlocks() const;
  52. uint64_t getBlockMapOffset() const;
  53. uint32_t getNumStreams() const override;
  54. uint32_t getMaxStreamSize() const;
  55. uint32_t getStreamByteSize(uint32_t StreamIndex) const override;
  56. ArrayRef<support::ulittle32_t>
  57. getStreamBlockList(uint32_t StreamIndex) const override;
  58. uint64_t getFileSize() const;
  59. Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex,
  60. uint32_t NumBytes) const override;
  61. Error setBlockData(uint32_t BlockIndex, uint32_t Offset,
  62. ArrayRef<uint8_t> Data) const override;
  63. ArrayRef<support::ulittle32_t> getStreamSizes() const {
  64. return ContainerLayout.StreamSizes;
  65. }
  66. ArrayRef<ArrayRef<support::ulittle32_t>> getStreamMap() const {
  67. return ContainerLayout.StreamMap;
  68. }
  69. const msf::MSFLayout &getMsfLayout() const { return ContainerLayout; }
  70. BinaryStreamRef getMsfBuffer() const { return *Buffer; }
  71. ArrayRef<support::ulittle32_t> getDirectoryBlockArray() const;
  72. std::unique_ptr<msf::MappedBlockStream>
  73. createIndexedStream(uint16_t SN) const;
  74. Expected<std::unique_ptr<msf::MappedBlockStream>>
  75. safelyCreateIndexedStream(uint32_t StreamIndex) const;
  76. Expected<std::unique_ptr<msf::MappedBlockStream>>
  77. safelyCreateNamedStream(StringRef Name);
  78. msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const;
  79. msf::MSFStreamLayout getFpmStreamLayout() const;
  80. Error parseFileHeaders();
  81. Error parseStreamData();
  82. Expected<InfoStream &> getPDBInfoStream();
  83. Expected<DbiStream &> getPDBDbiStream();
  84. Expected<GlobalsStream &> getPDBGlobalsStream();
  85. Expected<TpiStream &> getPDBTpiStream();
  86. Expected<TpiStream &> getPDBIpiStream();
  87. Expected<PublicsStream &> getPDBPublicsStream();
  88. Expected<SymbolStream &> getPDBSymbolStream();
  89. Expected<PDBStringTable &> getStringTable();
  90. Expected<InjectedSourceStream &> getInjectedSourceStream();
  91. BumpPtrAllocator &getAllocator() { return Allocator; }
  92. bool hasPDBDbiStream() const;
  93. bool hasPDBGlobalsStream();
  94. bool hasPDBInfoStream() const;
  95. bool hasPDBIpiStream() const;
  96. bool hasPDBPublicsStream();
  97. bool hasPDBSymbolStream();
  98. bool hasPDBTpiStream() const;
  99. bool hasPDBStringTable();
  100. bool hasPDBInjectedSourceStream();
  101. uint32_t getPointerSize();
  102. private:
  103. std::string FilePath;
  104. BumpPtrAllocator &Allocator;
  105. std::unique_ptr<BinaryStream> Buffer;
  106. msf::MSFLayout ContainerLayout;
  107. std::unique_ptr<GlobalsStream> Globals;
  108. std::unique_ptr<InfoStream> Info;
  109. std::unique_ptr<DbiStream> Dbi;
  110. std::unique_ptr<TpiStream> Tpi;
  111. std::unique_ptr<TpiStream> Ipi;
  112. std::unique_ptr<PublicsStream> Publics;
  113. std::unique_ptr<SymbolStream> Symbols;
  114. std::unique_ptr<msf::MappedBlockStream> DirectoryStream;
  115. std::unique_ptr<msf::MappedBlockStream> StringTableStream;
  116. std::unique_ptr<InjectedSourceStream> InjectedSources;
  117. std::unique_ptr<PDBStringTable> Strings;
  118. };
  119. }
  120. }
  121. #endif
  122. #ifdef __GNUC__
  123. #pragma GCC diagnostic pop
  124. #endif