StringsAndChecksums.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/ADT/STLExtras.h"
  10. #include "llvm/DebugInfo/CodeView/CodeView.h"
  11. #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
  12. #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
  13. #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
  14. #include "llvm/Support/Error.h"
  15. #include <cassert>
  16. using namespace llvm;
  17. using namespace llvm::codeview;
  18. StringsAndChecksumsRef::StringsAndChecksumsRef() = default;
  19. StringsAndChecksumsRef::StringsAndChecksumsRef(
  20. const DebugStringTableSubsectionRef &Strings)
  21. : Strings(&Strings) {}
  22. StringsAndChecksumsRef::StringsAndChecksumsRef(
  23. const DebugStringTableSubsectionRef &Strings,
  24. const DebugChecksumsSubsectionRef &Checksums)
  25. : Strings(&Strings), Checksums(&Checksums) {}
  26. void StringsAndChecksumsRef::initializeStrings(
  27. const DebugSubsectionRecord &SR) {
  28. assert(SR.kind() == DebugSubsectionKind::StringTable);
  29. assert(!Strings && "Found a string table even though we already have one!");
  30. OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>();
  31. consumeError(OwnedStrings->initialize(SR.getRecordData()));
  32. Strings = OwnedStrings.get();
  33. }
  34. void StringsAndChecksumsRef::reset() {
  35. resetStrings();
  36. resetChecksums();
  37. }
  38. void StringsAndChecksumsRef::resetStrings() {
  39. OwnedStrings.reset();
  40. Strings = nullptr;
  41. }
  42. void StringsAndChecksumsRef::resetChecksums() {
  43. OwnedChecksums.reset();
  44. Checksums = nullptr;
  45. }
  46. void StringsAndChecksumsRef::setStrings(
  47. const DebugStringTableSubsectionRef &StringsRef) {
  48. OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>();
  49. *OwnedStrings = StringsRef;
  50. Strings = OwnedStrings.get();
  51. }
  52. void StringsAndChecksumsRef::setChecksums(
  53. const DebugChecksumsSubsectionRef &CS) {
  54. OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>();
  55. *OwnedChecksums = CS;
  56. Checksums = OwnedChecksums.get();
  57. }
  58. void StringsAndChecksumsRef::initializeChecksums(
  59. const DebugSubsectionRecord &FCR) {
  60. assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
  61. if (Checksums)
  62. return;
  63. OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>();
  64. consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
  65. Checksums = OwnedChecksums.get();
  66. }