DebugChecksumsSubsection.h 3.2 KB

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