1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
llvm-mirror/tools/llvm-pdbdump/C13DebugFragmentVisitor.cpp
Zachary Turner 5d88e16362 [CodeView] Handle Cross Module Imports and Exports.
While it's not entirely clear why a compiler or linker might
put this information into an object or PDB file, one has been
spotted in the wild which was causing llvm-pdbdump to crash.

This patch adds support for reading-writing these sections.
Since I don't know how to get one of the native tools to
generate this kind of debug info, the only test here is one
in which we feed YAML into the tool to produce a PDB and
then spit out YAML from the resulting PDB and make sure that
it matches.

llvm-svn: 304738
2017-06-05 21:40:33 +00:00

106 lines
3.0 KiB
C++

//===- C13DebugFragmentVisitor.cpp -------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "C13DebugFragmentVisitor.h"
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
#include "llvm/DebugInfo/PDB/Native/RawError.h"
using namespace llvm;
using namespace llvm::codeview;
using namespace llvm::pdb;
C13DebugFragmentVisitor::C13DebugFragmentVisitor(PDBFile &F) : F(F) {}
C13DebugFragmentVisitor::~C13DebugFragmentVisitor() {}
Error C13DebugFragmentVisitor::visitUnknown(
codeview::DebugUnknownSubsectionRef &Fragment) {
return Error::success();
}
Error C13DebugFragmentVisitor::visitFileChecksums(
codeview::DebugChecksumsSubsectionRef &Checksums) {
assert(!this->Checksums.hasValue());
this->Checksums = Checksums;
return Error::success();
}
Error C13DebugFragmentVisitor::visitLines(
codeview::DebugLinesSubsectionRef &Lines) {
this->Lines.push_back(Lines);
return Error::success();
}
Error C13DebugFragmentVisitor::visitInlineeLines(
codeview::DebugInlineeLinesSubsectionRef &Lines) {
this->InlineeLines.push_back(Lines);
return Error::success();
}
Error C13DebugFragmentVisitor::visitCrossModuleExports(
codeview::DebugCrossModuleExportsSubsectionRef &Exports) {
this->CrossExports.push_back(Exports);
return Error::success();
}
Error C13DebugFragmentVisitor::visitCrossModuleImports(
codeview::DebugCrossModuleImportsSubsectionRef &Imports) {
this->CrossImports.push_back(Imports);
return Error::success();
}
Error C13DebugFragmentVisitor::finished() {
if (Checksums.hasValue()) {
if (auto EC = handleFileChecksums())
return EC;
if (auto EC = handleLines())
return EC;
if (auto EC = handleInlineeLines())
return EC;
}
if (auto EC = handleCrossModuleExports())
return EC;
if (auto EC = handleCrossModuleImports())
return EC;
return Error::success();
}
Expected<StringRef>
C13DebugFragmentVisitor::getNameFromStringTable(uint32_t Offset) {
auto ST = F.getStringTable();
if (!ST)
return ST.takeError();
return ST->getStringForID(Offset);
}
Expected<StringRef>
C13DebugFragmentVisitor::getNameFromChecksumsBuffer(uint32_t Offset) {
assert(Checksums.hasValue());
auto Array = Checksums->getArray();
auto ChecksumIter = Array.at(Offset);
if (ChecksumIter == Array.end())
return make_error<RawError>(raw_error_code::invalid_format);
const auto &Entry = *ChecksumIter;
return getNameFromStringTable(Entry.FileNameOffset);
}