blob: 9e204eec8604e15300ae3c24b83f548373735520 [file] [log] [blame]
Eugene Zelenko4fcfc192017-06-30 23:06:03 +00001//===- StringsAndChecksums.cpp --------------------------------------------===//
Zachary Turnera8cfc292017-06-14 15:59:27 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Zachary Turnera8cfc292017-06-14 15:59:27 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
Eugene Zelenko4fcfc192017-06-30 23:06:03 +000010#include "llvm/ADT/STLExtras.h"
11#include "llvm/DebugInfo/CodeView/CodeView.h"
Zachary Turnera8cfc292017-06-14 15:59:27 +000012#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
13#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
14#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
Eugene Zelenko4fcfc192017-06-30 23:06:03 +000015#include "llvm/Support/Error.h"
16#include <cassert>
Zachary Turnera8cfc292017-06-14 15:59:27 +000017
18using namespace llvm;
19using namespace llvm::codeview;
20
Eugene Zelenko4fcfc192017-06-30 23:06:03 +000021StringsAndChecksumsRef::StringsAndChecksumsRef() = default;
Zachary Turnera8cfc292017-06-14 15:59:27 +000022
23StringsAndChecksumsRef::StringsAndChecksumsRef(
24 const DebugStringTableSubsectionRef &Strings)
25 : Strings(&Strings) {}
26
27StringsAndChecksumsRef::StringsAndChecksumsRef(
28 const DebugStringTableSubsectionRef &Strings,
29 const DebugChecksumsSubsectionRef &Checksums)
30 : Strings(&Strings), Checksums(&Checksums) {}
31
32void StringsAndChecksumsRef::initializeStrings(
33 const DebugSubsectionRecord &SR) {
34 assert(SR.kind() == DebugSubsectionKind::StringTable);
35 assert(!Strings && "Found a string table even though we already have one!");
36
Zachary Turnerabb17cc2017-09-01 20:06:56 +000037 OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>();
Zachary Turnera8cfc292017-06-14 15:59:27 +000038 consumeError(OwnedStrings->initialize(SR.getRecordData()));
39 Strings = OwnedStrings.get();
40}
41
Zachary Turnerabb17cc2017-09-01 20:06:56 +000042void StringsAndChecksumsRef::reset() {
43 resetStrings();
44 resetChecksums();
45}
46
47void StringsAndChecksumsRef::resetStrings() {
48 OwnedStrings.reset();
49 Strings = nullptr;
50}
51
52void StringsAndChecksumsRef::resetChecksums() {
53 OwnedChecksums.reset();
54 Checksums = nullptr;
55}
56
57void StringsAndChecksumsRef::setStrings(
58 const DebugStringTableSubsectionRef &StringsRef) {
59 OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>();
60 *OwnedStrings = StringsRef;
61 Strings = OwnedStrings.get();
62}
63
Zachary Turner4e950642017-06-15 23:56:19 +000064void StringsAndChecksumsRef::setChecksums(
65 const DebugChecksumsSubsectionRef &CS) {
Zachary Turnerabb17cc2017-09-01 20:06:56 +000066 OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>();
Zachary Turner4e950642017-06-15 23:56:19 +000067 *OwnedChecksums = CS;
68 Checksums = OwnedChecksums.get();
69}
70
Zachary Turnera8cfc292017-06-14 15:59:27 +000071void StringsAndChecksumsRef::initializeChecksums(
72 const DebugSubsectionRecord &FCR) {
73 assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
74 if (Checksums)
75 return;
76
Zachary Turnerabb17cc2017-09-01 20:06:56 +000077 OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>();
Zachary Turnera8cfc292017-06-14 15:59:27 +000078 consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
79 Checksums = OwnedChecksums.get();
80}