1 //===- DebugChecksumsSubsection.h -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
10 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/CodeView/CodeView.h"
16 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/BinaryStreamArray.h"
19 #include "llvm/Support/BinaryStreamReader.h"
20 #include "llvm/Support/BinaryStreamRef.h"
21 #include "llvm/Support/Error.h"
29 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.
37 } // end namespace codeview
39 template <> struct VarStreamArrayExtractor
<codeview::FileChecksumEntry
> {
41 using ContextType
= void;
43 Error
operator()(BinaryStreamRef Stream
, uint32_t &Len
,
44 codeview::FileChecksumEntry
&Item
);
49 class DebugChecksumsSubsectionRef final
: public DebugSubsectionRef
{
50 using FileChecksumArray
= VarStreamArray
<codeview::FileChecksumEntry
>;
51 using Iterator
= FileChecksumArray::Iterator
;
54 DebugChecksumsSubsectionRef()
55 : DebugSubsectionRef(DebugSubsectionKind::FileChecksums
) {}
57 static bool classof(const DebugSubsectionRef
*S
) {
58 return S
->kind() == DebugSubsectionKind::FileChecksums
;
61 bool valid() const { return Checksums
.valid(); }
63 Error
initialize(BinaryStreamReader Reader
);
64 Error
initialize(BinaryStreamRef Stream
);
66 Iterator
begin() const { return Checksums
.begin(); }
67 Iterator
end() const { return Checksums
.end(); }
69 const FileChecksumArray
&getArray() const { return Checksums
; }
72 FileChecksumArray Checksums
;
75 class DebugChecksumsSubsection final
: public DebugSubsection
{
77 explicit DebugChecksumsSubsection(DebugStringTableSubsection
&Strings
);
79 static bool classof(const DebugSubsection
*S
) {
80 return S
->kind() == DebugSubsectionKind::FileChecksums
;
83 void addChecksum(StringRef FileName
, FileChecksumKind Kind
,
84 ArrayRef
<uint8_t> Bytes
);
86 uint32_t calculateSerializedSize() const override
;
87 Error
commit(BinaryStreamWriter
&Writer
) const override
;
88 uint32_t mapChecksumOffset(StringRef FileName
) const;
91 DebugStringTableSubsection
&Strings
;
93 DenseMap
<uint32_t, uint32_t> OffsetMap
;
94 uint32_t SerializedSize
= 0;
95 BumpPtrAllocator Storage
;
96 std::vector
<FileChecksumEntry
> Checksums
;
99 } // end namespace codeview
101 } // end namespace llvm
103 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H