Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:40

0001 //===- StringsAndChecksums.h ------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
0010 #define LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
0011 
0012 #include "llvm/DebugInfo/CodeView/CodeView.h"
0013 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
0014 #include <memory>
0015 
0016 namespace llvm {
0017 namespace codeview {
0018 class DebugChecksumsSubsection;
0019 class DebugChecksumsSubsectionRef;
0020 class DebugStringTableSubsection;
0021 class DebugStringTableSubsectionRef;
0022 
0023 class StringsAndChecksumsRef {
0024 public:
0025   // If no subsections are known about initially, we find as much as we can.
0026   StringsAndChecksumsRef();
0027 
0028   // If only a string table subsection is given, we find a checksums subsection.
0029   explicit StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings);
0030 
0031   // If both subsections are given, we don't need to find anything.
0032   StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings,
0033                          const DebugChecksumsSubsectionRef &Checksums);
0034 
0035   void setStrings(const DebugStringTableSubsectionRef &Strings);
0036   void setChecksums(const DebugChecksumsSubsectionRef &CS);
0037 
0038   void reset();
0039   void resetStrings();
0040   void resetChecksums();
0041 
0042   template <typename T> void initialize(T &&FragmentRange) {
0043     for (const DebugSubsectionRecord &R : FragmentRange) {
0044       if (Strings && Checksums)
0045         return;
0046       if (R.kind() == DebugSubsectionKind::FileChecksums) {
0047         initializeChecksums(R);
0048         continue;
0049       }
0050       if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
0051         // While in practice we should never encounter a string table even
0052         // though the string table is already initialized, in theory it's
0053         // possible.  PDBs are supposed to have one global string table and
0054         // then this subsection should not appear.  Whereas object files are
0055         // supposed to have this subsection appear exactly once.  However,
0056         // for testing purposes it's nice to be able to test this subsection
0057         // independently of one format or the other, so for some tests we
0058         // manually construct a PDB that contains this subsection in addition
0059         // to a global string table.
0060         initializeStrings(R);
0061         continue;
0062       }
0063     }
0064   }
0065 
0066   const DebugStringTableSubsectionRef &strings() const { return *Strings; }
0067   const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
0068 
0069   bool hasStrings() const { return Strings != nullptr; }
0070   bool hasChecksums() const { return Checksums != nullptr; }
0071 
0072 private:
0073   void initializeStrings(const DebugSubsectionRecord &SR);
0074   void initializeChecksums(const DebugSubsectionRecord &FCR);
0075 
0076   std::shared_ptr<DebugStringTableSubsectionRef> OwnedStrings;
0077   std::shared_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
0078 
0079   const DebugStringTableSubsectionRef *Strings = nullptr;
0080   const DebugChecksumsSubsectionRef *Checksums = nullptr;
0081 };
0082 
0083 class StringsAndChecksums {
0084 public:
0085   using StringsPtr = std::shared_ptr<DebugStringTableSubsection>;
0086   using ChecksumsPtr = std::shared_ptr<DebugChecksumsSubsection>;
0087 
0088   // If no subsections are known about initially, we find as much as we can.
0089   StringsAndChecksums() = default;
0090 
0091   void setStrings(const StringsPtr &SP) { Strings = SP; }
0092   void setChecksums(const ChecksumsPtr &CP) { Checksums = CP; }
0093 
0094   const StringsPtr &strings() const { return Strings; }
0095   const ChecksumsPtr &checksums() const { return Checksums; }
0096 
0097   bool hasStrings() const { return Strings != nullptr; }
0098   bool hasChecksums() const { return Checksums != nullptr; }
0099 
0100 private:
0101   StringsPtr Strings;
0102   ChecksumsPtr Checksums;
0103 };
0104 
0105 } // end namespace codeview
0106 } // end namespace llvm
0107 
0108 #endif // LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H