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