LLVM  15.0.0git
StringsAndChecksums.h
Go to the documentation of this file.
1 //===- StringsAndChecksums.h ------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
10 #define LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
11 
14 #include <memory>
15 
16 namespace llvm {
17 namespace codeview {
18 class DebugChecksumsSubsection;
19 class DebugChecksumsSubsectionRef;
20 class DebugStringTableSubsection;
21 class DebugStringTableSubsectionRef;
22 
24 public:
25  // If no subsections are known about initially, we find as much as we can.
27 
28  // If only a string table subsection is given, we find a checksums subsection.
30 
31  // If both subsections are given, we don't need to find anything.
33  const DebugChecksumsSubsectionRef &Checksums);
34 
35  void setStrings(const DebugStringTableSubsectionRef &Strings);
37 
38  void reset();
39  void resetStrings();
40  void resetChecksums();
41 
42  template <typename T> void initialize(T &&FragmentRange) {
43  for (const DebugSubsectionRecord &R : FragmentRange) {
44  if (Strings && Checksums)
45  return;
46  if (R.kind() == DebugSubsectionKind::FileChecksums) {
47  initializeChecksums(R);
48  continue;
49  }
50  if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
51  // While in practice we should never encounter a string table even
52  // though the string table is already initialized, in theory it's
53  // possible. PDBs are supposed to have one global string table and
54  // then this subsection should not appear. Whereas object files are
55  // supposed to have this subsection appear exactly once. However,
56  // for testing purposes it's nice to be able to test this subsection
57  // independently of one format or the other, so for some tests we
58  // manually construct a PDB that contains this subsection in addition
59  // to a global string table.
60  initializeStrings(R);
61  continue;
62  }
63  }
64  }
65 
66  const DebugStringTableSubsectionRef &strings() const { return *Strings; }
67  const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
68 
69  bool hasStrings() const { return Strings != nullptr; }
70  bool hasChecksums() const { return Checksums != nullptr; }
71 
72 private:
73  void initializeStrings(const DebugSubsectionRecord &SR);
74  void initializeChecksums(const DebugSubsectionRecord &FCR);
75 
76  std::shared_ptr<DebugStringTableSubsectionRef> OwnedStrings;
77  std::shared_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
78 
79  const DebugStringTableSubsectionRef *Strings = nullptr;
80  const DebugChecksumsSubsectionRef *Checksums = nullptr;
81 };
82 
84 public:
85  using StringsPtr = std::shared_ptr<DebugStringTableSubsection>;
86  using ChecksumsPtr = std::shared_ptr<DebugChecksumsSubsection>;
87 
88  // If no subsections are known about initially, we find as much as we can.
89  StringsAndChecksums() = default;
90 
91  void setStrings(const StringsPtr &SP) { Strings = SP; }
92  void setChecksums(const ChecksumsPtr &CP) { Checksums = CP; }
93 
94  const StringsPtr &strings() const { return Strings; }
95  const ChecksumsPtr &checksums() const { return Checksums; }
96 
97  bool hasStrings() const { return Strings != nullptr; }
98  bool hasChecksums() const { return Checksums != nullptr; }
99 
100 private:
101  StringsPtr Strings;
102  ChecksumsPtr Checksums;
103 };
104 
105 } // end namespace codeview
106 } // end namespace llvm
107 
108 #endif // LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
llvm::codeview::StringsAndChecksums::checksums
const ChecksumsPtr & checksums() const
Definition: StringsAndChecksums.h:95
llvm::codeview::StringsAndChecksums::ChecksumsPtr
std::shared_ptr< DebugChecksumsSubsection > ChecksumsPtr
Definition: StringsAndChecksums.h:86
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::codeview::StringsAndChecksumsRef::initialize
void initialize(T &&FragmentRange)
Definition: StringsAndChecksums.h:42
llvm::codeview::StringsAndChecksums
Definition: StringsAndChecksums.h:83
llvm::codeview::StringsAndChecksumsRef::setChecksums
void setChecksums(const DebugChecksumsSubsectionRef &CS)
Definition: StringsAndChecksums.cpp:63
llvm::codeview::DebugSubsectionKind::StringTable
@ StringTable
llvm::codeview::StringsAndChecksumsRef::resetChecksums
void resetChecksums()
Definition: StringsAndChecksums.cpp:51
llvm::codeview::StringsAndChecksumsRef
Definition: StringsAndChecksums.h:23
DebugSubsectionRecord.h
llvm::codeview::StringsAndChecksumsRef::hasChecksums
bool hasChecksums() const
Definition: StringsAndChecksums.h:70
llvm::codeview::DebugSubsectionKind::FileChecksums
@ FileChecksums
llvm::codeview::StringsAndChecksums::hasStrings
bool hasStrings() const
Definition: StringsAndChecksums.h:97
llvm::codeview::StringsAndChecksumsRef::resetStrings
void resetStrings()
Definition: StringsAndChecksums.cpp:46
CodeView.h
llvm::codeview::StringsAndChecksumsRef::reset
void reset()
Definition: StringsAndChecksums.cpp:41
llvm::codeview::StringsAndChecksumsRef::checksums
const DebugChecksumsSubsectionRef & checksums() const
Definition: StringsAndChecksums.h:67
llvm::codeview::StringsAndChecksums::hasChecksums
bool hasChecksums() const
Definition: StringsAndChecksums.h:98
llvm::codeview::DebugSubsectionRecord
Definition: DebugSubsectionRecord.h:35
llvm::codeview::StringsAndChecksums::StringsAndChecksums
StringsAndChecksums()=default
llvm::codeview::StringsAndChecksumsRef::StringsAndChecksumsRef
StringsAndChecksumsRef()
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
llvm::codeview::StringsAndChecksums::strings
const StringsPtr & strings() const
Definition: StringsAndChecksums.h:94
llvm::codeview::StringsAndChecksumsRef::setStrings
void setStrings(const DebugStringTableSubsectionRef &Strings)
Definition: StringsAndChecksums.cpp:56
llvm::codeview::StringsAndChecksums::setChecksums
void setChecksums(const ChecksumsPtr &CP)
Definition: StringsAndChecksums.h:92
llvm::codeview::DebugStringTableSubsectionRef
Represents a read-only view of a CodeView string table.
Definition: DebugStringTableSubsection.h:31
llvm::codeview::StringsAndChecksumsRef::strings
const DebugStringTableSubsectionRef & strings() const
Definition: StringsAndChecksums.h:66
llvm::codeview::StringsAndChecksumsRef::hasStrings
bool hasStrings() const
Definition: StringsAndChecksums.h:69
llvm::codeview::StringsAndChecksums::setStrings
void setStrings(const StringsPtr &SP)
Definition: StringsAndChecksums.h:91
llvm::codeview::StringsAndChecksums::StringsPtr
std::shared_ptr< DebugStringTableSubsection > StringsPtr
Definition: StringsAndChecksums.h:85
llvm::codeview::DebugChecksumsSubsectionRef
Definition: DebugChecksumsSubsection.h:51