DebugChecksumsSubsection.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //===- DebugChecksumsSubsection.h -------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
  9. #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
  10. #include "llvm/ADT/ArrayRef.h"
  11. #include "llvm/ADT/DenseMap.h"
  12. #include "llvm/ADT/StringRef.h"
  13. #include "llvm/DebugInfo/CodeView/CodeView.h"
  14. #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
  15. #include "llvm/Support/Allocator.h"
  16. #include "llvm/Support/BinaryStreamArray.h"
  17. #include "llvm/Support/BinaryStreamReader.h"
  18. #include "llvm/Support/BinaryStreamRef.h"
  19. #include "llvm/Support/Error.h"
  20. #include <cstdint>
  21. #include <vector>
  22. namespace llvm {
  23. namespace codeview {
  24. class DebugStringTableSubsection;
  25. struct FileChecksumEntry {
  26. uint32_t FileNameOffset; // Byte offset of filename in global stringtable.
  27. FileChecksumKind Kind; // The type of checksum.
  28. ArrayRef<uint8_t> Checksum; // The bytes of the checksum.
  29. };
  30. } // end namespace codeview
  31. template <> struct VarStreamArrayExtractor<codeview::FileChecksumEntry> {
  32. public:
  33. using ContextType = void;
  34. Error operator()(BinaryStreamRef Stream, uint32_t &Len,
  35. codeview::FileChecksumEntry &Item);
  36. };
  37. namespace codeview {
  38. class DebugChecksumsSubsectionRef final : public DebugSubsectionRef {
  39. using FileChecksumArray = VarStreamArray<codeview::FileChecksumEntry>;
  40. using Iterator = FileChecksumArray::Iterator;
  41. public:
  42. DebugChecksumsSubsectionRef()
  43. : DebugSubsectionRef(DebugSubsectionKind::FileChecksums) {}
  44. static bool classof(const DebugSubsectionRef *S) {
  45. return S->kind() == DebugSubsectionKind::FileChecksums;
  46. }
  47. bool valid() const { return Checksums.valid(); }
  48. Error initialize(BinaryStreamReader Reader);
  49. Error initialize(BinaryStreamRef Stream);
  50. Iterator begin() const { return Checksums.begin(); }
  51. Iterator end() const { return Checksums.end(); }
  52. const FileChecksumArray &getArray() const { return Checksums; }
  53. private:
  54. FileChecksumArray Checksums;
  55. };
  56. class DebugChecksumsSubsection final : public DebugSubsection {
  57. public:
  58. explicit DebugChecksumsSubsection(DebugStringTableSubsection &Strings);
  59. static bool classof(const DebugSubsection *S) {
  60. return S->kind() == DebugSubsectionKind::FileChecksums;
  61. }
  62. void addChecksum(StringRef FileName, FileChecksumKind Kind,
  63. ArrayRef<uint8_t> Bytes);
  64. uint32_t calculateSerializedSize() const override;
  65. Error commit(BinaryStreamWriter &Writer) const override;
  66. uint32_t mapChecksumOffset(StringRef FileName) const;
  67. private:
  68. DebugStringTableSubsection &Strings;
  69. DenseMap<uint32_t, uint32_t> OffsetMap;
  70. uint32_t SerializedSize = 0;
  71. BumpPtrAllocator Storage;
  72. std::vector<FileChecksumEntry> Checksums;
  73. };
  74. } // end namespace codeview
  75. } // end namespace llvm
  76. #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H