StringsAndChecksums.h 4.1 KB

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