StringsAndChecksums.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===- StringsAndChecksums.cpp --------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
  9. #include "llvm/DebugInfo/CodeView/CodeView.h"
  10. #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
  11. #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
  12. #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
  13. #include "llvm/Support/Error.h"
  14. #include <cassert>
  15. using namespace llvm;
  16. using namespace llvm::codeview;
  17. StringsAndChecksumsRef::StringsAndChecksumsRef() = default;
  18. StringsAndChecksumsRef::StringsAndChecksumsRef(
  19. const DebugStringTableSubsectionRef &Strings)
  20. : Strings(&Strings) {}
  21. StringsAndChecksumsRef::StringsAndChecksumsRef(
  22. const DebugStringTableSubsectionRef &Strings,
  23. const DebugChecksumsSubsectionRef &Checksums)
  24. : Strings(&Strings), Checksums(&Checksums) {}
  25. void StringsAndChecksumsRef::initializeStrings(
  26. const DebugSubsectionRecord &SR) {
  27. assert(SR.kind() == DebugSubsectionKind::StringTable);
  28. assert(!Strings && "Found a string table even though we already have one!");
  29. OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>();
  30. consumeError(OwnedStrings->initialize(SR.getRecordData()));
  31. Strings = OwnedStrings.get();
  32. }
  33. void StringsAndChecksumsRef::reset() {
  34. resetStrings();
  35. resetChecksums();
  36. }
  37. void StringsAndChecksumsRef::resetStrings() {
  38. OwnedStrings.reset();
  39. Strings = nullptr;
  40. }
  41. void StringsAndChecksumsRef::resetChecksums() {
  42. OwnedChecksums.reset();
  43. Checksums = nullptr;
  44. }
  45. void StringsAndChecksumsRef::setStrings(
  46. const DebugStringTableSubsectionRef &StringsRef) {
  47. OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>();
  48. *OwnedStrings = StringsRef;
  49. Strings = OwnedStrings.get();
  50. }
  51. void StringsAndChecksumsRef::setChecksums(
  52. const DebugChecksumsSubsectionRef &CS) {
  53. OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>();
  54. *OwnedChecksums = CS;
  55. Checksums = OwnedChecksums.get();
  56. }
  57. void StringsAndChecksumsRef::initializeChecksums(
  58. const DebugSubsectionRecord &FCR) {
  59. assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
  60. if (Checksums)
  61. return;
  62. OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>();
  63. consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
  64. Checksums = OwnedChecksums.get();
  65. }