| Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 1 | //===- C13DebugFragmentVisitor.cpp -------------------------------*- C++-*-===// |
| 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 "C13DebugFragmentVisitor.h" |
| 11 | |
| 12 | #include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" |
| 13 | #include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" |
| 14 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 15 | #include "llvm/DebugInfo/PDB/Native/RawError.h" |
| 16 | #include "llvm/DebugInfo/PDB/Native/StringTable.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | using namespace llvm::codeview; |
| 20 | using namespace llvm::pdb; |
| 21 | |
| 22 | C13DebugFragmentVisitor::C13DebugFragmentVisitor(PDBFile &F) : F(F) {} |
| 23 | |
| 24 | C13DebugFragmentVisitor::~C13DebugFragmentVisitor() {} |
| 25 | |
| 26 | Error C13DebugFragmentVisitor::visitUnknown( |
| Zachary Turner | 7cc13e5 | 2017-05-01 16:46:39 +0000 | [diff] [blame^] | 27 | codeview::ModuleDebugUnknownFragmentRef &Fragment) { |
| Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 28 | return Error::success(); |
| 29 | } |
| 30 | |
| 31 | Error C13DebugFragmentVisitor::visitFileChecksums( |
| Zachary Turner | 7cc13e5 | 2017-05-01 16:46:39 +0000 | [diff] [blame^] | 32 | codeview::ModuleDebugFileChecksumFragmentRef &Checksums) { |
| Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 33 | assert(!this->Checksums.hasValue()); |
| 34 | this->Checksums = Checksums; |
| 35 | return Error::success(); |
| 36 | } |
| 37 | |
| 38 | Error C13DebugFragmentVisitor::visitLines( |
| Zachary Turner | 7cc13e5 | 2017-05-01 16:46:39 +0000 | [diff] [blame^] | 39 | codeview::ModuleDebugLineFragmentRef &Lines) { |
| Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 40 | this->Lines.push_back(Lines); |
| 41 | return Error::success(); |
| 42 | } |
| 43 | |
| 44 | Error C13DebugFragmentVisitor::finished() { |
| 45 | if (!Checksums.hasValue()) { |
| 46 | assert(Lines.empty()); |
| 47 | return Error::success(); |
| 48 | } |
| 49 | if (auto EC = handleFileChecksums()) |
| 50 | return EC; |
| 51 | |
| 52 | if (auto EC = handleLines()) |
| 53 | return EC; |
| 54 | |
| 55 | return Error::success(); |
| 56 | } |
| 57 | |
| 58 | Expected<StringRef> |
| 59 | C13DebugFragmentVisitor::getNameFromStringTable(uint32_t Offset) { |
| 60 | auto ST = F.getStringTable(); |
| 61 | if (!ST) |
| 62 | return ST.takeError(); |
| 63 | |
| 64 | return ST->getStringForID(Offset); |
| 65 | } |
| 66 | |
| 67 | Expected<StringRef> |
| 68 | C13DebugFragmentVisitor::getNameFromChecksumsBuffer(uint32_t Offset) { |
| 69 | assert(Checksums.hasValue()); |
| 70 | |
| 71 | auto Array = Checksums->getArray(); |
| 72 | auto ChecksumIter = Array.at(Offset); |
| 73 | if (ChecksumIter == Array.end()) |
| 74 | return make_error<RawError>(raw_error_code::invalid_format); |
| 75 | const auto &Entry = *ChecksumIter; |
| 76 | return getNameFromStringTable(Entry.FileNameOffset); |
| 77 | } |