DebugChecksumsSubsection.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DebugChecksumsSubsection.h -------------------------------*- 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_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
  14. #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/DebugInfo/CodeView/CodeView.h"
  19. #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
  20. #include "llvm/Support/Allocator.h"
  21. #include "llvm/Support/BinaryStreamArray.h"
  22. #include "llvm/Support/BinaryStreamRef.h"
  23. #include "llvm/Support/Error.h"
  24. #include <cstdint>
  25. #include <vector>
  26. namespace llvm {
  27. class BinaryStreamReader;
  28. class BinaryStreamWriter;
  29. namespace codeview {
  30. class DebugStringTableSubsection;
  31. struct FileChecksumEntry {
  32. uint32_t FileNameOffset; // Byte offset of filename in global stringtable.
  33. FileChecksumKind Kind; // The type of checksum.
  34. ArrayRef<uint8_t> Checksum; // The bytes of the checksum.
  35. };
  36. } // end namespace codeview
  37. template <> struct VarStreamArrayExtractor<codeview::FileChecksumEntry> {
  38. public:
  39. using ContextType = void;
  40. Error operator()(BinaryStreamRef Stream, uint32_t &Len,
  41. codeview::FileChecksumEntry &Item);
  42. };
  43. namespace codeview {
  44. class DebugChecksumsSubsectionRef final : public DebugSubsectionRef {
  45. using FileChecksumArray = VarStreamArray<codeview::FileChecksumEntry>;
  46. using Iterator = FileChecksumArray::Iterator;
  47. public:
  48. DebugChecksumsSubsectionRef()
  49. : DebugSubsectionRef(DebugSubsectionKind::FileChecksums) {}
  50. static bool classof(const DebugSubsectionRef *S) {
  51. return S->kind() == DebugSubsectionKind::FileChecksums;
  52. }
  53. bool valid() const { return Checksums.valid(); }
  54. Error initialize(BinaryStreamReader Reader);
  55. Error initialize(BinaryStreamRef Stream);
  56. Iterator begin() const { return Checksums.begin(); }
  57. Iterator end() const { return Checksums.end(); }
  58. const FileChecksumArray &getArray() const { return Checksums; }
  59. private:
  60. FileChecksumArray Checksums;
  61. };
  62. class DebugChecksumsSubsection final : public DebugSubsection {
  63. public:
  64. explicit DebugChecksumsSubsection(DebugStringTableSubsection &Strings);
  65. static bool classof(const DebugSubsection *S) {
  66. return S->kind() == DebugSubsectionKind::FileChecksums;
  67. }
  68. void addChecksum(StringRef FileName, FileChecksumKind Kind,
  69. ArrayRef<uint8_t> Bytes);
  70. uint32_t calculateSerializedSize() const override;
  71. Error commit(BinaryStreamWriter &Writer) const override;
  72. uint32_t mapChecksumOffset(StringRef FileName) const;
  73. private:
  74. DebugStringTableSubsection &Strings;
  75. DenseMap<uint32_t, uint32_t> OffsetMap;
  76. uint32_t SerializedSize = 0;
  77. BumpPtrAllocator Storage;
  78. std::vector<FileChecksumEntry> Checksums;
  79. };
  80. } // end namespace codeview
  81. } // end namespace llvm
  82. #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
  83. #ifdef __GNUC__
  84. #pragma GCC diagnostic pop
  85. #endif