TpiStreamBuilder.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- 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_TPISTREAMBUILDER_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
  15. #include "llvm/ADT/Optional.h"
  16. #include "llvm/DebugInfo/CodeView/TypeRecord.h"
  17. #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
  18. #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
  19. #include "llvm/Support/Allocator.h"
  20. #include "llvm/Support/BinaryByteStream.h"
  21. #include "llvm/Support/BinaryItemStream.h"
  22. #include "llvm/Support/BinaryStreamRef.h"
  23. #include "llvm/Support/Error.h"
  24. #include <vector>
  25. namespace llvm {
  26. class BinaryByteStream;
  27. class WritableBinaryStreamRef;
  28. template <> struct BinaryItemTraits<llvm::codeview::CVType> {
  29. static size_t length(const codeview::CVType &Item) { return Item.length(); }
  30. static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) {
  31. return Item.data();
  32. }
  33. };
  34. namespace codeview {
  35. class TypeRecord;
  36. }
  37. namespace msf {
  38. class MSFBuilder;
  39. struct MSFLayout;
  40. }
  41. namespace pdb {
  42. class PDBFile;
  43. class TpiStream;
  44. struct TpiStreamHeader;
  45. class TpiStreamBuilder {
  46. public:
  47. explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
  48. ~TpiStreamBuilder();
  49. TpiStreamBuilder(const TpiStreamBuilder &) = delete;
  50. TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
  51. void setVersionHeader(PdbRaw_TpiVer Version);
  52. void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash);
  53. void addTypeRecords(ArrayRef<uint8_t> Types, ArrayRef<uint16_t> Sizes,
  54. ArrayRef<uint32_t> Hashes);
  55. Error finalizeMsfLayout();
  56. uint32_t getRecordCount() const { return TypeRecordCount; }
  57. Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
  58. uint32_t calculateSerializedLength();
  59. private:
  60. void updateTypeIndexOffsets(ArrayRef<uint16_t> Sizes);
  61. uint32_t calculateHashBufferSize() const;
  62. uint32_t calculateIndexOffsetSize() const;
  63. Error finalize();
  64. msf::MSFBuilder &Msf;
  65. BumpPtrAllocator &Allocator;
  66. uint32_t TypeRecordCount = 0;
  67. size_t TypeRecordBytes = 0;
  68. PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80;
  69. std::vector<ArrayRef<uint8_t>> TypeRecBuffers;
  70. std::vector<uint32_t> TypeHashes;
  71. std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
  72. uint32_t HashStreamIndex = kInvalidStreamIndex;
  73. std::unique_ptr<BinaryByteStream> HashValueStream;
  74. const TpiStreamHeader *Header;
  75. uint32_t Idx;
  76. };
  77. }
  78. }
  79. #endif
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif