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