blob: 01f83676afdf3122b65abd5b5ae25afd0555efbe [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- DebugChecksumsSubsection.h -------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
10#define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
11
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"
22#include <cstdint>
23#include <vector>
24
25namespace llvm {
26
27namespace codeview {
28
29class DebugStringTableSubsection;
30
31struct 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
37} // end namespace codeview
38
39template <> struct VarStreamArrayExtractor<codeview::FileChecksumEntry> {
40public:
41 using ContextType = void;
42
43 Error operator()(BinaryStreamRef Stream, uint32_t &Len,
44 codeview::FileChecksumEntry &Item);
45};
46
47namespace codeview {
48
49class DebugChecksumsSubsectionRef final : public DebugSubsectionRef {
50 using FileChecksumArray = VarStreamArray<codeview::FileChecksumEntry>;
51 using Iterator = FileChecksumArray::Iterator;
52
53public:
54 DebugChecksumsSubsectionRef()
55 : DebugSubsectionRef(DebugSubsectionKind::FileChecksums) {}
56
57 static bool classof(const DebugSubsectionRef *S) {
58 return S->kind() == DebugSubsectionKind::FileChecksums;
59 }
60
61 bool valid() const { return Checksums.valid(); }
62
63 Error initialize(BinaryStreamReader Reader);
64 Error initialize(BinaryStreamRef Stream);
65
66 Iterator begin() const { return Checksums.begin(); }
67 Iterator end() const { return Checksums.end(); }
68
69 const FileChecksumArray &getArray() const { return Checksums; }
70
71private:
72 FileChecksumArray Checksums;
73};
74
75class DebugChecksumsSubsection final : public DebugSubsection {
76public:
77 explicit DebugChecksumsSubsection(DebugStringTableSubsection &Strings);
78
79 static bool classof(const DebugSubsection *S) {
80 return S->kind() == DebugSubsectionKind::FileChecksums;
81 }
82
83 void addChecksum(StringRef FileName, FileChecksumKind Kind,
84 ArrayRef<uint8_t> Bytes);
85
86 uint32_t calculateSerializedSize() const override;
87 Error commit(BinaryStreamWriter &Writer) const override;
88 uint32_t mapChecksumOffset(StringRef FileName) const;
89
90private:
91 DebugStringTableSubsection &Strings;
92
93 DenseMap<uint32_t, uint32_t> OffsetMap;
94 uint32_t SerializedSize = 0;
95 BumpPtrAllocator Storage;
96 std::vector<FileChecksumEntry> Checksums;
97};
98
99} // end namespace codeview
100
101} // end namespace llvm
102
103#endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H