Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 1 | //===- StringsAndChecksums.cpp --------------------------------------------===// |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 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" |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/STLExtras.h" |
| 12 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" |
| 14 | #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" |
| 15 | #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Error.h" |
| 17 | #include <cassert> |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | using namespace llvm::codeview; |
| 21 | |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 22 | StringsAndChecksumsRef::StringsAndChecksumsRef() = default; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 23 | |
| 24 | StringsAndChecksumsRef::StringsAndChecksumsRef( |
| 25 | const DebugStringTableSubsectionRef &Strings) |
| 26 | : Strings(&Strings) {} |
| 27 | |
| 28 | StringsAndChecksumsRef::StringsAndChecksumsRef( |
| 29 | const DebugStringTableSubsectionRef &Strings, |
| 30 | const DebugChecksumsSubsectionRef &Checksums) |
| 31 | : Strings(&Strings), Checksums(&Checksums) {} |
| 32 | |
| 33 | void 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 | |
Zachary Turner | abb17cc | 2017-09-01 20:06:56 +0000 | [diff] [blame^] | 38 | OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>(); |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 39 | consumeError(OwnedStrings->initialize(SR.getRecordData())); |
| 40 | Strings = OwnedStrings.get(); |
| 41 | } |
| 42 | |
Zachary Turner | abb17cc | 2017-09-01 20:06:56 +0000 | [diff] [blame^] | 43 | void StringsAndChecksumsRef::reset() { |
| 44 | resetStrings(); |
| 45 | resetChecksums(); |
| 46 | } |
| 47 | |
| 48 | void StringsAndChecksumsRef::resetStrings() { |
| 49 | OwnedStrings.reset(); |
| 50 | Strings = nullptr; |
| 51 | } |
| 52 | |
| 53 | void StringsAndChecksumsRef::resetChecksums() { |
| 54 | OwnedChecksums.reset(); |
| 55 | Checksums = nullptr; |
| 56 | } |
| 57 | |
| 58 | void StringsAndChecksumsRef::setStrings( |
| 59 | const DebugStringTableSubsectionRef &StringsRef) { |
| 60 | OwnedStrings = std::make_shared<DebugStringTableSubsectionRef>(); |
| 61 | *OwnedStrings = StringsRef; |
| 62 | Strings = OwnedStrings.get(); |
| 63 | } |
| 64 | |
Zachary Turner | 4e95064 | 2017-06-15 23:56:19 +0000 | [diff] [blame] | 65 | void StringsAndChecksumsRef::setChecksums( |
| 66 | const DebugChecksumsSubsectionRef &CS) { |
Zachary Turner | abb17cc | 2017-09-01 20:06:56 +0000 | [diff] [blame^] | 67 | OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>(); |
Zachary Turner | 4e95064 | 2017-06-15 23:56:19 +0000 | [diff] [blame] | 68 | *OwnedChecksums = CS; |
| 69 | Checksums = OwnedChecksums.get(); |
| 70 | } |
| 71 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 72 | void StringsAndChecksumsRef::initializeChecksums( |
| 73 | const DebugSubsectionRecord &FCR) { |
| 74 | assert(FCR.kind() == DebugSubsectionKind::FileChecksums); |
| 75 | if (Checksums) |
| 76 | return; |
| 77 | |
Zachary Turner | abb17cc | 2017-09-01 20:06:56 +0000 | [diff] [blame^] | 78 | OwnedChecksums = std::make_shared<DebugChecksumsSubsectionRef>(); |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 79 | consumeError(OwnedChecksums->initialize(FCR.getRecordData())); |
| 80 | Checksums = OwnedChecksums.get(); |
| 81 | } |