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