1 //===- DebugChecksumsSubsection.h -------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H 11 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H 12 13 #include "llvm/ADT/ArrayRef.h" 14 #include "llvm/ADT/DenseMap.h" 15 #include "llvm/DebugInfo/CodeView/DebugSubsection.h" 16 #include "llvm/Support/Allocator.h" 17 #include "llvm/Support/BinaryStreamArray.h" 18 #include "llvm/Support/BinaryStreamReader.h" 19 #include "llvm/Support/Endian.h" 20 21 namespace llvm { 22 namespace codeview { 23 24 class DebugStringTableSubsection; 25 26 struct FileChecksumEntry { 27 uint32_t FileNameOffset; // Byte offset of filename in global stringtable. 28 FileChecksumKind Kind; // The type of checksum. 29 ArrayRef<uint8_t> Checksum; // The bytes of the checksum. 30 }; 31 } 32 } 33 34 namespace llvm { 35 template <> struct VarStreamArrayExtractor<codeview::FileChecksumEntry> { 36 public: 37 typedef void ContextType; 38 39 Error operator()(BinaryStreamRef Stream, uint32_t &Len, 40 codeview::FileChecksumEntry &Item); 41 }; 42 } 43 44 namespace llvm { 45 namespace codeview { 46 class DebugChecksumsSubsectionRef final : public DebugSubsectionRef { 47 typedef VarStreamArray<codeview::FileChecksumEntry> FileChecksumArray; 48 typedef FileChecksumArray::Iterator Iterator; 49 50 public: 51 DebugChecksumsSubsectionRef() 52 : DebugSubsectionRef(DebugSubsectionKind::FileChecksums) {} 53 54 static bool classof(const DebugSubsectionRef *S) { 55 return S->kind() == DebugSubsectionKind::FileChecksums; 56 } 57 58 bool valid() const { return Checksums.valid(); } 59 60 Error initialize(BinaryStreamReader Reader); 61 Error initialize(BinaryStreamRef Stream); 62 63 Iterator begin() const { return Checksums.begin(); } 64 Iterator end() const { return Checksums.end(); } 65 66 const FileChecksumArray &getArray() const { return Checksums; } 67 68 private: 69 FileChecksumArray Checksums; 70 }; 71 72 class DebugChecksumsSubsection final : public DebugSubsection { 73 public: 74 explicit DebugChecksumsSubsection(DebugStringTableSubsection &Strings); 75 76 static bool classof(const DebugSubsection *S) { 77 return S->kind() == DebugSubsectionKind::FileChecksums; 78 } 79 80 void addChecksum(StringRef FileName, FileChecksumKind Kind, 81 ArrayRef<uint8_t> Bytes); 82 83 uint32_t calculateSerializedSize() const override; 84 Error commit(BinaryStreamWriter &Writer) const override; 85 uint32_t mapChecksumOffset(StringRef FileName) const; 86 87 private: 88 DebugStringTableSubsection &Strings; 89 90 DenseMap<uint32_t, uint32_t> OffsetMap; 91 uint32_t SerializedSize = 0; 92 llvm::BumpPtrAllocator Storage; 93 std::vector<FileChecksumEntry> Checksums; 94 }; 95 } 96 } 97 98 #endif 99