1 //===- StringsAndChecksums.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_STRINGSANDCHECKSUMS_H
10 #define LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
12 #include "llvm/DebugInfo/CodeView/CodeView.h"
13 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
14 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
15 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
21 class StringsAndChecksumsRef
{
23 // If no subsections are known about initially, we find as much as we can.
24 StringsAndChecksumsRef();
26 // If only a string table subsection is given, we find a checksums subsection.
27 explicit StringsAndChecksumsRef(const DebugStringTableSubsectionRef
&Strings
);
29 // If both subsections are given, we don't need to find anything.
30 StringsAndChecksumsRef(const DebugStringTableSubsectionRef
&Strings
,
31 const DebugChecksumsSubsectionRef
&Checksums
);
33 void setStrings(const DebugStringTableSubsectionRef
&Strings
);
34 void setChecksums(const DebugChecksumsSubsectionRef
&CS
);
38 void resetChecksums();
40 template <typename T
> void initialize(T
&&FragmentRange
) {
41 for (const DebugSubsectionRecord
&R
: FragmentRange
) {
42 if (Strings
&& Checksums
)
44 if (R
.kind() == DebugSubsectionKind::FileChecksums
) {
45 initializeChecksums(R
);
48 if (R
.kind() == DebugSubsectionKind::StringTable
&& !Strings
) {
49 // While in practice we should never encounter a string table even
50 // though the string table is already initialized, in theory it's
51 // possible. PDBs are supposed to have one global string table and
52 // then this subsection should not appear. Whereas object files are
53 // supposed to have this subsection appear exactly once. However,
54 // for testing purposes it's nice to be able to test this subsection
55 // independently of one format or the other, so for some tests we
56 // manually construct a PDB that contains this subsection in addition
57 // to a global string table.
64 const DebugStringTableSubsectionRef
&strings() const { return *Strings
; }
65 const DebugChecksumsSubsectionRef
&checksums() const { return *Checksums
; }
67 bool hasStrings() const { return Strings
!= nullptr; }
68 bool hasChecksums() const { return Checksums
!= nullptr; }
71 void initializeStrings(const DebugSubsectionRecord
&SR
);
72 void initializeChecksums(const DebugSubsectionRecord
&FCR
);
74 std::shared_ptr
<DebugStringTableSubsectionRef
> OwnedStrings
;
75 std::shared_ptr
<DebugChecksumsSubsectionRef
> OwnedChecksums
;
77 const DebugStringTableSubsectionRef
*Strings
= nullptr;
78 const DebugChecksumsSubsectionRef
*Checksums
= nullptr;
81 class StringsAndChecksums
{
83 using StringsPtr
= std::shared_ptr
<DebugStringTableSubsection
>;
84 using ChecksumsPtr
= std::shared_ptr
<DebugChecksumsSubsection
>;
86 // If no subsections are known about initially, we find as much as we can.
87 StringsAndChecksums() = default;
89 void setStrings(const StringsPtr
&SP
) { Strings
= SP
; }
90 void setChecksums(const ChecksumsPtr
&CP
) { Checksums
= CP
; }
92 const StringsPtr
&strings() const { return Strings
; }
93 const ChecksumsPtr
&checksums() const { return Checksums
; }
95 bool hasStrings() const { return Strings
!= nullptr; }
96 bool hasChecksums() const { return Checksums
!= nullptr; }
100 ChecksumsPtr Checksums
;
103 } // end namespace codeview
104 } // end namespace llvm
106 #endif // LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H