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