blob: 940b38c4a8ce81fde8b9e5aa9e3c2a06a2234ecb [file] [log] [blame]
Zachary Turner5b6e4e02017-04-29 01:13:21 +00001//===- 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
18using namespace llvm;
19using namespace llvm::codeview;
20using namespace llvm::pdb;
21
22C13DebugFragmentVisitor::C13DebugFragmentVisitor(PDBFile &F) : F(F) {}
23
24C13DebugFragmentVisitor::~C13DebugFragmentVisitor() {}
25
26Error C13DebugFragmentVisitor::visitUnknown(
Zachary Turner7cc13e52017-05-01 16:46:39 +000027 codeview::ModuleDebugUnknownFragmentRef &Fragment) {
Zachary Turner5b6e4e02017-04-29 01:13:21 +000028 return Error::success();
29}
30
31Error C13DebugFragmentVisitor::visitFileChecksums(
Zachary Turner7cc13e52017-05-01 16:46:39 +000032 codeview::ModuleDebugFileChecksumFragmentRef &Checksums) {
Zachary Turner5b6e4e02017-04-29 01:13:21 +000033 assert(!this->Checksums.hasValue());
34 this->Checksums = Checksums;
35 return Error::success();
36}
37
38Error C13DebugFragmentVisitor::visitLines(
Zachary Turner7cc13e52017-05-01 16:46:39 +000039 codeview::ModuleDebugLineFragmentRef &Lines) {
Zachary Turner5b6e4e02017-04-29 01:13:21 +000040 this->Lines.push_back(Lines);
41 return Error::success();
42}
43
44Error 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
58Expected<StringRef>
59C13DebugFragmentVisitor::getNameFromStringTable(uint32_t Offset) {
60 auto ST = F.getStringTable();
61 if (!ST)
62 return ST.takeError();
63
64 return ST->getStringForID(Offset);
65}
66
67Expected<StringRef>
68C13DebugFragmentVisitor::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}