annotate include/llvm/DebugInfo/CodeView/StringsAndChecksums.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- StringsAndChecksums.h ------------------------------------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #define LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "llvm/DebugInfo/CodeView/CodeView.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include <memory>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 namespace codeview {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 class StringsAndChecksumsRef {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 // If no subsections are known about initially, we find as much as we can.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 StringsAndChecksumsRef();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 // If only a string table subsection is given, we find a checksums subsection.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 explicit StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 // If both subsections are given, we don't need to find anything.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 const DebugChecksumsSubsectionRef &Checksums);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 void setStrings(const DebugStringTableSubsectionRef &Strings);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 void setChecksums(const DebugChecksumsSubsectionRef &CS);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 void reset();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 void resetStrings();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 void resetChecksums();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 template <typename T> void initialize(T &&FragmentRange) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 for (const DebugSubsectionRecord &R : FragmentRange) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 if (Strings && Checksums)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 if (R.kind() == DebugSubsectionKind::FileChecksums) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 initializeChecksums(R);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 // While in practice we should never encounter a string table even
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 // though the string table is already initialized, in theory it's
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 // possible. PDBs are supposed to have one global string table and
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 // then this subsection should not appear. Whereas object files are
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 // supposed to have this subsection appear exactly once. However,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 // for testing purposes it's nice to be able to test this subsection
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 // independently of one format or the other, so for some tests we
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 // manually construct a PDB that contains this subsection in addition
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 // to a global string table.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 initializeStrings(R);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 const DebugStringTableSubsectionRef &strings() const { return *Strings; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 bool hasStrings() const { return Strings != nullptr; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 bool hasChecksums() const { return Checksums != nullptr; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 private:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 void initializeStrings(const DebugSubsectionRecord &SR);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 void initializeChecksums(const DebugSubsectionRecord &FCR);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 std::shared_ptr<DebugStringTableSubsectionRef> OwnedStrings;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 std::shared_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 const DebugStringTableSubsectionRef *Strings = nullptr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 const DebugChecksumsSubsectionRef *Checksums = nullptr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 class StringsAndChecksums {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 using StringsPtr = std::shared_ptr<DebugStringTableSubsection>;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 using ChecksumsPtr = std::shared_ptr<DebugChecksumsSubsection>;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 // If no subsections are known about initially, we find as much as we can.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 StringsAndChecksums() = default;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 void setStrings(const StringsPtr &SP) { Strings = SP; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 void setChecksums(const ChecksumsPtr &CP) { Checksums = CP; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 const StringsPtr &strings() const { return Strings; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 const ChecksumsPtr &checksums() const { return Checksums; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 bool hasStrings() const { return Strings != nullptr; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 bool hasChecksums() const { return Checksums != nullptr; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 private:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 StringsPtr Strings;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 ChecksumsPtr Checksums;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 } // end namespace codeview
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 } // end namespace llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 #endif // LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H