From c37cb0c6a5c266f102c130bfe1daaa25329cb997 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Thu, 27 Apr 2017 16:12:16 +0000 Subject: [CodeView] Isolate Debug Info Fragments into standalone classes. Previously parsing of these were all grouped together into a single master class that could parse any type of debug info fragment. With writing forthcoming, the complexity of each individual fragment is enough to warrant them having their own classes so that reading and writing of each fragment type can be grouped together, but isolated from the code for reading and writing other fragment types. In doing so, I found a place where parsing code was duplicated for the FileChecksums fragment, across llvm-readobj and the CodeView library, and one of the implementations had a bug. Now that the codepaths are merged, the bug is resolved. Differential Revision: https://reviews.llvm.org/D32547 llvm-svn: 301557 --- .../CodeView/ModuleDebugFileChecksumFragment.cpp | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 llvm/lib/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.cpp (limited to 'llvm/lib/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.cpp') diff --git a/llvm/lib/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.cpp b/llvm/lib/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.cpp new file mode 100644 index 00000000000..3f234adc1c2 --- /dev/null +++ b/llvm/lib/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.cpp @@ -0,0 +1,49 @@ +//===- ModuleDebugFileChecksumFragment.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/ModuleDebugFileChecksumFragment.h" + +#include "llvm/DebugInfo/CodeView/CodeViewError.h" +#include "llvm/Support/BinaryStreamReader.h" + +using namespace llvm; +using namespace llvm::codeview; + +struct FileChecksumEntryHeader { + using ulittle32_t = support::ulittle32_t; + + ulittle32_t FileNameOffset; // Byte offset of filename in global string table. + uint8_t ChecksumSize; // Number of bytes of checksum. + uint8_t ChecksumKind; // FileChecksumKind + // Checksum bytes follow. +}; + +Error llvm::VarStreamArrayExtractor::extract( + BinaryStreamRef Stream, uint32_t &Len, FileChecksumEntry &Item, void *Ctx) { + BinaryStreamReader Reader(Stream); + + const FileChecksumEntryHeader *Header; + if (auto EC = Reader.readObject(Header)) + return EC; + + Item.FileNameOffset = Header->FileNameOffset; + Item.Kind = static_cast(Header->ChecksumKind); + if (auto EC = Reader.readBytes(Item.Checksum, Header->ChecksumSize)) + return EC; + + Len = alignTo(Header->ChecksumSize + sizeof(FileChecksumEntryHeader), 4); + return Error::success(); +} + +Error ModuleDebugFileChecksumFragment::initialize(BinaryStreamReader Reader) { + if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining())) + return EC; + + return Error::success(); +} -- cgit v1.2.3