Zachary Turner | 591312c | 2017-05-30 17:13:33 +0000 | [diff] [blame] | 1 | //===- DebugFrameDataSubsection.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 "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" |
| 11 | #include "llvm/DebugInfo/CodeView/CodeViewError.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | using namespace llvm::codeview; |
| 15 | |
| 16 | Error DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader) { |
| 17 | if (auto EC = Reader.readObject(RelocPtr)) |
| 18 | return EC; |
| 19 | if (Reader.bytesRemaining() % sizeof(FrameData) != 0) |
| 20 | return make_error<CodeViewError>(cv_error_code::corrupt_record, |
| 21 | "Invalid frame data record format!"); |
| 22 | |
| 23 | uint32_t Count = Reader.bytesRemaining() / sizeof(FrameData); |
| 24 | if (auto EC = Reader.readArray(Frames, Count)) |
| 25 | return EC; |
| 26 | return Error::success(); |
| 27 | } |
| 28 | |
| 29 | uint32_t DebugFrameDataSubsection::calculateSerializedSize() const { |
| 30 | return 4 + sizeof(FrameData) * Frames.size(); |
| 31 | } |
| 32 | |
| 33 | Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const { |
| 34 | if (auto EC = Writer.writeInteger<uint32_t>(0)) |
| 35 | return EC; |
| 36 | |
| 37 | if (auto EC = Writer.writeArray(makeArrayRef(Frames))) |
| 38 | return EC; |
| 39 | return Error::success(); |
| 40 | } |
| 41 | |
| 42 | void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) { |
| 43 | Frames.push_back(Frame); |
| 44 | } |