llvm/lib/DebugInfo/CodeView/DebugCrossExSubsection.cpp
Zachary Turner 11d1678b59 [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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304738 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-05 21:40:33 +00:00

50 lines
1.6 KiB
C++

//===- DebugCrossExSubsection.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
using namespace llvm;
using namespace llvm::codeview;
Error DebugCrossModuleExportsSubsectionRef::initialize(
BinaryStreamReader Reader) {
if (Reader.bytesRemaining() % sizeof(CrossModuleExport) != 0)
return make_error<CodeViewError>(
cv_error_code::corrupt_record,
"Cross Scope Exports section is an invalid size!");
uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
return Reader.readArray(References, Size);
}
Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
BinaryStreamReader Reader(Stream);
return initialize(Reader);
}
void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
uint32_t Global) {
Mappings[Local] = Global;
}
uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
return Mappings.size() * sizeof(CrossModuleExport);
}
Error DebugCrossModuleExportsSubsection::commit(
BinaryStreamWriter &Writer) const {
for (const auto &M : Mappings) {
if (auto EC = Writer.writeObject(M))
return EC;
}
return Error::success();
}